computertrick wrote:
I am currently doing
DataStart = HIDDEN_BLOCKS + RESERVED_BLOCKS + TOTAL_FATS * BLOCKS_PER_FAT * BLOCK_SIZE
this should be instead: HIDDEN_BLOCKS + RESERVED_BLOCKS + TOTAL_FATS*BLOCKS_PER_FAT
without the *BLOCK_SIZE because you are looking for a sector number, not a number of bytes
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?
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:
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)
egos wrote:
I posted correct BPB+ structure for FAT12/16 here. Compare it to yours.
his BPB looks correct, don't think there is a problem there