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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

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

Post 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 ?
Last edited by stdcall on Tue Oct 03, 2017 3:12 pm, edited 1 time in total.
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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).
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

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

Post 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);
    }
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

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

Post by Octocontrabass »

The wiki code reads a single 16-bit integer. The code on the page you linked reads two 8-bit integers.
stdcall
Member
Member
Posts: 78
Joined: Thu Mar 14, 2013 1:30 am

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

Post by stdcall »

Facepalm.
Stop the Internet ! can we delete this thread ??? :)
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS
Post Reply