问题是“insmod成功”,但似乎没有执行入口函数“demo_init()”。 lsmod显示模块已成功加载,没有错误或警告。但是,我看不到“你好,世界!”在dmesg之后,并且没有设备节点“/ dev / demo_device”并且没有类“/ sys / class / demo_class”。我无法弄明白。 有人可以帮助我,谢谢。 内核版本是3.10.86。 系统Android。
这是我的代码:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/device.h>
int major;
static struct class *demo_class;
static struct device *demo_device;
static int demo_open(struct inode * inode, struct file * filp)
{
printk(KERN_ALERT "demo_open\n");
return 0;
}
static int demo_write(struct file * file, const char __user * buffer, size_t count, loff_t * ppos)
{
printk(KERN_ALERT "demo_write\n");
return 0;
}
static const struct file_operations demo_fops = {
.owner = THIS_MODULE,
.open = demo_open,
.write = demo_write,
};
static int __init demo_init(void) {
printk(KERN_ALERT "Hello, World!\n");
major = register_chrdev(0, "demo_drv", &demo_fops);
demo_class = class_create(THIS_MODULE, "demo_class");
demo_device = device_create(demo_class, NULL, MKDEV(major, 0), NULL, "demo_device");
return 0;
}
static void __exit demo_exit(void) {
printk(KERN_ALERT "Goodbye, World!\n");
unregister_chrdev(major, "demo_drv");
device_unregister(demo_device);
class_destroy(demo_class);
}
module_init(demo_init);
module_exit(demo_exit);
MODULE_VERSION("0.01");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_DESCRIPTION("A simple example Linux module.");