{"id":359607,"date":"2021-02-13T20:16:47","date_gmt":"2021-02-13T12:16:47","guid":{"rendered":"http:\/\/4563.org\/?p=359607"},"modified":"2021-02-13T20:16:47","modified_gmt":"2021-02-13T12:16:47","slug":"stat-%e7%9a%84%e8%b0%83%e7%94%a8%e6%b5%81%e7%a8%8b%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=359607","title":{"rendered":"stat() \u7684\u8c03\u7528\u6d41\u7a0b\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  stat() \u7684\u8c03\u7528\u6d41\u7a0b\u662f\u4ec0\u4e48\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : abersheeran <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6700\u8fd1\u5728\u5199\u4ee3\u7801\u7684\u65f6\u5019\u53d1\u73b0\u4e00\u4e2a\u95ee\u9898\uff0c\u628a Python \u7684 os.stat \u4e22\u5230\u7ebf\u7a0b\u6c60\u91cc\u8dd1\u3001\u76f4\u63a5\u5355\u7ebf\u7a0b\u8dd1\uff0c\u6027\u80fd\u5dee\u8ddd\u76f8\u5f53\u4e4b\u5927\u3002\u5e76\u4e14\u65e0\u8bba\u662f\u5f88\u5dee\u52b2\u7684\u673a\u68b0\u786c\u76d8\u3001\u4e0d\u9519\u7684\u673a\u68b0\u786c\u76d8\u6216\u8005 SSD\uff0c\u6027\u80fd\u5dee\u8ddd\u6bd4\u4f8b\u57fa\u672c\u4e00\u81f4\u3002<\/p>\n<p>\u4e8e\u662f\u5bf9 stat \u7684\u8c03\u7528\u903b\u8f91\u4ea7\u751f\u4e86\u597d\u5947\uff0c\u8c37\u6b4c\u3001\u5fc5\u5e94\u67e5\u9605\u4e86\u4e00\u756a\u8d44\u6599\u4e4b\u540e\u4e5f\u6ca1\u6709\u8bb2\u8fd9\u4e2a\u4e8b\u7684\u6587\u7ae0\u3002\u6240\u4ee5\u6765\u95ee\u95ee\u5927\u5bb6\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5408378\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : des <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             os \u7f13\u5b58\u7684\u539f\u56e0\u5427\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5408379\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liuxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/elixir.bootlin.com\/linux\/latest\/source\/fs\/stat.c#L166                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5408380\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bleepbloop <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7ebf\u7a0b\u6c60\u8dd1\u7684\u8bdd\u4e5f\u6709\u4e0a\u4e0b\u6587\u5207\u6362\u7684\u5f00\u9500\u5427\uff0c\u4f46\u4e0d\u77e5\u9053\u6709\u591a\u5c11                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5408381\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : abersheeran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @des \u6211\u9996\u5148\u5bf9\u5927\u91cf\u4e0d\u540c\u7684\u6587\u4ef6\u8fdb\u884c\u4e86\u6d4b\u8bd5\uff0c\u518d\u5bf9\u8fd9\u4e9b\u6587\u4ef6\u6bcf\u4e2a\u91cd\u590d\u8c03\u7528\u4e86\u5341\u6b21\u548c\u767e\u6b21\u3002\u5982\u679c\u5b58\u5728\u7f13\u5b58\uff0c\u8017\u65f6\u7684\u589e\u957f\u4e0d\u5e94\u8be5\u662f\u5b9e\u8df5\u7ed3\u679c\u6240\u5c55\u793a\u7684\u7ebf\u6027\u589e\u957f\u3002<\/p>\n<p>\u6211\u975e\u5e38\u597d\u5947\u8c03\u7528\u8fc7\u7a0b\u3002<\/p>\n<p>@liuxu \u6211\u4ece\u672a\u9605\u8bfb\u8fc7 Linux \u5185\u6838\u4ee3\u7801\u3002\u867d\u7136\u8fd9\u4e2a\u51fd\u6570\u6211\u77e5\u9053\u5b83\u5e72\u4e86\u4ec0\u4e48\uff0c\u4f46\u662f\u90a3\u4e9b flag \u4e0d\u77e5\u9053\u4ec0\u4e48\u610f\u601d\uff0c\u6211\u5bf9\u8c03\u7528\u8fc7\u7a0b\u8fd8\u662f\u6ca1\u7406\u89e3\u3002\u76f8\u6bd4\u8bfb\u5199\u6587\u4ef6\u6765\u8bf4\uff0cstat \u7684\u78c1\u76d8 IO \u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5c0f\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5408382\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liuxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @abersheeran \u6587\u4ef6\u5b58\u50a8\u5728\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u5206\u4e3a\u5c5e\u6027\u5b58\u50a8\u533a(inode)\u548c\u6570\u636e\u5b58\u50a8\u533a(block)\uff0cstat \u53ea\u9700\u8981\u8bfb\u5c5e\u6027\u5b58\u50a8\u533a<\/p>\n<p>\u4e0d\u9700\u8981\u8bfb\u8fc7 linux \u5185\u6838\u6e90\u7801\uff0c\u9047\u5230\u4ec0\u4e48\u67e5\u4ec0\u4e48\u800c\u5df2\uff0c\u628a\u5b83\u5f53\u505a helloworld \u8bfb\u5c31\u884c\uff0c\u50cf\u6211\u7ed9\u7684\u8fd9\u4e2a\u94fe\u63a5\uff0c\u4f60\u4e0d\u9700\u8981\u641e\u6e05\u695a flag \u662f\u4ec0\u4e48\u610f\u601d\uff0c\u53ea\u9700\u8981\u77e5\u9053\u5b83\u4eec\u4f1a\u88ab\u586b\u5145\u5230 stat \u6570\u636e\u7ed3\u6784\uff0c\u5e76\u770b\u770b\u8c03\u7528\u4e86\u54ea\u4e9b\u65b9\u6cd5\uff0c\u6839\u636e\u65b9\u6cd5\u5e76\u5927\u6982\u53ef\u4ee5\u77e5\u9053\u5e72\u4e86\u4ec0\u4e48\uff0c\u4e0d\u77e5\u9053\u7684\u8ddf\u8fdb\u53bb\u770b\u770b\u5c31\u77e5\u9053\u4e86<\/p>\n<p>\u4f8b\u5982\u7ed9\u4f60\u53d1\u7684\u8fd9\u4e2a\u94fe\u63a5\uff0cvfs_statx()\uff0c\u6839\u636e\u540d\u5b57\u4f60\u53ef\u4ee5\u77e5\u9053 linux \u8bfb\u53d6\u6587\u4ef6\u4fe1\u606f\u662f\u901a\u8fc7 linux vfs \u865a\u62df\u6587\u4ef6\u7cfb\u7edf\u5c42\u62ff\u7684\u6587\u4ef6\u4fe1\u606f<br \/>\u5b83\u5185\u90e8\u8c03\u7528\u4e86 user_path_at()\uff0c\u53ef\u4ee5\u77e5\u9053\u5b83\u8bfb\u53d6\u4e86\u6587\u4ef6\u8def\u5f84\uff0c\u90fd\u4e0d\u9700\u8981\u5f80\u91cc\u9762\u770b<br \/>\u7136\u540e\u8c03\u7528\u4e86 vfs_getattr()\uff0c\u662f\u901a\u8fc7 vfs \u5c42\u8bfb\u53d6\u4e86\u6587\u4ef6 attr<br \/>\u8fd8\u8c03\u7528\u4e86 real_mount()\uff0c\u90a3\u5230\u4e86\u5f53\u524d mount \u6570\u636e<br \/>&#8230;<\/p>\n<p>\u7136\u540e\u4f60\u53ef\u80fd\u8fd8\u60f3\u77e5\u9053 user_path_at()\uff0c\u4f1a\u53d1\u73b0\u6700\u540e\u8c03\u7528\u4e86 filename_lookup()\uff0c\u7136\u540e\u4f60\u518d\u5206\u6790\u5b83\u5982\u4f55\u90a3\u6587\u4ef6\u4fe1\u606f\u7684\uff0c\u6700\u5e95\u5c42\u4e00\u822c\u662f\u6c47\u7f16\u5b9e\u73b0\uff0c\u53ef\u8bfb\u6027\u4e0d\u9ad8\uff0c\u4e0d\u7528\u592a\u94bb\uff0c\u4f60\u975e\u8981\u94bb\u4e5f\u884c\uff0c\u65e0\u975e\u5c31\u662f\u82b1\u51e0\u5929\u51e0\u5468\u51e0\u4e2a\u6708\u800c\u5df2\uff0c\u4f60\u6382\u91cf\u6382\u91cf\u770b\u770b\u503c\u4e0d\u503c\u5c31\u884c\u4e86<\/p>\n<p>\u987a\u4fbf\u63d0\u4e00\u4e0b\uff0cc \u8bed\u8a00\u4e0d\u50cf\u73b0\u4ee3\u9ad8\u7ea7\u8bed\u8a00\uff0c\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\uff0c\u641e\u5e95\u5c42\u7684 c \u4e00\u822c\u4e0d\u4f1a\u8fd9\u4e48\u73a9\uff0c\u4e00\u822c\u4f1a\u521b\u5efa\u597d\u6570\u636e\u7ed3\u6784\uff0c\u628a\u6307\u9488\u4f20\u7ed9\u4e2a\u51fd\u6570\uff0c\u8ba9\u51fd\u6570\u5185\u90e8\u64cd\u4f5c\u586b\u5145\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u6700\u540e\u8fd4\u56de int \u578b\u72b6\u6001\u4fe1\u606f\uff0c\u6240\u4ee5\u4f60\u4f1a\u770b\u5230 vfs_statx()\u8fd4\u56de int\uff0c\u800c\u53c2\u6570 stat \u624d\u662f\u771f\u6b63\u8fd4\u56de\u7ed9\u8c03\u7528\u5c42\u7684\u6570\u636e\u7ed3\u6784<\/p>\n<p>\u5982\u679c\u4f60\u975e\u8981\u77e5\u9053 flag \u7684\u662f\uff0c\u62ff flag \u67e5 google \u4e00\u5b9a\u53ef\u4ee5\u67e5\u51fa\u6765\uff0c\u4f46\u662f\u6211\u7ed9\u4f60\u4e86\uff0c\u4f60\u5c31\u5f80\u65c1\u8fb9\u4e00\u6254\u8bf4\u672a\u9605\u8bfb\u8fc7 Linux \u5185\u6838\u4ee3\u7801\uff0c\u4f60\u5bf9\u5176\u4ed6\u4eba\u7ed9\u4f60\u5e26\u6765\u7684\u5e2e\u52a9\u7ed9\u4eba\u611f\u89c9\u6301\u6709\u6d88\u6781\u6001\u5ea6<\/p>\n<p>\u770b\u4e0d\u61c2\u5c31\u522b\u770b\u4e86\uff0c\u4f60\u76ee\u524d\u7684\u80fd\u529b\u6ca1\u6cd5\u6ee1\u8db3\u4f60\u7684\u597d\u5947\u5fc3\uff0c\u8fc7\u51e0\u5e74\u518d\u770b\u5427                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5408383\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : abersheeran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @liuxu \u6211\u4e0d\u89c9\u5f97\u6211\u7684\u6001\u5ea6\u6d88\u6781\u3002\u4f60\u53d1\u7684\u94fe\u63a5\u6211\u518d\u4e09\u770b\u4e86\uff0c\u4f60\u8bf4\u7684\u8fd9\u4e09\u4e2a\u51fd\u6570\uff0c\u4f60\u53ef\u80fd\u89c9\u5f97\u4f60\u770b\u51fd\u6570\u540d\u5c31\u77e5\u9053\u5e72\u4ec0\u4e48\u7684\uff0c\u4f46\u662f\u6211\u662f\u538b\u6839\u4e0d\u77e5\u9053\u5b83\u4eec\u5e72\u4e86\u5565\uff0c\u6211\u662f\u901a\u8fc7\u7f51\u7ad9\u7684\u70b9\u51fb\u8df3\u8f6c\u529f\u80fd\u4e00\u5c42\u5c42\u770b\u7684\uff0c\u4f46\u662f\u770b\u5230\u6700\u540e\u4ece path.dentry \u91cc\u62ff inode \u8282\u70b9\u8df3\u4e00\u5c42\uff0c\u8d4b\u503c\u7ed9 stat \u3002\u6211\u4eba\u90fd\u50bb\u4e86\uff0c\u53c8\u8c03\u56de\u53bb\u770b\u3002\u78c1\u76d8\u8bfb\u5199\u8fd9\u4e2a\u53d1\u751f\u5728\u54ea\u513f\u6211\u5b8c\u5168\u6ca1\u770b\u5230\uff0c\u6216\u8005\u8bf4\u6ca1\u770b\u61c2\u3002\u6240\u4ee5\u6211\u624d\u4f1a\u8bf4\u201c\u6211\u5bf9\u8c03\u7528\u8fc7\u7a0b\u8fd8\u662f\u6ca1\u7406\u89e3\u201d\u3002\u4f60\u73b0\u5728\u56de\u590d\u8bf4\u4e86 stat \u53ea\u9700\u8981\u8bfb\u5c5e\u6027\u5b58\u50a8\u533a\uff0c\u6211\u624d\u660e\u767d\u662f\u4ec0\u4e48\u610f\u601d\u3002<\/p>\n<p>\u603b\u4e4b\u611f\u8c22\u4f60\u7684\u56de\u590d\u3002\u53c8\u5b66\u5230\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5408384\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : v2exblog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @liuxu \u5927\u4f6c\uff0c\u6c42\u63a8\u8350\u51e0\u672c\u4e0d\u9519\u7684\u6280\u672f\u4e66\u3002\u8c22\u8c22\u5927\u4f6c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>stat() \u7684\u8c03\u7528\u6d41\u7a0b\u662f\u4ec0\u4e48\uff1f &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/359607"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=359607"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/359607\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=359607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=359607"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=359607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}