Page 1 of 1

[Solved] FAT12: bug in the wiki or in my head ?

Posted: Mon Oct 02, 2017 12:19 pm
by stdcall
Hi.
trying to understand how to read the clusters from the FAT table.
According to the wiki:

Code: Select all

 
unsigned short table_value = *(unsigned short*)&FAT_table[ent_offset];
 
if(active_cluster & 0x0001)
   table_value = table_value >> 4;
else
   table_value = table_value & 0x0FFF;
is enough for getting the value, but it contradicts the description I found here:
http://elm-chan.org/docs/fat_e.html#fat_access


What's the verdict ?

Re: FAT12: bug in the wiki or in my head ?

Posted: Mon Oct 02, 2017 12:30 pm
by Octocontrabass
I don't see any contradiction. Both appear to be different ways of writing the same thing (ignoring the fact that the wiki code is undefined behavior due to unaligned pointer access).

Re: FAT12: bug in the wiki or in my head ?

Posted: Mon Oct 02, 2017 12:40 pm
by stdcall
Octocontrabass wrote:I don't see any contradiction. Both appear to be different ways of writing the same thing (ignoring the fact that the wiki code is undefined behavior due to unaligned pointer access).
How can it be the same thing. the wiki only reads one entry from the fat table, and the site code reads two entries.

Code: Select all

Load a value of FAT12 entry:
    ReadSector(SecBuff, ThisFATSecNum);
    if (N & 1) {    /* Odd entry */
        ThisEntryVal = (SecBuff[ThisFATEntOffset] >> 4)
                     | ((uint16)SecBuff[ThisFATEntOffset + 1] << 4);
    } else {        /* Even entry */
        ThisEntryVal = SecBuff[ThisFATEntOffset]
                     | ((uint16)(SecBuff[ThisFATEntOffset + 1] & 0x0F) << 8);
    }

Re: FAT12: bug in the wiki or in my head ?

Posted: Mon Oct 02, 2017 12:43 pm
by Octocontrabass
The wiki code reads a single 16-bit integer. The code on the page you linked reads two 8-bit integers.

Re: FAT12: bug in the wiki or in my head ?

Posted: Mon Oct 02, 2017 12:46 pm
by stdcall
Facepalm.
Stop the Internet ! can we delete this thread ??? :)