2 Commits

Author SHA1 Message Date
95d2cc52ed Create vfs.c
Implementation for vfs
2026-01-28 11:28:47 -08:00
679e6101e0 Create vfs.h
This creates a  base VFS virtual file system
2026-01-28 11:24:34 -08:00
2 changed files with 61 additions and 0 deletions

19
kernel/vfs.c Normal file
View File

@@ -0,0 +1,19 @@
#include "vfs.h"
#include "kmalloc.h"
#include "string_utils.h"
vfs_node_t* vfs_root = NULL;
uint32_t vfs_read(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buffer) {
if (node->read != NULL) {
return node->read(node, offset, size, buffer);
}
return 0;
}
vfs_node_t* vfs_finddir(vfs_node_t* node, const char* name) {
if ((node->flags & VFS_DIRECTORY) && node->finddir != NULL) {
return node->finddir(node, name);
}
return NULL;
}

42
kernel/vfs.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef VFS_H
#define VFS_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
struct vfs_node;
// Function pointers that every FS driver must provide
typedef uint32_t (*vfs_read_func)(struct vfs_node*, uint32_t, uint32_t, uint8_t*);
typedef struct vfs_node* (*vfs_finddir_func)(struct vfs_node*, const char* name);
typedef struct vfs_node {
char name[128];
uint32_t mask; // Permissions
uint32_t uid; // User ID
uint32_t gid; // Group ID
uint32_t flags; // Node type (File, Directory, etc.)
uint32_t inode; // FS-specific identifier
uint32_t length; // Size in bytes
// Function table
vfs_read_func read;
vfs_finddir_func finddir;
struct vfs_node* ptr; // Used for mountpoints or symlinks
} vfs_node_t;
// Standard node types
#define VFS_FILE 0x01
#define VFS_DIRECTORY 0x02
#define VFS_MOUNTPOINT 0x04
// The root of the filesystem (/)
extern vfs_node_t* vfs_root;
// Public API
uint32_t vfs_read(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buffer);
vfs_node_t* vfs_finddir(vfs_node_t* node, const char* name);
#endif