mirror of
https://git.planet-casio.com/Lephenixnoir/gint.git
synced 2025-05-18 15:29:16 +02:00
fygue: fix FAT12 cluster handling + fix file seek() handling
This commit is contained in:
parent
ec6f7cedc5
commit
817e654e74
3 changed files with 25 additions and 20 deletions
|
@ -34,7 +34,6 @@ static int _fygue_fat16_cluster_get_next(
|
|||
}
|
||||
|
||||
/* _fygue_fat12_cluster_get_next(): FAT12 cluster handling */
|
||||
// TODO: assume fixed sector size to 512
|
||||
// TODO: better calculus
|
||||
static int _fygue_fat12_cluster_get_next(
|
||||
struct fygue_fat *fat,
|
||||
|
@ -51,39 +50,38 @@ static int _fygue_fat12_cluster_get_next(
|
|||
|
||||
fat_index0 = *cluster + (*cluster / 2);
|
||||
fat_index1 = fat_index0 + 1;
|
||||
fat_sector0 = fat->FAT0SectorID + (fat_index0 / fat->SectorSize);
|
||||
fat_sector1 = fat->FAT0SectorID + (fat_index1 / fat->SectorSize);
|
||||
fat_sector0 = fat->FAT0SectorID + (fat_index0 / 512);
|
||||
fat_sector1 = fat->FAT0SectorID + (fat_index1 / 512);
|
||||
|
||||
if (fat_sector0 == fat_sector1) {
|
||||
if (fygue_fat_sector_get_addr(fat, &fat_data0, fat_sector0) != 0)
|
||||
return -1;
|
||||
fat_data1 = fat_data0;
|
||||
fat_offset0 = fat_index0 - (fat_sector0 * fat->SectorSize);
|
||||
fat_offset0 = fat_index0 - ((fat_index0 / 512) * 512);
|
||||
fat_offset1 = fat_offset0 + 1;
|
||||
} else {
|
||||
if (fygue_fat_sector_get_addr(fat, &fat_data0, fat_sector0) != 0)
|
||||
return -1;
|
||||
if (fygue_fat_sector_get_addr(fat, &fat_data1, fat_sector1) != 0)
|
||||
return -1;
|
||||
fat_offset0 = fat_index0 - (fat_sector0 * fat->SectorSize);
|
||||
fat_offset1 = fat_index1 - (fat_sector1 * fat->SectorSize);
|
||||
fat_offset0 = fat_index0 - ((fat_index0 / 512) * 512);
|
||||
fat_offset1 = fat_index1 - ((fat_index1 / 512) * 512);
|
||||
}
|
||||
|
||||
if (*cluster & 1) {
|
||||
*cluster = (
|
||||
((((uint8_t*)fat_data0)[fat_offset0] & 0xf0) >> 4) |
|
||||
((((uint8_t*)fat_data1)[fat_offset1] & 0xff) << 4)
|
||||
(((((uint8_t*)fat_data0)[fat_offset0] & 0xf0) >> 4) << 0) |
|
||||
(((((uint8_t*)fat_data1)[fat_offset1] & 0xff) >> 0) << 4)
|
||||
);
|
||||
} else {
|
||||
*cluster = (
|
||||
((((uint8_t*)fat_data0)[fat_offset0] & 0xff) >> 0) |
|
||||
((((uint8_t*)fat_data1)[fat_offset1] & 0xf0) << 8)
|
||||
(((((uint8_t*)fat_data0)[fat_offset0] & 0xff) >> 0) << 0) |
|
||||
(((((uint8_t*)fat_data1)[fat_offset1] & 0x0f) >> 0) << 8)
|
||||
);
|
||||
}
|
||||
|
||||
if (*cluster == 0x0fff)
|
||||
*cluster = 0xffff;
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//---
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
#include <string.h>
|
||||
#include "fat.h"
|
||||
|
||||
uintptr_t debug_read_addr = 0;
|
||||
size_t debug_read_size = 0;
|
||||
int debug_read_off = 0;
|
||||
|
||||
/* fygue_fat_file_read(): read primitive */
|
||||
int fygue_fat_file_read(
|
||||
struct fygue_fat *fat,
|
||||
|
@ -30,6 +34,9 @@ int fygue_fat_file_read(
|
|||
chunk_data_available -= chunk_data_offset;
|
||||
if (read + chunk_data_available > size)
|
||||
{
|
||||
debug_read_addr = chunk_data_addr;
|
||||
debug_read_size = size - read;
|
||||
debug_read_off = chunk_data_offset;
|
||||
chunk_data_offset += size - read;
|
||||
memcpy(buffer, (void*)chunk_data_addr, size - read);
|
||||
read += size - read;
|
||||
|
|
|
@ -7,20 +7,20 @@ int fygue_fat_file_seek(
|
|||
struct fygue_fat_file *file,
|
||||
off_t offset
|
||||
) {
|
||||
off_t offset_test;
|
||||
off_t offset_current;
|
||||
|
||||
if (fat == NULL || file == NULL) {
|
||||
errno = EIO;
|
||||
if (fat == NULL || file == NULL)
|
||||
return -1;
|
||||
}
|
||||
offset_test = 0;
|
||||
offset_current = 0;
|
||||
file->chunk_rd_index = 0;
|
||||
file->chunk_rd_offset = 0;
|
||||
for (int i = 0; i < file->chunk_count; i++)
|
||||
{
|
||||
offset_test += file->chunk[i].size;
|
||||
if (offset_test > offset) {
|
||||
file->chunk_rd_offset = offset - offset_test;
|
||||
offset_current += file->chunk[i].size;
|
||||
if (offset_current > offset) {
|
||||
file->chunk_rd_offset = (
|
||||
file->chunk[i].size - (offset_current - offset)
|
||||
);
|
||||
file->cursor = offset;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue