Compare commits

..

No commits in common. "e5ce4d42d1b7ffc7de99955b3b90163f462e1d9e" and "2062a2dff3fdedda738250894af6f59b045c8a0e" have entirely different histories.

5 changed files with 18 additions and 44 deletions

View File

@ -26,7 +26,6 @@ void sysinit(){
read_initrd(boot_info->initrd); read_initrd(boot_info->initrd);
modules_init(); modules_init();
vfile_t *initrc = fopen("/boot/initrc.conf"); vfile_t *initrc = fopen("/boot/initrc.conf");
mlog("RAE", "\033[1;32mDid you remember to migrate your modules to the new API?\033[0m\n", MLOG_PRINT);
if(initrc){ if(initrc){
mlog("KERNEL", "Found initrc", MLOG_PRINT); mlog("KERNEL", "Found initrc", MLOG_PRINT);
initrc_read(initrc); initrc_read(initrc);

View File

@ -19,7 +19,7 @@ void ramfs_init(){
root_dir.size = 4096;//one page is 4096 bytes root_dir.size = 4096;//one page is 4096 bytes
} }
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags){ void ramfs_create(char *path, FS_FILE_FLAGS flags){
return 0; return 0;
} }

View File

@ -2,6 +2,5 @@
#include <stdint.h> #include <stdint.h>
void ramfs_init(); void ramfs_init();
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags); void ramfs_create(char *path, FS_FILE_FLAGS flags);
//Will never create a new reference
vfile_t *get_root_dir(); vfile_t *get_root_dir();

View File

@ -1,5 +1,4 @@
#include "vfs.h" #include "vfs.h"
#include "ramfs.h"
#include "../shared/kstdlib.h" #include "../shared/kstdlib.h"
#include "../shared/memory.h" #include "../shared/memory.h"
#include "../shared/string.h" #include "../shared/string.h"
@ -8,9 +7,9 @@
// !TODO: Modify code to become thread-safe // !TODO: Modify code to become thread-safe
// void add_file(vfile_t *vfile, vfile_t *current_dir){ void add_file(vfile_t *vfile, vfile_t *current_dir){
// return; return;
// } }
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){ vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){
vfcreate(get_root_dir(), path, flags); vfcreate(get_root_dir(), path, flags);
@ -18,7 +17,7 @@ vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){
vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){ vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
if(!relpath){ if(!relpath){
return 0; return;
} }
char *name = kmalloc((strlen(relpath) + 4095)/4096);//don't make modifications to the original string char *name = kmalloc((strlen(relpath) + 4095)/4096);//don't make modifications to the original string
@ -42,45 +41,31 @@ vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
new_file = parent_dir->fileops->create(name, flags); new_file = parent_dir->fileops->create(name, flags);
} }
else{ else{
vfile_t *new_parent = rfopen(name, parent_dir); vfile_t *new_parent = lookup(name, parent_dir);
if(!new_parent){ if(!new_parent){
kfree(name); kfree(name);
return 0; return 0;
} }
new_file = vfcreate(new_parent, name+name_index+1, flags); new_file = vfcreate(new_parent, name+name_index+1, flags);
fclose(new_parent);
} }
kfree(name); kfree(name);
return new_file; return new_file;
} }
int fdelete(vfile_t *file_entry){ int fdelete(vfile_t *file_entry){
if(!file_entry || !file_entry->fileops || !file_entry->fileops->delete){
return 0; return 0;
}
return file_entry->fileops->delete(file_entry);
} }
int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count){ int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count){
if(!file_entry || !file_entry->fileops || !file_entry->fileops->write ||!byte_array || count == 0){
return 0; return 0;
}
return file_entry->fileops->write(file_entry, byte_array, offset, count);
} }
int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count){ int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count){
if(!file_entry || !file_entry->fileops || !file_entry->fileops->read || !byte_array || count == 0){
return 0; return 0;
}
return file_entry->fileops->read(file_entry, byte_array, offset, count);
} }
//fopen but relative to *dir vfile_t *lookup(char *name, vfile_t *dir){
vfile_t *rfopen(char *name, vfile_t *dir){
if(!dir || !name || !dir->fileops || !dir->fileops->rfopen){
return 0; return 0;
}
return dir->fileops->rfopen(name);
} }
int readdir(vfile_t* file, vfile_t* buffer, uint32_t offset, uint32_t count){ int readdir(vfile_t* file, vfile_t* buffer, uint32_t offset, uint32_t count){
@ -88,15 +73,6 @@ int readdir(vfile_t* file, vfile_t* buffer, uint32_t offset, uint32_t count){
} }
vfile_t *fopen(char *name){ vfile_t *fopen(char *name){
if(!name){
return 0;
}
vfile_t *root = get_root_dir();
return root->fileops->open(name + (name[0] == '/'));
}
vfile_t *fclose(vfile_t *file){
if(!file || !file->fileops || !file->fileops->close);
file->fileops->close(file);
return 0; return 0;
} }

View File

@ -19,8 +19,8 @@ typedef struct fileops{
int (*read)(struct virtual_file *file_entry, void *data, uint32_t offset, uint32_t count); int (*read)(struct virtual_file *file_entry, void *data, uint32_t offset, uint32_t count);
struct virtual_file *(*open)(char *path); struct virtual_file *(*open)(char *path);
void (*close)(struct virtual_file *file); void (*close)(struct virtual_file *file);
// int (*readdir)(struct virtual_file* file, struct virtual_file *buffer, uint32_t count, uint32_t offset); int (*readdir)(struct virtual_file* file, struct virtual_file *buffer, uint32_t count, uint32_t offset);
struct virtual_file *(*rfopen)(char *name); // struct virtual_file **(*lookup)(char *name);
} fileops_t; } fileops_t;
typedef struct virtual_file{ typedef struct virtual_file{
@ -37,14 +37,14 @@ typedef struct virtual_file{
}vfile_t; }vfile_t;
// vfile_t *rfopen(char *name, vfile_t dir); // vfile_t *lookup(char *name, vfile_t dir);
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags); vfile_t *fcreate(char *path, FS_FILE_FLAGS flags);
int fdelete(vfile_t* file_entry); int fdelete(vfile_t* file_entry);
int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count); int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count);
int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count); int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count);
// int readdir(vfile_t* file, vfile_t *buffer, uint32_t offset, uint32_t count); int readdir(vfile_t* file, vfile_t *buffer, uint32_t offset, uint32_t count);
vfile_t *vfcreate(vfile_t *parent, char *relpath, FS_FILE_FLAGS flags); vfile_t *vfcreate(vfile_t *parent, char *relpath, FS_FILE_FLAGS flags);
vfile_t *rfopen(char *name, vfile_t *dir); vfile_t *lookup(char *name, vfile_t *dir);
vfile_t *fopen(char *path); vfile_t *fopen(char *path);