Skip to content

fix: accept blocksize=4096 in fat32.Read for 4k native block devices#320

Merged
deitch merged 1 commit intodiskfs:masterfrom
frezbo:fix/4k-detection-blockdevice
Dec 23, 2025
Merged

fix: accept blocksize=4096 in fat32.Read for 4k native block devices#320
deitch merged 1 commit intodiskfs:masterfrom
frezbo:fix/4k-detection-blockdevice

Conversation

@frezbo
Copy link
Copy Markdown
Contributor

@frezbo frezbo commented Dec 23, 2025

When go-diskfs opens a 4k native block device, it detects the logical block size as 4096 from the OS and passes this to fat32.Read(). However, the validation was rejecting any blocksize other than 0 or 512, causing 'unknown filesystem' errors.

This is a follow-up to PR #316 which added support for reading FAT32 filesystems with bytesPerSector=4096 from the BPB, but didn't update the blocksize validation. The blocksize parameter is only used for validation; the actual bytesPerSector is always read from the BPB.

Fixes reading VFAT filesystems on 4k native disks when opened as block devices (e.g., /dev/vda1).

Also fix the write code for 4k disks.

When go-diskfs opens a 4k native block device, it detects the logical
block size as 4096 from the OS and passes this to fat32.Read(). However,
the validation was rejecting any blocksize other than 0 or 512, causing
'unknown filesystem' errors.

This is a follow-up to PR diskfs#316 which added support for reading FAT32
filesystems with bytesPerSector=4096 from the BPB, but didn't update
the blocksize validation. The blocksize parameter is only used for
validation; the actual bytesPerSector is always read from the BPB.

Fixes reading VFAT filesystems on 4k native disks when opened as block
devices (e.g., /dev/vda1).

Also fix the write code for 4k disks.

Signed-off-by: Noel Georgi <git@frezbo.dev>
@frezbo
Copy link
Copy Markdown
Contributor Author

frezbo commented Dec 23, 2025

To see the 4k failure we need an actual loop device or block device.

@deitch
Copy link
Copy Markdown
Collaborator

deitch commented Dec 23, 2025

Looks good, thank you.

@deitch deitch merged commit fc569a0 into diskfs:master Dec 23, 2025
20 checks passed
@frezbo frezbo deleted the fix/4k-detection-blockdevice branch December 23, 2025 13:40
jfroy added a commit to jfroy/go-diskfs that referenced this pull request Apr 21, 2026
This patch allows creating FAT32 filesystems with 4K block size. This is
intended to create UEFI System Partitions (ESPs) on NVME namespaces with
a 4Kn format.

This is a follow-up to PR diskfs#320 which added support for reading FAT32
filesystems with 4K block size.

Signed-off-by: Jean-Francois Roy <jf@devklog.net>
Assisted-by: Claude:claude-opus-4-7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants