apue中:其中进程表项内部的数组又称为 进程打开文件表   

另外一个角度:

从linux内核角度开:

task_struct是进程描述符对应上面的进程表项,在task_struct描述符中有struct file_struct*类型的变量file,指向struct file_struct结构。

1.file_struct:该结构体有进程描述符中的files域指向,如下:

struct files_struct {

        atomic_t    count;              /* structure's usage count */

        spinlock_t  file_lock;          /* lock protecting this structure */

        int         max_fds;            /* maximum number of file objects */

        int         max_fdset;          /* maximum number of file descriptors */

        int         next_fd;            /* next file descriptor number */

        struct file **fd;               /* array of all file objects */

        fd_set      *close_on_exec;     /* file descriptors to close on exec() */

        fd_set      *open_fds;           /* pointer to open file descriptors */

        fd_set      close_on_exec_init; /* initial files to close on exec() */

        fd_set      open_fds_init;      /* initial set of file descriptors */

        struct file *fd_array[NR_OPEN_DEFAULT]; /* default array of file objects */

};

该结构中有一个struct file *fd_array[NR_OPEN_DEFAULT]的数组,对应上面的进程打开文件表,其数组的元素指向struct file 结构,此结构对应apue中的文件表
2、文件对象:文件对象表示进程以打开的文件。文件对象仅仅在进程观点上代表已打开文件,它反过来指向目录项对象(反过来指向索引节点),其实只有目录项对象才表示已打开的实际文件。虽然一个文件对应的文件对象不是唯一的,但对应的索引节点和目录项对象无疑是唯一的。文件对象由file结构表示,定义在文件linux/fs.h中,如下:

struct file {

        struct list_head       f_list;        /* list of file objects */

        struct dentry          *f_dentry;     /* associated dentry object */

        struct vfsmount        *f_vfsmnt;     /* associated mounted fs */

        struct file_operations *f_op;         /* file operations table */

        atomic_t               f_count;       /* file object's usage count */

        unsigned int           f_flags;       /* flags specified on open */

        mode_t                 f_mode;        /* file access mode */

        loff_t                 f_pos;         /* file offset (file pointer) */

        struct fown_struct     f_owner;       /* owner data for signals */

        unsigned int           f_uid;         /* user's UID */

        unsigned int           f_gid;         /* user's GID */

        int                    f_error;       /* error code */

        struct file_ra_state   f_ra;          /* read-ahead state */

        unsigned long          f_version;     /* version number */

        void                   *f_security;   /* security module */

        void                   *private_data; /* tty driver hook */

        struct list_head       f_ep_links;    /* list of eventpoll links */

        spinlock_t             f_ep_lock;     /* eventpoll lock */

        struct address_space   *f_mapping;    /* page cache mapping */

};

文件表项中包括了文件描述符的状态标志,文件的偏移量(或者说文件的位置),和v节点指针(unix独有)

struct file 包括我们通常说的文件描述符引用计数,文件偏移量,文件模式等等以系列核心功能,同时又指向文件file_operation结构的指针

struct file_operations {

        struct module *owner;

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

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

        ssize_t (*aio_read) (struct kiocb *, char *, size_t, loff_t);

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

        ssize_t (*aio_write) (struct kiocb *, const char *, size_t, loff_t);

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

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

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

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

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

        int (*flush) (struct file *);

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

        int (*fsync) (struct file *, struct dentry *, int);

        int (*aio_fsync) (struct kiocb *, int);

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

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

        ssize_t (*readv) (struct file *, const struct iovec *,

                          unsigned long, loff_t *);

        ssize_t (*writev) (struct file *, const struct iovec *,

                           unsigned long, loff_t *);

        ssize_t (*sendfile) (struct file *, loff_t *, size_t,

                             read_actor_t, void *);

        ssize_t (*sendpage) (struct file *, struct page *, int,

                             size_t, loff_t *, int);

        unsigned long (*get_unmapped_area) (struct file *, unsigned long,

                                            unsigned long, unsigned long,

                                            unsigned long);

        int (*check_flags) (int flags);

        int (*dir_notify) (struct file *filp, unsigned long arg);

        int (*flock) (struct file *filp, int cmd, struct file_lock *fl);

};

struct file包括指向struct dentry 的指针

struct dentry {

        atomic_t                 d_count;      /* usage count */

        unsigned long            d_vfs_flags;  /* dentry cache flags */

        spinlock_t               d_lock;       /* per-dentry lock */

        struct inode             *d_inode;     /* associated inode */

        struct list_head         d_lru;        /* unused list */

        struct list_head         d_child;      /* list of dentries within */

        struct list_head         d_subdirs;    /* subdirectories */

        struct list_head         d_alias;      /* list of alias inodes */

        unsigned long            d_time;       /* revalidate time */

        struct dentry_operations *d_op;        /* dentry operations table */

        struct super_block       *d_sb;        /* superblock of file */

        unsigned int             d_flags;      /* dentry flags */

        int                      d_mounted;    /* is this a mount point? */

        void                     *d_fsdata;    /* filesystem-specific data */

        struct rcu_head          d_rcu;        /* RCU locking */

        struct dcookie_struct    *d_cookie;    /* cookie */

        struct dentry            *d_parent;    /* dentry object of parent */

        struct qstr              d_name;       /* dentry name */

        struct hlist_node        d_hash;       /* list of hash table entries */

        struct hlist_head        *d_bucket;    /* hash bucket */

        unsigned char            d_iname[DNAME_INLINE_LEN_MIN]; /* short name */

};

由于目录项并非真正保存在磁盘上,所有目录项没有对应的磁盘数据结构,VFS根据字符串形式的路径名现场创建它,目录项结构体也没有是否被修改的标志。目录项对象有三种状态:被使用,未被使用和负状态。一个被使用的目录项对应一个有效的索引节点(即d_inode指向相应的索引节点)并且该对象存在一个或多个使用者(即d_count为正值)。一个未被使用的目录项对应一个有效的索引节点(d_inode指向一个索引节点),但是VFS当前并未使用它(d_count为0)。该目录项对象仍然指向一个有效对象,而且被保留在内存中以便需要时再使用它。显然这样要比重新创建要效率高些。一个负状态的目录项没有对应的有效索引节点(d_inode为NULL).因为索引节点已被删除了,或路径不再正确了,但是目录项仍然保留,以便快速解析以后的路径查询。虽然负的状态目录项有些用处,但如果需要的话话,还是可以删除的,可以销毁它。

只是路径对应的innode节点

linux文件系统总结的更多相关文章

  1. linux文件系统体系结构 和 虚拟文件系统(VFS)

    图 1. Linux 文件系统组件的体系结构 用户空间包含一些应用程序(例如,文件系统的使用者)和 GNU C 库(glibc),它们为文件系统调用(打开.读取.写和关闭)提供用户接口.系统调用接口的 ...

  2. Linux文件系统

    今天学习了Linux文件系统,现在来做个小总结. 首先Linux中一切都是文件,下面这个清单是Linux系统的顶层目录结构. 清单 1. Linux 系统的顶层目录结构 / 根目录 ├── bin 存 ...

  3. linux 文件系统简介

    linux文件系统简介   文件系统是linux的一个十分基础的知识,同时也是学习linux的必备知识. 本文将站在一个较高的视图来了解linux的文件系统,主要包括了linux磁盘分区和目录.挂载基 ...

  4. Linux文件系统层次结构标准

    该标准的目的是定义Linux文件系统的标准路径,使得开发者和用户可以在合理的位置找到需要的东西. Linux的文件布局的大体想法是将文件和目录分为如下3组: 对运行Linux的某一特定系统唯一的文件和 ...

  5. linux文件系统节点详解

    linux文件系统有两层结构,逻辑结构和物理结构.也就是inode和block. 每个文件都有一个inode, 记录文件属性:权限,时间还有最重要的block号码. block是实际存放文件内容的地方 ...

  6. Linux文件系统应用---系统数据备份和迁移(用户角度)

    1   前言 首先承诺:对于从Windows系统迁移过来的用户,困扰大家的  “Linux系统下是否可以把系统文件和用户文件分开到C盘和D盘中” 的问题也可以得到完满解决. 之前的文章对Linux的文 ...

  7. linux 文件系统解析及相关命令

    简介 文件系统就是分区或磁盘上的所有文件的逻辑集合. 文件系统不仅包含着文件中的数据而且还有文件系统的结构,所有Linux 用户和程序看到的文件.目录.软连接及文件保护信息等都存储在其中. 不同Lin ...

  8. 磁盘、分区及Linux文件系统 [Disk, Partition, Linux File System]

    1.磁盘基础知识 1.1 物理结构 硬盘的物理结构一般由磁头与碟片.电动机.主控芯片与排线等部件组成:当主电动机带动碟片旋转时,副电动机带动一组(磁头)到相对应的碟片上并确定读取正面还是反面的碟面,磁 ...

  9. linux文件系统简介

    文件系统是linux的一个十分基础的知识,同时也是学习linux的必备知识. 本文将站在一个较高的视图来了解linux的文件系统,主要包括了linux磁盘分区和目录.挂载基本原理.文件存储结构.软链接 ...

  10. linux文件系统---10

    进入 Linux 根目录(即“/”, Linux 文件系统的入口, 也是处于最高一级的目录),运行“ls –l”命令,可以看到 Linux 系统包含以下目录. 1./bin 包含基本命令,如 ls.c ...

随机推荐

  1. Celery-4.1 用户指南: Extensions and Bootsteps (扩展和Bootsteps)

    自定义消息消费者 你可能想要嵌入自定义的 Kombu 消费者来手动处理你的消息. 为了达到这个目的,celery 提供了一个 ConsumerStep bootstep 类,你只需要定义 get_co ...

  2. ping 127.0.0.1请求超时的解决办法?

    转自:http://blog.51cto.com/dengyong/1429699 打开网络连接,你很有可能启用了虚拟wifi.若有无线网卡就把无线网卡关掉,然后本地连接那里(就是有线网卡的那个连接) ...

  3. Java陷阱一箩筐----面试题集及解答

    Java陷阱一箩筐----面试题集及解答 面试是没什么道理可讲的,它的题目有的不合情理.脱离实际.有在纸上写的,有当面考你的,也有在电话里问的,给你IDE的估计很少. 当然这些都是Java的基本题,那 ...

  4. 解决实现OnPageChangeListener()接口的方法参数出现arg0,arg1的现象

    在安卓开发中,我们经常用到ViewPager,那么既然用到ViewPager,一般都需要去实现OnPageChangeListener()接口的三个方法. 但是有时候实现的三个方法的参数都变成agr0 ...

  5. 剑指offer 04_替换字符串中的空格

    #include <stdio.h> void ReplaceBlank(char string[],int length){ if(string == NULL || length == ...

  6. Eclipse中,将tab缩进改为4个空格

    用4个空格来缩进 , 不要用Tab来缩进 , 因为Tab在不同平台的点位不一样 eclipse->preferences->General->Editors->Text Edi ...

  7. android-auto-scroll-view-pager (无限广告轮播图)

    github 地址: https://github.com/Trinea/android-auto-scroll-view-pager Gradle: compile ('cn.trinea.andr ...

  8. day17 13.滚动结果集介绍

    滚动 一般结果集只能是向下的,不是滚动的,你要是想让它滚动你得设置才行. 类名或者接口里面有静态的可以.接口里面的属性全部都是public static final,类名/接口名.是属性,这些都是常量 ...

  9. Ubuntu14.04文件目录说明

    一.Dev设备目录 二.etc配置文件目录 三.bin默认程序安装目录 四.boot系统启动用到的配置文件以及内核镜像 五.home用户目录 六.lib库文件目录 七.media系统自动挂载设备会选择 ...

  10. 100198H Royal Federation

    传送门 题目大意 国家有N个城市,任意城市可以到达任意城市,是一棵树.国王要给这些城市分省份.每个省份最少M个城市,最多3M个城市.每个省有一个首府,首府不一定是这个省的城市,只是首府到这个省各个城市 ...