Page 1 of 1

FAT32 Structure

Posted: Sun May 08, 2005 11:00 pm
by prajwal
Is it possible to define a C structure which contains all fields of
a FAT32 Structure and use it directly to read & write the first
sector of the BootSector?

When I tried it, the memory allocated to structure fields were adjusted
by the compiler. What i mean is:-

struct x
{

char a[3];
char b[8];
unsigned short c;
};

here, after 'b' 1 byte of extra memory is allocated so that
'c' starts at 12th byte offset (assuming 0 based mem index) rather than
3 + 8 = 11byte offset.

Why is this? What's the solution?

Re: FAT32 Structure

Posted: Sun May 08, 2005 11:00 pm
by [AlAdDiN]
are you sure ?
did you tried to do a dump ?

if so, I think the extra byte is after a not after b, cause char[3] is not 2^
so the compiler adjust it to char[4]=2^32

if you give the real structure, and what are you using it for, it will help us to give a solution ..

anyway in such cases, you have to store a flat data and uses "masks' to extract your information : your structur becomes

Code: Select all

define x char[12] 

x my_data;
char a[3]; 
char b[8]; 
unsigned short c; 


do_something_with_my_data() {...}

a = my_data & 0xFFF0000000; 
b = (my_data & 0x000FFFFFFF0) << 3;
c = my_data[11]; 


Re: FAT32 Structure

Posted: Sun May 08, 2005 11:00 pm
by rexlunae
srinivasa_prajwal wrote:Is it possible to define a C structure which contains all fields of
a FAT32 Structure and use it directly to read & write the first
sector of the BootSector?

When I tried it, the memory allocated to structure fields were adjusted
by the compiler.
Although there is no standard for it that I am aware of, gcc and perhaps other compilers have a way of specifying that structures should not be padded. You will have to look at the documentation for your compiler, because these features are not standard. Which compiler are you using?