mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 10:15:57 +01:00
Remove toplevel trash, add debugfs and kernel config fragment
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
obj-m += hello.o hello2.o
|
||||
obj-m += debugfs.o hello.o hello2.o
|
||||
ccflags-y := -Wno-declaration-after-statement -std=gnu99
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
45
kernel_module/package/kernel_module/src/debugfs.c
Normal file
45
kernel_module/package/kernel_module/src/debugfs.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Adapted from: https://github.com/chadversary/debugfs-tutorial/blob/47b3cf7ca47208c61ccb51b27aac6f9f932bfe0b/example1/debugfs_example1.c
|
||||
|
||||
Requires CONFIG_DEBUG_FS.
|
||||
|
||||
mkdir /debugfs
|
||||
mount -t debugfs none /sys/kernel/debug
|
||||
insmod /debugfs.ko
|
||||
cd /debugfs/kernel_module_cheat
|
||||
cat myfile
|
||||
|
||||
Output:
|
||||
|
||||
42
|
||||
*/
|
||||
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static struct dentry *dir = 0;
|
||||
static u32 value = 42;
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
struct dentry *file;
|
||||
dir = debugfs_create_dir("kernel_module_cheat", 0);
|
||||
if (!dir) {
|
||||
printk(KERN_ALERT "debugfs_create_dir failed");
|
||||
return -1;
|
||||
}
|
||||
file = debugfs_create_u32("myfile", 0666, dir, &value);
|
||||
if (!file) {
|
||||
printk(KERN_ALERT "debugfs_create_u32 failed");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cleanup_module(void)
|
||||
{
|
||||
debugfs_remove_recursive(dir);
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
/*
|
||||
Hello world module.
|
||||
|
||||
dmesg -c
|
||||
insmod hello.ko
|
||||
dmesg -c | grep 'hello init'
|
||||
rmmod hello.ko
|
||||
dmesg -c | grep 'hello cleanup'
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
|
||||
Reference in New Issue
Block a user