Idk but i think i did something right
This commit is contained in:
parent
808fa4c13e
commit
167a00738f
|
|
@ -31,7 +31,7 @@ extern void kmain(kernel_info_t *kernel_info){
|
|||
pic_disable();
|
||||
pic_setmask(0xfe, PIC1_DATA);
|
||||
vfs_init();
|
||||
fcreate("Testing/testing/bleh", 0);
|
||||
fcreate("/test", 0);
|
||||
//TODO: Map and load filesystem and disk modules
|
||||
//TODO: Start Initial Process
|
||||
mlog("KERNEL", "Initializing Scheduler & starting PID 1\n", MLOG_PRINT);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "../shared/memory.h"
|
||||
#include "../shared/string.h"
|
||||
#define MODULE_NAME "KVFS"
|
||||
vfile_t root_dir = {"\0", VFILE_DIRECTORY};
|
||||
vfile_t root_dir = {"/", VFILE_DIRECTORY};
|
||||
|
||||
void vfs_init(){
|
||||
mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT);
|
||||
|
|
@ -12,15 +12,32 @@ void vfs_init(){
|
|||
}
|
||||
|
||||
void fcreate(char *name, VFILE_TYPE type, ...){
|
||||
printf("Sasdafdasdf\n");
|
||||
char *dir = strtok(name, '/');
|
||||
char *file = dir;
|
||||
char *tmp = dir;
|
||||
uint32_t filename_offset = 0;
|
||||
vfile_t *current_dir = &root_dir;
|
||||
vfile_t *tmpfile;
|
||||
while(tmp != 0){
|
||||
dir = file;
|
||||
file = tmp;
|
||||
dir = tmp;
|
||||
tmpfile = search_dir(tmp, *current_dir);
|
||||
if(!tmpfile){
|
||||
//create file in folder;
|
||||
|
||||
}
|
||||
switch(tmpfile->type){
|
||||
case VFILE_DIRECTORY:
|
||||
current_dir = tmpfile;
|
||||
break;
|
||||
case VFILE_MOUNT:
|
||||
return ((mount_t*)(tmpfile->access.data.ptr))->create(name + filename_offset, type == VFILE_DIRECTORY ? FS_FILE_IS_DIR : 0);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
filename_offset += strlen(tmp) + 1;
|
||||
kfree(tmp);
|
||||
tmp = strtok(0, '/');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void fdelete();
|
||||
|
||||
|
|
@ -36,22 +53,53 @@ uint32_t fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t
|
|||
file_entry->access.funcs.write(byte_array, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t fread();
|
||||
void fopen(char *name){
|
||||
|
||||
vfile_t *search_dir(char *name, vfile_t dir){
|
||||
vfile_t *dir_data = (vfile_t *)dir.access.data.ptr;
|
||||
uint32_t i = 0;
|
||||
while(dir_data[i].name[0]){
|
||||
if(!strcmp(dir_data[i].name, name)) return &dir_data[i];
|
||||
i++;
|
||||
}
|
||||
mlog(MODULE_NAME, "File not found\n", MLOG_ERR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
file_t vfile_to_file(vfile_t *file){
|
||||
file_t out = {-1, &file};
|
||||
}
|
||||
|
||||
int fopen(char *name, file_t *file){
|
||||
char *dir = strtok(name, '/');
|
||||
char *tmp = dir;
|
||||
uint32_t filename_offset = 0;
|
||||
vfile_t *current_dir = &root_dir;
|
||||
vfile_t *tmpfile;
|
||||
while(tmp != 0){
|
||||
dir = tmp;
|
||||
uint32_t i = 0;
|
||||
vfile_t *dir = ((vfile_t *)(current_dir->access.data.ptr));
|
||||
while(dir[i].name[0]){
|
||||
if(!strcmp(dir[i].name, tmp)){
|
||||
if(dir[i].type == )
|
||||
tmpfile = search_dir(tmp, *current_dir);
|
||||
if(!tmpfile){
|
||||
kfree(tmp);
|
||||
return -1;
|
||||
}
|
||||
switch(tmpfile->type){
|
||||
case VFILE_DIRECTORY:
|
||||
current_dir = tmpfile;
|
||||
break;
|
||||
case VFILE_MOUNT:
|
||||
return ((mount_t*)(tmpfile->access.data.ptr))->open(name + filename_offset, file);
|
||||
default:
|
||||
*file = vfile_to_file(tmpfile);
|
||||
kfree(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
filename_offset += strlen(tmp) + 1;
|
||||
kfree(tmp);
|
||||
tmp = strtok(0, '/');
|
||||
}
|
||||
return;
|
||||
*file = vfile_to_file(tmpfile);
|
||||
kfree(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -26,9 +26,29 @@ typedef struct virtual_file_t{
|
|||
}access;
|
||||
}vfile_t;
|
||||
|
||||
typedef struct file{
|
||||
uint32_t mount_index;
|
||||
void *dirent;
|
||||
}file_t;
|
||||
|
||||
typedef enum fs_flags{
|
||||
FS_FILE_IS_DIR = 1,
|
||||
FS_FILE_IS_SYSTEM = 2,
|
||||
FS_FILE_IS_HIDDEN = 4,
|
||||
}FS_FILE_FLAGS;
|
||||
|
||||
typedef struct mount_funcs{
|
||||
void (*write)(file_t *file, void *data, uint32_t offset, uint32_t count);
|
||||
void (*read)(file_t *file, void *data, uint32_t offset, uint32_t count);
|
||||
int (*open)(char *filename, file_t *file);
|
||||
void (*delete)(file_t *file);
|
||||
void (*create)(char *filename, FS_FILE_FLAGS flags);
|
||||
}mount_t;
|
||||
|
||||
void vfs_init();
|
||||
void fcreate(char *name, VFILE_TYPE type, ...);
|
||||
void fdelete();
|
||||
uint32_t fwrite();
|
||||
uint32_t fread();
|
||||
void fopen(char *name);
|
||||
vfile_t *search_dir(char *name, vfile_t dir){
|
||||
int fopen(char *name, file_t *file);
|
||||
Loading…
Reference in New Issue