当前位置: 技术问答>linux和unix
简单字符设备驱动实例, 为什么无法打开设备文件
来源: 互联网 发布时间:2016-12-14
本文导语: #include #include #include #include MODULE_LICENSE("GPL"); #define MAJOR_NUM 234 int globalvar_open(struct inode * ,struct file *); void globalvar_release(struct inode * ,struct file *) ; static ssize_t globalvar_read(struct file*, char*, size_t,loff_t*); static ssize_t glo...
#include
#include
#include
#include
MODULE_LICENSE("GPL");
#define MAJOR_NUM 234
int globalvar_open(struct inode * ,struct file *);
void globalvar_release(struct inode * ,struct file *) ;
static ssize_t globalvar_read(struct file*, char*, size_t,loff_t*);
static ssize_t globalvar_write(struct file*, const char*, size_t,loff_t*);
struct file_operations globalvar_fops =
{
open: globalvar_open,
release:globalvar_release,
read: globalvar_read,
write: globalvar_write
};
static int global_var = 0;
static int __init globalvar_init(void)
{
int ret;
ret = register_chrdev(MAJOR_NUM,"globalvar",&globalvar_fops);
if(ret)
{
printk("globalvar_init: ret == 1");
}
else
{
printk("globalvar_init: ret