syscalls: hopefully implement chdir syscall

This commit is contained in:
2025-10-30 22:29:06 +03:00
parent f4b0429062
commit 561de6a4e3
3 changed files with 37 additions and 6 deletions
+1 -1
View File
@@ -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);
+6 -4
View File
@@ -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
+30 -1
View File
@@ -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;
}