Skip to content

Commit d9b53cb

Browse files
authored
Merge pull request #91 from ryanbreen/feature/coreutils-to-ext2
feat(coreutils): install coreutils in ext2 /bin directory
2 parents 6c4f8f0 + 1c86d83 commit d9b53cb

File tree

12 files changed

+111
-40
lines changed

12 files changed

+111
-40
lines changed

scripts/create_ext2_disk.sh

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/bin/bash
22
# Create ext2 disk image for Breenix kernel testing
33
#
4-
# This script creates a 4MB ext2 filesystem image with test files.
4+
# This script creates a 4MB ext2 filesystem image with:
5+
# - Test files for filesystem testing
6+
# - Coreutils binaries in /bin/ (cat, ls, echo, mkdir, rmdir, rm, cp, mv)
7+
# - hello_world binary for exec testing
8+
#
59
# Requires Docker on macOS (or mke2fs on Linux).
610
#
711
# Usage:
@@ -15,15 +19,22 @@ set -e
1519
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1620
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
1721
TARGET_DIR="$PROJECT_ROOT/target"
22+
USERSPACE_DIR="$PROJECT_ROOT/userspace/tests"
1823
OUTPUT_FILE="$TARGET_DIR/ext2.img"
24+
TESTDATA_FILE="$PROJECT_ROOT/testdata/ext2.img"
1925
SIZE_MB=4
2026

27+
# Coreutils to install in /bin
28+
COREUTILS="cat ls echo mkdir rmdir rm cp mv"
29+
2130
echo "Creating ext2 disk image..."
2231
echo " Output: $OUTPUT_FILE"
2332
echo " Size: ${SIZE_MB}MB"
33+
echo " Coreutils: $COREUTILS"
2434

2535
# Ensure target directory exists
2636
mkdir -p "$TARGET_DIR"
37+
mkdir -p "$PROJECT_ROOT/testdata"
2738

2839
# Check if we're on macOS or Linux
2940
if [[ "$(uname)" == "Darwin" ]]; then
@@ -44,6 +55,7 @@ if [[ "$(uname)" == "Darwin" ]]; then
4455

4556
docker run --rm --privileged \
4657
-v "$TARGET_DIR:/work" \
58+
-v "$USERSPACE_DIR:/binaries:ro" \
4759
alpine:latest \
4860
sh -c '
4961
set -e
@@ -59,7 +71,31 @@ if [[ "$(uname)" == "Darwin" ]]; then
5971
mkdir -p /mnt/ext2
6072
mount /work/ext2.img /mnt/ext2
6173
62-
# Create test files
74+
# Create /bin directory for coreutils
75+
mkdir -p /mnt/ext2/bin
76+
77+
# Copy coreutils binaries
78+
echo "Installing coreutils in /bin..."
79+
for bin in cat ls echo mkdir rmdir rm cp mv; do
80+
if [ -f /binaries/${bin}.elf ]; then
81+
cp /binaries/${bin}.elf /mnt/ext2/bin/${bin}
82+
chmod 755 /mnt/ext2/bin/${bin}
83+
echo " /bin/${bin} installed"
84+
else
85+
echo " WARNING: ${bin}.elf not found in /binaries/"
86+
fi
87+
done
88+
89+
# Copy hello_world for exec testing
90+
if [ -f /binaries/hello_world.elf ]; then
91+
cp /binaries/hello_world.elf /mnt/ext2/bin/hello_world
92+
chmod 755 /mnt/ext2/bin/hello_world
93+
echo " /bin/hello_world installed"
94+
else
95+
echo " WARNING: hello_world.elf not found"
96+
fi
97+
98+
# Create test files for filesystem testing
6399
echo "Hello from ext2!" > /mnt/ext2/hello.txt
64100
mkdir -p /mnt/ext2/test
65101
echo "Nested file content" > /mnt/ext2/test/nested.txt
@@ -69,12 +105,17 @@ if [[ "$(uname)" == "Darwin" ]]; then
69105
echo "Deep nested content" > /mnt/ext2/deep/path/to/file/data.txt
70106
71107
# Show what was created
72-
echo "Files created:"
73-
find /mnt/ext2 -type f -exec ls -la {} \;
108+
echo ""
109+
echo "ext2 filesystem contents:"
110+
echo " Binaries in /bin:"
111+
ls -la /mnt/ext2/bin/ 2>/dev/null || echo " (none)"
112+
echo " Test files:"
113+
find /mnt/ext2 -type f -not -path "/mnt/ext2/bin/*" -exec ls -la {} \;
74114
75115
# Unmount
76116
umount /mnt/ext2
77117
118+
echo ""
78119
echo "ext2 image created successfully"
79120
'
80121
else
@@ -102,6 +143,28 @@ else
102143
MOUNT_DIR=$(mktemp -d)
103144
mount "$OUTPUT_FILE" "$MOUNT_DIR"
104145

146+
# Create /bin directory
147+
mkdir -p "$MOUNT_DIR/bin"
148+
149+
# Copy coreutils binaries
150+
echo "Installing coreutils in /bin..."
151+
for bin in cat ls echo mkdir rmdir rm cp mv; do
152+
if [ -f "$USERSPACE_DIR/${bin}.elf" ]; then
153+
cp "$USERSPACE_DIR/${bin}.elf" "$MOUNT_DIR/bin/${bin}"
154+
chmod 755 "$MOUNT_DIR/bin/${bin}"
155+
echo " /bin/${bin} installed"
156+
else
157+
echo " WARNING: ${bin}.elf not found"
158+
fi
159+
done
160+
161+
# Copy hello_world for exec testing
162+
if [ -f "$USERSPACE_DIR/hello_world.elf" ]; then
163+
cp "$USERSPACE_DIR/hello_world.elf" "$MOUNT_DIR/bin/hello_world"
164+
chmod 755 "$MOUNT_DIR/bin/hello_world"
165+
echo " /bin/hello_world installed"
166+
fi
167+
105168
# Create test files
106169
echo "Hello from ext2!" > "$MOUNT_DIR/hello.txt"
107170
mkdir -p "$MOUNT_DIR/test"
@@ -110,8 +173,10 @@ else
110173
echo "Deep nested content" > "$MOUNT_DIR/deep/path/to/file/data.txt"
111174

112175
# Show what was created
113-
echo "Files created:"
114-
find "$MOUNT_DIR" -type f -exec ls -la {} \;
176+
echo ""
177+
echo "ext2 filesystem contents:"
178+
ls -la "$MOUNT_DIR/bin/"
179+
find "$MOUNT_DIR" -type f -not -path "$MOUNT_DIR/bin/*" -exec ls -la {} \;
115180

116181
# Unmount and cleanup
117182
umount "$MOUNT_DIR"
@@ -120,16 +185,22 @@ else
120185
echo "ext2 image created successfully"
121186
fi
122187

123-
# Verify output
188+
# Copy to testdata/ for version control
124189
if [[ -f "$OUTPUT_FILE" ]]; then
190+
cp "$OUTPUT_FILE" "$TESTDATA_FILE"
125191
SIZE=$(ls -lh "$OUTPUT_FILE" | awk '{print $5}')
126192
echo ""
127-
echo "ext2 disk created: $OUTPUT_FILE"
193+
echo "ext2 disk created and copied to testdata/:"
194+
echo " $OUTPUT_FILE"
195+
echo " $TESTDATA_FILE"
128196
echo " Size: $SIZE"
129-
echo " Contents:"
130-
echo " /hello.txt - \"Hello from ext2!\""
131-
echo " /test/nested.txt - \"Nested file content\""
132-
echo " /deep/path/to/file/data.txt - \"Deep nested content\""
197+
echo ""
198+
echo "Contents:"
199+
echo " /bin/cat, ls, echo, mkdir, rmdir, rm, cp, mv - coreutils"
200+
echo " /bin/hello_world - exec test binary (exit code 42)"
201+
echo " /hello.txt - test file"
202+
echo " /test/nested.txt - nested test file"
203+
echo " /deep/path/to/file/data.txt - deep nested test file"
133204
else
134205
echo "Error: Failed to create ext2 image"
135206
exit 1

testdata/ext2.img

0 Bytes
Binary file not shown.

userspace/tests/Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -248,32 +248,32 @@ name = "cat"
248248
path = "cat.rs"
249249

250250
[[bin]]
251-
name = "ls_cmd"
252-
path = "ls_cmd.rs"
251+
name = "ls"
252+
path = "ls.rs"
253253

254254
[[bin]]
255-
name = "echo_cmd"
256-
path = "echo_cmd.rs"
255+
name = "echo"
256+
path = "echo.rs"
257257

258258
[[bin]]
259-
name = "mkdir_cmd"
260-
path = "mkdir_cmd.rs"
259+
name = "mkdir"
260+
path = "mkdir.rs"
261261

262262
[[bin]]
263-
name = "rm_cmd"
264-
path = "rm_cmd.rs"
263+
name = "rm"
264+
path = "rm.rs"
265265

266266
[[bin]]
267-
name = "rmdir_cmd"
268-
path = "rmdir_cmd.rs"
267+
name = "rmdir"
268+
path = "rmdir.rs"
269269

270270
[[bin]]
271-
name = "cp_cmd"
272-
path = "cp_cmd.rs"
271+
name = "cp"
272+
path = "cp.rs"
273273

274274
[[bin]]
275-
name = "mv_cmd"
276-
path = "mv_cmd.rs"
275+
name = "mv"
276+
path = "mv.rs"
277277

278278
[[bin]]
279279
name = "fork_memory_test"

userspace/tests/build.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ BINARIES=(
107107
"fs_block_alloc_test"
108108
"shell_pipe_test"
109109
# Coreutils
110-
"ls_cmd"
111-
"echo_cmd"
112-
"mkdir_cmd"
113-
"rmdir_cmd"
114-
"rm_cmd"
115-
"cp_cmd"
116-
"mv_cmd"
110+
"ls"
111+
"echo"
112+
"mkdir"
113+
"rmdir"
114+
"rm"
115+
"cp"
116+
"mv"
117117
)
118118

119119
echo "Building ${#BINARIES[@]} userspace binaries with libbreenix..."

userspace/tests/init_shell.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,37 +538,37 @@ static PROGRAM_REGISTRY: &[ProgramEntry] = &[
538538
},
539539
ProgramEntry {
540540
name: "ls",
541-
binary_name: b"ls_cmd\0",
541+
binary_name: b"ls\0",
542542
description: "List directory contents",
543543
},
544544
ProgramEntry {
545545
name: "mkdir",
546-
binary_name: b"mkdir_cmd\0",
546+
binary_name: b"mkdir\0",
547547
description: "Create directories",
548548
},
549549
ProgramEntry {
550550
name: "rmdir",
551-
binary_name: b"rmdir_cmd\0",
551+
binary_name: b"rmdir\0",
552552
description: "Remove empty directories",
553553
},
554554
ProgramEntry {
555555
name: "rm",
556-
binary_name: b"rm_cmd\0",
556+
binary_name: b"rm\0",
557557
description: "Remove files",
558558
},
559559
ProgramEntry {
560560
name: "cp",
561-
binary_name: b"cp_cmd\0",
561+
binary_name: b"cp\0",
562562
description: "Copy files",
563563
},
564564
ProgramEntry {
565565
name: "mv",
566-
binary_name: b"mv_cmd\0",
566+
binary_name: b"mv\0",
567567
description: "Move/rename files",
568568
},
569569
ProgramEntry {
570570
name: "echo",
571-
binary_name: b"echo_cmd\0",
571+
binary_name: b"echo\0",
572572
description: "Print arguments to stdout",
573573
},
574574
// === Network Tools ===

0 commit comments

Comments
 (0)