add lib9660 and test_iso9660 function
This commit is contained in:
+95
-3
@@ -14,6 +14,7 @@
|
||||
#include "../include/kheap.h"
|
||||
#include "../include/exec_from_file.h"
|
||||
#include "../include/atapi.h"
|
||||
#include "../include/lib9660.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -24,6 +25,99 @@ void apply_pic_masks()
|
||||
outb(0xa1,0xff);
|
||||
}
|
||||
|
||||
static l9660_fs g_iso_fs;
|
||||
static l9660_dir g_root_dir;
|
||||
static l9660_file g_test_file;
|
||||
|
||||
bool read_sector_callback(l9660_fs *fs, void *buf, uint32_t sector) {
|
||||
// The 'fs' parameter is not needed for our simple case, so we can ignore it.
|
||||
(void)fs;
|
||||
|
||||
// Call your existing CD-ROM read function to read 1 sector.
|
||||
// We assume the CD-ROM is the secondary master (0x170).
|
||||
int result = read_cdrom(0x170, false, sector, 1, (uint16_t*)buf);
|
||||
|
||||
// lib9660 expects 'true' for success and 'false' for failure.
|
||||
// Your read_cdrom returns 0 for success.
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
void test_iso9660()
|
||||
{
|
||||
l9660_status status = l9660_openfs(&g_iso_fs, read_sector_callback);
|
||||
|
||||
if (status != L9660_OK) {
|
||||
printf("Error opening ISO9660 filesystem!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Open the root directory
|
||||
status = l9660_fs_open_root(&g_root_dir, &g_iso_fs);
|
||||
if (status != L9660_OK) {
|
||||
printf("Error opening root directory!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Files in root directory:\n");
|
||||
for (;;) {
|
||||
l9660_dirent *dent;
|
||||
status = l9660_readdir(&g_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(&g_root_dir, &g_iso_fs);
|
||||
|
||||
// Note: ISO9660 filenames are often uppercase.
|
||||
status = l9660_openat(&g_test_file, &g_root_dir, "test.txt;1");
|
||||
|
||||
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;
|
||||
@@ -103,10 +197,8 @@ void kmain(unsigned int magic, unsigned int info)
|
||||
printf("huy1 points to: 0x%X huy2 points to:0x%X\n", huy, huy2);
|
||||
printf("huy1: %s\nhuy2: %s", huy, huy2);
|
||||
|
||||
uint8_t buffer[2048];
|
||||
test_iso9660();
|
||||
|
||||
read_cdrom(0x170, false, 1230, 1, (uint16_t*)buffer);
|
||||
printf("buffer:\n %s\n", buffer);
|
||||
//exec_from_file("/ebalo/main", "/ebalo/");
|
||||
|
||||
while(1)
|
||||
|
||||
Reference in New Issue
Block a user