oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
Data Structures | Functions
File System

VFS abstraction for portable file and directory access. More...

Data Structures

struct  ove_dirent
 Directory entry descriptor returned by ove_fs_readdir. More...
 

Functions

int ove_fs_open_init (ove_file_t *file, ove_file_storage_t *storage, const char *path, int flags)
 Open a file using caller-provided static storage.
 
int ove_fs_close_deinit (ove_file_t file)
 Close a statically-allocated file handle.
 
int ove_fs_opendir_init (ove_dir_t *dir, ove_dir_storage_t *storage, const char *path)
 Open a directory using caller-provided static storage.
 
int ove_fs_closedir_deinit (ove_dir_t dir)
 Close a statically-allocated directory handle.
 
int ove_fs_open (ove_file_t *file, const char *path, int flags)
 Open a file.
 
int ove_fs_close (ove_file_t file)
 Close a file handle returned by ove_fs_open.
 
int ove_fs_opendir (ove_dir_t *dir, const char *path)
 Open a directory (heap or backend-managed allocation).
 
int ove_fs_closedir (ove_dir_t dir)
 Close a directory handle returned by ove_fs_opendir.
 
int ove_fs_mount (const char *dev_path, const char *mount_point)
 Mount a storage device at a virtual path prefix.
 
void ove_fs_unmount (const char *mount_point)
 Unmount a previously mounted storage device.
 
int ove_fs_read (ove_file_t file, void *buf, size_t count, size_t *bytes_read)
 Read bytes from an open file.
 
int ove_fs_write (ove_file_t file, const void *buf, size_t count, size_t *bytes_written)
 Write bytes to an open file.
 
int ove_fs_size (ove_file_t file, size_t *out_size)
 Query the total size of an open file.
 
int ove_fs_seek (ove_file_t file, long offset, int whence)
 Reposition the file read/write offset.
 
long ove_fs_tell (ove_file_t file)
 Return the current file position.
 
int ove_fs_readdir (ove_dir_t dir, struct ove_dirent *entry)
 Read the next entry from an open directory.
 
int ove_fs_unlink (const char *path)
 Delete a file by path.
 
int ove_fs_rename (const char *old_path, const char *new_path)
 Rename or move a file.
 

File open flags

Flags passed to ove_fs_open or ove_fs_open_init. Flags may be combined with bitwise OR.

#define OVE_FS_O_READ   0x01
 Open for reading.
 
#define OVE_FS_O_WRITE   0x02
 Open for writing.
 
#define OVE_FS_O_CREATE   0x04
 Create the file if it does not exist.
 
#define OVE_FS_O_APPEND   0x08
 Seek to the end of the file before each write.
 

Seek whence constants

Passed as the whence argument to ove_fs_seek.

#define OVE_FS_SEEK_SET   0
 Seek relative to the beginning of the file.
 
#define OVE_FS_SEEK_CUR   1
 Seek relative to the current file position.
 
#define OVE_FS_SEEK_END   2
 Seek relative to the end of the file.
 

Detailed Description

VFS abstraction for portable file and directory access.

Provides a thin virtual file system (VFS) layer that maps POSIX-like file and directory operations onto the underlying RTOS storage backend. Volumes are mounted by path prefix, and all subsequent operations use absolute path strings.

File and directory handles follow the same dual-allocation pattern used elsewhere in oveRTOS:

Note
Requires CONFIG_OVE_FS.

Function Documentation

◆ ove_fs_open_init()

int ove_fs_open_init ( ove_file_t file,
ove_file_storage_t *  storage,
const char *  path,
int  flags 
)

Open a file using caller-provided static storage.

Opens the file at path with the given flags and stores the resulting handle in file. The caller must ensure storage remains valid for the lifetime of the open file.

Parameters
[out]fileReceives the opened file handle.
[in]storagePointer to statically-allocated file storage.
[in]pathAbsolute path of the file to open.
[in]flagsCombination of OVE_FS_O_* flags.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_FS.

◆ ove_fs_close_deinit()

int ove_fs_close_deinit ( ove_file_t  file)

Close a statically-allocated file handle.

Flushes any pending writes and releases the RTOS file resources. The storage memory is not freed.

Parameters
[in]fileFile handle returned by ove_fs_open_init.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_FS.

◆ ove_fs_opendir_init()

int ove_fs_opendir_init ( ove_dir_t dir,
ove_dir_storage_t *  storage,
const char *  path 
)

Open a directory using caller-provided static storage.

Opens the directory at path and stores the resulting handle in dir. Use ove_fs_readdir to iterate entries and ove_fs_closedir_deinit to close.

Parameters
[out]dirReceives the opened directory handle.
[in]storagePointer to statically-allocated directory storage.
[in]pathAbsolute path of the directory to open.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_FS.

◆ ove_fs_closedir_deinit()

int ove_fs_closedir_deinit ( ove_dir_t  dir)

Close a statically-allocated directory handle.

Releases the RTOS directory resources. The storage memory is not freed.

Parameters
[in]dirDirectory handle returned by ove_fs_opendir_init.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_FS.

◆ ove_fs_open()

int ove_fs_open ( ove_file_t file,
const char *  path,
int  flags 
)

Open a file.

Opens the file at path with the given flags. The returned handle must be closed with ove_fs_close when no longer needed. In zero-heap mode, the backend uses a static pool instead of malloc.

Parameters
[out]fileReceives the opened file handle.
[in]pathAbsolute path of the file to open.
[in]flagsCombination of OVE_FS_O_* flags.
Returns
OVE_OK on success, negative error code on failure.
Note
Requires CONFIG_OVE_FS.

◆ ove_fs_mount()

int ove_fs_mount ( const char *  dev_path,
const char *  mount_point 
)

Mount a storage device at a virtual path prefix.

Associates the block device at dev_path with the mount point mount_point. All file and directory paths rooted at mount_point will be dispatched to this device.

Parameters
[in]dev_pathPath identifying the storage device.
[in]mount_pointAbsolute path to use as the mount prefix.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_fs_unmount()

void ove_fs_unmount ( const char *  mount_point)

Unmount a previously mounted storage device.

Flushes any pending data and detaches the device associated with mount_point. All file handles under this mount point must be closed before calling this function.

Parameters
[in]mount_pointMount point string passed to ove_fs_mount.

◆ ove_fs_read()

int ove_fs_read ( ove_file_t  file,
void *  buf,
size_t  count,
size_t *  bytes_read 
)

Read bytes from an open file.

Reads up to count bytes starting at the current file position into buf. The file position advances by the number of bytes actually read.

Parameters
[in]fileOpen file handle.
[out]bufBuffer to receive the data.
[in]countMaximum number of bytes to read.
[out]bytes_readReceives the number of bytes actually read, or NULL if not needed.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_fs_write()

int ove_fs_write ( ove_file_t  file,
const void *  buf,
size_t  count,
size_t *  bytes_written 
)

Write bytes to an open file.

Writes up to count bytes from buf at the current file position. The file position advances by the number of bytes actually written. If the file was opened with OVE_FS_O_APPEND the write position is set to the end of file before each write.

Parameters
[in]fileOpen file handle.
[in]bufData to write.
[in]countNumber of bytes to write.
[out]bytes_writtenReceives the number of bytes actually written, or NULL if not needed.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_fs_size()

int ove_fs_size ( ove_file_t  file,
size_t *  out_size 
)

Query the total size of an open file.

Parameters
[in]fileOpen file handle.
[out]out_sizeReceives the file size in bytes.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_fs_seek()

int ove_fs_seek ( ove_file_t  file,
long  offset,
int  whence 
)

Reposition the file read/write offset.

Moves the current position of file to offset bytes relative to the position described by whence.

Parameters
[in]fileOpen file handle.
[in]offsetByte offset relative to whence.
[in]whenceOne of OVE_FS_SEEK_SET, OVE_FS_SEEK_CUR, or OVE_FS_SEEK_END.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_fs_tell()

long ove_fs_tell ( ove_file_t  file)

Return the current file position.

Parameters
[in]fileOpen file handle.
Returns
Current byte offset from the start of the file, or -1 on error.

◆ ove_fs_readdir()

int ove_fs_readdir ( ove_dir_t  dir,
struct ove_dirent entry 
)

Read the next entry from an open directory.

Fills entry with information about the next directory entry and advances the internal iterator. Returns a specific error when no more entries are available.

Parameters
[in]dirOpen directory handle.
[out]entryPointer to a ove_dirent structure to fill.
Returns
OVE_OK if an entry was read, OVE_ERR_EOF when the directory is exhausted, or another negative error code on failure.

◆ ove_fs_unlink()

int ove_fs_unlink ( const char *  path)

Delete a file by path.

Removes the file at path from the file system. The file must not currently be open.

Parameters
[in]pathAbsolute path of the file to delete.
Returns
OVE_OK on success, negative error code on failure.

◆ ove_fs_rename()

int ove_fs_rename ( const char *  old_path,
const char *  new_path 
)

Rename or move a file.

Renames the file or directory at old_path to new_path. Both paths must reside on the same mounted volume.

Parameters
[in]old_pathAbsolute path of the existing file or directory.
[in]new_pathAbsolute path for the new name or location.
Returns
OVE_OK on success, negative error code on failure.