{"id":263820,"date":"2023-02-09T06:21:23","date_gmt":"2023-02-08T22:21:23","guid":{"rendered":"https:\/\/lrxjmw.cn\/ljczsxnwjxtd.html"},"modified":"2023-02-09T06:21:23","modified_gmt":"2023-02-08T22:21:23","slug":"ljczsxnwjxtd","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ljczsxnwjxtd.html","title":{"rendered":"\u3010Linux\u57fa\u7840\u77e5\u8bc6\u3011\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\u7684\u534f\u540c\u5173\u7cfb\u6587\u4ef6\uff08\u4e8c\uff09"},"content":{"rendered":"
1\u3001\u6982\u8ff0<\/p>\n
\u865a\u62df\u6587\u4ef6\u7cfb\u7edf<\/a>(VFS\uff0cvirtual filesystem),\u662f\u4e00\u4e2a\u5185\u6838\u8f6f\u4ef6\u5c42\uff0c\u662f\u7269\u7406\u6587\u4ef6\u7cfb\u7edf\u4e0e\u670d\u52a1\u4e4b\u95f4\u7684\u4e00\u4e2a\u63a5\u53e3\u5c42\uff0c\u5b83\u5bf9Linux<\/a>\u7684\u6bcf\u4e2a\u6587\u4ef6\u7cfb\u7edf\u7684\u6240\u6709\u7ec6\u8282\u8fdb\u884c\u62bd\u8c61\uff0c\u4f7f\u5f97\u4e0d\u540c\u7684\u6587\u4ef6\u7cfb\u7edf\u5728Linux\u6838\u5fc3\u4ee5\u53ca\u7cfb\u7edf\u4e2d\u8fd0\u884c\u7684\u5176\u4ed6\u8fdb\u7a0b\u770b\u6765\uff0c\u90fd\u662f\u76f8\u540c\u7684\u3002\u4e25\u683c\u8bf4\u6765linux \u8bba\u575b\uff0cVFS\u5e76\u4e0d\u662f\u4e00\u79cd\u5b9e\u9645\u7684\u6587\u4ef6\u7cfb\u7edf\u3002\u5b83\u53ea\u5b58\u5728\u4e8e\u5185\u5b58\u4e2d\uff0c\u4e0d\u5b58\u5728\u4e8e\u4efb\u4f55\u5916\u5b58\u7a7a\u95f4\u3002VFS\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u5efa\u7acb\uff0c\u5728\u7cfb\u7edf\u5173\u95ed\u65f6\u6d88\u4ea1\u3002<\/p>\n VFS\u652f\u6301\u6587\u4ef6\u7cfb\u7edf\u4e3b\u8981\u6709\u4e09\u79cd\u7c7b\u578b\uff1a<\/p>\n \u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\uff1a\u7ba1\u7406\u672c\u5730\u78c1\u76d8\u5206\u533a\u4e2d\u53ef\u7528\u7684\u5b58\u50a8\u7a7a\u95f4\u6216\u8005\u5176\u4ed6\u53ef\u4ee5\u8d77\u5230\u78c1\u76d8\u4f5c\u7528\u7684\u7684\u8bbe\u5907(USB\u95ea\u5b58)\u3002\u5e38\u89c1\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u6709Ext2\uff0cExt3\uff0cSystemV\uff0cBSD\uff0c\u7b49\u3002\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf: \u8bbf\u95ee\u5c5e\u4e8e\u5176\u4ed6\u7f51\u7edc\u8ba1\u7b97\u673a\u7684\u6587\u4ef6\u7cfb\u7edf\u6240\u5305\u542b\u7684\u6587\u4ef6\u3002\u5e38\u7528\u7684\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\u6709NFS\uff0cAFS\uff0cCIFS\uff0c\u7b49\u3002\u7279\u6b8a\u6587\u4ef6\u7cfb\u7edf\uff1a\u4e0d\u7ba1\u7406\u672c\u5730\u6216\u8005\u8fdc\u7a0b\u78c1\u76d8\u7a7a\u95f4\u3002\/proc\u6587\u4ef6\u7cfb\u7edf\u662f\u7279\u6b8a\u6587\u4ef6\u7cfb\u7edf\u7684\u4e00\u4e2a\u5178\u578b\u7684\u8303\u4f8b\u3002<\/p>\n <\/p>\n \u56fe\u7247\u793a\u4f8b_VFS\u5728\u5185\u6838\u4e2d\u4e0e\u5176\u4ed6\u7684\u5185\u6838\u6a21\u5757\u7684\u534f\u540c\u5173\u7cfb<\/p>\n \u6587\u4ef6\uff1a \u4e00\u7ec4\u5728\u903b\u8f91\u4e0a\u5177\u6709\u5b8c\u6574\u610f\u4e49\u7684\u4fe1\u606f\u9879\u7684\u7cfb\u5217\u3002\u5728Linux\u4e2d\uff0c\u9664\u4e86\u666e\u901a\u6587\u4ef6\uff0c\u5176\u4ed6\u8bf8\u5982\u76ee\u5f55\u3001\u8bbe\u5907\u3001\u5957\u63a5\u5b57\u7b49 \u4e5f\u4ee5\u6587\u4ef6\u88ab\u5bf9\u5f85\u3002\u603b\u4e4b\uff0c\u201c\u4e00\u5207\u7686\u6587\u4ef6\u201d\u3002<\/p>\n \u76ee\u5f55\uff1a \u76ee\u5f55\u597d\u6bd4\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u7528\u6765\u5bb9\u7eb3\u76f8\u5173\u6587\u4ef6\u3002\u56e0\u4e3a\u76ee\u5f55\u53ef\u4ee5\u5305\u542b\u5b50\u76ee\u5f55\uff0c\u6240\u4ee5\u76ee\u5f55\u662f\u53ef\u4ee5\u5c42\u5c42\u5d4c\u5957\uff0c\u5f62\u6210\u6587\u4ef6\u8def\u5f84\u3002\u5728Linux\u4e2d\uff0c\u76ee\u5f55\u4e5f\u662f\u4ee5\u4e00\u79cd\u7279\u6b8a\u6587\u4ef6\u88ab\u5bf9\u5f85\u7684\uff0c\u6240\u4ee5\u7528\u4e8e\u6587\u4ef6\u7684\u64cd\u4f5c\u540c\u6837\u4e5f\u53ef\u4ee5\u7528\u5728\u76ee\u5f55\u4e0a\u3002<\/p>\n \u76ee\u5f55\u9879\uff1a \u5728\u4e00\u4e2a\u6587\u4ef6\u8def\u5f84\u4e2d\uff0c\u8def\u5f84\u4e2d\u7684\u6bcf\u4e00\u90e8\u5206\u90fd\u88ab\u79f0\u4e3a\u76ee\u5f55\u9879\uff1b\u5982\u8def\u5f84\/home\/source\/helloworld.c\u4e2d\uff0c\u76ee\u5f55 \/, home, source\u548c\u6587\u4ef6 helloworld.c\u90fd\u662f\u4e00\u4e2a\u76ee\u5f55\u9879\u3002<\/p>\n \u7d22\u5f15\u8282\u70b9\uff1a \u7528\u4e8e\u5b58\u50a8\u6587\u4ef6\u7684\u5143\u6570\u636e\u7684\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u3002\u6587\u4ef6\u7684\u5143\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u6587\u4ef6\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u548c\u6587\u4ef6\u672c\u8eab\u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u6982\u5ff5\u3002\u5b83\u5305\u542b\u7684\u662f\u8bf8\u5982\u6587\u4ef6\u7684\u5927\u5c0f\u3001\u62e5\u6709\u8005\u3001\u521b\u5efa\u65f6\u95f4\u3001\u78c1\u76d8\u4f4d\u7f6e\u7b49\u548c\u6587\u4ef6\u76f8\u5173\u7684\u4fe1\u606f\u3002<\/p>\n \u8d85\u7ea7\u5757\uff1a \u7528\u4e8e\u5b58\u50a8\u6587\u4ef6\u7cfb\u7edf\u7684\u63a7\u5236\u4fe1\u606f\u7684\u6570\u636e\u7ed3\u6784\u3002\u63cf\u8ff0\u6587\u4ef6\u7cfb\u7edf\u7684\u72b6\u6001\u3001\u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b\u3001\u5927\u5c0f\u3001\u533a\u5757\u6570\u3001\u7d22\u5f15\u8282 \u70b9\u6570\u7b49\uff0c\u5b58\u653e\u4e8e\u78c1\u76d8\u7684\u7279\u5b9a\u6247\u533a\u4e2d\u3002<\/p>\n \u5982\u4e0a\u7684\u51e0\u4e2a\u6982\u5ff5\u5728\u78c1\u76d8\u4e2d\u7684\u4f4d\u7f6e\u5173\u7cfb\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n \u78c1\u76d8\u4e0e\u6587\u4ef6\u7cfb\u7edf<\/p>\n <\/p>\n \u56fe\u7247\u793a\u4f8b_\u78c1\u76d8\u4e0e\u6587\u4ef6\u7cfb\u7edf.jpg<\/p>\n \u5173\u4e8e\u6587\u4ef6\u7cfb\u7edf\u7684\u4e09\u4e2a\u6613\u6df7\u6dc6\u7684\u6982\u5ff5\uff1a<\/p>\n \u521b\u5efa\uff1a \u4ee5\u67d0\u79cd\u65b9\u5f0f\u683c\u5f0f\u5316\u78c1\u76d8\u7684\u8fc7\u7a0b\u5c31\u662f\u5728\u5176\u4e4b\u4e0a\u5efa\u7acb\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u7684\u8fc7\u7a0b\u3002\u521b\u5efa\u6587\u73b0\u7cfb\u7edf\u65f6\uff0c\u4f1a\u5728\u78c1\u76d8\u7684\u7279\u5b9a\u4f4d\u7f6e\u5199\u5165\u5173\u4e8e\u8be5\u6587\u4ef6\u7cfb\u7edf\u7684\u63a7\u5236\u4fe1\u606f\u3002<\/p>\n **\u6ce8\u518c\uff1a **\u5411\u5185\u6838\u62a5\u5230\uff0c\u58f0\u660e\u81ea\u5df1\u80fd\u88ab\u5185\u6838\u652f\u6301\u3002\u4e00\u822c\u5728\u7f16\u8bd1\u5185\u6838\u7684\u65f6\u4faf\u6ce8\u518c\uff1b\u4e5f\u53ef\u4ee5\u52a0\u8f7d\u6a21\u5757\u7684\u65b9\u5f0f\u624b\u52a8\u6ce8\u518c\u3002\u6ce8\u518c\u8fc7\u7a0b\u5b9e\u9645\u4e0a\u662f\u5c06\u8868\u793a\u5404\u5b9e\u9645\u6587\u4ef6\u7cfb\u7edf\u7684\u6570\u636e\u7ed3\u6784struct file_system_type \u5b9e\u4f8b\u5316\u3002<\/p>\n \u5b89\u88c5\uff1a \u4e5f\u5c31\u662f\u6211\u4eec\u719f\u6089\u7684mount\u64cd\u4f5c\uff0c\u5c06\u6587\u4ef6\u7cfb\u7edf\u52a0\u5165\u5230Linux\u7684\u6839\u6587\u4ef6\u7cfb\u7edf\u7684\u76ee\u5f55\u6811\u7ed3\u6784\u4e0a\uff1b\u8fd9\u6837\u6587\u4ef6\u7cfb\u7edf\u624d\u80fd\u88ab\u8bbf\u95ee\u3002<\/p>\n 2\u3001\u901a\u7528\u6587\u4ef6\u6a21\u578b<\/p>\n \u524d\u8fb9\u63d0\u5230\uff0cVFS\u5bf9Linux\u7684\u6bcf\u4e2a\u6587\u4ef6\u7cfb\u7edf\u7684\u6240\u6709\u7ec6\u8282\u8fdb\u884c\u62bd\u8c61\uff0c\u4f7f\u5f97\u4e0d\u540c\u7684\u6587\u4ef6\u7cfb\u7edf\u5728Linux\u6838\u5fc3\u4ee5\u53ca\u7cfb\u7edf\u4e2d\u8fd0\u884c\u7684\u5176\u4ed6\u8fdb\u7a0b\u770b\u6765\uff0c\u90fd\u662f\u76f8\u540c\u7684\u3002\u628a\u8fd9\u4e2a\u62bd\u8c61\u7684\u7ed3\u6784\u79f0\u4e3a\u901a\u7528\u6587\u4ef6\u6a21\u578b\u3002\u5728\u901a\u7528\u6587\u4ef6\u6a21\u578b\u4e2d\uff0c\u6bcf\u4e2a\u76ee\u5f55\u90fd\u88ab\u770b\u505a\u662f\u4e00\u4e2a\u6587\u4ef6\uff0c\u53ef\u4ee5\u5305\u542b\u82e5\u5e72\u76ee\u5f55\u548c\u6587\u4ef6\u3002<\/p>\n \u901a\u7528\u6587\u4ef6\u6a21\u578b\u7531\u4e0b\u5217\u5bf9\u8c61\u7ec4\u6210\uff1a<\/p>\n \u5b58\u653e\u5df2\u5b89\u88c5\u6587\u4ef6\u7cfb\u7edf\u7684\u6709\u5173\u4fe1\u606f\uff0c\u5bf9\u57fa\u4e8e\u78c1\u76d8\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u8fd9\u7c7b\u5bf9\u8c61\u901a\u5e38\u5bf9\u5e94\u4e8e\u5b58\u653e\u5728\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u7cfb\u7edf\u7684\u63a7\u5236\u5757(filesystem contorl block).<\/p>\n \u5b58\u653e\u5173\u4e8e\u5177\u4f53\u6587\u4ef6\u7684\u4e00\u822c\u4fe1\u606f\uff0c\u5bf9\u57fa\u4e8e\u78c1\u76d8\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u8fd9\u7c7b\u5bf9\u8c61\u901a\u5e38\u5bf9\u5e94\u4e8e\u5b58\u653e\u5728\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u63a7\u5236\u5757(file contorl block),\u6bcf\u4e2a\u7d22\u5f15\u8282\u70b9\uff0c\u90fd\u6709\u4e00\u4e2a\u7d22\u5f15\u8282\u70b9\u53f7\uff0c\u8fd9\u4e2a\u8282\u70b9\u53f7\uff0c\u552f\u4e00\u7684\u6807\u8bc6\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u3002<\/p>\n \u5b58\u653e\u76ee\u5f55\u9879(\u6587\u4ef6\u7684\u7279\u5b9a\u540d\u79f0)\u4e0e\u5bf9\u5e94\u6587\u4ef6\u8fdb\u884c\u94fe\u63a5\u7684\u6709\u5173\u4fe1\u606f\u3002\u6bcf\u4e2a\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u90fd\u4ee5\u81ea\u5df1\u7279\u6709\u7684\u65b9\u5f0f\u5c06\u8be5\u4fe1\u606f\u5b58\u5728\u78c1\u76d8\u4e0a\u3002<\/p>\n \u5b58\u653e\u6253\u5f00\u6587\u4ef6\u4e0e\u8fdb\u7a0b\u4e4b\u95f4\u8fdb\u884c\u7684\u4ea4\u4e92\u7684\u6709\u5173\u4fe1\u606f\uff0c\u8fd9\u7c7b\u4fe1\u606f\u4ec5\u5f53\u8fdb\u7a0b\u8bbf\u95ee\u6587\u4ef6\u671f\u95f4\u5b58\u5728\u4e8e\u5185\u6838\u5185\u5b58\u4e2d\u3002<\/p>\n \u5b83\u5c5e\u4e8e\u78c1\u76d8\u9ad8\u901f\u7f13\u5b58\uff0c\u7528\u4e8e\u5b58\u653e\u6700\u8fd1\u6700\u5e38\u4f7f\u7528\u7684\u76ee\u5f55\u9879\u5bf9\u8c61\u3002\u4ee5\u52a0\u901f\u4ece\u6587\u4ef6\u8def\u5f84\u540d\u5230\u6700\u540e\u4e00\u4e2a\u8def\u5f84\u5206\u91cf\u7684\u7d22\u5f15\u8282\u70b9\u7684\u8f6c\u6362\u8fc7\u7a0b\u3002<\/p>\n \u5982\u4e0b\u56fe\uff0c\u8bf4\u660e\u8fdb\u7a0b\u600e\u6837\u548c\u6587\u4ef6\u8fdb\u884c\u4ea4\u4e92\u3002\u4e09\u4e2a\u4e0d\u540c\u7684\u8fdb\u7a0bwps for linux\uff0c\u6253\u5f00\u540c\u4e00\u4e2a\u6587\u4ef6\uff0c\u5176\u4e2d\uff0c\u4e24\u4e2a\u8fdb\u7a0b\u4f7f\u7528\u540c\u4e00\u4e2a\u786c\u94fe\u63a5\u3002\u5728\u8fd9\u4e2d\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u4f7f\u7528\u81ea\u5df1\u7684\u6587\u4ef6\u5bf9\u8c61\uff0c\u5355\u53ea\u9700\u89812\u4e2a\u76ee\u5f55\u9879\u5bf9\u8c61\uff0c\u6bcf\u4e2a\u786c\u94fe\u63a5\u5bf9\u5e94\u4e00\u4e2a\u76ee\u5f55\u9879\u5bf9\u8c61\uff0c\u8fd92\u4e2a\u76ee\u5f55\u9879\u5bf9\u8c61\u6307\u5411\u540c\u4e00\u4e2a\u7d22\u5f15\u8282\u70b9\u5bf9\u8c61\uff0c\u8be5\u7d22\u5f15\u8282\u70b9\u5bf9\u8c61\u6807\u8bc6\u8d85\u7ea7\u5757\u5bf9\u8c61\uff0c\u4ee5\u53ca\u968f\u540e\u7684\u666e\u901a\u78c1\u76d8\u6587\u4ef6\u3002<\/p>\n <\/p>\n image<\/p>\n 3\u3001VFS\u6570\u636e\u7ed3\u6784 3.1\u8d85\u7ea7\u5bf9\u8c61\u5757<\/p>\n \u8d85\u7ea7\u5bf9\u8c61\u5757\u7528\u6765\u5b58\u50a8\u4e00\u4e2a\u5df2\u5b89\u88c5\u7684\u6587\u4ef6\u7cfb\u7edf\u7684\u63a7\u5236\u4fe1\u606f\uff0c\u4ee3\u8868\u4e00\u4e2a\u5df2\u5b89\u88c5\u7684\u6587\u4ef6\u7cfb\u7edf\uff1b\u6bcf\u6b21\u4e00\u4e2a\u5b9e\u9645\u7684\u6587\u4ef6\u7cfb\u7edf\u88ab\u5b89\u88c5\u65f6\uff0c\u5185\u6838\u4f1a\u4ece\u78c1\u76d8\u7684\u7279\u5b9a\u4f4d\u7f6e\u8bfb\u53d6\u4e00\u4e9b\u63a7\u5236\u4fe1\u606f\u6765\u586b\u5145\u5185\u5b58\u4e2d\u7684\u8d85\u7ea7\u5757\u5bf9\u8c61\u3002\u4e00\u4e2a\u5b89\u88c5\u5b9e\u4f8b\u548c\u4e00\u4e2a\u8d85\u7ea7\u5757\u5bf9\u8c61\u4e00\u4e00\u5bf9\u5e94\u3002 \u8d85\u7ea7\u5757\u901a\u8fc7\u5176\u7ed3\u6784\u4e2d\u7684\u4e00\u4e2a\u57dfs_type\u8bb0\u5f55\u5b83\u6240\u5c5e\u7684\u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b\u3002\u5176\u7ed3\u6784\u5982\u4e0b<\/p>\n struct super_block {<\/p>\n struct list_head s_list;\/* \u6307\u5411\u6240\u6709\u8d85\u7ea7\u5757\u7684\u94fe\u8868 *\/<\/p>\n dev_t s_dev;\/* \u8bbe\u5907\u6807\u8bc6\u7b26 *\/<\/p>\n unsigned char s_dirt;\/* \u4fee\u6539\uff08\u810f\uff09\u6807\u5fd7*\/<\/p>\n unsigned char s_blocksize_bits;\/* \u4ee5\u4f4d\u4e3a\u5355\u4f4d\u7684\u5757\u7684\u5927\u5c0f *\/<\/p>\n unsigned long s_blocksize;\/* \u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u7684\u5757\u7684\u5927\u5c0f *\/<\/p>\n loff_t s_maxbytes;\/* \u6587\u4ef6\u5927\u5c0f\u4e0a\u9650 *\/<\/p>\n struct file_system_type s_type;\/ \u6587\u4ef6\u7cfb\u7edf\u7c7b\u578b *\/<\/p>\n const struct super_operations s_op;\/ \u8d85\u7ea7\u5757\u65b9\u6cd5 *\/<\/p>\n const struct dquot_operations dq_op;\/ \u78c1\u76d8\u9650\u989d\u65b9\u6cd5 *\/<\/p>\n const struct quotactl_ops s_qcop;\/ \u9650\u989d\u63a7\u5236\u65b9\u6cd5 *\/<\/p>\n const struct export_operations s_export_op;\/ \u5bfc\u51fa\u65b9\u6cd5 *\/<\/p>\n unsigned long s_flags;\/* \u6302\u8f7d\u6807\u5fd7 *\/<\/p>\n unsigned long s_magic;\/* \u6587\u4ef6\u7cfb\u7edf\u7684\u5e7b\u6570 *\/<\/p>\n struct dentry s_root;\/ \u76ee\u5f55\u6302\u8f7d\u70b9 *\/<\/p>\n struct rw_semaphore s_umount;\/* \u5378\u8f7d\u4fe1\u53f7\u91cf *\/<\/p>\n struct mutex s_lock;\/* \u8d85\u7ea7\u5757\u4fe1\u53f7\u91cf *\/<\/p>\n int s_count;\/* \u8d85\u7ea7\u5757\u5f15\u7528\u8ba1\u6570 *\/<\/p>\n <\/p>\n atomic_t s_active;\/* \u6d3b\u52a8\u5f15\u7528\u8ba1\u6570 *\/<\/p>\n void s_security;\/ \u5b89\u5168\u6a21\u5757 *\/<\/p>\n const struct xattr_handler *s_xattr;\/ \u6269\u5c55\u7684\u5c5e\u6027\u64cd\u4f5c *\/<\/p>\n struct list_head s_inodes;\/* inodes \u94fe\u8868 *\/<\/p>\n struct hlist_head s_anon;\/* \u533f\u540d\u76ee\u5f55\u9879 *\/<\/p>\n struct list_head s_files;\/* \u88ab\u5206\u914d\u6587\u4ef6\u5217\u8868 *\/<\/p>\n struct list_head s_dentry_lru;\/* \u672a\u4f7f\u7528\u76ee\u5f55\u9879\u94fe\u8868 *\/<\/p>\n int s_nr_dentry_unused;\/* \u94fe\u8868\u4e2d\u76ee\u5f55\u9879\u7684\u6570\u76ee *\/<\/p>\n struct block_device s_bdev;\/ \u76f8\u5173\u7684\u5757\u6587\u4ef6 *\/<\/p>\n struct backing_dev_info s_bdi;\/ *\/<\/p>\n struct mtd_info s_mtd;\/ \u5b58\u50a8\u78c1\u76d8\u4fe1\u606f *\/<\/p>\n struct list_head s_instances;\/* \u8be5\u6587\u4ef6\u7c7b\u578b\u7cfb\u7edf *\/<\/p>\n struct quota_info s_dquot;\/* \u9650\u989d\u76f8\u5173\u9009\u9879 *\/<\/p>\n int s_frozen;\/* frozen\u6807\u5fd7\u4f4d *\/<\/p>\n wait_queue_head_t s_wait_unfrozen;\/* \u51bb\u7ed3\u7684\u7b49\u5f85\u961f\u5217 *\/<\/p>\n char s_id[32];\/* \u6587\u672c\u540d\u5b57 *\/<\/p>\n void s_fs_info;\/ \u6587\u4ef6\u7cfb\u7edf\u7279\u6b8a\u4fe1\u606f *\/<\/p>\n fmode_t s_mode;\/* \u5b89\u88c5\u6743\u9650 *\/<\/p>\n u32 s_time_gran;\/* \u65f6\u95f4\u6233\u7c92\u5ea6 *\/<\/p>\n struct mutex s_vfs_rename_mutex;\/* \u91cd\u547d\u540d\u4fe1\u53f7\u91cf *\/<\/p>\n char s_subtype;\/ \u5b50\u7c7b\u578b\u540d\u79f0 *\/<\/p>\n char s_options;\/ \u5df2\u5b58\u5b89\u88c5\u9009\u9879 *\/<\/p>\n };<\/p>\n 3.2\u7d22\u5f15\u8282\u70b9\u5bf9\u8c61<\/p>\n \u7d22\u5f15\u8282\u70b9\u5bf9\u8c61\u5b58\u50a8\u4e86\u6587\u4ef6\u7684\u76f8\u5173\u4fe1\u606flinux\u865a\u62df\u6587\u4ef6\u7cfb\u7edf<\/strong>\uff0c\u4ee3\u8868\u4e86\u5b58\u50a8\u8bbe\u5907\u4e0a\u7684\u4e00\u4e2a\u5b9e\u9645\u7684\u7269\u7406\u6587\u4ef6\u3002\u5f53\u4e00\u4e2a \u6587\u4ef6\u9996\u6b21\u88ab\u8bbf\u95ee\u65f6\uff0c\u5185\u6838\u4f1a\u5728\u5185\u5b58\u4e2d\u7ec4\u88c5\u76f8\u5e94\u7684\u7d22\u5f15\u8282\u70b9\u5bf9\u8c61\uff0c\u4ee5\u4fbf\u5411\u5185\u6838\u63d0\u4f9b\u5bf9\u4e00\u4e2a\u6587\u4ef6\u8fdb\u884c\u64cd \u4f5c\u65f6\u6240\u5fc5\u9700\u7684\u5168\u90e8\u4fe1\u606f\uff1b\u8fd9\u4e9b\u4fe1\u606f\u4e00\u90e8\u5206\u5b58\u50a8\u5728\u78c1\u76d8\u7279\u5b9a\u4f4d\u7f6e\uff0c\u53e6\u5916\u4e00\u90e8\u5206\u662f\u5728\u52a0\u8f7d\u65f6\u52a8\u6001\u586b\u5145\u7684\u3002<\/p>\n \n <\/code><\/p>\n 3.3\u76ee\u5f55\u9879\u5bf9\u8c61<\/p>\n \u5f15\u5165\u76ee\u5f55\u9879\u7684\u6982\u5ff5\u4e3b\u8981\u662f\u51fa\u4e8e\u65b9\u4fbf\u67e5\u627e\u6587\u4ef6\u7684\u76ee\u7684\u3002\u4e00\u4e2a\u8def\u5f84\u7684\u5404\u4e2a\u7ec4\u6210\u90e8\u5206\uff0c\u4e0d\u7ba1\u662f\u76ee\u5f55\u8fd8\u662f\u666e\u901a\u7684\u6587\u4ef6\uff0c\u90fd\u662f\u4e00\u4e2a\u76ee\u5f55\u9879\u5bf9\u8c61\u3002\u5982\uff0c\u5728\u8def\u5f84\/home\/source\/test.c\u4e2dlinux\u865a\u62df\u6587\u4ef6\u7cfb\u7edf<\/strong>\uff0c\u76ee\u5f55 \/, home, source\u548c\u6587\u4ef6 test.c\u90fd\u5bf9\u5e94\u4e00\u4e2a\u76ee\u5f55\u9879\u5bf9\u8c61\u3002\u4e0d\u540c\u4e8e\u524d\u9762\u7684\u4e24\u4e2a\u5bf9\u8c61\uff0c\u76ee\u5f55\u9879\u5bf9\u8c61\u6ca1\u6709\u5bf9\u5e94\u7684\u78c1\u76d8\u6570\u636e\u7ed3\u6784\uff0cVFS\u5728\u904d\u5386\u8def\u5f84\u540d\u7684\u8fc7\u7a0b\u4e2d\u73b0\u573a\u5c06\u5b83\u4eec\u9010\u4e2a\u5730\u89e3\u6790\u6210\u76ee\u5f55\u9879\u5bf9\u8c61\u3002<\/p>\n \n <\/p>\n struct dentry *d_parent; \/\/\u7236\u76ee\u5f55\u7684\u76ee\u5f55\u9879\u5bf9\u8c61\n struct list_head d_hash; \/\/\u6563\u5217\u8868\u8868\u9879\u7684\u6307\u9488\n struct list_head d_lru; \/\/\u672a\u4f7f\u7528\u94fe\u8868\u7684\u6307\u9488\n struct list_head d_child; \/\/\u7236\u76ee\u5f55\u4e2d\u76ee\u5f55\u9879\u5bf9\u8c61\u7684\u94fe\u8868\u7684\u6307\u9488\n struct list_head d_subdirs; \/\/\u5bf9\u76ee\u5f55\u800c\u8a00\uff0c\u8868\u793a\u5b50\u76ee\u5f55\u76ee\u5f55\u9879\u5bf9\u8c61\u7684\u94fe\u8868\n struct list_head d_alias; \/\/\u76f8\u5173\u7d22\u5f15\u8282\u70b9\uff08\u522b\u540d\uff09\u7684\u94fe\u8868\n int d_mounted; \/\/\u5bf9\u4e8e\u5b89\u88c5\u70b9\u800c\u8a00\uff0c\u8868\u793a\u88ab\u5b89\u88c5\u6587\u4ef6\u7cfb\u7edf\u6839\u9879\n struct qstr d_name; \/\/\u6587\u4ef6\u540d\n unsigned long d_time; \/* used by d_revalidate *\/\n struct dentry_operations *d_op; \/\/\u76ee\u5f55\u9879\u65b9\u6cd5\n struct super_block *d_sb; \/\/\u6587\u4ef6\u7684\u8d85\u7ea7\u5757\u5bf9\u8c61\n vunsigned long d_vfs_flags;\n void *d_fsdata; \/\/\u4e0e\u6587\u4ef6\u7cfb\u7edf\u76f8\u5173\u7684\u6570\u636e\n unsigned char d_iname [DNAME_INLINE_LEN]; \/\/\u5b58\u653e\u77ed\u6587\u4ef6\u540d\n};<\/code><\/pre>\n<\/p>\n 3.4\u6587\u4ef6\u5bf9\u8c61<\/p>\n \u6587\u4ef6\u5bf9\u8c61\u662f\u5df2\u6253\u5f00\u7684\u6587\u4ef6\u5728\u5185\u5b58\u4e2d\u7684\u8868\u793a\uff0c\u4e3b\u8981\u7528\u4e8e\u5efa\u7acb\u8fdb\u7a0b\u548c\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u7684\u5bf9\u5e94\u5173\u7cfb\u3002\u5b83\u7531sys_open() \u73b0\u573a\u521b\u5efa\uff0c\u7531sys_close()\u9500\u6bc1\u3002\u6587\u4ef6\u5bf9\u8c61\u548c\u7269\u7406\u6587\u4ef6\u7684\u5173\u7cfb\u6709\u70b9\u50cf\u8fdb\u7a0b\u548c\u7a0b\u5e8f\u7684\u5173\u7cfb\u4e00\u6837\u3002\u5f53\u6211\u4eec\u7ad9\u5728\u7528\u6237\u7a7a\u95f4\u6765\u770b \u5f85VFS\uff0c\u6211\u4eec\u50cf\u662f\u53ea\u9700\u4e0e\u6587\u4ef6\u5bf9\u8c61\u6253\u4ea4\u9053\uff0c\u800c\u65e0\u987b\u5173\u5fc3\u8d85\u7ea7\u5757\uff0c\u7d22\u5f15\u8282\u70b9\u6216\u76ee\u5f55\u9879\u3002\u56e0\u4e3a\u591a\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u540c\u65f6\u6253\u5f00\u548c\u64cd\u4f5c \u540c\u4e00\u4e2a\u6587\u4ef6\uff0c\u6240\u4ee5\u540c\u4e00\u4e2a\u6587\u4ef6\u4e5f\u53ef\u80fd\u5b58\u5728\u591a\u4e2a\u5bf9\u5e94\u7684\u6587\u4ef6\u5bf9\u8c61\u3002\u6587\u4ef6\u5bf9\u8c61\u4ec5\u4ec5\u5728\u8fdb\u7a0b\u89c2\u70b9\u4e0a\u4ee3\u8868\u5df2\u7ecf\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u5b83 \u53cd\u8fc7\u6765\u6307\u5411\u76ee\u5f55\u9879\u5bf9\u8c61\uff08\u53cd\u8fc7\u6765\u6307\u5411\u7d22\u5f15\u8282\u70b9\uff09\u3002\u4e00\u4e2a\u6587\u4ef6\u5bf9\u5e94\u7684\u6587\u4ef6\u5bf9\u8c61\u53ef\u80fd\u4e0d\u662f\u60df\u4e00\u7684\uff0c\u4f46\u662f\u5176\u5bf9\u5e94\u7684\u7d22\u5f15\u8282\u70b9\u548c \u76ee\u5f55\u9879\u5bf9\u8c61\u65e0\u7591\u662f\u60df\u4e00\u7684\u3002<\/p>\n \n <\/code><\/p>\n \n \u8bbf\u95ee\u5c5e\u4e8e\u5176\u4ed6\u7f51\u7edc\u8ba1\u7b97\u673a\u7684\u6587\u4ef6\u7cfb\u7edf\u6240\u5305\u542b\u7684\u6587\u4ef6\u3002\u7279\u6b8a\u6587\u4ef6\u7cfb\u7edf\uff1a\u4e0d\u7ba1\u7406\u672c\u5730\u6216\u8005\u8fdc\u7a0b\u78c1\u76d8\u7a7a\u95f4\u3002\u521b\u5efa\u6587\u73b0\u7cfb\u7edf\u65f6\uff0c\u4f1a\u5728\u78c1\u76d8\u7684\u7279\u5b9a\u4f4d\u7f6e\u5199\u5165\u5173\u4e8e\u8be5\u6587\u4ef6\u7cfb\u7edf\u7684\u63a7\u5236\u4fe1\u606f\u3002block),\u6bcf\u4e2a\u7d22\u5f15\u8282\u70b9\uff0c\u90fd\u6709\u4e00\u4e2a\u7d22\u5f15\u8282\u70b9\u53f7\uff0c\u8fd9\u4e2a\u8282\u70b9\u53f7\uff0c\u552f\u4e00\u7684\u6807\u8bc6\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u3002\u6bcf\u4e2a\u78c1\u76d8\u6587\u4ef6\u7cfb\u7edf\u90fd\u4ee5\u81ea\u5df1\u7279\u6709\u7684\u65b9\u5f0f\u5c06\u8be5\u4fe1\u606f\u5b58\u5728\u78c1\u76d8\u4e0a\u3002\u7d22\u5f15\u8282\u70b9\u5bf9\u8c61\u5b58\u50a8\u4e86\u6587\u4ef6\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u4ee3\u8868\u4e86\u5b58\u50a8\u8bbe\u5907\u4e0a\u7684\u4e00\u4e2a\u5b9e\u9645\u7684\u7269\u7406\u6587\u4ef6\u3002<\/p>\n","protected":false},"author":1,"featured_media":263821,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-263820","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=263820"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/263820\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/263821"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=263820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=263820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=263820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}struct inode { \/\/........ unsigned long i_ino; \/\/\u8282\u70b9\u53f7 atomic_t i_count; \/\/\u5f15\u7528\u8ba1\u6570 \/\/........ uid_t i_uid; \/\/\u4f7f\u7528\u8005id gid_t i_gid; \/\/\u4f7f\u7528\u8005id\u7ec4 \/\/........ struct timespec i_atime; \/\/\u6700\u540e\u8bbf\u95ee\u65f6\u95f4 struct timespec i_mtime; \/\/\u6700\u540e\u4fee\u6539(modify)\u65f6\u95f4 struct timespec i_ctime; \/\/\u6700\u540e\u6539\u53d8(change)\u65f6\u95f4 unsigned long i_blocks; \/\/\u6587\u4ef6\u7684\u5757\u6570 unsigned short i_bytes; \/\/\u4f7f\u7528\u7684\u5b57\u8282\u6570 unsigned long i_state; \/\/\u72b6\u6001\u6807\u5fd7 struct list_head i_devices; \/\/\u5757\u8bbe\u5907\u94fe\u8868 unsigned char i_sock; \/\/\u662f\u5426\u5957\u63a5\u5b57 atomic_t i_writecount; \/\/\u5199\u8005\u8ba1\u6570 \/\/........ };<\/pre>\n
struct dentry {\n atomic_t d_count; \/\/\u76ee\u5f55\u9879\u5bf9\u8c61\u4f7f\u7528\u8ba1\u6570\u5668,\u53ef\u4ee5\u6709\u672a\u4f7f\u7528\u6001,\u4f7f\u7528\u6001\u548c\u8d1f\u72b6\u6001 \n unsigned int d_flags; \/\/\u76ee\u5f55\u9879\u6807\u5fd7\n struct inode *d_inode; \/\/\u4e0e\u6587\u4ef6\u540d\u5173\u8054\u7684\u7d22\u5f15\u8282\u70b9\n
struct file { union { struct list_head fu_list; \/\/\u6587\u4ef6\u5bf9\u8c61\u94fe\u8868\u6307\u9488linux\/include\/linux\/list.h struct rcu_head fu_rcuhead; \/\/RCU(Read-Copy Update)\u662fLinux 2.6\u5185\u6838\u4e2d\u65b0\u7684\u9501\u673a\u5236 } f_u; struct path f_path; \/\/\u5305\u542bdentry\u548cmnt\u4e24\u4e2a\u6210\u5458\uff0c\u7528\u4e8e\u786e\u5b9a\u6587\u4ef6\u8def\u5f84 #define f_dentry f_path.dentry \/\/f_path\u7684\u6210\u5458\u4e4b\u4e00\uff0c\u5f53\u524d\u6587\u4ef6\u7684dentry\u7ed3\u6784 #define f_vfsmnt f_path.mnt \/\/\u8868\u793a\u5f53\u524d\u6587\u4ef6\u6240\u5728\u6587\u4ef6\u7cfb\u7edf\u7684\u6302\u8f7d\u6839\u76ee\u5f55 const struct file_operations *f_op; \/\/\u4e0e\u8be5\u6587\u4ef6\u76f8\u5173\u8054\u7684\u64cd\u4f5c\u51fd\u6570 atomic_t f_count; \/\/\u6587\u4ef6\u7684\u5f15\u7528\u8ba1\u6570\uff08\u6709\u591a\u5c11\u8fdb\u7a0b\u6253\u5f00\u8be5\u6587\u4ef6\uff09 unsigned int f_flags; \/\/\u5bf9\u5e94\u4e8eopen\u65f6\u6307\u5b9a\u7684flag mode_t f_mode; \/\/\u8bfb\u5199\u6a21\u5f0f\uff1aopen\u7684mod_t mode\u53c2\u6570 off_t f_pos; \/\/\u8be5\u6587\u4ef6\u5728\u5f53\u524d\u8fdb\u7a0b\u4e2d\u7684\u6587\u4ef6\u504f\u79fb\u91cf struct fown_struct f_owner; \/\/\u8be5\u7ed3\u6784\u7684\u4f5c\u7528\u662f\u901a\u8fc7\u4fe1\u53f7\u8fdb\u884cI\/O\u65f6\u95f4\u901a\u77e5\u7684\u6570\u636e\u3002 unsigned int f_uid, f_gid; \/\/\u6587\u4ef6\u6240\u6709\u8005id\uff0c\u6240\u6709\u8005\u7ec4id struct file_ra_state f_ra; \/\/\u5728linux\/include\/linux\/fs.h\u4e2d\u5b9a\u4e49\uff0c\u6587\u4ef6\u9884\u8bfb\u76f8\u5173 unsigned long f_version; \/\/\u8bb0\u5f55\u6587\u4ef6\u7684\u7248\u672c\u53f7\uff0c\u6bcf\u6b21\u4f7f\u7528\u540e\u90fd\u81ea\u52a8\u9012\u589e\u3002 #ifdef CONFIG_SECURITY void *f_security; \/\/\u7528\u6765\u63cf\u8ff0\u5b89\u5168\u63aa\u65bd\u6216\u8005\u662f\u8bb0\u5f55\u4e0e\u5b89\u5168\u6709\u5173\u7684\u4fe1\u606f\u3002 #endif \/* needed for tty driver, and maybe others *\/ void *private_data; \/\/\u53ef\u4ee5\u7528\u5b57\u6bb5\u6307\u5411\u5df2\u5206\u914d\u7684\u6570\u636e #ifdef CONFIG_EPOLL \/* Used by fs\/eventpoll.c to link all the hooks to this file *\/ struct list_head f_ep_links; \u6587\u4ef6\u7684\u4e8b\u4ef6\u8f6e\u8be2\u7b49\u5f85\u8005\u94fe\u8868\u7684\u5934\uff0c spinlock_t f_ep_lock; f_ep_lock\u662f\u4fdd\u62a4f_ep_links\u94fe\u8868\u7684\u81ea\u65cb\u9501\u3002 #endif \/* #ifdef CONFIG_EPOLL *\/ struct address_space *f_mapping; \u6587\u4ef6\u5730\u5740\u7a7a\u95f4\u7684\u6307\u9488 };<\/pre>\n
struct files_struct { atomic_t count; \/* \u5171\u4eab\u8be5\u8868\u7684\u8fdb\u7a0b\u6570 *\/ rwlock_t file_lock; \/* \u4fdd\u62a4\u8be5\u7ed3\u6784\u4f53\u7684\u9501*\/ int max_fds; \/*\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\u7684\u6700\u5927\u6570*\/ int max_fdset; \/*\u5f53\u524d\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6700\u5927\u6570*\/ int next_fd; \/*\u5df2\u5206\u914d\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u52a01*\/ struct file ** fd; \/* \u6307\u5411\u6587\u4ef6\u5bf9\u8c61\u6307\u9488\u6570\u7ec4\u7684\u6307\u9488 *\/ fd_set *close_on_exec; \/*\u6307\u5411\u6267\u884cexec()\u65f6\u9700\u8981\u5173\u95ed\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26*\/ fd_set *open_fds; \/*\u6307\u5411\u6253\u5f00\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u6307\u9488*\/ fd_set close_on_exec_init; \/* \u6267\u884cexec()\u65f6\u5173\u95ed\u7684\u521d\u59cb\u6587\u4ef6*\/ fd_set open_fds_init; \/*\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u521d\u503c\u96c6\u5408*\/ struct file * fd_array[32]; \/* \u6587\u4ef6\u5bf9\u8c61\u6307\u9488\u7684\u521d\u59cb\u5316\u6570\u7ec4*\/ };<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"