fat12 portability?

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
uglyoldbob
Member
Member
Posts: 62
Joined: Tue Feb 13, 2007 10:46 am

fat12 portability?

Post by uglyoldbob »

I looked around for some stuff about FAT12. If it's here I probably didn't use the right search terms.
I was looking around for a strange bug in my FAT12 code the other day and finally found out the problem and solved it, but I have a feeling that it is now dependent on the "endian-ness" of the cpu.
The code regards retrieving entries from the FAT (which are 12 bits each). I originally used a (short *) to retrieve the values, but realized that when the address that it points to is odd is doesn't work because of address alignment with pointers. I changed over to using an (unsigned char*) and using two calls for it, but I am pretty sure that is endian dependent. Is there an easier way to do this and still be portable?
I have an 80386SX 20MHz 2MB RAM.
It is my testbed platform. Only has the 3.5" and 5.25" floppy drives.
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: fat12 portability?

Post by Stevo14 »

uglyoldbob wrote:I looked around for some stuff about FAT12. If it's here I probably didn't use the right search terms.
http://wiki.osdev.org/FAT#FAT_12_2
uglyoldbob wrote: I originally used a (short *) to retrieve the values, but realized that when the address that it points to is odd is doesn't work because of address alignment with pointers.
The official Microsoft specs has something about this. Basically all you need to do is use a different part of the 16 bits that you get from the (short*) depending on weather the address is odd or even. There is no need to fiddle with grabbing bytes separately.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: fat12 portability?

Post by Candy »

Stevo14 wrote:
uglyoldbob wrote:I looked around for some stuff about FAT12. If it's here I probably didn't use the right search terms.
http://wiki.osdev.org/FAT#FAT_12_2
uglyoldbob wrote: I originally used a (short *) to retrieve the values, but realized that when the address that it points to is odd is doesn't work because of address alignment with pointers.
The official Microsoft specs has something about this. Basically all you need to do is use a different part of the 16 bits that you get from the (short*) depending on weather the address is odd or even. There is no need to fiddle with grabbing bytes separately.
If you use the bytes separately, it's portable. If you use it as a short *, it's going to be endian-dependant. Your feeling was backward, reading any value longer than a byte is endian-dependant so the short * is the wrong approach.
Post Reply