tags:

views:

36

answers:

2

This might be sort of trivial question but in any case, i was wondering if there is a way to read a directory as a file which one will be using open(), close(), read() instead of opendir(), closedir(), readdir()...

I might be wrong, however, i'm thinking that this can speed-up directory traversing.

Thanks

A: 

No. Unless you're reading from the output of ls.

dlamblin
+1  A: 

This actually was how Unix directories worked, originally. The directory really was just a plain file like any other, and you read out a flat array of (IIRC) 16-byte records containing a 4 byte inode number and a 12 byte file name. opendir() and readdir() were simply library functions around that interface.

But starting with Sun's introduction of VFS in the mid-80's, there wasn't just one filesystem anymore. opendir and readdir became system calls instead, and the ability to read the "raw" content of a directory disappeared.

In any case, the filesystem authors have worked very (!) hard to make their code fast. There's nothing you can do externally to "speed up" directory traversal at this level. Try using fewer files, I guess.

Andy Ross