[linux device driver] Chapter 03:scullc_open理解
2015-02-27 22:27
429 查看
在阅读源代码时,到scullc_open的时候,有的地方不是很好理解。记录思考的过程,便于以后查找。
scullc_open源码如下:
在上面的代码中,filp->f_flags & O_ACCMODE是为了获得f_flags低2位,然后判断文件的属性是什么样的,具体如下:
有三类属性:只读、只写、可读可写。
最后调用scullc_trim(dev)。
scullc_open源码如下:
int scullc_open (struct inode *inode, struct file *filp) { struct scullc_dev *dev; /* device information */ /* Find the device */ dev = container_of(inode->i_cdev, struct scullc_dev, cdev); /* now trim to 0 the length of the device if open was write-only */ if ( (filp->f_flags & O_ACCMODE) == O_WRONLY) { if (down_interruptible (&dev->sem)) return -ERESTARTSYS; scullc_trim(dev); /* ignore errors */ up (&dev->sem); } /* and use filp->private_data to point to the device data */ filp->private_data = dev; return 0; /* success */ }
在上面的代码中,filp->f_flags & O_ACCMODE是为了获得f_flags低2位,然后判断文件的属性是什么样的,具体如下:
#define O_ACCMODE 0003 #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02
有三类属性:只读、只写、可读可写。
最后调用scullc_trim(dev)。
相关文章推荐
- [linux device driver] Chapter 03:scull_load脚本理解
- [linux device driver] Chapter 03:IS_ERR的理解
- [linux device driver] Chapter 03:从scull_load了解awk
- [linux device driver] Chapter 03:make输出重定向
- [linux device driver] Chapter 14:kobject_init的理解
- [linux device driver] Chapter 03:以scull_load为例,详解mknod命令
- [linux device driver] Chapter 03:以scull_load为引,详解shell逻辑运算、基本运算、位运算
- [linux device driver] Chapter 03:以scull_load为例,讲解bash中反单引号`、双引号等的作用
- [linux device driver]Chapter 03:scull_load中涉及到的bash命令 exit
- [linux device driver]Chapter 03:Scull_load中涉及到的群组权限之staff\wheel
- [linux device driver] Chapter 03:从scull_load学习小括号,中括号,和大括号的区别
- [linux device driver] Chapter 03:字符设备注册学习
- [linux device driver] Chapter 03:以scull_load为引,详解Bash的位置参数和内部参数
- [linux device driver] Chapter 04:Magic SysRq Key
- 深入理解Linux内核 Chapter1 introduction
- 深入理解Linux内核 Memory Addressing Chapter-2
- 用OpenJTAG烧写程序到Flash—— 韦东山嵌入式Linux视频学习笔记03
- [linux device driver] Chapter 04:使用/proc文件系统查询调试
- 《王保明老师----Linux开发学习笔记》------讲03:进程 -----fork( )函数的一点理解
- Linux系统函数open和close(03)---open函数的参数