亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 979 | 回復(fù): 0
打印 上一主題 下一主題

How to compile kernel modules for the kernel 2.6 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2009-10-09 21:46 |只看該作者 |倒序?yàn)g覽

How to compile kernel modules for the kernel 2.6
HOWTO compile kernel modules for the kernel 2.6:


If you want to compile the sum-module (source mirrored below), follow these steps:

Create the Makefile in your directory with the sum-module.c


obj-m    := sum-module.o

KDIR    := /lib/modules/$(shell uname -r)/build
PWD    := $(shell pwd)

default:
       $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

Now do a

make

... and the sum-module.ko is built.

If you get something like this
# make
make: Nothing to be done for `default'.

you need to install the kernel source and compile the kernel first (run "make" at least to the point until all "HOSTCC scripts/" stuff is done - this will configure your kernel and allows external module compilation). Make sure /lib/modules/$(shell uname -r)/build points to your build directory (most likely /usr/src/linux...).
Another reason for the above error can be, that your browser converted the TAB before $(MAKE) to spaces. Make sure there is a TAB before $(MAKE).



Install it with install.sh:

#!/bin/sh
install -m 644 sum-module.ko /lib/modules/`uname -r`/kernel/drivers/sum-module.ko
/sbin/depmod -a

(adjust the /lib/modules path according to your needs)

Now make a
# modprobe sum-module


Or if you don't want to install the module, do this:
# insmod ./sum-module.ko


..and if your system doesn't freeze you've done it right ;-)

For kernel 2.4, the Makefile would look like this:
TARGET       := modulename
INCLUDE    := -I/lib/modules/`uname -r`/build/include
CFLAGS      := -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX
CC  := gcc

${TARGET}.o: ${TARGET}.c
       $(CC) $(CFLAGS) ${INCLUDE} -c ${TARGET}.c

(not yet tested)



sum-module source from: http://www.win.tue.nl/~aeb/linux/lk/lk-9.html


/*
* sum-module.c
# modprobe sum-module.o
# ls -l /proc/arith
total 0
dr-xr-xr-x    2 root     root            0 Sep 30 12:40 .
dr-xr-xr-x   89 root     root            0 Sep 30 12:39 ..
-r--r--r--    1 root     root            0 Sep 30 12:40 sum
# cat /proc/arith/sum
0
# echo 7 > /proc/arith/sum
# echo 5 > /proc/arith/sum
# echo 13 > /proc/arith/sum
# cat /proc/arith/sum
25
# rmmod sum-module
# ls -l /proc/arith
ls: /proc/arith: No such file or directory
#
*/

#include
#include
#include
#include


static unsigned long long sum;

static int show_sum(char *buffer, char **start, off_t offset, int length) {
        int size;

        size = sprintf(buffer, "%lld\n", sum);
        *start = buffer + offset;
        size -= offset;
        return (size > length) ? length : (size > 0) ? size : 0;
}

/* Expect decimal number of at most 9 digits followed by '\n' */
static int add_to_sum(struct file *file, const char *buffer,
                      unsigned long count, void *data) {
        unsigned long val = 0;
        char buf[10];
        char *endp;

        if (count > sizeof(buf))
                return -EINVAL;
        if (copy_from_user(buf, buffer, count))
                return -EFAULT;
        val = simple_strtoul(buf, &endp, 10);
        if (*endp != '\n')
                return -EINVAL;
        sum += val;     /* mod 2^64 */
        return count;
}

static int __init sum_init(void) {
        struct proc_dir_entry *proc_arith;
        struct proc_dir_entry *proc_arith_sum;

        proc_arith = proc_mkdir("arith", 0);
        if (!proc_arith) {
                printk (KERN_ERR "cannot create /proc/arith\n");
                return -ENOMEM;
        }
        proc_arith_sum = create_proc_info_entry("arith/sum", 0, 0, show_sum);
        if (!proc_arith_sum) {
                printk (KERN_ERR "cannot create /proc/arith/sum\n");
                remove_proc_entry("arith", 0);
                return -ENOMEM;
        }
        proc_arith_sum->write_proc = add_to_sum;
        return 0;
}

static void __exit sum_exit(void) {
        remove_proc_entry("arith/sum", 0);
        remove_proc_entry("arith", 0);
}

module_init(sum_init);
module_exit(sum_exit);
MODULE_LICENSE("GPL");


本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u3/104286/showart_2066614.html
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP