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?
FAT32 Structure
Re: FAT32 Structure
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
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];
-----------------------
There are 10 types of people in this world... those that understand binary, and those that don't.
There are 10 types of people in this world... those that understand binary, and those that don't.
-
- Member
- Posts: 134
- Joined: Sun Oct 24, 2004 11:00 pm
- Location: North Dakota, where the buffalo roam
Re: FAT32 Structure
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?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.
Last edited by rexlunae on Sun May 08, 2005 11:00 pm, edited 1 time in total.