fat problems

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
Poseidon

fat problems

Post by Poseidon »

I've some problems with reading the fat filesystem... I'm trying to get the first sector of the rootdirectory, using this formula (from the microsoft specification):

Code: Select all

int start = header.fats_amount * header.sec_per_fat + header.res_sectors;
but this outputs a number which is wrong (can't remember what ;)). The value should be 0x13 (looked it up with a hex-editor).

This is what the header & values it reads look like:

Code: Select all

typedef struct {
   uchar NameVer[8]; // mkdosfs
   ushort bytes_per_sector; // 512
   uchar sec_per_cluster; // 1
   ushort res_sectors; // 512
   uchar fats_amount; // 224
   ushort rootdir_entries; // 2880
   ushort sec_in_vol; // 2544
   uchar media_desc; //0x0
   ushort sec_per_fat; // 512
   ushort sec_per_track; // 0
   ushort heads_no; // 0
   uint hidden_sectors; // 0
} fat12_header;
Anyone ideas?
Thanks.
proxy

Re:fat problems

Post by proxy »

looks to me that your struct may end up with padding which would make your fields not line up correctly.

use pragmas or attributes (depending on compiler and preference) to disable the padding of this structure and i think you'll be fine.

proxy
Poseidon

Re:fat problems

Post by Poseidon »

you mean adding __attribute__ ((packed)) at the end of the struct? it doesn't make any difference when i at it.. :(


edit: oh wait, it works when i put it at the end of every item in the struct. thanks :)
proxy

Re:fat problems

Post by proxy »

if you are using gcc (which i assume you are)

i personally prefer to use pragmas so you dont have to put it on every struct element.

like this

Code: Select all

#pragma pack (push, 1)
struct my_struct {
   uint16_t member1;
   uint32_t member2
};
#pragma pack(pop)

proxy
Poseidon

Re:fat problems

Post by Poseidon »

didn't know i could do it that way, #pragma looks much cleaner indeed.

thanks
Post Reply