mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
kernel modules: add a quick scull port from LDD3
Also:
* fix fops.c on both kernels:
* 5.9: the out of space error code was 1 not 8
* 6.6: for whatever reason we can't read the user buffer as before on the
diagnostic print, it leads to segfault and oops
* create memfile.c which is like fops.c but of unlimited size
This commit is contained in:
51
rootfs_overlay/lkmc/memfile.sh
Executable file
51
rootfs_overlay/lkmc/memfile.sh
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# 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}"
|
||||
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
|
||||
Reference in New Issue
Block a user