diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index aac4c1c..a84feb8 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -31,6 +31,7 @@ extern void kmain(kernel_info_t *kernel_info){ pic_disable(); pic_setmask(0xfe, PIC1_DATA); vfs_init(); + fcreate("Testing/testing/bleh", 0); //TODO: Map and load filesystem and disk modules //TODO: Start Initial Process mlog("KERNEL", "Initializing Scheduler & starting PID 1\n", MLOG_PRINT); diff --git a/src/kernel/shared/kstring.c b/src/kernel/shared/kstring.c new file mode 100644 index 0000000..a06b6e7 --- /dev/null +++ b/src/kernel/shared/kstring.c @@ -0,0 +1,32 @@ +#include "string.h" + +#pragma warning + +char res[256]; + +char* strtok(char* string, char d) +{ + static char* input = 0; + + if (string){ + input = string; + } + if (!input){ + return 0; + } + int i = 0; + for (; input[i] != 0; i++) { + if (input[i] != d){ + res[i] = input[i]; + } + else { + res[i] = '\0'; + input = input + i+1; + return res; + } + } + res[i] = '\0'; + input = 0; + + return res; +} \ No newline at end of file diff --git a/src/kernel/shared/string.h b/src/kernel/shared/string.h index aa95c08..5c3efe3 100644 --- a/src/kernel/shared/string.h +++ b/src/kernel/shared/string.h @@ -3,6 +3,7 @@ void itoa(int64_t data, char *res, uint8_t base); void strpad(char *string, char padding, uint32_t length); +//str cannot be null inline uint32_t strlen(char *str){ uint32_t c = 0; while(*str){ @@ -11,5 +12,15 @@ inline uint32_t strlen(char *str){ } return c; } +//str1 and str2 both cannot be null +inline uint32_t strcmp(char *str1, char *str2){ + uint32_t i = 0; + while(str1[i] && str1[i] == str2[i]){ + i++; + } + if(str1[i] == str2[i]) return 0; + else return 1; +} +char *strtok(char *str, char delim); void strcpy(char *src, char *dest); void memcpy(char *src, char *dest, uint32_t c); \ No newline at end of file diff --git a/src/kernel/system/vfs.c b/src/kernel/system/vfs.c index 01a0f09..482583f 100644 --- a/src/kernel/system/vfs.c +++ b/src/kernel/system/vfs.c @@ -1,16 +1,57 @@ #include "vfs.h" #include "../shared/kstdlib.h" - -vfile_t root_dir = {"/", VFILE_DIRECTORY}; +#include "../shared/memory.h" +#include "../shared/string.h" +#define MODULE_NAME "KVFS" +vfile_t root_dir = {"\0", VFILE_DIRECTORY}; void vfs_init(){ - // mlog() + mlog(MODULE_NAME, "Initializing VFS\n", MLOG_PRINT); root_dir.access.data.ptr = kmalloc(1); root_dir.access.data.size_pgs = 1; } -void fcreate(); +void fcreate(char *name, VFILE_TYPE type, ...){ + printf("Sasdafdasdf\n"); + char *dir = strtok(name, '/'); + char *file = dir; + char *tmp = dir; + while(tmp != 0){ + dir = file; + file = tmp; + tmp = strtok(0, '/'); + } +} void fdelete(); -uint32_t fwrite(); + +// navya was here https://github.com/novabansal +uint32_t 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 + // OR + // b: specify a pointer to data that is written to virtual file in memory + + // search through root directory + switch(file_entry->type){ + case VFILE_DEVICE: + file_entry->access.funcs.write(byte_array, offset, count); + } +} uint32_t fread(); -void fopen(); \ No newline at end of file +void fopen(char *name){ + char *dir = strtok(name, '/'); + char *tmp = dir; + vfile_t *current_dir = &root_dir; + 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 == ) + } + } + + tmp = strtok(0, '/'); + } + return; +} \ No newline at end of file diff --git a/src/kernel/system/vfs.h b/src/kernel/system/vfs.h index 8dfa45f..c783714 100644 --- a/src/kernel/system/vfs.h +++ b/src/kernel/system/vfs.h @@ -27,8 +27,8 @@ typedef struct virtual_file_t{ }vfile_t; void vfs_init(); -void fcreate(); +void fcreate(char *name, VFILE_TYPE type, ...); void fdelete(); uint32_t fwrite(); uint32_t fread(); -void fopen(); \ No newline at end of file +void fopen(char *name); \ No newline at end of file diff --git a/src/kmodules/modlib.h b/src/kmodules/modlib.h index a1d758b..7cf0f6d 100644 --- a/src/kmodules/modlib.h +++ b/src/kmodules/modlib.h @@ -23,4 +23,12 @@ typedef struct module{ uint32_t id; char name[16]; uint8_t flags; -}module_t; \ No newline at end of file +}module_t; + +typedef enum vfile_type{ + VFILE_POINTER, + VFILE_DEVICE, + VFILE_MOUNT, + VFILE_DIRECTORY, + VFILE_FILE, +}VFILE_TYPE; \ No newline at end of file