Re: files "." and ".." from readdir()



In article <g5m9sh02gif@xxxxxxxxxxxxxxxxx>, phil-news-nospam@xxxxxxxx
wrote:

Will readdir always return "." and ".." as the _first_ two entries returned
if the filesystem has them? I'm just curious if it testing for them can be
skipped after the first two have been tested. I've always written my loops
around readdir with the tests applied in every case.

While most filesystems will probably work this way most of the time,
it's not a good idea to depend on it. It will probably make your loop
more complicated, and the efficiency gained will be negligible on modern
hardware.

It would probably be better to lobby POSIX to create a readdir_nodots()
system call that automatically ignores the "." and ".." entries. A
number of filesystems don't actually have these in the directory, so the
system call has to simulate them on the fly; this call would be simpler,
and many applications (like yours) would happily use it. Although
because it would be new, you'd probably have to maintain the old loop
for a while to be portable to older systems.

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.



Relevant Pages

  • Re: [PATCH][RFC] fast file mapping for loop
    ... Jens Axboe wrote: ... COW is not that hard to handle, you just need to be notified of moving ... But at least for the loop use case, most non-cow filesystems will want ...
    (Linux-Kernel)
  • Re: files "." and ".." from readdir()
    ... While most filesystems will probably work this way most of the time, ... It will probably make your loop ... There's no need for readdir() to simulate those entries if they ... It just won't return them (which POSIX allows). ...
    (comp.unix.programmer)
  • Re: [PATCH] VFS readahead bug in 2.6.8-rc[1-3]
    ... The check needs to be in the for loop. ... That way all filesystems that cannot handle out-of-bound index access ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Sharing on Solaris 10 - newbie question
    ... where as opt has tons. ... Solaris allows what you call "hard linking across filesystems". ... actually called loop back mounting with the loop back filesystem. ...
    (comp.unix.solaris)
  • [2.6.24-rc] pdflush stuck in D state
    ... significantly different hardware but probably almost identical core kernel ... # SCSI support type ... # Input Device Drivers ...
    (Linux-Kernel)