Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Wrong root sectors count determined for FAT12 and FAT16? #2

@FrankHB

Description

@FrankHB

From Microsoft FAT Specification Section 3.5:

  1. First, determine the count of sectors occupied by the root directory:
RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec

Note that on a FAT32 volume, the BPB_RootEntCnt value is always 0. Therefore, on a
FAT32 volume, RootDirSectors is always 0.

In source/partition.c, line 250:

    partition->dataStart = partition->rootDirStart +
        (( u8array_to_u16(sectorBuffer, BPB_rootEntries) * DIR_ENTRY_DATA_SIZE) / partition->bytesPerSector);

It seems that the correct code would be:

    partition->dataStart = partition->rootDirStart +
        (( u8array_to_u16(sectorBuffer, BPB_rootEntries) * DIR_ENTRY_DATA_SIZE + (partition->bytesPerSector - 1)) / partition->bytesPerSector);

Not tested yet, not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions