3 ms·
Which was the last Unix release/flavor where you could still read(2) a directory? All manpages that I've found say that you get EISDIR if you try it.
by rzzzt 8y ago
Which was the last Unix release/flavor where you could still read(2) a directory? All manpages that I've found say that you get EISDIR if you try it.
- Pete_D 8y agoI certainly remember being surprised when I accidentally cat'd a directory on AIX and it worked. I can't remember exactly what you get back; I think it's a NUL-separated list of the files in it.
- Someone 8y agoThat depends on the file system (and, possibly, the OS, but I think the OS should just forward the call to the relevant driver and return its result) FreeBSD’s man page says (https://www.freebsd.org/cgi/man.cgi?sektion=2&query=read https://www.freebsd.org/cgi/man.cgi?sektion=2&query=read): [EISDIR] The file descriptor is associated with a directory residing on a file system that does not allow regular read operations on directories (e.g. NFS) NetBSD says something similar, adding ”The readdir() function should be used instead.” I also am not convinced that, for example, the Linux man page (http://man7.org/linux/man-pages/man2/read.2.html http://man7.org/linux/man-pages/man2/read.2.html) guarantees you get EISDIR when reading from a directory. It says that if you get EISDIR, fd refers to a directory, but isn’t explicit about the converse.
- rzzzt 8y agoYou are right. The default implementation in Linux returns -EISDIR, but filesystems are free to change it to something else: https://github.com/torvalds/linux/blob/2a56bb596b2c1fb612f9988afda9655c8c872a6e/fs/libfs.c#L211-L214 https://github.com/torvalds/linux/blob/2a56bb596b2c1fb612f99... https://github.com/torvalds/linux/search?p=1&q=generic_read_dir&unscoped_q=generic_read_dir https://github.com/torvalds/linux/search?p=1&q=generic_read_...
- koenigdavidmj 8y agoFreeBSD would allow this as of a few years ago (2007 at the earliest).
- skibo 8y agoStill does. I'm running 12-CURRENT and it looks like UFS allows it. I occasionally cat or more a directory by accident and get a screen full of junk.
- j-pb 8y agoImagine if unix was invented today and you would navigate a folder by reading it, and having a JSON encoded file of its content returned. Slow but so elegant and pretty.
- arendtio 8y agoIf unix was invented today, you would have 3rd party files everywhere, executing randomly and typing the newest offers to your prompt automatically.
- LukeShu 8y agoI know that SunOS 5.10 could read(2) a directory (that's what lore.cs.purdue.edu was running).