réplica de
https://github.com/Arnau478/quark.git
synced 2024-11-23 12:58:07 +01:00
Fixed VFS
This commit is contained in:
pare
a4f4838f0a
commit
20d796515b
S'han modificat 5 arxius amb 41 adicions i 10 eliminacions
|
@ -1,13 +1,16 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "vfs.h"
|
#include "vfs.h"
|
||||||
|
#include "../lib/string.h"
|
||||||
|
|
||||||
|
file_t g_file_table[256];
|
||||||
|
|
||||||
// Return some OR-ed flags for the given mode string
|
// Return some OR-ed flags for the given mode string
|
||||||
static uint8_t flags_from_mode(const char *mode){
|
static uint8_t flags_from_mode(const char *mode){
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
bool read = false;
|
bool read = false;
|
||||||
bool write = false;
|
bool write = false;
|
||||||
while(mode){
|
while(*mode){
|
||||||
switch(*mode){
|
switch(*mode){
|
||||||
case 'r':
|
case 'r':
|
||||||
read = true;
|
read = true;
|
||||||
|
@ -35,13 +38,22 @@ static uint8_t flags_from_mode(const char *mode){
|
||||||
return flags;
|
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);
|
uint8_t flags = flags_from_mode(mode);
|
||||||
for(int i = 0; i < 256; i++){
|
for(int i = 0; i < 256; i++){
|
||||||
if(!*g_fds[i].name){ // If empty
|
if(!*g_file_table[i].name){ // If empty
|
||||||
g_fds[i].flags = flags;
|
g_file_table[i].flags = flags;
|
||||||
strcpy(g_fds[i].name, path);
|
strcpy(g_file_table[i].name, (char *)path); // TODO: Check if path is longer than expected
|
||||||
return &g_fds[i];
|
return &g_file_table[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL; // No free file descriptors
|
return NULL; // No free file descriptors
|
||||||
|
|
|
@ -14,8 +14,10 @@
|
||||||
typedef struct{
|
typedef struct{
|
||||||
char name[256];
|
char name[256];
|
||||||
uint8_t flags;
|
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);
|
||||||
|
|
|
@ -10,3 +10,10 @@ int strcmp(char *s1, char *s2){
|
||||||
while(*s1 && (*s1 == *s2)) {s1++; s2++;}
|
while(*s1 && (*s1 == *s2)) {s1++; s2++;}
|
||||||
return *(const unsigned char *)s1 - *(const unsigned char *)s2;
|
return *(const unsigned char *)s1 - *(const unsigned char *)s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void strcpy(char *dest, char *src){
|
||||||
|
while(*src){
|
||||||
|
*(dest++) = *(src++);
|
||||||
|
}
|
||||||
|
*dest = '\0';
|
||||||
|
}
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
|
|
||||||
int strlen(char *s);
|
int strlen(char *s);
|
||||||
int strcmp(char *s1, char *s2);
|
int strcmp(char *s1, char *s2);
|
||||||
|
void strcpy(char *dest, char *src);
|
||||||
|
|
|
@ -4,12 +4,21 @@
|
||||||
#include "drivers/timer.h"
|
#include "drivers/timer.h"
|
||||||
#include "drivers/keyboard.h"
|
#include "drivers/keyboard.h"
|
||||||
#include "drivers/serial.h"
|
#include "drivers/serial.h"
|
||||||
|
#include "fs/vfs.h"
|
||||||
|
|
||||||
void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
|
void __attribute__((cdecl)) kmain(uint64_t magic, uint64_t addr){
|
||||||
|
// Clear screen
|
||||||
|
clear_screen();
|
||||||
|
|
||||||
|
// Initialize chip-specific hardware
|
||||||
hal_initialize();
|
hal_initialize();
|
||||||
|
|
||||||
|
// Initialize drivers
|
||||||
timer_initialize();
|
timer_initialize();
|
||||||
keyboard_initialize();
|
keyboard_initialize();
|
||||||
|
|
||||||
clear_screen();
|
// Initialize FS
|
||||||
|
vfs_initialize();
|
||||||
|
|
||||||
for(;;);
|
for(;;);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Referencia en una nova incidència