From 6f8168e7dc0f6fa70c45a307af56f8b24ca79371 Mon Sep 17 00:00:00 2001 From: David Vornholt Date: Fri, 13 Nov 2026 15:03:20 +0100 Subject: [PATCH] fs: Report corrupted exFAT as not clean instead of failing fsck.exfat from exfatprogs exits with 4 when it finds errors it didn't fix, which is always the case with "-n". bd_fs_exfat_check only cleared the error for exit code 1, so checking a corrupted exFAT file system failed with an error instead of returning FALSE. The ext check already handles exit code 4 the same way. Assisted-by: Claude Code (Claude Opus 5.5) --- src/plugins/fs/exfat.c | 4 ++-- tests/fs_tests/exfat_test.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/plugins/fs/exfat.c b/src/plugins/fs/exfat.c index 3557bff2..a2ada39c 100644 --- a/src/plugins/fs/exfat.c +++ b/src/plugins/fs/exfat.c @@ -212,8 +212,8 @@ gboolean bd_fs_exfat_check (const gchar *device, const BDExtraArg **extra, GErro return FALSE; ret = bd_utils_exec_and_report_status_error (args, extra, &status, error); - if (!ret && (status == 1)) { - /* no error should be reported for exit code 1 */ + if (!ret && (status == 1 || status == 4)) { + /* no error should be reported for exit code 1 and exit code 4 - File system errors left uncorrected */ g_clear_error (error); } return ret; diff --git a/tests/fs_tests/exfat_test.py b/tests/fs_tests/exfat_test.py index 7183577c..3e29d9aa 100644 --- a/tests/fs_tests/exfat_test.py +++ b/tests/fs_tests/exfat_test.py @@ -161,6 +161,27 @@ def test_exfat_check(self): succ = BlockDev.fs_exfat_check(self.loop_devs[0]) self.assertTrue(succ) + def test_exfat_check_corrupted(self): + """Verify that checking a corrupted exfat file system reports it as not clean""" + + succ = BlockDev.fs_exfat_mkfs(self.loop_devs[0], self._mkfs_options) + self.assertTrue(succ) + + # zero the checksum sector of the main boot region + with open(self.loop_devs[0], "r+b") as dev: + sector_size = 2 ** dev.read(512)[108] + dev.seek(11 * sector_size) + dev.write(b"\0" * sector_size) + + succ = BlockDev.fs_exfat_check(self.loop_devs[0]) + self.assertFalse(succ) + + succ = BlockDev.fs_exfat_repair(self.loop_devs[0]) + self.assertTrue(succ) + + succ = BlockDev.fs_exfat_check(self.loop_devs[0]) + self.assertTrue(succ) + class ExfatTestRepair(ExfatTestCase): def test_exfat_repair(self):