Unix Programming - Two questions about opendir and readdir

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2004 > Two questions about opendir and readdir





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Two questions about opendir and readdir
music4

2004-07-29, 7:52 am

Greetings,

Generally, I work on Solaris 2.8 operating system.

1. In which case I have to use readdir64()? If every file's size is less
than 2G under a dir, but total size of the dir is larger than 2G, do I need
to use readdir64()?

2. What's order of output of readdir()? It seems readdir get file entries by
mtime order, but I could not find a documenation to clarify that. Is it
true?

Thanks in advance,
Evan


Juha Laiho

2004-07-29, 5:55 pm

"music4" <music4@163.net> said:
>2. What's order of output of readdir()? It seems readdir get file entries by
>mtime order, but I could not find a documenation to clarify that. Is it
>true?


Order is not specified;
On "old" filesystems (so, derivatives of FFS/UFS), it was "directory order",
as directory was a simple data inode where entries had a constant size, and
each new entry was written to first unused position in the directory data.
So, the directory order was just the order in which the entries happened to
be in the directory data.
On newer filesystems (VxFS, Linux reiserfs, others) the directory structure
is some kind of hash; I guess the "directory order" there depends on the
hash scan mechanism, as no "simple" order exists any more.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
Aaron Isotton

2004-07-29, 5:55 pm

On Thu, 29 Jul 2004 17:04:47 +0800, music4 wrote:
> Generally, I work on Solaris 2.8 operating system
>
> 1. In which case I have to use readdir64()? If every file's size is

less
> than 2G under a dir, but total size of the dir is larger than 2G, do I
> need to use readdir64()?


readdir() will fail if 'One of the values in the structure to be returned
cannot be represented correctly.'; in this case, errno will be set to
EOVERFLOW.

See also:

http://www.unix.org/version2/whatsnew/lfs.html

I'm not totally sure about how this applies to SUSv3; in fact, SUSv3 does
/not/ specify any function readdir64().

> 2. What's order of output of readdir()? It seems readdir get file entries by
> mtime order, but I could not find a documenation to clarify that. Is it
> true?


SUSv3 does not specify any special order of the entries returned by
readdir(); I think that this is OS- and File-System dependent; probably
the files are being returned in the order they are stored in the file
system.

Greetings,
Aaron
--
Aaron Isotton | http://www.isotton.com/
You know it's Monday when you wake up and it's Tuesday. -- Garfield

David Schwartz

2004-07-29, 5:55 pm


"music4" <music4@163.net> wrote in message
news:ceaejd$juj@netnews.proxy.lucent.com...

> 1. In which case I have to use readdir64()? If every file's size is less
> than 2G under a dir, but total size of the dir is larger than 2G, do I
> need
> to use readdir64()?


It has nothing to do with the sizes of the files but with the size of
the directory itself (which has nothing to do with the sizes of the files in
it). You can't really have a directory over 2G in any sensible way I can
think of, so readdir64 should almost never be needed.

> 2. What's order of output of readdir()? It seems readdir get file entries
> by
> mtime order, but I could not find a documenation to clarify that. Is it
> true?


The order is arbitrary. You can't rely on it being anything specific.

DS


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com