The CrisOS v2 file system API spans two layers. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/CRISTOP-bot/cris-os-v2/llms.txt
Use this file to discover all available pages before exploring further.
fs.h layer provides raw access to the CRFS binary image — it parses the on-disk format and exposes a flat table of named files. The vfs.h layer wraps fs.h with a navigable in-memory node tree that supports the full file and directory interface used by the shell, including path resolution, writable files, and dynamic directory creation.
fs.h — Raw CRFS Layer
The fs.h layer operates directly on a CRFS binary image loaded into memory. A CRFS image begins with a 16-byte header (magic CRFS, version 1, file count) followed by a flat entry table of 72-byte records. fs_init must be called once before any other fs_* function.
Data Structure
struct fs_file is a lightweight view into the image — name points into the entry table and data points into the raw image buffer. Neither field is heap-allocated; the image must remain valid for the lifetime of the filesystem.
fs_init
image of size bytes. Validates the four-byte CRFS magic, checks the version field, and verifies that every file entry’s data region falls within the image bounds. Must be called before any other fs_* function.
Pointer to the start of the CRFS binary image in memory.
Total size of the image buffer in bytes.
1 on success; 0 if image is NULL, the buffer is too small, the magic bytes are not CRFS, the version is not 1, or any file entry’s data region extends beyond the image bounds.
fs_find
name exactly (case-sensitive). Uses kstrcmp for comparison.
Exact file name to search for, including any path separators (e.g.
"boot/kernel.bin").struct fs_file populated with the matching entry’s name, data pointer, and size; or NULL if no match is found.
fs_file_at
index in the flat file table. Useful for iterating all files in the image without knowing their names.
Zero-based index into the file table. Valid range:
0 to fs_file_count() - 1.struct fs_file; or NULL if index is out of range.
The returned pointer refers to a single static
struct fs_file that is overwritten on each call. Copy the fields if you need to hold multiple results simultaneously.fs_file_count
fs_init succeeds.
Returns: The number of file entries; 0 if fs_init has not been called successfully.
vfs.h — Virtual File System Layer
The VFS layer builds an in-memory node tree from the CRFS entries exposed by fs.h. Nodes are stored in a fixed-size static array; directories hold up to VFS_CHILDREN_MAX children. vfs_init must be called (after fs_init) before any other vfs_* function.
vfs_init
fs layer. The root node "/" is created as a read-only directory. Each CRFS file path is walked component-by-component; intermediate directory nodes are created automatically.
Returns: 1 on success.
vfs_pwd
"/home/user"). The buffer is overwritten on each call.
vfs_cd
path. Accepts both absolute paths (starting with /) and relative paths. The special components . (current) and .. (parent) are resolved correctly.
Target directory path, absolute or relative.
1 on success; 0 if the path does not resolve to a valid directory node.
vfs_list
"/ " and file children are prefixed with two spaces.
Path to the directory to list. Pass
NULL or an empty string to list the current working directory.1 on success; 0 if the path does not resolve to a directory node.
vfs_cat
Path to the file whose contents should be printed.
1 on success; 0 if the path does not exist or resolves to a directory node.
vfs_mkdir
path. All intermediate path components must already exist.
Path for the new directory. The parent directory must already exist.
1 on success; 0 if the parent does not exist, the name already exists, or the node pool is full.
vfs_touch
path. If the node already exists, the call succeeds without modifying it.
Path for the new file. The parent directory must already exist.
1 on success; 0 if the parent does not exist or the node pool is full.
vfs_remove
Path to the file to remove.
1 on success; 0 if the path does not exist, resolves to a directory, or the node is marked read-only.
vfs_rmdir
Path to the directory to remove.
1 on success; 0 if the path does not exist, is not a directory, is not empty, or is read-only.
vfs_cp
src to dst. The file data is duplicated into the VFS data store. The destination must not already exist, and its parent directory must exist.
Path to the source file.
Path for the destination file. Must not already exist.
1 on success; 0 if src does not exist, is a directory, dst already exists, the parent of dst does not exist, or the data store is full.
vfs_mv
Path to the source node.
Destination path. The destination name must not already exist under the destination parent.
1 on success; 0 if src does not exist, is read-only, the destination parent does not exist, or the destination name is already taken.
vfs_write
length bytes from content into the file at path. If the file does not exist it is created. If it already exists its data pointer and size are replaced; the old data remains in the data store and is not reclaimed.
Path to the target file. Created if it does not exist.
Pointer to the data to write.
Number of bytes from
content to write.1 on success; 0 if the path resolves to a directory, the file could not be created, or the data store is full.
vfs_read
path. No copy is made; the pointer refers directly to either the CRFS image buffer or the VFS data store.
Path to the file to read.
const void * pointer to the file’s data; NULL if the path does not exist or resolves to a directory.
vfs_get_size
path in bytes.
Path to the file.
0 if the path does not exist or resolves to a directory.
vfs_exists
path.
Path to test.
1 if a node exists at path; 0 otherwise.