This commit is contained in:
Arnau Camprubí 2022-07-15 21:45:56 +02:00
pare a4f4838f0a
commit 20d796515b
S'han modificat 5 arxius amb 41 adicions i 10 eliminacions

Veure arxiu

@ -1,13 +1,16 @@
#include <stddef.h>
#include <stdbool.h>
#include "vfs.h"
#include "../lib/string.h"
file_t g_file_table[256];
// Return some OR-ed flags for the given mode string
static uint8_t flags_from_mode(const char *mode){
uint8_t flags = 0;
bool read = false;
bool write = false;
while(mode){
while(*mode){
switch(*mode){
case 'r':
read = true;
@ -35,13 +38,22 @@ static uint8_t flags_from_mode(const char *mode){
return flags;
}
file_descriptor_t *vfs_open(const char *path, const char *mode){
// Initialize VFS
void vfs_initialize(){
for(int i = 0; i < 256; i++){
*g_file_table[i].name = '\0';
g_file_table[i].flags = 0;
}
}
// Open a file and return its file descriptor
file_t *vfs_open(const char *path, const char *mode){
uint8_t flags = flags_from_mode(mode);
for(int i = 0; i < 256; i++){
if(!*g_fds[i].name){ // If empty
g_fds[i].flags = flags;
strcpy(g_fds[i].name, path);
return &g_fds[i];
if(!*g_file_table[i].name){ // If empty
g_file_table[i].flags = flags;
strcpy(g_file_table[i].name, (char *)path); // TODO: Check if path is longer than expected
return &g_file_table[i];
}
}
return NULL; // No free file descriptors

Veure arxiu

@ -14,8 +14,10 @@
typedef struct{
char name[256];
uint8_t flags;
} file_descriptor_t;
} file_t;
file_descriptor_t g_fds[256];
extern file_t g_file_table[256];
file_descriptor_t *vfs_open(const char *path, const char *mode);
void vfs_initialize();
file_t *vfs_open(const char *path, const char *mode);

Veure arxiu

@ -10,3 +10,10 @@ int strcmp(char *s1, char *s2){
while(*s1 && (*s1 == *s2)) {s1++; s2++;}
return *(const unsigned char *)s1 - *(const unsigned char *)s2;
}
void strcpy(char *dest, char *src){
while(*src){
*(dest++) = *(src++);
}
*dest = '\0';
}

Veure arxiu

@ -2,3 +2,4 @@
int strlen(char *s);
int strcmp(char *s1, char *s2);
void strcpy(char *dest, char *src);

Veure arxiu

@ -4,12 +4,21 @@
#include "drivers/timer.h"
#include "drivers/keyboard.h"
#include "drivers/serial.h"
#include "fs/vfs.h"
void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
// Clear screen
clear_screen();
// Initialize chip-specific hardware
hal_initialize();
// Initialize drivers
timer_initialize();
keyboard_initialize();
clear_screen();
// Initialize FS
vfs_initialize();
for(;;);
}