#define DEVFS_H
#include "fs.h"
+#include "blockdev.h"
#define DEVFS_MAX_DEVICES 32
+struct block_device;
+
fs_node_t* devfs_create_root(void);
+/* VFS mount interface */
+vfs_mount_result_t devfs_mount(struct block_device* bdev, uint32_t lba);
+void devfs_kill_sb(vfs_superblock_t* sb);
+
/*
* Register a device node with devfs.
* The caller owns the fs_node_t storage (must remain valid for the
#define PROCFS_H
#include "fs.h"
+#include "blockdev.h"
+
+struct block_device;
fs_node_t* procfs_create_root(void);
+/* VFS mount interface */
+vfs_mount_result_t procfs_mount(struct block_device* bdev, uint32_t lba);
+void procfs_kill_sb(vfs_superblock_t* sb);
+
#endif
#define TMPFS_H
#include "fs.h"
+#include "blockdev.h"
#include <stdint.h>
+struct block_device;
+
fs_node_t* tmpfs_create_root(void);
int tmpfs_add_file(fs_node_t* root_dir, const char* name, const uint8_t* data, uint32_t len);
+/* VFS mount interface */
+vfs_mount_result_t tmpfs_mount(struct block_device* bdev, uint32_t lba);
+void tmpfs_kill_sb(vfs_superblock_t* sb);
+
int tmpfs_mkdir_p(fs_node_t* root_dir, const char* path);
fs_node_t* tmpfs_create_file(fs_node_t* root_dir, const char* path, const uint8_t* data, uint32_t len);
int tmpfs_create_symlink(fs_node_t* root_dir, const char* link_path, const char* target);
*/
#include "devfs.h"
+#include "fs.h"
+#include "blockdev.h"
#include "errno.h"
#include "utils.h"
static fs_node_t g_dev_zero;
static fs_node_t g_dev_random;
static fs_node_t g_dev_urandom;
+static fs_node_t g_dev_vda;
static uint32_t g_devfs_inited = 0;
static struct fs_node* devfs_finddir_impl(struct fs_node* node, const char* name);
g_dev_urandom.flags = FS_CHARDEVICE;
g_dev_urandom.inode = 9;
g_dev_urandom.f_ops = &dev_random_ops;
+
+ /* Initialize /dev/vda block device node (placeholder, will be registered by virtio-blk) */
+ memset(&g_dev_vda, 0, sizeof(g_dev_vda));
+ strcpy(g_dev_vda.name, "vda");
+ g_dev_vda.flags = FS_BLOCKDEVICE;
+ g_dev_vda.inode = 10;
+ /* f_ops will be set by virtio-blk driver when it registers */
+ devfs_register_device(&g_dev_vda);
}
fs_node_t* devfs_create_root(void) {
devfs_init_once();
return &g_dev_root.vfs;
}
+
+/* ---- VFS mount interface ---- */
+vfs_mount_result_t devfs_mount(block_device_t* bdev, uint32_t lba) {
+ (void)bdev;
+ (void)lba;
+ vfs_mount_result_t result = {NULL, NULL};
+ result.root = devfs_create_root();
+ return result;
+}
+
+void devfs_kill_sb(vfs_superblock_t* sb) {
+ (void)sb;
+ /* devfs uses static globals, no cleanup needed */
+}
};
vfs_fs_type_register(&ext2_fs_type);
+ /* Register virtual filesystems (no block device needed) */
+ static vfs_fs_type_t tmpfs_fs_type = {
+ .name = "tmpfs",
+ .flags = 0,
+ .mount = tmpfs_mount,
+ .kill_sb = tmpfs_kill_sb
+ };
+ vfs_fs_type_register(&tmpfs_fs_type);
+
+ static vfs_fs_type_t devfs_fs_type = {
+ .name = "devfs",
+ .flags = 0,
+ .mount = devfs_mount,
+ .kill_sb = devfs_kill_sb
+ };
+ vfs_fs_type_register(&devfs_fs_type);
+
+ static vfs_fs_type_t procfs_fs_type = {
+ .name = "procfs",
+ .flags = 0,
+ .mount = procfs_mount,
+ .kill_sb = procfs_kill_sb
+ };
+ vfs_fs_type_register(&procfs_fs_type);
+
/* Parse kernel command line (Linux-like triaging) */
cmdline_parse(bi ? bi->cmdline : NULL);
*/
#include "procfs.h"
+#include "fs.h"
+#include "blockdev.h"
#include "process.h"
#include "spinlock.h"
#include "pmm.h"
#include "timer.h"
#include "kernel/cmdline.h"
-#include "fs.h"
#include <stddef.h>
return &g_proc_root;
}
+
+/* ---- VFS mount interface ---- */
+vfs_mount_result_t procfs_mount(block_device_t* bdev, uint32_t lba) {
+ (void)bdev;
+ (void)lba;
+ vfs_mount_result_t result = {NULL, NULL};
+ result.root = procfs_create_root();
+ return result;
+}
+
+void procfs_kill_sb(vfs_superblock_t* sb) {
+ (void)sb;
+ /* procfs uses static globals, no cleanup needed */
+}
*/
#include "tmpfs.h"
+#include "fs.h"
+#include "blockdev.h"
#include "errno.h"
#include "heap.h"
return &root->vfs;
}
+/* ---- VFS mount interface ---- */
+vfs_mount_result_t tmpfs_mount(block_device_t* bdev, uint32_t lba) {
+ (void)bdev;
+ (void)lba;
+ vfs_mount_result_t result = {NULL, NULL};
+ result.root = tmpfs_create_root();
+ return result;
+}
+
+void tmpfs_kill_sb(vfs_superblock_t* sb) {
+ if (sb && sb->root) {
+ struct tmpfs_node* root = (struct tmpfs_node*)sb->root;
+ /* Free all children recursively */
+ struct tmpfs_node* child = root->first_child;
+ while (child) {
+ struct tmpfs_node* next = child->next_sibling;
+ if (child->data) kfree(child->data);
+ kfree(child);
+ child = next;
+ }
+ kfree(root);
+ }
+}
+
int tmpfs_add_file(fs_node_t* root_dir, const char* name, const uint8_t* data, uint32_t len) {
if (!root_dir || root_dir->flags != FS_DIRECTORY) return -ENOTDIR;
if (!name || name[0] == 0) return -EINVAL;