首先在 Linux 下,视一切事物皆为文件,它同样把驱动设备也看成是文件,对于简单的文件操作,无非就是 open/close/read/write,在 Linux 对于文件的操作有一个关键的数据结构:file_operation,它的定义在源码目录下的 include/linux/fs.h 中,内容如下:

[cpp] view plain copy

1. struct file_operations {

2. struct module *owner;

3. loff_t (*llseek) (struct file *, loff_t, int);

4. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);

5. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);

6. ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);

7. ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);

8. int (*readdir) (struct file *, void *, filldir_t);

9. unsigned int (*poll) (struct file *, struct poll_table_struct *);

10. int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);

11. long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);

12. long (*compat_ioctl) (struct file *, unsigned int, unsigned long);

13. int (*mmap) (struct file *, struct vm_area_struct *);

14. int (*open) (struct inode *, struct file *);

15. int (*flush) (struct file *, fl_owner_t id);

16. int (*release) (struct inode *, struct file *);

17. int (*fsync) (struct file *, int datasync);

18. int (*aio_fsync) (struct kiocb *, int datasync);

19. int (*fasync) (int, struct file *, int);

20. int (*lock) (struct file *, int, struct file_lock *);

21. ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);

22. unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);

  • UC3846控制芯片工作原理控制图 逆变焊机原理与用途
  • 数字万用表电阻档测试二极管正反向没有阻值(使用万用表测量二极管的正向电阻,为什么各档)
  • 学单片机需要学数电模电吗(学单片机要先学数电模电吗)
  • 电工怎么选择适合自己用的万用表(电工初学者买什么样的万用表好)
  • 单片机需要同时运行多个任务怎么办(单片机怎么同时执行多个任务)
  • 电机保护的方案取决于负载的机械特性
  • 绝缘电阻表正负搭接不复零位是怎么回事
  • 短路怎么用万用表查