diff --git a/include/vfs.h b/include/vfs.h index 877b2d4..dbf92f9 100644 --- a/include/vfs.h +++ b/include/vfs.h @@ -17,4 +17,6 @@ void list_files(l9660_dir *dir); size_t vfs_read_file(l9660_file *file, uint8_t* buffer); size_t vfs_read_file_length(l9660_file *file, uint8_t* buffer, size_t length); +void test_iso9660(); + #endif \ No newline at end of file diff --git a/src/fs/vfs.c b/src/fs/vfs.c index 6821115..9503842 100644 --- a/src/fs/vfs.c +++ b/src/fs/vfs.c @@ -117,4 +117,76 @@ size_t vfs_read_file_length(l9660_file *file, uint8_t* buffer, size_t length) } return total_read; +} + +void test_iso9660() +{ + l9660_file g_test_file; + + l9660_status status; + + printf("Files in root directory:\n"); + for (;;) { + l9660_dirent *dent; + status = l9660_readdir(root_dir, &dent); + + if (dent == NULL || status != L9660_OK) { + break; // End of directory or error + } + + // Print the filename. It's not null-terminated, so use the length field. + for (int i = 0; i < dent->name_len; ++i) { + printf("%c", dent->name[i]); + } + printf("\n"); + } + + printf("\nReading content of /TEST.TXT:\n"); + + // Re-open the root directory to reset its position before searching + l9660_fs_open_root(root_dir, global_fs); + + l9660_dir boot_dir; + l9660_dir grub_dir; + status = l9660_opendirat(&boot_dir, root_dir, "boot"); + printf("STATUS %X\n", status); + status = l9660_opendirat(&grub_dir, &boot_dir, "grub"); + printf("STATUS %X\n", status); + + status = l9660_openat(&g_test_file, &grub_dir, "grub.cfg"); + + if (status != L9660_OK) { + printf("Error opening TEST.TXT;1. Error code: "); + printf("%X\n", status); // Print the error code + printf("\n"); + } else { + char file_buffer[129]; + size_t bytes_read; + uint32_t total_bytes; + + for (;;) { + // Read the next chunk of the file + status = l9660_read(&g_test_file, file_buffer, 128, &bytes_read); + + // Check for a read error + if (status != L9660_OK) { + printf("An error occurred during file read!\n"); + break; + } + + // Check for End-Of-File + if (bytes_read == 0) { + break; // We're done + } + + // Process the data we just read + total_bytes += bytes_read; + file_buffer[bytes_read] = '\0'; // Null-terminate the chunk + printf(file_buffer); // Print the chunk + } + + printf("\n--- EOF ---\n"); + printf("Total bytes read: "); + printf("0x%X\n", total_bytes); + } } \ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index ad93a90..720463b 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -26,78 +26,6 @@ void apply_pic_masks() outb(0xa1,0xff); } -void test_iso9660() -{ - l9660_file g_test_file; - - l9660_status status; - - printf("Files in root directory:\n"); - for (;;) { - l9660_dirent *dent; - status = l9660_readdir(root_dir, &dent); - - if (dent == NULL || status != L9660_OK) { - break; // End of directory or error - } - - // Print the filename. It's not null-terminated, so use the length field. - for (int i = 0; i < dent->name_len; ++i) { - printf("%c", dent->name[i]); - } - printf("\n"); - } - - printf("\nReading content of /TEST.TXT:\n"); - - // Re-open the root directory to reset its position before searching - l9660_fs_open_root(root_dir, global_fs); - - l9660_dir boot_dir; - l9660_dir grub_dir; - status = l9660_opendirat(&boot_dir, root_dir, "boot"); - printf("STATUS %X\n", status); - status = l9660_opendirat(&grub_dir, &boot_dir, "grub"); - printf("STATUS %X\n", status); - - status = l9660_openat(&g_test_file, &grub_dir, "grub.cfg"); - - if (status != L9660_OK) { - printf("Error opening TEST.TXT;1. Error code: "); - printf("%X\n", status); // Print the error code - printf("\n"); - } else { - char file_buffer[129]; - size_t bytes_read; - uint32_t total_bytes; - - for (;;) { - // Read the next chunk of the file - status = l9660_read(&g_test_file, file_buffer, 128, &bytes_read); - - // Check for a read error - if (status != L9660_OK) { - printf("An error occurred during file read!\n"); - break; - } - - // Check for End-Of-File - if (bytes_read == 0) { - break; // We're done - } - - // Process the data we just read - total_bytes += bytes_read; - file_buffer[bytes_read] = '\0'; // Null-terminate the chunk - printf(file_buffer); // Print the chunk - } - - printf("\n--- EOF ---\n"); - printf("Total bytes read: "); - printf("0x%X\n", total_bytes); - } -} - void kmain(unsigned int magic, unsigned int info) { struct multiboot_info mbi;