libexfat, fsck: exit() upon I/O error during fsck
Subsystems (2)
PATCH 1/7 libexfat, fsck: exit() upon I/O error during fsck
Add I/O error handling callback to give up fsck process when an I/O error occurs. There are several places where I/O errors are either improperly treated as filesystem inconsistency errors or silently ignored.
As most of the codebase wasn't built with EIO in mind, rather than adding EIO checks where I/O syscalls are involved, intercepting errors in syscall wrappers through a callback to prevent further operation of fsck seems to be a reasonable fix with low risk of regression.
--- fsck/fsck.c | 28 +++++++++++++++++ include/libexfat.h | 34 ++++++++++++++++++++ lib/libexfat.c | 77 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 134 insertions(+), 5 deletions(-)
fsck/fsck.c +28 -0
@@ -2008,6 +2008,30 @@ unrec_mbr:return 0 ; } +static void fsck_ioerror_callback (enum exfat_what_ioerror what,int err, +int fd,off_t ofs,off_t size,const void *buf,void *ctx) +{ +const char *w_str; + +if (fd != exfat_fsck.exfat->blk_dev->dev_fd) +return ; + +/* prevent recursive callbacks */ +exfat_set_ioerror_callback (NULL ,NULL ); + + w_str =exfat_what_ioerror_str (what); +assert (w_str !=NULL ); +exfat_err ("ERROR: I/O error %d at %" PRIdMAX", length %" PRIdMAX", %s\n" , + err, (intmax_t )ofs, (intmax_t )size, w_str); + +exfat_fsync (exfat_fsck.exfat->blk_dev->dev_fd); + +exit (FSCK_EXIT_OPERATION_ERROR ); +/* Shut compiler up */ + (void )buf; + (void )ctx; +} +int main (int argc,char *const argv[]) {struct fsck_user_input ui;
@@ -2166,6 +2190,8 @@ int main(int argc, char * const argv[]) goto err; } +exfat_set_ioerror_callback (fsck_ioerror_callback,NULL ); +exfat_debug ("verifying root directory...\n" ); ret =exfat_root_dir_check (&exfat_fsck);if (ret) {
@@ -2191,6 +2217,8 @@ int main(int argc, char * const argv[]) exfat_fsck.dirty_fat = true; } +exfat_set_ioerror_callback (NULL ,NULL ); +if (exfat_fsck.options &FSCK_OPTS_REPAIR_WRITE ) { ret =write_bitmap (&exfat_fsck);if (ret) {
include/libexfat.h +34 -0
@@ -259,6 +259,40 @@ void exfat_init_blk_dev_info(struct exfat_blk_dev *bd);void exfat_deinit_blk_dev_info (struct exfat_blk_dev *bd);int exfat_get_blk_dev_info (struct exfat_user_input *ui,struct exfat_blk_dev *bd); + +/* I/O Error Handling Facilities */ + +enum exfat_what_ioerror { +EXFAT_IOERROR_READ ,/* [p]read() */ +EXFAT_IOERROR_WRITE ,/* [p]write() */ +EXFAT_IOERROR_ZERO ,/* exfat_write_zero*() or exfat_zeroout_blocks() */ +EXFAT_IOERROR_DISCARD ,/* ioctl(..., BLK*DISCARD, ...) */ +EXFAT_IOERROR_SYNC ,/* fsync() */ +}; +/* Convert the enum to a string of one word describing the action */ +const char *exfat_what_ioerror_str (enum exfat_what_ioerror w); +/* +* I/O Error Callback Function Type +* +* err holds the errno set by the syscall. fd, ofs, size and buf are the +* parameters passed to the syscall. Obviously, in case of pread(), buf contains +* no meaningful data. In case of non-offset syscalls like read() and write(), +* ofs is -1. If the operation does not involve data range(in case of fsync()), +* ofs and size are passed as negative values. If the operation does not involve +* data(in case of exfat_write_zero*() and exfat_*_blocks()), buf is passed as +* NULL. ctx is the user context set with exfat_set_ioerror_callback(). +*/ +typedef void (*exfat_ioerror_callback_t )(enum exfat_what_ioerror what,int err, +int fd,off_t ofs,off_t size,const void *buf,void *ctx); +/* +* Set the callback function for handling I/O errors +* +* The function will be called from the library I/O wrappers including +* exfat_read*(), exfat_write*(), exfat_fsync() and exfat_discard_blocks() when +* the underlying syscall returns an error. Set cb to NULL to disable callbacks. +*/ +void exfat_set_ioerror_callback (exfat_ioerror_callback_t cb,void *ctx); +/* * Load the requested size of data from the file onto buf *
lib/libexfat.c +72 -5
137 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH 2/7 exfat2img: refactor restore_from_stdin()
Remove meaningless declaration and assignment of in_fd, which is a macro constant integer value of 0. Remove the dead if statement. This commit ammends the original commit introduced the changes.
No functional change.
--- exfat2img/exfat2img.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
exfat2img/exfat2img.c +6 -12
@@ -747,7 +747,7 @@ static ssize_t read_stream(int fd, void *buf, size_t len)static int restore_from_stdin (struct exfat2img *ei) { -int in_fd, ret =0 ; +int ret =0 ;unsigned char cc;unsigned int clu, end_clu;unsigned int cc_clu_count;
@@ -757,13 +757,7 @@ static int restore_from_stdin(struct exfat2img *ei)off_t in_start_off;size_t len; - in_fd =STDIN_FILENO ;/* POSIX spec mandates stdin == 0 */ -if (in_fd <0 ) { -exfat_err ("failed to get fd from stdin\n" ); -return in_fd; - } - -if (read_stream (in_fd, &ei_hdr,sizeof (ei_hdr)) != (ssize_t )sizeof (ei_hdr)) { +if (read_stream (STDIN_FILENO , &ei_hdr,sizeof (ei_hdr)) != (ssize_t )sizeof (ei_hdr)) {exfat_err ("failed to read a header\n" );return -EIO ; }
@@ -787,7 +781,7 @@ static int restore_from_stdin(struct exfat2img *ei) out_end_off_excl =le32_to_cpu (ei_hdr.heap_clus_offset);while (out_start_off < out_end_off_excl) { len =MIN (out_end_off_excl - out_start_off, clus_size); -if (read_stream (in_fd, ei->dump_cluster, len) != (ssize_t )len) { +if (read_stream (STDIN_FILENO , ei->dump_cluster, len) != (ssize_t )len) {exfat_err ("failed to read first meta region. %llu ~ %llu\n" , (unsigned long long )in_start_off, (unsigned long long )in_start_off + len);
@@ -810,7 +804,7 @@ static int restore_from_stdin(struct exfat2img *ei)/* restore heap clusters */ clu =0 ;while (clu <le32_to_cpu (ei_hdr.cluster_count)) { -if (read_stream (in_fd, &cc,sizeof (cc)) != (ssize_t )sizeof (cc)) { +if (read_stream (STDIN_FILENO , &cc,sizeof (cc)) != (ssize_t )sizeof (cc)) {exfat_err ("failed to read cc at %llu\n" , (unsigned long long )in_start_off); ret = -EIO ;
@@ -819,7 +813,7 @@ static int restore_from_stdin(struct exfat2img *ei) in_start_off +=1 ;if (cc ==EI_CC_COPY_2 || cc ==EI_CC_SKIP_2 ) { -if (read_stream (in_fd, &t_cc_clu_count,EI_CC_PAYLOAD_LEN ) != +if (read_stream (STDIN_FILENO , &t_cc_clu_count,EI_CC_PAYLOAD_LEN ) != (ssize_t )EI_CC_PAYLOAD_LEN ) {exfat_err ("failed to read cc cluster count at %llu\n" , (unsigned long long )in_start_off);
@@ -840,7 +834,7 @@ static int restore_from_stdin(struct exfat2img *ei)if (cc ==EI_CC_COPY_1 || cc ==EI_CC_COPY_2 ) { end_clu = clu + cc_clu_count;while (clu < end_clu) { -if (read_stream (in_fd, ei->dump_cluster, +if (read_stream (STDIN_FILENO , ei->dump_cluster, clus_size) != (ssize_t )clus_size) { exfat_err("failed to read range %llu ~ %llu\n", (unsigned long long)in_start_off,
Signature · 1 line
2.56.0
PATCH 3/7 fsck: fix missing line ending in error messages
In reply to David TimberFix missing or erroneous new line chararcter(\n) in error messages.
--- fsck/fsck.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fsck/fsck.c +2 -2
@@ -287,7 +287,7 @@ static int root_check_clus_chain(struct exfat *exfat,exfat_bitmap_set (exfat->alloc_bitmap, clus);if (exfat_get_inode_next_clus (exfat, node, clus, &next)) { -exfat_err ("ERROR: failed to read the fat entry of root" ); +exfat_err ("ERROR: failed to read the fat entry of root\n" ); goto out_trunc; }
@@ -1790,7 +1790,7 @@ static int rescue_orphan_clusters(struct exfat_fsck *fsck)/* build a template dentry set */ err =exfat_build_file_dentry_set (exfat, name,0 , &dset, &dcount);if (err) { -exfat_err ("failed to create a temporary file in LOST+FOUNDn" ); +exfat_err ("failed to create a temporary file in LOST+FOUND\n" ); goto out; } dset[1 ].dentry.stream.flags |=EXFAT_SF_CONTIGUOUS ;
Signature · 1 line
2.56.0
PATCH 3/7 fsck: fix missing line ending in error messages
Quoted 9 lines
fsck/fsck.c +1
-1exfat_bitmap_set (exfat->alloc_bitmap, clus);if (exfat_get_inode_next_clus (exfat, node, clus, &next)) { -exfat_err ("ERROR: failed to read the fat entry of root" ); +exfat_err ("ERROR: failed to read the fat entry of root\n" ); goto out_trunc; }
fsck/fsck.c static int rescue_orphan_clusters(struct exfat_fsck *fsck) · line 1796
Quoted 8 lines
fsck/fsck.c +1
-1@@ -1790,7 +1790,7 @@ static int rescue_orphan_clusters(struct exfat_fsck *fsck)/* build a template dentry set */ err =exfat_build_file_dentry_set (exfat, name,0 , &dset, &dcount);if (err) { -exfat_err ("failed to create a temporary file in LOST+FOUNDn" ); +exfat_err ("failed to create a temporary file in LOST+FOUND\n" ); goto out; } dset[1 ].dentry.stream.flags |=EXFAT_SF_CONTIGUOUS ;
Hi David,
I found two more error messages that are missing a trailing newline:
defrag/defrag.c:
exfat_err("memory run out in %s", __func__); lib/libexfat.c:
exfat_err("ERROR: failed to read the fat entry of root");
Thanks.
Re: [PATCH 3/7] fsck: fix missing line ending in error messages
Quoted 21 lines · Yang Wen
Quoted 9 lines
fsck/fsck.c +1
-1exfat_bitmap_set (exfat->alloc_bitmap, clus);if (exfat_get_inode_next_clus (exfat, node, clus, &next)) { -exfat_err ("ERROR: failed to read the fat entry of root" ); +exfat_err ("ERROR: failed to read the fat entry of root\n" ); goto out_trunc; }fsck/fsck.c static int rescue_orphan_clusters(struct exfat_fsck *fsck) · line 1796
Quoted 8 lines
fsck/fsck.c +1
-1@@ -1790,7 +1790,7 @@ static int rescue_orphan_clusters(struct exfat_fsck *fsck)/* build a template dentry set */ err =exfat_build_file_dentry_set (exfat, name,0 , &dset, &dcount);if (err) { -exfat_err ("failed to create a temporary file in LOST+FOUNDn" ); +exfat_err ("failed to create a temporary file in LOST+FOUND\n" ); goto out; } dset[1 ].dentry.stream.flags |=EXFAT_SF_CONTIGUOUS ;Hi David,
I found two more error messages that are missing a trailing newline:
Quoted 7 lines
defrag/defrag.c: exfat_err("memory run out in %s", __func__);
lib/libexfat.c:
exfat_err("ERROR: failed to read the fat entry of root");Thanks.
ACK
PATCH 4/7 fsck: do not print version if run with -p or -a
In reply to David TimberWhen run with the option -p or -a, do not print version info to stderr. This is to prevent unnecessary output to the system log if the volume is automatically mounted via fstab.
When run with -V or --version, only print the version info before exiting.
--- fsck/fsck.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fsck/fsck.c +7 -3
@@ -2106,13 +2106,17 @@ int main(int argc, char * const argv[]) } } -show_version (); +if (version_only) { +show_version (); +exit (FSCK_EXIT_SYNTAX_ERROR ); + } +if (!(ui.options &FSCK_OPTS_REPAIR_AUTO )) +show_version (); +if (optind != argc -1 || (ui.options &FSCK_OPTS_REPAIR_ASK && ui.options &FSCK_OPTS_PROGRESS_BAR ))usage (argv[0 ]); -if (version_only) -exit (FSCK_EXIT_SYNTAX_ERROR );if (ui.options &FSCK_OPTS_REPAIR_WRITE ) ui.ei.writeable = true;else {
Signature · 1 line
2.56.0
PATCH 5/7 fsck: add test script for EIO handling
In reply to David TimberTo test the feature introduced in commit 949da8b46e3f ("libexfat, fsck:exit() upon I/O error during fsck"), add a script to test if fsck.exfat leaves the contents of the filesystem intact upon encountering EIO.
Prior to the patch, where EIO is not handled properly, fsck.exfat modified the filesystem which resulted in the volume in a broken state or, in some cases, data loss. The script tests fsck.exfat by setting each sector of the test device bad.
The script is not integrated to the CI due to performance issues. On a reasonably prices machine, the script finishes in 12 hours or even more.
--- scripts/test-bads.sh | 161 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 scripts/test-bads.sh
scripts/test-bads.sh new file +161 -0
@@ -0,0 +1,161 @@ +#!/bin/bash +# Test EIO bail out behaviour of fsck.exfat: fsck.exfat mustn't modify the +# volume with no issues just because the underlying hardware is faulty. The +# script requires root privileges for dmsetup. Please run it on a VM. +# +# 1. Set up a loop device +# 2. Format the loop device +# 3. Mount the loop device +# 4. Populate a deep directory structure on the device +# 5. Unmount the device +# 6. Control run: run fsck.exfat on the device(expect exit code 0) +# 7. Hash the loop device (to ensure no modification of the filesystem upon EIO) +# 8. Set up a dm-dust device +# 9. For each logical sector of the device +# a. Set the sector "read" bad (write should succeed) +# b. Run fsck.exfat ... +# c. Hash the loop device and confirm no modification of the device contents +# +# This is brute force testing so the script is quite slow even on +# enterprise-grade machines. To run the test in parallel, use the 1st and the +# 2nd args, which are the badblock offset and the step, respectively. For +# example, to run two instances in parallel, +# +# ./test-bads.sh 0 2 & +# ./test-bads.sh 1 2 & +# +set -e +declare -r PRINTABLES=( {a..z} {A..Z} {0..9} ) +declare -r PRINTABLES_CNT=${#PRINTABLES[@]} +# parallel run params +[ -z "$1" ] && declare -r RUN_OFS="0" || declare -r RUN_OFS="$1" +[ -z "$2" ] && declare -r RUN_STEP="1" || declare -r RUN_STEP="$2" + +declare -r IMG_FILE="$(mktemp)" +declare -r IMG_BACKUP="$(mktemp)" +declare -r IMG_SIZE="67108864" +declare -r IMG_SS=$((IMG_SIZE / 512)) +declare -r LOOP="/dev/disk/by-loop-inode/$(stat -c '%Hd:%Ld-%i' "$IMG_FILE")" +[ -z "$MKFS_EXFAT" ] && MKFS_EXFAT="mkfs.exfat" +[ -z "$FSCK_EXFAT" ] && FSCK_EXFAT="fsck.exfat" +declare -r DUST_NAME="dustexfatbads$RUN_OFS" + +hash_img() +{ + # Use CRC32C for speed. Ignore LBA 0 which contains volume dirty flag + dd status=none if="$1" skip=1 | rhash --one-hash -C - +} + +get_rand_name() +{ + local cnt="$1" + local ret="" + + for (( i = 0; i < cnt; i++ )) + do + ret="$ret${PRINTABLES[RANDOM % PRINTABLES_CNT]}" + done + + echo "$ret" +} + +bomb_dir() +{ + local -r TLDS=( + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "天下皆知美之為美,斯惡已;皆知善之為善,斯不善已。故有無相生,難易相成,長短相形,高下相傾,音聲相和,前後相隨。" + "吾輩は猫である。名前はまだ無い。どこで生れたかとんと見当がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。" + "모든인간은태어날때부터자유로우며그존엄과권리에있어동등하다.인간은천부적으로이성과양심을부여받았으며서로형제애의정신으로행동하여야한다." + ) + + for tld in "${TLDS[@]}" + do + mkdir -p "$tld" + pushd "$tld" > /dev/null + + mkdir -p {a,b,c}/{1,2,3}/{X,Y,Z} + set -o pipefail + find -mindepth 1 -type d | while read dir + do + pushd "$dir" > /dev/null + for (( i = 0; i < 64; i++ )) + do + truncate -s $((i + 1)) "f-$(get_rand_name $i)" + done + popd > /dev/null + done + set +o pipefail + + popd > /dev/null + done +} + +cleanup() +{ + dmsetup remove "$DUST_NAME" + udisksctl loop-delete -b "$LOOP" + rm -f "$IMG_FILE" "$IMG_BACKUP" +} + +dmsetup remove "$DUST_NAME" > /dev/null 2> /dev/null || true + +fallocate -l "$IMG_SIZE" "$IMG_FILE" +"$MKFS_EXFAT" "$IMG_FILE" + +set +e +udisksctl loop-setup --file "$IMG_FILE" +ec=$? +if [ "$ec" -ne 0 ]; then + exit "$ec" +fi +set -e + +udisksctl mount -b "$LOOP" +declare -r MP="$(findmnt "$LOOP" -no TARGET)" + +pushd "$MP" +bomb_dir +popd + +udisksctl unmount -b "$LOOP" + +cat "$IMG_FILE" > "$IMG_BACKUP" +declare -r HASH="$(hash_img "$LOOP")" +echo "image: $IMG_FILE" +echo "backup: $IMG_BACKUP" + +"$FSCK_EXFAT" -y "$IMG_FILE" + +if [ "$HASH" != "$(hash_img "$LOOP")" ] +then + echo "FAIL: the filesystem implementation corrupted the filesystem or there's a problem in fsck.exfat" >&2 + exit 1 +fi + +dmsetup create "$DUST_NAME" --table "0 $IMG_SS dust $LOOP 0 512" +dmsetup message "$DUST_NAME" 0 enable + +set +e + +for (( i = RUN_OFS; i < IMG_SS; i += RUN_STEP )) +do + dmsetup message "$DUST_NAME" 0 addbadblock "$i" + valgrind -q --error-exitcode=100 "$FSCK_EXFAT" -y "/dev/mapper/$DUST_NAME" > /dev/null + ec=$? + dmsetup message "$DUST_NAME" 0 removebadblock "$i" > /dev/null 2> /dev/null + sync "/dev/mapper/$DUST_NAME" + + if [ "$HASH" != "$(hash_img "$LOOP")" ] + then + echo "FAIL: fsck.exfat modified the filesystem (badblock: $i)" >&2 + exit 1 + elif [ "$ec" -eq 100 ] + then + # Didn't modify the volume but there's a memory bug?? + echo "FAIL: fsck.exfat experienced memory error (badblock: $i)" >&2 + exit 1 + fi +done + +echo "OK: fsck.exfat does not modify the filesystem on EIO" +cleanup
Signature · 1 line
2.56.0
Re: [PATCH 5/7] fsck: add test script for EIO handling
Hi David,
I tested this script on Ubuntu 22.04 and found a few portability and prerequisite issues.
First, the script failed immediately after creating the loop device:
Mapped file /tmp/tmp.WUyy32nDsS as /dev/loop6.
Error looking up object for device /dev/disk/by-loop-inode/?d:?d-661642
The problem is this line:
Quoted 1 line
+declare -r LOOP="/dev/disk/by-loop-inode/$(stat -c '%Hd:%Ld-%i' "$IMG_FILE")"
The %Hd and %Ld stat format directives were introduced in GNU coreutils 9.0. Ubuntu 22.04 has coreutils 8.32, with which the command produces "?d:?d-<inode>". The loop device itself is created successfully, but the script passes a nonexistent path to udisksctl.
Could we avoid that coreutils version dependency by looking up the loop device after udisksctl creates it? For example:
LOOP=""
...
udisksctl loop-setup --file "$IMG_FILE"
ec=$?
if [ "$ec" -ne 0 ]; then
exit "$ec"
fi
LOOP="$(losetup -j "$IMG_FILE" --noheadings --output NAME |
head -n 1 | tr -d '[:space:]')"
if [ -z "$LOOP" ] || [ ! -b "$LOOP" ]; then
echo "FAIL: cannot find loop device for $IMG_FILE" >&2
exit 1
fi
declare -r LOOPThis also avoids depending on the /dev/disk/by-loop-inode symlink and uses the loop device that was actually created.
After working around that issue, the hash command failed as well:
RHash: unknown option: --one-hash
The installed version is RHash 1.4.2. It supports CRC32C, but does not support --one-hash. More importantly, the failure is hidden by the command substitution assigned through declare, so HASH becomes empty. The next hash calculation also produces an empty string and the test incorrectly treats the two failed calculations as matching hashes.
This form works with RHash 1.4.2 and produces only the CRC32C value:
dd status=none if="$1" skip=1 |
rhash --printf='%{crc32c}' -Also, -C selects CRC32 rather than CRC32C in RHash 1.4.2, despite the comment saying that CRC32C is used.
Finally, the script later failed while creating the dm-dust mapping:
device-mapper: reload ioctl on dustexfatbads0 failed: Invalid argument Command failed.
The kernel log gives the actual reason:
device-mapper: table: dust: unknown target type
On this system:
$ grep CONFIG_DM_DUST /boot/config-$(uname -r)
# CONFIG_DM_DUST is not set $ modinfo dm_dust
modinfo: ERROR: Module dm_dust not found.dmsetup targets consequently does not list the dust target. The script currently documents the root requirement, but not the CONFIG_DM_DUST requirement. Could it check for the dust target before creating the image and print a clear error or skip result? Doing the prerequisite checks before allocating, formatting and mounting the image would also avoid spending time populating the filesystem when the test cannot run.
It would also be useful to install an EXIT/INT/TERM trap for cleanup. Each of the failures above leaves the loop device and temporary image files behind because cleanup is called only on the successful path.
Thanks.
Re: [PATCH 5/7] fsck: add test script for EIO handling
Quoted 1 line · Yang Wen
Hi David,
Hi, Yang.
Thanks for reviewing. I really appreciate that someone is actually taking time to review the patches of exfatprogs, which is often not looked at. The review does seems a bit LLM-like, but if you've done the work yourself, good work!
The added script is more of a proof of work than a practical one, just to absolutely make sure that fsck.exfat does not modify an innocent error-free exfat volume just because the hardware is faulty. That was the whole point of it.
Quoted 80 lines
I tested this script on Ubuntu 22.04 and found a few portability and prerequisite issues.
First, the script failed immediately after creating the loop device:
Mapped file
/tmp/tmp.WUyy32nDsSas/dev/loop6.
Error looking up object for device /dev/disk/by-loop-inode/?d:?d-661642The problem is this line:
Quoted 1 line
+declare -r LOOP="/dev/disk/by-loop-inode/$(stat -c '%Hd:%Ld-%i' "$IMG_FILE")"
The %Hd and %Ld stat format directives were introduced in GNU coreutils 9.0. Ubuntu 22.04 has coreutils 8.32, with which the command produces "?d:?d-<inode>". The loop device itself is created successfully, but the script passes a nonexistent path to udisksctl.
Could we avoid that coreutils version dependency by looking up the loop device after udisksctl creates it? For example:
LOOP="" ... udisksctl loop-setup --file "$IMG_FILE" ec=$? if [ "$ec" -ne 0 ]; then exit "$ec" fi LOOP="$(losetup -j "$IMG_FILE" --noheadings --output NAME | head -n 1 | tr -d '[:space:]')" if [ -z "$LOOP" ] || [ ! -b "$LOOP" ]; then echo "FAIL: cannot find loop device for $IMG_FILE" >&2 exit 1 fi declare -r LOOPThis also avoids depending on the
/dev/disk/by-loop-inodesymlink and uses the loop device that was actually created.After working around that issue, the hash command failed as well:
RHash: unknown option: --one-hashThe installed version is RHash 1.4.2. It supports CRC32C, but does not support --one-hash. More importantly, the failure is hidden by the command substitution assigned through declare, so HASH becomes empty. The next hash calculation also produces an empty string and the test incorrectly treats the two failed calculations as matching hashes.
This form works with RHash 1.4.2 and produces only the CRC32C value:
dd status=none if="$1" skip=1 | rhash --printf='%{crc32c}' -Also, -C selects CRC32 rather than CRC32C in RHash 1.4.2, despite the comment saying that CRC32C is used.
Finally, the script later failed while creating the dm-dust mapping:
device-mapper: reload ioctl on dustexfatbads0 failed: Invalid argument Command failed.
The kernel log gives the actual reason:
device-mapper: table: dust: unknown target type
On this system:
$ grep CONFIG_DM_DUST /boot/config-$(uname -r) # CONFIG_DM_DUST is not set$ modinfo dm_dust modinfo: ERROR: Module dm_dust not found.dmsetup targets consequently does not list the dust target. The script currently documents the root requirement, but not the
CONFIG_DM_DUSTrequirement. Could it check for the dust target before creating the image and print a clear error or skip result? Doing the prerequisite checks before allocating, formatting and mounting the image would also avoid spending time populating the filesystem when the test cannot run.
Quoted 5 lines
It would also be useful to install an EXIT/INT/TERM trap for cleanup. Each of the failures above leaves the loop device and temporary image files behind because cleanup is called only on the successful path.
Thanks.
I realised that this is something that shouldn't be done with dm-dust, let alone with a bash script. It just doesn't scale up. If we really want to make a test suite that could fit into the CI, we should write a special program for this. The general gist of it is ...
1. do a fault injection in the program itself(debug #if ... #endif), just like f2fs kernel driver does its fault injection
2. use O_TMPFILE(XFAIL if not supported) and mmap()+memcmp() to assert failure
eliminating the need to rely on external utils and the kernel module. The program should be light and fast enough to run it in make check. Heck, maybe just make it fs-agnostic and submit it to xfstests. Why not? The kernel devs would actually appreciate such test case.
I just didn't feel like doing it. You(or anyone else snooping) are more than welcome to vibe code send submit patches replacing my script. idk............ Kinda don't want to do it for now. Maybe someday, when I don't have too much on my plate.
Thanks,
Davo
PATCH 6/7 tests: add suite0000-dump-arch for CPU arch info
In reply to David TimberAdd a dummy test suite for recording information on the CPU arch being tested on the CI pipeline. This is for porting the project to new hardware platforms.
--- lib/Makefile.am | 7 ++++-- lib/tests/suite0000-dump-arch.c | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 lib/tests/suite0000-dump-arch.c
lib/Makefile.am +5 -2
@@ -3,8 +3,11 @@ noinst_LIBRARIES = libexfat.a libexfat_a_SOURCES = libexfat.c exfat_fs.c exfat_dir.c utils.c -check_PROGRAMS = tests/suite0000-bitmap tests/suite0001-parse -TESTS = tests/suite0000-bitmap tests/suite0001-parse +check_PROGRAMS = tests/suite0000-bitmap tests/suite0000-dump-arch tests/suite0001-parse +TESTS = tests/suite0000-bitmap tests/suite0000-dump-arch tests/suite0001-parse + +tests_suite0000_dump_arch_SOURCES = tests/suite0000-dump-arch.c +tests_suite0000_dump_arch_LDADD = libexfat.a tests_suite0000_bitmap_SOURCES = tests/suite0000-bitmap.c tests_suite0000_bitmap_LDADD = libexfat.a
lib/tests/suite0000-dump-arch.c new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH 6/7 tests: add suite0000-dump-arch for CPU arch info
lib/Makefile.am noinst_LIBRARIES = libexfat.a · line 10
Quoted 2 lines
lib/Makefile.am +2
-0+tests_suite0000_dump_arch_SOURCES = tests/suite0000-dump-arch.c +tests_suite0000_dump_arch_LDADD = libexfat.a
The dump-arch test does not reference any symbols from libexfat.a, so the LDADD assignment appears to be unnecessary.
I also verified this by linking suite0000-dump-arch.o without libexfat.a. The link succeeded, the test ran successfully, and the resulting executable was byte-identical to the executable linked with libexfat.a.
Thanks.
Re: [PATCH 6/7] tests: add suite0000-dump-arch for CPU arch info
Quoted 4 lines · Yang Wen
lib/Makefile.am noinst_LIBRARIES = libexfat.a · line 10
Quoted 2 lines
lib/Makefile.am +2
-0+tests_suite0000_dump_arch_SOURCES = tests/suite0000-dump-arch.c +tests_suite0000_dump_arch_LDADD = libexfat.aThe dump-arch test does not reference any symbols from libexfat.a, so the LDADD assignment appears to be unnecessary.
ACK
Doesn't really matter, but will remove that line next time I get around that particular Makefile recipe.
Thanks
PATCH 7/7 Github Actions: bump to Ubuntu 26.04 runner
In reply to David TimberGithub rolled out 26.04 for the "ubuntu-latest" runner, breaking the CI pipeline due to deprecated and missing packages used, one of which being MIPS.
Replace MIPS emulation with SPARC64 for big-endian tests. Avoid using the -E option of sudo that's been removed in Ubuntu 26.04. Do not install other packages that have been removed.
--- .github/workflows/c-cpp.yml | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-)
.github/workflows/c-cpp.yml +12 -17
@@ -64,7 +64,6 @@ jobs: sudo apt-get --update --quiet --yes install \ linux-headers-$(uname -r) xz-utils \ valgrind libblkid-dev ${{ matrix.cc }} - sudo apt-get install -y linux-modules-extra-$(uname -r) - name: Build run: | export "CC=${{ matrix.cc }}"
@@ -80,9 +79,10 @@ jobs: - name: Run fsck with Valgrind run: | pushd tests - export FSCK1="valgrind --error-exitcode=1 ../fsck/fsck.exfat" - export FSCK2="valgrind --error-exitcode=1 ../fsck/fsck.exfat" - sudo -E ./test_fsck.sh + sudo \ + FSCK1="valgrind --error-exitcode=1 ../fsck/fsck.exfat" \ + FSCK2="valgrind --error-exitcode=1 ../fsck/fsck.exfat" \ + ./test_fsck.sh popd - name: Run the rest with Valgrind shell: bash
@@ -163,11 +163,11 @@ jobs: fail-fast: false matrix: include: - - host: mips-linux-gnu - qemu: qemu-system-mips - gcc: gcc-mips-linux-gnu - run: qemu-mips - name: mips + - host: sparc64-linux-gnu + qemu: qemu-system-sparc + gcc: gcc-sparc64-linux-gnu + run: qemu-sparc64 + name: sparc - host: x86_64-linux-gnu qemu: qemu-system-x86 gcc: gcc-x86-64-linux-gnu
@@ -186,7 +186,6 @@ jobs: cryptsetup parted dosfstools e2fsprogs btrfs-progs f2fs-tools ntfs-3g xfsprogs \ ${{ matrix.gcc }} ${{ matrix.qemu }} \ qemu-user qemu-utils - sudo apt-get install -y linux-modules-extra-$(uname -r) export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH export PATH=/usr/local/lib:$PATH
@@ -288,12 +287,8 @@ jobs: - name: run fsck repair testcases run: | pushd tests - export FSCK1="${{ matrix.run }} ../fsck/fsck.exfat" - export FSCK2="fsck.exfat" - sudo -E ./test_fsck.sh - export FSCK1="fsck.exfat" - export FSCK2="${{ matrix.run }} ../fsck/fsck.exfat" - sudo -E ./test_fsck.sh + sudo FSCK1="${{ matrix.run }} ../fsck/fsck.exfat" FSCK2="fsck.exfat" ./test_fsck.sh + sudo FSCK1="fsck.exfat" FSCK2="${{ matrix.run }} ../fsck/fsck.exfat" ./test_fsck.sh popd - name: dentry creation/deletion stress test shell: bash
@@ -450,7 +445,7 @@ jobs: fail-fast: false matrix: os: [windows-2022, windows-latest] - name: [mips, i686, x86_64] + name: [sparc, i686, x86_64] runs-on: ${{ matrix.os }} steps: - uses: actions/download-artifact@v8
Signature · 1 line
2.56.0
Re: [PATCH 7/7] Github Actions: bump to Ubuntu 26.04 runner
I can see that the CI is failing. It looks like you're stuck with 24.04 for some reason.
https://github.blog/changelog/2026-09-17-ubuntu-26-generally-available-and-latest-migration/
I don't understand why they decided to do a gradual roll out. My bad for not checking this before writing up the patch.
We should just pin the runner to "ubuntu-26.04". It should be good for another decade.
Davo
Namjae Jeon
maintainerRe: [PATCH 7/7] Github Actions: bump to Ubuntu 26.04 runner
Quoted 11 lines · David Timber
I can see that the CI is failing. It looks like you're stuck with 24.04 for some reason.
https://github.blog/changelog/2026-09-17-ubuntu-26-generally-available-and-latest-migration/
I don't understand why they decided to do a gradual roll out. My bad for not checking this before writing up the patch.
We should just pin the runner to "ubuntu-26.04". It should be good for another decade.
I also tried changing to ubuntu-26.04, but CI failed. because the exFAT module is missing in sparc64's linux module package.
Namjae Jeon
maintainerRe: [PATCH 7/7] Github Actions: bump to Ubuntu 26.04 runner
Quoted 8 lines · Namjae Jeon
Quoted 6 lines · David Timber
I can see that the CI is failing. It looks like you're stuck with 24.04 for some reason.
https://github.blog/changelog/2026-09-17-ubuntu-26-generally-available-and-latest-migration/
Quoted 7 lines
Quoted 5 lines
I don't understand why they decided to do a gradual roll out. My bad for not checking this before writing up the patch.
We should just pin the runner to "ubuntu-26.04". It should be good for another decade.
I also tried changing to ubuntu-26.04, but CI failed. because the exFAT module is missing in sparc64's linux module package.
See:
https://github.com/exfatprogs/exfatprogs/actions/runs/40640760753
Re: [PATCH 7/7] Github Actions: bump to Ubuntu 26.04 runner
https://github.com/dxdxdt/exfatprogs/actions/runs/40466719701
Well, I know. Devs don't like to hear "it works on my machine". That's why we have CI but the very thing basically betrayed us. Oh boy I love GH.
So, it must have something to do with the Ubuntu package management.... I'll have a look.
On 10/28/26 09:36, Namjae Jeon wrote:
[...]
Quoted 4 lines
Quoted 2 lines
I also tried changing to ubuntu-26.04, but CI failed. because the exFAT module is missing in sparc64's linux module package.
See:
https://github.com/exfatprogs/exfatprogs/actions/runs/40640760753
Thanks. I can dx from there.
Davo
Namjae Jeon
maintainerQuoted 6 lines · David Timber
Add I/O error handling callback to give up fsck process when an I/O error occurs. There are several places where I/O errors are either improperly treated as filesystem inconsistency errors or silently ignored.
Quoted 8 lines
As most of the codebase wasn't built with EIO in mind, rather than adding EIO checks where I/O syscalls are involved, intercepting errors in syscall wrappers through a callback to prevent further operation of fsck seems to be a reasonable fix with low risk of regression.
Reported-by sofine.ljm <[email protected]>Signed-off-by David Timber <[email protected]>
Applied your seven patches to #exfat-next.
Thanks!