Skip to contentSkip to conversation

mkfs: make mkfs.exfat deterministic to reduce CI runtime

PATCH Applied David Timber 2 participants 9 messages Nov 10 – Nov 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mkfs: make mkfs.exfat deterministic to reduce CI runtime

This series addresses rather wasteful use of Github Actions runners. mkfs.exfat can now be run in a mode that doesn't involve any randomness (ie. deterministic) so that tests in the CI pipeline can expect volume images with the identical contents every time. Other randomness generated and tests unrelated to exfatprogs are removed. Moving forward, the CI pipelines should focus on testing exfatprogs code, not other external implementations like Linux kernel or Microsoft Windows.

In action:

1. https://github.com/dxdxdt/exfatprogs/actions/runs/42765932946/attempts/1
2. https://github.com/dxdxdt/exfatprogs/actions/runs/42765932946

On the first run, the generated images are consolidated and then tested on Windows runners. On the subsequent run, the cached images are restored and diff'd. The Windows runners are not run as the diff script reports that both cached and generated images are identical.

---

The series also includes a patch that fixes a minor endianness confusion in GPT structure creation code. This is only fixed to make the tests work and there should be no real-life impact whatsoever(the disk signature in protective MBR seems to be ignored by all OSes).

This series doesn't fix any serious bug and there are some memory errors and fsck stability issues reported by users so I wouldn't recommend releasing the features in a timely manner.

On removing the stress tests in CI:

I'm planning on building CI pipelines focusing on the Linux kernel fs implementation that involve snooping on the patches(https://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat.git/), running xfstests and publishing the result. I've already made a couple of repo mirrors using CI with other providers(just in case Github decides to go kaput overnight):

- https://codeberg.org/exfat-dev/exfatprogs-releases
- https://codeberg.org/exfat-dev/exfatprogs

The tests should also the cover cases that are specific to exFAT in addition to xfstests. That goes without saying.

The prototype will be hosted on a Github repo. However, I do strongly feel that the tests deserve to be run on real hardware including USB thumb drives, sdcards and external HDDs as they're the ones exFAT is usually used on.

David Timber (7):
README.md: update build prerequisite packages
lib: make exfat_parse_guid() library function
mkfs: add -i/--volume-serial, --disk-guid and --part-guid options
mkfs: set disk signature of protective MBR to zero
CI: add mkfs entropy test
CI: generate images in deterministic manner to reduce runtime
CI: remove stress test

 .github/workflows/c-cpp.yml | 277 +++++++++++++++++++++++++-----------
 README.md                   |   4 +-
 include/libexfat.h          |   2 +
 lib/libexfat.c              |  13 +-
 manpages/mkfs.exfat.8       |  26 +++-
 mkfs/mkfs.c                 |  67 ++++++---
 mkfs/mkfs.h                 |  14 +-
 scripts/diff-images.py      | 134 +++++++++++++++++
 8 files changed, 426 insertions(+), 111 deletions(-)
 create mode 100755 scripts/diff-images.py
Signature · 1 line
2.56.0
#1 lore raw

PATCH 1/7 README.md: update build prerequisite packages

Add missing build prerequisite packages in README.md.

---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
README.md +2 -2
index 9a523a6..198fb4a 100644
@@ -11,10 +11,10 @@ under the GNU General Public License Version 2.
 Install prerequisite packages:
 ```
 For Debian, Ubuntu:
-    sudo apt-get install autoconf libtool automake make pkgconf libblkid-dev
+    sudo apt-get install autoconf automake bison libtool make pkgconf libblkid-dev
 
 For Fedora, RHEL:
-    sudo dnf install autoconf automake libtool libblkid-devel
+    sudo dnf install autoconf automake bison libtool make pkgconf libblkid-devel
 ```
 
 Build steps:
Signature · 1 line
2.56.0
#2 lore raw

PATCH 2/7 lib: make exfat_parse_guid() library function

In reply to David Timber

Make exfat_parse_guid(), which was previously set_guid(), a library function for upcoming features. Take an extra param type for error messages.

No functional change.

---
 include/libexfat.h |  2 ++
 lib/libexfat.c     | 13 ++++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)
include/libexfat.h +2 -0
index 1364d25..3749086 100644
@@ -386,6 +386,8 @@ DECLARE_PARSE_NUM(long, exfat_parse_long);
 DECLARE_PARSE_NUM(long long, exfat_parse_longlong);
 #undef DECLARE_PARSE_NUM
 
+int exfat_parse_guid(__u8 *guid, const char *input, const char *type);
+
 /*
  * Parse a software version string
  *
lib/libexfat.c +8 -5
index 3484a48..af96884 100644
@@ -1294,14 +1294,17 @@ out:
 	return err;
 }
 
-static int set_guid(__u8 *guid, const char *input)
+int exfat_parse_guid(__u8 *guid, const char *input, const char *type)
 {
 	__u8 buf[EXFAT_GUID_LEN];
 	int i, j, zero_len = 0;
 	int len = strlen(input);
 
+	if (type == NULL)
+		type = "GUID";
+
 	if (len != EXFAT_GUID_LEN * 2 && len != EXFAT_GUID_LEN * 2 + 4) {
-		exfat_err("invalid format for volume guid\n");
+		exfat_err("invalid format for %s\n", type);
 		return -EINVAL;
 	}
 
@@ -1318,7 +1321,7 @@ static int set_guid(__u8 *guid, const char *input)
 			 (i == 8 || i == 13 || i == 18 || i == 23))
 			continue;
 		else {
-			exfat_err("invalid character '%c' for volume GUID\n", ch);
+			exfat_err("invalid character '%c' for %s\n", ch, type);
 			return -EINVAL;
 		}
 
@@ -1334,7 +1337,7 @@ static int set_guid(__u8 *guid, const char *input)
 	}
 
 	if (zero_len == EXFAT_GUID_LEN * 2) {
-		exfat_err("%s is invalid for volume GUID\n", input);
+		exfat_err("%s is invalid for %s\n", input, type);
 		return -EINVAL;
 	}
 
@@ -1398,7 +1401,7 @@ int __exfat_set_volume_guid(struct exfat_dentry *dentry, const char *guid)
 	memset(dentry, 0, sizeof(*dentry));
 	dentry->type = EXFAT_GUID;
 
-	err = set_guid(dentry->dentry.guid.guid, guid);
+	err = exfat_parse_guid(dentry->dentry.guid.guid, guid, "volume GUID");
 	if (err)
 		return err;
 
Signature · 1 line
2.56.0
#3 lore raw

PATCH 3/7 mkfs: add -i/--volume-serial, --disk-guid and --part-guid options

In reply to David Timber

The purpose of these options is to provide a way to make fsck.exfat deterministic for testing purposes. For example, if the size and serial of the volume are constant, mkfs.exfat produces the volume with exact same contents. This makes it possible for tests to cache the previous result and the skip expensive verification process if there's no change in the generated images.

  $ truncate -s 32M a.img
  $ truncate -s 32M b.img
  $ mkfs.exfat -F -i 0x12345678 a.img
  ...
  $ mkfs.exfat -F -i 0x12345678 b.img
  ...
  $ sha256sum -b a.img b.img
  e293574fd06bfe9ed6e6d399c856387cf07dad4fe4a82f7605741e41a12ba2a5 *a.img
  e293574fd06bfe9ed6e6d399c856387cf07dad4fe4a82f7605741e41a12ba2a5 *b.img
  $ ./mkfs/mkfs.exfat -i 0x12345678 -F -Pgpt\
      --disk-guid=9129413c-768c-416e-8212-3c0688c2b396\
      --part-guid=dae52c4e-bb76-4759-9088-c25867217218\
        a.img
  ...
  $ ./mkfs/mkfs.exfat -i 0x12345678 -F -Pgpt\
      --disk-guid=9129413c-768c-416e-8212-3c0688c2b396\
      --part-guid=dae52c4e-bb76-4759-9088-c25867217218\
        b.img
  $ sha256sum -b a.img b.img
  b05dcf981ae6c622b07e3eb15d64fc54d7d2ffe86329a719c3001a711e719fe4 *a.img
  b05dcf981ae6c622b07e3eb15d64fc54d7d2ffe86329a719c3001a711e719fe4 *b.img

Also, fix a typo in manpages/mkfs.exfat.8 ("hypenized" -> "hyphenized").

---
 manpages/mkfs.exfat.8 | 26 +++++++++++++++++-
 mkfs/mkfs.c           | 63 ++++++++++++++++++++++++++++++++++---------
 mkfs/mkfs.h           | 14 +++++++---
 3 files changed, 85 insertions(+), 18 deletions(-)
manpages/mkfs.exfat.8 +25 -1
index 88085de..837ec5d 100644
@@ -22,9 +22,16 @@ mkfs.exfat \- create an exFAT filesystem
 .B \-U
 .I volume_guid
 ] [
+.B \-i
+.I volume_serial
+] [
 .B \-P
 .I type
 ] [
+.B \-\-disk\-guid\fR=\fIguid\fR
+] [
+.B \-\-part\-guid\fR=\fIguid\fR
+] [
 .B \-\-pack\-bitmap
 ] [
 .B \-\-upcase\fR=\fIfile\fR
@@ -163,11 +170,28 @@ Specifies the volume label to be associated with the exFAT filesystem.
 .TP
 .BR \-U ", " \-\-volume\-guid =\fIguid\fR
 Specifies the volume GUID to be associated with the exFAT filesystem.
-It can be given in the standard, hypenized UUID format like
+It can be given in the standard, hyphenized UUID format like
 \fBaaaabbbb-cccc-dddd-eeee-ffff00001111\fR. Note: The volume GUID cannot be used
 to set the the 8-letter ID reported by \fIblkid\fR or used as
 the filesystem UUID in \fB/etc/fstab\fR.
 .TP
+.BR \-i ", " \-\-volume\-serial =\fIserial\fR
+Specifies the volume serial of the exFAT filesystem. The volume serial is an
+unsigned 32-bit integer. It can be represented either in hexadecimal or decimal
+format. In the former case, the number must be prefixed with "0x" (for example,
+0xdeedbeef). The default is a number which depends on the filesystem creation
+time.
+.TP
+.BR \-\-disk\-guid =\fIguid\fR
+Specifies the disk GUID to be associated with the GUID partition table(GPT).
+If GPT is not used for the new exFAT volume, the GUID is only validated but not
+used.
+.TP
+.BR \-\-part\-guid =\fIguid\fR
+Specifies the partition GUID to be associated with the GUID partition
+table(GPT). If GPT is not used for the new exFAT volume, the GUID is only
+validated but not used.
+.TP
 .B \-\-pack\-bitmap
 Attempts to relocate the exFAT allocation bitmap so that it ends at the
 alignment boundary immediately following the FAT rather than beginning at that
mkfs/mkfs.c +50 -13

128 lines not on this page · raw message

mkfs/mkfs.h +10 -4
index c93685d..4eadc96 100644
@@ -32,6 +32,10 @@ struct exfat_mkfs_data_region {
 	void *data;
 };
 
+struct exfat_guid {
+	uint8_t b[16];
+};
+
 struct exfat_mkfs_info {
 	struct {
 		struct {
@@ -62,16 +66,18 @@ struct exfat_mkfs_info {
 	unsigned int volume_serial;
 
 	struct {
+		struct exfat_guid disk_guid;
+		struct exfat_guid part_guid;
+
 		void *mbr;
 		struct exfat_gpt_header *head_main;
 		struct exfat_gpt_header *head_backup;
 		struct exfat_gpt_entry *arr;
 		struct exfat_mkfs_data_region regions[EXFAT_GPT_DATA_REGION_CNT];
-	} gpt;
-};
 
-struct exfat_guid {
-	uint8_t b[16];
+		bool has_disk_guid:1;
+		bool has_part_guid:1;
+	} gpt;
 };
 
 struct exfat_gpt_header {
Signature · 1 line
2.56.0
#4 lore raw

PATCH 4/7 mkfs: set disk signature of protective MBR to zero

In reply to David Timber

According to Intel's UEFI specs 2.10, the disk signature in protective MBR of GPT should be set to zero. The mkfs.exfat implementation incorrectly sets it to the fixed value of 0xA2A0.

Because the value is not converted from little endian to host endian, the value on disk ended up different depending on the host's endianness, preventing mkfs.exfat from generating the exact same data structures even if all the GUIDs and the volume serial are fixed.

LE hosts(i686 and x86_64):

    0000 01B0: 00 00 00 00 00 00 00 00  A2 A0 00 00 00 00 00 00

BE hosts(SPARC 64):

    0000 01B0: 00 00 00 00 00 00 00 00  A0 A2 00 00 00 00 00 00

This patch fixes the endian confusion introduced in the original patch by always using the value of zero.

Fixes 0844be34e702 ("mkfs: add partition table creation support for Windows compatibility")
---
 mkfs/mkfs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mkfs/mkfs.c +1 -3
index 6c8bd76..fe3e416 100644
@@ -132,7 +132,6 @@ static int build_gpt(struct exfat_blk_dev *bd, const struct exfat_user_input *ui
 	int ret = 0;
 	unsigned long long req_size = 0;
 	unsigned long long first_usable, first_aligned, last_usable, last_aligned, part_sec_cnt;
-	uint16_t serial;
 	uint8_t *mbr = calloc(1, sector);
 	struct exfat_gpt_header *head_main = calloc(1, bd->sector_size);
 	struct exfat_gpt_header *head_backup = calloc(1, bd->sector_size);
@@ -237,7 +236,6 @@ static int build_gpt(struct exfat_blk_dev *bd, const struct exfat_user_input *ui
 	/* The first GPT entry */
 
 	memcpy(&arr[0].partition_type_guid, EXFAT_GPT_PART_TYPE, 16);
-	memcpy(&serial, &arr[0].partition_type_guid, 2);
 	if (finfo.gpt.has_part_guid)
 		memcpy(&arr[0].unique_partition_guid, &finfo.gpt.part_guid, EXFAT_GUID_LEN);
 	else
@@ -247,7 +245,7 @@ static int build_gpt(struct exfat_blk_dev *bd, const struct exfat_user_input *ui
 
 	/* Protective MBR */
 	exfat_put_bootstrap_code(ui->bootcode_msg, mbr, 0);
-	exfat_put_mbr_partition(bd, mbr, serial, 1, false, 0xEE, 0xFFFFFF);
+	exfat_put_mbr_partition(bd, mbr, 0, 1, false, 0xEE, 0xFFFFFF);
 	mbr[510] = 0x55;
 	mbr[511] = 0xAA;
 
Signature · 1 line
2.56.0
#5 lore raw

PATCH 5/7 CI: add mkfs entropy test

In reply to David Timber

Add mkfs entropy test to catch regressions caused by poor RNG entropy. mkfs.exfat must always generate different volume serials and GUIDs regardless of temporal factors(eg. mkfs.exfat run in rapid succession).

---
 .github/workflows/c-cpp.yml | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
.github/workflows/c-cpp.yml +36 -0
index 4e5eaf1..1be7e15 100644
@@ -284,6 +284,42 @@ jobs:
         rm -rf "$(realpath .)"
         popd
 
+# If run without -i, --disk-guid or --part-guid, mkfs.exfat must always create
+# randomly generated volume serial and GUIDs
+    - name: test mkfs RNG entropy
+      run: |
+        set -e
+
+        EXFAT_MKFS="$(realpath ./mkfs/mkfs.exfat)"
+
+        TMPDIR="$(mktemp -d)"
+        pushd "$TMPDIR"
+
+        rm -f a.img b.img
+        truncate -s 256M a.img
+        truncate -s 256M b.img
+        "$EXFAT_MKFS" -F -Pnone a.img
+        "$EXFAT_MKFS" -F -Pnone b.img
+        if diff a.img b.img
+        then
+          echo "mkfs.exfat generated the same volume serial !!!" >&2
+          exit 1
+        fi
+
+        rm -f a.img b.img
+        truncate -s 256M a.img
+        truncate -s 256M b.img
+        "$EXFAT_MKFS" -F -Pgpt -i 0x12345678 a.img
+        "$EXFAT_MKFS" -F -Pgpt -i 0x12345678 b.img
+        if diff a.img b.img
+        then
+          echo "mkfs.exfat generated the same GUIDs !!!" >&2
+          exit 1
+        fi
+
+        popd
+        rm -rf "$TMPDIR"
+
     - name: run fsck repair testcases
       run: |
         pushd tests
Signature · 1 line
2.56.0
#6 lore raw

PATCH 6/7 CI: generate images in deterministic manner to reduce runtime

In reply to David Timber

Currently, multiple instances of Windows runners are run for various target platforms to ensure no endianness or bit width confusion is introduced. However, this method has proved to be rather wasteful.

To reduce CI pipeline runtime, remove randomness in generated exfat volume images so that only a couple of Windows runners can be run to check the images. The randomness includes the volume serials, the test file placed in the volume and random data at the start of the image.

Add a python script for comparing sparse exfat volume images for use in CI.

Cache the last known good images to run the Windows runners only when a change is detected in the generated images.

To further reduce runtime and occasional failures due to a suspected race condition in Windows kernel, skip the drive letter assignment process and invoke CHKDSK through Repair-Volume powershell command.

---
 .github/workflows/c-cpp.yml | 197 +++++++++++++++++++++++++++++-------
 scripts/diff-images.py      | 134 ++++++++++++++++++++++++
 2 files changed, 292 insertions(+), 39 deletions(-)
 create mode 100755 scripts/diff-images.py
.github/workflows/c-cpp.yml +158 -39
index 1be7e15..106540f 100644
@@ -31,7 +31,6 @@ env:
     7M 128M 256M 512M
     2G 3G 4G 5G 7G 32G 64G 128G 256G 512G
     1T 2T 3T 4T 6T 8T 16T 32T 44T 64T
-  TEST_MAGIC: dd01aeee-bab0-babe-babe-deadcafebeef
 
   UTIL_LINUX_TARBALL: util-linux-2.42.tar.xz
   UTIL_LINUX_SRC: https://www.kernel.org/pub/linux/utils/util-linux/v2.42/util-linux-2.42.tar.xz
@@ -49,6 +48,9 @@ env:
       "parted img mkt msdos"
       "parted img mkt gpt"
     )
+  MKFS_INVAR_SERIAL: '0xdeadbeef'
+  MKFS_INVAR_PART_GUID: b1083784-c8ff-4ac1-a298-8328a05cc10b
+  MKFS_INVAR_DISK_GUID: 1c75d565-b6b8-4d30-aea4-401d588e85e1
 
 jobs:
   memcheck:
@@ -185,7 +187,7 @@ jobs:
              linux-headers-$(uname -r) xz-utils curl \
              cryptsetup parted dosfstools e2fsprogs btrfs-progs f2fs-tools ntfs-3g xfsprogs \
              ${{ matrix.gcc }} ${{ matrix.qemu }} \
-             qemu-user qemu-utils
+             qemu-user
         export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
         export PATH=/usr/local/lib:$PATH
 
@@ -403,16 +405,11 @@ jobs:
 
             for vs in $TEST_VOLUMESIZES
             do
-              img_a="exfat-$vs.img"
-              img_b="exfat-$vs.vhdx"
-
-              # fill the first 2MB with random data to see if mkfs.exfat leaves
-              # any garbage that confuses EXFAT.sys driver
-              dd iflag=fullblock if=/dev/urandom bs=2M count=1 of="$img_a" conv=notrunc status=none
+              img_raw="exfat-$vs.img"
 
               # truncate up to the volume size
-              truncate -s "$vs" "$img_a"
-              img_size="$(stat -c '%s' "$img_a")"
+              truncate -s "$vs" "$img_raw"
+              img_size="$(stat -c '%s' "$img_raw")"
               if [ "$pt" == "mbr" ] && [ "$img_size" -ge 2199023255552 ]
               then
                 expected=false
@@ -421,9 +418,14 @@ jobs:
               fi
               echo "========== $pt $img_size expected to succeed: $expected =========="
 
-              sudo losetup -Pb "$bs" /dev/loop22 "$img_a"
+              sudo losetup -Pb "$bs" /dev/loop22 "$img_raw"
               sudo blockdev --report /dev/loop22
-              if sudo ${{ matrix.run }} "$EXFAT_MKFS" -vP$pt /dev/loop22
+              if sudo ${{ matrix.run }} "$EXFAT_MKFS" -v \
+                -P$pt \
+                -i "$MKFS_INVAR_SERIAL" \
+                --part-guid="$MKFS_INVAR_PART_GUID" \
+                --disk-guid="$MKFS_INVAR_DISK_GUID" \
+                  /dev/loop22
               then
                 if ! "$expected"
                 then
@@ -434,28 +436,16 @@ jobs:
               elif ! "$expected"
               then
                 sudo losetup -d /dev/loop22
-                rm -f "$img_a"
+                rm -f "$img_raw"
                 continue
               else
                 exit 1
               fi
 
-              sudo ${{ matrix.run }} "$EXFAT_MKFS" -CP$pt /dev/loop22
               sudo blockdev --report /dev/loop22*
-
-              sudo ${{ matrix.run }} "$EXFAT_FSCK" /dev/loop22p1
-
-              sudo mount -t exfat /dev/loop22p1 /mnt/test/
-              sudo mkdir /mnt/test/a
-              echo "$TEST_MAGIC" | sudo tee /mnt/test/a/b > /dev/null
-              sudo umount /mnt/test/
-
               sudo ${{ matrix.run }} "$EXFAT_FSCK" /dev/loop22p1
               sudo ${{ matrix.run }} "$EXFAT_DUMP" /dev/loop22p1 | grep -iE 'Bytes per Sector:(\s+)?'"$bs" > /dev/null
               sudo losetup -d /dev/loop22
-
-              qemu-img convert -f raw -O vhdx "$img_a" "$img_b"
-              rm -f "$img_a"
             done
             popd
           done
@@ -463,7 +453,8 @@ jobs:
         done
         popd
 
-        tar -cf "images-${{ matrix.name }}.tar" "images-${{ matrix.name }}"
+        du -hs "images-${{ matrix.name }}"
+        tar -Scf "images-${{ matrix.name }}.tar" "images-${{ matrix.name }}"
         TAR_FILE="$(realpath "images-${{ matrix.name }}.tar")"
         popd
 
@@ -474,40 +465,168 @@ jobs:
         name: images-${{ matrix.name }}.tar
         path: images-${{ matrix.name }}.tar
 
-  test-windows-interop:
-    name: test generated large sparse images on Windows runners
+# Images generated by different targets should be exactly the same, given that
+# the same volume serial and the GUIDs are used. If not, it's indicative of
+# endianness or integer width confusion.
+#
+# After confirming that the contents of the images are same, compare them
+# against the cached images if exists. Fire up the Windows runners only when the
+# generated images are different.
+  check-images:
+    name: Compare and consolidate generated images
     needs: tests
+    runs-on: "ubuntu-26.04"
+    env:
+      TARGETS: sparc i686 x86_64
+    outputs:
+      mkfs_differ: ${{ steps.diff.outputs.result }}
+    steps:
+    - name: Install packages
+      run: sudo apt-get --update --quiet --yes install qemu-utils
+    - uses: actions/checkout@v6
+    - uses: actions/download-artifact@v8
+      with:
+        pattern: images-*.tar
+        merge-multiple: true
+    - name: Retrieve cached images from cache
+      uses: actions/cache/restore@v6
+      id: restore-images
+      with:
+        path: images-raw.cached.tar
+        # This is only a placeholder. No cache with this key will be actually created
+        key: images-raw.cached.tar-
+        restore-keys: images-raw.cached.tar-
+    - name: diff images and re-tar
+      id: diff
+      run: |
+        set -e
+        DL_DIR="$(realpath .)"
+        FIRST_TARGET=""
+        DIFF_SCRIPT="$(realpath ./scripts/diff-images.py)"
+        if [ -f "images-raw.cached.tar" ]
+        then
+          CACHED_IMG="$(realpath images-raw.cached.tar)"
+        else
+          CACHED_IMG=""
+        fi
+        RESULT=true
+
+        # cd to tmp dir as the rootfs the runner is running in might not support LFS
+        pushd "$(mktemp -d -p /dev/shm)"
+
+          # diff images from target platforms
+
+          for t in $TARGETS
+          do
+            tar -Sxf "$DL_DIR"/images-"$t".tar
+            if [ -z "$FIRST_TARGET" ]
+            then
+              FIRST_TARGET="$t"
+            fi
+          done
+
+          for t in $TARGETS
+          do
+            if [ "$FIRST_TARGET" = "$t" ]
+            then
+              continue
+            fi
+
+            "$DIFF_SCRIPT" "images-$FIRST_TARGET" "images-$t"
+          done
+
+          # re-tar the consolidated raw images
+
+          mv "images-$FIRST_TARGET" "images-raw"
+          tar -Scf images-raw.tar images-raw
+          IMG_TAR="$(realpath images-raw.tar)"
+
+          # diff against the cached last known good images (if exists)
+          if [ ! -z "$CACHED_IMG" ]
+          then
+            mkdir -p cached
+            pushd cached
+              tar -Sxf "$CACHED_IMG"
+            popd
+            if "$DIFF_SCRIPT" images-raw cached/images-raw
+            then
+              RESULT=false
+            fi
+          fi
+
+          # make VHDX images for Windows runners
+
+          mv images-raw images-vhdx
+          find images-vhdx -type f -iname '*.img' | while read img
+          do
+            vhdx_img="${img::-4}.vhdx"
+            qemu-img convert -f raw -O vhdx "$img" "$vhdx_img"
+            rm -f "$img"
+          done
+          tar -cf images-vhdx.tar images-vhdx
+          VHDX_TAR="$(realpath images-vhdx.tar)"
+        popd
+
+        mv "$IMG_TAR" .
+        mv "$VHDX_TAR" .
+        echo "result=$RESULT" >> "$GITHUB_OUTPUT"
+
+    # Always upload these for diagnosis.
+    - name: Upload consolidated raw images
+      uses: actions/upload-artifact@v7
+      with:
+        name: images-raw.tar
+        path: images-raw.tar
+    - name: Upload VHDX images
+      uses: actions/upload-artifact@v7
+      with:
+        name: images-vhdx.tar
+        path: images-vhdx.tar
+
+  test-windows-interop:
+    name: Test generated large sparse images on Windows runners
+    needs: check-images
+    if: needs.check-images.outputs.mkfs_differ == 'true'
     strategy:
       fail-fast: false
       matrix:
         os: [windows-2022, windows-latest]
-        name: [sparc, i686, x86_64]
     runs-on: ${{ matrix.os }}
     steps:
     - uses: actions/download-artifact@v8
       with:
-        name: images-${{ matrix.name }}.tar
+        name: images-vhdx.tar
     - shell: bash
       run: |
         set -e
 
-        tar -C /c -xf images-${{ matrix.name }}.tar
+        tar -C /c -xf images-vhdx.tar
 
-        for img in "/c/images-${{ matrix.name }}"/*/*/*.vhdx
+        for img in "/c/images-vhdx"/*/*/*.vhdx
         do
           img="$(echo "$img" | tr '/' '\\')"
           img="C:\\${img:3}"
 
           # mount the image and get the disk number assigned by the kernel
           disknum=$(powershell "Mount-DiskImage \"$img\" | Select-Object -ExpandProperty Number")
-          # assign it drive letter X
-          powershell "Get-Partition -DiskNumber $disknum -PartitionNumber 1 | Set-Partition -NewDriveLetter X"
+          # run chkdsk /f ...
+          powershell "Get-Partition -DiskNumber $disknum -PartitionNumber 1 | Repair-Volume -OfflineScanAndFix"
+          # dump some info
           powershell "Get-DiskImage \"$img\""
-
-          # simple sanity check
-          powershell 'chkdsk X: /f'
-          grep "$TEST_MAGIC" /x/a/b > /dev/null
-
           # unmount the image
           powershell "Dismount-DiskImage \"$img\"" > /dev/null
         done
+
+  cache-good-images:
+    name: Cache last known good images
+    needs: test-windows-interop
+    runs-on: ubuntu-26.04
+    steps:
+    - uses: actions/download-artifact@v8
+      with:
+        name: images-raw.tar
+    - run: mv images-raw.tar images-raw.cached.tar
+    - uses: actions/cache/save@v6
+      with:
+        path: images-raw.cached.tar
+        key: images-raw.cached.tar-${{ github.run_id }}
scripts/diff-images.py new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
2.56.0
#7 lore raw

PATCH 7/7 CI: remove stress test

In reply to David Timber

The stress test does not belong in exfatprogs because it tests the exfat fs implementation in Linux kernel, not implementation of exfatprogs. Also, the version of Linux kernel used cannot be controlled in CI.

---
 .github/workflows/c-cpp.yml | 44 -------------------------------------
 1 file changed, 44 deletions(-)
.github/workflows/c-cpp.yml +0 -44
index 106540f..33092a2 100644
@@ -328,50 +328,6 @@ jobs:
         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
-      run: |
-        set -e
-        sudo modprobe exfat
-        sudo mkdir -p /mnt/test
-        truncate -s 10G test.img
-        sudo losetup /dev/loop22 test.img
-        sudo ${{ matrix.run }} ./mkfs/mkfs.exfat -vfC /dev/loop22
-        sudo mount -t exfat /dev/loop22 /mnt/test/
-        pushd /mnt/test/
-        cat << EOF | sudo bash
-          set -e
-
-          for (( i = 0; i < 10000; i++ ))
-          do
-            touch file\$i
-          done
-          sync
-          find -mindepth 1 -delete
-          for (( i = 0; i < 10000; i++ ))
-          do
-            mkdir dir\$i
-          done
-          sync
-          find -mindepth 1 -delete
-
-          for (( i = 0; i < 10000; i++ ))
-          do
-            touch file\$i
-          done
-          for (( i = 0; i < 10000; i++ ))
-          do
-            mkdir dir\$i
-          done
-          sync
-        EOF
-        popd
-        sudo ${{ matrix.run }} ./fsck/fsck.exfat /dev/loop22
-        sudo find /mnt/test/ -mindepth 1 -delete
-        sudo umount /mnt/test/
-        sudo ${{ matrix.run }} ./fsck/fsck.exfat /dev/loop22
-        sudo losetup -d /dev/loop22
-        rm -f test.img
 
     - name: generate large images for Windows runners
       shell: bash
Signature · 1 line
2.56.0
maintainer Applied
#8 lore raw
In reply to David Timber
Quoted 51 lines · David Timber

This series addresses rather wasteful use of Github Actions runners. mkfs.exfat can now be run in a mode that doesn't involve any randomness (ie. deterministic) so that tests in the CI pipeline can expect volume images with the identical contents every time. Other randomness generated and tests unrelated to exfatprogs are removed. Moving forward, the CI pipelines should focus on testing exfatprogs code, not other external implementations like Linux kernel or Microsoft Windows.

In action:

1. https://github.com/dxdxdt/exfatprogs/actions/runs/42765932946/attempts/1
2. https://github.com/dxdxdt/exfatprogs/actions/runs/42765932946

On the first run, the generated images are consolidated and then tested on Windows runners. On the subsequent run, the cached images are restored and diff'd. The Windows runners are not run as the diff script reports that both cached and generated images are identical.

---

The series also includes a patch that fixes a minor endianness confusion in GPT structure creation code. This is only fixed to make the tests work and there should be no real-life impact whatsoever(the disk signature in protective MBR seems to be ignored by all OSes).

This series doesn't fix any serious bug and there are some memory errors and fsck stability issues reported by users so I wouldn't recommend releasing the features in a timely manner.

On removing the stress tests in CI:

I'm planning on building CI pipelines focusing on the Linux kernel fs implementation that involve snooping on the patches(https://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat.git/), running xfstests and publishing the result. I've already made a couple of repo mirrors using CI with other providers(just in case Github decides to go kaput overnight):

- https://codeberg.org/exfat-dev/exfatprogs-releases
- https://codeberg.org/exfat-dev/exfatprogs

The tests should also the cover cases that are specific to exFAT in addition to xfstests. That goes without saying.

The prototype will be hosted on a Github repo. However, I do strongly feel that the tests deserve to be run on real hardware including USB thumb drives, sdcards and external HDDs as they're the ones exFAT is usually used on.

Quoted 8 lines

David Timber (7):
README.md: update build prerequisite packages
lib: make exfat_parse_guid() library function
mkfs: add -i/--volume-serial, --disk-guid and --part-guid options
mkfs: set disk signature of protective MBR to zero
CI: add mkfs entropy test
CI: generate images in deterministic manner to reduce runtime
CI: remove stress test

Applied them to #exfat-next.
Thanks.