From c5bd4e57664da00a013e6429e8723d979bbda97c Mon Sep 17 00:00:00 2001 From: notsomeidiot123 Date: Tue, 3 Mar 2026 21:12:26 -0500 Subject: [PATCH] Implemented MOUNT command for initrc.conf. Documentation in initrc.conf. (initrc.c:initrc_read()) --- initrc.conf | 9 +++- src/kernel/entry.s | 2 +- src/kernel/kmain.c | 2 +- src/kernel/shared/kstdlib.c | 24 +++++++++++ src/kernel/shared/kstdlib.h | 3 ++ src/kernel/system/intirc.c | 82 ++++++++++++++++++++++++++++++++++--- src/kernel/system/vfs.c | 2 +- 7 files changed, 114 insertions(+), 10 deletions(-) diff --git a/initrc.conf b/initrc.conf index 936f9ac..7eb6507 100644 --- a/initrc.conf +++ b/initrc.conf @@ -1,5 +1,10 @@ -ECHO "Initrc for Kimi's OS" -MODULE boot/idm.elf +ECHO "Initrc for Kimi's OS" # Prints a string to the debug log +MODULE boot/idm.elf # Loads and executes a module located at the path MODULE boot/ifsm.elf # This is a comment +# source file dest offset +# MOUNT /dev/disk/ide0 /home 0x1000 # this is hexadecimal + # 4096 this is decimal + #0010000 this is octal +MOUNT /dev/disk/ide0 /home END # does nothing but make the whole thing slightly more efficient ( stops before end of file's page) diff --git a/src/kernel/entry.s b/src/kernel/entry.s index 1aab9df..2468a14 100644 --- a/src/kernel/entry.s +++ b/src/kernel/entry.s @@ -14,5 +14,5 @@ _start: jmp $ section .bss -stack_bottom: resb 0x4000 +stack_bottom: resb 0x10000 stack_top: \ No newline at end of file diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index a6dcf23..82177d3 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -38,7 +38,7 @@ void sysinit(){ mlog("KERNEL", "Filename: %s\n", MLOG_PRINT, dir_data[i]->name); vfs_detect_partitions(dir_data[i]); } - dispatch_message(0); + // dispatch_message(0); printf("Bleh\n"); //why did i stop working on this? what was wrong with this? for(;;); diff --git a/src/kernel/shared/kstdlib.c b/src/kernel/shared/kstdlib.c index b110462..9236e26 100644 --- a/src/kernel/shared/kstdlib.c +++ b/src/kernel/shared/kstdlib.c @@ -1,6 +1,7 @@ #include "kstdlib.h" #include #include "memory.h" +#include "string.h" char* log_info_types[] = { "\b", @@ -99,4 +100,27 @@ void vector_pop(uint32_t pos, vector_t *vector, void *element){ ((uint8_t *)element)[i] = ((uint8_t *)(vector->ptr))[i]; } vector->size--; +} + +uint32_t atoi(char *str, uint32_t base){ + // char reverse[strlen(str)]; + // // printf("strlen: %d, %s", strlen(str), str); + // uint32_t j = 0; + // for(uint32_t i = strlen(str) - 1; i >= 0; i--){ + // j + // } + uint32_t i = 0; + uint32_t total = 0; + while(str[i]){ + char c = str[i]; + total *= base; + if(c >= 48 && c <= (57 - ((10 - base) * (base < 10)))){ + total += (c-48); + } + if(base > 10 && c >= 97 && c <= 102 - (16 - base)){ + total += (c - 97 + 10); + } + i++; + } + return total; } \ No newline at end of file diff --git a/src/kernel/shared/kstdlib.h b/src/kernel/shared/kstdlib.h index d89440e..af3e847 100644 --- a/src/kernel/shared/kstdlib.h +++ b/src/kernel/shared/kstdlib.h @@ -26,6 +26,9 @@ void *vector_get(uint32_t pos, vector_t *vector); void vector_set(uint32_t pos, vector_t *vector, void *new_element); void vector_push(vector_t *vector, void *new_element); void vector_pop(uint32_t pos, vector_t *vector, void *element); +uint32_t atoi(char *str, uint32_t base); + + typedef struct kernel_info{ void *mmap_ptr; diff --git a/src/kernel/system/intirc.c b/src/kernel/system/intirc.c index b48bdc3..ae59bd4 100644 --- a/src/kernel/system/intirc.c +++ b/src/kernel/system/intirc.c @@ -8,6 +8,12 @@ //link: create symlink from one file to another (useful for actually selecting where to mount things) //exec: execute program in userspace +int is_num(char c){ + if(c < 48 || (c > 57 && c < 97)) return 0; + if(c > 102) return 0; + return 1; +} + void initrc_read(vfile_t *file){ mlog("KERNEL", "Reading initrc:\n", MLOG_PRINT); @@ -17,6 +23,9 @@ void initrc_read(vfile_t *file){ uint32_t i = 0; while(strcmp(statement, "END")){ uint32_t s_i = 0; + while(ptr[i] == ' ' || ptr[i] == '\t' || ptr[i] == '\n'){ + i++; + } while(ptr[i] != ' ' && ptr[i] != '\n' && ptr[i]){ statement[s_i++] = ptr[i]; i++; @@ -27,7 +36,7 @@ void initrc_read(vfile_t *file){ i++; } } - if(!strcmp(statement, "ECHO")){ + else if(!strcmp(statement, "ECHO")){ //this is purely for testing purposes. printf("[ INITRC ]"); i++; @@ -39,11 +48,11 @@ void initrc_read(vfile_t *file){ } printf("\n"); } - if(!strcmp(statement, "MODULE")){ + else if(!strcmp(statement, "MODULE")){ i++; char module_name[512]; int j = 0; - for(; j < 512 && ptr[i + j] && ptr[i+j] != '\n'; j++){ + for(; j < 512 && ptr[i + j] && ptr[i+j] != '\n' && ptr[i + j] != ' '; j++){ module_name[j] = ptr[i + j]; } i+=j; @@ -56,10 +65,73 @@ void initrc_read(vfile_t *file){ } module_start(module->access.data.ptr); } - // printf("%d\n", i); - if(i >= size){ + else if(!strcmp(statement, "MOUNT")){ + char mount_src_name[512] = {0}; + char mount_dest[512] = {0}; + uint32_t offset = 0; + i++; + int j = 0; + for(; j < 512 && ptr[i + j] && ptr[i+j] != '\n' && ptr[i+j] != ' '; j++){ + mount_src_name[j] = ptr[i + j]; + } + i+=j; + mount_src_name[j] = 0; + for(j = 1; ptr[i + j] && ptr[i + j] != '\n' && ptr[i + j] != ' '; j++){ + mount_dest[j-1] = ptr[i + j]; + } + + mount_dest[j-1] = 0; + i += j; + if(ptr[i] == ' '){ + i++; + j = 0; + char atoi_str[512] = {0}; + + uint32_t base = 10; + if(ptr[i + j + 1] == 'x'){ + // printf("base 16\n"); + i+=2; + base = 16; + } + else if(ptr[i+j] == '0' && ptr[i+j+1] == '0'){ + // printf("Base 8!\n"); + i += 2; + base = 8; + } + + for(; j < 512 && ptr[i + j] && ptr[i+j] != '\n' && ptr[i + j] != ' ' && is_num(ptr[i+j]); j++){ + atoi_str[j] = ptr[i + j]; + } + i += j; + atoi_str[j] = 0; + + offset = atoi(atoi_str, base); + + // printf("String: %s, Result: %d\n", atoi_str, offset); + + } + + // if(ptr[i] ) + + // printf("TEST: %s, %s, %d\n", mount_src_name, mount_dest, ptr[i]); + + vfile_t *to_mount = fget_file(mount_src_name); + dispatch_message(MESSAGE_MOUNT_FS, to_mount, mount_dest, offset); + } + else if(!strcmp(statement, "END")){ return; } + else{ + printf("FATAL ERROR: Unknown Instruction: %s\n", statement); + asm("int $6"); + } + // printf("%d\n", i); + while(ptr[i] != '\n'){ + i++; + if(i >= size){ + return; + } + } i++; } } \ No newline at end of file diff --git a/src/kernel/system/vfs.c b/src/kernel/system/vfs.c index 44a9f04..3efc4b4 100644 --- a/src/kernel/system/vfs.c +++ b/src/kernel/system/vfs.c @@ -278,7 +278,7 @@ vfile_t *fget_file(char *name){ char *tmp = dir; uint32_t filename_offset = 0; vfile_t *current_dir = &root_dir; - vfile_t *tmpfile; + vfile_t *tmpfile = 0; while(tmp != 0){ dir = tmp; tmpfile = search_dir(tmp, *current_dir);