我正在尝试在内核2.6.21中进行新的系统调用
并且其中一个新系统调用使用'sys_write'函数,
但要使用此功能,我意识到我必须根据2.6.21版本安装内核头文件。
但我找不到内核头文件(2.6.21)
我尝试了apt-get install linux-headers-'uname -r'
,apt-cache search linux-headers-$(uname -r)
但我找不到任何东西..
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
#include <asm/uaccess.h>
int main(){
int fd;
int old_fs;
old_fs = get_fs();
set_fs(KERNEL_DS);
fd = sys_open("config.txt", O_RDONLY, 0);
if(fd >= 0)
sys_close(fd);
set_fs(old_fs);
return 0;
}
vv.c:2:24: error: linux/init.h: No such file or directory
vv.c:3:26: error: linux/module.h: No such file or directory
vv.c:4:28: error: linux/syscalls.h: No such file or directory
In file included from /usr/include/asm/fcntl.h:1,
from /usr/include/linux/fcntl.h:4,
from vv.c:5:
/usr/include/asm-generic/fcntl.h:120: error: expected specifier-qualifier-list before ‘off_t’
/usr/include/asm-generic/fcntl.h:143: error: expected specifier-qualifier-list before ‘loff_t’
vv.c:6:25: error: asm/uaccess.h: No such file or directory
vv.c: In function ‘main’:
vv.c:12: error: ‘KERNEL_DS’ undeclared (first use in this function)
vv.c:12: error: (Each undeclared identifier is reported only once
vv.c:12: error: for each function it appears in.)
另外,上面的头文件是我想要的。
如何获取内核头文件?
请帮帮我..
答案 0 :(得分:1)
安装标头是否完整?如果是这样,那么它们应该安装在/usr/include
中,并且你提供的include指令应该可以正常工作。
编辑:
首先运行:
sudo apt-get update
为确保您拥有最新的套餐,请:
sudo apt-get install linux-headers-$(uname -r)
这是一个应该包含Ubuntu中所有内核头文件的包。