Subject: Re: problem with tmpfs and linux emulation?
To: YAMAMOTO Takashi <>
From: Steven M. Bellovin <>
List: current-users
Date: 11/12/2005 16:55:00
In message <>, 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>

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

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

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

        if (argc == 1) rd(".");
                for (i = 1; i < argc; i++)
        return 0;

		--Steven M. Bellovin,