从文件 I/O 看 Linux 的虚拟文件系统
http://tech.ddvip.com 2008年04月15日 社区交流
内容摘要:本文在简要介绍 VFS 的相关数据结构后,以文件 I/O 为切入点深入 Linux 内核源代码,追踪了 sys_open 和 sys_read 两个系统调用的代码结构,并在追踪的过程中理清了跨文件系统的文件操作的基本原理和“一切皆是文件”的口号得以实现的根本。
2.2.5.2 和进程相关
清单6. 打开的文件集
struct files_struct {//打开的文件集
atomic_t count; /*结构的使用计数*/
……
int max_fds; /*文件对象数的上限*/
int max_fdset; /*文件描述符的上限*/
int next_fd; /*下一个文件描述符*/
struct file ** fd; /*全部文件对象数组*/
……
};
struct fs_struct {//建立进程与文件系统的关系
atomic_t count; /*结构的使用计数*/
rwlock_t lock; /*保护该结构体的锁*/
int umask; /*默认的文件访问权限*/
struct dentry * root; /*根目录的目录项对象*/
struct dentry * pwd; /*当前工作目录的目录项对象*/
struct dentry * altroot; /*可供选择的根目录的目录项对象*/
struct vfsmount * rootmnt; /*根目录的安装点对象*/
struct vfsmount * pwdmnt; /*pwd的安装点对象*/
struct vfsmount * altrootmnt;/*可供选择的根目录的安装点对象*/
};
2.2.5.3 和路径查找相关
清单7. 辅助查找
struct nameidata {
struct dentry *dentry; /*目录项对象的地址*/
struct vfsmount *mnt; /*安装点的数据*/
struct qstr last; /*路径中的最后一个component*/
unsigned int flags; /*查找标识*/
int last_type; /*路径中的最后一个component的类型*/
unsigned depth; /*当前symbolic link的嵌套深度,不能大于6*/
char *saved_names[MAX_NESTED_LINKS + 1];/
/*和嵌套symbolic link 相关的pathname*/
union {
struct open_intent open; /*说明文件该如何访问*/
} intent; /*专用数据*/
};
来源:ibm 作者:吴美清 责编:豆豆技术应用
- Linux/Unix 新闻
- Linux/Unix 入门
- Linux/Unix 命令
- Linux/Unix 安装
- Linux 嵌入式系统
- Linux/Unix 编程
- Linux/Unix 管理
- Linux/Unix 桌面
- Linux/Unix 内核
- Linux/Unix 软件
- SCO Unix
- NetBSD
- OpenBSD
- Redhat/Fedora Linux
- 手机
- Linux/Unix find 搜索命令
- Linux/Unix vi 命令
- Linux/Unix kde 桌面环境
- Linux/Unix GNOME 桌面环境
- Linux/Unix Make 命令
- Linux/Unix crontab 命令
- Linux/Unix ext3 文件系统
- Linux/Unix 文件系统详解
- Linux/Unix ADSL 拨号设置
- Linux/Unix GRUB 配置及应用
- Linux/Unix nfs配置
- Linux/Unix 硬件信息查看及管理
- Linux/Unix 优化
- Linux/Unix 交换分区Swap管理及应用
- Linux/Unix 用户管理
- Linux/Unix Ramdisk
- Linux/Unix 密码恢复管理
- Linux/Unix 文件删除恢复
- Linux/Unix fdisk分区
- Linux/Unix lvs负载均衡管理
- Linux/Unix root用户
- Linux/Unix 集群
- Linux/Unix 日志
- 更多Linux/Unix专题……