Decoupled ramfs from vfs functionality
This commit is contained in:
parent
a83fc6a45d
commit
9abca0e245
|
|
@ -3,4 +3,5 @@
|
||||||
|
|
||||||
void ramfs_init();
|
void ramfs_init();
|
||||||
vfile_t *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();
|
vfile_t *get_root_dir();
|
||||||
|
|
@ -42,31 +42,45 @@ 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 = lookup(name, parent_dir);
|
vfile_t *new_parent = rfopen(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){
|
||||||
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){
|
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){
|
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){
|
//fopen but relative to *dir
|
||||||
return 0;
|
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){
|
int readdir(vfile_t* file, vfile_t* buffer, uint32_t offset, uint32_t count){
|
||||||
|
|
@ -74,6 +88,15 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
@ -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 **(*lookup)(char *name);
|
struct virtual_file *(*rfopen)(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 *lookup(char *name, vfile_t dir);
|
// vfile_t *rfopen(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 *lookup(char *name, vfile_t *dir);
|
vfile_t *rfopen(char *name, vfile_t *dir);
|
||||||
|
|
||||||
vfile_t *fopen(char *path);
|
vfile_t *fopen(char *path);
|
||||||
Loading…
Reference in New Issue