Linux struct inode結構

來源:互聯網
上載者:User

*索引節點對象由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 *);
        /*該函數從給定檔案中刪除指定的屬性*/
};

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.