objc

fs.h
Go to the documentation of this file.
1 
16 #pragma once
17 #include <stdbool.h>
18 #include <stddef.h>
19 #include <stdint.h>
20 
22 // GLOBALS
23 
24 #define FS_PATH_MAX 255
25 #define FS_PATH_SEPARATOR '/'
26 
27 // TYPES
29 
30 typedef struct fs_volume_t fs_volume_t;
31 
36 typedef struct {
38  bool dir;
39  char path[FS_PATH_MAX + 1];
40  const char *name;
43  size_t size;
45  void *ctx;
46 } fs_file_t;
47 
49 // LIFECYCLE
50 
62 extern fs_volume_t *fs_vol_init_memory(size_t size);
63 
76 extern fs_volume_t *fs_vol_init_file(const char *path, size_t size);
77 
89 extern fs_volume_t *fs_vol_init_flash(size_t size);
90 
99 extern void fs_vol_finalize(fs_volume_t *volume);
100 
110 extern size_t fs_vol_size(fs_volume_t *volume, size_t *free);
111 
121 extern bool fs_vol_readdir(fs_volume_t *volume, const char *path,
122  fs_file_t *iterator);
123 
132 extern fs_file_t fs_vol_stat(fs_volume_t *volume, const char *path);
133 
142 extern bool fs_vol_mkdir(fs_volume_t *volume, const char *path);
143 
152 extern bool fs_vol_remove(fs_volume_t *volume, const char *path);
153 
163 extern bool fs_vol_move(fs_volume_t *volume, const char *old_path,
164  const char *new_path);
165 
174 fs_file_t fs_file_create(fs_volume_t *volume, const char *path);
175 
185 fs_file_t fs_file_open(fs_volume_t *volume, const char *path, bool write);
186 
193 bool fs_file_close(fs_file_t *file);
194 
204 size_t fs_file_read(fs_file_t *file, void *buffer, size_t size);
205 
215 size_t fs_file_write(fs_file_t *file, const void *buffer, size_t size);
216 
225 bool fs_file_seek(fs_file_t *file, size_t offset);
fs_file_t fs_file_open(fs_volume_t *volume, const char *path, bool write)
Open an existing file for read/write.
fs_volume_t * volume
Owning volume (set by APIs)
Definition: fs.h:37
bool fs_file_close(fs_file_t *file)
Close an opened file.
bool fs_vol_readdir(fs_volume_t *volume, const char *path, fs_file_t *iterator)
Iterate directory entries.
fs_volume_t * fs_vol_init_file(const char *path, size_t size)
Open or create a host file–backed persistent volume.
bool fs_vol_remove(fs_volume_t *volume, const char *path)
Remove a file or (empty) directory.
size_t fs_file_write(fs_file_t *file, const void *buffer, size_t size)
Write data to an opened file.
bool dir
True if directory, false if regular file.
Definition: fs.h:38
void * ctx
Opaque iterator cursor (do not modify)
Definition: fs.h:45
File and directory metadata.
Definition: fs.h:36
fs_volume_t * fs_vol_init_flash(size_t size)
Open or create a non-volatile flash-backed persistent volume.
size_t fs_vol_size(fs_volume_t *volume, size_t *free)
Return total addressable size of a mounted volume.
bool fs_file_seek(fs_file_t *file, size_t offset)
Seek to a position within an opened file.
#define FS_PATH_MAX
Maximum length of a single path component.
Definition: fs.h:24
struct fs_volume_t fs_volume_t
Opaque filesystem volume handle.
Definition: fs.h:30
fs_volume_t * fs_vol_init_memory(size_t size)
Create a new volatile (RAM) filesystem volume.
bool fs_vol_mkdir(fs_volume_t *volume, const char *path)
Create a directory.
void fs_vol_finalize(fs_volume_t *volume)
Unmount and release all resources for a volume.
size_t fs_file_read(fs_file_t *file, void *buffer, size_t size)
Read data from an opened file.
bool fs_vol_move(fs_volume_t *volume, const char *old_path, const char *new_path)
Move or rename a file/directory.
fs_file_t fs_file_create(fs_volume_t *volume, const char *path)
Create a new file or truncate an existing file to zero length.
fs_file_t fs_vol_stat(fs_volume_t *volume, const char *path)
Lookup file or directory metadata for a path.