Okay now we're done frfr... I hope...
This commit is contained in:
parent
ff9425c321
commit
b24c215984
|
|
@ -63,6 +63,7 @@ void fcreate(char *name, VFILE_TYPE type, ...){
|
||||||
//create file in folder;
|
//create file in folder;
|
||||||
vfile_t *vfile = kmalloc(1);
|
vfile_t *vfile = kmalloc(1);
|
||||||
vfile->type = type;
|
vfile->type = type;
|
||||||
|
vfile->parent = current_dir;
|
||||||
uint32_t tmpnsize = strlen(tmp);
|
uint32_t tmpnsize = strlen(tmp);
|
||||||
if(tmp[tmpnsize - 1] == '/'){
|
if(tmp[tmpnsize - 1] == '/'){
|
||||||
tmp[tmpnsize - 1] = 0;
|
tmp[tmpnsize - 1] = 0;
|
||||||
|
|
@ -109,25 +110,42 @@ void fcreate(char *name, VFILE_TYPE type, ...){
|
||||||
void fdelete();
|
void fdelete();
|
||||||
|
|
||||||
// navya was here https://github.com/novabansal
|
// navya was here https://github.com/novabansal
|
||||||
uint32_t 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){
|
||||||
// a: a way to call RW functions from any given module
|
//sorry navya, I deleted the comment and it's not coming back :(
|
||||||
// OR
|
|
||||||
// b: specify a pointer to data that is written to virtual file in memory
|
|
||||||
|
|
||||||
// search through root directory
|
|
||||||
switch(file_entry->type){
|
switch(file_entry->type){
|
||||||
|
case VFILE_DIRECTORY:
|
||||||
case VFILE_POINTER:
|
case VFILE_POINTER:
|
||||||
memcpy(byte_array, file_entry->access.data.ptr + offset, count);
|
memcpy(byte_array, file_entry->access.data.ptr + offset, count);
|
||||||
|
return 0; //always successful. If it's not, there's been a page fault. Yk, quantum sort style.
|
||||||
break;
|
break;
|
||||||
|
case VFILE_MOUNT:
|
||||||
|
mount_t *funcs = file_entry->access.data.ptr;
|
||||||
|
return funcs->write(file_entry, byte_array, offset, count);
|
||||||
case VFILE_PDIR:
|
case VFILE_PDIR:
|
||||||
case VFILE_FILE:
|
case VFILE_FILE:
|
||||||
case VFILE_DEVICE:
|
case VFILE_DEVICE:
|
||||||
file_entry->access.funcs.write(file_entry, byte_array, offset, count);
|
return file_entry->access.funcs.write(file_entry, byte_array, offset, count);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t fread();
|
int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count){
|
||||||
|
switch(file_entry->type){
|
||||||
|
case VFILE_DIRECTORY:
|
||||||
|
case VFILE_POINTER:
|
||||||
|
memcpy(file_entry->access.data.ptr + offset, byte_array, count);
|
||||||
|
return 0; //always successful. If it's not, there's been a page fault. Yk, quantum sort style.
|
||||||
|
break;
|
||||||
|
case VFILE_MOUNT:
|
||||||
|
mount_t *funcs = file_entry->access.data.ptr;
|
||||||
|
return funcs->read(file_entry, byte_array, offset, count);
|
||||||
|
case VFILE_PDIR:
|
||||||
|
case VFILE_FILE:
|
||||||
|
case VFILE_DEVICE:
|
||||||
|
return file_entry->access.funcs.read(file_entry, byte_array, offset, count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vfile_t *search_dir(char *name, vfile_t dir){
|
vfile_t *search_dir(char *name, vfile_t dir){
|
||||||
vfile_t **dir_data = (vfile_t **)dir.access.data.ptr;
|
vfile_t **dir_data = (vfile_t **)dir.access.data.ptr;
|
||||||
|
|
@ -168,4 +186,6 @@ int fopen(char *name, vfile_t *file){
|
||||||
}
|
}
|
||||||
*file = *tmpfile;
|
*file = *tmpfile;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
//who needs a way to delete things?
|
||||||
|
//TODO: Write a function to delete files
|
||||||
|
|
@ -16,10 +16,11 @@ typedef struct virtual_file{
|
||||||
VFILE_TYPE type;
|
VFILE_TYPE type;
|
||||||
uint32_t id;//to be assigned by driver;
|
uint32_t id;//to be assigned by driver;
|
||||||
uint32_t mount_id;
|
uint32_t mount_id;
|
||||||
|
struct virtual_file *parent;//should point to A: a virtual directory, or B: a mounted filesystem
|
||||||
union{
|
union{
|
||||||
struct{
|
struct{
|
||||||
void (*read)(struct virtual_file *file, void *data, uint32_t offset, uint32_t count);
|
int (*read)(struct virtual_file *file, void *data, uint32_t offset, uint32_t count);
|
||||||
void (*write)(struct virtual_file *file, void *data, uint32_t offset, uint32_t count);
|
int (*write)(struct virtual_file *file, void *data, uint32_t offset, uint32_t count);
|
||||||
}funcs;
|
}funcs;
|
||||||
struct{
|
struct{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
@ -47,7 +48,7 @@ typedef struct mount_funcs{
|
||||||
void vfs_init();
|
void vfs_init();
|
||||||
void fcreate(char *name, VFILE_TYPE type, ...);
|
void fcreate(char *name, VFILE_TYPE type, ...);
|
||||||
void fdelete();
|
void fdelete();
|
||||||
uint32_t fwrite();
|
int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count);
|
||||||
uint32_t fread();
|
int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count);
|
||||||
vfile_t *search_dir(char *name, vfile_t dir);
|
vfile_t *search_dir(char *name, vfile_t dir);
|
||||||
int fopen(char *name, vfile_t *file);
|
int fopen(char *name, vfile_t *file);
|
||||||
Loading…
Reference in New Issue