vfs - start making the VFS

This commit is contained in:
RaphProductions 2025-05-12 22:26:19 +02:00
parent 8b75d8d5e6
commit 6a77b066e8
8 changed files with 128 additions and 63 deletions

37
kernel/src/fs/vfs.h Normal file
View file

@ -0,0 +1,37 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
struct vnode;
#define VN_FILE 1
#define VN_DIR 2
typedef uint32_t vnode_type_t;
typedef struct vnode_ops {
int (*read)(struct vnode* vn, void* buf, size_t size);
} vnode_ops_t;
typedef struct vnode {
char name[256];
vnode_type_t type;
struct vnode* parent;
struct vnode* child;
struct vnode* next;
struct vnode_ops* ops;
void* internal;
} vnode_t;
typedef struct fs {
char name[32];
int (*mount)(struct vnode** root);
} fs_t;
void vfs_init(void);
int vfs_mount(char *path, fs_t* fs);
int vfs_unmount(char *path);
int vfs_open(const char* path, vnode_t** result);
int vfs_read(vnode_t* vn, void* buf, size_t size);

View file

@ -1,4 +1,5 @@
#include <lib/string.h> #include <lib/string.h>
#include <mm/liballoc/liballoc.h>
#include <stddef.h> #include <stddef.h>
int strlen(const char *str) { int strlen(const char *str) {
@ -16,13 +17,13 @@ int strcmp(const char *s1, const char *s2) {
return *s1 - *s2; return *s1 - *s2;
} }
char *strcpy(char *dest, const char *src) char *strcpy(char *dest, const char *src) {
{
if (dest == NULL || src == NULL) if (dest == NULL || src == NULL)
return NULL; return NULL;
char *temp = dest; char *temp = dest;
while((*dest++ = *src++) != '\0'); while ((*dest++ = *src++) != '\0')
;
return temp; return temp;
} }
@ -55,3 +56,16 @@ int oct2bin(unsigned char *str, int size) {
} }
return n; return n;
} }
char *strdup(const char *str) {
if (str == NULL)
return NULL;
int len = strlen(str);
char *dup = (char *)malloc(len + 1);
if (dup == NULL)
return NULL;
strcpy(dup, str);
return dup;
}

View file

@ -6,3 +6,4 @@ char *strchr(const char *s, int c);
char *strcpy(char *dest, const char *src); char *strcpy(char *dest, const char *src);
char *strrchr(const char *s, int c); char *strrchr(const char *s, int c);
int oct2bin(unsigned char *str, int size); int oct2bin(unsigned char *str, int size);
char *strdup(const char *str);

View file

@ -18,11 +18,13 @@
#include <sys/arch/x86_64/fpu.h> #include <sys/arch/x86_64/fpu.h>
#include <sys/arch/x86_64/gdt.h> #include <sys/arch/x86_64/gdt.h>
#include <sys/arch/x86_64/idt.h> #include <sys/arch/x86_64/idt.h>
#include <sys/error_handling/panic.h> #include <sys/errhnd/panic.h>
#include <sys/gfx/flanterm/backends/fb.h> #include <sys/gfx/flanterm/backends/fb.h>
#include <sys/gfx/flanterm/flanterm.h> #include <sys/gfx/flanterm/flanterm.h>
#include <sys/log.h> #include <sys/log.h>
#include <sys/printf.h> #include <sys/printf.h>
#include <fs/vfs.h>
#include <fs/hellofs.h>
__attribute__(( __attribute__((
used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3); used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
@ -89,7 +91,17 @@ void kmain(void) {
pit_init(1000); pit_init(1000);
sched_init(); sched_init();
panic("No working initialization program found. (This is normal due to Soaplin's current state, so please do not report this as a bug)"); vfs_init();
if (hellofs_init() < 0) {
log("kernel - Failed to initialize HelloFS\n");
} else {
log("kernel - HelloFS initialized successfully\n");
}
panic("No working initialization program found. (This is normal due to "
"Soaplin's current state, so please do not report this as a bug)");
log("kernel - Soaplin initialized sucessfully.\n"); log("kernel - Soaplin initialized sucessfully.\n");

View file

@ -34,8 +34,10 @@ int rtc_init() {
outb(0x70, 0x8B); // select register B, and disable NMI outb(0x70, 0x8B); // select register B, and disable NMI
char prev = inb(0x71); // read the current value of register B char prev = inb(0x71); // read the current value of register B
outb(0x70, 0x8B); // set the index again (a read will reset the index to register D) outb(0x70,
outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This turns on bit 6 of register B 0x8B); // set the index again (a read will reset the index to register D)
outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This
// turns on bit 6 of register B
__asm__ volatile("sti"); __asm__ volatile("sti");
return 0; return 0;
} }

0
kernel/src/sys/arch/x86_64/rtc.h Executable file → Normal file
View file

View file

@ -65,7 +65,6 @@ void __panic_display_ascii_art() {
"halt the PC.\n"); "halt the PC.\n");
} }
void panic(char *msg) { void panic(char *msg) {
__panic_display_ascii_art(); __panic_display_ascii_art();