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:
@@ -3,7 +3,9 @@ set -e
|
||||
|
||||
# Setup
|
||||
f=/sys/kernel/debug/lkmc_fops
|
||||
insmod fops.ko
|
||||
mod="${1:-fops.ko}"
|
||||
shift
|
||||
insmod "$mod" "$@"
|
||||
|
||||
# read
|
||||
[ "$(cat "$f")" = abcd ]
|
||||
@@ -18,7 +20,7 @@ set +e
|
||||
printf 12345 > "$f"
|
||||
exit_status="$?"
|
||||
set -e
|
||||
[ "$exit_status" -eq 8 ]
|
||||
[ "$exit_status" -eq 1 ]
|
||||
[ "$(cat "$f")" = abcd ]
|
||||
|
||||
# seek
|
||||
@@ -26,5 +28,12 @@ printf 1234 > "$f"
|
||||
printf z | dd bs=1 of="$f" seek=2
|
||||
[ "$(cat "$f")" = 12z4 ]
|
||||
|
||||
# seek past the end
|
||||
printf 1234 > "$f"
|
||||
printf xy | dd bs=1 of="$f" seek=6
|
||||
[ "$(cat "$f")" = 1234 ]
|
||||
|
||||
# Teardown
|
||||
rmmod fops
|
||||
|
||||
echo passed
|
||||
|
||||
Reference in New Issue
Block a user