From 353336d632040dd00b89e4d358df0928e01c5285 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Mon, 1 Jun 2020 11:36:52 -0500 Subject: [PATCH] fs: make file system description const There's no reason the table of pointers to file system functions needs to be mutable at runtime. Signed-off-by: Peter A. Bigot --- doc/reference/file_system/index.rst | 4 ++-- include/fs/fs.h | 4 ++-- subsys/fs/fat_fs.c | 2 +- subsys/fs/fs.c | 8 ++++---- subsys/fs/littlefs_fs.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/doc/reference/file_system/index.rst b/doc/reference/file_system/index.rst index 8f2ebdb7f0d..84b9d97603e 100644 --- a/doc/reference/file_system/index.rst +++ b/doc/reference/file_system/index.rst @@ -16,9 +16,9 @@ pulled out through a file system registration API. .. code-block:: c - int fs_register(enum fs_type type, struct fs_file_system_t *fs); + int fs_register(enum fs_type type, const struct fs_file_system_t *fs); - int fs_unregister(enum fs_type type, struct fs_file_system_t *fs); + int fs_unregister(enum fs_type type, const struct fs_file_system_t *fs); Zephyr RTOS supports multiple instances of a file system by making use of the mount point as the disk volume name, which is used by the file system library diff --git a/include/fs/fs.h b/include/fs/fs.h index ffa30576a09..8f6a001754b 100644 --- a/include/fs/fs.h +++ b/include/fs/fs.h @@ -494,7 +494,7 @@ int fs_statvfs(const char *path, struct fs_statvfs *stat); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_register(enum fs_type type, struct fs_file_system_t *fs); +int fs_register(enum fs_type type, const struct fs_file_system_t *fs); /** * @brief Unregister a file system @@ -507,7 +507,7 @@ int fs_register(enum fs_type type, struct fs_file_system_t *fs); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_unregister(enum fs_type type, struct fs_file_system_t *fs); +int fs_unregister(enum fs_type type, const struct fs_file_system_t *fs); /** * @} diff --git a/subsys/fs/fat_fs.c b/subsys/fs/fat_fs.c index 6e364c26df0..ce4cdd46a92 100644 --- a/subsys/fs/fat_fs.c +++ b/subsys/fs/fat_fs.c @@ -407,7 +407,7 @@ static int fatfs_unmount(struct fs_mount_t *mountp) } /* File system interface */ -static struct fs_file_system_t fatfs_fs = { +static const struct fs_file_system_t fatfs_fs = { .open = fatfs_open, .close = fatfs_close, .read = fatfs_read, diff --git a/subsys/fs/fs.c b/subsys/fs/fs.c index 5b6cc14ae0d..6a278c960da 100644 --- a/subsys/fs/fs.c +++ b/subsys/fs/fs.c @@ -24,7 +24,7 @@ static sys_dlist_t fs_mnt_list; static struct k_mutex mutex; /* file system map table */ -static struct fs_file_system_t *fs_map[FS_TYPE_END]; +static const struct fs_file_system_t *fs_map[FS_TYPE_END]; static int fs_get_mnt_point(struct fs_mount_t **mnt_pntp, const char *name, size_t *match_len) @@ -526,7 +526,7 @@ int fs_statvfs(const char *abs_path, struct fs_statvfs *stat) int fs_mount(struct fs_mount_t *mp) { struct fs_mount_t *itr; - struct fs_file_system_t *fs; + const struct fs_file_system_t *fs; sys_dnode_t *node; int rc = -EINVAL; @@ -664,7 +664,7 @@ int fs_readmount(int *number, const char **name) } /* Register File system */ -int fs_register(enum fs_type type, struct fs_file_system_t *fs) +int fs_register(enum fs_type type, const struct fs_file_system_t *fs) { int rc = 0; @@ -682,7 +682,7 @@ reg_err: } /* Unregister File system */ -int fs_unregister(enum fs_type type, struct fs_file_system_t *fs) +int fs_unregister(enum fs_type type, const struct fs_file_system_t *fs) { int rc = 0; diff --git a/subsys/fs/littlefs_fs.c b/subsys/fs/littlefs_fs.c index 5f3c00de836..448b7719356 100644 --- a/subsys/fs/littlefs_fs.c +++ b/subsys/fs/littlefs_fs.c @@ -722,7 +722,7 @@ static int littlefs_unmount(struct fs_mount_t *mountp) } /* File system interface */ -static struct fs_file_system_t littlefs_fs = { +static const struct fs_file_system_t littlefs_fs = { .open = littlefs_open, .close = littlefs_close, .read = littlefs_read,