<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=GB2312" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
首先:<br>
<b><i>也就是说把file2在文件系统中占用的数据块分配给file1 <br>
</i></b><b><i>占用的数据块分配给file1 <br>
</i></b><b><i>数据块 &lt;--- </i></b><b><i>块</i></b><br>
<br>
然后, cat 的工作*不是*剪切文件, 他只是把参数指定的文件读出来, 按顺序串起来输到 stdout, 至于 &gt;&gt; 是
bash 的事情.<br>
bash 看到 &gt;&gt; , 以 append 方式打开 file2, 然后 write cat 的 stdout 的东西进去.
文件系统*不可能*知道要write的东西是来自哪个文件的, 更不可能实现所谓的"优化". 实际上文件系统并没有什么 cat 操作...<br>
<b><i><br>
</i></b>石康志 写道:
<blockquote
 cite="mid:7c29abc90806132346l26ae2218g287181d3b031925b@mail.gmail.com"
 type="cite">
  <meta http-equiv="Context-Type" content="text/html; charset=GB2312">
首先你应该好好看看问题,他并没有说要让file2的<b>块</b>剪切到file1的后面,而且这是完全没有道理的。建议你看看ext3文件系统的基
本概念(大部分的文件系统基本概念差不多)。<br>
再说cat是用来连接文件的,就是把file2剪切到file1里啊,而且原问题就已经说了可以cat
file2&gt;&gt;file1。不过我承认这是文件系统驱动的事(我没有说不是啊),为什么不可以优化文件系统的cat操作?<br>
  <br>
  <div>2008/6/14 AutumnCat &lt;<a moz-do-not-send="true"
 href="mailto:bigsnake_list@sina.com">bigsnake_list@sina.com</a>&gt;:<br>
  <blockquote>
    <div>你看回原问题
    <div><br>
    <b><i>有没有一种办法,能把file2 "剪切"到file1中?也就是说把file2在文件系统中占用的数据块分配给file1 <br>
    </i></b></div>
他的意思是将 file2&nbsp; 的块"串在" file1 后面, 这显然是文件系统驱动的事, 根本不轮cat, rename
....管.<br>
    <br>
石康志 写道:
    <blockquote type="cite">
块如何组织的确是文件系统决定的,但这个操作绝不会破坏数据结构,因为实际文件和文件地址信息是分开管理的,我们根本不需要对实际文件进行操作,需要改动
的只是地址信息,这实现起来是完全可行的(包括link, rm,
rename,……好多都是只改了地址信息),你说别的程序不会用到我没理解,这只是改进了cat操作,并没有新的接口,为什么没有通用型?
      <div>
      <div><br>
      <br>
      <div>2008/6/14 AutumnCat &lt;<a moz-do-not-send="true"
 href="mailto:bigsnake_list@sina.com">bigsnake_list@sina.com</a>&gt;:<br>
      <blockquote>
        <div>块如何组织是文件系统的数据结构决定的, 不一定支持这种操作(否则就破坏数据结构). 即使实现了,
也得修改文件系统驱动,
但别的程序根本不会用这个接口, 不具有通用性.<br>
        <br>
Zu 写道:
        <blockquote type="cite"> 没错<br>
          <br>
          <div>
          <div>2008/6/13 石康志 &lt;<a moz-do-not-send="true"
 href="mailto:shikangzhi@gmail.com">shikangzhi@gmail.com</a>&gt;:<br>
          </div>
          <blockquote>虽然块是顺序存储的,但是如果一个文件由3个块组成,并不要求这三个块要放到一起,所以如果文件A有4k,
B有8k
+
1byte,在这里并不需要移动任何一方,需要做的只是更改文件A的地址信息加上地址B,并删掉B的文件地址信息(和rm做的一样,rm也只删掉地址信
息,所以可以找回数据)。
            <div>
            <div><br>
            <br>
            <div>
            <div>2008/6/13 Zu &lt;<a moz-do-not-send="true"
 href="mailto:zzh@rashost.com">zzh@rashost.com</a>&gt;:<br>
            </div>
            <blockquote>Ok,考虑当一个块没有被占满的情况呢?看看我前面举的例子?
              <div>
              <div><br>
              <br>
              <div>
              <div>2008/6/13 石康志 &lt;<a moz-do-not-send="true"
 href="mailto:shikangzhi@gmail.com">shikangzhi@gmail.com</a>&gt;:<br>
              </div>
              <blockquote>的确在块内是排序的,不过整个文件根本不需要移动,所有从哪儿来的问题呢?
                <div>
                <div><br>
                <br>
                <div>
                <div>2008/6/13 Zu &lt;<a moz-do-not-send="true"
 href="mailto:zzh@rashost.com">zzh@rashost.com</a>&gt;:<br>
                </div>
                <blockquote>
                  <div>没有人说是按顺序排列的。按不按顺序排列是不一定的,说不定哪天谁开发出一个完全按顺序排列的,不考虑效
率的文
件系统也不是没有可能。<br>
                  <br>
ext3在块内是按顺序的。建议先了解一下ext3的分块的基本概念再讨论。<br>
                  <br>
                  </div>
                  <div>
                  <div>
                  <div>2008/6/13 石康志 &lt;<a moz-do-not-send="true"
 href="mailto:shikangzhi@gmail.com">shikangzhi@gmail.com</a>&gt;:<br>
                  </div>
                  </div>
                  <blockquote>完全不对!在文件系统中,文件并不是顺序排列的,也许一个1G的文件有100MB在'0,
0'-&gt;100mb地址,后面可以在'10000000,
10000000'-&gt;900mb,并不要求这一个G的东西全部按顺序放到一起,控制这一切的,仅仅是一个文件的地址信息(你可以把它想象成指
针),所以可以通过改变地址信息控制文件。
                    <div>
                    <div>
                    <div>
                    <div><br>
                    <br>
                    <div>
                    <div>2008/6/13 Zu &lt;<a moz-do-not-send="true"
 href="mailto:zzh@rashost.com">zzh@rashost.com</a>&gt;:<br>
                    </div>
                    <blockquote>可能是我没有把问题说清楚,我的原话是:
                      <div>
                      <div>
                      <div><br>
                      <br>
                      <b><i>有2个文件,file1和file2,大小都是4G,如果想合并file1和file2,可以
cat<br>
file2&gt;&gt;file1来实现,这样要花几分钟时间。有没有一种办法,能把file2 "剪切"<br>
到file1中?也就是说把file2在文件系统中占用的数据块分配给file1?使用的是ext3文件系统。</i></b><br>
                      <br>
                      </div>
mv
的作用是把一个文件改一个名字,该文件除了文件名以外其他信息都不变,所以mv的速度特别快。mv不能把一个文件的内容移动到另一个文件的末尾去。我觉着
下面shell909090说的比较有道理:<br>
                      <br>
                      <b><i>有点困难,因为根据我的理解,任何文件在磁盘中都是"块</i></b>
                      <div><b><i>"的集合存储的。如果头<br>
一个文件正好放满N块还好说,如果正好差一点,那么后面的数据按</i></b><b><i>照规则必须先<br>
填充前面的块。这样会造成后一个文件全面的内容位移</i></b><b><i>,其读写数据量没有比直接<br>
附加低多少。</i></b></div>
                      <br>
举例:<br>
file1的文件长度是1个字节,在块大小是4k的ext3文件系统下,这个文件要占用4k的空间,也就是一个块的空间。<br>
file2的文件长度是8K+1个字节,在块大小是4k的ext3文件系统下,这个文件要占用8K+4k的空间,也就是3个块的空间。<br>
如果要把file2剪切到file1的末尾,要做到比"cat file2&gt;&gt;file1"更快,不修改内核中的文件系统能做到吗?<br>
                      <br>
2008/6/13 马利 &lt;<a moz-do-not-send="true"
 href="mailto:richard.ma.19850509@gmail.com">richard.ma.19850509@gmail.com</a>&gt;:
                      <div><br>
&gt; 看看mv的源代码就差不多了吧,适当复用,没看出来和内核有什么关系<br>
&gt;<br>
&gt; --<br>
&gt; 马利<br>
&gt; <a moz-do-not-send="true" href="http://richard.ma">richard.ma</a><br>
                      </div>
                      <div>
                      <div>&gt; --<br>
&gt; ubuntu-zh mailing list<br>
&gt; <a moz-do-not-send="true" href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
&gt; <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
&gt;<br>
&gt;<br>
                      <br>
                      <br>
                      <br>
-- <br>
瑞豪开源VPS - 基于Linux/Xen - 最低58元/月 - 免费试用<br>
                      <a moz-do-not-send="true"
 href="http://www.RasHost.com">http://www.RasHost.com</a><br>
                      </div>
                      </div>
                      <br>
--<br>
ubuntu-zh mailing list<br>
                      <a moz-do-not-send="true"
 href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
                      <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
                      <br>
                      </div>
                      </div>
                    </blockquote>
                    </div>
                    <br>
                    <br>
--<br>
ubuntu-zh mailing list<br>
                    <a moz-do-not-send="true"
 href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
                    <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
                    <br>
                    </div>
                    </div>
                    </div>
                    </div>
                  </blockquote>
                  </div>
                  <div>
                  <div>
                  <div>
                  <div><br>
                  <br>
                  <br>
-- <br>
瑞豪开源VPS - 基于Linux/Xen - 最低58元/月 - 免费试用<br>
                  <a moz-do-not-send="true"
 href="http://www.RasHost.com">http://www.RasHost.com</a> </div>
                  </div>
                  <br>
--<br>
ubuntu-zh mailing list<br>
                  <a moz-do-not-send="true"
 href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
                  <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
                  <br>
                  </div>
                  </div>
                </blockquote>
                </div>
                <br>
                </div>
                </div>
                <div>
                <div> <br>
--<br>
ubuntu-zh mailing list<br>
                <a moz-do-not-send="true"
 href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
                <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
                <br>
                </div>
                </div>
              </blockquote>
              </div>
              <div>
              <div> <br>
              <br>
              <br>
-- <br>
瑞豪开源VPS - 基于Linux/Xen - 最低58元/月 - 免费试用<br>
              <a moz-do-not-send="true" href="http://www.RasHost.com">http://www.RasHost.com</a>
              </div>
              </div>
              </div>
              </div>
              <div>
              <div> <br>
--<br>
ubuntu-zh mailing list<br>
              <a moz-do-not-send="true"
 href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
              <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
              <br>
              </div>
              </div>
            </blockquote>
            </div>
            <br>
            </div>
            </div>
            <div>
            <div> <br>
--<br>
ubuntu-zh mailing list<br>
            <a moz-do-not-send="true"
 href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
            <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
            <br>
            </div>
            </div>
          </blockquote>
          </div>
          <div>
          <div> <br>
          <br>
          <br>
-- <br>
瑞豪开源VPS - 基于Linux/Xen - 最低58元/月 - 免费试用<br>
          <a moz-do-not-send="true" href="http://www.RasHost.com">http://www.RasHost.com</a>
          </div>
          </div>
        </blockquote>
        </div>
        <br>
--<br>
ubuntu-zh mailing list<br>
        <a moz-do-not-send="true"
 href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
        <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
        <br>
      </blockquote>
      </div>
      <br>
      </div>
      </div>
    </blockquote>
    </div>
    <br>
--<br>
ubuntu-zh mailing list<br>
    <a moz-do-not-send="true" href="mailto:ubuntu-zh@lists.ubuntu.com">ubuntu-zh@lists.ubuntu.com</a><br>
    <a moz-do-not-send="true"
 href="https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh">https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh</a><br>
    <br>
  </blockquote>
  </div>
  <br>
  <br>
  <br>
-- <br>
qingshi163
</blockquote>
</body>
</html>