FAT12 clusters not correctly calculated
Posted: Fri Sep 09, 2011 4:08 pm
for some reason, my FAT driver is not following cluster chains properly for FAT12 floppies. FAT16 on hard drives works just fine, and according to the wiki here, this code should do it? reading the first cluster given in it's directory entry of any file always returns the correct data, but when i go into the allocation table to get the next cluster it always reads the value as 512 or 6632. wtf?
Code: Select all
uint16 get_clust_val(uint8 part, uint32 cluster) {
uint16 i;
if ((fat[part].bpb.totalsects / fat[part].bpb.sectsperclust) < 4085) { //FAT12
cluster = cluster + (cluster>>1);
disk_read(fat[part].drive, fat[part].fatloc + cluster, (void far *)FARPTR(_CS, &i), 2);
if (cluster&1) i = i >> 4;
else i &= 0x0FFF;
} else { //FAT16
disk_read(fat[part].drive, fat[part].fatloc + (cluster<<1), (void far *)FARPTR(_CS, &i), 2);
}
return(i);
}
uint32 follow_clust_chain(uint16 part, uint32 first, uint32 count) {
uint32 cluster, i;
if (count==0) return(first);
cluster = first;
for (i=0; i<count; i++) {
cluster = (uint32)get_clust_val(part, cluster);
}
return(cluster);
}