still trying to read a file
This commit is contained in:
+21
-7
@@ -1,6 +1,7 @@
|
||||
#include "../include/vfs.h"
|
||||
#include "../include/stdio.h"
|
||||
#include "../include/string.h"
|
||||
#include "../include/paging.h"
|
||||
|
||||
l9660_fs global_fs;
|
||||
|
||||
@@ -48,25 +49,38 @@ void list_files(l9660_dir *dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t vfs_read_file(l9660_file *file, uint8_t* buffer)
|
||||
//TODO: fix invalid opcode exception that somehow happens when the memcpy is called with buffer+total_read address being 0xE0008CA0
|
||||
size_t vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size)
|
||||
{
|
||||
size_t total_read = 0;
|
||||
l9660_status status;
|
||||
|
||||
for(;;) {
|
||||
char buf[128];
|
||||
size_t read;
|
||||
l9660_read(file, buf, 128, &read);
|
||||
status = l9660_read(file, buf, 128, &read);
|
||||
|
||||
if (status != L9660_OK) {
|
||||
printf("An error occurred during file read!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("total_read: %X status: %X buffer+total_read: %X/%X read: %X\n", total_read, status, buffer + total_read, final_size, read);
|
||||
if(buffer+total_read == 0xE0008CA0)
|
||||
{
|
||||
printf("ERROR ERROR\n");
|
||||
printf("get_physaddr: %X", get_physaddr((void*)0xE0008CA0));
|
||||
}
|
||||
|
||||
//check for EOF
|
||||
if (read == 0)
|
||||
break;
|
||||
|
||||
memcpy(buffer, buf, 128);
|
||||
buffer += 128;
|
||||
memcpy(buffer + total_read, buf, read);
|
||||
total_read += read;
|
||||
}
|
||||
|
||||
//reset the current position to the original position
|
||||
buffer -= total_read;
|
||||
printf("total_read: %X\n", total_read);
|
||||
|
||||
return total_read;
|
||||
}
|
||||
@@ -186,8 +186,6 @@ void kmain(unsigned int magic, unsigned int info)
|
||||
|
||||
mount_fs();
|
||||
|
||||
test_iso9660();
|
||||
|
||||
exec_from_file("main.", ".");
|
||||
|
||||
while(1)
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
|
||||
int read_file(const char* path, uint8_t** buffer, l9660_dir* dir)
|
||||
{
|
||||
//file_t file;
|
||||
l9660_file file;
|
||||
|
||||
l9660_status err;
|
||||
|
||||
err = l9660_openat(&file, dir, path);//fat_fopen(&file, path, "r");
|
||||
err = l9660_openat(&file, dir, path);
|
||||
if (err != L9660_OK)
|
||||
{
|
||||
debug_log("read_file: err: 0x%X\n", err);
|
||||
@@ -27,28 +26,21 @@ int read_file(const char* path, uint8_t** buffer, l9660_dir* dir)
|
||||
}
|
||||
|
||||
l9660_seek(&file, L9660_SEEK_END, 0);
|
||||
uint32_t file_size = l9660_tell(&file);//fat_fsize(&file);
|
||||
uint32_t file_size = l9660_tell(&file);
|
||||
debug_log("file_size: %X\n", file_size);
|
||||
l9660_seek(&file, L9660_SEEK_SET, 0);
|
||||
|
||||
uint8_t buf[512];
|
||||
debug_log("heh\n");
|
||||
|
||||
*buffer = (uint8_t*)malloc(file_size+1);
|
||||
uint8_t* current = *buffer;
|
||||
*buffer = (uint8_t*)malloc(file_size);
|
||||
debug_log("eeee\n");
|
||||
|
||||
size_t read;
|
||||
|
||||
debug_log("info: buffer: %X, *buffer: %X, &buffer: %X\n", buffer, *buffer, &buffer);
|
||||
uint32_t final_size = (uint32_t)*buffer + file_size;
|
||||
|
||||
//err = l9660_read(&file, *buffer, file_size, &read);//fat_fread(&file, *buffer, file_size);
|
||||
read = vfs_read_file(&file, *buffer);
|
||||
read = vfs_read_file(&file, *buffer, final_size);
|
||||
debug_log("bytes read: 0x%X\n", read);
|
||||
|
||||
while(1){}
|
||||
|
||||
return 0;//fat_fclose(&file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void exec_from_file(const char* filename, const char* dirname)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../include/paging.h"
|
||||
#include "../include/string.h"
|
||||
#include "../include/screen.h"
|
||||
#include "../include/fat.h"
|
||||
|
||||
#define STDIN_FILENO 0
|
||||
#define STDOUT_FILENO 1
|
||||
@@ -156,7 +157,7 @@ int sys_read(TrapFrame *tf)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
return fat_fread(current->file_descriptors[tf->ebx], (void*)tf->ecx, tf->edx);
|
||||
return 0;//fat_fread(current->file_descriptors[tf->ebx], (void*)tf->ecx, tf->edx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +188,7 @@ int sys_write(TrapFrame *tf)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
return fat_fwrite(current->file_descriptors[tf->ebx], (void*)tf->ecx, tf->edx);
|
||||
return 0;//fat_fwrite(current->file_descriptors[tf->ebx], (void*)tf->ecx, tf->edx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +210,7 @@ int sys_open(TrapFrame *tf)
|
||||
{
|
||||
current->file_descriptors[i] = malloc(sizeof(file_t)); // Kernel malloc
|
||||
//debug_log("\n====FILE_DESCRIPTOR: %X\n", i);
|
||||
int result = fat_fopen(current->file_descriptors[i], filename, mode_str);
|
||||
int result = 0;//fat_fopen(current->file_descriptors[i], filename, mode_str);
|
||||
if (result < 0) {
|
||||
free(current->file_descriptors[i]); // Free on failure
|
||||
current->file_descriptors[i] = NULL;
|
||||
@@ -230,7 +231,7 @@ int sys_close(TrapFrame *tf)
|
||||
if(current->file_descriptors[fd] != NULL)
|
||||
{
|
||||
//debug_log("SYS_CLOSE: current->file_descriptors[fd] != NULL");
|
||||
int result = fat_fclose(current->file_descriptors[fd]);
|
||||
int result = 0;//fat_fclose(current->file_descriptors[fd]);
|
||||
//debug_log("SYS_CLOSE: fat_fclose result: 0x%X", result);
|
||||
free(current->file_descriptors[fd]);
|
||||
current->file_descriptors[fd] = NULL;
|
||||
@@ -241,10 +242,10 @@ int sys_close(TrapFrame *tf)
|
||||
|
||||
int sys_chdir(TrapFrame *tf)
|
||||
{
|
||||
strcat(current->cwd->fat->path, "/");
|
||||
strcat(current->cwd->fat->path, (char*)tf->ebx);
|
||||
//strcat(current->cwd->fat->path, "/");
|
||||
//strcat(current->cwd->fat->path, (char*)tf->ebx);
|
||||
|
||||
int result = fat_opendir(current->cwd, (const char*)tf->ebx);
|
||||
int result = 0;//fat_opendir(current->cwd, (const char*)tf->ebx);
|
||||
if(result == 0)
|
||||
return 0;
|
||||
|
||||
@@ -253,7 +254,7 @@ int sys_chdir(TrapFrame *tf)
|
||||
|
||||
int sys_getcwd(TrapFrame *tf)
|
||||
{
|
||||
strcpy((char*)tf->ebx, current->cwd->fat->path);
|
||||
//strcpy((char*)tf->ebx, current->cwd->fat->path);
|
||||
|
||||
return tf->ebx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user