mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-26 03:31:36 +01:00
Generalize module_version.c into module_info.c
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
.. link:params.c[]
|
.. link:params.c[]
|
||||||
.. link:vermagic.c[]
|
.. link:vermagic.c[]
|
||||||
.. link:vermagic_fail.c[]
|
.. link:vermagic_fail.c[]
|
||||||
.. link:module_version.c[]
|
.. link:module_info.c[]
|
||||||
. Pseudo filesystems
|
. Pseudo filesystems
|
||||||
.. link:debugfs.c[]
|
.. link:debugfs.c[]
|
||||||
.. link:procfs.c[]
|
.. link:procfs.c[]
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ static ssize_t write(struct file *filp, const char __user *buf, size_t len, loff
|
|||||||
pr_info("ko = %d\n", ret);
|
pr_info("ko = %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
pr_info("ok = %llu\n", res);
|
pr_info("ok = %llu\n", res);
|
||||||
*off= len;
|
*off= len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|||||||
32
kernel_module/module_info.c
Normal file
32
kernel_module/module_info.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
- https://stackoverflow.com/questions/4839024/how-to-find-the-version-of-a-compiled-kernel-module/42556565#42556565
|
||||||
|
- https://stackoverflow.com/questions/19467150/significance-of-this-module-in-linux-driver/49812248#49812248
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
insmod /module_info.ko
|
||||||
|
# dmesg => name = module_info
|
||||||
|
# dmesg => version = 1.0
|
||||||
|
cat /sys/module/module_info/version
|
||||||
|
# => module_info
|
||||||
|
modinfo /module_info.ko | grep -E '^version:'
|
||||||
|
# => version: 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
|
||||||
|
static int myinit(void)
|
||||||
|
{
|
||||||
|
/* Set by default based on the module file name. */
|
||||||
|
pr_info("name = %s\n", THIS_MODULE->name);
|
||||||
|
pr_info("version = %s\n", THIS_MODULE->version);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void myexit(void) {}
|
||||||
|
|
||||||
|
module_init(myinit)
|
||||||
|
module_exit(myexit)
|
||||||
|
MODULE_VERSION("1.0");
|
||||||
|
MODULE_LICENSE("GPL");
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
https://stackoverflow.com/questions/4839024/how-to-find-the-version-of-a-compiled-kernel-module/42556565#42556565
|
|
||||||
|
|
||||||
insmod /module_version.ko
|
|
||||||
cat /sys/modules/module_version/version
|
|
||||||
# => 1.0
|
|
||||||
cat /sys/module/module_version/srcversion
|
|
||||||
# => AB0F06618BC3A36B687CDC5
|
|
||||||
modinfo /module_version.ko | grep -E '^(src|)version'
|
|
||||||
# => version: 1.0
|
|
||||||
# => srcversion: AB0F06618BC3A36B687CDC5
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/kernel.h>
|
|
||||||
|
|
||||||
static int myinit(void)
|
|
||||||
{
|
|
||||||
pr_info(__FILE__ "\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void myexit(void) {}
|
|
||||||
|
|
||||||
module_init(myinit)
|
|
||||||
module_exit(myexit)
|
|
||||||
MODULE_VERSION("1.0");
|
|
||||||
MODULE_LICENSE("GPL");
|
|
||||||
Reference in New Issue
Block a user