Add FAT addon for DriveSetup
Tested with a 5MB image, seems to work. There seems to be an issue with too long names though, or possibly names with spaces. Also, technically it supports FAT12,16 and 32, so it should probably be renamed in the interface. Didn't check how to declare support for more than 1 partition types either.
This commit is contained in:
@@ -259,7 +259,8 @@ AddFilesToPackage add-ons Print transport
|
||||
AddFilesToPackage add-ons Screen\ Savers : $(SYSTEM_ADD_ONS_SCREENSAVERS) ;
|
||||
|
||||
AddFilesToPackage add-ons disk_systems
|
||||
: <disk_system>intel <disk_system>gpt <disk_system>bfs <disk_system>ntfs ;
|
||||
: <disk_system>fat <disk_system>intel <disk_system>gpt <disk_system>bfs
|
||||
<disk_system>ntfs ;
|
||||
|
||||
|
||||
# the MIME DB
|
||||
|
||||
@@ -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 ;
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright 2015, François Revol <[email protected]>
|
||||
* Copyright 2007, Ingo Weinhold, [email protected].
|
||||
* Copyright 2008-2012, Axel Dörfler, [email protected].
|
||||
* Copyright 2012, Gerasim Troeglazov (3dEyes**), [email protected]
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "FATAddOn.h"
|
||||
#include "InitializeParameterEditor.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <List.h>
|
||||
#include <Path.h>
|
||||
#include <Volume.h>
|
||||
|
||||
#include <DiskDeviceTypes.h>
|
||||
#include <MutablePartition.h>
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
#include <StringForSize.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#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<FATPartitionHandle> 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;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2015, François Revol <[email protected]>
|
||||
* Copyright 2007, Ingo Weinhold, [email protected].
|
||||
* Copyright 2008-2012, Axel Dörfler, [email protected].
|
||||
* Copyright 2012, Gerasim Troeglazov (3dEyes**), [email protected]
|
||||
*
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _FAT_ADD_ON_H
|
||||
#define _FAT_ADD_ON_H
|
||||
|
||||
#include <DiskSystemAddOn.h>
|
||||
|
||||
#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
|
||||
@@ -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."
|
||||
};
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright 2015, François Revol <[email protected]>
|
||||
* Copyright 2009-2010, Stephan Aßmus <[email protected]>
|
||||
* Copyright 2009, Bryce Groff, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "InitializeParameterEditor.h"
|
||||
|
||||
#include <Button.h>
|
||||
#include <Catalog.h>
|
||||
#include <CheckBox.h>
|
||||
#include <ControlLook.h>
|
||||
#include <GridLayoutBuilder.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Partition.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <TextControl.h>
|
||||
#include <Variant.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
|
||||
|
||||
#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()
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2015, François Revol <[email protected]>
|
||||
* Copyright 2009-2010, Stephan Aßmus <[email protected]>
|
||||
* Copyright 2009, Bryce Groff, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _INITIALIZE_PARAMETER_EDITOR
|
||||
#define _INITIALIZE_PARAMETER_EDITOR
|
||||
|
||||
|
||||
#include <PartitionParameterEditor.h>
|
||||
#include <String.h>
|
||||
|
||||
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
|
||||
@@ -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 <disk_system>fat : FATAddOn.rdef ;
|
||||
|
||||
Addon <disk_system>fat :
|
||||
FATAddOn.cpp
|
||||
InitializeParameterEditor.cpp
|
||||
|
||||
: be localestub $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++) libshared.a
|
||||
;
|
||||
|
||||
DoCatalogs <disk_system>fat :
|
||||
x-vnd.Haiku-FATAddOn
|
||||
:
|
||||
InitializeParameterEditor.cpp
|
||||
;
|
||||
Reference in New Issue
Block a user