Subject: Re: problem with tmpfs and linux emulation?
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: Steven M. Bellovin <smb@cs.columbia.edu>
List: current-users
Date: 11/12/2005 16:55:00
In message <1131830239.441703.10393.nullmailer@yamt.dyndns.org>, YAMAMOTO Takas
hi writes:
>> > Linux libc doesn't use read(2) to read directories, it uses
>> > getdents64().
>> 
>> "It depends".  There were discussions on linux kernel lists as little
>> as a year ago about how it would be _nice_ to be able to assume that
>> libc always used getdents64() to avoid supporting lseek() on directories.
>> 
>> Thor
>
>are you sure?
>iirc, linux doesn't support read(2) on directories, even for ext2.
>

Certainly, my test program on Linux systems can't read any directories 
using read(2) -- I tried ext2, ext3, devpts, and NFS-mounted file 
systems.  Amusingly enough, that simple test program did work on NetBSD 
via linux emulation for ffs file systems.  It failed for tmpfs file 
systems the same way it failed for Linux: "Is a directory".  For /proc 
and /kern, it said "Operation not supported", which is a different 
error than I get on Linux.

---------
#include <stdio.h>

void
rd(char *dir)
{
        unsigned char buf[1024];
        int fd, i, n;

        fd = open(dir, 0);
        if (fd < 0) {
                perror(dir);
                return;
        }
        while ((n = read(fd, buf, sizeof buf)) > 0) {
                for (i = 0; i < n; i++)
                        printf("%02x", buf[i]);
                printf("\n");
        }
        if (n < 0)
                perror("read");
        (void) close(fd);
        return;
}

main(int argc, char *argv[])
{
        int i, rc;

        if (argc == 1) rd(".");
        else
                for (i = 1; i < argc; i++)
                        rd(argv[i]);
        return 0;
}


		--Steven M. Bellovin, http://www.cs.columbia.edu/~smb