The Linux Kernel Module Programming Guide简译(二)续
sighofwraith 发表于 2005-6-24 16:48:39
2.5. Hello World (part 4): Licensing and Module Documentation
如果你是运行在2.4以后的内核上,你可能会在insmod模块的时候发现下面这样的话:
# insmod hello-3.o
Warning: loading hello-3.o will taint the kernel: no license
See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Hello, world 3
Module hello-3 loaded, with warnings
把代码的认证设置成GPL就可以了。这个认证机制都是在linux/module.h里面定义的。参考一下下面的代码就可以了。
Example 2-6. hello-4.c
/* hello-4.c - Demonstrates module documentation.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#define DRIVER_AUTHOR "Peiter Jay Salzman <p@dirac.org>"
#define DRIVER_DESC "A sample driver"
int init_hello_3(void);
void cleanup_hello_3(void);
static int init_hello_4(void)
{
printk(KERN_ALERT "Hello, world 4\n");
return 0;
}
static void cleanup_hello_4(void)
{
printk(KERN_ALERT "Goodbye, world 4\n");
}
module_init(init_hello_4);
module_exit(cleanup_hello_4);
/* You can use strings, like this:
*/
MODULE_LICENSE("GPL"); // Get rid of taint message by declaring code as GPL.
/* Or with defines, like this:
*/
MODULE_AUTHOR(DRIVER_AUTHOR); // Who wrote this module?
MODULE_DESCRIPTION(DRIVER_DESC); // What does this module do?
/* This module uses /dev/testdevice. The MODULE_SUPPORTED_DEVICE macro might be used in
* the future to help automatic configuration of modules, but is currently unused other
* than for documentation purposes.
*/
MODULE_SUPPORTED_DEVICE("testdevice");