电子工程专辑网站,wordpress optimize,广告推广怎么做,wordpress 图片失效以下读书笔记内容摘自宋宝华《Linux设备驱动开发详解》一书。
file_operations结构体在字符设备驱动的地位 file_operations结构体的定义 此结构体定义在x210kernel/include/linux/fs.h文件中。 struct file_operations {struct module *owner;loff_t (*llseek) (struct file …以下读书笔记内容摘自宋宝华《Linux设备驱动开发详解》一书。
file_operations结构体在字符设备驱动的地位 file_operations结构体的定义 此结构体定义在x210kernel/include/linux/fs.h文件中。 struct file_operations {struct module *owner;loff_t (*llseek) (struct file *, loff_t, int);ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);int (*readdir) (struct file *, void *, filldir_t);unsigned int (*poll) (struct file *, struct poll_table_struct *);int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);long (*compat_ioctl) (struct file *, unsigned int, unsigned long);int (*mmap) (struct file *, struct vm_area_struct *);int (*open) (struct inode *, struct file *);int (*flush) (struct file *, fl_owner_t id);int (*release) (struct inode *, struct file *);int (*fsync) (struct file *, int datasync);int (*aio_fsync) (struct kiocb *, int datasync);int (*fasync) (int, struct file *, int);int (*lock) (struct file *, int, struct file_lock *);ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);int (*check_flags)(int);int (*flock) (struct file *, int, struct file_lock *);ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);int (*setlease)(struct file *, long, struct file_lock **);
}; 1llseek()函数 用来修改一个文件的当前读写位置并将新位置返回。出错时这个函数返回一个负值。2read()函数 用来从设备中读取数据成功时函数返回读取的字节数出错时返回一个负值。它与用户空间应用程序中的size_t read(int fd,void* buf,size_t count)和size_t fread(void* ptr,size_t size,size_t nmemb,FILE* stream)。3write()函数 向设备发送数据成功时该函数返回写入的字节数。如果此函数未被实现当用户进行 write()系统调用时将得到-EINVAL 返回值。它与用户空间应用程序中的size_t write(int fd,const void* buf,size_t count)和size_t fwrite(……);4readdir()函数 仅用于目录设备节点不需要实现它。5ioctl()函数即IO控制函数 提供设备相关控制命令的实现既不是读操作也不是写操作当调用成功时返回给调用程序一个非负值。内核本身识别部分控制命令而不必调用设备驱动中的ioctl()。如果设备不提供 ioctl()函数对于内核不能识别的命令用户进行 ioctl()系统调用时将获得-EINVAL 返回值。它与用户空间应用程序中的int fcntl(……)和int ioctl(……)6mmap()函数 将设备内存映射到进程的内存中即进程的虚拟地址空间中如果设备驱动未实现此函数用户进行 mmap()系统调用时将获得-ENODEV 返回值。这个函数对于帧缓冲等设备特别有意义。帧缓冲被映射到用户空间后应用程序可以直接访问它而无需在内核与应用间进行内存复制。和用户空间应用程序中的void* mmap(……)函数对应。7poll()函数 一般用于询问设备是否可被非阻塞地立即读写。当询问的条件未触发时用户空间进行 select()和 poll()系统调用将引起进程的阻塞。8aio_read()和 aio_write()函数 分别对与文件描述符对应的设备进行异步读、写操作。设备实现这两个函数后用户空间可以对该设备文件描述符调用 aio_read()、aio_write()等系统调用进行读写。9open()函数 当用户空间调用 Linux API 函数 open()打开设备文件时设备驱动的 open()函数最终被调用。驱动程序可以不实现这个函数在这种情况下设备的打开操作永远成功。与 open()函数对应的是 release()函数。