|
ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
|
Internal RAM-backed flat-file filesystem implementation. More...
Go to the source code of this file.
Data Structures | |
| struct | fs_entry_t |
Functions | |
| static int16_t | fs_find (const char *name) |
Find slot index for name, or -1 if not found. | |
| static int16_t | fs_free_slot (void) |
| Find first free slot, or -1 if full. | |
| void | __fs_init (void) |
| Privileged implementation of fs_init(). | |
| bool | __fs_create (const char *name, fs_file_t *out) |
| Privileged implementation of fs_create(). | |
| bool | __fs_open (const char *name, fs_file_t *out) |
| Privileged implementation of fs_open(). | |
| bool | __fs_write (fs_file_t *f, const uint8_t *data, uint16_t len) |
| Privileged implementation of fs_write(). | |
| uint16_t | __fs_read (fs_file_t *f, uint8_t *buf, uint16_t len, uint16_t offset) |
| Privileged implementation of fs_read(). | |
| bool | __fs_delete (const char *name) |
| Privileged implementation of fs_delete(). | |
| uint8_t | __fs_list (fs_file_info_t *out, uint8_t max) |
| Privileged implementation of fs_list(). | |
| void | __fs_stats (fs_stats_t *out) |
| Privileged implementation of fs_stats(). | |
| void | fs_init (void) |
| Clear all file table entries and zero the data store via SVC gate. | |
| bool | fs_create (const char *name, fs_file_t *out) |
| Create a new file via SVC gate. | |
| bool | fs_open (const char *name, fs_file_t *out) |
| Open an existing file by name via SVC gate. | |
| bool | fs_write (fs_file_t *f, const uint8_t *data, uint16_t len) |
| Append data to an open file via SVC gate. | |
| 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 via SVC gate. | |
| bool | fs_delete (const char *name) |
| Delete a file by name via SVC gate. | |
| uint8_t | fs_list (fs_file_info_t *out, uint8_t max) |
| Enumerate all files via SVC gate. | |
| void | fs_stats (fs_stats_t *out) |
| Return aggregate filesystem statistics via SVC gate. | |
Variables | |
| static fs_entry_t | fs_table [16] |
| static uint8_t | fs_data [16][2048] |
Internal RAM-backed flat-file filesystem implementation.
The store is a static byte array divided into FS_MAX_FILES fixed-size blocks. A parallel table of fs_entry_t structs tracks name, size, and occupancy for each block.
The __fs_* prefixed functions are the privileged implementations that execute inside the SVC handler with full access to kernel data. The unprefixed public functions issue SVC instructions so that unprivileged tasks can use the filesystem without triggering MemManage faults.
Definition in file fs.c.
| bool __fs_create | ( | const char * | name, |
| fs_file_t * | out | ||
| ) |
Privileged implementation of fs_create().
| [in] | name | Null-terminated file name. |
| [out] | out | File handle written on success. |
| true | File created. |
| false | Full, duplicate, or invalid name. |
Definition at line 88 of file fs.c.
References fs_data, fs_find(), fs_free_slot(), FS_MAX_FILE_SIZE, FS_MAX_NAME_LEN, fs_table, fs_entry_t::name, fs_entry_t::size, fs_file_t::slot, fs_entry_t::used, and fs_file_t::valid.
Referenced by fs_create(), and SVC_Handler_C().
| bool __fs_delete | ( | const char * | name | ) |
Privileged implementation of fs_delete().
| [in] | name | File name to remove. |
| true | File found and deleted. |
| false | File does not exist. |
Definition at line 205 of file fs.c.
References fs_data, fs_find(), FS_MAX_FILE_SIZE, and fs_table.
Referenced by fs_delete(), and SVC_Handler_C().
| void __fs_init | ( | void | ) |
| uint8_t __fs_list | ( | fs_file_info_t * | out, |
| uint8_t | max | ||
| ) |
Privileged implementation of fs_list().
| [out] | out | Array of file info entries. |
| [in] | max | Maximum entries to write. |
Definition at line 227 of file fs.c.
References FS_MAX_FILES, FS_MAX_NAME_LEN, fs_table, fs_file_info_t::name, fs_file_info_t::size, and fs_entry_t::size.
Referenced by fs_list(), and SVC_Handler_C().
| bool __fs_open | ( | const char * | name, |
| fs_file_t * | out | ||
| ) |
Privileged implementation of fs_open().
| [in] | name | File name to look up. |
| [out] | out | File handle written on success. |
| true | File found and handle populated. |
| false | File does not exist. |
Definition at line 124 of file fs.c.
References fs_find(), fs_file_t::slot, and fs_file_t::valid.
Referenced by fs_open(), and SVC_Handler_C().
| uint16_t __fs_read | ( | fs_file_t * | f, |
| uint8_t * | buf, | ||
| uint16_t | len, | ||
| uint16_t | offset | ||
| ) |
Privileged implementation of fs_read().
| [in] | f | File handle. |
| [out] | buf | Destination buffer. |
| [in] | len | Maximum bytes to read. |
| [in] | offset | Byte offset into the file. |
len near EOF), or 0 on error. Definition at line 175 of file fs.c.
References fs_data, FS_MAX_FILES, fs_table, fs_entry_t::size, fs_file_t::slot, and fs_file_t::valid.
Referenced by fs_read(), and SVC_Handler_C().
| void __fs_stats | ( | fs_stats_t * | out | ) |
Privileged implementation of fs_stats().
| [out] | out | Aggregate filesystem statistics. |
Definition at line 249 of file fs.c.
References fs_stats_t::file_count, fs_stats_t::free_bytes, FS_MAX_FILE_SIZE, FS_MAX_FILES, fs_table, fs_entry_t::size, fs_stats_t::total_bytes, and fs_stats_t::used_bytes.
Referenced by fs_stats(), and SVC_Handler_C().
| bool __fs_write | ( | fs_file_t * | f, |
| const uint8_t * | data, | ||
| uint16_t | len | ||
| ) |
Privileged implementation of fs_write().
| [in] | f | File handle. |
| [in] | data | Bytes to append. |
| [in] | len | Number of bytes. |
| true | Data appended. |
| false | Invalid handle, null data, or would exceed max size. |
Definition at line 146 of file fs.c.
References fs_data, FS_MAX_FILE_SIZE, FS_MAX_FILES, fs_table, fs_entry_t::size, fs_file_t::slot, and fs_file_t::valid.
Referenced by fs_write(), and SVC_Handler_C().
| bool fs_create | ( | const char * | name, |
| fs_file_t * | out | ||
| ) |
Create a new file via SVC gate.
Create a new file with the given name.
| [in] | name | Null-terminated file name. |
| [out] | out | File handle written on success. |
| true | File created. |
| false | Full, duplicate, or invalid name. |
Definition at line 292 of file fs.c.
References __fs_create(), and SVC_FS_CREATE.
| bool fs_delete | ( | const char * | name | ) |
Delete a file by name via SVC gate.
Delete a file by name.
| [in] | name | File name to remove. |
| true | File deleted. |
| false | File does not exist. |
Definition at line 401 of file fs.c.
References __fs_delete(), and SVC_FS_DELETE.
|
static |
Find slot index for name, or -1 if not found.
Definition at line 48 of file fs.c.
References FS_MAX_FILES, FS_MAX_NAME_LEN, and fs_table.
Referenced by __fs_create(), __fs_delete(), and __fs_open().
|
static |
Find first free slot, or -1 if full.
Definition at line 59 of file fs.c.
References FS_MAX_FILES, and fs_table.
Referenced by __fs_create().
| void fs_init | ( | void | ) |
Clear all file table entries and zero the data store via SVC gate.
Clear all file table entries and zero the data store.
Definition at line 277 of file fs.c.
References __fs_init(), and SVC_FS_INIT.
| uint8_t fs_list | ( | fs_file_info_t * | out, |
| uint8_t | max | ||
| ) |
Enumerate all files via SVC gate.
Enumerate all files currently in the filesystem.
| [out] | out | Array of file info entries. |
| [in] | max | Maximum entries to write. |
Definition at line 424 of file fs.c.
References __fs_list(), and SVC_FS_LIST.
| bool fs_open | ( | const char * | name, |
| fs_file_t * | out | ||
| ) |
Open an existing file by name via SVC gate.
Open an existing file by name.
| [in] | name | File name to look up. |
| [out] | out | File handle written on success. |
| true | File found. |
| false | File does not exist. |
Definition at line 318 of file fs.c.
References __fs_open(), and SVC_FS_OPEN.
| 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 via SVC gate.
Read bytes from an open file at a given offset.
| [in] | f | File handle. |
| [out] | buf | Destination buffer. |
| [in] | len | Maximum bytes to read. |
| [in] | offset | Byte offset into the file. |
Definition at line 373 of file fs.c.
References __fs_read(), and SVC_FS_READ.
| void fs_stats | ( | fs_stats_t * | out | ) |
Return aggregate filesystem statistics via SVC gate.
Return aggregate filesystem statistics.
| [out] | out | Statistics structure to fill. |
Definition at line 447 of file fs.c.
References __fs_stats(), and SVC_FS_STATS.
| bool fs_write | ( | fs_file_t * | f, |
| const uint8_t * | data, | ||
| uint16_t | len | ||
| ) |
Append data to an open file via SVC gate.
Append data to an open file.
| [in] | f | File handle. |
| [in] | data | Bytes to append. |
| [in] | len | Number of bytes. |
| true | Data appended. |
| false | Invalid handle, null data, or would exceed max size. |
Definition at line 345 of file fs.c.
References __fs_write(), and SVC_FS_WRITE.
|
static |
Definition at line 43 of file fs.c.
Referenced by __fs_create(), __fs_delete(), __fs_init(), __fs_read(), and __fs_write().
|
static |
Definition at line 42 of file fs.c.
Referenced by __fs_create(), __fs_delete(), __fs_init(), __fs_list(), __fs_read(), __fs_stats(), __fs_write(), fs_find(), and fs_free_slot().