Add VFS subsystem and initrd filesystem driver (AI)

VFS subsystem (vfs.c/h):
- Mount table with up to 16 mount points, longest-prefix path matching.
- File descriptor table (256 entries, fds 0-2 reserved for std streams).
- Path resolution walks mount table then delegates to filesystem's
  finddir() for each path component.
- Operations: open, close, read, write, seek, readdir, stat.
- Each filesystem driver provides a vfs_fs_ops_t with callbacks.

Initrd filesystem driver (initrd_fs.c/h):
- Read-only VFS driver backed by the CPIO ramdisk.
- Mounted at '/initrd' during boot.
- Zero-copy reads: file data points directly into the CPIO archive
  memory, no allocation or copying needed.
- Supports readdir (flat iteration) and finddir (name lookup).

Bug fix: resolve_path was overwriting file-specific fs_data (set by
finddir, e.g. pointer to CPIO file data) with the mount's fs_data
(NULL). Fixed to preserve fs_data from finddir.

Verified in QEMU: kernel reads /initrd/README via VFS and prints its
contents. Ring 3 user process continues to work.
This commit is contained in:
AI
2026-02-23 12:23:32 +00:00
parent 3d5fb4c267
commit 0c5aa72fd3
8 changed files with 740 additions and 2 deletions

View File

@@ -14,6 +14,8 @@
#include "syscall.h"
#include "process.h"
#include "cpio.h"
#include "vfs.h"
#include "initrd_fs.h"
void offset_print(const char *str)
{
@@ -101,6 +103,27 @@ void kernel_main(uint32_t magic, uint32_t addr) {
offset_print("No initrd module found\n");
}
init_vfs();
offset_print("VFS initialized\n");
if (initrd_start != 0) {
init_initrd_fs();
offset_print("Initrd filesystem mounted\n");
/* Test VFS: read a file from the initrd */
int fd = vfs_open("/initrd/README", 0);
if (fd >= 0) {
char buf[64];
int32_t n = vfs_read(fd, buf, sizeof(buf) - 1);
if (n > 0) {
buf[n] = '\0';
offset_print("VFS read /initrd/README: ");
offset_print(buf);
}
vfs_close(fd);
}
}
init_tss();
offset_print("TSS initialized\n");