2 * Copyright 2003-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold, ingo_weinhold@gmx.de
9 #include "KFileSystem.h"
15 #include <fs_interface.h>
17 #include "ddm_modules.h"
18 #include "KDiskDeviceUtils.h"
19 #include "KPartition.h"
23 KFileSystem::KFileSystem(const char *name
)
31 KFileSystem::~KFileSystem()
40 status_t error
= KDiskSystem::Init();
46 error
= SetShortName(fModule
->short_name
);
48 error
= SetPrettyName(fModule
->pretty_name
);
50 SetFlags(fModule
->flags
| B_DISK_SYSTEM_IS_FILE_SYSTEM
);
58 KFileSystem::Identify(KPartition
*partition
, void **cookie
)
60 if (!partition
|| !cookie
|| !fModule
|| !fModule
->identify_partition
)
63 if (partition
->Open(O_RDONLY
, &fd
) != B_OK
)
65 float result
= fModule
->identify_partition(fd
, partition
->PartitionData(),
74 KFileSystem::Scan(KPartition
*partition
, void *cookie
)
76 if (!partition
|| !fModule
|| !fModule
->scan_partition
)
79 status_t result
= partition
->Open(O_RDONLY
, &fd
);
82 result
= fModule
->scan_partition(fd
, partition
->PartitionData(), cookie
);
90 KFileSystem::FreeIdentifyCookie(KPartition
*partition
, void *cookie
)
92 if (!partition
|| !fModule
|| !fModule
->free_identify_partition_cookie
)
94 fModule
->free_identify_partition_cookie(partition
->PartitionData(), cookie
);
100 KFileSystem::FreeContentCookie(KPartition
*partition
)
102 if (!partition
|| !fModule
|| !fModule
->free_partition_content_cookie
)
104 fModule
->free_partition_content_cookie(partition
->PartitionData());
110 KFileSystem::Defragment(KPartition
* partition
, disk_job_id job
)
119 KFileSystem::Repair(KPartition
* partition
, bool checkOnly
, disk_job_id job
)
128 KFileSystem::Resize(KPartition
* partition
, off_t size
, disk_job_id job
)
137 KFileSystem::Move(KPartition
* partition
, off_t offset
, disk_job_id job
)
146 KFileSystem::SetContentName(KPartition
* partition
, const char* name
,
150 if (!partition
|| !fModule
)
152 if (!fModule
->set_content_name
)
153 return B_NOT_SUPPORTED
;
155 // open partition device
157 status_t result
= partition
->Open(O_RDWR
, &fd
);
161 // let the module do its job
162 result
= fModule
->set_content_name(fd
, partition
->ID(), name
, job
);
164 // cleanup and return
170 // SetContentParameters
172 KFileSystem::SetContentParameters(KPartition
* partition
,
173 const char* parameters
, disk_job_id job
)
176 if (!partition
|| !fModule
)
178 if (!fModule
->set_content_parameters
)
179 return B_NOT_SUPPORTED
;
181 // open partition device
183 status_t result
= partition
->Open(O_RDWR
, &fd
);
187 // let the module do its job
188 result
= fModule
->set_content_parameters(fd
, partition
->ID(), parameters
,
191 // cleanup and return
199 KFileSystem::Initialize(KPartition
* partition
, const char* name
,
200 const char* parameters
, disk_job_id job
)
203 if (!partition
|| !fModule
)
205 if (!fModule
->initialize
)
206 return B_NOT_SUPPORTED
;
208 // open partition device
210 status_t result
= partition
->Open(O_RDWR
, &fd
);
214 // let the module do its job
215 result
= fModule
->initialize(fd
, partition
->ID(), name
, parameters
,
216 partition
->Size(), job
);
218 // cleanup and return
225 KFileSystem::Uninitialize(KPartition
* partition
, disk_job_id job
)
228 if (partition
== NULL
|| fModule
== NULL
)
230 if (fModule
->uninitialize
== NULL
)
231 return B_NOT_SUPPORTED
;
233 // open partition device
235 status_t result
= partition
->Open(O_RDWR
, &fd
);
239 // let the module do its job
240 result
= fModule
->uninitialize(fd
, partition
->ID(), partition
->Size(),
241 partition
->BlockSize(), job
);
243 // cleanup and return
251 KFileSystem::LoadModule()
253 if (fModule
) // shouldn't happen
256 return get_module(Name(), (module_info
**)&fModule
);
262 KFileSystem::UnloadModule()
265 put_module(fModule
->info
.name
);