mirror of
https://github.com/RhapsodiOS/RhapsodiOS.git
synced 2026-11-03 22:01:40 -07:00
[GH-ISSUE #56] msdosfs: newfs_msdos fails with EINVAL on 1024-byte-sector labelled disks and sizes the volume from the whole device #50
Labels
No labels
bug
documentation
enhancement
enhancement
good first issue
help wanted
help wanted
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github-starred/RhapsodiOS#50
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @raynorpat on GitHub (Oct 15, 2026).
Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/56
Symptom
newfs_msdos(src/msdosfs-1/msdos_newfs) fails on partitionaof a disk whose NeXT label uses 1024-byte label sectors, the layoutvm/ffsbench.py build_scratchand the installed root disk use. It prints a layout and exits 1 with EINVAL, leaving a half-written volume, andmount_msdosthen mounts that volume without complaint:The same failure happens with an explicit size,
newfs_msdos -s 524288 /dev/rhd1a, which is well inside the partition. On partitionaof a disk with a 512-byte-sector label (thevm/ext2_guest.py wrap_volumelayout),newfs_msdos -s 524288 /dev/rhd2aworks.Observations
bsec=1048768is the whole 512 MB device in 512-byte units, label area included. The partition is smaller.getdiskinfo()(newfs_msdos.c~732) sizes the filesystem fromDKIOCBLKSIZE/DKIOCNUMBLKS, which looks like it reports the whole device rather than the partition, so the layout can run past the partition's end.bps=512comes fromDKIOCBLKSIZE, while the disk's label uses 1024-byte sectors. Since #47's fix (4f3c58658), raw transfers that aren't a whole number of the device's sectors fail with EINVAL. The explicit-s 524288case, which can't run past the end, still fails, which points at this.mount_msdosaccepts the half-made volume, with no check that the boot sector and FATs are complete.Reproduce
i386 QEMU guest (v2 image), kernel with msdosfs (the issue-43 kernel was used), a scratch disk made by
vm/ffsbench.py build_scratchas hd1, thennewfs_msdos /dev/rhd1a. Logs:vm/work/fsrepro/res-mh.log,res-m2.log.Where to look
newfs_msdos.cgetdiskinfo(): take the size and sector size from the partition (the NeXT disk label for theapartition) rather than fromDKIOCNUMBLKS/DKIOCBLKSIZEalone, or check thatDKIOCNUMBLKSon/dev/rhdNareally is the partition size on this kernel.mount_msdos/msdosfs_mountfs: reject a volume whose BPB doesn't fit the partition.Found during the stress suite's filesystem run (branch
stress-phase3). Related: #47, #54, #55.@raynorpat commented on GitHub (Oct 16, 2026):
Fixed by
84cd4eed3(msdosfs: size newfs_msdos volumes from the labelled partition and write in its sector size), merged into ffs-perf in56b7c5a31.Root cause (probe on the guest): both guesses in the issue were real.
-s 524288failed too.The fix takes the sector size and size from DKIOCGPARTINFO first (1024 bps there, which is a valid FAT value), keeps the boot-sector signature and FSInfo fields at their fixed offsets inside the first 512 bytes, and reports a failed write's offset and length.
Verified on a guest: newfs with and without
-son both the 1024- and 512-byte-label disks, fsck_msdos clean; on the 512-label disk a full mount / write / remount / read-back cycle, fsck clean;-Cimages of 1440k, 32m and 512m and a plain file all fine, and a-C 32mimage is byte-identical to the old binary's.Mounting the new volume on a 1024-byte-label partition still fails. That's a separate kernel msdosfs block-unit bug, along with the missing BPB-vs-partition size check on mount, now #58.