From 8a82600f5fab395c37bc4a08761b995a3db13145 Mon Sep 17 00:00:00 2001 From: notsomeidiot123 Date: Fri, 12 Sep 2025 15:34:34 -0400 Subject: [PATCH] Moving to my PC --- src/kernel/system/modules.c | 3 +++ src/kernel/system/modules.h | 11 ++++++----- src/kernel/system/vfs.c | 22 +++++++++++++--------- src/kernel/system/vfs.h | 2 +- src/kmodules/modlib.h | 11 ++++++----- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/kernel/system/modules.c b/src/kernel/system/modules.c index c857a0f..13dbd3c 100644 --- a/src/kernel/system/modules.c +++ b/src/kernel/system/modules.c @@ -57,6 +57,9 @@ uint32_t module_api(uint32_t func, ...){ case MODULE_API_DELET: return_value = -1; break; + case MODULE_API_OPEN: + return_value = -1; + break; case MODULE_API_MAP: return_value = -1; break; diff --git a/src/kernel/system/modules.h b/src/kernel/system/modules.h index 807387d..a4d8790 100644 --- a/src/kernel/system/modules.h +++ b/src/kernel/system/modules.h @@ -19,11 +19,12 @@ #define MODULE_API_WRITE 7 //write to virtual file #define MODULE_API_CREAT 8 //create a virtual file and assigns it to the the proper module (requires having a read and write function passed) #define MODULE_API_DELET 9 //delete a virtual file -#define MODULE_API_MAP 10 //map physical address to virtual address -#define MODULE_API_UNMAP 11 //unmap physical address to virtual address -#define MODULE_API_PADDR 12 //get physical address of memory -#define MODULE_API_MALLOC 13 //allocate memory in 4kb blocks -#define MODULE_API_FREE 14 //free memory allocated by malloc +#define MODULE_API_OPEN 10 +#define MODULE_API_MAP 11 //map physical address to virtual address +#define MODULE_API_UNMAP 12 //unmap physical address to virtual address +#define MODULE_API_PADDR 13 //get physical address of memory +#define MODULE_API_MALLOC 14 //allocate memory in 4kb blocks +#define MODULE_API_FREE 15 //free memory allocated by malloc typedef struct module{ void *init_entry; diff --git a/src/kernel/system/vfs.c b/src/kernel/system/vfs.c index ca87d4b..80f9ad2 100644 --- a/src/kernel/system/vfs.c +++ b/src/kernel/system/vfs.c @@ -45,7 +45,7 @@ Long comment cause this one's a complicated one. specify a pointer to be used as the write function, with the same function prototype as the function above void write(struct virtual_file *file, void *data, uint32_t offset, uint32_t count); */ -void fcreate(char *name, VFILE_TYPE type, ...){ +vfile_t *fcreate(char *name, VFILE_TYPE type, ...){ name += name[0]== '/'; char *last = strtok(name, '/'); char *tmp = last; @@ -79,7 +79,7 @@ void fcreate(char *name, VFILE_TYPE type, ...){ vfile->access.data.size_pgs = va_arg(args, uint32_t); add_file(vfile, current_dir); // printf("Created File: %s\n", vfile->name); - return; + break; case VFILE_FILE: case VFILE_DEVICE: void *write = va_arg(args, void *); @@ -87,8 +87,9 @@ void fcreate(char *name, VFILE_TYPE type, ...){ vfile->access.funcs.write = write; vfile->access.funcs.read = read; // strcpy + break; } - return; + return vfile; //allow drivers to make last minute changes before it's sent to the user } switch(tmpfile->type){ case VFILE_DIRECTORY: @@ -98,15 +99,18 @@ void fcreate(char *name, VFILE_TYPE type, ...){ ((mount_t*)(tmpfile->access.data.ptr))->create(name + filename_offset, type == VFILE_DIRECTORY ? FS_FILE_IS_DIR : 0); return; default: - mlog(MODULE_NAME, "Error: Cannot create file with same name as another file! %d\n", MLOG_ERR, tmpfile->type); - return; - break; + mlog(MODULE_NAME, "Error: Cannot create file with same name as another file! %d\n", MLOG_ERR, tmpfile->type); + return; + break; } filename_offset += strlen(tmp) + 1; tmp = strtok(0, '/'); } return; } + +//who needs a way to delete things? +//TODO: Write a function to delete files void fdelete(); // navya was here https://github.com/novabansal @@ -127,6 +131,7 @@ int fwrite(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t coun return file_entry->access.funcs.write(file_entry, byte_array, offset, count); break; } + return INT32_MIN;//how did we get here? } int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count){ @@ -145,6 +150,7 @@ int fread(vfile_t *file_entry, void *byte_array, uint32_t offset, uint32_t count return file_entry->access.funcs.read(file_entry, byte_array, offset, count); break; } + return INT32_MIN; //Okay, alright, funny joke guys but we really shouldn't be able to get here } vfile_t *search_dir(char *name, vfile_t dir){ @@ -186,6 +192,4 @@ int fopen(char *name, vfile_t *file){ } *file = *tmpfile; return 0; -} -//who needs a way to delete things? -//TODO: Write a function to delete files \ No newline at end of file +} \ No newline at end of file diff --git a/src/kernel/system/vfs.h b/src/kernel/system/vfs.h index 737e79c..85da1ae 100644 --- a/src/kernel/system/vfs.h +++ b/src/kernel/system/vfs.h @@ -46,7 +46,7 @@ typedef struct mount_funcs{ }mount_t; void vfs_init(); -void fcreate(char *name, VFILE_TYPE type, ...); +vfile_t *fcreate(char *name, VFILE_TYPE type, ...); void fdelete(); 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); diff --git a/src/kmodules/modlib.h b/src/kmodules/modlib.h index 162e544..1656b44 100644 --- a/src/kmodules/modlib.h +++ b/src/kmodules/modlib.h @@ -11,11 +11,12 @@ #define MODULE_API_WRITE 7 //write to virtual file #define MODULE_API_CREAT 8 //create a virtual file and assigns it to the the proper module (requires having a read and write function passed) #define MODULE_API_DELET 9 //delete a virtual file -#define MODULE_API_MAP 10 //map physical address to virtual address -#define MODULE_API_UNMAP 11 //unmap physical address to virtual address -#define MODULE_API_PADDR 12 //get physical address of memory -#define MODULE_API_MALLOC 13 //allocate memory in 4kb blocks -#define MODULE_API_FREE 14 //free memory allocated by malloc +#define MODULE_API_OPEN 10 //open a virtual file +#define MODULE_API_MAP 11 //map physical address to virtual address +#define MODULE_API_UNMAP 12 //unmap physical address to virtual address +#define MODULE_API_PADDR 13 //get physical address of memory +#define MODULE_API_MALLOC 14 //allocate memory in 4kb blocks +#define MODULE_API_FREE 15 //free memory allocated by malloc typedef uint32_t (*KOS_MAPI_FP)(unsigned int function, ...); typedef struct module{