From owner-freebsd-hackers Fri May 28 16:18: 2 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from quark.ChrisBowman.com (crbowman.erols.com [209.122.47.155]) by hub.freebsd.org (Postfix) with ESMTP id 1D19015077 for ; Fri, 28 May 1999 16:17:52 -0700 (PDT) (envelope-from crb@ChrisBowman.com) Received: from fermion (fermion.ChrisBowman.com [10.0.1.2]) by quark.ChrisBowman.com (8.9.2/8.8.8) with SMTP id TAA11260; Fri, 28 May 1999 19:17:17 -0400 (EDT) (envelope-from crb@ChrisBowman.com) Message-Id: <199905282317.TAA11260@quark.ChrisBowman.com> X-Sender: crb@quark X-Mailer: QUALCOMM Windows Eudora Pro Version 4.0.1 Date: Fri, 28 May 1999 19:12:48 -0400 To: Zhihui Zhang From: "Christopher R. Bowman" Subject: Re: Algorithm used to delete part of a file Cc: freebsd-hackers@FreeBSD.ORG In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG At 04:03 PM 5/28/99 -0400, Zhihui Zhang wrote: > >I am wondering what will happen to the underlying data blocks and indirect >blocks of a file if I delete a part of the file - how these blocks are >re-organized. I have no idea which source code should I look into to >understand this. Maybe I should read the source code for vi or another >editor. I hope someone can suggest me a better way to understand this or >describe briefly the algorithm. 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. If, on the other hand, you want to know how an application like vi will deal with, for instance, a deletion that occurs in the middle of the file. It will essentially have to read in and write out the entire file, omitting the deleted material since there is no syscall or way to tell the file system to remove a part of the file in the middle. If this has not answered your question, please feel free to state it in more detail. -------- Christopher R. Bowman crb@ChrisBowman.com http://www.ChrisBowman.com/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message