Standard C Library File, I/O and OS Retargeting
All Data Structures Functions Variables Typedefs Modules Pages
File Interface

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. More...
 
int32_t rt_fs_close (int32_t fd)
 Close a file. More...
 
int32_t rt_fs_write (int32_t fd, const void *buf, uint32_t cnt)
 Write to a file. More...
 
int32_t rt_fs_read (int32_t fd, void *buf, uint32_t cnt)
 Read from a file. More...
 
int64_t rt_fs_seek (int32_t fd, int64_t offset, int32_t whence)
 Move the file position pointer. More...
 
int64_t rt_fs_size (int32_t fd)
 Get file size. More...
 
int32_t rt_fs_stat (int32_t fd, rt_fs_stat_t *stat)
 Get file status information. More...
 
int32_t rt_fs_remove (const char *path)
 Remove a file or directory. More...
 
int32_t rt_fs_rename (const char *oldpath, const char *newpath)
 Rename or move a file or directory. More...
 

Description


Data Structure Documentation

◆ rt_fs_time_t

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.

Data Fields
uint8_t day Day of month [1, 31].
uint8_t hour Hours [0, 23].
uint8_t min Minutes [0, 59].
uint8_t mon Month of year [0, 11].
uint8_t rsvd Reserved.
uint8_t sec Seconds [0, 60].
uint16_t year Year.

◆ rt_fs_stat_t

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
rt_fs_time_t access Last file data access timestamp.
uint32_t attr File attribute bitmap.
uint32_t blkcount Number of allocated filesystem blocks.
uint32_t blksize The size of filesystem block.
rt_fs_time_t change Last file object change timestamp.
rt_fs_time_t modify Last file data modification timestamp.

Function Documentation

◆ rt_fs_close()

int32_t rt_fs_close ( int32_t  fd)

Close a file.

This function closes the file associated with the file descriptor fd.

Parameters
[in]fdfile descriptor of an opened file
Returns
zero if the file was successfully closed, or error code on failure

◆ rt_fs_open()

int32_t rt_fs_open ( const char *  path,
int32_t  mode 
)

Open a file.

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:

  • FS_OPEN_RDONLY: open file for reading only
  • FS_OPEN_WRONLY: open file for writing only
  • FS_OPEN_RDWR: open file for reading and writing

In addition, any combination of the values below can be set:

  • FS_OPEN_APPEND: if set, the file offset is set to the end of file prior to each write
  • FS_OPEN_CREATE: if set, the file is created if it does not exist
  • FS_OPEN_TRUNCATE: if set, the size of an existing file opened for writing is truncated to zero

The file position offset shall be set to the beginning of the file unless append mode is specified.

Parameters
[in]pathstring specifying the pathname of the file to be opened
[in]modeinteger bitmap specifying the file open mode
Returns
a non-negative integer representing the file descriptor on success, or error code on failure

◆ rt_fs_read()

int32_t rt_fs_read ( int32_t  fd,
void *  buf,
uint32_t  cnt 
)

Read from a file.

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.

Parameters
[in]fdfile descriptor of an opened file
[out]bufpointer to the buffer to store read data
[in]cntnumber of bytes to read
Returns
number of bytes actually read, 0 at the EOF, or error code on failure

◆ rt_fs_remove()

int32_t rt_fs_remove ( const char *  path)

Remove a file or directory.

If removing a directory, the directory must be empty.

Parameters
[in]pathstring specifying the pathname
Returns
zero if the file or directory was successfully removed, or error code on failure

◆ rt_fs_rename()

int32_t rt_fs_rename ( const char *  oldpath,
const char *  newpath 
)

Rename or move a file or directory.

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.

Parameters
[in]oldpathstring specifying file or directory to be renamed
[in]newpathstring specifying the new pathname
Returns
zero if the file or directory was successfully renamed or moved, or error code on failure

◆ rt_fs_seek()

int64_t rt_fs_seek ( int32_t  fd,
int64_t  offset,
int32_t  whence 
)

Move the file position pointer.

This functions moves the file position pointer as specified with parameters offset and whence. Parameter whence can have the following possible values:

  • RT_SEEK_SET: set the file position pointer to offset bytes from the start of the file
  • RT_SEEK_CUR: set the file position pointer to offset bytes from the current location
  • RT_SEEK_END: set the file position pointer to offset bytes from the end of the file
Parameters
[in]fdfile descriptor of an opened file
[in]offsetthe number of bytes to move
[in]whencefile position location (RT_SEEK_SET, RT_SEEK_CUR, RT_SEEK_END)
Returns
current file position from the beginning of the file, or error code on failure

◆ rt_fs_size()

int64_t rt_fs_size ( int32_t  fd)

Get file size.

This function retrieves the size of an opened file.

Parameters
[in]fdfile descriptor of an opened file
Returns
file size in bytes, or error code on failure

◆ rt_fs_stat()

int32_t rt_fs_stat ( int32_t  fd,
rt_fs_stat_t stat 
)

Get file status information.

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.

Parameters
[in]fdfile descriptor of an opened file
[out]statpointer to a rt_fs_stat_t object to store the status information in
Returns
zero if the file status was successfully retrieved, or error code on failure

◆ rt_fs_write()

int32_t rt_fs_write ( int32_t  fd,
const void *  buf,
uint32_t  cnt 
)

Write to a file.

This function shall write cnt bytes from the buffer pointed to by buf to the file associated with the open file descriptor, fd.

Parameters
[in]fdfile descriptor of an opened file
[in]bufpointer to the buffer containing data to write
[in]cntnumber of bytes to write
Returns
number of bytes actually written, or error code on failure