The Linux Kernel Module Programming Guide簡譯(二)續

來源:互聯網
上載者:User
轉載
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");

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.