3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / disk_systems / fat / FATAddOn.cpp
blob2110799455091fc104ca5fcc7238accf53903d36
1 /*
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.
8 */
11 #include "FATAddOn.h"
12 #include "InitializeParameterEditor.h"
14 #include <new>
16 #include <Directory.h>
17 #include <List.h>
18 #include <Path.h>
19 #include <Volume.h>
21 #include <DiskDeviceTypes.h>
22 #include <MutablePartition.h>
24 #include <AutoDeleter.h>
25 #include <StringForSize.h>
27 #include <debug.h>
28 #include <stdio.h>
30 #ifdef ASSERT
31 # undef ASSERT
32 #endif
35 using std::nothrow;
37 static const uint32 kDiskSystemFlags =
39 | B_DISK_SYSTEM_SUPPORTS_INITIALIZING
40 | B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME
43 #define TRACE printf
45 FATAddOn::FATAddOn()
46 : BDiskSystemAddOn(kPartitionTypeFAT32, kDiskSystemFlags)
51 FATAddOn::~FATAddOn()
56 status_t
57 FATAddOn::CreatePartitionHandle(BMutablePartition* partition,
58 BPartitionHandle** _handle)
60 FATPartitionHandle* handle = new(nothrow) FATPartitionHandle(partition);
61 if (!handle)
62 return B_NO_MEMORY;
64 status_t error = handle->Init();
65 if (error != B_OK) {
66 delete handle;
67 return error;
70 *_handle = handle;
72 return B_OK;
76 bool
77 FATAddOn::CanInitialize(const BMutablePartition* partition)
79 return true;
83 status_t
84 FATAddOn::ValidateInitialize(const BMutablePartition* partition, BString* name,
85 const char* parameterString)
87 if (!CanInitialize(partition) || !name)
88 return B_BAD_VALUE;
90 if (name->Length() >= MAX_PATH)
91 name->Truncate(MAX_PATH - 1);
93 name->ReplaceAll('/', '-');
95 return B_OK;
99 status_t
100 FATAddOn::Initialize(BMutablePartition* partition, const char* name,
101 const char* parameterString, BPartitionHandle** _handle)
103 if (!CanInitialize(partition) || name == NULL)
104 return B_BAD_VALUE;
106 FATPartitionHandle* handle = new(nothrow) FATPartitionHandle(partition);
107 if (!handle)
108 return B_NO_MEMORY;
109 ObjectDeleter<FATPartitionHandle> handleDeleter(handle);
111 status_t error = partition->SetContentType(Name());
112 if (error != B_OK)
113 return error;
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();
123 return B_OK;
127 status_t
128 FATAddOn::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
129 BPartitionParameterEditor** editor)
131 *editor = NULL;
132 if (type == B_INITIALIZE_PARAMETER_EDITOR) {
133 try {
134 *editor = new InitializeFATEditor();
135 } catch (std::bad_alloc) {
136 return B_NO_MEMORY;
138 return B_OK;
140 return B_NOT_SUPPORTED;
144 FATPartitionHandle::FATPartitionHandle(BMutablePartition* partition)
145 : BPartitionHandle(partition)
150 FATPartitionHandle::~FATPartitionHandle()
155 status_t
156 FATPartitionHandle::Init()
158 return B_OK;
162 uint32
163 FATPartitionHandle::SupportedOperations(uint32 mask)
165 return kDiskSystemFlags & mask;
169 status_t
170 get_disk_system_add_ons(BList* addOns)
172 FATAddOn* addOn = new(nothrow) FATAddOn;
173 if (!addOn)
174 return B_NO_MEMORY;
176 if (!addOns->AddItem(addOn)) {
177 delete addOn;
178 return B_NO_MEMORY;
180 return B_OK;