新手上路
- 积分
- 31
- 金钱
- 31
- 注册时间
- 2022-10-11
- 在线时间
- 6 小时
|
13金钱
本帖最后由 susuquxuexi 于 2023-3-22 22:09 编辑
能成功的的代码:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#define CHRDEVBASE_MAJOR 4000
#define CHRDEVBASE_NAME "chardevbase"
/*
模块入出口
*/
static int __init chrdevbase_init(void)
{
return 0;
}
static void __exit chrdevbase_exit(void)
{
}
module_init(chrdevbase_init); //模块入口
module_exit(chrdevbase_exit); //模块出口
MODULE_AUTHOR("zyh");
MODULE_LICENSE("GPL");
报错的代码:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#define CHRDEVBASE_MAJOR 4000
#define CHRDEVBASE_NAME "chardevbase"
static int chrdevbase_open(struct inode *inode, struct file *file)
{
printk("chrdevbase_open\r\n");
return 0;
}
static int chrdevbase_release(struct inode *inode, struct file *file)
{
printk("chrdevbase_release\r\n");
return 0;
}
static ssize_t chrdevbase_write(struct file *file,
const char __user *user_buf, size_t count, loff_t *ppos)
{
printk("chrdevbase_write\r\n");
return 0;
}
static ssize_t chrdevbase_read(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos)
{
printk("chrdevbase_read\r\n");
return 0;
}
static const struct file_operations chrdevbase =
{
.owner = THIS_MODULE,
.open = chrdevbase_open,
.write = chrdevbase_write,
.read = chrdevbase_read ,
.release = chrdevbase_release,
};
/*
模块入出口
*/
static int __init chrdevbase_init(void)
{
int ret;
printk("chrdevbase_init");
ret = register_chrdev(CHRDEVBASE_MAJOR, CHRDEVBASE_NAME, &chrdevbase);
if(ret < 0){
printk("chrdevbase init error\r\n");
}
return 0;
}
static void __exit chrdevbase_exit(void)
{
printk("chrdevbase_exit");
unregister_chrdev(CHRDEVBASE_MAJOR, CHRDEVBASE_NAME);
}
module_init(chrdevbase_init); //模块入口
module_exit(chrdevbase_exit); //模块出口
MODULE_AUTHOR("zyh");
MODULE_LICENSE("GPL");
|
|