From owner-freebsd-hackers Fri May 28 17:56:18 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from sol (cs1-gw.cs.binghamton.edu [128.226.171.72]) by hub.freebsd.org (Postfix) with SMTP id 9349A14D77 for ; Fri, 28 May 1999 17:56:14 -0700 (PDT) (envelope-from zzhang@cs.binghamton.edu) Received: from localhost (zzhang@localhost) by sol (SMI-8.6/8.6.9) with SMTP id UAA11804; Fri, 28 May 1999 20:44:59 -0400 Date: Fri, 28 May 1999 20:44:58 -0400 (EDT) From: Zhihui Zhang To: "Christopher R. Bowman" Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Algorithm used to delete part of a file In-Reply-To: <199905282317.TAA11260@quark.ChrisBowman.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Fri, 28 May 1999, Christopher R. Bowman wrote: > It is difficult to understand if you are talking at the file system layer > (because you mention data and indirect blocks) or the application layer (you > mention looking at the vi code). At the file system layer you don't delete > blocks in the middle of a file. You can append to the file thus allocating new > data blocks (and perhaps indirect blocks if they are needed) that will be added > to the end of the file. Or you can truncate a file, thus freeing the data > blocks (and perhaps indirect blocks) at the end of the. When you truncate a > file the data blocks are returned to a list of free blocks, and when a block is > later reused for another purpose it is either written to in it's entirety or > zero filled, and then partially filed with your data (if you don't write the > entire block). In either case blocks are never added or removed except at the > end of the file, thus blocks never have to be "re-organized." They are simply > allocated or freed. If this is the level of your interest then looking at vi > source code won't help you. Thanks for your valuable information. This explains why I have not found any routines in the files under /ufs/ffs and /ufs/ufs that re-organize the on-disk image of a file in that way. If a middle part of a file is deleted, then all the remaining part of the file must be read by an editor (such as vi) and written out to another place before the file length is truncated. This algorithm seems to be not very efficient. But disk is not like memory, where we can simply modify pointers to point to new locations easily, I guess there may be no better way to do this. If you have any ideas about why this is not done by the filesystem itself, please let me know. Thanks for your help. Zhihui To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message