vfs: put test_iso9660 into vfs.c

This commit is contained in:
2025-08-29 17:08:06 +03:00
parent 7c43956ebe
commit 9e21167bd3
3 changed files with 74 additions and 72 deletions
+72
View File
@@ -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);
}
}
-72
View File
@@ -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;