Basic VFS implementation

This commit is contained in:
Arnau Camprubí 2022-07-02 16:37:02 +02:00
pare 85f1b0969a
commit 18f73a5357
S'han modificat 3 arxius amb 96 adicions i 1 eliminacions

46
src/kernel/fs/fs.c Normal file
Veure arxiu

@ -0,0 +1,46 @@
#include <stddef.h>
#include "fs.h"
fs_node_t *fs_root = NULL;
uint32_t fs_read(fs_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;
}
uint32_t fs_write(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer){
if(node->write != NULL){
return node->write(node, offset, size, buffer);
}
return 0;
}
void fs_open(fs_node_t *node, uint8_t read, uint8_t write){
if(node->open != NULL){
return node->open(node);
}
return 0;
}
void fs_close(fs_node_t *node){
if(node->close != NULL){
return node->close(node);
}
return 0;
}
dirent_t *fs_readdir(fs_node_t *node, uint32_t index){
if(node->readdir != NULL && (node->flags & 0x7 == FS_DIRECTORY)){
return node->readdir(node, index);
}
return 0;
}
fs_node_t *fs_finddir(fs_node_t *node, char *name){
if(node->finddir != NULL && (node->flags & 0x7 == FS_DIRECTORY)){
return node->finddir(node, name);
}
return 0;
}

50
src/kernel/fs/fs.h Normal file
Veure arxiu

@ -0,0 +1,50 @@
#pragma once
#include <stdint.h>
#define FS_FILE 0x01
#define FS_DIRECTORY 0x02
#define FS_CHARDEVICE 0x03
#define FS_BLOCKDEVICE 0x04
#define FS_PIPE 0x05
#define FS_SYMLINK 0x06
#define FS_MOUNTPOINT 0x08
typedef struct fs_node{
char name[128];
uint32_t mask;
uint32_t uid;
uint32_t gid;
uint32_t flags;
uint32_t inode;
uint32_t length;
uint32_t impl;
fs_read_fn_t read;
fs_write_fn_t write;
fs_open_fn_t open;
fs_close_fn_t close;
fs_readdir_fn_t readdir;
fs_finddir_fn_t finddir;
struct fs_node *ptr;
} fs_node_t;
typedef struct dirent{
char name[128];
uint32_t inode;
} dirent_t;
typedef uint32_t (*fs_read_fn_t)(fs_node_t *, uint32_t, uint32_t, uint8_t *);
typedef uint32_t (*fs_write_fn_t)(fs_node_t *, uint32_t, uint32_t, uint8_t *);
typedef void (*fs_open_fn_t)(fs_node_t *);
typedef void (*fs_close_fn_t)(fs_node_t *);
typedef dirent_t *(*fs_readdir_fn_t)(fs_node_t *, uint32_t);
typedef fs_node_t *(*fs_finddir_fn_t)(fs_node_t *, char *);
extern fs_node_t *fs_root;
uint32_t fs_read(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
uint32_t fs_write(fs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer);
void fs_open(fs_node_t *node, uint8_t read, uint8_t write);
void fs_close(fs_node_t *node);
dirent_t *fs_readdir(fs_node_t *node, uint32_t index);
fs_node_t *fs_finddir(fs_node_t *node, char *name);

Veure arxiu

@ -11,6 +11,5 @@ void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
keyboard_initialize(); keyboard_initialize();
clear_screen(); clear_screen();
printf("Serial status: %i\n", serial_initialize(COM1));
for(;;); for(;;);
} }