Subject: Re: Defragmenting a NetBSD drive
To: Brian Buhrow <>
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: (Brian Buhrow)
    Message-ID:  <>

  | 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 *
		mv "$file" X_$$ && mv X_$$ "$file"

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


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