VFS mount/umount + sys_open/close/read/fake write

This commit is contained in:
2026-04-10 14:31:38 +02:00
parent 17589d72cf
commit aff113d02b
10 changed files with 592 additions and 12 deletions
+2
View File
@@ -28,6 +28,7 @@
#define PROCESS_NAME_MAX 64
#define PROCESS_STACK_SIZE 0x10000 // 64kb
#define PROCESS_STACK_TOP 0x80000000
#define PROCESS_FD_MAX 32
/* sched */
// 1 tick = 1 ms => quantum = 10ms
@@ -47,6 +48,7 @@
/* fs */
#define CALYXFS_FILES_MAX 10
#define TAR_OPEN_FILES_MAX 64
/* paging */
#define PAGING_MAX_PHYS 0x200000000
+6
View File
@@ -9,6 +9,7 @@
#include <stdint.h>
#include <limine.h>
#include <stddef.h>
struct tar_header
{
@@ -33,4 +34,9 @@ int tar_init_fs(struct limine_file* file);
struct tar_header* tar_file_lookup(const char* filename);
void tar_file_read(struct tar_header* header, uint8_t* buf);
int tar_open(const char* path, int flags);
int tar_close(int fd);
int64_t tar_read(int fd, char* buf, size_t count);
int64_t tar_write(int fd, char* buf, size_t count);
#endif
+50
View File
@@ -0,0 +1,50 @@
/*
* @author xamidev <xamidev@riseup.net>
* @brief Virtual filesystem layer
* @license GPL-3.0-only
*/
/*
PepperOS will not work like the Unix-based mountpoint approach,
but rather like what Windows does. Filesystems will be separated
into "drives", and each drive will have a number assigned.
*/
#ifndef VFS_H
#define VFS_H
#include <limine.h>
#include <stddef.h>
#include <stdint.h>
typedef enum
{
DRIVE_TAR
} DriveType;
struct drive
{
unsigned int id;
DriveType type;
struct fs_operations* operations;
struct drive* next;
};
struct fs_operations
{
int (*open)(const char* path, int flags);
int (*close)(int fd);
int64_t (*read)(int fd, char* buf, size_t count);
int64_t (*write)(int fd, char* buf, size_t count);
};
int vfs_mount(struct limine_file* file, DriveType type);
int vfs_umount(unsigned int drive_id);
int vfs_open(const char* path, int flags);
int vfs_close(int fd);
int64_t vfs_read(int fd, char* buf, size_t count);
int64_t vfs_write(int fd, const char* buf, size_t count);
#endif
+7 -1
View File
@@ -10,7 +10,13 @@
#include "limine.h"
enum ErrorCodes {
ENOMEM,
EIO
EIO,
EINVAL,
ENOENT,
EFAULT,
EBADF,
EBUSY,
ENOSYS
};
#define CLEAR_INTERRUPTS __asm__ volatile("cli")
+13
View File
@@ -11,6 +11,7 @@
#include <config.h>
#include <stdint.h>
#include <limine.h>
#include <stdbool.h>
typedef enum {
READY,
@@ -18,6 +19,12 @@ typedef enum {
DEAD
} status_t;
struct process_fd {
bool used;
unsigned int drive_id;
int fs_fd;
};
struct process {
size_t pid;
char name[PROCESS_NAME_MAX];
@@ -26,6 +33,7 @@ struct process {
struct cpu_status* context;
void* root_page_table; // Process PML4 (should contain kernel PML4 in higher half [256-511]
void* kernel_stack; // Used for interrupts (syscall: int 0x80), defines the TSS RSP0
struct process_fd fds[PROCESS_FD_MAX];
struct process* next;
};
@@ -40,4 +48,9 @@ void process_display_list(struct process* processes_list);
void process_create_user(struct limine_file* file, char* name);
void process_fd_init(struct process* proc);
int process_fd_alloc(struct process* proc, unsigned int drive_id, int fs_fd);
int process_fd_get_fsfd(struct process* proc, int fd, unsigned int* drive_id, int* fs_fd);
int process_fd_release(struct process* proc, int fd);
#endif