Re: ext2fs: do directories ever shrink?

Clifford Wolf (clifford@clifford.at)
Mon, 13 Jul 1998 16:48:47 +0200 (MEST)


On Sun, 12 Jul 1998, Dancer wrote:

> I remember this same thing in every unix system I've ever written
> software on. There may be 'standard' unix filesystems out there that
> don't partake of this behaviour...I just never recall seeing one.
>
> Jakob Borg wrote:
> >
> > If a directory is created and filled with, say, 500 files, it will
> > grow to 6K in size. It will retain this size when all files in it are
> > unlinked.
> >
> > Does it ever shrink in size or will it retain it's 6 blocks until
> > it's unlinked? If so, is this just another form of preallocation, in
> > case we would that many files again in the same directory?

I don't know much about the implementation of the ext2 fs, but on most
unixes a directorie is just a file which is accesed useing diffrent kernel
functions (on some unixes - e.g. HP-UX - you can do a read() on a dir).

A general behaviour with UNIX files is that a file can never shrink! A
file can be trucated - but it can shrink e.g. from 10 bytes to 5. Since
a directory is just a file it can't shrink too (except the implementation
contains additional code for it).

But what you can do if you have a large directory with only a few files
(let's call the dir 'foobar') is:

" mkdir temp ; mv foobar/* temp/ ; rmdir foobar ; mv temp foobar "

happy hacking,
clifford

-- -- -- -- -- -- -- -- -- -- -- -- --
Clifford Wolf
magnet - Internet at Work IRC: efnet / clifford
Director of System Development http://www.clifford.at/
e-mail: c.wolf@magnet.at email: god@clifford.at

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html