Subject: Re: Defragmenting a NetBSD drive
To: Brian Buhrow <buhrow@cats.ucsc.edu>
From: Robert Elz <kre@munnari.OZ.AU>
List: netbsd-ports
Date: 09/16/1999 03:04:44
    Date:        Wed, 15 Sep 1999 09:48:15 +0000
    From:        buhrow@cats.ucsc.edu (Brian Buhrow)
    Message-ID:  <199909151648.JAA25081@baloo.ucsc.edu>

  | The kernel already collects unused blocks of directories.  Given a
  | directory that takes up 2 512 byte blocks, if you remove enough directory
  | entries to cause the required space to drop to 1 512 byte block, as soon as
  | you create another directory entry, the compaction occurs.

Not quite.

That happens, if, and only if, the last block(s) of the directory are
empty - there's nothing which will move the entries around in a
directory so that the empty blocks appear at the end - nor to move directory
entries from one block to another so as to make empty blocks.

However, what is there is enough so that huge directories can be made
smaller using just standard tools (in particular, mv). 

	for file in *
	do
		mv "$file" X_$$ && mv X_$$ "$file"
	done

(plus the same for any .* files that exist).   When that is done, the
directory will be close to minimum size.

kre

ps: and for the historical record, the truncation technique was invented
at the University of Sydney sometime in the early 80's (perhaps even late 
70's).