diff --git a/include/vfs.h b/include/vfs.h index 13a28db..c509d41 100644 --- a/include/vfs.h +++ b/include/vfs.h @@ -20,7 +20,7 @@ size_t vfs_read_file_length(l9660_file *file, uint8_t* buffer, size_t length); void test_iso9660(); int vfs_read_file_by_path(const char* path, uint8_t** buffer); -void follow_path(const char* path, l9660_file* file, l9660_dir* dir); +int follow_path(const char* path, l9660_file* file, l9660_dir* dir); l9660_status find_name_for_sector(char* name_buf, int buf_len, l9660_dir* parent_dir, uint32_t child_sector); bool is_root_dir(l9660_dir* dir); diff --git a/src/fs/vfs.c b/src/fs/vfs.c index 5bbcd08..2858066 100644 --- a/src/fs/vfs.c +++ b/src/fs/vfs.c @@ -220,7 +220,7 @@ int vfs_read_file_by_path(const char* path, uint8_t** buffer) return 0; } -void follow_path(const char* path, l9660_file* file, l9660_dir* dir) +int follow_path(const char* path, l9660_file* file, l9660_dir* dir) { int pos = 0; int start_from_root = 0; @@ -263,7 +263,7 @@ void follow_path(const char* path, l9660_file* file, l9660_dir* dir) if(status != L9660_OK) { debug_log("FUCKFUCKFUCKFUCK BLYAAAT!!!!!\n"); - return; + return status; } *dir = dir2; } @@ -275,15 +275,17 @@ void follow_path(const char* path, l9660_file* file, l9660_dir* dir) if(status != L9660_OK) { debug_log("PIZDAPIZDA BLYAAAT!!!!!\n"); - return; + return status; } - return; + return status; } pos++; } debug_log("\n"); //printf("buf: %s\n", buf); debug_log("isdir: %X\n", isdir); + + return status; } #ifdef L9660_BIG_ENDIAN diff --git a/src/tasking/syscalls.c b/src/tasking/syscalls.c index 3830a60..bdc4249 100644 --- a/src/tasking/syscalls.c +++ b/src/tasking/syscalls.c @@ -406,6 +406,35 @@ int sys_execve(TrapFrame *tf) { int sys_chdir(TrapFrame *tf) { + l9660_dir new_cwd; + l9660_file placeholder_file; + + int status = follow_path((char*)tf->ebx, &placeholder_file, &new_cwd); + + if(status == L9660_OK) + { + *(current->cwd) = new_cwd; + } + + switch(status) + { + case L9660_EIO: + return -5;//-EIO + break; + case L9660_EBADFS: + return -5;//EIO as well + break; + case L9660_ENOENT: + return -2; + break; + case L9660_ENOTDIR: + return -20;//ENOTDIR + break; + default: + return -5;//EIO + break; + } + //strcat(current->cwd->fat->path, "/"); //strcat(current->cwd->fat->path, (char*)tf->ebx); @@ -503,7 +532,7 @@ uint32_t sys_brk(TrapFrame *tf) debug_log("mapping page %X to %X\n", phys_addr, virt_addr); memset(virt_addr, 0, 0x1000); current->brk = (void*)tf->ebx; - debug_log("new brk is %X\n", (uint32_t)current->brk); + //debug_log("new brk is %X\n", (uint32_t)current->brk); } return (uint32_t)current->brk; }