2 * Copyright 2015, François Revol <revol@free.fr>
3 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Copyright 2008-2012, Axel Dörfler, axeld@pinc-software.de.
5 * Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com
7 * Distributed under the terms of the MIT License.
12 #include "InitializeParameterEditor.h"
16 #include <Directory.h>
21 #include <DiskDeviceTypes.h>
22 #include <MutablePartition.h>
24 #include <AutoDeleter.h>
25 #include <StringForSize.h>
37 static const uint32 kDiskSystemFlags
=
39 | B_DISK_SYSTEM_SUPPORTS_INITIALIZING
40 | B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME
46 : BDiskSystemAddOn(kPartitionTypeFAT32
, kDiskSystemFlags
)
57 FATAddOn::CreatePartitionHandle(BMutablePartition
* partition
,
58 BPartitionHandle
** _handle
)
60 FATPartitionHandle
* handle
= new(nothrow
) FATPartitionHandle(partition
);
64 status_t error
= handle
->Init();
77 FATAddOn::CanInitialize(const BMutablePartition
* partition
)
84 FATAddOn::ValidateInitialize(const BMutablePartition
* partition
, BString
* name
,
85 const char* parameterString
)
87 if (!CanInitialize(partition
) || !name
)
90 if (name
->Length() >= MAX_PATH
)
91 name
->Truncate(MAX_PATH
- 1);
93 name
->ReplaceAll('/', '-');
100 FATAddOn::Initialize(BMutablePartition
* partition
, const char* name
,
101 const char* parameterString
, BPartitionHandle
** _handle
)
103 if (!CanInitialize(partition
) || name
== NULL
)
106 FATPartitionHandle
* handle
= new(nothrow
) FATPartitionHandle(partition
);
109 ObjectDeleter
<FATPartitionHandle
> handleDeleter(handle
);
111 status_t error
= partition
->SetContentType(Name());
115 partition
->SetContentName(name
);
116 partition
->SetContentParameters(parameterString
);
117 uint32 blockSize
= 4096;
118 partition
->SetBlockSize(blockSize
);
119 partition
->SetContentSize(partition
->Size() / blockSize
* blockSize
);
120 partition
->Changed(B_PARTITION_CHANGED_INITIALIZATION
);
122 *_handle
= handleDeleter
.Detach();
128 FATAddOn::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type
,
129 BPartitionParameterEditor
** editor
)
132 if (type
== B_INITIALIZE_PARAMETER_EDITOR
) {
134 *editor
= new InitializeFATEditor();
135 } catch (std::bad_alloc
) {
140 return B_NOT_SUPPORTED
;
144 FATPartitionHandle::FATPartitionHandle(BMutablePartition
* partition
)
145 : BPartitionHandle(partition
)
150 FATPartitionHandle::~FATPartitionHandle()
156 FATPartitionHandle::Init()
163 FATPartitionHandle::SupportedOperations(uint32 mask
)
165 return kDiskSystemFlags
& mask
;
170 get_disk_system_add_ons(BList
* addOns
)
172 FATAddOn
* addOn
= new(nothrow
) FATAddOn
;
176 if (!addOns
->AddItem(addOn
)) {