Skip to content

Commit 1b08161

Browse files
committed
Ready for review and testing?
CFG_UF2_NUM_BLOCKS is currently set in uf2cfg.h. Likely will hard-code file system to a large value. Maximum value for CFG_UF2_NUM_BLOCKS: 0x101dd If remove one `STATIC_ASSERT()`, at the risk of compatibility issues with FAT implementations that have off-by-one errors (of which there are many), the maximum value could be raised to 0x101fd. The maximum value is based on the following values: * BPB_SECTOR_SIZE (fixed at 512 for FAT16) * BPB_RESERVED_SECTORS (fixed at 1 for FAT16) * BPB_NUMBER_OF_FATS (fixed at 2 for FAT16) * BPB_ROOT_DIR_ENTRIES (fixed at 64 by GhostFAT) * BPB_SECTORS_PER_CLUSTER (fixed at 1 by GhostFAT) * BPB_SECTORS_PER_FAT (calculated from CFG_UF2_NUM_BLOCKS) If any of the above change, then the maximum value will also change.
1 parent 041defe commit 1b08161

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/usb/uf2/ghostfat.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ struct TextFile {
6868
#define BPB_RESERVED_SECTORS ( 1)
6969
#define BPB_NUMBER_OF_FATS ( 2)
7070
#define BPB_ROOT_DIR_ENTRIES ( 64)
71-
// #define BPB_TOTAL_SECTORS CFG_UF2_NUM_BLOCKS
72-
#define BPB_TOTAL_SECTORS (0x101dd) // 0x101dd is absolute max at current code commit
71+
#define BPB_TOTAL_SECTORS CFG_UF2_NUM_BLOCKS // 0x101dd is absolute max at current code commit
7372
#define BPB_MEDIA_DESCRIPTOR_BYTE (0xF8)
7473
#define FAT_ENTRY_SIZE (2)
7574
#define FAT_ENTRIES_PER_SECTOR (BPB_SECTOR_SIZE / FAT_ENTRY_SIZE)
@@ -163,11 +162,12 @@ static FAT_BootBlock const BootBlock = {
163162
.ReservedSectors = BPB_RESERVED_SECTORS,
164163
.FATCopies = BPB_NUMBER_OF_FATS,
165164
.RootDirectoryEntries = BPB_ROOT_DIR_ENTRIES,
166-
.TotalSectors16 = BPB_TOTAL_SECTORS,
165+
.TotalSectors16 = (BPB_TOTAL_SECTORS > 0xFFFF) ? 0 : BPB_TOTAL_SECTORS,
167166
.MediaDescriptor = BPB_MEDIA_DESCRIPTOR_BYTE,
168167
.SectorsPerFAT = BPB_SECTORS_PER_FAT,
169168
.SectorsPerTrack = 1,
170169
.Heads = 1,
170+
.TotalSectors32 = (BPB_TOTAL_SECTORS > 0xFFFF) ? BPB_TOTAL_SECTORS : 0,
171171
.PhysicalDriveNum = 0x80, // to match MediaDescriptor of 0xF8
172172
.ExtendedBootSig = 0x29,
173173
.VolumeSerialNumber = 0x00420042,

0 commit comments

Comments
 (0)