blob: a2d9b45d1f062490ed52a6586b1802c2ac1abfa1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
|