假设模块的源文件为hello.c,源码如下:
#include
#include
#include
#include
#include
#define HELLO_MAJOR 231
#define DEVICE_NAME "HelloModule"
static int hello_open(struct inode *inode, struct file *file)
{
printk(KERN_EMERG "hello open.\n");
return 0;
}
static ssize_t hello_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
printk(KERN_EMERG "hello write.\n");
return 0;
}
static struct file_operations hello_flops = {
.owner = THIS_MODULE,
.open = hello_open,
.write = hello_write,
};
static int __init hello_init(void)
{
int ret;
ret = register_chrdev(HELLO_MAJOR, DEVICE_NAME, &hello_flops);
if (r