Xref: utzoo comp.unix.questions:8183 comp.unix.wizards:9864 comp.sys.apollo:1115
Path: utzoo!attcan!uunet!husc6!purdue!umd5!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.unix.questions,comp.unix.wizards,comp.sys.apollo
Subject: Re: File space allocation/deallocation under Unix (BSD4.x)
Keywords: Unix, BSD, File, Delete
Message-ID: <12423@mimsy.UUCP>
Date: 12 Jul 88 21:09:18 GMT
References: <9662@eddie.MIT.EDU>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 26

In article <9662@eddie.MIT.EDU> rich@eddie.MIT.EDU (Richard Caloggero) writes:
>     If you create a directory "d", then create a file "d/f" 1 megabyte
>long (big), then "rm d/f", is it true that the space remains allocated
>to directory "d" and cannot be garbage collected or otherwise reclaimed
>until another file is created in directory "d" or "d" is deleted?

The answer is `yes', but given the way you phrased the question, I think
you misunderstand what is going on.  The space FOR THE NAME `f' remains
allocated.  Since file names are typically very small, this makes little
difference (space is allocated in 512 byte or 1 kbyte units).  On the
other hand, if a directory grows very large (many file names) and the
file names are subsequently removed, the space remains occupied, except
in 4.3BSD and later versions of BSD, where any new file creation or
renaming will truncate any unused blocks off the end.  For this to
work, the remaining file names need to be near the front of the directory;
this can be arranged by renaming those files near the end:

	# approximately,
	# do
	ls -f
	mv last_name_shown x; mv x last_name_shown
	# until last_name_shown does not move.
	# the directory has now been compacted.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris