Skip to main content
The RAMFS (RAM filesystem) implements the low-level filesystem layer inside MVH Kernel. It stores all files and directories in kernel-managed heap memory and exposes a flat, path-based interface directly tied to the RAMFS driver. For most purposes you should use the vfs_* functions instead, which wrap the same RAMFS operations behind the Virtual Filesystem mount abstraction. The fs_* API documented here is intended for driver authors and kernel subsystems that need direct access below the VFS mount layer.
Prefer the vfs_* API for general use. The VFS handles mount-point resolution and remains correct if additional filesystem backends are introduced. Only call fs_* functions directly when you specifically need to bypass the VFS mount layer.

Constants

All constants are defined in mvh/fs.h.

The fs_entry_t Struct

Directory listing functions populate arrays of fs_entry_t. Each element describes one file or subdirectory found inside the listed path.
char[24]
Null-terminated filename. At most FS_NAME_MAX - 1 (23) usable characters.
uint8_t
Set to 1 when the entry is a directory, 0 when it is a regular file.
uint16_t
Content size in bytes. Always 0 for directories. Never exceeds FS_DATA_MAX (256) for files.

Functions

fs_init

Initialize the RAMFS driver and prepare the root directory. You must call this before any other fs_* function. When using the VFS API, vfs_init calls fs_init internally — do not call it a second time.
The current working directory is set to / after initialization.

fs_chdir

Change the RAMFS current working directory to the given path.
const char *
required
Absolute or relative path of the directory to change into. Must not exceed FS_PATH_MAX (128) bytes including the null terminator.
int
0 on success, or a negative value if the path does not exist or is not a directory.

fs_pwd

Write the absolute path of the RAMFS current working directory into a caller-supplied buffer.
char *
required
Buffer to receive the null-terminated path string. Must be at least capacity bytes.
uint32_t
required
Size of output in bytes. A value of FS_PATH_MAX (128) is always sufficient.
int
0 on success, or a negative value if output is NULL or capacity is too small to hold the current path.

fs_list

List the contents of a directory into a caller-supplied array of fs_entry_t structs.
const char *
required
Absolute or relative path of the directory to list.
fs_entry_t *
required
Array of fs_entry_t to receive directory entries. Allocate at least FS_LIST_MAX (64) elements to capture every entry in any directory.
uint32_t
required
Number of elements available in entries. Results are truncated to this limit when a directory holds more entries than capacity.
int
Non-negative entry count on success, or a negative value if the path does not exist or is not a directory.
A single directory holds at most FS_LIST_MAX (64) entries. Allocating FS_LIST_MAX elements for the entries array guarantees no entries are lost.

fs_mkdir

Create a new directory at the specified path.
const char *
required
Absolute or relative path of the directory to create. The parent directory must already exist. The final path component must not exceed FS_NAME_MAX - 1 (23) characters.
int
0 on success, or a negative value if the parent does not exist, the name is too long, or an entry with that name already exists.

fs_touch

Create a new empty file at the specified path.
const char *
required
Absolute or relative path of the file to create. The parent directory must already exist. The final path component must not exceed FS_NAME_MAX - 1 (23) characters.
int
0 on success, or a negative value if the parent does not exist, the name is too long, or an entry with that name already exists.

fs_write

Write or append text to an existing RAMFS file.
const char *
required
Absolute or relative path of the target file. The file must already exist; call fs_touch first if needed.
const char *
required
Null-terminated string to write. The resulting file content must not exceed FS_DATA_MAX (256) bytes.
uint8_t
required
Pass 0 to overwrite the file’s existing content with text. Pass 1 to append text after the current content.
int
0 on success, or a negative value if the path does not exist, the target is a directory, or the write would push the file beyond FS_DATA_MAX (256) bytes.

fs_read

Read the content of a RAMFS file, returning a pointer into the kernel’s internal buffer and the current byte count.
const char *
required
Absolute or relative path of the file to read.
const char **
required
On success, *data is set to a pointer into the kernel’s internal file buffer. Do not free this pointer or write through it.
uint16_t *
required
On success, *size is set to the current content length in bytes. The value does not include a null terminator and never exceeds FS_DATA_MAX (256).
int
0 on success, or a negative value if the path does not exist or is a directory.

fs_remove

Remove a file or an empty directory from RAMFS.
const char *
required
Absolute or relative path of the entry to remove. Directories must be empty before they can be removed.
int
0 on success, or a negative value if the path does not exist, the directory is not empty, or the path resolves to the root.

File Size and Directory Capacity Limits

Each RAMFS file can hold at most FS_DATA_MAX = 256 bytes of content. Any fs_write call that would push a file past this limit fails with a negative return value. Each RAMFS directory can contain at most FS_LIST_MAX = 64 entries (files and subdirectories combined). Attempting to create a new entry in a full directory fails with a negative return value.

Example