157{
158 int ret = RT_EOK;
164
165 if (type)
166 {
168 if (!fullpath)
169 {
170 rt_set_errno(EPERM);
171 ret = -1;
172 }
173 }
174 else
175 {
176 rt_set_errno(ENODEV);
177 ret = -1;
178 }
179
180 if (fullpath)
181 {
182 DLOG(note,
"mnt",
"mount %s(%s) on path: %s", device_name, filesystemtype, fullpath);
183
184
186
189 {
190 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"mnt_parent = dfs_mnt_lookup(%s)", fullpath);
192 if ((!mnt_parent && (strcmp(fullpath, "/") == 0 || strcmp(fullpath, "/dev") == 0))
193 || (mnt_parent && strcmp(fullpath,
"/") == 0 && strcmp(mnt_parent->
fullpath, fullpath) != 0))
194 {
195 LOG_D(
"no mnt found @ mount point %s, should be root.", fullpath);
196 DLOG(msg,
"mnt",
"dfs", DLOG_MSG_RET,
"no mnt");
197
198
199
200
201 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"mnt_parent = dfs_mnt_create(path)");
203 if (mnt_parent)
204 {
205 DLOG(msg,
"mnt",
"dfs", DLOG_MSG_RET,
"return mnt, ref_count=1");
206
208 mnt_parent->
dev_id = dev_id;
210 {
211 DLOG(msg,
"dfs", type->
fs_ops->
name, DLOG_MSG,
"fs_ops->mount(mnt_parent, rwflag, data)");
212 ret = mnt_parent->
fs_ops->
mount(mnt_parent, rwflag, data);
213 if (ret == RT_EOK)
214 {
215 DLOG(msg, type->
fs_ops->
name,
"dfs", DLOG_MSG_RET,
"mount OK, ret root_dentry");
216
217 mnt_child = mnt_parent;
219
220 DLOG(note_right,
"mnt",
"mount sucessfully");
221 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_insert(, mnt_child)");
223
224
225 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_unref(mnt_parent)");
227
228
229
230
231
232
233
234 }
235 else
236 {
237 LOG_W(
"mount %s failed with file system type: %s", fullpath, type->
fs_ops->
name);
238 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_destroy(mnt_parent)");
241 rt_set_errno(EPERM);
242 ret = -1;
243 }
244 }
245 else
246 {
248 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_destroy(mnt_parent), no mount method");
251 rt_set_errno(EIO);
252 ret = -1;
253 }
254 }
255 else
256 {
257 LOG_E(
"create a mnt point failed.");
258 rt_set_errno(ENOMEM);
259 ret = -1;
260 }
261 }
262 else if (mnt_parent && (strcmp(mnt_parent->
fullpath, fullpath) != 0))
263 {
264 DLOG(msg,
"dfs",
"dentry", DLOG_MSG,
"mntpoint_dentry = dfs_dentry_lookup(mnt_parent, %s, 0)", fullpath);
266 if (mntpoint_dentry)
267 {
268 DLOG(msg,
"dentry",
"dfs", DLOG_MSG_RET,
"dentry exist");
269 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"mnt_child = dfs_mnt_create(path)");
271 if (mnt_child)
272 {
273 LOG_D(
"create mnt point %p", mnt_child);
274
275 mnt_child->fs_ops = type->
fs_ops;
276 mnt_child->dev_id = dev_id;
277
278 if (mnt_child->fs_ops->mount)
279 {
280 DLOG(msg,
"dfs", type->
fs_ops->
name, DLOG_MSG,
"root_dentry = fs_ops->mount(mnt_child, rwflag, data)");
281 ret = mnt_child->fs_ops->mount(mnt_child, rwflag, data);
282 if (ret == RT_EOK)
283 {
285
286 LOG_D(
"mount %s sucessfully", fullpath);
287 DLOG(msg, mnt_child->fs_ops->name,
"dfs", DLOG_MSG_RET,
"mount OK");
288
289 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_insert(mnt_parent, mnt_child)");
291
292
293 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_unref(mnt_child)");
295 }
296 else
297 {
298 LOG_W(
"mount %s failed with file system type: %s", fullpath, type->
fs_ops->
name);
299 DLOG(msg, mnt_child->fs_ops->name,
"dfs", DLOG_MSG_RET,
"mount failed");
301 rt_set_errno(EPERM);
302 ret = -1;
303 }
304 }
305 else
306 {
309 rt_set_errno(EIO);
310 ret = -1;
311 }
312 }
313 else
314 {
315 LOG_E(
"create a mnt point failed.");
316 rt_set_errno(ENOMEM);
317 ret = -1;
318 }
320 }
321 else
322 {
323 LOG_W(
"no mount point (%s) in file system: %s", fullpath, mnt_parent->
fullpath);
324 rt_set_errno(ENOTDIR);
325 ret = -1;
326 }
327 }
328 else
329 {
330 LOG_E(
"mount point (%s) already mounted!", fullpath);
331 rt_set_errno(EEXIST);
332 ret = -1;
333 }
334 }
335 else
336 {
337 LOG_E(
"No device found for this file system.");
338 rt_set_errno(ENODEV);
339 ret = -1;
340 }
342 }
343
344 return ret;
345}
struct dfs_dentry * dfs_dentry_lookup(struct dfs_mnt *mnt, const char *path, uint32_t flags)
struct dfs_dentry * dfs_dentry_unref(struct dfs_dentry *dentry)
int dfs_mnt_insert(struct dfs_mnt *mnt, struct dfs_mnt *child)
int dfs_mnt_unref(struct dfs_mnt *mnt)
int dfs_mnt_destroy(struct dfs_mnt *mnt)
struct dfs_mnt * dfs_mnt_create(const char *path)
rt_device_t rt_device_find(const char *name)
struct rt_device * rt_device_t
rt_weak void rt_free(void *ptr)
This function will release the previously allocated memory block by rt_malloc. The released memory bl...
int(* mount)(struct dfs_mnt *mnt, unsigned long rwflag, const void *data)
const struct dfs_filesystem_ops * fs_ops