#!/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