小编don*_*don的帖子

cat函数无限次调用read()

我正在研究简单字符设备驱动程序。我已经在模块中实现了读取和写入功能,问题是当我尝试使用设备读取设备文件时,cat /dev/devicefile它将进入无限循环,即反复读取相同的数据。有人可以建议我解决这个问题吗?下面是我的驱动程序代码。

#include<linux/module.h>
#include<linux/fs.h>
#include<linux/string.h>
#include<asm/uaccess.h>
#include<linux/init.h>
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("character device driver");
MODULE_AUTHOR("Srinivas");

static char msg[100]={0};

static int t;

static int dev_open(struct inode *, struct file *);
static int dev_rls(struct inode *, struct file *);
static ssize_t dev_read(struct file *, char *,size_t, loff_t *);
static ssize_t dev_write(struct file *, const char *, size_t,loff_t *);

static struct file_operations fops =
{
    .read = dev_read,
    .open = dev_open,
    .write = dev_write,
    .release = dev_rls,
};
static int himodule( void )
{ …
Run Code Online (Sandbox Code Playgroud)

c linux-device-driver linux-kernel

1
推荐指数
1
解决办法
1935
查看次数

标签 统计

c ×1

linux-device-driver ×1

linux-kernel ×1