"Cleaning up" inodes in a directory

J

J.A. Hacker

Hello,

There's a fixed directory, mydir. This directory contains many files;
frequently, files are removed (in a random order) and new files added.

Now I have some code that reads the directory entries periodically with
readdir(3) or scandir(3) or equivalent. It would be nice if the order the
files came out was essentially in order of their creation, without
needing to sort. Instead, new files' inodes seem to "fill in the gaps" in
the directory's structure.

What I envisage is a sort of "compactification" of the directory that
rearranges the inodes in the B-tree(?) making up the directory, so that
the next file created in the directory will get its inode added at the end
of the tree. Then after removing a file in mydir, this compactifier would
be called to keep the entries in order.

Would that be easy to achieve? Is there a utility function or program that
already does it?

Cheers!
 
J

Joachim Schmitz

J.A. Hacker said:
Hello,

There's a fixed directory, mydir. This directory contains many files;
frequently, files are removed (in a random order) and new files added.

Now I have some code that reads the directory entries periodically
with readdir(3) or scandir(3) or equivalent. It would be nice if the
order the files came out was essentially in order of their creation,
without needing to sort. Instead, new files' inodes seem to "fill in
the gaps" in the directory's structure.

What I envisage is a sort of "compactification" of the directory that
rearranges the inodes in the B-tree(?) making up the directory, so
that the next file created in the directory will get its inode added
at the end of the tree. Then after removing a file in mydir, this
compactifier would be called to keep the entries in order.

Would that be easy to achieve? Is there a utility function or program
that already does it?

Try comp.unix.programmer.

Bye, Jojo
 
D

David Schwartz

There's a fixed directory, mydir. This directory contains many files;
frequently, files are removed (in a random order) and new files added.
Now I have some code that reads the directory entries periodically with
readdir(3) or scandir(3) or equivalent. It would be nice if the order the
files came out was essentially in order of their creation, without
needing to sort. Instead, new files' inodes seem to "fill in the gaps" in
the directory's structure.

Are you looking to guarantee the order? Or just reduce the amount of
work the sort needs to do?

Those are two very different things, one much easier than the other.

DS
 
K

Keith Thompson

CBFalconer said:
You forgot to set follow-ups.

Anyone answering J.A. Hacker's question is going to post a followup to
J.A. Hacker's article, not to Joachim Schmitz's followup. Setting
followups on the followup would be pointless.

(I haven't set followups in this article; choose wisely if you post a
followup to this.)
 
J

Joachim Schmitz

Keith said:
Anyone answering J.A. Hacker's question is going to post a followup to
J.A. Hacker's article, not to Joachim Schmitz's followup. Setting
followups on the followup would be pointless.

Indeed, that's why I deliberatly decided against a follow up...

Bye, Jojo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top