Overview
Aurora OS implements a Unix-like Virtual File System (VFS) that provides a unified interface for multiple filesystem types. The VFS supports mounting filesystems, path resolution, and standard file operations.VFS is mounted at boot with tmpfs for
/ and /tmp. ELF binaries are loaded through VFS.Architecture
Source:kernel/src/fs/vfs.c
- Mount Points: Up to 8 simultaneous mounts
- Filesystem Types: tmpfs, ext2 (stub), FAT (stub)
- Path Resolution: Recursive component-by-component lookup
- Operations: read, write, create, unlink, mkdir, readdir, stat
Data Structures
vfs_node
Represents a file, directory, or symlink in the VFS.kernel/src/fs/vfs.h:27-34
vfs_type_t
Node type enumeration.Regular file.
Directory.
Symbolic link (not yet implemented).
kernel/src/fs/vfs.h:17
vfs_ops
Filesystem operation function pointers.kernel/src/fs/vfs.h:36-47
vfs_stat
File metadata (similar to POSIXstat).
kernel/src/fs/vfs.h:19-25
vfs_mount
Mount table entry.VFS_MAX_MOUNTS = 8
Source: kernel/src/fs/vfs.h:49-53
Core Functions
vfs_mount
Mount a filesystem at a specified path.Mount path (e.g.,
/, /mnt/usb).Root directory node of the filesystem.
Filesystem type string (“tmpfs”, “ext2”, “fat32”).
Returns
0 on success, -1 if mount table is full.kernel/src/fs/vfs.c:20-27
vfs_resolve
Resolve an absolute path to a VFS node.Absolute path (must start with
/).Pointer to resolved node, or
NULL if path not found.- Find longest matching mount point
- Start at mount’s root node
- Split remaining path into components (separated by
/) - Call
ops->lookup()for each component - Return final node or
NULL
kernel/src/fs/vfs.c:29-58
vfs_read
Read data from a file.File node to read from.
Byte offset in file.
Destination buffer.
Number of bytes to read.
Number of bytes read, or
-1 on error.- Delegates to
node->ops->read() - Returns
-1if node isNULLor read operation not supported
kernel/src/fs/vfs.c:60-64
vfs_write
Write data to a file.File node to write to.
Byte offset in file.
Source buffer.
Number of bytes to write.
Number of bytes written, or
-1 on error.kernel/src/fs/vfs.c:66-70
vfs_create
Create a new file or directory entry.Parent directory.
Filename (no path separators).
VFS_FILE or VFS_DIR.Returns
0 on success, -1 on error.kernel/src/fs/vfs.c:72-76
vfs_unlink
Delete a file.Parent directory.
Filename to delete.
Returns
0 on success, -1 on error.kernel/src/fs/vfs.c:78-82
vfs_mkdir
Create a directory.Parent directory.
Directory name.
Returns
0 on success, -1 on error.kernel/src/fs/vfs.c:84-88
vfs_stat
Get file metadata.File or directory node.
Pointer to stat structure to fill.
Returns
0 on success, -1 on error.- Calls
node->ops->stat()if available - Falls back to filling stat from
vfs_nodefields:inode,size,typefrom nodemode = 0755(default)nlink = 1(default)
kernel/src/fs/vfs.c:90-102
vfs_readdir
Read directory entry by index.Directory node.
Entry index (0-based).
Pointer to entry node, or
NULL if index out of bounds.kernel/src/fs/vfs.c:104-108
Filesystem Implementations
tmpfs (In-Memory Filesystem)
Fully functional RAM-based filesystem. Features:- Mounted at
/and/tmpby default - Supports files and directories
- All operations implemented (create, unlink, mkdir, read, write)
- Data stored in kernel heap via
kmalloc()
kernel/src/fs/tmpfs/
ext2 (Extended Filesystem 2)
Status: Stub implementation. Not functional yet.
- Read-only access to ext2 partitions
- Inode-based structure
- Block group descriptors
kernel/src/fs/ext2/
FAT32 (File Allocation Table)
Status: Stub implementation. Not functional yet.
- Read/write access to FAT32 partitions
- Long filename support (VFAT)
- Boot sector parsing
kernel/src/fs/fat/
File Descriptor Integration
Processes use file descriptors to interact with VFS. Each process has an FD table.FD_MAX = 32file descriptors per process- FD 0 = stdin, 1 = stdout, 2 = stderr (reserved)
kernel/src/proc/process.h:36-43
Syscall Interface
VFS operations are exposed through syscalls:SYS_OPEN
Open file and return FD
SYS_READ
Read from FD
SYS_WRITE
Write to FD
SYS_CLOSE
Close FD
SYS_STAT
Get file metadata
SYS_MKDIR
Create directory
SYS_UNLINK
Delete file
SYS_READDIR
Read directory entries
kernel/src/proc/syscall.c
Path Resolution Examples
-
Path:
/etc/passwd- Matches mount:
/ - Lookup:
etcin root →passwdinetc
- Matches mount:
-
Path:
/tmp/session.dat- Matches mount:
/tmp(longest match wins) - Lookup:
session.datin tmpfs root
- Matches mount:
-
Path:
/mnt/usb/data- No matching mount → returns
NULL
- No matching mount → returns
Performance Considerations
Path Resolution: O(n×m) where n = path depth, m = directory entriestmpfs: All operations O(1) or O(n) linear scan (no hash tables yet)Mount Lookup: O(m) where m = number of mounts (max 8)
Limitations
Related APIs
- Process Management - File descriptor table per process
- Syscalls - open, read, write, close, stat, etc.
- ELF Loader - Loads executables via VFS
References
- OSDev Wiki - VFS
- Linux VFS Documentation
- Source:
kernel/src/fs/vfs.c,kernel/src/fs/vfs.h