From b108d02ebac25eaf873f19848f88081c7c787fa8 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 30 Oct 2016 08:57:35 +0200 Subject: [PATCH] fs: Make API naming adhere to the appropriate namespace The namespace allocated for the filesystem API is fs_* and FS_*. That means all symbols and defines should adhere to it. Jira: ZEP-1155 Change-Id: I422310448b7c7c347f621aea6d7b1d97ef25c94d Signed-off-by: Johan Hedberg --- include/fs.h | 72 +++++++++++++++--------------- include/fs/fat_fs.h | 6 +-- include/fs/fs_interface.h | 8 ++-- subsys/fs/fat_fs.c | 34 +++++++------- tests/filesystem/fat_fs/src/main.c | 44 +++++++++--------- 5 files changed, 82 insertions(+), 82 deletions(-) diff --git a/include/fs.h b/include/fs.h index 68691138297..07b55848b42 100644 --- a/include/fs.h +++ b/include/fs.h @@ -24,15 +24,15 @@ extern "C" { #endif -/* Create a ZFILE type similar to FILE for familiarity */ -typedef struct _zfile_object ZFILE; +/* Create a fs_file_t type similar to FILE for familiarity */ +typedef struct _fs_file_object fs_file_t; -/* Create a ZDIR type similar to DIR for familiarity */ -typedef struct _zdir_object ZDIR; +/* Create a fs_dir_t type similar to DIR for familiarity */ +typedef struct _fs_dir_object fs_dir_t; -enum dir_entry_type { - DIR_ENTRY_FILE, - DIR_ENTRY_DIR +enum fs_dir_entry_type { + FS_DIR_ENTRY_FILE, + FS_DIR_ENTRY_DIR }; /** @@ -42,11 +42,11 @@ enum dir_entry_type { * @{ */ -/** @var ZFILE +/** @var fs_file_t * @brief File object representing an open file */ -/** @var ZDIR +/** @var fs_dir_t * @brief Directory object representing an open directory */ @@ -57,13 +57,13 @@ enum dir_entry_type { * file or directory information. * * @param dir_entry_type Whether file or directory - * - DIR_ENTRY_FILE - * - DIR_ENTRY_DIR + * - FS_DIR_ENTRY_FILE + * - FS_DIR_ENTRY_DIR * @param name Name of directory or file * @param size Size of file. 0 if directory */ -struct zfs_dirent { - enum dir_entry_type type; +struct fs_dirent { + enum fs_dir_entry_type type; char name[MAX_FILE_NAME + 1]; size_t size; }; @@ -79,7 +79,7 @@ struct zfs_dirent { * @param f_blocks Size of FS in f_frsize units * @param f_bfree Number of free blocks */ -struct zfs_statvfs { +struct fs_statvfs { unsigned long f_bsize; unsigned long f_frsize; unsigned long f_blocks; @@ -90,14 +90,14 @@ struct zfs_statvfs { * @} */ -#ifndef SEEK_SET -#define SEEK_SET 0 /* Seek from beginning of file. */ +#ifndef FS_SEEK_SET +#define FS_SEEK_SET 0 /* Seek from beginning of file. */ #endif -#ifndef SEEK_CUR -#define SEEK_CUR 1 /* Seek from current position. */ +#ifndef FS_SEEK_CUR +#define FS_SEEK_CUR 1 /* Seek from current position. */ #endif -#ifndef SEEK_END -#define SEEK_END 2 /* Seek from end of file. */ +#ifndef FS_SEEK_END +#define FS_SEEK_END 2 /* Seek from end of file. */ #endif /** @@ -119,7 +119,7 @@ struct zfs_statvfs { * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_open(ZFILE *zfp, const char *file_name); +int fs_open(fs_file_t *zfp, const char *file_name); /** * @brief File close @@ -132,7 +132,7 @@ int fs_open(ZFILE *zfp, const char *file_name); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_close(ZFILE *zfp); +int fs_close(fs_file_t *zfp); /** * @brief File unlink @@ -160,7 +160,7 @@ int fs_unlink(const char *path); * requested if there are not enough bytes available in file. Will return * -ERRNO code on error. */ -ssize_t fs_read(ZFILE *zfp, void *ptr, size_t size); +ssize_t fs_read(fs_file_t *zfp, void *ptr, size_t size); /** * @brief File write @@ -181,7 +181,7 @@ ssize_t fs_read(ZFILE *zfp, void *ptr, size_t size); * In that case, it returns less number of bytes written than requested, but * not a negative -ERRNO value as in regular error case. */ -ssize_t fs_write(ZFILE *zfp, const void *ptr, size_t size); +ssize_t fs_write(fs_file_t *zfp, const void *ptr, size_t size); /** * @brief File seek @@ -192,14 +192,14 @@ ssize_t fs_write(ZFILE *zfp, const void *ptr, size_t size); * @param zfp Pointer to the file object * @param offset Relative location to move the file pointer to * @param whence Relative location from where offset is to be calculated. - * - SEEK_SET = from beginning of file - * - SEEK_CUR = from current position, - * - SEEK_END = from end of file. + * - FS_SEEK_SET = from beginning of file + * - FS_SEEK_CUR = from current position, + * - FS_SEEK_END = from end of file. * * @retval 0 Success * @retval -ERRNO errno code if error. */ -int fs_seek(ZFILE *zfp, off_t offset, int whence); +int fs_seek(fs_file_t *zfp, off_t offset, int whence); /** * @brief Get current file position. @@ -211,7 +211,7 @@ int fs_seek(ZFILE *zfp, off_t offset, int whence); * @retval position Current position in file * Current revision does not validate the file object. */ -off_t fs_tell(ZFILE *zfp); +off_t fs_tell(fs_file_t *zfp); /** * @brief Change the size of an open file @@ -231,7 +231,7 @@ off_t fs_tell(ZFILE *zfp); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_truncate(ZFILE *zfp, off_t length); +int fs_truncate(fs_file_t *zfp, off_t length); /** * @brief Flushes any cached write of an open file @@ -247,7 +247,7 @@ int fs_truncate(ZFILE *zfp, off_t length); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_sync(ZFILE *zfp); +int fs_sync(fs_file_t *zfp); /** * @brief Directory create @@ -272,7 +272,7 @@ int fs_mkdir(const char *path); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_opendir(ZDIR *zdp, const char *path); +int fs_opendir(fs_dir_t *zdp, const char *path); /** * @brief Directory read entry @@ -287,7 +287,7 @@ int fs_opendir(ZDIR *zdp, const char *path); * @return In end-of-dir condition, this will return 0 and set * entry->name[0] = 0 */ -int fs_readdir(ZDIR *zdp, struct zfs_dirent *entry); +int fs_readdir(fs_dir_t *zdp, struct fs_dirent *entry); /** * @brief Directory close @@ -299,7 +299,7 @@ int fs_readdir(ZDIR *zdp, struct zfs_dirent *entry); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_closedir(ZDIR *zdp); +int fs_closedir(fs_dir_t *zdp); /** * @brief File or directory status @@ -313,7 +313,7 @@ int fs_closedir(ZDIR *zdp); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_stat(const char *path, struct zfs_dirent *entry); +int fs_stat(const char *path, struct fs_dirent *entry); /** * @brief Retrieves statistics of the file system volume @@ -325,7 +325,7 @@ int fs_stat(const char *path, struct zfs_dirent *entry); * @retval 0 Success * @retval -ERRNO errno code if error */ -int fs_statvfs(struct zfs_statvfs *stat); +int fs_statvfs(struct fs_statvfs *stat); /** * @} diff --git a/include/fs/fat_fs.h b/include/fs/fat_fs.h index f69930c35c8..8ddad07855a 100644 --- a/include/fs/fat_fs.h +++ b/include/fs/fat_fs.h @@ -24,12 +24,12 @@ extern "C" { #endif -ZFILE_DEFINE(FIL fp); -ZDIR_DEFINE(DIR dp); +FS_FILE_DEFINE(FIL fp); +FS_DIR_DEFINE(DIR dp); #define MAX_FILE_NAME 12 /* Uses 8.3 SFN */ -static inline off_t fs_tell(struct _zfile_object *zfp) +static inline off_t fs_tell(struct _fs_file_object *zfp) { return f_tell(&zfp->fp); } diff --git a/include/fs/fs_interface.h b/include/fs/fs_interface.h index 53dbd52528b..d145c4e6645 100644 --- a/include/fs/fs_interface.h +++ b/include/fs/fs_interface.h @@ -31,8 +31,8 @@ extern "C" { * @param _file_object File structure used by underlying file system */ -#define ZFILE_DEFINE(_file_object) \ - struct _zfile_object { \ +#define FS_FILE_DEFINE(_file_object) \ + struct _fs_file_object { \ _file_object; \ } @@ -46,8 +46,8 @@ extern "C" { * @param _dir_object Directory structure used by underlying file system */ -#define ZDIR_DEFINE(_dir_object) \ - struct _zdir_object { \ +#define FS_DIR_DEFINE(_dir_object) \ + struct _fs_dir_object { \ _dir_object; \ } diff --git a/subsys/fs/fat_fs.c b/subsys/fs/fat_fs.c index 414241e3b19..116ff3e1141 100644 --- a/subsys/fs/fat_fs.c +++ b/subsys/fs/fat_fs.c @@ -64,7 +64,7 @@ static int translate_error(int error) return -EIO; } -int fs_open(ZFILE *zfp, const char *file_name) +int fs_open(fs_file_t *zfp, const char *file_name) { FRESULT res; uint8_t fs_mode; @@ -76,7 +76,7 @@ int fs_open(ZFILE *zfp, const char *file_name) return translate_error(res); } -int fs_close(ZFILE *zfp) +int fs_close(fs_file_t *zfp) { FRESULT res; @@ -94,7 +94,7 @@ int fs_unlink(const char *path) return translate_error(res); } -ssize_t fs_read(ZFILE *zfp, void *ptr, size_t size) +ssize_t fs_read(fs_file_t *zfp, void *ptr, size_t size) { FRESULT res; unsigned int br; @@ -107,7 +107,7 @@ ssize_t fs_read(ZFILE *zfp, void *ptr, size_t size) return br; } -ssize_t fs_write(ZFILE *zfp, const void *ptr, size_t size) +ssize_t fs_write(fs_file_t *zfp, const void *ptr, size_t size) { FRESULT res; unsigned int bw; @@ -120,19 +120,19 @@ ssize_t fs_write(ZFILE *zfp, const void *ptr, size_t size) return bw; } -int fs_seek(ZFILE *zfp, off_t offset, int whence) +int fs_seek(fs_file_t *zfp, off_t offset, int whence) { FRESULT res = FR_OK; off_t pos; switch (whence) { - case SEEK_SET: + case FS_SEEK_SET: pos = offset; break; - case SEEK_CUR: + case FS_SEEK_CUR: pos = f_tell(&zfp->fp) + offset; break; - case SEEK_END: + case FS_SEEK_END: pos = f_size(&zfp->fp) + offset; break; default: @@ -148,7 +148,7 @@ int fs_seek(ZFILE *zfp, off_t offset, int whence) return translate_error(res); } -int fs_truncate(ZFILE *zfp, off_t length) +int fs_truncate(fs_file_t *zfp, off_t length) { FRESULT res = FR_OK; off_t cur_length = f_size(&zfp->fp); @@ -194,7 +194,7 @@ int fs_truncate(ZFILE *zfp, off_t length) return translate_error(res); } -int fs_sync(ZFILE *zfp) +int fs_sync(fs_file_t *zfp) { FRESULT res = FR_OK; @@ -212,7 +212,7 @@ int fs_mkdir(const char *path) return translate_error(res); } -int fs_opendir(ZDIR *zdp, const char *path) +int fs_opendir(fs_dir_t *zdp, const char *path) { FRESULT res; @@ -221,7 +221,7 @@ int fs_opendir(ZDIR *zdp, const char *path) return translate_error(res); } -int fs_readdir(ZDIR *zdp, struct zfs_dirent *entry) +int fs_readdir(fs_dir_t *zdp, struct fs_dirent *entry) { FRESULT res; FILINFO fno; @@ -229,7 +229,7 @@ int fs_readdir(ZDIR *zdp, struct zfs_dirent *entry) res = f_readdir(&zdp->dp, &fno); if (res == FR_OK) { entry->type = ((fno.fattrib & AM_DIR) ? - DIR_ENTRY_DIR : DIR_ENTRY_FILE); + FS_DIR_ENTRY_DIR : FS_DIR_ENTRY_FILE); strcpy(entry->name, fno.fname); entry->size = fno.fsize; } @@ -237,7 +237,7 @@ int fs_readdir(ZDIR *zdp, struct zfs_dirent *entry) return translate_error(res); } -int fs_closedir(ZDIR *zdp) +int fs_closedir(fs_dir_t *zdp) { FRESULT res; @@ -246,7 +246,7 @@ int fs_closedir(ZDIR *zdp) return translate_error(res); } -int fs_stat(const char *path, struct zfs_dirent *entry) +int fs_stat(const char *path, struct fs_dirent *entry) { FRESULT res; FILINFO fno; @@ -254,7 +254,7 @@ int fs_stat(const char *path, struct zfs_dirent *entry) res = f_stat(path, &fno); if (res == FR_OK) { entry->type = ((fno.fattrib & AM_DIR) ? - DIR_ENTRY_DIR : DIR_ENTRY_FILE); + FS_DIR_ENTRY_DIR : FS_DIR_ENTRY_FILE); strcpy(entry->name, fno.fname); entry->size = fno.fsize; } @@ -262,7 +262,7 @@ int fs_stat(const char *path, struct zfs_dirent *entry) return translate_error(res); } -int fs_statvfs(struct zfs_statvfs *stat) +int fs_statvfs(struct fs_statvfs *stat) { FATFS *fs; FRESULT res; diff --git a/tests/filesystem/fat_fs/src/main.c b/tests/filesystem/fat_fs/src/main.c index c4bccb743db..6e3175b370f 100644 --- a/tests/filesystem/fat_fs/src/main.c +++ b/tests/filesystem/fat_fs/src/main.c @@ -45,14 +45,14 @@ void main(void) static int check_file_dir_exists(const char *path) { int res; - struct zfs_dirent entry; + struct fs_dirent entry; res = fs_stat(path, &entry); return !res; } -static int open_file(ZFILE *fp, const char *path) +static int open_file(fs_file_t *fp, const char *path) { int res; @@ -75,12 +75,12 @@ static int open_file(ZFILE *fp, const char *path) static const char test_str[] = "hello world!"; -static int write_test(ZFILE *fp, off_t ofs, const char *str) +static int write_test(fs_file_t *fp, off_t ofs, const char *str) { ssize_t brw; int res; - res = fs_seek(fp, ofs, SEEK_SET); + res = fs_seek(fp, ofs, FS_SEEK_SET); if (res) { printk("fs_seek failed [%d]\n", res); fs_close(fp); @@ -106,12 +106,12 @@ static int write_test(ZFILE *fp, off_t ofs, const char *str) return res; } -static int read_test(ZFILE *fp, off_t ofs, size_t sz, char *read_buff) +static int read_test(fs_file_t *fp, off_t ofs, size_t sz, char *read_buff) { ssize_t brw; int res; - res = fs_seek(fp, ofs, SEEK_SET); + res = fs_seek(fp, ofs, FS_SEEK_SET); if (res) { printk("fs_seek failed [%d]\n", res); fs_close(fp); @@ -132,7 +132,7 @@ static int read_test(ZFILE *fp, off_t ofs, size_t sz, char *read_buff) return res; } -static int close_file(ZFILE *fp, const char *path) +static int close_file(fs_file_t *fp, const char *path) { int res; @@ -169,7 +169,7 @@ static int delete_test(const char *path) return 0; } -static int truncate_test(ZFILE *fp) +static int truncate_test(fs_file_t *fp) { int res; off_t pos; @@ -186,7 +186,7 @@ static int truncate_test(ZFILE *fp) return res; } - fs_seek(fp, 0, SEEK_END); + fs_seek(fp, 0, FS_SEEK_END); if (fs_tell(fp) > 0) { printk("Failed truncating to size 0\n"); fs_close(fp); @@ -200,7 +200,7 @@ static int truncate_test(ZFILE *fp) return res; } - fs_seek(fp, 0, SEEK_END); + fs_seek(fp, 0, FS_SEEK_END); pos = fs_tell(fp); printk("Original size of file = %ld\n", pos); @@ -214,7 +214,7 @@ static int truncate_test(ZFILE *fp) return res; } - fs_seek(fp, 0, SEEK_END); + fs_seek(fp, 0, FS_SEEK_END); printk("File size after shrinking by 5 bytes = %ld\n", fs_tell(fp)); if (fs_tell(fp) != (pos - 5)) { printk("File size after fs_truncate not as expected\n"); @@ -238,7 +238,7 @@ static int truncate_test(ZFILE *fp) /* Test expanding file */ - fs_seek(fp, 0, SEEK_END); + fs_seek(fp, 0, FS_SEEK_END); pos = fs_tell(fp); res = fs_truncate(fp, pos + 10); if (res) { @@ -247,7 +247,7 @@ static int truncate_test(ZFILE *fp) return res; } - fs_seek(fp, 0, SEEK_END); + fs_seek(fp, 0, FS_SEEK_END); printk("File size after expanding by 10 bytes = %ld\n", fs_tell(fp)); if (fs_tell(fp) != (pos + 10)) { @@ -272,7 +272,7 @@ static int truncate_test(ZFILE *fp) /* Check if expanded regions are zeroed */ - fs_seek(fp, -5, SEEK_END); + fs_seek(fp, -5, FS_SEEK_END); printk("Testing for zeroes in expanded region\n"); @@ -297,7 +297,7 @@ static int truncate_test(ZFILE *fp) static void file_tests(void) { - ZFILE fp; + fs_file_t fp; int res; char read_buff[80]; @@ -358,8 +358,8 @@ static int create_dir(const char *path) static int remove_dir(const char *path) { int res; - ZDIR dp; - static struct zfs_dirent entry; + fs_dir_t dp; + static struct fs_dirent entry; char file_path[80]; if (!check_file_dir_exists(path)) { @@ -411,8 +411,8 @@ static int remove_dir(const char *path) static int list_dir(const char *path) { int res; - ZDIR dp; - static struct zfs_dirent entry; + fs_dir_t dp; + static struct fs_dirent entry; res = fs_opendir(&dp, path); if (res) { @@ -428,7 +428,7 @@ static int list_dir(const char *path) if (res || entry.name[0] == 0) { break; } - if (entry.type == DIR_ENTRY_DIR) { + if (entry.type == FS_DIR_ENTRY_DIR) { printk("[DIR ] %s\n", entry.name); } else { printk("[FILE] %s (size = %zu)\n", @@ -443,7 +443,7 @@ static int list_dir(const char *path) static void dir_tests(void) { - ZFILE fp[2]; + fs_file_t fp[2]; int res; /* Remove sub dir if already exists */ @@ -513,7 +513,7 @@ static void dir_tests(void) static void vol_tests(void) { - struct zfs_statvfs stat; + struct fs_statvfs stat; int res; res = fs_statvfs(&stat);