{"id":1984,"date":"2010-11-16T16:01:47","date_gmt":"2010-11-16T08:01:47","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=1984"},"modified":"2010-11-25T17:38:51","modified_gmt":"2010-11-25T09:38:51","slug":"vfs%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/1984","title":{"rendered":"VFS\u4e2d\u7684\u57fa\u672c\u6570\u636e\u7ed3\u6784"},"content":{"rendered":"<p><strong><em>\u672c\u6587\u6d89\u53caVFS\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u6709\uff1astruct super_block;struct inode;struct dentry;struct file;<\/em><\/strong><\/p>\n<p>Linux\u4e2d\u7684VFS\uff08\u5173\u4e8eVFS\u66f4\u52a0\u5168\u9762\u7684\u89e3\u8bf4\u53ef\u4ee5\u770b<a href=\"http:\/\/home.lupaworld.com\/home-space-uid-26540-do-blog-id-230527.html\" target=\"_blank\">\u8fd9\u91cc<\/a>\uff09\u4ee5\u4e00\u7ec4\u901a\u7528\u7684\u6570\u636e\u7ed3\u6784\u6765\u63cf\u8ff0\u5404\u79cd\u6587\u4ef6\u7cfb\u7edf\u3002\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u5206\u522b\u662f\u8d85\u7ea7\u5757\u3001\u7d22\u5f15\u7ed3\u70b9\u3001\u76ee\u5f55\u9879\u548c\u6587\u4ef6\u3002\u4e0b\u9762\u5c06\u5206\u522b\u5bf9\u8fd9\u4e9b\u7ed3\u6784\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n<h4><strong>\u8d85\u7ea7\u5757\u7ed3\u6784\u4f53<\/strong><\/h4>\n<p>\u8d85\u7ea7\u5757\u7ed3\u6784\u4ee3\u8868\u4e00\u4e2a\u5df2\u7ecf\u5b89\u88c5\u4e86\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u5176\u5b58\u50a8\u8be5\u6587\u4ef6\u7cfb\u7edf\u7684\u6709\u5173\u4fe1\u606f\u3002\u5bf9\u4e8e\u4e00\u4e2a\u57fa\u4e8e\u78c1\u76d8\u7684\u6587\u4ef6\u7cfb\u7edf\u6765\u8bf4\uff0c\u8fd9\u7c7b\u5bf9\u8c61\u5b58\u653e\u4e8e\u78c1\u76d8\u7684\u7279\u5b9a\u6247\u533a\u4e2d\uff1b\u5bf9\u4e8e\u975e\u57fa\u4e8e\u78c1\u76d8\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u5b83\u4f1a\u5728\u8be5\u6587\u4ef6\u7cfb\u7edf\u7684\u4f7f\u7528\u73b0\u573a\u521b\u5efa\u8d85\u7ea7\u5757\u7ed3\u6784\u5e76\u5b58\u653e\u5728\u5185\u5b58\u4e2d\u3002<br \/>\n\u5728yoursource\/include\/linux\/fs.h\u4e2d\u6709\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u3002\u4e0b\u9762\u5bf9\u8be5\u7ed3\u6784\u7684\u90e8\u5206\u5b57\u6bb5\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n<pre class=\"brush:c\">1318struct super_block {\r\n1319        struct list_head        s_list;         \/* Keep this first *\/\r\n1320        dev_t                   s_dev;          \/* search index; _not_ kdev_t *\/\r\n1321        unsigned char           s_dirt;\r\n1322        unsigned char           s_blocksize_bits;\r\n1323        unsigned long           s_blocksize;\r\n1324        loff_t                  s_maxbytes;     \/* Max file size *\/\r\n1325        struct file_system_type *s_type;\r\n1326        const struct super_operations   *s_op;\r\n\u2026\u2026 \u2026\u2026\r\n1330        unsigned long           s_flags;\r\n1332        struct dentry           *s_root;\r\n1335        int                     s_count;\r\n1342        struct list_head        s_inodes;       \/* all inodes *\/\r\n1347        struct list_head        s_files;\r\n1353        struct block_device     *s_bdev;\r\n1357        struct quota_info       s_dquot;        \/* Diskquota specific options *\/\r\n1362        char s_id[32];                          \/* Informational name *\/\r\n\u2026\u2026 \u2026\u2026\r\n1388};<\/pre>\n<p><strong>s_list<\/strong>\uff1a\u6240\u4ee5\u7684\u8d85\u7ea7\u5757\u5f62\u6210\u4e00\u4e2a\u53cc\u8054\u8868\uff0cs_list.prev\u548cs_list.next\u5206\u522b\u6307\u5411\u4e0e\u5f53\u524d\u8d85\u7ea7\u5757\u76f8\u90bb\u7684\u524d\u4e00\u4e2a\u5143\u7d20\u548c\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u901a\u5e38\u6211\u4eec\u901a\u8fc7list_entry\u5b8f\u6765\u83b7\u53d6s_list\u6240\u5728\u8d85\u7ea7\u5757\u7ed3\u6784\u4f53\u7684\u5730\u5740\u3002\u8d85\u7ea7\u5757\u94fe\u8868\u7684\u5934\u7ed3\u70b9\u662f\u53d8\u91cfsuper_blocks\uff1b<br \/>\n<strong> s_dev<\/strong>\uff1a\u8d85\u7ea7\u5757\u6240\u63cf\u8ff0\u7684\u6587\u4ef6\u7cfb\u7edf\u6240\u5728\u8bbe\u5907\u7684\u8bbe\u5907\u53f7\u3002\u6bd4\u5982\uff0cext2\u6587\u4ef6\u7cfb\u7edf\u6240\u5728\u8bbe\u5907\u4e3a\u78c1\u76d8\uff0c\u5219\u8be5\u8bbe\u5907\u53f7\u5373\u4e3a\u8be5\u78c1\u76d8\u5728\u7cfb\u7edf\u4e2d\u7684\u8bbe\u5907\u53f7\uff1b<br \/>\n<strong> s_dirt<\/strong>\uff1a\u8d85\u7ea7\u5757\u5728\u5185\u5b58\u4e2d\u88ab\u4fee\u6539\u540e\uff0c\u8be5\u6807\u5fd7\u4e3a1\uff0c\u5219\u4fee\u6539\u540e\u7684\u8d85\u7ea7\u5757\u5fc5\u987b\u5199\u56de\u78c1\u76d8\u3002<br \/>\n<strong> s_dirty\uff1a<\/strong>\u6240\u6709\u810finode\u94fe\u63a5\u5728\u4e00\u8d77\u6240\u5f62\u6210\u7684\u6307\u9488\uff1b<br \/>\n<strong> s_blocksize<\/strong>\uff1a\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u8868\u793a\u5757\u7684\u5927\u5c0f\u3002\u7cfb\u7edf\u5bf9\u6587\u4ef6\u7684\u5b58\u53d6\u64cd\u4f5c\u662f\u4ee5\u5757\u4e3a\u5355\u4f4d\u7684\uff0c\u8be5\u503c\u5373\u4ee3\u8868\u8fd9\u4e2a\u5757\u7684\u5177\u4f53\u5927\u5c0f\uff1b<br \/>\n<strong> s_blocksize_bits<\/strong>\uff1a\u4ee5\u4f4d\u6765\u8868\u793a\u5757\u7684\u5927\u5c0f\u3002\u6bd4\u5982\uff0c\u4e00\u4e2a\u5757\u7684\u5927\u5c0f\u4e3a1024\u5b57\u8282\uff0c\u5219\u8be5\u503c\u4e3a10\uff1b<br \/>\n<strong> s_maxbytes<\/strong>\uff1a\u8be5\u8d85\u7ea7\u5757\u6240\u5c5e\u6587\u4ef6\u7cfb\u7edf\u4e2d\u6587\u4ef6\u7684\u6700\u5927\u957f\u5ea6\uff1b<br \/>\n<strong> s_type<\/strong>\uff1a\u6307\u5411\u5177\u4f53\u7684\u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b\uff1b<br \/>\n<strong> s_op<\/strong>\uff1a\u6307\u5411\u5bf9\u8d85\u7ea7\u5757\u64cd\u4f5c\u7684\u51fd\u6570\u6307\u9488\u7ed3\u6784\u4f53\uff1b<br \/>\n<strong> s_flags<\/strong>\uff1a\u5b89\u88c5\u6587\u4ef6\u7cfb\u7edf\u65f6\u7684\u6807\u5fd7\uff0c\u8bb0\u5f55\u6bd4\u5982\u53ea\u8bfb\u6216\u53ef\u64e6\u5199\u7b49\u8fd9\u6837\u7684\u6807\u5fd7\uff1b<br \/>\n<strong> s_root<\/strong>\uff1a\u8be5\u6587\u4ef6\u7cfb\u7edf\u6839\u76ee\u5f55\u7684\u76ee\u5f55\u9879\u7ed3\u6784\u6307\u9488\u3002\u5229\u7528\u8be5\u6839\u76ee\u5f55\u9879\uff0c\u53ef\u4ee5\u8bbf\u95ee\u5230\u8fd9\u4e2a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u6587\u4ef6\uff1b<br \/>\n<strong> s_count<\/strong>\uff1a\u5bf9\u8be5\u8d85\u7ea7\u5757\u7684\u5f15\u7528\u8ba1\u6570\uff1b<br \/>\n<strong> s_inodes<\/strong>\uff1a\u8be5\u6587\u4ef6\u7cfb\u7edf\u4e2d\u6240\u6709\u7684\u7d22\u5f15\u7ed3\u70b9\u5f62\u6210\u4e00\u4e2a\u53cc\u8054\u8868\uff0c\u8be5\u5b57\u6bb5\u5b58\u653e\u8fd9\u4e2a\u94fe\u8868\u7684\u5934\u7ed3\u70b9\uff1b<br \/>\n<strong> s_files<\/strong>\uff1a\u8be5\u6587\u4ef6\u7cfb\u7edf\u4e2d\u6240\u6709\u5df2\u88ab\u6253\u5f00\u7684\u6587\u4ef6\u5f62\u6210\u4e00\u4e2a\u53cc\u8054\u8868\uff0c\u8be5\u5b57\u6bb5\u5b58\u653e\u8fd9\u4e2a\u94fe\u8868\u7684\u5934\u7ed3\u70b9\uff1b<br \/>\n<strong> s_instances<\/strong>\uff1a\u67d0\u4e2a\u5177\u4f53\u6587\u4ef6\u7cfb\u7edf\u4e2d\u6240\u6709\u8d85\u7ea7\u5757\u4f1a\u7ec4\u6210\u4e00\u4e2a\u53cc\u8054\u8868\u3002\u8fd9\u4e2a\u94fe\u8868\u7684\u5934\u7ed3\u70b9\u4e3asuper_block\uff0c\u5934\u7ed3\u70b9\u5b9a\u4e49\u5728\u8be5\u6587\u4ef6\u7cfb\u7edf\u5bf9\u5e94\u7684file_system_type\u7ed3\u6784\u4f53\u4e2d\uff1b<\/p>\n<p><strong> s_id[32]<\/strong>\uff1a\u6587\u4ef6\u7cfb\u7edf\u7684\u540d\u79f0\u3002\u6bd4\u5982ext3\u6587\u4ef6\u7cfb\u7edf\uff0c\u8be5\u503c\u4e3a\u201cext3\u201d\uff1b<\/p>\n<h4><strong>\u8d85\u7ea7\u5757\u64cd\u4f5c\u7ed3\u6784\u4f53<\/strong><\/h4>\n<p>\u4ece\u4e0a\u9762\u7684\u5b57\u6bb5\u8bf4\u660e\u53ef\u4ee5\u77e5\u9053\uff0c\u8d85\u7ea7\u5757\u4e2d\u6709\u4e00\u4e2as_op\u5b57\u6bb5\uff0c\u5b83\u6307\u5411\u4e0e\u8be5\u64cd\u4f5c\u5757\u76f8\u5173\u7684\u64cd\u4f5c\u3002\u8be5\u5b57\u6bb5\u7684\u7c7b\u578b\u4e3astruct super_operations\uff0c\u5728yoursource\/include\/linux\/fs.h\u4e2d\u6709\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u3002\u4e0b\u9762\u5bf9\u8be5\u7ed3\u6784\u7684\u90e8\u5206\u5b57\u6bb5\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n<pre class=\"brush:c\">1560struct super_operations {\r\n1561        struct inode *(*alloc_inode)(struct super_block *sb);\r\n1562        void (*destroy_inode)(struct inode *);\r\n\u2026\u2026 \u2026\u2026\r\n1564        void (*dirty_inode) (struct inode *);\r\n1565        int (*write_inode) (struct inode *, struct writeback_control *wbc);\r\n1568        void (*put_super) (struct super_block *);\r\n1569        void (*write_super) (struct super_block *);\r\n\u2026\u2026 \u2026\u2026\r\n1584};<\/pre>\n<p><strong>alloc_inode<\/strong>\uff1a\u521b\u5efa\u548c\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684\u7d22\u5f15\u7ed3\u70b9\uff1b<br \/>\n<strong> destroy_inode<\/strong>\uff1a\u91ca\u653e\u6307\u5b9a\u7684\u7d22\u5f15\u7ed3\u70b9\uff1b<br \/>\n<strong> put_super<\/strong>\uff1a\u91ca\u653e\u6307\u5b9a\u7684\u8d85\u7ea7\u5757\uff0c\u6587\u4ef6\u7cfb\u7edf\u88ab\u5378\u8f7d\u65f6\u4f7f\u7528\uff1b<br \/>\n<strong> write_super<\/strong>\uff1a\u5982\u679c\u8be5\u8d85\u7ea7\u5757\u88ab\u4fee\u6539\uff0c\u5373s_dirt\u4e3a1\u65f6\uff0c\u5219\u8981\u5c06\u8d85\u7ea7\u5757\u5199\u56de\u78c1\u76d8\uff0c\u540c\u65f6\u8fd8\u8981\u5c06s_dirt\u91cd\u8bbe\u4e3a0\uff1b<br \/>\n<strong> write_inode<\/strong>\uff1a\u5c06\u6307\u5b9a\u7684inode\u5199\u56de\u78c1\u76d8\uff0c\u7528\u4e8e\u6307\u5b9ainode\u7684\u66f4\u65b0\uff1b<br \/>\n<strong> drop_inode<\/strong>\uff1a\u91ca\u653e\u6307\u5b9a\u7684inode\uff0c\u4e0ewrite_inode\u6210\u5bf9\u51fa\u73b0\uff1b<\/p>\n<p>\u5f53\u6587\u4ef6\u7cfb\u7edf\u9700\u8981\u5bf9\u5176\u6240\u5bf9\u5e94\u7684\u8d85\u7ea7\u5757\u8fdb\u884c\u64cd\u4f5c\u65f6\uff0c\u5c31\u5e94\u8be5\u4f7f\u7528\u8d85\u7ea7\u5757\u64cd\u4f5c\u7c7b\u4e2d\u7684\u5177\u4f53\u51fd\u6570\u3002\u6bd4\u5982\uff0c\u5b9a\u4e49sb\u4e3a\u6307\u5411\u67d0\u4e2a\u8d85\u7ea7\u5757\u7684\u6307\u9488\uff0c\u5982\u679c\u8be5\u8d85\u7ea7\u5757\u9700\u8981\u5c06\u81ea\u5df1\u5199\u56de\u78c1\u76d8\uff0c\u5219\u5e94\u8be5\u8fd9\u4e48\u8c03\u7528\uff1a<\/p>\n<p>sb-&gt;s_op-&gt;write_super(sb);<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u867d\u7136write_super\u51fd\u6570\u662f\u7531sb\u6240\u6307\u7684\u8d85\u7ea7\u5757\u6240\u8c03\u7528\u7684\uff0c\u4f46\u662f\u4ecd\u7136\u5c06sb\u4f20\u9012\u7ed9write_super\u51fd\u6570\u3002<\/p>\n<h4>\u7d22\u5f15\u7ed3\u70b9\u7ed3\u6784\u4f53<\/h4>\n<p>\u7d22\u5f15\u7ed3\u70b9\u7ed3\u6784\u4f53\u7528\u6765\u63cf\u8ff0\u5b58\u653e\u5728\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u4fe1\u606f\u3002\u6bcf\u5f53\u5185\u6838\u5bf9\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u8fdb\u884c\u64cd\u4f5c\u65f6\uff0c\u5c31\u4f1a\u5c06\u8be5\u6587\u4ef6\u7684\u4fe1\u606f\u586b\u5145\u5230\u4e00\u4e2a\u7d22\u5f15\u7ed3\u70b9\u53ef\u4ee5\u4ee3\u8868\u4e00\u4e2a\u666e\u901a\u7684\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u4ee3\u8868\u7ba1\u9053\u6216\u8005\u8bbe\u5907\u6587\u4ef6\u7b49\u8fd9\u6837\u7684\u7279\u6b8a\u6587\u4ef6\u3002\u56e0\u6b64\uff0c\u5728\u7d22\u5f15\u7ed3\u70b9\u7ed3\u6784\u4e2d\uff0c\u4f1a\u5305\u542b\u9488\u5bf9\u8fd9\u4e9b\u7279\u6b8a\u6587\u4ef6\u7684\u4e00\u4e9b\u5c5e\u6027\u3002\u8be5\u7ed3\u6784\u4f53\u5b9a\u4e49\u4e8e\u5728yoursource\/include\/linux\/fs.h\u4e2d\u6709\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u3002\u4e0b\u9762\u5bf9\u8be5\u7ed3\u6784\u7684\u90e8\u5206\u5b57\u6bb5\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n<pre class=\"brush:c\"> 725struct inode {\r\n 726        struct hlist_node       i_hash;\r\n 727        struct list_head        i_list;         \/* backing dev IO list *\/\r\n 729        struct list_head        i_dentry;\r\n 730        unsigned long           i_ino;\r\n 731        atomic_t                i_count;\r\n 732        unsigned int            i_nlink;\r\n 733        uid_t                   i_uid;\r\n 734        gid_t                   i_gid;\r\n 735        dev_t                   i_rdev;\r\n 736        unsigned int            i_blkbits;\r\n 737        u64                     i_version;\r\n 738        loff_t                  i_size;\r\n\u2026\u2026 \u2026\u2026\r\n 742        struct timespec         i_atime;\r\n 743        struct timespec         i_mtime;\r\n 744        struct timespec         i_ctime;\r\n 745        blkcnt_t                i_blocks;\r\n 746        unsigned short          i_bytes;\r\n 747        umode_t                 i_mode;\r\n \u2026\u2026 \u2026\u2026\r\n 751        const struct inode_operations   *i_op;\r\n 752        const struct file_operations    *i_fop; \/* former -&gt;i_op-&gt;default_file_ops *\/\r\n 753        struct super_block      *i_sb;\r\n 760        struct list_head        i_devices;\r\n 761        union {\r\n 762                struct pipe_inode_info  *i_pipe;\r\n 763                struct block_device     *i_bdev;\r\n 764                struct cdev             *i_cdev;\r\n 765        };\r\n \u2026\u2026 \u2026\u2026\r\n 788};<\/pre>\n<p><strong> i_hash<\/strong>\uff1a\u4e3a\u4e86\u63d0\u9ad8\u67e5\u627e\u6b63\u5728\u88ab\u4f7f\u7528\u7684inode\u7684\u6548\u7387\uff0c\u6bcf\u4e00\u4e2ainode\u90fd\u4f1a\u6709\u4e00\u4e2ahash\u503c\uff0c\u6240\u6709hash\u503c\u76f8\u540c\u7684inode\u5f62\u6210\u4e00\u4e2a\u53cc\u94fe\u8868\u3002\u8be5\u5b57\u6bb5\u5305\u542bprev\u548cnext\u4e24\u4e2a\u6307\u9488\uff0c\u5206\u522b\u6307\u5411\u4e0a\u8ff0\u94fe\u8868\u7684\u524d\u4e00\u4e2a\u5143\u7d20\u548c\u540e\u4e00\u4e2a\u5143\u7d20\uff1b<br \/>\n<strong> i_list<\/strong>\uff1aVFS\u4e2d\u4f7f\u7528\u56db\u4e2a\u94fe\u8868\u6765\u7ba1\u7406\u4e0d\u540c\u72b6\u6001\u7684inode\u7ed3\u70b9\u3002inode_unused\u5c06\u5f53\u524d\u672a\u4f7f\u7528\u7684inode\u94fe\u63a5\u8d77\u6765\uff0cinode_in_use\u5c06\u5f53\u524d\u6b63\u5728\u88ab\u4f7f\u7528\u7684inode\u94fe\u63a5\u8d77\u6765\uff0c\u8d85\u7ea7\u5757\u4e2d\u7684s_dirty\u5c06\u6240\u6709\u810finode\u94fe\u63a5\u8d77\u6765\uff0ci_hash\u5c06\u6240\u6709hash\u503c\u76f8\u540c\u7684inode\u94fe\u63a5\u8d77\u6765\u3002i_list\u4e2d\u5305\u542bprev\u548cnext\u4e24\u4e2a\u6307\u9488\uff0c\u5206\u522b\u6307\u5411\u4e0e\u5f53\u524dinode\u5904\u4e8e\u540c\u4e00\u4e2a\u72b6\u6001\u94fe\u8868\u7684\u524d\u540e\u4e24\u4e2a\u5143\u7d20\u3002<br \/>\n<strong> i_sb_list<\/strong>\uff1a\u6bcf\u4e2a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684inode\u90fd\u4f1a\u5f62\u6210\u4e00\u4e2a\u53cc\u8054\u8868\uff0c\u8fd9\u4e2a\u53cc\u94fe\u8868\u7684\u5934\u7ed3\u70b9\u5b58\u653e\u5728\u8d85\u7ea7\u5757\u7684s_inodes\u4e2d\u3002\u800c\u8be5\u5b57\u6bb5\u4e2d\u7684prev\u548cnext\u6307\u9488\u5206\u522b\u6307\u5411\u5728\u53cc\u94fe\u8868\u4e2d\u4e0e\u5176\u76f8\u90bb\u7684\u524d\u540e\u4e24\u4e2a\u5143\u7d20\uff1b<br \/>\n<strong> i_dentry<\/strong>\uff1a\u6240\u6709\u5f15\u7528\u8be5inode\u7684\u76ee\u5f55\u9879\u5c06\u5f62\u6210\u4e00\u4e2a\u53cc\u8054\u8868\uff0c\u8be5\u5b57\u6bb5\u5373\u4e3a\u8fd9\u4e2a\u53cc\u8054\u8868\u7684\u5934\u7ed3\u70b9\uff1b<br \/>\n<strong> i_ino<\/strong>\uff1a\u7d22\u5f15\u7ed3\u70b9\u53f7\u3002\u901a\u8fc7ls -l\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u6587\u4ef6\u7684\u7d22\u5f15\u8282\u70b9\u53f7\uff1b<br \/>\n<strong> i_count<\/strong>\uff1a\u5f15\u7528\u8ba1\u6570\uff1b<br \/>\n<strong> i_nlink<\/strong>\uff1a\u786c\u94fe\u63a5\u6570\u3002\u5f53\u8be5inode\u63cf\u8ff0\u4e00\u4e2a\u76ee\u5f55\u65f6\uff0c\u8fd9\u4e2a\u503c\u81f3\u5c11\u4e3a2\uff0c\u4ee3\u8868.\u548c..\u7684\u6570\u76ee\uff1b<br \/>\n<strong> i_uid<\/strong>\uff1ainode\u6240\u5c5e\u6587\u4ef6\u7684\u62e5\u6709\u8005\u7684id\uff0c\u901a\u8fc7ls -n\u53ef\u67e5\u770b\u62e5\u6709\u8005id\uff1b<br \/>\n<strong> i_gid<\/strong>\uff1ainode\u6240\u5c5e\u6587\u4ef6\u6240\u5728\u7ec4\u7684id\uff0c\u901a\u8fc7ls -n\u53ef\u67e5\u770b\u7ec4id\uff1b<br \/>\n<strong> i_rdev<\/strong>\uff1a\u5982\u679c\u8be5inode\u63cf\u8ff0\u7684\u662f\u4e00\u4e2a\u8bbe\u5907\u6587\u4ef6\uff0c\u6b64\u503c\u4e3a\u8bbe\u5907\u53f7\uff1b<br \/>\n<strong> i_blkbits<\/strong>\uff1a\u4ee5\u4f4d\u4e3a\u5355\u4f4d\u7684\u5757\u5927\u5c0f\uff1b<br \/>\n<strong> i_atime<\/strong>\uff1a\u6587\u4ef6\u6700\u8fd1\u4e00\u6b21\u88ab\u8bbf\u95ee\u7684\u65f6\u95f4\u3002\u901a\u8fc7ls -lu\u53ef\u67e5\u770b\u8be5\u65f6\u95f4\uff1b<br \/>\n<strong> i_mtime<\/strong>\uff1a\u6587\u4ef6\u6700\u8fd1\u4e00\u6b21\u88ab\u4fee\u6539\u7684\u65f6\u95f4\uff0c\u8fd9\u91cc\u7684\u4fee\u6539\u53ea\u6587\u4ef6\u5185\u5bb9\u88ab\u4fee\u6539\u3002\u901a\u8fc7ls -l\u53ef\u67e5\u770b\u8be5\u65f6\u95f4\uff1b<br \/>\n<strong> i_ctime<\/strong>\uff1a\u6587\u4ef6\u6700\u8fd1\u4e00\u6b21\u88ab\u4fee\u6539\u7684\u65f6\u95f4\uff0c\u8fd9\u91cc\u7684\u4fee\u6539\u9664\u4e86\u6307\u6587\u4ef6\u5185\u5bb9\u88ab\u4fee\u6539\u5916\uff0c\u66f4\u5f3a\u8c03\u7684\u662f\u6587\u4ef6\u7684\u5c5e\u6027\u88ab\u4fee\u6539\u3002\u901a\u8fc7ls -lc\u53ef\u67e5\u770b\u8be5\u65f6\u95f4\uff1b<br \/>\n<strong> i_blocks<\/strong>\uff1a\u6587\u4ef6\u4f7f\u7528\u5757\u7684\u4e2a\u6570\uff0c\u901a\u8fc7ls -s\u53ef\u4ee5\u67e5\u770b\u8be5\u67d0\u4e2a\u6587\u4ef6\u7684\u5757\u4f7f\u7528\u6570\u76ee\uff1b<br \/>\n<strong> i_mode<\/strong>\uff1a\u6587\u4ef6\u7684\u8bbf\u95ee\u6743\u9650\uff1b<br \/>\n<strong> i_op<\/strong>\uff1a\u6307\u5411\u7d22\u5f15\u7ed3\u70b9\u64cd\u4f5c\u7ed3\u6784\u4f53\u7684\u6307\u9488\uff1b<br \/>\n<strong> i_fop<\/strong>\uff1a\u6307\u5411\u6587\u4ef6\u64cd\u4f5c\u7ed3\u6784\u4f53\u7684\u6307\u9488\uff0c\u8fd9\u4e2a\u5b57\u6bb5\u7528\u6765\u521d\u59cb\u5316\u6587\u4ef6\u7ed3\u6784\u4f53\uff08struct file\uff09\u4e2d\u7684f_op\u5b57\u6bb5\uff1b<br \/>\n<strong> i_sb<\/strong>\uff1a\u6307\u5411inode\u6240\u5c5e\u6587\u4ef6\u7cfb\u7edf\u7684\u8d85\u7ea7\u5757\u7684\u6307\u9488\uff1b<br \/>\n<strong> i_pipe<\/strong>\uff1a\u5982\u679cinode\u6240\u4ee3\u8868\u7684\u6587\u4ef6\u662f\u4e00\u4e2a\u7ba1\u9053\uff0c\u5219\u4f7f\u7528\u8be5\u5b57\u6bb5\uff1b<br \/>\n<strong> i_bdev<\/strong>\uff1a\u5982\u679cinode\u6240\u4ee3\u8868\u7684\u6587\u4ef6\u662f\u4e00\u4e2a\u5757\u8bbe\u5907\uff0c\u5219\u4f7f\u7528\u8be5\u5b57\u6bb5\uff1b<br \/>\n<strong> i_cdev<\/strong>\uff1a\u5982\u679cinode\u6240\u4ee3\u8868\u7684\u6587\u4ef6\u662f\u4e00\u4e2a\u5b57\u7b26\u8bbe\u5907\uff0c\u5219\u4f7f\u7528\u8be5\u5b57\u6bb5\uff1b<\/p>\n<p>\u7d22\u5f15\u7ed3\u70b9\u64cd\u4f5c\u7ed3\u6784\u4f53<\/p>\n<p>\u5728inode\u7ed3\u6784\u4f53\u4e2d\uff0c\u6709\u4e00\u4e2ai_op\u5b57\u6bb5\uff0c\u8be5\u5b57\u6bb5\u6307\u5411\u4e0e\u7d22\u5f15\u7ed3\u70b9\u76f8\u5173\u7684\u64cd\u4f5c\u3002\u8fd9\u4e2a\u5b57\u6bb5\u7684\u7c7b\u578b\u4e3astruct inode_operations\uff0c\u5728yoursource\/include\/linux\/fs.h\u4e2d\u6709\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u3002\u4e0b\u9762\u53ea\u5217\u51fa\u90e8\u5206\u5b57\u6bb5\u7684\u8bf4\u660e\u3002<\/p>\n<pre class=\"brush:c\">1516struct inode_operations {\r\n1517        int (*create) (struct inode *,struct dentry *,int, struct nameidata *);\r\n1518        struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);\r\n\u2026\u2026 \u2026\u2026\r\n1519        int (*link) (struct dentry *,struct inode *,struct dentry *);\r\n1520        int (*unlink) (struct inode *,struct dentry *);\r\n1521        int (*symlink) (struct inode *,struct dentry *,const char *);\r\n1522        int (*mkdir) (struct inode *,struct dentry *,int);\r\n1523        int (*rmdir) (struct inode *,struct dentry *);\r\n1524        int (*mknod) (struct inode *,struct dentry *,int,dev_t);\r\n\u2026\u2026 \u2026\u2026\r\n1544};<\/pre>\n<p><strong> create<\/strong>\uff1a\u5982\u679c\u8be5inode\u63cf\u8ff0\u4e00\u4e2a\u76ee\u5f55\u6587\u4ef6\uff0c\u90a3\u4e48\u5f53\u5728\u8be5\u76ee\u5f55\u4e0b\u521b\u5efa\u6216\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\u65f6\uff0c\u5185\u6838\u5fc5\u987b\u4e3a\u8fd9\u4e2a\u6587\u4ef6\u521b\u5efa\u4e00\u4e2ainode\u3002VFS\u901a\u8fc7\u8c03\u7528\u8be5inode\u7684i_op-&gt;create()\u51fd\u6570\u6765\u5b8c\u6210\u4e0a\u8ff0\u65b0inode\u7684\u521b\u5efa\u3002\u8be5\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u8be5\u76ee\u5f55\u7684inode\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u8981\u6253\u5f00\u65b0\u6587\u4ef6\u7684dentry\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u662f\u5bf9\u8be5\u6587\u4ef6\u7684\u8bbf\u95ee\u6743\u9650\u3002\u5982\u679c\u8be5inode\u63cf\u8ff0\u7684\u662f\u4e00\u4e2a\u666e\u901a\u6587\u4ef6\uff0c\u90a3\u4e48\u8be5inode\u6c38\u8fdc\u90fd\u4e0d\u4f1a\u8c03\u7528\u8fd9\u4e2acreate\u51fd\u6570\uff1b<br \/>\n<strong> lookup<\/strong>\uff1a\u67e5\u627e\u6307\u5b9a\u6587\u4ef6\u7684dentry\uff1b<br \/>\n<strong> link<\/strong>\uff1a\u7528\u4e8e\u5728\u6307\u5b9a\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u786c\u94fe\u63a5\u3002\u8fd9\u4e2alink\u51fd\u6570\u6700\u7ec8\u4f1a\u88ab\u7cfb\u7edf\u8c03\u7528link()\u8c03\u7528\u3002\u8be5\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u539f\u59cb\u6587\u4ef6\u7684dentry\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5373\u4e3a\u4e0a\u8ff0\u6307\u5b9a\u76ee\u5f55\u7684inode\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u662f\u94fe\u63a5\u6587\u4ef6\u7684dentry\u3002<br \/>\n<strong> unlink<\/strong>\uff1a\u5728\u67d0\u4e2a\u76ee\u5f55\u4e0b\u5220\u9664\u6307\u5b9a\u7684\u786c\u94fe\u63a5\u3002\u8fd9\u4e2aunlink\u51fd\u6570\u6700\u7ec8\u4f1a\u88ab\u7cfb\u7edf\u8c03\u7528unlink()\u8c03\u7528\u3002 \u7b2c\u4e00\u4e2a\u53c2\u6570\u5373\u4e3a\u4e0a\u8ff0\u786c\u94fe\u63a5\u6240\u5728\u76ee\u5f55\u7684inode\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u8981\u5220\u9664\u6587\u4ef6\u7684dentry\u3002<br \/>\n<strong> symlink<\/strong>\uff1a\u5728\u67d0\u4e2a\u76ee\u5f55\u4e0b\u65b0\u5efa<br \/>\nmkdir\uff1a\u5728\u6307\u5b9a\u7684\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u5b50\u76ee\u5f55\uff0c\u5f53\u524d\u76ee\u5f55\u7684inode\u4f1a\u8c03\u7528i_op-&gt;mkdir()\u3002\u8be5\u51fd\u6570\u4f1a\u88ab\u7cfb\u7edf\u8c03\u7528mkdir()\u8c03\u7528\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570\u5373\u4e3a\u6307\u5b9a\u76ee\u5f55\u7684inode\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u5b50\u76ee\u5f55\u7684dentry\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u4e3a\u5b50\u76ee\u5f55\u6743\u9650\uff1b<br \/>\n<strong> rmdir<\/strong>\uff1a\u4eceinode\u6240\u63cf\u8ff0\u7684\u76ee\u5f55\u4e2d\u5220\u9664\u4e00\u4e2a\u6307\u5b9a\u7684\u5b50\u76ee\u5f55\u65f6\uff0c\u8be5\u51fd\u6570\u4f1a\u88ab\u7cfb\u7edf\u8c03\u7528rmdir()\u6700\u7ec8\u8c03\u7528\uff1b<br \/>\n<strong> mknod<\/strong>\uff1a\u5728\u6307\u5b9a\u7684\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u7279\u6b8a\u6587\u4ef6\uff0c\u6bd4\u5982\u7ba1\u9053\u3001\u8bbe\u5907\u6587\u4ef6\u6216\u5957\u63a5\u5b57\u7b49\u3002<\/p>\n<h4>\u76ee\u5f55\u9879\u7ed3\u6784\u4f53<\/h4>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u5bf9\u76ee\u6807\u6587\u4ef6\u7684\u5feb\u901f\u67e5\u627e\uff0cVFS\u5f15\u5165\u4e86\u76ee\u5f55\u9879\u3002\u76ee\u6807\u6587\u4ef6\u8def\u5f84\u4e2d\u7684\u6bcf\u4e00\u9879\u90fd\u4ee3\u8868\u4e00\u4e2a\u76ee\u5f55\u9879\uff0c\u6bd4\u5982\/home\/test.c\u4e2d\uff0c\/\uff0chome\uff0ctest.c\u90fd\u5206\u522b\u662f\u4e00\u4e2a\u76ee\u5f55\u9879\u3002\u8fd9\u4e9b\u76ee\u5f55\u9879\u90fd\u5c5e\u4e8e\u8def\u5f84\u7684\u4e00\u90e8\u5206\uff0c\u5e76\u4e14\u6bcf\u4e2a\u76ee\u5f55\u9879\u90fd\u4e0e\u5176\u5bf9\u5e94\u7684inode\u76f8\u8054\u7cfb\u3002\u5982\u679cVFS\u5f97\u5230\u4e86\u67d0\u4e2adentry\uff0c\u90a3\u4e48\u4e5f\u5c31\u968f\u4e4b\u5f97\u5230\u4e86\u8fd9\u4e2a\u76ee\u5f55\u9879\u6240\u5bf9\u5e94\u6587\u4ef6\u7684inode\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5bf9\u8fd9\u4e2ainode\u6240\u5bf9\u5e94\u7684\u6587\u4ef6\u8fdb\u884c\u76f8\u5e94\u64cd\u4f5c\u3002\u6240\u4ee5\uff0c\u4f9d\u6b21\u6cbf\u7740\u76ee\u6807\u6587\u4ef6\u8def\u5f84\u4e2d\u5404\u90e8\u5206\u7684\u76ee\u5f55\u9879\u8fdb\u884c\u641c\u7d22\uff0c\u6700\u7ec8\u5219\u53ef\u627e\u5230\u76ee\u6807\u6587\u4ef6\u7684inode\u3002<\/p>\n<p>\u4e0e\u8d85\u7ea7\u5757\u548c\u7d22\u5f15\u7ed3\u70b9\u4e0d\u540c\u7684\u662f\uff0c\u76ee\u5f55\u9879\u5728\u78c1\u76d8\u4e0a\u5e76\u6ca1\u6709\u5bf9\u5e94\u7684\u5b9e\u4f53\u6587\u4ef6\uff0c\u5b83\u4f1a\u5728\u9700\u8981\u65f6\u5019\u73b0\u573a\u88ab\u521b\u5efa\u3002\u56e0\u6b64\uff0c\u5728\u76ee\u5f55\u9879\u7ed3\u6784\u4f53\u4e2d\u5e76\u6ca1\u6709\u810f\u6570\u636e\u5b57\u6bb5\uff0c\u56e0\u4e3a\u76ee\u5f55\u9879\u5e76\u4e0d\u4f1a\u6d89\u53ca\u91cd\u5199\u5230\u78c1\u76d8\u3002<\/p>\n<p>\u76ee\u5f55\u9879\u7531struct dentry\u63cf\u8ff0\uff0c\u5728yoursource\/include\/linux\/dcache.h\u4e2d\u6709\u8fd9\u4e2a\u7ed3\u6784\u7684\u5b9a\u4e49\u3002\u4e0b\u9762\u53ea\u5bf9\u90e8\u5206\u5b57\u6bb5\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n<pre class=\"brush:c\"> 89struct dentry {\r\n  90        atomic_t d_count;\r\n  91        unsigned int d_flags;           \/* protected by d_lock *\/\r\n  92        spinlock_t d_lock;              \/* per dentry lock *\/\r\n  93        int d_mounted;\r\n  94        struct inode *d_inode;          \/* Where the name belongs to - NULL is\r\n  \u2026\u2026 \u2026\u2026\r\n 100        struct hlist_node d_hash;       \/* lookup hash list *\/\r\n 101        struct dentry *d_parent;        \/* parent directory *\/\r\n 102        struct qstr d_name;\r\n 103\r\n 104        struct list_head d_lru;         \/* LRU list *\/\r\n 108        union {\r\n 109                struct list_head d_child;       \/* child of parent list *\/\r\n 110                struct rcu_head d_rcu;\r\n 111        } d_u;\r\n 112        struct list_head d_subdirs;     \/* our children *\/\r\n 113        struct list_head d_alias;       \/* inode alias list *\/\r\n 115        const struct dentry_operations *d_op;\r\n 116        struct super_block *d_sb;       \/* The root of the dentry tree *\/\r\n\u2026\u2026 \u2026\u2026\r\n 120};<\/pre>\n<p><strong>d_count<\/strong>\uff1a\u5f15\u7528\u8ba1\u6570\uff1b<br \/>\n<strong> d_inode<\/strong>\uff1a\u4e0e\u8be5\u76ee\u5f55\u9879\u76f8\u5173\u8054\u7684\u7d22\u5f15\u7ed3\u70b9\uff1b<br \/>\n<strong> d_hash<\/strong>\uff1a\u5185\u6838\u4f7f\u7528\u54c8\u5e0c\u8868\u5bf9\u6240\u6709dentry\u8fdb\u884c\u7ba1\u7406\uff0c\u8be5\u5b57\u6bb5\u4f7f\u5f97\u5f53\u524ddentry\u5904\u4e8e\u54c8\u5e0c\u8868\u7684\u67d0\u4e2a\u51b2\u7a81\u94fe\u8868\u5f53\u4e2d\uff1b<br \/>\n<strong> d_parent<\/strong>\uff1a\u6307\u5411\u7236\u76ee\u5f55\u7684\u76ee\u5f55\u9879\uff1b<br \/>\n<strong> d_name<\/strong>\uff1a\u76ee\u5f55\u9879\u7684\u540d\u79f0\uff1b<br \/>\n<strong> d_subdirs<\/strong>\uff1a\u5982\u679c\u5f53\u524d\u76ee\u5f55\u9879\u662f\u4e00\u4e2a\u76ee\u5f55\uff0c\u90a3\u4e48\u8be5\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u5b50\u76ee\u5f55\u5f62\u6210\u4e00\u4e2a\u94fe\u8868\u3002\u8be5\u5b57\u6bb5\u662f\u8fd9\u4e2a\u94fe\u8868\u7684\u8868\u5934\uff1b<br \/>\n<strong> d_child<\/strong>\uff1a\u5982\u679c\u5f53\u524d\u76ee\u5f55\u9879\u662f\u4e00\u4e2a\u76ee\u5f55\uff0c\u90a3\u4e48\u8be5\u76ee\u5f55\u9879\u901a\u8fc7\u8fd9\u4e2a\u5b57\u6bb5\u52a0\u5165\u5230\u7236\u76ee\u5f55\u7684d_subdirs\u94fe\u8868\u5f53\u4e2d\u3002\u8fd9\u4e2a\u5b57\u6bb5\u4e2d\u7684next\u548cprev\u6307\u9488\u5206\u522b\u6307\u5411\u7236\u76ee\u5f55\u4e2d\u7684\u53e6\u5916\u4e24\u4e2a\u5b50\u76ee\u5f55\uff1b<br \/>\n<strong> d_alias<\/strong>\uff1a\u4e00\u4e2ainode\u53ef\u80fd\u5bf9\u5e94\u591a\u4e2a\u76ee\u5f55\u9879\uff0c\u6240\u6709\u7684\u76ee\u5f55\u9879\u5f62\u6210\u4e00\u4e2a\u94fe\u8868\u3002inode\u7ed3\u6784\u4e2d\u7684i_dentry\u5373\u4e3a\u8fd9\u4e2a\u94fe\u8868\u7684\u5934\u7ed3\u70b9\u3002\u5f53\u524d\u76ee\u5f55\u9879\u4ee5\u8fd9\u4e2a\u5b57\u6bb5\u5904\u4e8ei_dentry\u94fe\u8868\u4e2d\u3002\u8be5\u5b57\u6bb5\u4e2d\u7684prev\u548cnext\u6307\u9488\u5206\u522b\u6307\u5411\u4e0e\u8be5\u76ee\u5f55\u9879\u540cinode\u7684\u5176\u4ed6\u4e24\u4e2a\uff08\u5982\u679c\u6709\u7684\u8bdd\uff09\u76ee\u5f55\u9879\uff1b<br \/>\n<strong> d_op<\/strong>\uff1a\u6307\u5411\u76ee\u5f55\u9879\u64cd\u4f5c\u7ed3\u6784\u4f53\u7684\u6307\u9488\uff1b<br \/>\n<strong> d_sb<\/strong>\uff1a\u6307\u5411\u8be5\u76ee\u5f55\u9879\u6240\u5c5e\u7684\u6587\u4ef6\u7cfb\u7edf\u5bf9\u5e94\u7684\u8d85\u7ea7\u5757\uff1b<\/p>\n<h4>\u76ee\u5f55\u9879\u64cd\u4f5c\u7ed3\u6784\u4f53<\/h4>\n<pre class=\"brush:c\"> 134struct dentry_operations {\r\n 135        int (*d_revalidate)(struct dentry *, struct nameidata *);\r\n 136        int (*d_hash) (struct dentry *, struct qstr *);\r\n 137        int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);\r\n 138        int (*d_delete)(struct dentry *);\r\n 139        void (*d_release)(struct dentry *);\r\n 140        void (*d_iput)(struct dentry *, struct inode *);\r\n 141        char *(*d_dname)(struct dentry *, char *, int);\r\n 142};<\/pre>\n<h4>\u6587\u4ef6\u7ed3\u6784\u4f53<\/h4>\n<p>VFS\u4f7f\u7528struct file\u6765\u63cf\u8ff0\u4e00\u4e2a\u88ab\u8fdb\u7a0b\u5df2\u7ecf\u6253\u5f00\u7684\u6587\u4ef6\u3002\u4e0e\u4e0a\u8ff0\u4e09\u4e2a\u7ed3\u6784\u4f53\u4e0d\u540c\uff0c\u6587\u4ef6\u7ed3\u6784\u4f53\u662f\u8fdb\u7a0b\u76f4\u63a5\u5904\u7406\u7684\u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u5728\u8be5\u7ed3\u6784\u4f53\u4e2d\u4f60\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u719f\u6089\u7684\u4e00\u4e9b\u6587\u4ef6\u5c5e\u6027\u4fe1\u606f\u3002\u6587\u4ef6\u5bf9\u8c61\u662f\u5df2\u6253\u5f00\u6587\u4ef6\u5728\u5185\u5b58\u4e2d\u7684\u8868\u793a\uff0c\u56e0\u6b64\uff0c\u5b83\u5728\u78c1\u76d8\u4e0a\u5e76\u6ca1\u6709\u4e0e\u4e4b\u5bf9\u5e94\u7684\u6570\u636e\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6587\u4ef6\u5bf9\u8c61\u53ea\u5b58\u5728\u4e8e\u5185\u5b58\u4e2d\uff0c\u6240\u4ee5\u8fd9\u4e2a\u7ed3\u6784\u4e5f\u5c31\u4e0d\u6d89\u53ca\u810f\u6570\u636e\u5b57\u6bb5\u548c\u662f\u5426\u9700\u8981\u5199\u56de\u78c1\u76d8\u3002<\/p>\n<p>\u6709\u4e0a\u8ff0\u53ef\u77e5\uff0c\u6bcf\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\u65f6\uff0c\u5185\u5b58\u4e2d\u6709\u4f1a\u6709\u76f8\u5e94\u7684file\u7ed3\u6784\u4f53\u3002\u56e0\u6b64\uff0c\u5f53\u4e00\u4e2a\u6587\u4ef6\u88ab\u591a\u4e2a\u8fdb\u7a0b\u6253\u5f00\u65f6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u5c31\u4f1a\u6709\u591a\u4e2a\u5bf9\u5e94\u7684\u6587\u4ef6\u7ed3\u6784\u4f53\u3002\u4f46\u662f\uff0c\u8fd9\u4e9b<span style=\"font-size: 13.3333px;\">\u6587\u4ef6\u7ed3\u6784\u4f53\u5bf9\u5e94\u7684\u7d22\u5f15\u7ed3\u70b9\u548c\u76ee\u5f55\u9879\u5374\u662f\u552f\u4e00\u7684\u3002\u5728yoursource\/include\/linux\/fs.h\u4e2d\u6709\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u3002\u4e0b\u9762\u53ea\u5217\u51fa\u90e8\u5206\u5b57\u6bb5\u7684\u8bf4\u660e\u3002<\/span><\/p>\n<pre class=\"brush:c\"> 909struct file {\r\n\u2026\u2026 \u2026\u2026\r\n 914        union {\r\n 915                struct list_head        fu_list;\r\n 916                struct rcu_head         fu_rcuhead;\r\n 917        } f_u;\r\n 918        struct path             f_path;\r\n 919#define f_dentry        f_path.dentry\r\n 920#define f_vfsmnt        f_path.mnt\r\n 921        const struct file_operations    *f_op;\r\n 922        spinlock_t              f_lock;  \/* f_ep_links, f_flags, no IRQ *\/\r\n 923#ifdef CONFIG_SMP\r\n 924        int                     f_sb_list_cpu;\r\n 925#endif\r\n 926        atomic_long_t           f_count;\r\n 927        unsigned int            f_flags;\r\n 928        fmode_t                 f_mode;\r\n 929        loff_t                  f_pos;\r\n 930        struct fown_struct      f_owner;\r\n 935#ifdef CONFIG_SECURITY\r\n 936        void                    *f_security;\r\n 937#endif\r\n 938        \/* needed for tty driver, and maybe others *\/\r\n 939        void                    *private_data;\r\n 940\r\n\u2026\u2026 \u2026\u2026\r\n 949};<\/pre>\n<p><strong> fu_list<\/strong>\uff1a\u6bcf\u4e2a\u6587\u4ef6\u7cfb\u7edf\u4e2d\u4ee5\u88ab\u6253\u5f00\u7684\u6587\u4ef6\u90fd\u4f1a\u5f62\u6210\u4e00\u4e2a\u53cc\u8054\u8868\uff0c\u8fd9\u4e2a\u53cc\u8054\u8868\u7684\u5934\u7ed3\u70b9\u5b58\u653e\u5728\u8d85\u7ea7\u5757\u7684s_files\u5b57\u6bb5\u4e2d\u3002\u8be5\u5b57\u6bb5\u7684prev\u548cnext\u6307\u9488\u5206\u522b\u6307\u5411\u5728\u94fe\u8868\u4e2d\u4e0e\u5f53\u524d\u6587\u4ef6\u7ed3\u6784\u4f53\u76f8\u90bb\u7684\u524d\u540e\u4e24\u4e2a\u5143\u7d20\uff1b<br \/>\n<strong>f_dentry<\/strong>\uff1a\u4e0e\u8be5\u6587\u4ef6\u5bf9\u5e94\u7684dentry\uff1b<br \/>\n<strong> f_vfsmnt<\/strong>\uff1a\u8be5\u6587\u4ef6\u6240\u5728\u6587\u7cfb\u7edf\u7684\u5b89\u88c5\u70b9\uff0c\u4e0ef_dentry\u76f8\u7ed3\u5408\u53ef\u4ee5\u5f97\u5230\u8be5\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\uff1b<br \/>\n<strong> f_op<\/strong>\uff1a\u6307\u5411\u4e0e\u8be5\u6587\u4ef6\u76f8\u5173\u7684\u64cd\u4f5c\u7684\u7ed3\u6784\u4f53\uff1b<br \/>\n<strong> f_count<\/strong>\uff1a\u8be5\u6587\u4ef6\u7684\u5f15\u7528\u8ba1\u6570\uff1b<br \/>\n<strong> f_flags<\/strong>\uff1a\u8fdb\u7a0b\u6253\u5f00\u8be5\u6587\u4ef6\u65f6\u5019\u7684\u6807\u5fd7\uff0c\u6bd4\u5982\u4ee5\u53ea\u8bfb\uff0c\u53ef\u8bfb\u5199\u7b49\u65b9\u5f0f\u6253\u5f00\u8be5\u6587\u4ef6\uff1b<br \/>\n<strong> f_mode<\/strong>\uff1a\u8be5\u6587\u4ef6\u7684\u8bbf\u95ee\u6743\u9650\uff1b<br \/>\n<strong> f_pos<\/strong>\uff1a\u5f53\u524d\u8be5\u6587\u4ef6\u7684\u504f\u79fb\u91cf\uff0c\u8bfb\u5199\u64cd\u4f5c\u5747\u4ece\u8be5\u504f\u79fb\u91cf\u5f00\u59cb\uff1b<br \/>\n<strong> f_security<\/strong>\uff1a\u6307\u5411\u6587\u4ef6\u5b89\u5168\u6570\u636e\u7ed3\u6784struct file_security_struct\u7684\u6307\u9488\uff1b<\/p>\n<p>\u6587\u4ef6\u64cd\u4f5c\u7ed3\u6784\u4f53<\/p>\n<p>VFS\u4f7f\u7528struct file_operations\u6765\u63cf\u8ff0\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u64cd\u4f5c\u96c6\u5408\uff0c\u6587\u4ef6\u7ed3\u6784\u4f53\u4e2d\u7684f_op\u5b57\u6bb5\u5c31\u6307\u5411\u8fd9\u79cd\u7ed3\u6784\u4f53\u7c7b\u578b\u3002\u5728\u8fd9\u4e2a\u64cd\u4f5c\u7ed3\u6784\u4f53\u4e2d\uff0c\u6709\u8bb8\u591a\u6211\u4eec\u6240\u719f\u6089\u7684\u51fd\u6570\u6307\u9488\uff0c\u5927\u591a\u6570\u4e0e\u6587\u4ef6\u76f8\u5173\u7684\u7cfb\u7edf\u8c03\u7528\u6700\u7ec8\u4f1a\u8c03\u7528\u8fd9\u91cc\u7684\u51fd\u6570\u3002\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u6253\u5f00\u67d0\u4e2a\u6587\u4ef6\u65f6\uff0c\u8be5\u6587\u4ef6\u7ed3\u6784\u4f53\u4e2d\u7684f_op\u5b57\u6bb5\u662f\u901a\u8fc7\u8be5\u6587\u4ef6inode\u5bf9\u8c61\u4e2d\u7684i_fop\u5b57\u6bb5\u6765\u521d\u59cb\u5316\u7684\u3002\u5728yoursource\/include\/linux\/fs.h\u4e2d\u6709\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7684\u5b9a\u4e49\u3002\u4e0b\u9762\u53ea\u5217\u51fa\u90e8\u5206\u5b57\u6bb5\u7684\u8bf4\u660e\u3002<\/p>\n<pre class=\"brush:c\">1488struct file_operations {\r\n1489        struct module *owner;\r\n1490        loff_t (*llseek) (struct file *, loff_t, int);\r\n1491        ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);\r\n1492        ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);\r\n\u2026\u2026 \u2026\u2026\r\n1499        int (*mmap) (struct file *, struct vm_area_struct *);\r\n1500        int (*open) (struct inode *, struct file *);\r\n1502        int (*release) (struct inode *, struct file *);\r\n\u2026\u2026 \u2026\u2026\r\n1514};<\/pre>\n<p><strong>owner<\/strong>\uff1a\u7528\u4e8e\u6307\u5b9a\u62e5\u6709\u8fd9\u4e2a\u6587\u4ef6\u64cd\u4f5c\u7ed3\u6784\u4f53\u7684\u6a21\u5757\uff0c\u901a\u5e38\u53d6THIS_MODULE\uff1b<br \/>\n<strong> llseek<\/strong>\uff1a\u7528\u4e8e\u8bbe\u7f6e\u6587\u4ef6\u7684\u504f\u79fb\u91cf\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u660e\u8981\u64cd\u4f5c\u7684\u6587\u4ef6\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u504f\u79fb\u91cf\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u4e3a\u5f00\u59cb\u504f\u79fb\u7684\u4f4d\u7f6e\uff08\u53ef\u53d6SEEK_SET,SEEK_CUR\u548cSEEK_END\u4e4b\u4e00\uff09\u3002<br \/>\n<strong> read<\/strong>\uff1a\u4ece\u6587\u4ef6\u4e2d\u8bfb\u6570\u636e\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u6e90\u6587\u4ef6\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u76ee\u7684\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u6307\u660e\u6b32\u8bfb\u6570\u636e\u7684\u603b\u5b57\u8282\u6570\uff0c\u7b2c\u56db\u4e2a\u53c2\u6570\u6307\u660e\u4ece\u6e90\u6587\u4ef6\u7684\u67d0\u4e2a\u504f\u79fb\u91cf\u5904\u5f00\u59cb\u8bfb\u6570\u636e\u3002\u7531\u7cfb\u7edf\u8c03\u7528read()\u8c03\u7528\uff1b<br \/>\n<strong> write<\/strong>\uff1a\u5f80\u6587\u4ef6\u91cc\u5199\u6570\u636e\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u76ee\u7684\u6587\u4ef6\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6e90\u5b57\u7b26\u4e32\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u6307\u660e\u6b32\u5199\u6570\u636e\u7684\u603b\u5b57\u8282\u6570\uff0c\u7b2c\u56db\u4e2a\u53c2\u6570\u6307\u660e\u4ece\u76ee\u7684\u6587\u4ef6\u7684\u67d0\u4e2a\u504f\u79fb\u91cf\u51fa\u5f00\u59cb\u5199\u6570\u636e\u3002\u7531\u7cfb\u7edf\u8c03\u7528write()\u8c03\u7528\uff1b<br \/>\n<strong> mmap<\/strong>\uff1a\u5c06\u6307\u5b9a\u6587\u4ef6\u6620\u5c04\u5230\u6307\u5b9a\u7684\u5730\u5740\u7a7a\u95f4\u4e0a\u3002\u7531\u7cfb\u7edf\u8c03\u7528mmap()\u8c03\u7528\uff1b<br \/>\nopen\uff1a\u6253\u5f00\u6307\u5b9a\u6587\u4ef6\uff0c\u5e76\u4e14\u5c06\u8fd9\u4e2a\u6587\u4ef6\u548c\u6307\u5b9a\u7684\u7d22\u5f15\u7ed3\u70b9\u5173\u8054\u8d77\u6765\u3002\u7531\u7cfb\u7edf\u8c03\u7528open()\u8c03\u7528\uff1b<br \/>\n<strong> release<\/strong>\uff1a\u91ca\u653e\u4ee5\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u5f53\u6253\u5f00\u6587\u4ef6\u7684\u5f15\u7528\u8ba1\u6570\uff08f_count\uff09\u4e3a0\u65f6\uff0c\u8be5\u51fd\u6570\u88ab\u8c03\u7528\uff1b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6d89\u53caVFS\u4e2d\u7684\u6570\u636e\u7ed3\u6784\u6709\uff1astruct super_block;struct inode;struct d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110],"tags":[174,404,176],"class_list":["post-1984","post","type-post","status-publish","format-standard","hentry","category-linux","tag-vfs","tag-404","tag-176"],"views":10043,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=1984"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/1984\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=1984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=1984"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=1984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}