Compare commits
3 Commits
2062a2dff3
...
e5ce4d42d1
| Author | SHA1 | Date |
|---|---|---|
|
|
e5ce4d42d1 | |
|
|
9abca0e245 | |
|
|
a83fc6a45d |
|
|
@ -26,6 +26,7 @@ void sysinit(){
|
|||
read_initrd(boot_info->initrd);
|
||||
modules_init();
|
||||
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){
|
||||
mlog("KERNEL", "Found initrc", MLOG_PRINT);
|
||||
initrc_read(initrc);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ void ramfs_init(){
|
|||
root_dir.size = 4096;//one page is 4096 bytes
|
||||
}
|
||||
|
||||
void ramfs_create(char *path, FS_FILE_FLAGS flags){
|
||||
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@
|
|||
#include <stdint.h>
|
||||
|
||||
void ramfs_init();
|
||||
void ramfs_create(char *path, FS_FILE_FLAGS flags);
|
||||
vfile_t *ramfs_create(char *path, FS_FILE_FLAGS flags);
|
||||
//Will never create a new reference
|
||||
vfile_t *get_root_dir();
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#include "vfs.h"
|
||||
#include "ramfs.h"
|
||||
#include "../shared/kstdlib.h"
|
||||
#include "../shared/memory.h"
|
||||
#include "../shared/string.h"
|
||||
|
|
@ -7,9 +8,9 @@
|
|||
// !TODO: Modify code to become thread-safe
|
||||
|
||||
|
||||
void add_file(vfile_t *vfile, vfile_t *current_dir){
|
||||
return;
|
||||
}
|
||||
// void add_file(vfile_t *vfile, vfile_t *current_dir){
|
||||
// return;
|
||||
// }
|
||||
|
||||
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){
|
||||
vfcreate(get_root_dir(), path, flags);
|
||||
|
|
@ -17,7 +18,7 @@ vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){
|
|||
|
||||
vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
|
||||
if(!relpath){
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *name = kmalloc((strlen(relpath) + 4095)/4096);//don't make modifications to the original string
|
||||
|
|
@ -41,31 +42,45 @@ vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
|
|||
new_file = parent_dir->fileops->create(name, flags);
|
||||
}
|
||||
else{
|
||||
vfile_t *new_parent = lookup(name, parent_dir);
|
||||
vfile_t *new_parent = rfopen(name, parent_dir);
|
||||
if(!new_parent){
|
||||
kfree(name);
|
||||
return 0;
|
||||
}
|
||||
new_file = vfcreate(new_parent, name+name_index+1, flags);
|
||||
fclose(new_parent);
|
||||
}
|
||||
kfree(name);
|
||||
return new_file;
|
||||
}
|
||||
|
||||
int fdelete(vfile_t *file_entry){
|
||||
return 0;
|
||||
if(!file_entry || !file_entry->fileops || !file_entry->fileops->delete){
|
||||
return 0;
|
||||
}
|
||||
return file_entry->fileops->delete(file_entry);
|
||||
}
|
||||
|
||||
int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count){
|
||||
return 0;
|
||||
if(!file_entry || !file_entry->fileops || !file_entry->fileops->write ||!byte_array || count == 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){
|
||||
return 0;
|
||||
if(!file_entry || !file_entry->fileops || !file_entry->fileops->read || !byte_array || count == 0){
|
||||
return 0;
|
||||
}
|
||||
return file_entry->fileops->read(file_entry, byte_array, offset, count);
|
||||
}
|
||||
|
||||
vfile_t *lookup(char *name, vfile_t *dir){
|
||||
return 0;
|
||||
//fopen but relative to *dir
|
||||
vfile_t *rfopen(char *name, vfile_t *dir){
|
||||
if(!dir || !name || !dir->fileops || !dir->fileops->rfopen){
|
||||
return 0;
|
||||
}
|
||||
return dir->fileops->rfopen(name);
|
||||
}
|
||||
|
||||
int readdir(vfile_t* file, vfile_t* buffer, uint32_t offset, uint32_t count){
|
||||
|
|
@ -73,6 +88,15 @@ int readdir(vfile_t* file, vfile_t* buffer, uint32_t offset, uint32_t count){
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -19,8 +19,8 @@ typedef struct fileops{
|
|||
int (*read)(struct virtual_file *file_entry, void *data, uint32_t offset, uint32_t count);
|
||||
struct virtual_file *(*open)(char *path);
|
||||
void (*close)(struct virtual_file *file);
|
||||
int (*readdir)(struct virtual_file* file, struct virtual_file *buffer, uint32_t count, uint32_t offset);
|
||||
// struct virtual_file **(*lookup)(char *name);
|
||||
// int (*readdir)(struct virtual_file* file, struct virtual_file *buffer, uint32_t count, uint32_t offset);
|
||||
struct virtual_file *(*rfopen)(char *name);
|
||||
} fileops_t;
|
||||
|
||||
typedef struct virtual_file{
|
||||
|
|
@ -37,14 +37,14 @@ typedef struct virtual_file{
|
|||
|
||||
}vfile_t;
|
||||
|
||||
// vfile_t *lookup(char *name, vfile_t dir);
|
||||
// vfile_t *rfopen(char *name, vfile_t dir);
|
||||
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags);
|
||||
int fdelete(vfile_t* file_entry);
|
||||
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 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 *lookup(char *name, vfile_t *dir);
|
||||
vfile_t *rfopen(char *name, vfile_t *dir);
|
||||
|
||||
vfile_t *fopen(char *path);
|
||||
Loading…
Reference in New Issue