oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
fs.h
Go to the documentation of this file.
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
32#ifndef OVE_FS_H
33#define OVE_FS_H
34
35#include "ove/types.h"
36#include "ove_config.h"
37#include "ove/storage.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
50#define OVE_FS_O_READ 0x01
52#define OVE_FS_O_WRITE 0x02
54#define OVE_FS_O_CREATE 0x04
56#define OVE_FS_O_APPEND 0x08
65#define OVE_FS_SEEK_SET 0
67#define OVE_FS_SEEK_CUR 1
69#define OVE_FS_SEEK_END 2
75struct ove_dirent {
76 char name[256];
77 unsigned int size;
78 int is_dir;
79};
80
81#ifdef CONFIG_OVE_FS
82
97int ove_fs_open_init(ove_file_t *file, ove_file_storage_t *storage, const char *path, int flags);
98
110
124int ove_fs_opendir_init(ove_dir_t *dir, ove_dir_storage_t *storage, const char *path);
125
136
151int ove_fs_open(ove_file_t *file, const char *path, int flags);
152
160
170int ove_fs_opendir(ove_dir_t *dir, const char *path);
171
179
191int ove_fs_mount(const char *dev_path, const char *mount_point);
192
202void ove_fs_unmount(const char *mount_point);
203
217int ove_fs_read(ove_file_t file, void *buf, size_t count, size_t *bytes_read);
218
234int ove_fs_write(ove_file_t file, const void *buf, size_t count, size_t *bytes_written);
235
243int ove_fs_size(ove_file_t file, size_t *out_size);
244
257int ove_fs_seek(ove_file_t file, long offset, int whence);
258
266
279int ove_fs_readdir(ove_dir_t dir, struct ove_dirent *entry);
280
290int ove_fs_unlink(const char *path);
291
302int ove_fs_rename(const char *old_path, const char *new_path);
303
304#else /* !CONFIG_OVE_FS */
305
306static inline int ove_fs_mount(const char *dev_path, const char *mount_point)
307{
308 (void)dev_path;
309 (void)mount_point;
311}
312static inline void ove_fs_unmount(const char *mount_point)
313{
314 (void)mount_point;
315}
316static inline int ove_fs_open(ove_file_t *file, const char *path, int flags)
317{
318 (void)file;
319 (void)path;
320 (void)flags;
322}
323static inline int ove_fs_close(ove_file_t file)
324{
325 (void)file;
327}
328static inline int ove_fs_read(ove_file_t file, void *buf, size_t count, size_t *bytes_read)
329{
330 (void)file;
331 (void)buf;
332 (void)count;
333 (void)bytes_read;
335}
336static inline int ove_fs_write(ove_file_t file, const void *buf, size_t count,
337 size_t *bytes_written)
338{
339 (void)file;
340 (void)buf;
341 (void)count;
342 (void)bytes_written;
344}
345static inline int ove_fs_size(ove_file_t file, size_t *out_size)
346{
347 (void)file;
348 (void)out_size;
350}
351static inline int ove_fs_seek(ove_file_t file, long offset, int whence)
352{
353 (void)file;
354 (void)offset;
355 (void)whence;
357}
358static inline long ove_fs_tell(ove_file_t file)
359{
360 (void)file;
361 return -1;
362}
363static inline int ove_fs_opendir(ove_dir_t *dir, const char *path)
364{
365 (void)dir;
366 (void)path;
368}
369static inline int ove_fs_readdir(ove_dir_t dir, struct ove_dirent *entry)
370{
371 (void)dir;
372 (void)entry;
374}
375static inline int ove_fs_closedir(ove_dir_t dir)
376{
377 (void)dir;
379}
380static inline int ove_fs_unlink(const char *path)
381{
382 (void)path;
384}
385static inline int ove_fs_rename(const char *old_path, const char *new_path)
386{
387 (void)old_path;
388 (void)new_path;
390}
391
392#endif /* CONFIG_OVE_FS */
393
394#ifdef __cplusplus
395}
396#endif
397
/* end of ove_fs group */
399
400#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 (heap-backed handle).
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-backed handle).
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.
struct ove_dir * ove_dir_t
Opaque handle for an open directory.
Definition types.h:241
struct ove_file * ove_file_t
Opaque handle for an open file.
Definition types.h:238
@ OVE_ERR_NOT_SUPPORTED
Definition types.h:98
Directory entry descriptor returned by ove_fs_readdir.
Definition fs.h:75
char name[256]
Null-terminated entry name (not full path).
Definition fs.h:76
int is_dir
Non-zero if the entry is a directory.
Definition fs.h:78
unsigned int size
File size in bytes; 0 for directories.
Definition fs.h:77