|
oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
|
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 | |
| #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. | |
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:
ove_fs_open_init / ove_fs_close_deinit and ove_fs_opendir_init / ove_fs_closedir_deinit.OVE_HEAP_FS is defined.CONFIG_OVE_FS. | 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.
| [out] | file | Receives the opened file handle. |
| [in] | storage | Pointer to statically-allocated file storage. |
| [in] | path | Absolute path of the file to open. |
| [in] | flags | Combination of OVE_FS_O_* flags. |
CONFIG_OVE_FS. | 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.
| [in] | file | File handle returned by ove_fs_open_init. |
CONFIG_OVE_FS. | 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.
| [out] | dir | Receives the opened directory handle. |
| [in] | storage | Pointer to statically-allocated directory storage. |
| [in] | path | Absolute path of the directory to open. |
CONFIG_OVE_FS. | 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.
| [in] | dir | Directory handle returned by ove_fs_opendir_init. |
CONFIG_OVE_FS. | 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.
| [out] | file | Receives the opened file handle. |
| [in] | path | Absolute path of the file to open. |
| [in] | flags | Combination of OVE_FS_O_* flags. |
CONFIG_OVE_FS. | 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.
| [in] | dev_path | Path identifying the storage device. |
| [in] | mount_point | Absolute path to use as the mount prefix. |
| 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.
| [in] | mount_point | Mount point string passed to ove_fs_mount. |
| 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.
| [in] | file | Open file handle. |
| [out] | buf | Buffer to receive the data. |
| [in] | count | Maximum number of bytes to read. |
| [out] | bytes_read | Receives the number of bytes actually read, or NULL if not needed. |
| 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.
| [in] | file | Open file handle. |
| [in] | buf | Data to write. |
| [in] | count | Number of bytes to write. |
| [out] | bytes_written | Receives the number of bytes actually written, or NULL if not needed. |
| int ove_fs_size | ( | ove_file_t | file, |
| size_t * | out_size | ||
| ) |
Query the total size of an open file.
| [in] | file | Open file handle. |
| [out] | out_size | Receives the file size in bytes. |
| 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.
| [in] | file | Open file handle. |
| [in] | offset | Byte offset relative to whence. |
| [in] | whence | One of OVE_FS_SEEK_SET, OVE_FS_SEEK_CUR, or OVE_FS_SEEK_END. |
| long ove_fs_tell | ( | ove_file_t | file | ) |
Return the current file position.
| [in] | file | Open file handle. |
| 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.
| [in] | dir | Open directory handle. |
| [out] | entry | Pointer to a ove_dirent structure to fill. |
OVE_ERR_EOF when the directory is exhausted, or another negative error code on failure. | 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.
| [in] | path | Absolute path of the file to delete. |
| 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.
| [in] | old_path | Absolute path of the existing file or directory. |
| [in] | new_path | Absolute path for the new name or location. |