Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 May 1999 19:12:48 -0400
From:      "Christopher R. Bowman" <crb@ChrisBowman.com>
To:        Zhihui Zhang <zzhang@cs.binghamton.edu>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Algorithm used to delete part of a file
Message-ID:  <199905282317.TAA11260@quark.ChrisBowman.com>
In-Reply-To: <Pine.GSO.3.96.990528155518.10813A-100000@sol.cs.binghamton .edu>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199905282317.TAA11260>