ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
Loading...
Searching...
No Matches
fs.h
Go to the documentation of this file.
1
20#ifndef ICARUS_FS_H
21#define ICARUS_FS_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <stdint.h>
28#include <stdbool.h>
29
30/* ---- Sizing ------------------------------------------------------------ */
31
32#define FS_MAX_FILES 16
33#define FS_MAX_NAME_LEN 12 /* null-terminated, so 11 usable chars */
34#define FS_MAX_FILE_SIZE 2048 /* bytes per file */
35#define FS_TOTAL_BYTES (FS_MAX_FILES * FS_MAX_FILE_SIZE) /* 32 KB */
36
37/* ---- Types ------------------------------------------------------------- */
38
40typedef struct {
41 uint8_t slot;
42 bool valid;
43} fs_file_t;
44
46typedef struct {
47 char name[FS_MAX_NAME_LEN];
48 uint16_t size;
50
52typedef struct {
53 uint32_t total_bytes;
54 uint32_t used_bytes;
55 uint32_t free_bytes;
56 uint8_t file_count;
58
59/* ---- API --------------------------------------------------------------- */
60
65void fs_init(void);
66
72bool fs_create(const char *name, fs_file_t *out);
73
78bool fs_open(const char *name, fs_file_t *out);
79
85bool fs_write(fs_file_t *f, const uint8_t *data, uint16_t len);
86
92uint16_t fs_read(fs_file_t *f, uint8_t *buf, uint16_t len, uint16_t offset);
93
98bool fs_delete(const char *name);
99
104uint8_t fs_list(fs_file_info_t *out, uint8_t max);
105
109void fs_stats(fs_stats_t *out);
110
111/* ---- Privileged implementations (internal — do not call directly) ------ */
112
113void __fs_init(void);
114bool __fs_create(const char *name, fs_file_t *out);
115bool __fs_open(const char *name, fs_file_t *out);
116bool __fs_write(fs_file_t *f, const uint8_t *data, uint16_t len);
117uint16_t __fs_read(fs_file_t *f, uint8_t *buf, uint16_t len, uint16_t offset);
118bool __fs_delete(const char *name);
119uint8_t __fs_list(fs_file_info_t *out, uint8_t max);
120void __fs_stats(fs_stats_t *out);
121
122#ifdef __cplusplus
123}
124#endif
125
126#endif /* ICARUS_FS_H */
bool __fs_write(fs_file_t *f, const uint8_t *data, uint16_t len)
Privileged implementation of fs_write().
Definition fs.c:146
#define FS_MAX_NAME_LEN
Definition fs.h:33
bool fs_write(fs_file_t *f, const uint8_t *data, uint16_t len)
Append data to an open file.
Definition fs.c:345
bool fs_create(const char *name, fs_file_t *out)
Create a new file with the given name.
Definition fs.c:292
bool fs_delete(const char *name)
Delete a file by name.
Definition fs.c:401
void __fs_init(void)
Privileged implementation of fs_init().
Definition fs.c:76
uint8_t __fs_list(fs_file_info_t *out, uint8_t max)
Privileged implementation of fs_list().
Definition fs.c:227
bool __fs_open(const char *name, fs_file_t *out)
Privileged implementation of fs_open().
Definition fs.c:124
uint16_t fs_read(fs_file_t *f, uint8_t *buf, uint16_t len, uint16_t offset)
Read bytes from an open file at a given offset.
Definition fs.c:373
bool __fs_create(const char *name, fs_file_t *out)
Privileged implementation of fs_create().
Definition fs.c:88
void fs_stats(fs_stats_t *out)
Return aggregate filesystem statistics.
Definition fs.c:447
uint8_t fs_list(fs_file_info_t *out, uint8_t max)
Enumerate all files currently in the filesystem.
Definition fs.c:424
bool fs_open(const char *name, fs_file_t *out)
Open an existing file by name.
Definition fs.c:318
void fs_init(void)
Clear all file table entries and zero the data store.
Definition fs.c:277
void __fs_stats(fs_stats_t *out)
Privileged implementation of fs_stats().
Definition fs.c:249
uint16_t __fs_read(fs_file_t *f, uint8_t *buf, uint16_t len, uint16_t offset)
Privileged implementation of fs_read().
Definition fs.c:175
bool __fs_delete(const char *name)
Privileged implementation of fs_delete().
Definition fs.c:205
Per-file metadata returned by fs_list().
Definition fs.h:46
uint16_t size
Current number of bytes written.
Definition fs.h:48
Opaque file handle — callers hold one of these per open file.
Definition fs.h:40
uint8_t slot
Index into internal file table (0-based).
Definition fs.h:41
bool valid
True if handle references a live file entry.
Definition fs.h:42
Aggregate filesystem statistics.
Definition fs.h:52
uint32_t free_bytes
Bytes available for new data.
Definition fs.h:55
uint32_t used_bytes
Bytes occupied by all file data.
Definition fs.h:54
uint32_t total_bytes
Total storage capacity in bytes.
Definition fs.h:53
uint8_t file_count
Number of files currently stored.
Definition fs.h:56