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 <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-10-30 08:57:35 +02:00
commit b108d02eba
5 changed files with 82 additions and 82 deletions

View file

@ -24,15 +24,15 @@
extern "C" { extern "C" {
#endif #endif
/* Create a ZFILE type similar to FILE for familiarity */ /* Create a fs_file_t type similar to FILE for familiarity */
typedef struct _zfile_object ZFILE; typedef struct _fs_file_object fs_file_t;
/* Create a ZDIR type similar to DIR for familiarity */ /* Create a fs_dir_t type similar to DIR for familiarity */
typedef struct _zdir_object ZDIR; typedef struct _fs_dir_object fs_dir_t;
enum dir_entry_type { enum fs_dir_entry_type {
DIR_ENTRY_FILE, FS_DIR_ENTRY_FILE,
DIR_ENTRY_DIR 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 * @brief File object representing an open file
*/ */
/** @var ZDIR /** @var fs_dir_t
* @brief Directory object representing an open directory * @brief Directory object representing an open directory
*/ */
@ -57,13 +57,13 @@ enum dir_entry_type {
* file or directory information. * file or directory information.
* *
* @param dir_entry_type Whether file or directory * @param dir_entry_type Whether file or directory
* - DIR_ENTRY_FILE * - FS_DIR_ENTRY_FILE
* - DIR_ENTRY_DIR * - FS_DIR_ENTRY_DIR
* @param name Name of directory or file * @param name Name of directory or file
* @param size Size of file. 0 if directory * @param size Size of file. 0 if directory
*/ */
struct zfs_dirent { struct fs_dirent {
enum dir_entry_type type; enum fs_dir_entry_type type;
char name[MAX_FILE_NAME + 1]; char name[MAX_FILE_NAME + 1];
size_t size; size_t size;
}; };
@ -79,7 +79,7 @@ struct zfs_dirent {
* @param f_blocks Size of FS in f_frsize units * @param f_blocks Size of FS in f_frsize units
* @param f_bfree Number of free blocks * @param f_bfree Number of free blocks
*/ */
struct zfs_statvfs { struct fs_statvfs {
unsigned long f_bsize; unsigned long f_bsize;
unsigned long f_frsize; unsigned long f_frsize;
unsigned long f_blocks; unsigned long f_blocks;
@ -90,14 +90,14 @@ struct zfs_statvfs {
* @} * @}
*/ */
#ifndef SEEK_SET #ifndef FS_SEEK_SET
#define SEEK_SET 0 /* Seek from beginning of file. */ #define FS_SEEK_SET 0 /* Seek from beginning of file. */
#endif #endif
#ifndef SEEK_CUR #ifndef FS_SEEK_CUR
#define SEEK_CUR 1 /* Seek from current position. */ #define FS_SEEK_CUR 1 /* Seek from current position. */
#endif #endif
#ifndef SEEK_END #ifndef FS_SEEK_END
#define SEEK_END 2 /* Seek from end of file. */ #define FS_SEEK_END 2 /* Seek from end of file. */
#endif #endif
/** /**
@ -119,7 +119,7 @@ struct zfs_statvfs {
* @retval 0 Success * @retval 0 Success
* @retval -ERRNO errno code if error * @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 * @brief File close
@ -132,7 +132,7 @@ int fs_open(ZFILE *zfp, const char *file_name);
* @retval 0 Success * @retval 0 Success
* @retval -ERRNO errno code if error * @retval -ERRNO errno code if error
*/ */
int fs_close(ZFILE *zfp); int fs_close(fs_file_t *zfp);
/** /**
* @brief File unlink * @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 * requested if there are not enough bytes available in file. Will return
* -ERRNO code on error. * -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 * @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 * In that case, it returns less number of bytes written than requested, but
* not a negative -ERRNO value as in regular error case. * 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 * @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 zfp Pointer to the file object
* @param offset Relative location to move the file pointer to * @param offset Relative location to move the file pointer to
* @param whence Relative location from where offset is to be calculated. * @param whence Relative location from where offset is to be calculated.
* - SEEK_SET = from beginning of file * - FS_SEEK_SET = from beginning of file
* - SEEK_CUR = from current position, * - FS_SEEK_CUR = from current position,
* - SEEK_END = from end of file. * - FS_SEEK_END = from end of file.
* *
* @retval 0 Success * @retval 0 Success
* @retval -ERRNO errno code if error. * @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. * @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 * @retval position Current position in file
* Current revision does not validate the file object. * 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 * @brief Change the size of an open file
@ -231,7 +231,7 @@ off_t fs_tell(ZFILE *zfp);
* @retval 0 Success * @retval 0 Success
* @retval -ERRNO errno code if error * @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 * @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 0 Success
* @retval -ERRNO errno code if error * @retval -ERRNO errno code if error
*/ */
int fs_sync(ZFILE *zfp); int fs_sync(fs_file_t *zfp);
/** /**
* @brief Directory create * @brief Directory create
@ -272,7 +272,7 @@ int fs_mkdir(const char *path);
* @retval 0 Success * @retval 0 Success
* @retval -ERRNO errno code if error * @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 * @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 * @return In end-of-dir condition, this will return 0 and set
* entry->name[0] = 0 * 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 * @brief Directory close
@ -299,7 +299,7 @@ int fs_readdir(ZDIR *zdp, struct zfs_dirent *entry);
* @retval 0 Success * @retval 0 Success
* @retval -ERRNO errno code if error * @retval -ERRNO errno code if error
*/ */
int fs_closedir(ZDIR *zdp); int fs_closedir(fs_dir_t *zdp);
/** /**
* @brief File or directory status * @brief File or directory status
@ -313,7 +313,7 @@ int fs_closedir(ZDIR *zdp);
* @retval 0 Success * @retval 0 Success
* @retval -ERRNO errno code if error * @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 * @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 0 Success
* @retval -ERRNO errno code if error * @retval -ERRNO errno code if error
*/ */
int fs_statvfs(struct zfs_statvfs *stat); int fs_statvfs(struct fs_statvfs *stat);
/** /**
* @} * @}

View file

@ -24,12 +24,12 @@
extern "C" { extern "C" {
#endif #endif
ZFILE_DEFINE(FIL fp); FS_FILE_DEFINE(FIL fp);
ZDIR_DEFINE(DIR dp); FS_DIR_DEFINE(DIR dp);
#define MAX_FILE_NAME 12 /* Uses 8.3 SFN */ #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); return f_tell(&zfp->fp);
} }

View file

@ -31,8 +31,8 @@ extern "C" {
* @param _file_object File structure used by underlying file system * @param _file_object File structure used by underlying file system
*/ */
#define ZFILE_DEFINE(_file_object) \ #define FS_FILE_DEFINE(_file_object) \
struct _zfile_object { \ struct _fs_file_object { \
_file_object; \ _file_object; \
} }
@ -46,8 +46,8 @@ extern "C" {
* @param _dir_object Directory structure used by underlying file system * @param _dir_object Directory structure used by underlying file system
*/ */
#define ZDIR_DEFINE(_dir_object) \ #define FS_DIR_DEFINE(_dir_object) \
struct _zdir_object { \ struct _fs_dir_object { \
_dir_object; \ _dir_object; \
} }

View file

@ -64,7 +64,7 @@ static int translate_error(int error)
return -EIO; return -EIO;
} }
int fs_open(ZFILE *zfp, const char *file_name) int fs_open(fs_file_t *zfp, const char *file_name)
{ {
FRESULT res; FRESULT res;
uint8_t fs_mode; uint8_t fs_mode;
@ -76,7 +76,7 @@ int fs_open(ZFILE *zfp, const char *file_name)
return translate_error(res); return translate_error(res);
} }
int fs_close(ZFILE *zfp) int fs_close(fs_file_t *zfp)
{ {
FRESULT res; FRESULT res;
@ -94,7 +94,7 @@ int fs_unlink(const char *path)
return translate_error(res); 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; FRESULT res;
unsigned int br; unsigned int br;
@ -107,7 +107,7 @@ ssize_t fs_read(ZFILE *zfp, void *ptr, size_t size)
return br; 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; FRESULT res;
unsigned int bw; unsigned int bw;
@ -120,19 +120,19 @@ ssize_t fs_write(ZFILE *zfp, const void *ptr, size_t size)
return bw; 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; FRESULT res = FR_OK;
off_t pos; off_t pos;
switch (whence) { switch (whence) {
case SEEK_SET: case FS_SEEK_SET:
pos = offset; pos = offset;
break; break;
case SEEK_CUR: case FS_SEEK_CUR:
pos = f_tell(&zfp->fp) + offset; pos = f_tell(&zfp->fp) + offset;
break; break;
case SEEK_END: case FS_SEEK_END:
pos = f_size(&zfp->fp) + offset; pos = f_size(&zfp->fp) + offset;
break; break;
default: default:
@ -148,7 +148,7 @@ int fs_seek(ZFILE *zfp, off_t offset, int whence)
return translate_error(res); 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; FRESULT res = FR_OK;
off_t cur_length = f_size(&zfp->fp); off_t cur_length = f_size(&zfp->fp);
@ -194,7 +194,7 @@ int fs_truncate(ZFILE *zfp, off_t length)
return translate_error(res); return translate_error(res);
} }
int fs_sync(ZFILE *zfp) int fs_sync(fs_file_t *zfp)
{ {
FRESULT res = FR_OK; FRESULT res = FR_OK;
@ -212,7 +212,7 @@ int fs_mkdir(const char *path)
return translate_error(res); return translate_error(res);
} }
int fs_opendir(ZDIR *zdp, const char *path) int fs_opendir(fs_dir_t *zdp, const char *path)
{ {
FRESULT res; FRESULT res;
@ -221,7 +221,7 @@ int fs_opendir(ZDIR *zdp, const char *path)
return translate_error(res); 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; FRESULT res;
FILINFO fno; FILINFO fno;
@ -229,7 +229,7 @@ int fs_readdir(ZDIR *zdp, struct zfs_dirent *entry)
res = f_readdir(&zdp->dp, &fno); res = f_readdir(&zdp->dp, &fno);
if (res == FR_OK) { if (res == FR_OK) {
entry->type = ((fno.fattrib & AM_DIR) ? 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); strcpy(entry->name, fno.fname);
entry->size = fno.fsize; entry->size = fno.fsize;
} }
@ -237,7 +237,7 @@ int fs_readdir(ZDIR *zdp, struct zfs_dirent *entry)
return translate_error(res); return translate_error(res);
} }
int fs_closedir(ZDIR *zdp) int fs_closedir(fs_dir_t *zdp)
{ {
FRESULT res; FRESULT res;
@ -246,7 +246,7 @@ int fs_closedir(ZDIR *zdp)
return translate_error(res); 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; FRESULT res;
FILINFO fno; FILINFO fno;
@ -254,7 +254,7 @@ int fs_stat(const char *path, struct zfs_dirent *entry)
res = f_stat(path, &fno); res = f_stat(path, &fno);
if (res == FR_OK) { if (res == FR_OK) {
entry->type = ((fno.fattrib & AM_DIR) ? 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); strcpy(entry->name, fno.fname);
entry->size = fno.fsize; entry->size = fno.fsize;
} }
@ -262,7 +262,7 @@ int fs_stat(const char *path, struct zfs_dirent *entry)
return translate_error(res); return translate_error(res);
} }
int fs_statvfs(struct zfs_statvfs *stat) int fs_statvfs(struct fs_statvfs *stat)
{ {
FATFS *fs; FATFS *fs;
FRESULT res; FRESULT res;

View file

@ -45,14 +45,14 @@ void main(void)
static int check_file_dir_exists(const char *path) static int check_file_dir_exists(const char *path)
{ {
int res; int res;
struct zfs_dirent entry; struct fs_dirent entry;
res = fs_stat(path, &entry); res = fs_stat(path, &entry);
return !res; return !res;
} }
static int open_file(ZFILE *fp, const char *path) static int open_file(fs_file_t *fp, const char *path)
{ {
int res; int res;
@ -75,12 +75,12 @@ static int open_file(ZFILE *fp, const char *path)
static const char test_str[] = "hello world!"; 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; ssize_t brw;
int res; int res;
res = fs_seek(fp, ofs, SEEK_SET); res = fs_seek(fp, ofs, FS_SEEK_SET);
if (res) { if (res) {
printk("fs_seek failed [%d]\n", res); printk("fs_seek failed [%d]\n", res);
fs_close(fp); fs_close(fp);
@ -106,12 +106,12 @@ static int write_test(ZFILE *fp, off_t ofs, const char *str)
return res; 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; ssize_t brw;
int res; int res;
res = fs_seek(fp, ofs, SEEK_SET); res = fs_seek(fp, ofs, FS_SEEK_SET);
if (res) { if (res) {
printk("fs_seek failed [%d]\n", res); printk("fs_seek failed [%d]\n", res);
fs_close(fp); fs_close(fp);
@ -132,7 +132,7 @@ static int read_test(ZFILE *fp, off_t ofs, size_t sz, char *read_buff)
return res; return res;
} }
static int close_file(ZFILE *fp, const char *path) static int close_file(fs_file_t *fp, const char *path)
{ {
int res; int res;
@ -169,7 +169,7 @@ static int delete_test(const char *path)
return 0; return 0;
} }
static int truncate_test(ZFILE *fp) static int truncate_test(fs_file_t *fp)
{ {
int res; int res;
off_t pos; off_t pos;
@ -186,7 +186,7 @@ static int truncate_test(ZFILE *fp)
return res; return res;
} }
fs_seek(fp, 0, SEEK_END); fs_seek(fp, 0, FS_SEEK_END);
if (fs_tell(fp) > 0) { if (fs_tell(fp) > 0) {
printk("Failed truncating to size 0\n"); printk("Failed truncating to size 0\n");
fs_close(fp); fs_close(fp);
@ -200,7 +200,7 @@ static int truncate_test(ZFILE *fp)
return res; return res;
} }
fs_seek(fp, 0, SEEK_END); fs_seek(fp, 0, FS_SEEK_END);
pos = fs_tell(fp); pos = fs_tell(fp);
printk("Original size of file = %ld\n", pos); printk("Original size of file = %ld\n", pos);
@ -214,7 +214,7 @@ static int truncate_test(ZFILE *fp)
return res; 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)); printk("File size after shrinking by 5 bytes = %ld\n", fs_tell(fp));
if (fs_tell(fp) != (pos - 5)) { if (fs_tell(fp) != (pos - 5)) {
printk("File size after fs_truncate not as expected\n"); printk("File size after fs_truncate not as expected\n");
@ -238,7 +238,7 @@ static int truncate_test(ZFILE *fp)
/* Test expanding file */ /* Test expanding file */
fs_seek(fp, 0, SEEK_END); fs_seek(fp, 0, FS_SEEK_END);
pos = fs_tell(fp); pos = fs_tell(fp);
res = fs_truncate(fp, pos + 10); res = fs_truncate(fp, pos + 10);
if (res) { if (res) {
@ -247,7 +247,7 @@ static int truncate_test(ZFILE *fp)
return res; 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)); printk("File size after expanding by 10 bytes = %ld\n", fs_tell(fp));
if (fs_tell(fp) != (pos + 10)) { if (fs_tell(fp) != (pos + 10)) {
@ -272,7 +272,7 @@ static int truncate_test(ZFILE *fp)
/* Check if expanded regions are zeroed */ /* 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"); printk("Testing for zeroes in expanded region\n");
@ -297,7 +297,7 @@ static int truncate_test(ZFILE *fp)
static void file_tests(void) static void file_tests(void)
{ {
ZFILE fp; fs_file_t fp;
int res; int res;
char read_buff[80]; char read_buff[80];
@ -358,8 +358,8 @@ static int create_dir(const char *path)
static int remove_dir(const char *path) static int remove_dir(const char *path)
{ {
int res; int res;
ZDIR dp; fs_dir_t dp;
static struct zfs_dirent entry; static struct fs_dirent entry;
char file_path[80]; char file_path[80];
if (!check_file_dir_exists(path)) { if (!check_file_dir_exists(path)) {
@ -411,8 +411,8 @@ static int remove_dir(const char *path)
static int list_dir(const char *path) static int list_dir(const char *path)
{ {
int res; int res;
ZDIR dp; fs_dir_t dp;
static struct zfs_dirent entry; static struct fs_dirent entry;
res = fs_opendir(&dp, path); res = fs_opendir(&dp, path);
if (res) { if (res) {
@ -428,7 +428,7 @@ static int list_dir(const char *path)
if (res || entry.name[0] == 0) { if (res || entry.name[0] == 0) {
break; break;
} }
if (entry.type == DIR_ENTRY_DIR) { if (entry.type == FS_DIR_ENTRY_DIR) {
printk("[DIR ] %s\n", entry.name); printk("[DIR ] %s\n", entry.name);
} else { } else {
printk("[FILE] %s (size = %zu)\n", printk("[FILE] %s (size = %zu)\n",
@ -443,7 +443,7 @@ static int list_dir(const char *path)
static void dir_tests(void) static void dir_tests(void)
{ {
ZFILE fp[2]; fs_file_t fp[2];
int res; int res;
/* Remove sub dir if already exists */ /* Remove sub dir if already exists */
@ -513,7 +513,7 @@ static void dir_tests(void)
static void vol_tests(void) static void vol_tests(void)
{ {
struct zfs_statvfs stat; struct fs_statvfs stat;
int res; int res;
res = fs_statvfs(&stat); res = fs_statvfs(&stat);