icsu7039@attila.cs.montana.edu (Spannring) (04/29/91)
A few years back I purchased a book called "Programming in the Unix Environment" by Kernighan and Pike. After reading this book I was impressed how everything in Unix is just a file. In fact, they showed how even a directory is just another file. There was an example using the od command to look at the actual contents of the current working directory. Then they wrote some nifty C functions to take an incorrectly spelled file name and make a guess as to what the user really meant. Times have changed. I tried using od to look at my current directory on an Ultrix box. No dice. So I wrote a little program using only low-level system calls. No dice. f = open(".", ORDONLY) worked fine, but read(f, buf, 1) failed with errno equal to 21 (EISDIR). It seems to me that Unix used to be a nice little OS without special cases. Not any more. Since handling special cases will slow the system down, why do it? Comments? Explanations? -- ==================================================================== Six of one, 110 (base 2) of | Craig Spannring another. | icsu7039@caesar.cs.montana.edu ----------------------------------+--------------------------------
rearl@gnu.ai.mit.edu (Robert Earl) (04/29/91)
Was the directory mounted across NFS? If so, file operations like this one on directories fail, as you pointed out. --robert
allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/AA) (04/30/91)
As quoted from <REARL.91Apr29125106@nutrimat.gnu.ai.mit.edu> by rearl@gnu.ai.mit.edu (Robert Earl): +--------------- | Was the directory mounted across NFS? If so, file operations like | this one on directories fail, as you pointed out. +--------------- Way back when, a directory was just a file. Nowadays, however, directories in different filesystems can have extremely different formats (courtesy FSSW or vnodes) or even not actually exist! It's a lot easier to fail a directory read with EISDIR than it is to have special code to generate and/or modify directory entries to be what a program reading the directory as a file expects. ++Brandon -- Me: Brandon S. Allbery Ham: KB8JRR/AA 10m,6m,2m,220,440,1.2 Internet: allbery@NCoast.ORG (restricted HF at present) Delphi: ALLBERY AMPR: kb8jrr.AmPR.ORG [44.70.4.88] uunet!usenet.ins.cwru.edu!ncoast!allbery KB8JRR @ WA8BXN.OH
flee@cs.psu.edu (Felix Lee) (05/01/91)
Well, given that getdents() is a system call, the obvious thing to do is to treat directories as objects that return a sequence of dirents when read. Unfortunately, getdents() wants you to give it a "real" lseek offset for the real directory file. -- Felix Lee flee@cs.psu.edu