mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2026-03-09 08:25:19 -07:00
Compare commits
2 Commits
56faa3143d
...
gbowne1-ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 95d2cc52ed | |||
| 679e6101e0 |
19
kernel/vfs.c
Normal file
19
kernel/vfs.c
Normal 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
42
kernel/vfs.h
Normal 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
|
||||||
Reference in New Issue
Block a user