Subject: Re: Defragmenting a NetBSD drive
To: Guenther Grau <>
From: Todd Whitesel <>
List: netbsd-ports
Date: 09/17/1999 22:24:45
> Ok, you are right. All the processes doing a opendir()/readdir()
> need to fail when the directory changes behind their backs.
> So a real solution (I wonder what I forgot now :-) would be
> to return E_DIRWASCHANGED on readdir() in this case, and
> fix all the programs you were talking about to handle this
> case, right? This should be possible, as the kernel should know
> which processes have the directory open for reading and could
> mark the fds as invalid for additional readdir() calls.

Ultimately I have to come down against something like E_DIRWASCHANGED
for the same reason that EINTR is a bug generator. Ideally, user programs
should be allowed to be sloppy, and only the kernel should be required to
maintain anal-retentive levels of discipline. This is one element of
reliability-by-design IMHO.

For me, I don't care about perfect compaction of directories, I'd just
like to find ways of allowing background garbage collection to occur.

How about requiring the garbage collector userland thingy to readdir()
each directory, and request for each name encountered that it be packed
forward in the directory? The packing syscall would fail gracefully if
it would have to move the directory slot across any other readdir()
pointers. At the end of the directory, another request could be issued
to truncate off any unused space at the end of the directory.

This would clean up what it can, without fouling up any other processes
that might be using the tree.

Todd Whitesel
toddpw @