An API that enables integration of standard C library with an arbitrary file system. More...
Content | |
Definitions | |
Data Structures | |
struct | rt_fs_time_t |
Time and Date Information. More... | |
struct | rt_fs_stat_t |
File Status Information. More... | |
Functions | |
int32_t | rt_fs_open (const char *path, int32_t mode) |
Open a file. | |
int32_t | rt_fs_close (int32_t fd) |
Close a file. | |
int32_t | rt_fs_write (int32_t fd, const void *buf, uint32_t cnt) |
Write to a file. | |
int32_t | rt_fs_read (int32_t fd, void *buf, uint32_t cnt) |
Read from a file. | |
int64_t | rt_fs_seek (int32_t fd, int64_t offset, int32_t whence) |
Move the file position pointer. | |
int64_t | rt_fs_size (int32_t fd) |
Get file size. | |
int32_t | rt_fs_stat (int32_t fd, rt_fs_stat_t *stat) |
Get file status information. | |
int32_t | rt_fs_remove (const char *path) |
Remove a file or directory. | |
int32_t | rt_fs_rename (const char *oldpath, const char *newpath) |
Rename or move a file or directory. | |
An API that enables integration of standard C library with an arbitrary file system.
struct rt_fs_time_t |
Time and Date Information.
This struct contains time and date information, including seconds, minutes, hours, day of the month, month of the year and year. Values outside of the specified range are treated as invalid. Reserved bits should be ignored.
struct rt_fs_stat_t |
File Status Information.
This struct contains various attributes and metadata about a file or directory in a filesystem, including its attribute bitmap, access time, modification time, change time and filesystem specific block size and block count allocated to store the file.
Data Fields | ||
---|---|---|
uint32_t | attr | File attribute bitmap. |
rt_fs_time_t | access | Last file data access timestamp. |
rt_fs_time_t | modify | Last file data modification timestamp. |
rt_fs_time_t | change | Last file object change timestamp. |
uint32_t | blksize | The size of filesystem block. |
uint32_t | blkcount | Number of allocated filesystem blocks. |
int32_t rt_fs_open | ( | const char * | path, |
int32_t | mode | ||
) |
Open a file.
[in] | path | string specifying the pathname of the file to be opened |
[in] | mode | integer bitmap specifying the file open mode |
This function opens a file specified by the pathname.
The mode parameter is a bitmap that specifies the file open mode. The following bits are exclusive:
In addition, any combination of the values below can be set:
The file position offset shall be set to the beginning of the file unless append mode is specified.
int32_t rt_fs_close | ( | int32_t | fd | ) |
Close a file.
[in] | fd | file descriptor of an opened file |
This function closes the file associated with the file descriptor fd.
int32_t rt_fs_write | ( | int32_t | fd, |
const void * | buf, | ||
uint32_t | cnt | ||
) |
Write to a file.
[in] | fd | file descriptor of an opened file |
[in] | buf | pointer to the buffer containing data to write |
[in] | cnt | number of bytes to write |
This function shall write cnt bytes from the buffer pointed to by buf to the file associated with the open file descriptor, fd.
int32_t rt_fs_read | ( | int32_t | fd, |
void * | buf, | ||
uint32_t | cnt | ||
) |
Read from a file.
[in] | fd | file descriptor of an opened file |
[out] | buf | pointer to the buffer to store read data |
[in] | cnt | number of bytes to read |
This function reads cnt bytes from the file associated with the file descriptor fd, into the buffer pointed to by buf. The actual number of bytes read can be less than cnt.
int64_t rt_fs_seek | ( | int32_t | fd, |
int64_t | offset, | ||
int32_t | whence | ||
) |
Move the file position pointer.
[in] | fd | file descriptor of an opened file |
[in] | offset | the number of bytes to move |
[in] | whence | file position location (RT_SEEK_SET, RT_SEEK_CUR, RT_SEEK_END) |
This functions moves the file position pointer as specified with parameters offset and whence. Parameter whence can have the following possible values:
int64_t rt_fs_size | ( | int32_t | fd | ) |
Get file size.
[in] | fd | file descriptor of an opened file |
This function retrieves the size of an opened file.
int32_t rt_fs_stat | ( | int32_t | fd, |
rt_fs_stat_t * | stat | ||
) |
Get file status information.
[in] | fd | file descriptor of an opened file |
[out] | stat | pointer to a rt_fs_stat_t object to store the status information in |
This function retrieves status information about the file associated with the given file descriptor. The status information is stored in the rt_fs_stat_t struct pointed to by stat. The function shall return with error if fd is not a valid file descriptor or if parameter stat is NULL.
int32_t rt_fs_remove | ( | const char * | path | ) |
Remove a file or directory.
[in] | path | string specifying the pathname |
If removing a directory, the directory must be empty.
int32_t rt_fs_rename | ( | const char * | oldpath, |
const char * | newpath | ||
) |
Rename or move a file or directory.
[in] | oldpath | string specifying file or directory to be renamed |
[in] | newpath | string specifying the new pathname |
This function changes the name of a file or directory.
If the destination exists, it must match the source in type. If the destination is a directory, the directory must be empty.