From abe3b03c6678be3cff16629623aabc671661b94e Mon Sep 17 00:00:00 2001 From: Aphlita Date: Thu, 30 Apr 2026 20:55:47 +0800 Subject: [PATCH 1/3] dfs/romfs: validate ioctl args for RT_FIOGETADDR --- components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c | 5 +++++ components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c b/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c index b84c0498eb2..f50f0c74d62 100644 --- a/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c @@ -44,6 +44,11 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) { case RT_FIOGETADDR: { + if (args == RT_NULL) + { + ret = -RT_EINVAL; + break; + } *(rt_ubase_t*)args = (rt_ubase_t)dirent->data; break; } diff --git a/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c b/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c index 6350ad75f53..772e2218ae8 100644 --- a/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c @@ -64,6 +64,11 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) { case RT_FIOGETADDR: { + if (args == RT_NULL) + { + ret = -RT_EINVAL; + break; + } *(rt_ubase_t*)args = (rt_ubase_t)dirent->data; break; } From 48b96aebf79f2d554040dc083d7f5a9a8d173009 Mon Sep 17 00:00:00 2001 From: Aphlita Date: Thu, 30 Apr 2026 13:08:09 +0000 Subject: [PATCH 2/3] style: format code with clang-format [skip ci] --- .../dfs/dfs_v1/filesystems/romfs/dfs_romfs.c | 103 +++++++++++------- .../dfs/dfs_v2/filesystems/romfs/dfs_romfs.c | 92 ++++++++-------- 2 files changed, 106 insertions(+), 89 deletions(-) diff --git a/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c b/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c index f50f0c74d62..d1bd8e1e432 100644 --- a/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c @@ -43,19 +43,19 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) switch (cmd) { case RT_FIOGETADDR: + { + if (args == RT_NULL) { - if (args == RT_NULL) - { - ret = -RT_EINVAL; - break; - } - *(rt_ubase_t*)args = (rt_ubase_t)dirent->data; + ret = -RT_EINVAL; break; } + *(rt_ubase_t *)args = (rt_ubase_t)dirent->data; + break; + } case RT_FIOFTRUNCATE: - { - break; - } + { + break; + } default: ret = -RT_EINVAL; break; @@ -65,8 +65,7 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) rt_inline int check_dirent(struct romfs_dirent *dirent) { - if ((dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) - || dirent->size == ~0U) + if ((dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) || dirent->size == ~0U) return -1; return 0; } @@ -96,31 +95,31 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch subpath_end = path; /* skip /// */ while (*subpath_end && *subpath_end == '/') - subpath_end ++; + subpath_end++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) - subpath_end ++; + subpath_end++; while (dirent != NULL) { found = 0; /* search in folder */ - for (index = 0; index < dirent_size; index ++) + for (index = 0; index < dirent_size; index++) { if (check_dirent(&dirent[index]) != 0) return NULL; - if (rt_strlen(dirent[index].name) == (rt_size_t)(subpath_end - subpath) && - rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) + if (rt_strlen(dirent[index].name) == (rt_size_t)(subpath_end - subpath) && + rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) { dirent_size = dirent[index].size; /* skip /// */ while (*subpath_end && *subpath_end == '/') - subpath_end ++; + subpath_end++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) - subpath_end ++; + subpath_end++; if (!(*subpath)) { @@ -215,8 +214,7 @@ int dfs_romfs_open(struct dfs_file *file) RT_ASSERT(file->vnode->ref_count > 0); if (file->vnode->ref_count > 1) { - if (file->vnode->type == FT_DIRECTORY - && !(file->flags & O_DIRECTORY)) + if (file->vnode->type == FT_DIRECTORY && !(file->flags & O_DIRECTORY)) { return -ENOENT; } @@ -345,14 +343,13 @@ int dfs_romfs_getdents(struct dfs_file *file, struct dirent *dirp, uint32_t coun rt_strncpy(d->d_name, name, DIRENT_NAME_MAX); /* move to next position */ - ++ file->pos; + ++file->pos; } return index * sizeof(struct dirent); } -static const struct dfs_file_ops _rom_fops = -{ +static const struct dfs_file_ops _rom_fops = { dfs_romfs_open, dfs_romfs_close, dfs_romfs_ioctl, @@ -363,8 +360,7 @@ static const struct dfs_file_ops _rom_fops = dfs_romfs_getdents, NULL, }; -static const struct dfs_filesystem_ops _romfs = -{ +static const struct dfs_filesystem_ops _romfs = { "rom", DFS_FS_FLAG_DEFAULT, &_rom_fops, @@ -388,29 +384,56 @@ int dfs_romfs_init(void) INIT_COMPONENT_EXPORT(dfs_romfs_init); #ifndef RT_USING_DFS_ROMFS_USER_ROOT -static const unsigned char _dummy_dummy_txt[] = -{ - 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a, +static const unsigned char _dummy_dummy_txt[] = { + 0x74, + 0x68, + 0x69, + 0x73, + 0x20, + 0x69, + 0x73, + 0x20, + 0x61, + 0x20, + 0x66, + 0x69, + 0x6c, + 0x65, + 0x21, + 0x0d, + 0x0a, }; -static const struct romfs_dirent _dummy[] = -{ - {ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt)}, +static const struct romfs_dirent _dummy[] = { + { ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt) }, }; -static const unsigned char _dummy_txt[] = -{ - 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a, +static const unsigned char _dummy_txt[] = { + 0x74, + 0x68, + 0x69, + 0x73, + 0x20, + 0x69, + 0x73, + 0x20, + 0x61, + 0x20, + 0x66, + 0x69, + 0x6c, + 0x65, + 0x21, + 0x0d, + 0x0a, }; -rt_weak const struct romfs_dirent _root_dirent[] = -{ - {ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy) / sizeof(_dummy[0])}, - {ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt)}, +rt_weak const struct romfs_dirent _root_dirent[] = { + { ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy) / sizeof(_dummy[0]) }, + { ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt) }, }; -rt_weak const struct romfs_dirent romfs_root = -{ +rt_weak const struct romfs_dirent romfs_root = { ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_root_dirent, sizeof(_root_dirent) / sizeof(_root_dirent[0]) }; #endif diff --git a/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c b/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c index 772e2218ae8..a96c37a298e 100644 --- a/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c @@ -22,16 +22,15 @@ static const struct dfs_file_ops _rom_fops; -static const mode_t romfs_modemap[] = -{ - S_IFREG | 0644, /* regular file */ - S_IFDIR | 0644, /* directory */ +static const mode_t romfs_modemap[] = { + S_IFREG | 0644, /* regular file */ + S_IFDIR | 0644, /* directory */ 0, /* hard link */ - S_IFLNK | 0777, /* symlink */ - S_IFBLK | 0600, /* blockdev */ - S_IFCHR | 0600, /* chardev */ + S_IFLNK | 0777, /* symlink */ + S_IFBLK | 0600, /* blockdev */ + S_IFCHR | 0600, /* chardev */ S_IFSOCK | 0644, /* socket */ - S_IFIFO | 0644 /* FIFO */ + S_IFIFO | 0644 /* FIFO */ }; static int dfs_romfs_mount(struct dfs_mnt *mnt, unsigned long rwflag, const void *data) @@ -63,19 +62,19 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) switch (cmd) { case RT_FIOGETADDR: + { + if (args == RT_NULL) { - if (args == RT_NULL) - { - ret = -RT_EINVAL; - break; - } - *(rt_ubase_t*)args = (rt_ubase_t)dirent->data; + ret = -RT_EINVAL; break; } + *(rt_ubase_t *)args = (rt_ubase_t)dirent->data; + break; + } case RT_FIOFTRUNCATE: - { - break; - } + { + break; + } default: ret = -RT_EINVAL; break; @@ -85,9 +84,7 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) rt_inline int check_dirent(struct romfs_dirent *dirent) { - if (dirent == NULL - ||(dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) - || dirent->size == ~0) + if (dirent == NULL || (dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) || dirent->size == ~0) return -1; return 0; } @@ -117,31 +114,31 @@ struct romfs_dirent *__dfs_romfs_lookup(struct romfs_dirent *root_dirent, const subpath_end = path; /* skip /// */ while (*subpath_end && *subpath_end == '/') - subpath_end ++; + subpath_end++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) - subpath_end ++; + subpath_end++; while (dirent != NULL) { found = 0; /* search in folder */ - for (index = 0; index < dirent_size; index ++) + for (index = 0; index < dirent_size; index++) { if (check_dirent(&dirent[index]) != 0) return NULL; if (rt_strlen(dirent[index].name) == (subpath_end - subpath) && - rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) + rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) { dirent_size = dirent[index].size; /* skip /// */ while (*subpath_end && *subpath_end == '/') - subpath_end ++; + subpath_end++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) - subpath_end ++; + subpath_end++; if (!(*subpath)) { @@ -172,7 +169,7 @@ struct romfs_dirent *__dfs_romfs_lookup(struct romfs_dirent *root_dirent, const return NULL; } -static struct dfs_vnode *dfs_romfs_lookup (struct dfs_dentry *dentry) +static struct dfs_vnode *dfs_romfs_lookup(struct dfs_dentry *dentry) { rt_size_t size; struct dfs_vnode *vnode = RT_NULL; @@ -360,37 +357,34 @@ static int dfs_romfs_getdents(struct dfs_file *file, struct dirent *dirp, uint32 rt_strncpy(d->d_name, name, DIRENT_NAME_MAX); /* move to next position */ - ++ file->fpos; + ++file->fpos; } return index * sizeof(struct dirent); } -static const struct dfs_file_ops _rom_fops = -{ - .open = dfs_romfs_open, - .close = dfs_romfs_close, - .ioctl = dfs_romfs_ioctl, - .lseek = generic_dfs_lseek, - .read = dfs_romfs_read, - .getdents = dfs_romfs_getdents, +static const struct dfs_file_ops _rom_fops = { + .open = dfs_romfs_open, + .close = dfs_romfs_close, + .ioctl = dfs_romfs_ioctl, + .lseek = generic_dfs_lseek, + .read = dfs_romfs_read, + .getdents = dfs_romfs_getdents, }; -static const struct dfs_filesystem_ops _romfs_ops = -{ - .name ="rom", - .flags = 0, - .default_fops = &_rom_fops, - .mount = dfs_romfs_mount, - .umount = dfs_romfs_umount, - .stat = dfs_romfs_stat, - .lookup = dfs_romfs_lookup, - .free_vnode = dfs_romfs_free_vnode +static const struct dfs_filesystem_ops _romfs_ops = { + .name = "rom", + .flags = 0, + .default_fops = &_rom_fops, + .mount = dfs_romfs_mount, + .umount = dfs_romfs_umount, + .stat = dfs_romfs_stat, + .lookup = dfs_romfs_lookup, + .free_vnode = dfs_romfs_free_vnode }; -static struct dfs_filesystem_type _romfs = -{ - .fs_ops = &_romfs_ops, +static struct dfs_filesystem_type _romfs = { + .fs_ops = &_romfs_ops, }; int dfs_romfs_init(void) From 56b406c95a0778ad01378b02aa6ac49abe757722 Mon Sep 17 00:00:00 2001 From: Aphlita Date: Thu, 30 Apr 2026 21:40:50 +0800 Subject: [PATCH 3/3] Revert "style: format code with clang-format [skip ci]" This reverts commit 48b96aebf79f2d554040dc083d7f5a9a8d173009. --- .../dfs/dfs_v1/filesystems/romfs/dfs_romfs.c | 103 +++++++----------- .../dfs/dfs_v2/filesystems/romfs/dfs_romfs.c | 92 ++++++++-------- 2 files changed, 89 insertions(+), 106 deletions(-) diff --git a/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c b/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c index d1bd8e1e432..f50f0c74d62 100644 --- a/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c @@ -43,19 +43,19 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) switch (cmd) { case RT_FIOGETADDR: - { - if (args == RT_NULL) { - ret = -RT_EINVAL; + if (args == RT_NULL) + { + ret = -RT_EINVAL; + break; + } + *(rt_ubase_t*)args = (rt_ubase_t)dirent->data; break; } - *(rt_ubase_t *)args = (rt_ubase_t)dirent->data; - break; - } case RT_FIOFTRUNCATE: - { - break; - } + { + break; + } default: ret = -RT_EINVAL; break; @@ -65,7 +65,8 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) rt_inline int check_dirent(struct romfs_dirent *dirent) { - if ((dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) || dirent->size == ~0U) + if ((dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) + || dirent->size == ~0U) return -1; return 0; } @@ -95,31 +96,31 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch subpath_end = path; /* skip /// */ while (*subpath_end && *subpath_end == '/') - subpath_end++; + subpath_end ++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) - subpath_end++; + subpath_end ++; while (dirent != NULL) { found = 0; /* search in folder */ - for (index = 0; index < dirent_size; index++) + for (index = 0; index < dirent_size; index ++) { if (check_dirent(&dirent[index]) != 0) return NULL; - if (rt_strlen(dirent[index].name) == (rt_size_t)(subpath_end - subpath) && - rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) + if (rt_strlen(dirent[index].name) == (rt_size_t)(subpath_end - subpath) && + rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) { dirent_size = dirent[index].size; /* skip /// */ while (*subpath_end && *subpath_end == '/') - subpath_end++; + subpath_end ++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) - subpath_end++; + subpath_end ++; if (!(*subpath)) { @@ -214,7 +215,8 @@ int dfs_romfs_open(struct dfs_file *file) RT_ASSERT(file->vnode->ref_count > 0); if (file->vnode->ref_count > 1) { - if (file->vnode->type == FT_DIRECTORY && !(file->flags & O_DIRECTORY)) + if (file->vnode->type == FT_DIRECTORY + && !(file->flags & O_DIRECTORY)) { return -ENOENT; } @@ -343,13 +345,14 @@ int dfs_romfs_getdents(struct dfs_file *file, struct dirent *dirp, uint32_t coun rt_strncpy(d->d_name, name, DIRENT_NAME_MAX); /* move to next position */ - ++file->pos; + ++ file->pos; } return index * sizeof(struct dirent); } -static const struct dfs_file_ops _rom_fops = { +static const struct dfs_file_ops _rom_fops = +{ dfs_romfs_open, dfs_romfs_close, dfs_romfs_ioctl, @@ -360,7 +363,8 @@ static const struct dfs_file_ops _rom_fops = { dfs_romfs_getdents, NULL, }; -static const struct dfs_filesystem_ops _romfs = { +static const struct dfs_filesystem_ops _romfs = +{ "rom", DFS_FS_FLAG_DEFAULT, &_rom_fops, @@ -384,56 +388,29 @@ int dfs_romfs_init(void) INIT_COMPONENT_EXPORT(dfs_romfs_init); #ifndef RT_USING_DFS_ROMFS_USER_ROOT -static const unsigned char _dummy_dummy_txt[] = { - 0x74, - 0x68, - 0x69, - 0x73, - 0x20, - 0x69, - 0x73, - 0x20, - 0x61, - 0x20, - 0x66, - 0x69, - 0x6c, - 0x65, - 0x21, - 0x0d, - 0x0a, +static const unsigned char _dummy_dummy_txt[] = +{ + 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a, }; -static const struct romfs_dirent _dummy[] = { - { ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt) }, +static const struct romfs_dirent _dummy[] = +{ + {ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt)}, }; -static const unsigned char _dummy_txt[] = { - 0x74, - 0x68, - 0x69, - 0x73, - 0x20, - 0x69, - 0x73, - 0x20, - 0x61, - 0x20, - 0x66, - 0x69, - 0x6c, - 0x65, - 0x21, - 0x0d, - 0x0a, +static const unsigned char _dummy_txt[] = +{ + 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x21, 0x0d, 0x0a, }; -rt_weak const struct romfs_dirent _root_dirent[] = { - { ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy) / sizeof(_dummy[0]) }, - { ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt) }, +rt_weak const struct romfs_dirent _root_dirent[] = +{ + {ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy) / sizeof(_dummy[0])}, + {ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt)}, }; -rt_weak const struct romfs_dirent romfs_root = { +rt_weak const struct romfs_dirent romfs_root = +{ ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_root_dirent, sizeof(_root_dirent) / sizeof(_root_dirent[0]) }; #endif diff --git a/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c b/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c index a96c37a298e..772e2218ae8 100644 --- a/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/dfs_v2/filesystems/romfs/dfs_romfs.c @@ -22,15 +22,16 @@ static const struct dfs_file_ops _rom_fops; -static const mode_t romfs_modemap[] = { - S_IFREG | 0644, /* regular file */ - S_IFDIR | 0644, /* directory */ +static const mode_t romfs_modemap[] = +{ + S_IFREG | 0644, /* regular file */ + S_IFDIR | 0644, /* directory */ 0, /* hard link */ - S_IFLNK | 0777, /* symlink */ - S_IFBLK | 0600, /* blockdev */ - S_IFCHR | 0600, /* chardev */ + S_IFLNK | 0777, /* symlink */ + S_IFBLK | 0600, /* blockdev */ + S_IFCHR | 0600, /* chardev */ S_IFSOCK | 0644, /* socket */ - S_IFIFO | 0644 /* FIFO */ + S_IFIFO | 0644 /* FIFO */ }; static int dfs_romfs_mount(struct dfs_mnt *mnt, unsigned long rwflag, const void *data) @@ -62,19 +63,19 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) switch (cmd) { case RT_FIOGETADDR: - { - if (args == RT_NULL) { - ret = -RT_EINVAL; + if (args == RT_NULL) + { + ret = -RT_EINVAL; + break; + } + *(rt_ubase_t*)args = (rt_ubase_t)dirent->data; break; } - *(rt_ubase_t *)args = (rt_ubase_t)dirent->data; - break; - } case RT_FIOFTRUNCATE: - { - break; - } + { + break; + } default: ret = -RT_EINVAL; break; @@ -84,7 +85,9 @@ int dfs_romfs_ioctl(struct dfs_file *file, int cmd, void *args) rt_inline int check_dirent(struct romfs_dirent *dirent) { - if (dirent == NULL || (dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) || dirent->size == ~0) + if (dirent == NULL + ||(dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR) + || dirent->size == ~0) return -1; return 0; } @@ -114,31 +117,31 @@ struct romfs_dirent *__dfs_romfs_lookup(struct romfs_dirent *root_dirent, const subpath_end = path; /* skip /// */ while (*subpath_end && *subpath_end == '/') - subpath_end++; + subpath_end ++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) - subpath_end++; + subpath_end ++; while (dirent != NULL) { found = 0; /* search in folder */ - for (index = 0; index < dirent_size; index++) + for (index = 0; index < dirent_size; index ++) { if (check_dirent(&dirent[index]) != 0) return NULL; if (rt_strlen(dirent[index].name) == (subpath_end - subpath) && - rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) + rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) { dirent_size = dirent[index].size; /* skip /// */ while (*subpath_end && *subpath_end == '/') - subpath_end++; + subpath_end ++; subpath = subpath_end; while ((*subpath_end != '/') && *subpath_end) - subpath_end++; + subpath_end ++; if (!(*subpath)) { @@ -169,7 +172,7 @@ struct romfs_dirent *__dfs_romfs_lookup(struct romfs_dirent *root_dirent, const return NULL; } -static struct dfs_vnode *dfs_romfs_lookup(struct dfs_dentry *dentry) +static struct dfs_vnode *dfs_romfs_lookup (struct dfs_dentry *dentry) { rt_size_t size; struct dfs_vnode *vnode = RT_NULL; @@ -357,34 +360,37 @@ static int dfs_romfs_getdents(struct dfs_file *file, struct dirent *dirp, uint32 rt_strncpy(d->d_name, name, DIRENT_NAME_MAX); /* move to next position */ - ++file->fpos; + ++ file->fpos; } return index * sizeof(struct dirent); } -static const struct dfs_file_ops _rom_fops = { - .open = dfs_romfs_open, - .close = dfs_romfs_close, - .ioctl = dfs_romfs_ioctl, - .lseek = generic_dfs_lseek, - .read = dfs_romfs_read, - .getdents = dfs_romfs_getdents, +static const struct dfs_file_ops _rom_fops = +{ + .open = dfs_romfs_open, + .close = dfs_romfs_close, + .ioctl = dfs_romfs_ioctl, + .lseek = generic_dfs_lseek, + .read = dfs_romfs_read, + .getdents = dfs_romfs_getdents, }; -static const struct dfs_filesystem_ops _romfs_ops = { - .name = "rom", - .flags = 0, - .default_fops = &_rom_fops, - .mount = dfs_romfs_mount, - .umount = dfs_romfs_umount, - .stat = dfs_romfs_stat, - .lookup = dfs_romfs_lookup, - .free_vnode = dfs_romfs_free_vnode +static const struct dfs_filesystem_ops _romfs_ops = +{ + .name ="rom", + .flags = 0, + .default_fops = &_rom_fops, + .mount = dfs_romfs_mount, + .umount = dfs_romfs_umount, + .stat = dfs_romfs_stat, + .lookup = dfs_romfs_lookup, + .free_vnode = dfs_romfs_free_vnode }; -static struct dfs_filesystem_type _romfs = { - .fs_ops = &_romfs_ops, +static struct dfs_filesystem_type _romfs = +{ + .fs_ops = &_romfs_ops, }; int dfs_romfs_init(void)