oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
fs.h
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
31#ifndef OVE_FS_H
32#define OVE_FS_H
33
34#include "ove/types.h"
35#include "ove_config.h"
36#include "ove/storage.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
49#define OVE_FS_O_READ 0x01
51#define OVE_FS_O_WRITE 0x02
53#define OVE_FS_O_CREATE 0x04
55#define OVE_FS_O_APPEND 0x08
64#define OVE_FS_SEEK_SET 0
66#define OVE_FS_SEEK_CUR 1
68#define OVE_FS_SEEK_END 2
74struct ove_dirent {
75 char name[256];
76 unsigned int size;
77 int is_dir;
78};
79
80#ifdef CONFIG_OVE_FS
81
96int ove_fs_open_init(ove_file_t *file, ove_file_storage_t *storage,
97 const char *path, int flags);
98
110
124int ove_fs_opendir_init(ove_dir_t *dir, ove_dir_storage_t *storage,
125 const char *path);
126
137
151int ove_fs_open(ove_file_t *file, const char *path, int flags);
152
157
161int ove_fs_opendir(ove_dir_t *dir, const char *path);
162
167
179int ove_fs_mount(const char *dev_path, const char *mount_point);
180
190void ove_fs_unmount(const char *mount_point);
191
205int ove_fs_read(ove_file_t file, void *buf, size_t count,
206 size_t *bytes_read);
207
223int ove_fs_write(ove_file_t file, const void *buf, size_t count,
224 size_t *bytes_written);
225
233int ove_fs_size(ove_file_t file, size_t *out_size);
234
247int ove_fs_seek(ove_file_t file, long offset, int whence);
248
256
269int ove_fs_readdir(ove_dir_t dir, struct ove_dirent *entry);
270
280int ove_fs_unlink(const char *path);
281
292int ove_fs_rename(const char *old_path, const char *new_path);
293
294#else /* !CONFIG_OVE_FS */
295
296static inline int ove_fs_mount(const char *dev_path, const char *mount_point) { (void)dev_path; (void)mount_point; return OVE_ERR_NOT_SUPPORTED; }
297static inline void ove_fs_unmount(const char *mount_point) { (void)mount_point; }
298static inline int ove_fs_open(ove_file_t *file, const char *path, int flags) { (void)file; (void)path; (void)flags; return OVE_ERR_NOT_SUPPORTED; }
299static inline int ove_fs_close(ove_file_t file) { (void)file; return OVE_ERR_NOT_SUPPORTED; }
300static inline int ove_fs_read(ove_file_t file, void *buf, size_t count, size_t *bytes_read) { (void)file; (void)buf; (void)count; (void)bytes_read; return OVE_ERR_NOT_SUPPORTED; }
301static inline int ove_fs_write(ove_file_t file, const void *buf, size_t count, size_t *bytes_written) { (void)file; (void)buf; (void)count; (void)bytes_written; return OVE_ERR_NOT_SUPPORTED; }
302static inline int ove_fs_size(ove_file_t file, size_t *out_size) { (void)file; (void)out_size; return OVE_ERR_NOT_SUPPORTED; }
303static inline int ove_fs_seek(ove_file_t file, long offset, int whence) { (void)file; (void)offset; (void)whence; return OVE_ERR_NOT_SUPPORTED; }
304static inline long ove_fs_tell(ove_file_t file) { (void)file; return -1; }
305static inline int ove_fs_opendir(ove_dir_t *dir, const char *path) { (void)dir; (void)path; return OVE_ERR_NOT_SUPPORTED; }
306static inline int ove_fs_readdir(ove_dir_t dir, struct ove_dirent *entry) { (void)dir; (void)entry; return OVE_ERR_NOT_SUPPORTED; }
307static inline int ove_fs_closedir(ove_dir_t dir) { (void)dir; return OVE_ERR_NOT_SUPPORTED; }
308static inline int ove_fs_unlink(const char *path) { (void)path; return OVE_ERR_NOT_SUPPORTED; }
309static inline int ove_fs_rename(const char *old_path, const char *new_path) { (void)old_path; (void)new_path; return OVE_ERR_NOT_SUPPORTED; }
310
311#endif /* CONFIG_OVE_FS */
312
313#ifdef __cplusplus
314}
315#endif
316
/* end of ove_fs group */
318
319#endif /* OVE_FS_H */
int ove_fs_size(ove_file_t file, size_t *out_size)
Query the total size of an open file.
int ove_fs_readdir(ove_dir_t dir, struct ove_dirent *entry)
Read the next entry from an open directory.
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.
void ove_fs_unmount(const char *mount_point)
Unmount a previously mounted storage device.
int ove_fs_closedir_deinit(ove_dir_t dir)
Close a statically-allocated directory handle.
int ove_fs_unlink(const char *path)
Delete a file by path.
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_open(ove_file_t *file, const char *path, int flags)
Open a file.
int ove_fs_rename(const char *old_path, const char *new_path)
Rename or move a file.
long ove_fs_tell(ove_file_t file)
Return the current file position.
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_seek(ove_file_t file, long offset, int whence)
Reposition the file read/write offset.
int ove_fs_close_deinit(ove_file_t file)
Close a statically-allocated file handle.
int ove_fs_mount(const char *dev_path, const char *mount_point)
Mount a storage device at a virtual path prefix.
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_write(ove_file_t file, const void *buf, size_t count, size_t *bytes_written)
Write bytes to an open file.
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38
struct ove_dir * ove_dir_t
Opaque handle for an open directory.
Definition types.h:115
struct ove_file * ove_file_t
Opaque handle for an open file.
Definition types.h:112
Directory entry descriptor returned by ove_fs_readdir.
Definition fs.h:74
char name[256]
Null-terminated entry name (not full path).
Definition fs.h:75
int is_dir
Non-zero if the entry is a directory.
Definition fs.h:77
unsigned int size
File size in bytes; 0 for directories.
Definition fs.h:76