OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:16 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [Solved] FAT12: bug in the wiki or in my head ?
PostPosted: Mon Oct 02, 2017 12:19 pm 
Offline
Member
Member

Joined: Thu Mar 14, 2013 1:30 am
Posts: 78
Hi.
trying to understand how to read the clusters from the FAT table.
According to the wiki:
Code:

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 ?

_________________
“Meaningless! Meaningless!”
says the Teacher.
“Utterly meaningless!
Everything is meaningless.” - Ecclesiastes 1, 2

Educational Purpose Operating System - EPOS


Last edited by stdcall on Tue Oct 03, 2017 3:12 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: FAT12: bug in the wiki or in my head ?
PostPosted: Mon Oct 02, 2017 12:30 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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).


Top
 Profile  
 
 Post subject: Re: FAT12: bug in the wiki or in my head ?
PostPosted: Mon Oct 02, 2017 12:40 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: FAT12: bug in the wiki or in my head ?
PostPosted: Mon Oct 02, 2017 12:43 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
The wiki code reads a single 16-bit integer. The code on the page you linked reads two 8-bit integers.


Top
 Profile  
 
 Post subject: Re: FAT12: bug in the wiki or in my head ?
PostPosted: Mon Oct 02, 2017 12:46 pm 
Offline
Member
Member

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 60 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group