How do you read a specific cluster's data from the FAT. The problem is that each cluster's data is 12-bits (1.5 bytes) I've heard you can't have an array of that i.e The bellow won't work:-
typedef struct
{
int data : 12;
}fatdata_t
fatdata_t TheFat[1000];
readfloppy(whateversector,TheFat);
kprintf("%d\n",TheFat[clusterno]);
So what can I do to read the data?
Thanks in advanced
Pete
FAT12
-
Tim
Re:FAT12
This:
(m_fat is a uint8_t* pointing to a copy of the entire FAT read from disk)
Code: Select all
uint32_t Fat::GetNextCluster(uint32_t cluster)
{
uint32_t FATOffset;
uint16_t w;
uint8_t* b;
if (cluster >=
(uint32_t) (m_sectors / m_bpb.sectors_per_cluster))
{
wprintf(L"Cluster 0x%x (%d) beyond total clusters 0x%x (%d)\n",
cluster, cluster,
m_sectors / m_bpb.sectors_per_cluster,
m_sectors / m_bpb.sectors_per_cluster);
assert(false);
}
switch (m_fat_bits)
{
case 12:
FATOffset = cluster + cluster / 2;
break;
case 16:
FATOffset = cluster * 2;
break;
default:
assert(m_fat_bits == 12 || m_fat_bits == 16);
return (uint32_t) -1;
}
b = m_fat + FATOffset;
/* xxx -- won't work for FAT32 */
w = *(uint16_t*) b;
if (m_fat_bits == 12)
{
if (cluster & 1) /* cluster is odd */
w >>= 4;
else /* cluster is even */
w &= 0xfff;
if (w >= 0xff0)
w |= 0xf000;
}
return w;
}-
Guest
Re:FAT12
It still won't work the code is at:-
http://xinit.port5.com/fat12.c
http://xinit.port5.com/fat12.h
Please can someone look at what might be the bug. The code works fine for files <513 bytes but when getting the next cluster number it gets 1070 instead of 3 no matter what code I use. This makes me think that it might be an error reading the FAT in, although my Floppy Driver works for everything else.
Thanks in advance
Pete
http://xinit.port5.com/fat12.c
http://xinit.port5.com/fat12.h
Please can someone look at what might be the bug. The code works fine for files <513 bytes but when getting the next cluster number it gets 1070 instead of 3 no matter what code I use. This makes me think that it might be an error reading the FAT in, although my Floppy Driver works for everything else.
Thanks in advance
Pete