我正在编写内核模块(Linux中的C),我想更改其中的其他文件的权限.任何解决方案 因为我在内核中我不能使用chmod系统调用...并感谢您的帮助
这是我的Makefile:
> obj-m += ca.o
>
> all:
> make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
>
> clean:
> make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
> #include <linux/string.h>
> #include <linux/mm.h>
> /* Snip, tons of includes (all of them :))*/
> #include <linux/delay.h> .... int procfile_write(struct file *file,
> const char *buffer, unsigned long
> count,
> void *data) { ... sys_chmod(path, per); ... } ...
Run Code Online (Sandbox Code Playgroud)
当它发出警告时:
WARNING: "sys_chmod" [file] undefiened
当使用"sudo insmod"加载模块时,它会出现以下错误:
Unknown …
Linux中的内核函数是否会返回运行内核模块的物理内核和逻辑内核(在超线程的情况下)的数量?
我正在尝试为嵌入式设备创建简约的Linux.这意味着编译内核和驱动程序的必要性.一个驱动程序由它的创建者直接为设备的板写入,因此它不是存储库.它可以编译为内核模块.
但是由于Linux的不可变性以及对内存使用极少的要求,我不想使用模块.我想要内核中内置的所有驱动程序.所有提供内核的驱动程序都是这样设置的.
所以我的问题是如何将一个特殊的驱动程序编译到内核?
所有搜索都没有为我提供解决方案 - 所有这些只是关于编译为模块.
谢谢你的帮助.
我尝试在nasm中编写简单的内核模块(v3.6),但insmod说我:
$ sudo insmod ./hello.ko
insmod: ERROR: could not insert module ./hello.ko: Invalid module format
$ echo $?
1
Run Code Online (Sandbox Code Playgroud)
我编译我的代码:
$ nasm -f elf64 -o hello.m hello.asm
$ ld -m elf_x86_64 -r -o hello.ko hello.m
Run Code Online (Sandbox Code Playgroud)
和我的模块代码:
section .modinfo
__mod_kernel_version db "kernel_version=3.6.8", 0
__mod_license db "license=GPL", 0
__mod_author db "author=actics", 0
__mod_description db "description=hello world module in nasm", 0
section .data
init_mess db "init_module", 10, 0
cleanup_mess db "cleanup_module", 10, 0
section .text
global init_module
global cleanup_module
extern printk
init_module:
push …Run Code Online (Sandbox Code Playgroud) 我的操作系统Ubuntu 12.04.我写了这个内核模块,我使用insmod和rmmod命令,但/ var/log消息中没有任何内容.我该如何解决这个问题?
/*
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
Run Code Online (Sandbox Code Playgroud)
我试图了解内核中的异步中断处理,当然是通过传奇的了解Linux内核.
在这个过程中如何以及谁将触发内核中断处理程序?
我想帮助我纠正这个并澄清我的问题1)如何以及谁触发内核中断处理程序?2)如何定义新的或更改现有的硬件中断处理程序?
先感谢您!
美好的一天.我想创建两个(几乎相同)模块 - 每个模块使用netlink套接字并回复来自用户空间程序的传入消息.
在初始化第一个模块期间,它成功执行以下命令:
netlink kernel create(&init_net, NETLINK_USER, &cfg)
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用相同的参数启动第二个模块,则相同的命令将导致错误.
我认为发生此错误是因为两个模块的NETLINK_USER值相同 - 这就是为什么我无法为同一个netlink用户创建第二个套接字连接.但是,如果我尝试将NETLINK_USER值设置为32,则会出现内核错误.任何其他值 - 错误.
请告诉我,我需要做什么,以便同时使用两个内核模块?
我习惯于-std=c99在编译应用程序代码时使用c99功能.
最近我一直在关注一些基本的内核模块示例,并添加ccflags-y := -std=c99到makefile中.然而,当我尝试制作时,这导致17K行错误.gnu99工作得很好.
内核代码依赖的gnu99和c99有什么区别?
我在使用我的机器上构建任何内核模块时遇到问题.每当我构建一个模块时,modpost总是说零模块:
MODPOST 0 modules
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我编写了一个测试模块(hello.c):
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}
module_init(hello_start);
module_exit(hello_end);
Run Code Online (Sandbox Code Playgroud)
这是模块的Makefile:
obj-m = hello.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) clean
Run Code Online (Sandbox Code Playgroud)
当我在我的机器上构建它时,我得到以下输出:
make -C …Run Code Online (Sandbox Code Playgroud) 我正在为linux编写以太网网络驱动程序.我想接收数据包,编辑并重新发送它们.我知道如何在packet_interceptor函数中编辑数据包,但是如何在此函数中丢弃传入的数据包?
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <net/sock.h>
struct packet_type my_proto;
int packet_interceptor(struct sk_buff *skb,
struct net_device *dev,
struct packet_type *pt,
struct net_device *orig_dev) {
// I dont want certain packets go to upper in net_devices for further processing.
// How can I drop sk_buff here?!
return 0;
}
static int hello_init( void ) {
printk(KERN_INFO "Hello, world!\n");
my_proto.type = htons(ETH_P_ALL);
my_proto.dev = NULL;
my_proto.func = packet_interceptor;
dev_add_pack(&my_proto);
return 0;
}
static void hello_exit(void) {
dev_remove_pack(&my_proto);
printk(KERN_INFO …Run Code Online (Sandbox Code Playgroud) c network-programming netfilter kernel-module linux-device-driver
kernel-module ×10
linux-kernel ×6
kernel ×4
linux ×4
c ×3
assembly ×1
c99 ×1
compilation ×1
driver ×1
gcc ×1
gnu99 ×1
netfilter ×1
netlink ×1
sockets ×1
x86-64 ×1