still trying to read a file

This commit is contained in:
2025-08-16 21:43:42 +03:00
parent ce6e9642ee
commit 0628470a7c
7 changed files with 44 additions and 36 deletions
+3
View File
@@ -58,6 +58,9 @@ iso:
test-cdrom: test-cdrom:
qemu-system-i386 -cdrom boot.iso -m 4096M -d int qemu-system-i386 -cdrom boot.iso -m 4096M -d int
debug-cdrom:
qemu-system-i386 -s -S -cdrom boot.iso -m 4096M -monitor stdio
test: test:
qemu-system-i386 -drive file=boot.iso,media=disk,format=raw -m 4096M -d int qemu-system-i386 -drive file=boot.iso,media=disk,format=raw -m 4096M -d int
+4 -4
View File
@@ -1,6 +1,6 @@
romimage: file=$BXSHARE/BIOS-bochs-latest romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
#boot: cdrom boot: cdrom
#ata0-master: type=cdrom, path="boot.iso", status=inserted ata0-master: type=cdrom, path="boot.iso", status=inserted
boot:disk #boot:disk
ata0-master: type=disk, path="boot.iso", cylinders=306, heads=16, spt=17 #ata0-master: type=disk, path="boot.iso", cylinders=306, heads=16, spt=17
+1 -1
View File
@@ -11,6 +11,6 @@ bool read_sector_callback(l9660_fs *fs, void *buf, uint32_t sector);
void mount_fs(); void mount_fs();
void list_files(l9660_dir *dir); void list_files(l9660_dir *dir);
size_t vfs_read_file(l9660_file *file, uint8_t* buffer); size_t vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size);
#endif #endif
+21 -7
View File
@@ -1,6 +1,7 @@
#include "../include/vfs.h" #include "../include/vfs.h"
#include "../include/stdio.h" #include "../include/stdio.h"
#include "../include/string.h" #include "../include/string.h"
#include "../include/paging.h"
l9660_fs global_fs; l9660_fs global_fs;
@@ -48,25 +49,38 @@ void list_files(l9660_dir *dir)
} }
} }
//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 vfs_read_file(l9660_file *file, uint8_t* buffer, size_t final_size)
{ {
size_t total_read = 0; size_t total_read = 0;
l9660_status status;
for(;;) { for(;;) {
char buf[128]; char buf[128];
size_t read; 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 //check for EOF
if (read == 0) if (read == 0)
break; break;
memcpy(buffer, buf, 128); memcpy(buffer + total_read, buf, read);
buffer += 128;
total_read += read; total_read += read;
} }
//reset the current position to the original position printf("total_read: %X\n", total_read);
buffer -= total_read;
return total_read; return total_read;
} }
-2
View File
@@ -186,8 +186,6 @@ void kmain(unsigned int magic, unsigned int info)
mount_fs(); mount_fs();
test_iso9660();
exec_from_file("main.", "."); exec_from_file("main.", ".");
while(1) while(1)
+6 -14
View File
@@ -14,12 +14,11 @@
int read_file(const char* path, uint8_t** buffer, l9660_dir* dir) int read_file(const char* path, uint8_t** buffer, l9660_dir* dir)
{ {
//file_t file;
l9660_file file; l9660_file file;
l9660_status err; l9660_status err;
err = l9660_openat(&file, dir, path);//fat_fopen(&file, path, "r"); err = l9660_openat(&file, dir, path);
if (err != L9660_OK) if (err != L9660_OK)
{ {
debug_log("read_file: err: 0x%X\n", err); 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); 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); debug_log("file_size: %X\n", file_size);
l9660_seek(&file, L9660_SEEK_SET, 0); l9660_seek(&file, L9660_SEEK_SET, 0);
uint8_t buf[512]; *buffer = (uint8_t*)malloc(file_size);
debug_log("heh\n");
*buffer = (uint8_t*)malloc(file_size+1);
uint8_t* current = *buffer;
debug_log("eeee\n"); debug_log("eeee\n");
size_t read; 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, final_size);
read = vfs_read_file(&file, *buffer);
debug_log("bytes read: 0x%X\n", read); 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) void exec_from_file(const char* filename, const char* dirname)
+9 -8
View File
@@ -5,6 +5,7 @@
#include "../include/paging.h" #include "../include/paging.h"
#include "../include/string.h" #include "../include/string.h"
#include "../include/screen.h" #include "../include/screen.h"
#include "../include/fat.h"
#define STDIN_FILENO 0 #define STDIN_FILENO 0
#define STDOUT_FILENO 1 #define STDOUT_FILENO 1
@@ -156,7 +157,7 @@ int sys_read(TrapFrame *tf)
{ {
return -EBADF; 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 -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 current->file_descriptors[i] = malloc(sizeof(file_t)); // Kernel malloc
//debug_log("\n====FILE_DESCRIPTOR: %X\n", i); //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) { if (result < 0) {
free(current->file_descriptors[i]); // Free on failure free(current->file_descriptors[i]); // Free on failure
current->file_descriptors[i] = NULL; current->file_descriptors[i] = NULL;
@@ -230,7 +231,7 @@ int sys_close(TrapFrame *tf)
if(current->file_descriptors[fd] != NULL) if(current->file_descriptors[fd] != NULL)
{ {
//debug_log("SYS_CLOSE: 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); //debug_log("SYS_CLOSE: fat_fclose result: 0x%X", result);
free(current->file_descriptors[fd]); free(current->file_descriptors[fd]);
current->file_descriptors[fd] = NULL; current->file_descriptors[fd] = NULL;
@@ -241,10 +242,10 @@ 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, "/");
strcat(current->cwd->fat->path, (char*)tf->ebx); //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) if(result == 0)
return 0; return 0;
@@ -253,7 +254,7 @@ int sys_chdir(TrapFrame *tf)
int sys_getcwd(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; return tf->ebx;
} }