Skip to main content
coreydaley.dev

A FAT32 drive doesn't cut a file at exactly 4 GB

Every USB stick that comes formatted as FAT32 has the same limit: no single file can be 4 GiB or larger. The largest possible file is 4,294,967,295 bytes, because FAT32 stores each file’s size in 32 bits.

So when a big archive won’t open and it came off a FAT32 drive, the obvious test is: is it exactly 4,294,967,295 bytes? If so, it was cut off. I was about to write that check for Purrchiver, and then tested it first. It’s the wrong test.

The experiment

A FAT32 disk image is enough; no USB stick needed. On a Mac:

hdiutil create -size 6g -fs "MS-DOS FAT32" -type SPARSE -volname FATTEST fat.sparseimage
hdiutil attach -nobrowse -mountpoint ./mnt fat.sparseimage

(Current macOS prints a deprecation notice suggesting diskutil image; the commands still work. FAT32 can’t store sparse files, so the image grows to about 4.3 GB on your disk during the test.) Then write 4.5 GiB of zeros to it with dd, three times, changing only how much dd writes at once:

dd if=/dev/zero of=mnt/big.bin bs=64m count=72
dd if=/dev/zero of=mnt/big.bin bs=1m count=4608
dd if=/dev/zero of=mnt/big.bin bs=1000000 count=4832

All three stop with File too large, and leave a file behind. But not the same file:

Written in chunks ofFile left on the driveShort of the limit by
64 MiB4,227,858,432 bytes67,108,863 bytes
1 MiB4,293,918,720 bytes1,048,575 bytes
1,000,000 bytes4,294,000,000 bytes967,295 bytes

None of them is 4,294,967,295. (When you’re done, hdiutil detach mnt and delete the image.)

Why

macOS’s FAT32 driver doesn’t fill the file up to the last byte and then stop. When a write would take the file past the limit, it refuses the whole write. So the file ends after the last write that fit completely, and how far below 4 GiB that is depends on how big each write was: up to one write’s worth short.

Most programs write in chunks of somewhere between a few kilobytes and a few megabytes, so a file cut off this way usually ends within a few megabytes of the limit. One writing in 64 MiB chunks, like the first test, stops 64 MiB short.

Copying is different

cp, and the Finder, behave differently: they know the file’s size before they start, and refuse up front.

$ cp big.bin mnt/copy.bin
cp: mnt/copy.bin: fcopyfile failed: File too large

cp leaves a 0-byte copy.bin behind, which is worth knowing if you find an empty file on a USB stick later. The Finder says the item “can’t be copied because it’s too large for the volume’s format” and copies nothing.

So a big file cut off on FAT32 usually came from something that writes as it goes: a download saved straight to the stick, a recording, a backup tool, or an app exporting a large file.

What that means for spotting it

If you’re checking whether a file was cut off by a FAT32 drive, look for a size a little below 4,294,967,295 bytes (within a few megabytes, or up to 64 MiB), together with an archive that ends early, rather than an exact match. An exact 4,294,967,295 is possible but not what you’ll usually see.

The fix is the same either way: reformat the drive as exFAT, or split the file into pieces under 4 GB. Both are covered in “Too large for the volume’s format”, and a file that was already cut off may still give up most of what’s inside: see Repair a damaged or corrupt ZIP on a Mac.