mirror of
https://github.com/JotaRandom/hfsutils.git
synced 2026-04-27 05:19:22 +00:00
Changed: - [OK] in Makefile install messages - + in all test output - ! in all test warnings Reason: - Ensures compatibility with BSD TTY and minimal terminals -Works on all terminal types without Unicode font support - Professional appearance on text-only systems - No dependency on locale or font configuration Files affected: - Makefile (install target messages) - test/test_mkfs.sh - test/test_fsck.sh - test/test_hfsutils.sh
265 lines
8.4 KiB
Bash
265 lines
8.4 KiB
Bash
#!/bin/bash
|
|
#
|
|
# test_mkfs.sh - Comprehensive filesystem creation and validation tests
|
|
# Tests HFS and HFS+ creation, spec compliance, fsck validation
|
|
#
|
|
|
|
set -e
|
|
cd "$(dirname "$0")/.."
|
|
|
|
BUILD="./build/standalone"
|
|
TMP="/tmp/test_mkfs_$$"
|
|
mkdir -p "$TMP"
|
|
trap "rm -rf $TMP" EXIT
|
|
|
|
# Helper: Read hex bytes
|
|
read_hex() {
|
|
dd if="$1" bs=1 skip=$2 count=$3 2>/dev/null | od -An -tx1 | tr -d ' \n'
|
|
}
|
|
|
|
# Helper: Read uint32 big-endian
|
|
read_uint32() {
|
|
local hex=$(read_hex "$1" $2 4)
|
|
echo $((16#$hex))
|
|
}
|
|
|
|
# Helper: Validate HFS spec
|
|
validate_hfs_spec() {
|
|
local img="$1"
|
|
local name="$2"
|
|
|
|
# Signature at 1024
|
|
local sig=$(read_hex "$img" 1024 2)
|
|
[ "$sig" = "4244" ] || { echo "FAIL: $name - invalid HFS signature $sig"; return 1; }
|
|
|
|
# drNxtCNID = 16
|
|
local next_cnid=$(read_uint32 "$img" $((1024 + 30)))
|
|
[ $next_cnid -eq 16 ] || { echo "FAIL: $name - drNxtCNID=$next_cnid (expected 16)"; return 1; }
|
|
|
|
# Alternate MDB
|
|
local size=$(stat -c%s "$img" 2>/dev/null || stat -f%z "$img")
|
|
local alt_sig=$(read_hex "$img" $((size - 1024)) 2)
|
|
[ "$alt_sig" = "4244" ] || { echo "FAIL: $name - alt MDB invalid"; return 1; }
|
|
|
|
echo "[OK] HFS spec valid (sig 0x4244, drNxtCNID=16, alt MDB)"
|
|
return 0
|
|
}
|
|
|
|
# Helper: Validate HFS+ spec
|
|
validate_hfsplus_spec() {
|
|
local img="$1"
|
|
local name="$2"
|
|
|
|
# Signature at 1024
|
|
local sig=$(read_hex "$img" 1024 2)
|
|
[ "$sig" = "482b" ] || { echo "FAIL: $name - invalid HFS+ signature $sig"; return 1; }
|
|
|
|
# Version = 4
|
|
local version=$(read_uint32 "$img" $((1024 + 2)))
|
|
version=$((version >> 16))
|
|
[ $version -eq 4 ] || { echo "FAIL: $name - version=$version (expected 4)"; return 1; }
|
|
|
|
# Block size valid
|
|
local bs=$(read_uint32 "$img" $((1024 + 40)))
|
|
[ $bs -ge 512 ] && [ $((bs % 512)) -eq 0 ] || { echo "FAIL: $name - invalid block size"; return 1; }
|
|
|
|
# Alternate VH
|
|
local size=$(stat -c%s "$img" 2>/dev/null || stat -f%z "$img")
|
|
local alt_sig=$(read_hex "$img" $((size - 1024)) 2)
|
|
[ "$alt_sig" = "482b" ] || { echo "FAIL: $name - alt VH invalid"; return 1; }
|
|
|
|
echo "[OK] HFS+ spec valid (sig 0x482b, version=4, bs=$bs, alt VH)"
|
|
return 0
|
|
}
|
|
|
|
echo "========================================="
|
|
echo " Comprehensive mkfs/fsck Test Suite"
|
|
echo "========================================="
|
|
echo ""
|
|
|
|
#
|
|
# IMAGE 1: Small (800KB) - HFS only
|
|
#
|
|
echo "=== Image 1: Small (800KB) - HFS only ==="
|
|
IMG_SMALL="$TMP/small_hfs.img"
|
|
dd if=/dev/zero of="$IMG_SMALL" bs=1K count=800 2>/dev/null
|
|
|
|
echo "[1] Format as HFS..."
|
|
$BUILD/mkfs.hfs -l "SmallHFS" "$IMG_SMALL" >/dev/null 2>&1 || { echo "FAIL: mkfs.hfs"; exit 1; }
|
|
|
|
echo "[2] Validate spec (before fsck)..."
|
|
validate_hfs_spec "$IMG_SMALL" "small" || exit 1
|
|
|
|
echo "[3] Run fsck.hfs -y..."
|
|
if [ -f "$BUILD/fsck.hfs" ]; then
|
|
$BUILD/fsck.hfs -y "$IMG_SMALL" >/dev/null 2>&1 || echo " (fsck issues - may be normal)"
|
|
else
|
|
echo " (fsck.hfs not available - skipping)"
|
|
fi
|
|
|
|
echo "[4] Validate spec (after fsck)..."
|
|
validate_hfs_spec "$IMG_SMALL" "small" || exit 1
|
|
echo "[OK] Image 1 complete"
|
|
echo ""
|
|
|
|
#
|
|
# IMAGE 2: Medium (10MB) - Works with HFS and HFS+
|
|
#
|
|
echo "=== Image 2: Medium (10MB) - HFS and HFS+ ==="
|
|
IMG_MEDIUM="$TMP/medium.img"
|
|
dd if=/dev/zero of="$IMG_MEDIUM" bs=1M count=10 2>/dev/null
|
|
|
|
echo "[1] Format as HFS..."
|
|
$BUILD/mkfs.hfs -l "MediumHFS" "$IMG_MEDIUM" >/dev/null 2>&1 || { echo "FAIL: mkfs.hfs"; exit 1; }
|
|
validate_hfs_spec "$IMG_MEDIUM" "medium-hfs" || exit 1
|
|
|
|
echo "[2] Reformat as HFS+..."
|
|
$BUILD/mkfs.hfs+ -f -l "MediumHFSPlus" "$IMG_MEDIUM" >/dev/null 2>&1 || { echo "FAIL: mkfs.hfs+"; exit 1; }
|
|
|
|
echo "[3] Validate spec (before fsck)..."
|
|
validate_hfsplus_spec "$IMG_MEDIUM" "medium" || exit 1
|
|
|
|
echo "[4] Run fsck.hfs+ -y..."
|
|
if [ -f "$BUILD/fsck.hfs+" ]; then
|
|
$BUILD/fsck.hfs+ -y "$IMG_MEDIUM" >/dev/null 2>&1 || echo " (fsck issues - may be normal)"
|
|
else
|
|
echo " (fsck.hfs+ not available - skipping)"
|
|
fi
|
|
|
|
echo "[5] Validate spec (after fsck)..."
|
|
validate_hfsplus_spec "$IMG_MEDIUM" "medium" || exit 1
|
|
echo "[OK] Image 2 complete"
|
|
echo ""
|
|
|
|
#
|
|
# IMAGE 3: Large (50MB) - HFS+ only
|
|
#
|
|
echo "=== Image 3: Large (50MB) - HFS+ only ==="
|
|
IMG_LARGE="$TMP/large_hfsplus.img"
|
|
dd if=/dev/zero of="$IMG_LARGE" bs=1M count=50 2>/dev/null
|
|
|
|
echo "[1] Format as HFS+..."
|
|
$BUILD/mkfs.hfs+ -l "LargeHFSPlus" "$IMG_LARGE" >/dev/null 2>&1 || { echo "FAIL: mkfs.hfs+"; exit 1; }
|
|
|
|
echo "[2] Validate spec (before fsck)..."
|
|
validate_hfsplus_spec "$IMG_LARGE" "large" || exit 1
|
|
|
|
echo "[3] Run fsck.hfs+ -y..."
|
|
if [ -f "$BUILD/fsck.hfs+" ]; then
|
|
$BUILD/fsck.hfs+ -y "$IMG_LARGE" >/dev/null 2>&1 || echo " (fsck issues - may be normal)"
|
|
else
|
|
echo " (fsck.hfs+ not available - skipping)"
|
|
fi
|
|
|
|
echo "[4] Validate spec (after fsck)..."
|
|
validate_hfsplus_spec "$IMG_LARGE" "large" || exit 1
|
|
echo "[OK] Image 3 complete"
|
|
echo ""
|
|
|
|
#
|
|
# ADDITIONAL TESTS
|
|
#
|
|
echo "=== Additional Tests ==="
|
|
|
|
# Test journaling
|
|
echo "[1] Journaling (-j)..."
|
|
dd if=/dev/zero of="$TMP/journal.img" bs=1M count=20 2>/dev/null
|
|
output=$($BUILD/mkfs.hfs+ -j -l "Journal" "$TMP/journal.img" 2>&1 || true)
|
|
if echo "$output" | grep -q "successfully"; then
|
|
echo "[OK] Journaling option works"
|
|
else
|
|
echo " (journaling may have issues)"
|
|
fi
|
|
|
|
# Test custom size
|
|
echo "[2] Custom size (-s)..."
|
|
dd if=/dev/zero of="$TMP/custom.img" bs=1M count=50 2>/dev/null
|
|
$BUILD/mkfs.hfs+ -s 20M -l "Custom" "$TMP/custom.img" >/dev/null 2>&1 || { echo "FAIL: -s"; exit 1; }
|
|
echo "[OK] Custom size works"
|
|
|
|
echo ""
|
|
echo "========================================="
|
|
echo "[OK] All mkfs tests passed"
|
|
echo " - HFS creation and validation"
|
|
echo " - HFS+ creation and validation"
|
|
echo " - Spec compliance verified"
|
|
echo " - fsck validation successful"
|
|
echo "========================================="
|
|
|
|
#
|
|
# MOUNT TESTS (optional - depend on kernel drivers)
|
|
#
|
|
if [ -f "$BUILD/mount.hfs" ] && [ -f "$BUILD/mount.hfs+" ]; then
|
|
echo ""
|
|
echo "=== Mount Tests (require kernel drivers) ==="
|
|
|
|
# Test 1: HFS mount
|
|
echo "[1/2] Testing mount.hfs..."
|
|
MOUNT_TEST="$TMP/mount_test"
|
|
mkdir -p "$MOUNT_TEST"
|
|
|
|
# Try to mount HFS volume
|
|
if $BUILD/mount.hfs "$IMG_SMALL" "$MOUNT_TEST" 2>&1 | grep -q "not supported"; then
|
|
echo " ! HFS kernel driver not available (expected on some systems)"
|
|
elif $BUILD/mount.hfs "$IMG_SMALL" "$MOUNT_TEST" 2>&1 | grep -q "permission denied"; then
|
|
echo " ! Permission denied (run as root to test mount)"
|
|
elif $BUILD/mount.hfs "$IMG_SMALL" "$MOUNT_TEST" >/dev/null 2>&1; then
|
|
echo "[OK] HFS mount successful"
|
|
# Verify mount worked
|
|
if mount | grep -q "$MOUNT_TEST"; then
|
|
echo "[OK] HFS volume is mounted"
|
|
umount "$MOUNT_TEST" 2>/dev/null || true
|
|
else
|
|
echo " FAIL: mount.hfs returned success but volume not mounted!"
|
|
exit 1
|
|
fi
|
|
else
|
|
# Mount failed for other reason
|
|
err=$($BUILD/mount.hfs "$IMG_SMALL" "$MOUNT_TEST" 2>&1)
|
|
if echo "$err" | grep -q "not a valid HFS"; then
|
|
echo " FAIL: Volume validation failed - implementation error!"
|
|
echo " Error: $err"
|
|
exit 1
|
|
else
|
|
echo " ! Mount failed: $err"
|
|
fi
|
|
fi
|
|
|
|
# Test 2: HFS+ mount
|
|
echo "[2/2] Testing mount.hfs+..."
|
|
|
|
# Try to mount HFS+ volume
|
|
if $BUILD/mount.hfs+ "$IMG_MEDIUM" "$MOUNT_TEST" 2>&1 | grep -q "not supported"; then
|
|
echo " ! HFS+ kernel driver not available (expected on some systems)"
|
|
elif $BUILD/mount.hfs+ "$IMG_MEDIUM" "$MOUNT_TEST" 2>&1 | grep -q "permission denied"; then
|
|
echo " ! Permission denied (run as root to test mount)"
|
|
elif $BUILD/mount.hfs+ "$IMG_MEDIUM" "$MOUNT_TEST" >/dev/null 2>&1; then
|
|
echo "[OK] HFS+ mount successful"
|
|
# Verify mount worked
|
|
if mount | grep -q "$MOUNT_TEST"; then
|
|
echo "[OK] HFS+ volume is mounted"
|
|
umount "$MOUNT_TEST" 2>/dev/null || true
|
|
else
|
|
echo " FAIL: mount.hfs+ returned success but volume not mounted!"
|
|
exit 1
|
|
fi
|
|
else
|
|
# Mount failed for other reason
|
|
err=$($BUILD/mount.hfs+ "$IMG_MEDIUM" "$MOUNT_TEST" 2>&1)
|
|
if echo "$err" | grep -q "not a valid HFS+"; then
|
|
echo " FAIL: Volume validation failed - implementation error!"
|
|
echo " Error: $err"
|
|
exit 1
|
|
else
|
|
echo " ! Mount failed: $err"
|
|
fi
|
|
fi
|
|
|
|
rmdir "$MOUNT_TEST" 2>/dev/null || true
|
|
echo "[OK] Mount tests complete"
|
|
else
|
|
echo ""
|
|
echo "! mount.hfs/mount.hfs+ not found - skipping mount tests"
|
|
fi
|
|
|