33#
44# This script creates a 4MB ext2 filesystem image with:
55# - Test files for filesystem testing
6- # - Coreutils binaries in /bin/ (cat, ls, echo, mkdir, rmdir, rm, cp, mv, true, false, head, tail, wc)
6+ # - Coreutils binaries in /bin/ (cat, ls, echo, mkdir, rmdir, rm, cp, mv, false, head, tail, wc, which)
7+ # - /sbin/true for PATH order testing
78# - hello_world binary for exec testing
89#
910# Requires Docker on macOS (or mke2fs on Linux).
@@ -25,7 +26,7 @@ TESTDATA_FILE="$PROJECT_ROOT/testdata/ext2.img"
2526SIZE_MB=4
2627
2728# Coreutils to install in /bin
28- COREUTILS=" cat ls echo mkdir rmdir rm cp mv true false head tail wc"
29+ COREUTILS=" cat ls echo mkdir rmdir rm cp mv true false head tail wc which "
2930
3031echo " Creating ext2 disk image..."
3132echo " Output: $OUTPUT_FILE "
@@ -71,12 +72,13 @@ if [[ "$(uname)" == "Darwin" ]]; then
7172 mkdir -p /mnt/ext2
7273 mount /work/ext2.img /mnt/ext2
7374
74- # Create /bin directory for coreutils
75+ # Create /bin and /sbin directories for coreutils
7576 mkdir -p /mnt/ext2/bin
77+ mkdir -p /mnt/ext2/sbin
7678
77- # Copy coreutils binaries
79+ # Copy coreutils binaries to /bin (excluding true which goes to /sbin)
7880 echo "Installing coreutils in /bin..."
79- for bin in cat ls echo mkdir rmdir rm cp mv true false head tail wc; do
81+ for bin in cat ls echo mkdir rmdir rm cp mv false head tail wc which ; do
8082 if [ -f /binaries/${bin}.elf ]; then
8183 cp /binaries/${bin}.elf /mnt/ext2/bin/${bin}
8284 chmod 755 /mnt/ext2/bin/${bin}
@@ -86,6 +88,16 @@ if [[ "$(uname)" == "Darwin" ]]; then
8688 fi
8789 done
8890
91+ # Install true in /sbin to test PATH lookup order
92+ echo "Installing binaries in /sbin..."
93+ if [ -f /binaries/true.elf ]; then
94+ cp /binaries/true.elf /mnt/ext2/sbin/true
95+ chmod 755 /mnt/ext2/sbin/true
96+ echo " /sbin/true installed"
97+ else
98+ echo " WARNING: true.elf not found in /binaries/"
99+ fi
100+
89101 # Copy hello_world for exec testing
90102 if [ -f /binaries/hello_world.elf ]; then
91103 cp /binaries/hello_world.elf /mnt/ext2/bin/hello_world
@@ -97,13 +109,34 @@ if [[ "$(uname)" == "Darwin" ]]; then
97109
98110 # Create test files for filesystem testing
99111 echo "Hello from ext2!" > /mnt/ext2/hello.txt
112+ echo "Truncate test file" > /mnt/ext2/trunctest.txt
113+ touch /mnt/ext2/empty.txt # Empty file for wc testing
100114 mkdir -p /mnt/ext2/test
101115 echo "Nested file content" > /mnt/ext2/test/nested.txt
102116
103117 # Create additional test content
104118 mkdir -p /mnt/ext2/deep/path/to/file
105119 echo "Deep nested content" > /mnt/ext2/deep/path/to/file/data.txt
106120
121+ # Create multi-line test file for head/tail/wc testing (15 lines)
122+ cat > /mnt/ext2/lines.txt << EOF
123+ Line 1
124+ Line 2
125+ Line 3
126+ Line 4
127+ Line 5
128+ Line 6
129+ Line 7
130+ Line 8
131+ Line 9
132+ Line 10
133+ Line 11
134+ Line 12
135+ Line 13
136+ Line 14
137+ Line 15
138+ EOF
139+
107140 # Show what was created
108141 echo ""
109142 echo "ext2 filesystem contents:"
@@ -143,12 +176,13 @@ else
143176 MOUNT_DIR=$( mktemp -d)
144177 mount " $OUTPUT_FILE " " $MOUNT_DIR "
145178
146- # Create /bin directory
179+ # Create /bin and /sbin directories
147180 mkdir -p " $MOUNT_DIR /bin"
181+ mkdir -p " $MOUNT_DIR /sbin"
148182
149- # Copy coreutils binaries
183+ # Copy coreutils binaries to /bin (excluding true which goes to /sbin)
150184 echo " Installing coreutils in /bin..."
151- for bin in cat ls echo mkdir rmdir rm cp mv true false head tail wc; do
185+ for bin in cat ls echo mkdir rmdir rm cp mv false head tail wc which ; do
152186 if [ -f " $USERSPACE_DIR /${bin} .elf" ]; then
153187 cp " $USERSPACE_DIR /${bin} .elf" " $MOUNT_DIR /bin/${bin} "
154188 chmod 755 " $MOUNT_DIR /bin/${bin} "
@@ -158,6 +192,16 @@ else
158192 fi
159193 done
160194
195+ # Install true in /sbin to test PATH lookup order
196+ echo " Installing binaries in /sbin..."
197+ if [ -f " $USERSPACE_DIR /true.elf" ]; then
198+ cp " $USERSPACE_DIR /true.elf" " $MOUNT_DIR /sbin/true"
199+ chmod 755 " $MOUNT_DIR /sbin/true"
200+ echo " /sbin/true installed"
201+ else
202+ echo " WARNING: true.elf not found"
203+ fi
204+
161205 # Copy hello_world for exec testing
162206 if [ -f " $USERSPACE_DIR /hello_world.elf" ]; then
163207 cp " $USERSPACE_DIR /hello_world.elf" " $MOUNT_DIR /bin/hello_world"
@@ -167,11 +211,32 @@ else
167211
168212 # Create test files
169213 echo " Hello from ext2!" > " $MOUNT_DIR /hello.txt"
214+ echo " Truncate test file" > " $MOUNT_DIR /trunctest.txt"
215+ touch " $MOUNT_DIR /empty.txt" # Empty file for wc testing
170216 mkdir -p " $MOUNT_DIR /test"
171217 echo " Nested file content" > " $MOUNT_DIR /test/nested.txt"
172218 mkdir -p " $MOUNT_DIR /deep/path/to/file"
173219 echo " Deep nested content" > " $MOUNT_DIR /deep/path/to/file/data.txt"
174220
221+ # Create multi-line test file for head/tail/wc testing (15 lines)
222+ cat > " $MOUNT_DIR /lines.txt" << EOF
223+ Line 1
224+ Line 2
225+ Line 3
226+ Line 4
227+ Line 5
228+ Line 6
229+ Line 7
230+ Line 8
231+ Line 9
232+ Line 10
233+ Line 11
234+ Line 12
235+ Line 13
236+ Line 14
237+ Line 15
238+ EOF
239+
175240 # Show what was created
176241 echo " "
177242 echo " ext2 filesystem contents:"
@@ -197,10 +262,11 @@ if [[ -f "$OUTPUT_FILE" ]]; then
197262 echo " "
198263 echo " Contents:"
199264 echo " /bin/cat, ls, echo, mkdir, rmdir, rm, cp, mv - file coreutils"
200- echo " /bin /true, false - exit status coreutils"
201- echo " /bin/head, tail, wc - text processing coreutils"
265+ echo " /sbin /true, /bin/ false - exit status coreutils"
266+ echo " /bin/head, tail, wc, which - text processing coreutils"
202267 echo " /bin/hello_world - exec test binary (exit code 42)"
203- echo " /hello.txt - test file"
268+ echo " /hello.txt - test file (1 line)"
269+ echo " /lines.txt - multi-line test file (15 lines) for head/tail/wc"
204270 echo " /test/nested.txt - nested test file"
205271 echo " /deep/path/to/file/data.txt - deep nested test file"
206272else
0 commit comments