Linux struct inode結構【轉】

轉自:https://www.cnblogs.com/wanghetao/archive/2012/05/28/2521675.html

*索引節點對象由inode結構體表示,定義文件在linux/fs.h中
*/
struct inode {
        struct hlist_node       i_hash;              /* 哈希表 */
        struct list_head        i_list;              /* 索引節點鏈表 */
        struct list_head        i_dentry;            /* 目錄項鍊表 */
        unsigned long           i_ino;               /* 節點號 */
        atomic_t                i_count;             /* 引用記數 */
        umode_t                 i_mode;              /* 訪問權限控制 */
        unsigned int            i_nlink;             /* 硬鏈接數 */
        uid_t                   i_uid;               /* 使用者id */
        gid_t                   i_gid;               /* 使用者id組 */
        kdev_t                  i_rdev;              /* 實設備標識符 */
        loff_t                  i_size;              /* 以字節爲單位的文件大小 */
        struct timespec         i_atime;             /* 最後訪問時間 */
        struct timespec         i_mtime;             /* 最後修改(modify)時間 */
        struct timespec         i_ctime;             /* 最後改變(change)時間 */
        unsigned int            i_blkbits;           /* 以位爲單位的塊大小 */
        unsigned long           i_blksize;           /* 以字節爲單位的塊大小 */
        unsigned long           i_version;           /* 版本號 */
        unsigned long           i_blocks;            /* 文件的塊數 */
        unsigned short          i_bytes;             /* 使用的字節數 */
        spinlock_t              i_lock;              /* 自旋鎖 */
        struct rw_semaphore     i_alloc_sem;         /* 索引節點信號量 */
        struct inode_operations *i_op;               /* 索引節點操作表 */
        struct file_operations  *i_fop;              /* 默認的索引節點操作 */
        struct super_block      *i_sb;               /* 相關的超級塊 */
        struct file_lock        *i_flock;            /* 文件鎖鏈表 */
        struct address_space    *i_mapping;          /* 相關的地址映射 */
        struct address_space    i_data;              /* 設備地址映射 */
        struct dquot            *i_dquot[MAXQUOTAS]; /* 節點的磁盤限額 */
        struct list_head        i_devices;           /* 塊設備鏈表 */
        struct pipe_inode_info  *i_pipe;             /* 管道信息 */
        struct block_device     *i_bdev;             /* 塊設備驅動 */
        unsigned long           i_dnotify_mask;      /* 目錄通知掩碼 */
        struct dnotify_struct   *i_dnotify;          /* 目錄通知 */
        unsigned long           i_state;             /* 狀態標誌 */
        unsigned long           dirtied_when;        /* 首次修改時間 */
        unsigned int            i_flags;             /* 文件系統標誌 */
        unsigned char           i_sock;              /* 可能是個套接字吧 */
        atomic_t                i_writecount;        /* 寫者記數 */
        void                    *i_security;         /* 安全模塊 */
        __u32                   i_generation;        /* 索引節點版本號 */
        union {
                void            *generic_ip;         /* 文件特殊信息 */
        } u;
};
/*
*索引節點的操作inode_operations定義在linux/fs.h中
*/
struct inode_operations {
        int (*create) (struct inode *, struct dentry *,int);
        /*VFS通過系統調用create()和open()來調用該函數,從而爲dentry對象創建一個新的索引節點。在創建時使用mode制定初始模式*/
        struct dentry * (*lookup) (struct inode *, struct dentry *);
        /*該韓式在特定目錄中尋找索引節點,該索引節點要對應於dentry中給出的文件名*/
        int (*link) (struct dentry *, struct inode *, struct dentry *);
        /*該函數被系統調用link()電泳,用來創建硬連接。硬鏈接名稱由dentry參數指定,連接對象是dir目錄中ld_dentry目錄想所代表的文件*/
        int (*unlink) (struct inode *, struct dentry *);
        /*該函數被系統調用unlink()調用,從目錄dir中刪除由目錄項dentry制動的索引節點對象*/
        int (*symlink) (struct inode *, struct dentry *, const char *);
        /*該函數被系統電泳symlik()調用,創建符號連接,該符號連接名稱由symname指定,連接對象是dir目錄中的dentry目錄項*/
        int (*mkdir) (struct inode *, struct dentry *, int);
        /*該函數被mkdir()調用,創建一個新魯姆。創建時使用mode制定的初始模式*/
        int (*rmdir) (struct inode *, struct dentry *);
        /*該函數被系統調用rmdir()調用,刪除dir目錄中的dentry目錄項代表的文件*/
        int (*mknod) (struct inode *, struct dentry *, int, dev_t);
        /*該函數被系統調用mknod()調用,創建特殊文件(設備文件、命名管道或套接字)。要創建的文件放在dir目錄中,其目錄項問dentry,關聯的設備爲rdev,初始權限由mode指定*/
        int (*rename) (struct inode *, struct dentry *,
                       struct inode *, struct dentry *);
        /*VFS調用該函數來移動文件。文件源路徑在old_dir目錄中,源文件由old_dentry目錄項所指定,目標路徑在new_dir目錄中,目標文件由new_dentry指定*/
        int (*readlink) (struct dentry *, char *, int);
        /*該函數被系統調用readlink()調用,拷貝數據到特定的緩衝buffer中。拷貝的數據來自dentry指定的符號鏈接,最大拷貝大小可達到buflen字節*/
        int (*follow_link) (struct dentry *, struct nameidata *);
        /*該函數由VFS調用,從一個符號連接查找他指向的索引節點,由dentry指向的連接被解析*/
        int (*put_link) (struct dentry *, struct nameidata *);
        /*在follow_link()調用之後,該函數由vfs調用進行清楚工作*/
        void (*truncate) (struct inode *);
        /*該函數由VFS調用,修改文件的大小,在調用之前,索引節點的i_size項必須被設置成預期的大小*/
        int (*permission) (struct inode *, int);
        /*該函數用來檢查給低昂的inode所代表的文件是否允許特定的訪問模式,如果允許特定的訪問模式,返回0,否則返回負值的錯誤碼。多數文件系統 都將此區域設置爲null,使用VFS提供的通用方法進行檢查,這種檢查操作僅僅比較索引及誒但對象中的訪問模式位是否和mask一致,比較複雜的系統, 比如支持訪問控制鏈(ACL)的文件系統,需要使用特殊的permission()方法*/
        int (*setattr) (struct dentry *, struct iattr *);
        /*該函數被notify_change調用,在修改索引節點之後,通知發生了改變事件*/
        int (*getattr) (struct vfsmount *, struct dentry *, struct kstat *);
        /*在通知索引節點需要從磁盤中更新時,VFS會調用該函數*/
        int (*setxattr) (struct dentry *, const char *,
                         const void *, size_t, int);
        /*該函數由VFS調用,向dentry指定的文件設置擴展屬性,屬性名爲name,值爲value*/
        ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
        /*該函數被VFS調用,向value中拷貝給定文件的擴展屬性name對應的數值*/
        ssize_t (*listxattr) (struct dentry *, char *, size_t);
        /*該函數將特定文件所有屬性別表拷貝到一個緩衝列表中*/
        int (*removexattr) (struct dentry *, const char *);
        /*該函數從給定文件中刪除指定的屬性*/
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章