relan / exfat

Free exFAT file system implementation
GNU General Public License v2.0
789 stars 179 forks source link

exfatfsck doesn't report error on shrunk device #104

Open dxdxdt opened 5 years ago

dxdxdt commented 5 years ago

I was curious as to what happens if you accidentally shrink file systems. So far, I've found that the developers of btrfs, exfat, and vfat didn't think this through.

truncate -s 1G a
mkfs.exfat a
fsck.exfat a

truncate -s 1073733632 a
fsck.exfat a

output

exfatfsck 1.2.8
WARN: file system in sectors is larger than device: 2097152 * 512 > 1073733632.
Checking file system on a.
File system version           1.0
Sector size                 512 bytes
Cluster size                 32 KB
Volume size                   1 GB
Used space                  288 KB
Available space               1 GB
Totally 0 directories and 0 files.
File system checking finished. No errors found.

(exit code 0)

I assume the "WARN: " line is from mount.c:293. Shouldn't it be an error?

dxdxdt commented 5 years ago

Note that fsck.extN/xfs/cramfs reports this case as error.

relan commented 5 years ago

It used to be an error, but several users with buggy cameras were unhappy with that: https://github.com/relan/exfat/commit/fcba4d92e7a78feb263f8ee0374ec5277341cdd3

dxdxdt commented 5 years ago

It used to be an error, but several users with buggy cameras were unhappy with that: fcba4d9

yes, I saw the comment. But fsck'ing is a different thing? Using shrunk fs is dangerous. It's obvious that using the fs will fail at some point. Isn't that why people run fsck? If main users of this software use exfat for broken cameras and run fsck for other problems than this, fair enough. I admit that the case is pretty rare but can happen.

Your project, your decision.

relan commented 5 years ago

fsck should probably mark clusters beyond the end as bad. This way, the warning can be turned into an error again.