3 ms·
That 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
by Someone 8y ago
That 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_...