72 lines
1.8 KiB
C
72 lines
1.8 KiB
C
#include "../include/vfs.h"
|
|
#include "../include/stdio.h"
|
|
#include "../include/string.h"
|
|
|
|
l9660_fs global_fs;
|
|
|
|
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 mount_fs()
|
|
{
|
|
l9660_status status = l9660_openfs(&global_fs, read_sector_callback);
|
|
|
|
if (status != L9660_OK) {
|
|
printf("Error opening ISO9660 filesystem!\n");
|
|
return;
|
|
}
|
|
printf("FS mounted\n");
|
|
}
|
|
|
|
void list_files(l9660_dir *dir)
|
|
{
|
|
debug_log("----------CONTENTS----------");
|
|
l9660_status status;
|
|
for (;;) {
|
|
l9660_dirent *dent;
|
|
status = l9660_readdir(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");
|
|
}
|
|
}
|
|
|
|
|
|
size_t vfs_read_file(l9660_file *file, uint8_t* buffer)
|
|
{
|
|
size_t total_read = 0;
|
|
for(;;) {
|
|
char buf[128];
|
|
size_t read;
|
|
l9660_read(file, buf, 128, &read);
|
|
|
|
//check for EOF
|
|
if (read == 0)
|
|
break;
|
|
|
|
memcpy(buffer, buf, 128);
|
|
buffer += 128;
|
|
total_read += read;
|
|
}
|
|
|
|
//reset the current position to the original position
|
|
buffer -= total_read;
|
|
return total_read;
|
|
} |