diff --git a/build/jam/packages/Haiku b/build/jam/packages/Haiku index 13aef951e3..147f3f592c 100644 --- a/build/jam/packages/Haiku +++ b/build/jam/packages/Haiku @@ -259,7 +259,8 @@ AddFilesToPackage add-ons Print transport AddFilesToPackage add-ons Screen\ Savers : $(SYSTEM_ADD_ONS_SCREENSAVERS) ; AddFilesToPackage add-ons disk_systems - : intel gpt bfs ntfs ; + : fat intel gpt bfs + ntfs ; # the MIME DB diff --git a/src/add-ons/disk_systems/Jamfile b/src/add-ons/disk_systems/Jamfile index 9ef53ba605..d9f2e1be0a 100644 --- a/src/add-ons/disk_systems/Jamfile +++ b/src/add-ons/disk_systems/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src add-ons disk_systems ; SubInclude HAIKU_TOP src add-ons disk_systems bfs ; +SubInclude HAIKU_TOP src add-ons disk_systems fat ; SubInclude HAIKU_TOP src add-ons disk_systems gpt ; SubInclude HAIKU_TOP src add-ons disk_systems intel ; SubInclude HAIKU_TOP src add-ons disk_systems ntfs ; diff --git a/src/add-ons/disk_systems/fat/FATAddOn.cpp b/src/add-ons/disk_systems/fat/FATAddOn.cpp new file mode 100644 index 0000000000..2110799455 --- /dev/null +++ b/src/add-ons/disk_systems/fat/FATAddOn.cpp @@ -0,0 +1,181 @@ +/* + * Copyright 2015, François Revol + * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2008-2012, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com + * + * Distributed under the terms of the MIT License. + */ + + +#include "FATAddOn.h" +#include "InitializeParameterEditor.h" + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#ifdef ASSERT +# undef ASSERT +#endif + + +using std::nothrow; + +static const uint32 kDiskSystemFlags = + 0 + | B_DISK_SYSTEM_SUPPORTS_INITIALIZING + | B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME +; + +#define TRACE printf + +FATAddOn::FATAddOn() + : BDiskSystemAddOn(kPartitionTypeFAT32, kDiskSystemFlags) +{ +} + + +FATAddOn::~FATAddOn() +{ +} + + +status_t +FATAddOn::CreatePartitionHandle(BMutablePartition* partition, + BPartitionHandle** _handle) +{ + FATPartitionHandle* handle = new(nothrow) FATPartitionHandle(partition); + if (!handle) + return B_NO_MEMORY; + + status_t error = handle->Init(); + if (error != B_OK) { + delete handle; + return error; + } + + *_handle = handle; + + return B_OK; +} + + +bool +FATAddOn::CanInitialize(const BMutablePartition* partition) +{ + return true; +} + + +status_t +FATAddOn::ValidateInitialize(const BMutablePartition* partition, BString* name, + const char* parameterString) +{ + if (!CanInitialize(partition) || !name) + return B_BAD_VALUE; + + if (name->Length() >= MAX_PATH) + name->Truncate(MAX_PATH - 1); + + name->ReplaceAll('/', '-'); + + return B_OK; +} + + +status_t +FATAddOn::Initialize(BMutablePartition* partition, const char* name, + const char* parameterString, BPartitionHandle** _handle) +{ + if (!CanInitialize(partition) || name == NULL) + return B_BAD_VALUE; + + FATPartitionHandle* handle = new(nothrow) FATPartitionHandle(partition); + if (!handle) + return B_NO_MEMORY; + ObjectDeleter handleDeleter(handle); + + status_t error = partition->SetContentType(Name()); + if (error != B_OK) + return error; + + partition->SetContentName(name); + partition->SetContentParameters(parameterString); + uint32 blockSize = 4096; + partition->SetBlockSize(blockSize); + partition->SetContentSize(partition->Size() / blockSize * blockSize); + partition->Changed(B_PARTITION_CHANGED_INITIALIZATION); + + *_handle = handleDeleter.Detach(); + return B_OK; +} + + +status_t +FATAddOn::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type, + BPartitionParameterEditor** editor) +{ + *editor = NULL; + if (type == B_INITIALIZE_PARAMETER_EDITOR) { + try { + *editor = new InitializeFATEditor(); + } catch (std::bad_alloc) { + return B_NO_MEMORY; + } + return B_OK; + } + return B_NOT_SUPPORTED; +} + + +FATPartitionHandle::FATPartitionHandle(BMutablePartition* partition) + : BPartitionHandle(partition) +{ +} + + +FATPartitionHandle::~FATPartitionHandle() +{ +} + + +status_t +FATPartitionHandle::Init() +{ + return B_OK; +} + + +uint32 +FATPartitionHandle::SupportedOperations(uint32 mask) +{ + return kDiskSystemFlags & mask; +} + + +status_t +get_disk_system_add_ons(BList* addOns) +{ + FATAddOn* addOn = new(nothrow) FATAddOn; + if (!addOn) + return B_NO_MEMORY; + + if (!addOns->AddItem(addOn)) { + delete addOn; + return B_NO_MEMORY; + } + return B_OK; +} diff --git a/src/add-ons/disk_systems/fat/FATAddOn.h b/src/add-ons/disk_systems/fat/FATAddOn.h new file mode 100644 index 0000000000..0cb9436168 --- /dev/null +++ b/src/add-ons/disk_systems/fat/FATAddOn.h @@ -0,0 +1,54 @@ +/* + * Copyright 2015, François Revol + * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2008-2012, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com + * + * Distributed under the terms of the MIT License. + */ + +#ifndef _FAT_ADD_ON_H +#define _FAT_ADD_ON_H + +#include + +#ifndef MAX_PATH +#define MAX_PATH 1024 +#endif + +class FATAddOn : public BDiskSystemAddOn { +public: + FATAddOn(); + virtual ~FATAddOn(); + + virtual status_t CreatePartitionHandle( + BMutablePartition* partition, + BPartitionHandle** handle); + virtual status_t GetParameterEditor( + B_PARAMETER_EDITOR_TYPE type, + BPartitionParameterEditor** editor); + + virtual bool CanInitialize( + const BMutablePartition* partition); + virtual status_t ValidateInitialize( + const BMutablePartition* partition, + BString* name, const char* parameters); + virtual status_t Initialize(BMutablePartition* partition, + const char* name, const char* parameters, + BPartitionHandle** handle); +}; + + +class FATPartitionHandle : public BPartitionHandle { +public: + FATPartitionHandle( + BMutablePartition* partition); + ~FATPartitionHandle(); + + status_t Init(); + + virtual uint32 SupportedOperations(uint32 mask); +}; + + +#endif // _FAT_ADD_ON_H diff --git a/src/add-ons/disk_systems/fat/FATAddOn.rdef b/src/add-ons/disk_systems/fat/FATAddOn.rdef new file mode 100644 index 0000000000..f2dcf70e83 --- /dev/null +++ b/src/add-ons/disk_systems/fat/FATAddOn.rdef @@ -0,0 +1,15 @@ +/* + * FATAddOn.rdef + */ + +resource app_signature "application/x-vnd.Haiku-FATAddOn"; + +resource app_version { + major = 0, + middle = 0, + minor = 1, + variety = 0, + internal = 0, + short_info = "0.0.1", + long_info = "Haiku FAT disk add-on." +}; diff --git a/src/add-ons/disk_systems/fat/InitializeParameterEditor.cpp b/src/add-ons/disk_systems/fat/InitializeParameterEditor.cpp new file mode 100644 index 0000000000..8132b6eaf6 --- /dev/null +++ b/src/add-ons/disk_systems/fat/InitializeParameterEditor.cpp @@ -0,0 +1,148 @@ +/* + * Copyright 2015, François Revol + * Copyright 2009-2010, Stephan Aßmus + * Copyright 2009, Bryce Groff, brycegroff@gmail.com. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include "InitializeParameterEditor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "FAT_Initialize_Parameter" + + +static uint32 MSG_NAME_CHANGED = 'nmch'; +static uint32 MSG_FAT_BITS = 'fatb'; + +InitializeFATEditor::InitializeFATEditor() + : + BPartitionParameterEditor(), + fView(NULL), + fNameControl(NULL), + fFatBitsMenuField(NULL), + fParameters(NULL) +{ + _CreateViewControls(); +} + + +InitializeFATEditor::~InitializeFATEditor() +{ +} + + +void +InitializeFATEditor::SetTo(BPartition* partition) +{ + BString name = partition->ContentName(); + if (!name.IsEmpty()) + fNameControl->SetText(name.String()); +} + + +BView* +InitializeFATEditor::View() +{ + return fView; +} + + +bool +InitializeFATEditor::ValidateParameters() const +{ + // The name must be set + return fNameControl->TextView()->TextLength() > 0; +} + + +status_t +InitializeFATEditor::ParameterChanged(const char* name, + const BVariant& variant) +{ + if (!strcmp(name, "name")) + fNameControl->SetText(variant.ToString()); + return B_OK; +} + + +status_t +InitializeFATEditor::GetParameters(BString& parameters) +{ + parameters = ""; + + if (BMenuItem* item = fFatBitsMenuField->Menu()->FindMarked()) { + const char* size; + BMessage* message = item->Message(); + if (!message || message->FindString("fat", &size) < B_OK) + size = "0"; // autodetect + // TODO: use libroot driver settings API + parameters << "fat " << size << ";\n"; + } + + parameters << "name \""; + parameters << fNameControl->Text() << "\";\n"; +printf("p:%s", parameters.String()); + return B_OK; +} + + +void +InitializeFATEditor::_CreateViewControls() +{ + fNameControl = new BTextControl(B_TRANSLATE("Name:"), "New FAT Vol", + NULL); + fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); + // TODO find out what is the max length for this specific FS partition name + fNameControl->TextView()->SetMaxBytes(11); + + BPopUpMenu* fatBitsMenu = new BPopUpMenu("fat size"); + BMessage* message = new BMessage(MSG_FAT_BITS); + message->AddString("fat", "0"); + BMenuItem* defaultItem = new BMenuItem( + B_TRANSLATE("Auto (default)"), message); + fatBitsMenu->AddItem(defaultItem); + message = new BMessage(MSG_FAT_BITS); + message->AddString("fat", "12"); + fatBitsMenu->AddItem(new BMenuItem("12", message)); + message = new BMessage(MSG_FAT_BITS); + message->AddString("fat", "16"); + fatBitsMenu->AddItem(new BMenuItem("16", message)); + message = new BMessage(MSG_FAT_BITS); + message->AddString("fat", "32"); + fatBitsMenu->AddItem(new BMenuItem("32", message)); + + fFatBitsMenuField = new BMenuField(B_TRANSLATE("FAT bits:"), + fatBitsMenu); + defaultItem->SetMarked(true); + + float spacing = be_control_look->DefaultItemSpacing(); + + fView = BGridLayoutBuilder(spacing, spacing) + // row 1 + .Add(fNameControl->CreateLabelLayoutItem(), 0, 0) + .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0) + + // row 2 + .Add(fFatBitsMenuField->CreateLabelLayoutItem(), 0, 1) + .Add(fFatBitsMenuField->CreateMenuBarLayoutItem(), 1, 1).View() + ; +} diff --git a/src/add-ons/disk_systems/fat/InitializeParameterEditor.h b/src/add-ons/disk_systems/fat/InitializeParameterEditor.h new file mode 100644 index 0000000000..05e71f9ce4 --- /dev/null +++ b/src/add-ons/disk_systems/fat/InitializeParameterEditor.h @@ -0,0 +1,48 @@ +/* + * Copyright 2015, François Revol + * Copyright 2009-2010, Stephan Aßmus + * Copyright 2009, Bryce Groff, brycegroff@gmail.com. + * Distributed under the terms of the MIT License. + */ +#ifndef _INITIALIZE_PARAMETER_EDITOR +#define _INITIALIZE_PARAMETER_EDITOR + + +#include +#include + +class BCheckBox; +class BMenuField; +class BTextControl; +class BView; + + +class InitializeFATEditor : public BPartitionParameterEditor { +public: + InitializeFATEditor(); + virtual ~InitializeFATEditor(); + + virtual void SetTo(BPartition* partition); + + virtual bool ValidateParameters() const; + virtual status_t ParameterChanged(const char* name, + const BVariant& variant); + + virtual BView* View(); + + virtual status_t GetParameters(BString& parameters); + +// virtual status_t PartitionNameChanged(const char* name); + +private: + void _CreateViewControls(); + + BView* fView; + BTextControl* fNameControl; + BMenuField* fFatBitsMenuField; + + BString fParameters; +}; + + +#endif //_INITIALIZE_PARAMETER_EDITOR diff --git a/src/add-ons/disk_systems/fat/Jamfile b/src/add-ons/disk_systems/fat/Jamfile new file mode 100644 index 0000000000..282f1b3c4e --- /dev/null +++ b/src/add-ons/disk_systems/fat/Jamfile @@ -0,0 +1,21 @@ +SubDir HAIKU_TOP src add-ons disk_systems fat ; + +UsePrivateKernelHeaders ; +UsePrivateHeaders shared storage ; + +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems fat ] ; + +AddResources fat : FATAddOn.rdef ; + +Addon fat : + FATAddOn.cpp + InitializeParameterEditor.cpp + + : be localestub $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++) libshared.a +; + +DoCatalogs fat : + x-vnd.Haiku-FATAddOn + : + InitializeParameterEditor.cpp +;