News for hackers. Stuff that matters.
Re:The everything-is-a-file principle – Linus Torvalds by vbezhenar on Saturday July 14, 2018 @06:13PM (#17532675)
There are many abstractions with Unix that are not files. I don't even know any modern unix, where directory is a file.
Re:The everything-is-a-file principle – Linus Torvalds by lazyant on Saturday July 14, 2018 @06:31PM (#17532746)
A directory is just a special type of file that contains a list of file names and their corresponding inodes, how is a directory NOT a file?
Re:The everything-is-a-file principle – Linus Torvalds by ioquatix on Saturday July 14, 2018 @07:14PM (#17532887)
That's a reasonable point at an abstract level. But in reality, while you use `open`, `read`, `write` and `close` for files, the equivalent for directories is `opendir`, `readdir`, `closedir`.
Re:The everything-is-a-file principle – Linus Torvalds by elderK on Sunday July 15, 2018 @01:53AM (#17533988)
I don't see how providing specialized open/read/close calls for directories breaks the file abstraction.

Imagine byte-level access to a directory. You'd have to have some library in userspace that would correctly be able to manipulate that directory's metadata. Now imagine doing that for various filesystems.

Plan 9's namespaces and file-servers were pretty awesome and flexible. It really opened my eyes to the generality of the file abstraction.

Re:The everything-is-a-file principle – Linus Torvalds by DonHopkins on Sunday July 15, 2018 @09:02AM (#17535071)
I do see how having a specialized set of calls for directories breaks the abstraction that directories are files. Isn't that the very definition of breaking the abstraction?
Re:The everything-is-a-file principle – Linus Torvalds by elderK on Tuesday July 17, 2018 @05:28AM (#17548419)
:) Care to elaborate?

I mean, as far as I see it, the directory is still a file, of a specific format.

How is that any different than an image file, say, of a particular format? You still need specialized programs in order to manipulate them in a meaningful way. But they're just bytes. Just like the directory is just bytes.

The difference, of course, is that allowing the user to arbitrarily manipulate a directory entry at the byte-level could lead to filesystem corruption.

I'm aware I may be missing something really obvious here. Heck, even contradicting myself :)

Educate me :)

Re:The everything-is-a-file principle – Linus Torvalds by DonHopkins on Tuesday July 17, 2018 @01:00PM (#17551188)
Well, you could unify the interface to files and directories by removing all the system calls to deal with opening and closing and reading and writing files, and then removing all the system calls to deal with opening and closing and reading and writing directories, and then simply using ioctl() for everything!
Re:The everything-is-a-file principle – Linus Torvalds by zokier on Saturday July 14, 2018 @06:34PM (#17532758)
> I don't even know any modern unix, where directory is a file.

On Linux? You `open()` a directory, and `getdents()` takes that file descriptor as input.

Re:The everything-is-a-file principle – Linus Torvalds by gaius on Sunday July 15, 2018 @03:58AM (#17534276)
You `open()` a directory, and `getdents()` takes that file descriptor as input.

“These are not the interfaces you are interested in. Look at readdir(3) for the POSIX-conforming C library interface.” — getdents manpage

Re:The everything-is-a-file principle – Linus Torvalds by zbentley on Sunday July 15, 2018 @08:30AM (#17534963)
The same is true with signals, timers, filesystem notifications, etc.

There are a few (redundant/duplicated with minor feature differences in triplicate, 'cause it's Linux) file-ish abstractions over parts of those concepts, but those abstractions are neither the only, recommended, or most widely used means of accessing those functionalities.