aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authormanuel <manuel.bott@eps.ch>2026-11-22 01:06:22 +0000
committermanuel <manuel.bott@eps.ch>2026-11-22 01:06:22 +0000
commitd260c7339080e8c72224b68b93781139c297861f (patch)
tree1c40512c6b4257c0fdc7c1ec6a7168f0c2808758 /scripts
parentea79ee8e74f28f05803f458294f17fc873df2153 (diff)
downloadkernel-d260c7339080e8c72224b68b93781139c297861f.tar.xz
kernel-d260c7339080e8c72224b68b93781139c297861f.zip
kernel/filesystem: add bigger fat32 image to test and adjust teststest/fat32-real-imagefa26/develop
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/create_fat32_test_image.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/scripts/create_fat32_test_image.sh b/scripts/create_fat32_test_image.sh
new file mode 100755
index 00000000..a2d9b45d
--- /dev/null
+++ b/scripts/create_fat32_test_image.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+#
+# Create the fat32 image used by the fat32 driver tests (kernel/kernel/test_support/vfs/test_assets/fat32.img).
+#
+# The image is crafted to exercise the driver beyond a single file in the root directory:
+# - nested directories (/docs/sub) and ".." entries pointing to the root (cluster 0) and to a subdirectory
+# - a directory (/docs) with more entries than fit into one cluster, whose cluster chain is not contiguous
+# - deleted entries interleaved with live ones (every even tmpN.bin is deleted)
+# - files spanning multiple clusters (/docs/fragment.txt, /docs/sub/file2.txt, /longDirectoryName/longFileName.jpeg)
+# - long file name entries next to their 8.3 aliases (LONGDI~1, LONGFI~1.JPE)
+# - short names with the lowercase flags set (hello.txt, docs)
+#
+# The tests assert concrete cluster numbers and offsets of this image, so regenerating it requires updating
+# kernel/kernel/test_support/filesystems/fat32_image.hpp accordingly.
+#
+# Requires dosfstools (mkfs.fat) and mtools (mmd, mcopy, mdel).
+
+set -euo pipefail
+
+IMG="$(realpath -m "${1:-fat32.img}")"
+WORK_DIR="$(mktemp -d)"
+trap 'rm -rf "${WORK_DIR}"' EXIT
+cd "${WORK_DIR}"
+
+text() {
+ yes "Very important text document stored on fat32 drive." | head -c "$1"
+}
+
+dd if=/dev/zero of="${IMG}" bs=1M count=65 status=none
+mkfs.fat -F 32 -s 2 -n "TESTFAT" -i B50957CD "${IMG}" >/dev/null
+
+mmd -i "${IMG}" ::/docs
+mmd -i "${IMG}" ::/docs/sub
+mmd -i "${IMG}" ::/longDirectoryName
+
+echo "Hello World!" >hello.txt
+mcopy -i "${IMG}" hello.txt ::/
+
+# more than 32 entries, so that the directory has to grow into a second cluster
+for i in {1..36}; do
+ echo "tmp" >"tmp${i}.bin"
+ mcopy -i "${IMG}" "tmp${i}.bin" ::/docs
+done
+
+for i in {2..36..2}; do
+ mdel -i "${IMG}" "::/docs/tmp${i}.bin"
+done
+
+text 234 >fragment.txt
+mcopy -i "${IMG}" fragment.txt ::/docs
+
+text 11 >file.txt
+mcopy -i "${IMG}" file.txt ::/docs
+
+text 2345 >fragment.txt
+mcopy -o -i "${IMG}" fragment.txt ::/docs
+
+text 789 >file1.txt
+mcopy -i "${IMG}" file1.txt ::/docs/sub
+
+text 2345 >file2.txt
+mcopy -i "${IMG}" file2.txt ::/docs/sub
+
+text 2345 >longFileName.jpeg
+mcopy -i "${IMG}" longFileName.jpeg ::/longDirectoryName