The Linux Kernel Module Programming Guide简译(二)续

王朝system·作者佚名  2006-01-09
宽屏版  字体: |||超大  

转载

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");

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有