/*
改进:读写时,新添加了利用llseek()函数,修改偏移量属性
*/
/*
对设备属性进行了封装,读写时重要的改变
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/errno.h>
#include <linux/slab.h>
#define P_DEBUG(fmt, args...) printk("<kernel>[%s]:"fmt, __FUNCTION__, ##args)
#define DEVSIZE 512
//将设备属性封装成一个结构体,表示一个字符设备
struct test_dev_t {
char kbuf[DEVSIZE];
int curr_size;
int major;
int minor;
dev_t devno;
struct cdev test_cdev;
}*dev;
/*
static dev_t devno;
static int major = 0;
static int minor = 0;
struct cdev test_cdev;
*/
//设备驱动的操作方法
static int test_open(struct inode *,struct file *);
static int test_close(struct inode *,struct file *);
static ssize_t test_read(struct file *, char __user *, size_t , loff_t *);
static ssize_t test_write(struct file *, const char __user *, size_t, lof
字符设备(3)lseek
最新推荐文章于 2023-05-21 12:19:37 发布