mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-22 17:55:57 +01:00
52 lines
913 B
Bash
Executable File
52 lines
913 B
Bash
Executable File
#!/bin/sh
|
|
set -eux
|
|
|
|
# Helpers
|
|
odraw() (
|
|
od -A n -t x1 -v "$@" | tr -d '\n' | cut -c 2-
|
|
)
|
|
|
|
# Setup
|
|
f=/sys/kernel/debug/lkmc_memfile
|
|
mod="${1:-memfile.ko}"
|
|
[ $# -gt 1 ] && shift
|
|
insmod "$mod" "$@"
|
|
|
|
# Starts off empty
|
|
[ -z "$(cat "$f")" ]
|
|
|
|
# write and check it is there
|
|
printf 12 > "$f"
|
|
[ 12 = "$(cat "$f")" ]
|
|
|
|
# Append and check that it is there
|
|
printf 34 >> "$f"
|
|
[ 1234 = "$(cat "$f")" ]
|
|
|
|
# Restart
|
|
printf 56 > "$f"
|
|
[ 56 = "$(cat "$f")" ]
|
|
|
|
# skip
|
|
printf 1234 > "$f"
|
|
[ 23 = "$(dd if="$f" bs=1 count=2 skip=1)" ]
|
|
|
|
# seek
|
|
printf 1234 > "$f"
|
|
printf xy | dd bs=1 of="$f" seek=1 conv=notrunc
|
|
[ 1xy4 = "$(cat "$f")" ]
|
|
|
|
# seek past the end
|
|
printf 1234 > "$f"
|
|
printf xy | dd bs=1 of="$f" seek=6 conv=notrunc
|
|
[ '31 32 33 34 00 00 78 79' = "$(odraw "$f")" ]
|
|
|
|
# Allocate 1 GB for fun.
|
|
dd if=/dev/zero of="$f" bs=1k count=1M
|
|
[ '00 00' = "$(dd if="$f" bs=1 count=2 skip=500M | odraw)" ]
|
|
|
|
# Teardown
|
|
rmmod memfile
|
|
|
|
echo passed
|