FAT16 cluster problem?
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
FAT16 cluster problem?
Hi I have implemented FAT16 into my operating system so far all good I can calculate the root directory but when it comes to finding the physical address of the data I have a problem.
Here is more information
Reserved Blocks: 1
Total fats: 1
Total root entries: 512
Blocks per FAT: 1
Blocks per allocation unit: 128
Block size: 512
and the cluster number of the file I am trying to read is 6.
Could anyone help me with the math to calculate this I would appreciate it.
Many thanks
Here is more information
Reserved Blocks: 1
Total fats: 1
Total root entries: 512
Blocks per FAT: 1
Blocks per allocation unit: 128
Block size: 512
and the cluster number of the file I am trying to read is 6.
Could anyone help me with the math to calculate this I would appreciate it.
Many thanks
1100110100010011
Re: FAT16 cluster problem?
StartFileSector = DataStart + (SrartFileCluster-2)*SectorsPerCluster
DataStart = HiddenSectors + ReservedSectors + FATs*FATSize + RootSize
DataStart = HiddenSectors + ReservedSectors + FATs*FATSize + RootSize
If you have seen bad English in my words, tell me what's wrong, please.
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
Re: FAT16 cluster problem?
Hi thanks for your reply using what you have given me I get pretty close to the data about 16000 bytes off. I think I am missing something here is my assembly in the boot sector for listing FAT informationegos wrote:StartFileSector = DataStart + (SrartFileCluster-2)*SectorsPerCluster
DataStart = HiddenSectors + ReservedSectors + FATs*FATSize + RootSize
Code: Select all
org 0 ; we start everything at zero
jmp start
MANU_DESC db 'mkdosfs '
BLOCK_SIZE dw 512
BLOCKS_PER_ALLOCATION_UNIT db 128
RESERVED_BLOCKS dw 1
TOTAL_FATS db 1
TOTAL_ROOT_ENTRIES dw 512
TOTAL_BLOCKS dw 0xffff
MEDIA_DESCRIPTOR db 0xf8
BLOCKS_PER_FAT dw 0x01
BLOCKS_PER_TRACK dw 18
TOTAL_HEADS dw 0x02
HIDDEN_BLOCKS dd 0x00
TOTAL_BLOCKS_2 dd 0x00
DRIVE_NUMBER dw 0x00
EXTENDED_BOOT_SIGNATURE db 0x29
VOLUME_SERIAL_NUMBER dd 0x9d86f18c
VOLUME_LABEL db 'SEAGULL '
FILE_SYSTEM_IDENTIFIER db 'FAT16 '
DataStart = HIDDEN_BLOCKS + RESERVED_BLOCKS + TOTAL_FATS * BLOCKS_PER_FAT * BLOCK_SIZE
I don't know what you mean by root size??
StartFilesector = DataStart + (0x0A -2) * BLOCKS_PER_ALLOCATION_UNIT * BLOCK_SIZE
The root directory is at 0x400 which I assume is where DataStart is meant to be?
using Python3 this is the result I get
Code: Select all
> hex(0x400 + (0x0a-2) * 128 * 512)
'0x80400'
1100110100010011
Re: FAT16 cluster problem?
Don't think, look into the FAT manual.computertrick wrote:I think I am missing something here is my assembly in the boot sector for listing FAT information
It's size of root directory in sectors.I don't know what you mean by root size??
* BLOCK_SIZEWhat am i doing wrong?
If you have seen bad English in my words, tell me what's wrong, please.
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
Re: FAT16 cluster problem?
I'm still having trouble could you please explain it more using the assembly I wrote in the last postegos wrote:Don't think, look into the FAT manual.computertrick wrote:I think I am missing something here is my assembly in the boot sector for listing FAT information
It's size of root directory in sectors.I don't know what you mean by root size??
* BLOCK_SIZEWhat am i doing wrong?
1100110100010011
Re: FAT16 cluster problem?
I posted correct BPB+ structure for FAT12/16 here. Compare it to yours.
If you have seen bad English in my words, tell me what's wrong, please.
Re: FAT16 cluster problem?
this should be instead: HIDDEN_BLOCKS + RESERVED_BLOCKS + TOTAL_FATS*BLOCKS_PER_FATcomputertrick wrote: I am currently doing
DataStart = HIDDEN_BLOCKS + RESERVED_BLOCKS + TOTAL_FATS * BLOCKS_PER_FAT * BLOCK_SIZE
without the *BLOCK_SIZE because you are looking for a sector number, not a number of bytes
no, this is wrong -- what you are calling DataStart here is the location of the root directory, the FAT12/16 FS does not consider this to be part of the data area (FAT32 does count this, as the Root Directory is mapped to a cluster chain as a file) to find the start of the data area, you would need:I don't know what you mean by root size??
StartFilesector = DataStart + (0x0A -2) * BLOCKS_PER_ALLOCATION_UNIT * BLOCK_SIZE
The root directory is at 0x400 which I assume is where DataStart is meant to be?
DataStart + (NumRoots/8)
so to find the location of a cluster on the disk you would need:
LBA = (cluster-2)*BLOCKS_PER_ALLOCATION_UNIT + (NumRoots/8) + (HIDDEN_BLOCKS + RESERVED_BLOCKS + TOTAL_FATS*BLOCKS_PER_FAT)
so using the specific values in your particular example from your OP this would be:
LBA = (6-2)*128 + (512/8) + (0 + 1 + 1*1)
LBA = 4*128 + 64 + 1 + 1
LBA = 512 + 64 + 2
LBA = 578
so your file starts in sector 578
that should give you LBA = sector number of the start of the cluster you are looking for (i don't know why you would want the number of bytes offset, but if you did, you could multiply LBA by BLOCK_SIZE (in this example it would be 578 * 512 = 289KB (259,936 bytes 0x048400)
his BPB looks correct, don't think there is a problem thereegos wrote: I posted correct BPB+ structure for FAT12/16 here. Compare it to yours.
Re: FAT16 cluster problem?
Don't forget about root directory.JAAman wrote:this should be instead: HIDDEN_BLOCKS + RESERVED_BLOCKS + TOTAL_FATS*BLOCKS_PER_FAT
One 512-byte sector holds 512/32=16 file records, not 8.(NumRoots/8)
I don't know where problem is, maybe in the initial jump instruction. Actually I don't see any problems here at all. I posted the exact answer.his BPB looks correct, don't think there is a problem there
If you have seen bad English in my words, tell me what's wrong, please.
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
Re: FAT16 cluster problem?
I want to learn more about FAT16 do you know any good documentation I have been using this partly http://www.tavi.co.uk/phobos/fat.html but I don't find it as useful as I should.
Also can anyone tell me what an allocation unit is? Is that the 32 bytes allocated for each file or I think thats called a directory entry right?
Also can anyone tell me what an allocation unit is? Is that the 32 bytes allocated for each file or I think thats called a directory entry right?
1100110100010011
Re: FAT16 cluster problem?
its almost identical to FAT12, except the size of the cluster number is 16-bits instead of 12-bits (FAT32 is a little different)computertrick wrote:I want to learn more about FAT16 do you know any good documentation I have been using this partly http://www.tavi.co.uk/phobos/fat.html but I don't find it as useful as I should.
best way to find information about it is by reading the actual specification -- no other file/website is a replacement for the actual specification you can also look at the FAT entry in our wiki
the term "allocation unit" refers to the "cluster", and refers to the individual chunks of the disk that may be allocated to a file -- only full clusters can be given to a file, so the cluster size (counted in sectors, must be power-of-two) is important for disk space usage (smaller cluster size means less wasted space at the end of files) -- this is why most FAT12 drives use 1-sector clusters (usually you use the smallest cluster size possible for FAT12/16)Also can anyone tell me what an allocation unit is? Is that the 32 bytes allocated for each file or I think thats called a directory entry right?
doh! your right... don't know what i was thinking... trying to calculate it in my head while writing that -- must have had 256 on my mind for some reasonegos wrote: One 512-byte sector holds 512/32=16 file records, not 8.