Wojtek Lerch <wojtek_l@yahoo.ca> wrote:
Robert Krten <> nospam83@parse.com> > wrote:
Wojtek Lerch <> wojtek_l@yahoo.ca> > wrote:
…
Robert Krten <> nospam83@parse.com> > wrote:
I assume that it is invalid to move directory entries around
in a directory while an opendir() is in effect, right?
…
In your example, “c” was neither created nor deleted, so it’s your
responsibility to make sure that readdir() reports it. The easiest way
may be by never moving stuff around, but that doesn’t mean it’s the only
way…
Ok, but that gets complicated 'cuz I now have to keep track of all the
users of a directory to see how far they’ve read and only make changes on
stuff that they haven’t read you – if I wanted, for example, to keep all
my directory entries sorted >
> that would be problematic…
You could take a complete snapshot of the directory when someone calls
opendir(), and feed it in pieces to their readdir() calls.
OMG! Now that’s a DOS attack waiting to happen ![:slight_smile: :slight_smile:](/images/emoji/twitter/slight_smile.png?v=9)
I’ll be avoiding that, as directories are unbounded in size ![:slight_smile: :slight_smile:](/images/emoji/twitter/slight_smile.png?v=9)
I think I’ll just do the placeholder-for-deleted-entries stuff – that
seems to work fine for now…
Sure; that’s how filesystems work, and that’s what POSIX is modelled
after, right?
That’s how some filesystems work, yes…
If you keep track of how many readers you have, you can remove the
placeholders on the last closedir(). And if someone deletes a file
while you know there’s no readers, you don’t have to create a
placeholder.
I was thinking of a “cleanup” thread that would run around at low
priority optimizing things, but… I’ll prolly avoid that in the
short term as well.
There is one optimization I do already, which is to clean out entries
starting at the end – if you delete a whack of entries, and then (finally)
delete the last entry, the directory will collapse to no longer take into
account the FINAL deleted components.
Cheers,
-RK
–
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.