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

博客围绕Linux模块展开,提到运行2.4以后内核,insmod模块时会有相关提示。指出将代码认证设置成GPL即可,认证机制在linux/module.h中定义,还给出示例代码hello - 4.c。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值