Bug 15521

Summary: findfs cannot find fat32 filesystems by UUID in certain configurations
Product: Busybox Reporter: VIAVI_AB <andrea.biardi>
Component: Standard ComplianceAssignee: unassigned
Status: NEW ---    
Severity: major CC: busybox-cvs
Priority: P5    
Version: 1.35.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:
Attachments: patch

Description VIAVI_AB 2023-04-07 18:53:02 UTC
Created attachment 9576 [details]
patch

(vanilla busybox 1.35 sources)

findfs relies on the assumption that if cluster_count is within the limits of a FAT16 filesystem, the filesystem *must* be FAT16 (util-linux/volume_id/fat.c, volume_id_probe_vfat).

This fails for me in two situations:
- On "standard" disks, with a fat32 filesystem in a relatively small partition (say, 10M).
- On disks with 4KB logical sectors, even for larger filesystems (in my case, a 512M EFI ESP partition formatted with busybox mkdosfs); this is because on this kind of device you don't need as many clusters (the sector being 8 times larger than usual).

This is a simple script that reproduces this behavior (all busybox binaries):

#! /bin/sh
for size in 10M 100M 5G; do
  echo
  echo "testing with size=$size"
  sfdisk --quiet --wipe=always --wipe-partitions=always /dev/sda << EOF
label: dos
1: type=0b, size=$size
EOF
  mkdosfs /dev/sda1 # unlike util-linux, this always makes a fat32 filesystem
  uuid=$(lsblk -nr -o UUID /dev/sda1)
  echo "uuid is $uuid"
  dev=$(findfs UUID=$uuid)
  echo "dev is $dev" # fals in the 10M case
done

I'm not an expert in the various versions of BPB/EBPB of FAT, but I'm assuming that if there is a clear FAT32 signature it should be honored regardless of the value of cluster_count.

Attached is a trivial patch for consideration.