Hi everyone,
Ok, I have been on and off playing around with creating my own OS, I am trying to understand how FAT12 works but something doesn't seem right, I am pretty sure I am missing something, but I just want some clarification so that I understand it properly.
The numbers below represent the first 10 bytes of the FAT organized into their 12 bit entries, so 001 is FAT(0), 122 is FAT(1), etc...
001 122 334 455 667 788 99
If I look at a directory entry and get a first cluster number of 2 then I first read the corresponding cluster, this is fine, I understand this but when it comes to getting the next cluster number from the FAT I don't understand something, I will explain that now.
The process to get the next cluster number is as follows:
EntryLocation = (ClusterNumber / 2) + ClusterNumber
Viewing the FAT as an array of bytes I would read a word, the word I would read is in italics in the above numbers
word FatEntry = FAT[EntryLocation]
now I have to adjust this value to get the 12 bits I am after, here is the problem:
If ClusterNumber is even, I am supposed to clear the highest nibble which would leave me with 344, but a ClusterNumber of 2 means I should end up with 334... It seems to me that I should be shifting FatEntry right 4 bits if its even and clear the high 4 bits if its odd which is opposite to what the documentation says...
I hope you can understand this post, I am really confused about this ???
Cheers.
Question about FAT12
Re:Question about FAT12
That's little endian done wrong.GenX wrote: Hi everyone,
Ok, I have been on and off playing around with creating my own OS, I am trying to understand how FAT12 works but something doesn't seem right, I am pretty sure I am missing something, but I just want some clarification so that I understand it properly.
The numbers below represent the first 10 bytes of the FAT organized into their 12 bit entries, so 001 is FAT(0), 122 is FAT(1), etc...
001 122 334 455 667 788 99
If I look at a directory entry and get a first cluster number of 2 then I first read the corresponding cluster, this is fine, I understand this but when it comes to getting the next cluster number from the FAT I don't understand something, I will explain that now.
The process to get the next cluster number is as follows:
EntryLocation = (ClusterNumber / 2) + ClusterNumber
Viewing the FAT as an array of bytes I would read a word, the word I would read is in italics in the above numbers
word FatEntry = FAT[EntryLocation]
now I have to adjust this value to get the 12 bits I am after, here is the problem:
If ClusterNumber is even, I am supposed to clear the highest nibble which would leave me with 344, but a ClusterNumber of 2 means I should end up with 334... It seems to me that I should be shifting FatEntry right 4 bits if its even and clear the high 4 bits if its odd which is opposite to what the documentation says...
I hope you can understand this post, I am really confused about this ???
Cheers.
The bytes are like:
00 11 22 33 44 55 66 77 88 -> 100 221 433 554 766 887
so, if you want the 1st entry, load a 16-bit word from address 0. That gives you (after little endian conversion) 1100. Since it's even, mask out the upper 4 bits and you got it.
For the second, load byte 1 and 2 as word. That gives 2211. Shift it right by 1 nibble to get 221, which is the right one.
Re:Question about FAT12
Don't mind it, most people (including me) mess up little-endian and big-endian stuff regularly.GenX wrote: :-[ Now thats embarassing!!
Thanks a bundle.
On a sidenote, try to use name each nibble, it makes it clearer which bits you want. This is for FAT12:
ab cd ef => dab efc
Re:Question about FAT12
And then there are people who really believe that little-endian is "correct".
Every good solution is obvious once you've found it.
Re:Question about FAT12
Oh yes, most certainly it is. I usually mess up the big endian stuffSolar wrote: And then there are people who really believe that little-endian is "correct".
Re:Question about FAT12
Ahem... *cough* seethedoc *cough*...
Every good solution is obvious once you've found it.
Re:Question about FAT12
I have to say that I can never remember which way round it goes, it's usually a case of
1) Try it the way that seems right
2) Check the result and find out it's wrong
3) Flip it backwards
1) Try it the way that seems right
2) Check the result and find out it's wrong
3) Flip it backwards
Re:Question about FAT12
Phew!! I am not alone. ;D
Thanks everyone.
I think i'll write this down and stick it to my monitor...ab cd ef => dab efc
Thanks everyone.