/***********************************************************************************
*
* volatile,container_of,file_operations,file,inode
*
* 声明:
* 1. 本系列文档是在vim下编辑,请尽量是用vim来阅读,在其它编辑器下可能会
* 不对齐,从而影响阅读.
* 2. 本文的结构体的注释主要是参考网络上的解释,几乎无任何个人理解,主要是为后续
* 代码编辑提供参考.
**********************************************************************************/
\\\\\\\--*目录*--//////////////
| 一. volatile修饰字段:
| 二. container_of:
| 三. 驱动错误返回值:
| 四. struct file_operations注释:
| 五. struct file注释:
| 六. struct inode注释:
\\\\\\\\\///////////////////
一. volatile修饰字段:
告诉gcc不要对该类型的数据做优化处理,对它的访问都是对内存的访问,而不是对寄存器的访问.
二. container_of:
1. container_of定义:
#define __offset(type, mem)
((unsigned long)&(((type *)0)->mem))
#define container_of(addr, type, mem)
((type *)((void *)addr - __offset(type, mem)))
2. container_of使用:
static int test_open(struct inode *inode, struct file *file)
{
test_t *p;
p = container_of(file->f_op, test_t, fops);
file->private_data = p;
return 0;
}
三. 驱动错误返回值:
#ifnder _ASM_GENERIC_ERRNO_BASE_H
#define _ASM_GENERIC_ERRNO_BASE_H
#define EPERM 1 /* Operation not permitted --> 操作不允许 */
#define ENOENT 2 /* No such file or directory --> 找不到对应文件或文件夹 */
#define ESRCH 3 /* No such process --> 找不到对应的进程 */
#define EINTR 4 /* Interrupted system call --> 被系统调用中断 */
#define EIO 5 /* I/O error --> IO错误 */
#define ENXIO 6 /* No such device or address --> 找不到对应的设备或者地址 */
#define E2BIG 7 /* Argument list too long --> 参数列表太长 */
#define ENOEXEC 8 /* Exec format error --> 执行格式错误 */
#define EBADF 9 /* Bad file number --> 错误的文件数 */
#define ECHILD 10 /* No child processes --> 没有子进程 */
#define EAGAIN 11 /* Try again --> 重新调用该函数调用 */
#define ENOMEM 12 /* Out of memory --> 内存溢出 */
#define EACCES 13 /* Permission denied --> 权限被拒绝 */
#define EFAULT 14 /* Bad address --> 错误地址 */
#define ENOTBLK 15 /* Block device required --> 需要块设备 */
#define EBUSY 16 /* Device or resource busy --> 设备或者资源正在被使用 */
#define EEXIST 17 /* File exists --> 文件已经存在 */
#define EXDEV 18 /* Cross-device link --> 交叉设备链接 */
#define ENODEV 19 /* No such device --> 找不到设备 */
#define ENOTDIR 20 /* Not a directory --> 不是一个目录 */
#define EISDIR 21 /* Is a directory --> 是一个目录 */
#define EINVAL 22 /* Invalid argument --> 非法的参数 */
#define ENFILE 23 /* File table overflow --> 文件表溢出 */
#define EMFILE 24 /* Too many open files --> 打开太多的文件 */
#define ENOTTY 25 /* Not a typewriter --> 不是设备命令 */
#define ETXTBSY 26 /* Text file busy --> 文本文件忙 */
#define EFBIG 27 /* File too large --> 文件太大 */
#define ENOSPC 28 /* No space left on device --> 设备空间不足 */
#define ESPIPE 29 /* Illegal seek --> 非法的偏移 */
#define EROFS 30 /* Read-only file system --> 只读文件系统 */
#define EMLINK 31 /* Too many links --> 链接太多 */
#define EPIPE 32 /* Broken pipe --> 损坏的管道 */
#define EDOM 33 /* Math argument out of domain of func --> 数字参数超出函数域 */
#define ERANGE 34 /* Math result not representable --> 数字结果不能表示 */
#endif
四. struct file_operations注释:
struct file_operations {
/* 指向拥有这个结构模块的指针,当模块被使用时,阻止模块被卸载,它被简单初始化为THIS_MODULE */
struct module *owner;
上一篇:Samsung_tiny4412(驱动笔记05)----Makefile,open,read,write,lseek,poll,ioctl,fasync
下一篇:Samsung_tiny4412(驱动笔记03)----字符设备驱动基本操作及调用流程
推荐阅读最新更新时间:2026-03-25 11:00
- 用于 7VIN 至 16VIN、1.5V 和 1.2V 输出的 LTM4628EV DC/DC 模块稳压器的典型应用电路
- 使用 Analog Devices 的 LTC3728LIGN 的参考设计
- DER-406 - 适用于 A19 灯的 5.76 W 高 PF 非隔离降压-升压型 TRIAC 调光 LED 驱动器
- ADR5045B 5V 输出精密微功率并联模式电压基准的典型应用
- LT3970EDDB-3.42 2.5V 降压转换器的典型应用
- MC78M08BDTG 8V 电流调节器的典型应用
- LT1021DCN8-5 精密电压基准的典型应用
- DER-282 - 100W, 扁平(11 mm), LLC DC-DC转换器
- REF193 低压差开尔文连接电压基准的典型应用电路
- LT3088EM 线性稳压器用于添加软启动的典型应用



Linux内核驱动笔记
三星2410开发板ALLEGRO BRD原文件
非常经典的关于LLC的杨波博士论文
XC6406PP60DL






京公网安备 11010802033920号