{"id":2932,"date":"2011-09-06T14:04:17","date_gmt":"2011-09-06T06:04:17","guid":{"rendered":"https:\/\/www.icocean.com\/wp\/?p=2932"},"modified":"2011-09-06T14:04:17","modified_gmt":"2011-09-06T06:04:17","slug":"%e6%96%87%e4%bb%b6%e7%a9%ba%e6%b4%9e%e4%ba%a7%e7%94%9f%e7%9a%84%e5%8e%9f%e5%9b%a0%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.icocean.com\/blog\/?p=2932","title":{"rendered":"\u6587\u4ef6\u7a7a\u6d1e\u4ea7\u751f\u7684\u539f\u56e0\u5206\u6790"},"content":{"rendered":"<p>\u5728\u6587\u4ef6\u62f7\u8d1d\u65f6\u5019\uff0cscp\u4e00\u4e2a\u5360\u78c1\u76d8\u7a7a\u95f4300G\u5927\u5c0f\uff08du\u547d\u4ee4\u7684\u7ed3\u679c\uff09\u5de6\u53f3\u7684\u76ee\u5f55\u5230\u53e6\u5916\u4e00\u53f0\u673a\u5668\u4e0a\uff0cdu\u547d\u4ee4\u53d1\u73b0\u8be5\u76ee\u5f55\u5360\u7528\u7684\u78c1\u76d8\u7a7a\u95f4\u53d8\u5927\u4e86\uff0c\u7ea6330\u591aG\u3002\u4e3a\u4ec0\u4e48\u4f1a\u591a\u51fa\u6765\u8fd930G\u5462\uff1f<\/p>\n<p>\u5206\u6790\u53ef\u80fd\u539f\u56e0\uff1a<\/p>\n<p>\u4e00.\u539f\u673a\u5668\u7684block\u5927\u5c0f\u4e3a1024k,\u65b0\u673a\u5668\u7684block\u5927\u5c0f\u4e3a4096k,\u53ef\u80fd\u662f\u6587\u4ef6\u7cfb\u7edfblock\u5927\u5c0f\u5f15\u8d77\u7684\u3002<br \/>\n\u62f7\u8d1d\u7684\u6570\u636e\u6587\u4ef6\u5927\u6982\u67091000\u4e2a\uff0c\u6587\u4ef6\u5757\u7684\u5f71\u54cd\u4e5f\u5c31\u662f1000*4K=4M,\u800c\u7a7a\u95f4\u589e\u5927\u4e86\u7ea630G\uff0c\u6240\u4ee5\u4e0d\u53ef\u80fd\u662f\u539f\u56e0\u4e00\u3002<\/p>\n<p>\u4e8c.\u6709\u4e9b\u6587\u4ef6\u5b58\u5728\u7a7a\u6d1e\u3002\u7a7a\u6d1escp\u5230\u65b0\u673a\u5668\u540e\uff0c\u88ab\u586b\u5145\uff0c\u5360\u7528\u78c1\u76d8\u7a7a\u95f4\u3002<!--more--><\/p>\n<p>\u5b9e\u9a8c\uff1a\u5728\u672c\u673a\u4e0acp\u4e00\u4e2a\u6709\u7a7a\u6d1e\u7684\u6587\u4ef6\uff0c\u53d1\u73b0cp\u524d\u540e\u5360\u7528\u7684\u78c1\u76d8\u5927\u5c0f\u672a\u53d8\uff0c\u800cscp\u5230\u53e6\u4e00\u53f0\u673a\u5668\u540e\uff0c\u7a7a\u6d1e\u88ab\u586b\u6ee1\uff0c\u5360\u7528\u78c1\u76d8\u5757\u53d8\u5927\u3002<\/p>\n<p>\u80cc\u666f\u77e5\u8bc6\uff1a<\/p>\n<p>ll\u548cdu \u2013s\u8bfb\u53d6\u7684\u6587\u4ef6\u5927\u5c0f\u548c\u5360\u7528\u78c1\u76d8\u7a7a\u95f4\u6570\u636e\u6765\u6e90<br \/>\n<code>struct stat {<br \/>\ndev_t st_dev; \/* device *\/<br \/>\nino_t st_ino; \/* inode *\/<br \/>\nmode_t st_mode; \/* protection *\/<br \/>\nnlink_t st_nlink; \/* number of hard links *\/<br \/>\nuid_t st_uid; \/* user ID of owner *\/<br \/>\ngid_t st_gid; \/* group ID of owner *\/<br \/>\ndev_t st_rdev; \/* device type (if inode device) *\/<br \/>\noff_t st_size; \/* total size, in bytes *\/<br \/>\nblksize_t st_blksize; \/* blocksize for filesystem I\/O *\/<br \/>\nblkcnt_t st_blocks; \/* number of blocks allocated *\/<br \/>\ntime_t st_atime; \/* time of last access *\/<br \/>\ntime_t st_mtime; \/* time of last modification *\/<br \/>\ntime_t st_ctime; \/* time of last status change *\/<br \/>\n};<\/code><\/p>\n<p>\u81ea\u5df1\u7f16\u5199\u4e00\u4e2a\u5c0fC\u7a0b\u5e8f\u901a\u8fc7fstat\u51fd\u6570\uff0c\u53d6\u5f97\u6587\u4ef6\u72b6\u6001\uff0cst_size\u5c31\u662fll\u770b\u5230\u7684\u6587\u4ef6\u5927\u5c0f\uff0cst_blksize\u662f\u7cfb\u7edf\u6bcf\u6b21read,write\u7b49i\/o\u7684buff\u5927\u5c0f\uff0c\u901a\u5e38\u548c\u6587\u4ef6\u7cfb\u7edf\u5757\u5927\u5c0f\u4e00\u81f4\uff0cst_blocks\u662f\u5360\u7528\u7684\u6587\u4ef6\u7cfb\u7edf\u7684\u5757\u6570\uff0c\u8fd9\u4e2a\u5757\u533a\u522b\u4ee5\u6587\u4ef6\u7cfb\u7edf\u7684\u5757\uff0c\u4e00\u822c\u662f512\u5b57\u8282\u3002Du\u547d\u4ee4\u8bfb\u53d6st_blocks\uff08du\u4f1a\u6839\u636e\u547d\u4ee4\u53c2\u6570\u8f6c\u6362\uff09\u3002<\/p>\n<p>\u5b9e\u9a8c\u8fc7\u7a0b\uff1a\u521b\u5efa\u4e00\u4e2a\u7a7a\u6d1e\u6587\u4ef6file.hole\u3002\u901a\u8fc7lseek\u5c06\u6587\u4ef6\u504f\u79fb\u91cf\u6307\u9488\u8d85\u8fc7\u6587\u4ef6\u672b\u5c3e\u3002<br \/>\n\u5b9e\u9a8c\u673a\u5668:block\u5927\u5c0f\u4e3a4k.<\/p>\n<p><code>ll file.hole<br \/>\n-rw-r--r-- 1 zhangfan zhangfan 16394 Jun 22 15:08 file.hole<br \/>\ndu -sh file.hole<br \/>\n8.0K file.hole<\/code><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u7a7a\u6d1e\u90e8\u5206\u6ca1\u6709\u5360\u7528block.<br \/>\ncp\u4e00\u4e2a\u7a7a\u6d1e\u6587\u4ef6<br \/>\n<code>cp file.hole file.hole.cp<br \/>\nll file.hole.cp<br \/>\n-rw-r--r-- 1 zhangfan zhangfan 16394 Jul 10 15:51 file.hole.cp<br \/>\ndu -sh file.hole.cp<br \/>\n8.0K file.hole.cp<\/code><\/p>\n<p>trace\u4e00\u4e0b\u7cfb\u7edf\u8c03\u7528\u7684\u8fc7\u7a0b<\/p>\n<p><code>read(3, \"abcdefghij\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nwrite(4, \"abcdefghij\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nread(3, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nlseek(4, 4096, SEEK_CUR) = 8192<br \/>\nread(3, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nlseek(4, 4096, SEEK_CUR) = 12288<br \/>\nread(3, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nlseek(4, 4096, SEEK_CUR) = 16384<br \/>\nread(3, \"ABCDEFGHIJ\", 4096) = 10<br \/>\nwrite(4, \"ABCDEFGHIJ\", 10) = 10<br \/>\nread(3, \"\", 4096) = 0<br \/>\nclose(4) = 0<br \/>\nclose(3) = 0<\/code><\/p>\n<p>\u53eawrite\u4e86\u6709\u5177\u4f53\u5185\u5bb9\u7684\u5757\uff0c\u7a7a\u6d1e\u6ca1\u6709write,\u4f46\u662flseek\u662f\u4e00\u76f4\u5728\u53d8\u7684\uff0c\u6240\u4ee5cp\u4e0d\u4f1a\u62f7\u8d1d\u7a7a\u6d1e\u3002<\/p>\n<p>\u901a\u8fc7\u770bcp\u7684\u6e90\u7801\uff0c\u53ef\u4ee5\u770b\u5230cp\u7684\u5177\u4f53\u8fc7\u7a0b\uff1a<\/p>\n<p>1\u3001 \u5224\u65ad\u76ee\u6807\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u5b58\u5728\u5219\u6e05\u7a7a\u76ee\u6807\u6587\u4ef6\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u521b\u5efa\u76ee\u6807\u6587\u4ef6<br \/>\n2\u3001\u6839\u636e\u76ee\u6807\u6587\u4ef6\u7684\u903b\u8f91\u5757\u5927\u5c0f\uff0c\u521b\u5efa\u62f7\u8d1d\u7f13\u51b2\u533a<br \/>\n3\u3001\u5224\u65ad\u6e90\u6587\u4ef6\u662f\u5426\u6709\u7a7a\u6d1e\uff1a\u6587\u4ef6\u5927\u5c0f\uff0f\u6587\u4ef6\u5757\u5927\u5c0f > \u5757\u6570 \uff1f<br \/>\n4\u3001\u8bfb\u53d6\u6e90\u6587\u4ef6\u5b58\u653e\u5230\u7f13\u51b2\u533a\uff0c\u6bcf\u6b21\u8bfb\u53d6\u4e00\u5757<br \/>\n5\u3001\u5728\u7b2c3\u6b65\u4e2d\u5224\u65ad\uff0c\u5982\u679c\u5b58\u5728\u6587\u4ef6\u7a7a\u6d1e\uff0c\u5219\u5bf9\u7f13\u51b2\u533a\u6570\u636e\u8fdb\u884c\u5224\u65ad\uff0c\u5982\u679c\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u5747\u4e3a0\uff0c\u5219\u8ba4\u4e3a\u8be5\u6570\u636e\u5feb\u4e3a\u7a7a\u6d1e\uff0c\u5426\u5219\u8ba4\u4e3a\u662f\u6b63\u5e38\u6587\u4ef6\u6570\u636e<br \/>\n6\u3001\u5982\u679c\u6570\u636e\u5757\u4e3a\u7a7a\u6d1e\uff0c\u5219\u8c03\u7528lseek\uff0c\u5728\u76ee\u6807\u6587\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u7a7a\u6d1e\uff1b\u5426\u5219\u62f7\u8d1d\u7f13\u51b2\u533a\u6570\u636e\u5230\u76ee\u6807\u6587\u4ef6<br \/>\n7\u3001\u5224\u65ad\u672c\u6b21\u8bfb\u53d6\u662f\u5426\u8bfb\u5230\u6e90\u6587\u4ef6\u7684\u6587\u4ef6\u5c3e\uff0c\u5982\u679c\u662f\uff0c\u5219\u5224\u65ad\u672c\u6b21\u8bfb\u53d6\u7684\u662f\u5426\u662f\u7a7a\u6d1e\uff0c\u5982\u679c\u662f\u7a7a\u6d1e\u5219\u5728\u6587\u4ef6\u7684\u6700\u540e\u5199\u5165&#8221;&#8221;<br \/>\n8\u3001\u91cd\u590d1 ~ 7<br \/>\n9\u3001\u5173\u95ed\u76ee\u6807\u6587\u4ef6\u3001\u6e90\u6587\u4ef6<\/p>\n<p>Scp file.hole\u5230\u53e6\u5916\u4e00\u53f0\u673a\u5668<br \/>\nScp\u540e\u7684\u6587\u4ef6 ll file.hole<\/p>\n<p><code>-rw-r--r-- 1 zhangfan zhangfan 16394 Jul 10 15:57 file.hole<br \/>\ndu -sh file.hole<br \/>\n20K file.hole<\/code><\/p>\n<p>\u518dtrace\u4e00\u4e0bscp.<\/p>\n<p><code>read(3, \"abcdefghij\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nwrite(6, \"abcdefghij\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nread(3, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nwrite(6, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nread(3, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nwrite(6, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nread(3, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nwrite(6, \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"..., 4096) = 4096<br \/>\nread(3, \"ABCDEFGHIJ\", 10) = 10<\/code><\/p>\n<p>\u7a7a\u6d1e\u4e5f\u88abwrite\u4e86\uff0c\u6240\u4ee5du -s\u4f1a\u53d8\u5927 \u3002cp\u5bf9\u4e8e\u7a00\u758f\u6587\u4ef6\u7684\u652f\u6301(sparse file)\uff0c\u662f\u7531\u9009\u9879\u63a7\u5236\u7684\uff0c&#8211;sparse=(auto|always|never)\uff0c\u9ed8\u8ba4\u662f\u652f\u6301(auto)\uff0c\u5177\u4f53\u8bf7man\u3002scp\u5e94\u8be5\u4e0d\u652f\u6301\u7a00\u758f\u6587\u4ef6\uff0c\u6240\u4ee5scp\u8fd9\u6837\u7684\u6587\u4ef6\uff0c\u4f1a\u88ab\u586b\u5145\u62100 ;\u4e0d\u8fc7\uff0ctar(-S\u9009\u9879)\u3001rsync(\u4e5f\u662f-S)\u90fd\u662f\u652f\u6301\u7684\uff0c\u6240\u6709scp\u7684\u65f6\u5019\u53ef\u4ee5\u8ddf\u4ed6\u4eec\u914d\u5408\u7740\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6587\u4ef6\u62f7\u8d1d\u65f6\u5019\uff0cscp\u4e00\u4e2a\u5360\u78c1\u76d8\u7a7a\u95f4300G\u5927\u5c0f\uff08du\u547d\u4ee4\u7684\u7ed3\u679c\uff09\u5de6\u53f3\u7684\u76ee\u5f55\u5230\u53e6\u5916\u4e00\u53f0\u673a\u5668\u4e0a\uff0cdu\u547d\u4ee4\u53d1\u73b0\u8be5\u76ee <a href='https:\/\/www.icocean.com\/blog\/?p=2932' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[3472,3475,3473,3471,3474],"class_list":["post-2932","post","type-post","status-publish","format-standard","hentry","category-4","tag-block","tag-filesystem","tag-3473","tag-3471","tag-3474","category-4-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2932"}],"version-history":[{"count":1,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2932\/revisions"}],"predecessor-version":[{"id":2933,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2932\/revisions\/2933"}],"wp:attachment":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}