libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / system / kernel / disk_device_manager / KFileSystem.cpp
blob90f0018a7a30e288601d1a3446a47b2eaa877685
1 /*
2 * Copyright 2003-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold, ingo_weinhold@gmx.de
7 */
9 #include "KFileSystem.h"
11 #include <fcntl.h>
12 #include <stdlib.h>
13 #include <unistd.h>
15 #include <fs_interface.h>
17 #include "ddm_modules.h"
18 #include "KDiskDeviceUtils.h"
19 #include "KPartition.h"
22 // constructor
23 KFileSystem::KFileSystem(const char *name)
24 : KDiskSystem(name),
25 fModule(NULL)
30 // destructor
31 KFileSystem::~KFileSystem()
36 // Init
37 status_t
38 KFileSystem::Init()
40 status_t error = KDiskSystem::Init();
41 if (error != B_OK)
42 return error;
43 error = Load();
44 if (error != B_OK)
45 return error;
46 error = SetShortName(fModule->short_name);
47 if (error == B_OK)
48 error = SetPrettyName(fModule->pretty_name);
50 SetFlags(fModule->flags | B_DISK_SYSTEM_IS_FILE_SYSTEM);
51 Unload();
52 return error;
56 // Identify
57 float
58 KFileSystem::Identify(KPartition *partition, void **cookie)
60 if (!partition || !cookie || !fModule || !fModule->identify_partition)
61 return -1;
62 int fd = -1;
63 if (partition->Open(O_RDONLY, &fd) != B_OK)
64 return -1;
65 float result = fModule->identify_partition(fd, partition->PartitionData(),
66 cookie);
67 close(fd);
68 return result;
72 // Scan
73 status_t
74 KFileSystem::Scan(KPartition *partition, void *cookie)
76 if (!partition || !fModule || !fModule->scan_partition)
77 return B_ERROR;
78 int fd = -1;
79 status_t result = partition->Open(O_RDONLY, &fd);
80 if (result != B_OK)
81 return result;
82 result = fModule->scan_partition(fd, partition->PartitionData(), cookie);
83 close(fd);
84 return result;
88 // FreeIdentifyCookie
89 void
90 KFileSystem::FreeIdentifyCookie(KPartition *partition, void *cookie)
92 if (!partition || !fModule || !fModule->free_identify_partition_cookie)
93 return;
94 fModule->free_identify_partition_cookie(partition->PartitionData(), cookie);
98 // FreeContentCookie
99 void
100 KFileSystem::FreeContentCookie(KPartition *partition)
102 if (!partition || !fModule || !fModule->free_partition_content_cookie)
103 return;
104 fModule->free_partition_content_cookie(partition->PartitionData());
108 // Defragment
109 status_t
110 KFileSystem::Defragment(KPartition* partition, disk_job_id job)
112 // to be implemented
113 return B_ERROR;
117 // Repair
118 status_t
119 KFileSystem::Repair(KPartition* partition, bool checkOnly, disk_job_id job)
121 // to be implemented
122 return B_ERROR;
126 // Resize
127 status_t
128 KFileSystem::Resize(KPartition* partition, off_t size, disk_job_id job)
130 // to be implemented
131 return B_ERROR;
135 // Move
136 status_t
137 KFileSystem::Move(KPartition* partition, off_t offset, disk_job_id job)
139 // to be implemented
140 return B_ERROR;
144 // SetContentName
145 status_t
146 KFileSystem::SetContentName(KPartition* partition, const char* name,
147 disk_job_id job)
149 // check parameters
150 if (!partition || !fModule)
151 return B_BAD_VALUE;
152 if (!fModule->set_content_name)
153 return B_NOT_SUPPORTED;
155 // open partition device
156 int fd = -1;
157 status_t result = partition->Open(O_RDWR, &fd);
158 if (result != B_OK)
159 return result;
161 // let the module do its job
162 result = fModule->set_content_name(fd, partition->ID(), name, job);
164 // cleanup and return
165 close(fd);
166 return result;
170 // SetContentParameters
171 status_t
172 KFileSystem::SetContentParameters(KPartition* partition,
173 const char* parameters, disk_job_id job)
175 // check parameters
176 if (!partition || !fModule)
177 return B_BAD_VALUE;
178 if (!fModule->set_content_parameters)
179 return B_NOT_SUPPORTED;
181 // open partition device
182 int fd = -1;
183 status_t result = partition->Open(O_RDWR, &fd);
184 if (result != B_OK)
185 return result;
187 // let the module do its job
188 result = fModule->set_content_parameters(fd, partition->ID(), parameters,
189 job);
191 // cleanup and return
192 close(fd);
193 return result;
197 // Initialize
198 status_t
199 KFileSystem::Initialize(KPartition* partition, const char* name,
200 const char* parameters, disk_job_id job)
202 // check parameters
203 if (!partition || !fModule)
204 return B_BAD_VALUE;
205 if (!fModule->initialize)
206 return B_NOT_SUPPORTED;
208 // open partition device
209 int fd = -1;
210 status_t result = partition->Open(O_RDWR, &fd);
211 if (result != B_OK)
212 return result;
214 // let the module do its job
215 result = fModule->initialize(fd, partition->ID(), name, parameters,
216 partition->Size(), job);
218 // cleanup and return
219 close(fd);
220 return result;
224 status_t
225 KFileSystem::Uninitialize(KPartition* partition, disk_job_id job)
227 // check parameters
228 if (partition == NULL || fModule == NULL)
229 return B_BAD_VALUE;
230 if (fModule->uninitialize == NULL)
231 return B_NOT_SUPPORTED;
233 // open partition device
234 int fd = -1;
235 status_t result = partition->Open(O_RDWR, &fd);
236 if (result != B_OK)
237 return result;
239 // let the module do its job
240 result = fModule->uninitialize(fd, partition->ID(), partition->Size(),
241 partition->BlockSize(), job);
243 // cleanup and return
244 close(fd);
245 return result;
249 // LoadModule
250 status_t
251 KFileSystem::LoadModule()
253 if (fModule) // shouldn't happen
254 return B_OK;
256 return get_module(Name(), (module_info **)&fModule);
260 // UnloadModule
261 void
262 KFileSystem::UnloadModule()
264 if (fModule) {
265 put_module(fModule->info.name);
266 fModule = NULL;