syscalls: fix cwd-related stuff
This commit is contained in:
@@ -2,4 +2,4 @@
|
|||||||
#include "../include/elf.h"
|
#include "../include/elf.h"
|
||||||
#include "../include/stdio.h"
|
#include "../include/stdio.h"
|
||||||
|
|
||||||
void exec_from_file(const char* filename);
|
void exec_from_file(const char* filename, const char* dirname);
|
||||||
@@ -8,5 +8,7 @@ void* memcpy(void* __restrict, const void* __restrict, size_t);
|
|||||||
void* memmove(void*, const void*, size_t);
|
void* memmove(void*, const void*, size_t);
|
||||||
void* memset(void*, int, size_t);
|
void* memset(void*, int, size_t);
|
||||||
size_t strlen(const char*);
|
size_t strlen(const char*);
|
||||||
|
char *strcat(char *dest, const char *src);
|
||||||
|
char *strcpy(char *dest, const char *src);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -218,7 +218,7 @@ void kmain(unsigned int magic, unsigned int info)
|
|||||||
printf("huy1 points to: 0x%X huy2 points to:0x%X\n", huy, huy2);
|
printf("huy1 points to: 0x%X huy2 points to:0x%X\n", huy, huy2);
|
||||||
printf("huy1: %s\nhuy2: %s", huy, huy2);
|
printf("huy1: %s\nhuy2: %s", huy, huy2);
|
||||||
|
|
||||||
exec_from_file("/ebalo/forktest");
|
exec_from_file("/ebalo/aye", "/ebalo/");
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ disk_ops_t ops1 =
|
|||||||
|
|
||||||
static fat_t g_fat;
|
static fat_t g_fat;
|
||||||
|
|
||||||
int read_file(const char* path, uint8_t** buffer)
|
int read_file(const char* path, uint8_t** buffer, dir_t* dir)
|
||||||
{
|
{
|
||||||
file_t file;
|
file_t file;
|
||||||
int err = fat_fopen(&file, path, "r");
|
int err = fat_fopen(&file, path, "r");
|
||||||
@@ -39,18 +39,21 @@ int read_file(const char* path, uint8_t** buffer)
|
|||||||
|
|
||||||
int cnt = fat_fread(&file, *buffer, file_size);
|
int cnt = fat_fread(&file, *buffer, file_size);
|
||||||
|
|
||||||
|
*dir = file.dir;
|
||||||
|
|
||||||
return fat_fclose(&file);
|
return fat_fclose(&file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void exec_from_file(const char* filename)
|
void exec_from_file(const char* filename, const char* dirname)
|
||||||
{
|
{
|
||||||
asm volatile("cli");
|
asm volatile("cli");
|
||||||
int err, cnt;
|
int err, cnt;
|
||||||
err = fat_mount(&ops1, 0, &g_fat, "ebalo");
|
err = fat_mount(&ops1, 0, &g_fat, "ebalo");
|
||||||
|
|
||||||
uint8_t* file;
|
uint8_t* file;
|
||||||
|
dir_t dir;
|
||||||
|
|
||||||
int result = read_file(filename, &file);
|
int result = read_file(filename, &file, &dir);
|
||||||
//debug_log("result: %X\n", result);
|
//debug_log("result: %X\n", result);
|
||||||
//debug_log("buffer: %s\n", file);
|
//debug_log("buffer: %s\n", file);
|
||||||
|
|
||||||
@@ -140,6 +143,7 @@ void exec_from_file(const char* filename)
|
|||||||
|
|
||||||
set_page_dir(curr_pd_phys);
|
set_page_dir(curr_pd_phys);
|
||||||
Process* p_task1 = task_create(elf_ehdr->e_entry, USER_STACK_TOP, 3, proc_pd);
|
Process* p_task1 = task_create(elf_ehdr->e_entry, USER_STACK_TOP, 3, proc_pd);
|
||||||
|
*p_task1->cwd = dir;
|
||||||
|
|
||||||
asm volatile("sti");
|
asm volatile("sti");
|
||||||
}
|
}
|
||||||
@@ -232,17 +232,15 @@ int sys_close(TrapFrame *tf)
|
|||||||
|
|
||||||
int sys_chdir(TrapFrame *tf)
|
int sys_chdir(TrapFrame *tf)
|
||||||
{
|
{
|
||||||
|
strcat(current->cwd->fat->path, "/");
|
||||||
|
strcat(current->cwd->fat->path, (char*)tf->ebx);
|
||||||
return fat_opendir(current->cwd, (const char*)tf->ebx);
|
return fat_opendir(current->cwd, (const char*)tf->ebx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sys_getcwd(TrapFrame *tf)
|
int sys_getcwd(TrapFrame *tf)
|
||||||
{
|
{
|
||||||
int len = tf->ecx;
|
strcpy((char*)tf->ebx, current->cwd->fat->path);
|
||||||
|
|
||||||
if(len >= 260)
|
|
||||||
return (int)NULL;
|
|
||||||
|
|
||||||
memcpy((void*)tf->ebx, current->cwd->fat->name, current->cwd->fat->namelen);
|
|
||||||
return tf->ebx;
|
return tf->ebx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,3 +48,25 @@ size_t strlen(const char* str)
|
|||||||
len++;
|
len++;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *strcat(char *dest, const char *src) {
|
||||||
|
char *original_dest = dest;
|
||||||
|
|
||||||
|
while (*dest != '\0') {
|
||||||
|
dest++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((*dest++ = *src++) != '\0')
|
||||||
|
;
|
||||||
|
|
||||||
|
return original_dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *strcpy(char *dest, const char *src) {
|
||||||
|
char *original_dest = dest;
|
||||||
|
|
||||||
|
while ((*dest++ = *src++) != '\0')
|
||||||
|
;
|
||||||
|
|
||||||
|
return original_dest;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user