Skip to content

Commit

Permalink
fs: Make API naming adhere to the appropriate namespace
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Johan Hedberg committed Oct 31, 2016
1 parent e354ad2 commit b108d02
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 82 deletions.
72 changes: 36 additions & 36 deletions include/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand All @@ -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
*/

Expand All @@ -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;
};
Expand All @@ -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;
Expand All @@ -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

/**
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);

/**
* @}
Expand Down
6 changes: 3 additions & 3 deletions include/fs/fat_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions include/fs/fs_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
}

Expand All @@ -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; \
}

Expand Down
34 changes: 17 additions & 17 deletions subsys/fs/fat_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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:
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -221,23 +221,23 @@ 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;

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;
}

return translate_error(res);
}

int fs_closedir(ZDIR *zdp)
int fs_closedir(fs_dir_t *zdp)
{
FRESULT res;

Expand All @@ -246,23 +246,23 @@ 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;

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;
}

return translate_error(res);
}

int fs_statvfs(struct zfs_statvfs *stat)
int fs_statvfs(struct fs_statvfs *stat)
{
FATFS *fs;
FRESULT res;
Expand Down
Loading

0 comments on commit b108d02

Please sign in to comment.