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 用户指南: Daemonization (系统守护进程)

    Generic init-scripts 查看Celery发布里的 extra/generic-init.d/ 文件夹. 这个文件夹中包含了celery worker 程序的通用bash初始化脚本,可 ...

  2. Python函数(九)-装饰器(二)

    如果给被装饰器装饰的函数传递参数的话,需要在装饰器里修改 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import tim ...

  3. LNMP 1.4 nginx启动脚本和配置文件

    编写Nginx启动脚本,写入下面这段,授权755 vim /etc/init.d/nginx #!/bin/bash # chkconfig: - # description: http servic ...

  4. LAMP 2.2 Apache配置静态缓存

    这里的静态文件指的是图片.js.css 等文件,用户访问一个站点,其实大多数元素都是图片.js.css 等,这些静态文件其实是会被客户端的浏览器缓存到本地电脑上的,目的就是为了下次再请求时不再去服务器 ...

  5. linux命令-df查看磁盘命令

    格式 df -h 人性化变换数据单位 -k 数据以k为单位 -m 数据以m为单位 -i  查看indoe使用情况 free(查看swap)

  6. EF CODEFIRST WITH ORACLE 存储过程

    EF  CODEFIRST WITH ORACLE 解决存储过程一直没找到解决方案 所以最后也没办法还是用了最基本的解决方案 采用Oracle.ManagedDataAccess提供的ADO基础访问类 ...

  7. spring整合mybatis的事物管理配置

    一.基本配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:/ ...

  8. CentOS和Ubuntu系统下安装vsftp(助推大数据部署搭建)

    不多说,直接上干货! 同时,声明,我这里安装的vsftp,仅仅只为我的大数据着想,关于网上的复杂安装,那是服务和运维那块.我不多牵扯,也不多赘述. 一.CentOS系统里安装vsftp 第一步:使用y ...

  9. Vim 配置文件===/etc/vimrc

    1.替换方法 替换对应的vimrc文件,定制自己的vimrc /etc/vimrc              替换此文件: /home/lmy/.vimrc     只对当前用户有效: Ubuntu9 ...

  10. dubbo-admin打包和zookper安装

    1 首选安装Zookper,下载zookeeper-3.5.3-beta版本,在这里我主要演示这个:下载地址:http://mirrors.hust.edu.cn/apache/zookeeper/ ...