22#ifdef RT_USING_PAGECACHE
26#define DBG_TAG "DFS.fs"
27#define DBG_LVL DBG_INFO
41 for (type = &file_systems; *type; type = &(*type)->
next)
43 if (strcmp((*type)->fs_ops->name, name) == 0)
83 for (type = &file_systems; *type; type = &(*type)->
next)
85 if (strcmp((*type)->fs_ops->name, fs->
fs_ops->
name) == 0)
87 *type = (*type)->
next;
92 if (!*type) ret = -EINVAL;
98#define REMNT_UNSUPP_FLAGS (~(MS_REMOUNT | MS_RMT_MASK))
117 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"mnt = dfs_mnt_lookup(%s)",
fullpath);
127 struct stat buf = {0};
128 if (
dfs_file_stat(fullpath, &buf) == 0 && S_ISBLK(buf.st_mode))
154 const char *filesystemtype,
155 unsigned long rwflag,
176 rt_set_errno(ENODEV);
182 DLOG(note,
"mnt",
"mount %s(%s) on path: %s", device_name, filesystemtype, fullpath);
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))
195 LOG_D(
"no mnt found @ mount point %s, should be root.", fullpath);
196 DLOG(msg,
"mnt",
"dfs", DLOG_MSG_RET,
"no mnt");
201 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"mnt_parent = dfs_mnt_create(path)");
205 DLOG(msg,
"mnt",
"dfs", DLOG_MSG_RET,
"return mnt, ref_count=1");
208 mnt_parent->
dev_id = dev_id;
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);
215 DLOG(msg, type->
fs_ops->
name,
"dfs", DLOG_MSG_RET,
"mount OK, ret root_dentry");
217 mnt_child = mnt_parent;
220 DLOG(note_right,
"mnt",
"mount sucessfully");
221 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_insert(, mnt_child)");
225 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_unref(mnt_parent)");
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)");
248 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_destroy(mnt_parent), no mount method");
257 LOG_E(
"create a mnt point failed.");
258 rt_set_errno(ENOMEM);
262 else if (mnt_parent && (strcmp(mnt_parent->
fullpath, fullpath) != 0))
264 DLOG(msg,
"dfs",
"dentry", DLOG_MSG,
"mntpoint_dentry = dfs_dentry_lookup(mnt_parent, %s, 0)", fullpath);
268 DLOG(msg,
"dentry",
"dfs", DLOG_MSG_RET,
"dentry exist");
269 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"mnt_child = dfs_mnt_create(path)");
273 LOG_D(
"create mnt point %p", mnt_child);
275 mnt_child->fs_ops = type->
fs_ops;
276 mnt_child->dev_id = dev_id;
278 if (mnt_child->fs_ops->mount)
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);
286 LOG_D(
"mount %s sucessfully", fullpath);
287 DLOG(msg, mnt_child->fs_ops->name,
"dfs", DLOG_MSG_RET,
"mount OK");
289 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_insert(mnt_parent, mnt_child)");
293 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_unref(mnt_child)");
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");
315 LOG_E(
"create a mnt point failed.");
316 rt_set_errno(ENOMEM);
323 LOG_W(
"no mount point (%s) in file system: %s", fullpath, mnt_parent->
fullpath);
324 rt_set_errno(ENOTDIR);
330 LOG_E(
"mount point (%s) already mounted!", fullpath);
331 rt_set_errno(EEXIST);
337 LOG_E(
"No device found for this file system.");
338 rt_set_errno(ENODEV);
356 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"mnt = dfs_mnt_lookup(%s)",
fullpath);
367#ifdef RT_USING_PAGECACHE
368 dfs_pcache_unmount(mnt);
371 DLOG(msg,
"dfs",
"mnt", DLOG_MSG,
"dfs_mnt_destroy(mnt)");
376 LOG_I(
"the file system is busy!");
388 LOG_I(
"no filesystem found.");
394 rt_set_errno(-ENOTDIR);
418int dfs_mkfs(
const char *fs_name,
const char *device_name)
424 type = *_find_filesystem(fs_name);
427 rt_kprintf(
"no file system: %s found!\n", fs_name);
435 if (device_name != NULL)
440 rt_set_errno(-ENODEV);
441 rt_kprintf(
"Device (%s) was not found", device_name);
454#ifdef RT_USING_PAGECACHE
462 dfs_pcache_unmount(mnt);
483 DLOG(msg,
"dfs_file",
"mnt", DLOG_MSG,
"dfs_mnt_lookup(%s)",
fullpath);
508 const char *path = NULL;
526#define DPT_ADDRESS 0x1be
527#define DPT_ITEM_SIZE 16
538 if ((*dpt != 0x80) && (*dpt != 0x00))
549 part->
offset = *(dpt + 8) | *(dpt + 9) << 8 | *(dpt + 10) << 16 | *(dpt + 11) << 24;
550 part->
size = *(dpt + 12) | *(dpt + 13) << 8 | *(dpt + 14) << 16 | *(dpt + 15) << 24;
552 rt_kprintf(
"found part[%d], begin: %ld, size: ",
553 pindex, part->
offset * 512);
554 if ((part->
size >> 11) == 0)
558 unsigned int part_size;
559 part_size = part->
size >> 11;
560 if ((part_size >> 10) == 0)
561 rt_kprintf(
"%d.%ld%s", part_size, (part->
size >> 1) & 0x3FF,
"MB\n");
563 rt_kprintf(
"%d.%d%s", part_size >> 10, part_size & 0x3FF,
"GB\n");
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_file_stat(const char *path, struct stat *buf)
int dfs_statfs(const char *path, struct statfs *buffer)
int dfs_unregister(struct dfs_filesystem_type *fs)
int dfs_mkfs(const char *fs_name, const char *device_name)
#define REMNT_UNSUPP_FLAGS
int dfs_is_mounted(struct dfs_mnt *mnt)
int dfs_mount(const char *device_name, const char *path, const char *filesystemtype, unsigned long rwflag, const void *data)
const char * dfs_filesystem_get_mounted_path(struct rt_device *device)
int dfs_unmount(const char *specialfile)
int dfs_umount(const char *specialfile, int flags)
int dfs_register(struct dfs_filesystem_type *fs)
int dfs_filesystem_get_partition(struct dfs_partition *part, uint8_t *buf, uint32_t pindex)
struct dfs_filesystem_type * dfs_filesystems(void)
int dfs_remount(const char *path, rt_ubase_t flags, void *data)
int dfs_mnt_insert(struct dfs_mnt *mnt, struct dfs_mnt *child)
int dfs_mnt_setflags(struct dfs_mnt *mnt, int flags)
struct dfs_mnt * dfs_mnt_dev_lookup(rt_device_t dev_id)
int dfs_mnt_unref(struct dfs_mnt *mnt)
int dfs_mnt_destroy(struct dfs_mnt *mnt)
struct dfs_mnt * dfs_mnt_lookup(const char *fullpath)
struct dfs_mnt * dfs_mnt_create(const char *path)
char * dfs_normalize_path(const char *directory, const char *filename)
rt_device_t rt_device_find(const char *name)
struct rt_device * rt_device_t
int stat(const char *file, struct stat *buf)
int statfs(const char *path, struct statfs *buf)
rt_inline int rt_list_isempty(const rt_list_t *l)
tests whether a list is empty
rt_weak void rt_free(void *ptr)
This function will release the previously allocated memory block by rt_malloc. The released memory bl...
#define rt_atomic_load(ptr)
struct rt_list_node rt_list_t
int(* mkfs)(rt_device_t devid, const char *fs_name)
int(* statfs)(struct dfs_mnt *mnt, struct statfs *buf)
int(* mount)(struct dfs_mnt *mnt, unsigned long rwflag, const void *data)
const struct dfs_filesystem_ops * fs_ops
struct dfs_filesystem_type * next
const struct dfs_filesystem_ops * fs_ops