本节用于介绍应用层和内核层数据传输
Linux一切皆文件!
文件对应的操作有打开,关闭,读写
设备节点对应的操作有打开,关闭,读写
1、如果我在应用层使用系统IO对设备节点进行打开,关闭,读写等操作会发生什么呢?
首先看一下文件操作集结构体,下面先选取我们常用的一部分
文件位置:include/linux/fs.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| struct file_operations { struct module *owner; ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); unsigned int (*poll) (struct file *, struct poll_table_struct *); long (*compat_ioctl) (struct file *, unsigned int, unsigned long); int (*open) (struct inode *, struct file *); int (*release) (struct inode *, struct file *); ... }
|

通过框图我们知道,设备节点用于连接应用层和内核层
2、假如我们的file_operations里面没有read,我们在应用层read设备节点的时候会发生什么?
什么也不会发生,也不会报错!
3、我们的应用层和内核层是不能直接进行数据传输的。
文件位置:include/linux/uaccess.h
1 2 3 4 5
| static __always_inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
static __always_inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
|