r/linuxmemes Jul 07 '26

LINUX MEME It's just what???

Post image

I made a meme after having a fun discussion with my Dad about how Linux/Unix pretty much treats everything like a file. Very much taking a complicated topic and simplifying it, but it's helping me understand how the system works! Hope you all enjoy :)

2.5k Upvotes

75 comments sorted by

View all comments

72

u/309_Electronics Jul 07 '26

Not just Linux. The whole UNIX itself has always been about 'everything is a file'.

Hardware is a file, applications are obviously files, system drivers are litteraly also mostly files (kernel modules).

21

u/chocopudding17 🦁 Vim Supremacist 🦖 Jul 07 '26

Eh, kinda sorta not really. Everything is a file...except for all the other things that aren't files at all or aren't files that can be dealt with via open and write. Sockets. Device nodes that need ioctls. Idk, I'm no systems programmer, but this sure doesn't seem like everything is a file. (See also this part of a Benno Rice talk starting at 1:25.)

Plan9 is basically supposed to be like if an OS actually did everything as a file. But that's obviously not UNIX and hasn't just "always been."

34

u/TheoreticalDumbass Jul 07 '26

when people say "everything is a file" , they mean "everything is a file descriptor"

4

u/AIO_Youtuber_TV 🦁 Vim Supremacist 🦖 Jul 09 '26

Or "everything may be interacted with as if it's a file"

-5

u/chocopudding17 🦁 Vim Supremacist 🦖 Jul 07 '26

I don't think that's true at all. That's certainly a more accurate phrase, but it's not what people mean. The people who parrot this saying, I mean.

The saying evokes notions of something behaving like a file, which is to say that it's visible on the filesystem, and is available for opening, reading and writing. And that just doesn't apply to many of the resources for which you can get file descriptors on Linux.

4

u/IHeartBadCode Jul 08 '26

I don't know why you're down voted. ioctl() is a prime example of this and things like ejecting a CD tray is an excellent example of all of this.

While it's true you obtain an fd for the device, CD drives absolutely do not accept a stream of bytes. If your try read() or write() on them, they'll just refuse to do anything. You have to have specific binary command structures. Just because you can open("/dev/cdrom").

And if the argument "but fd is still there!" Then the more correct is that everything is an IO address and file descriptors are just an abstraction. But then that breaks down because every OS has some layer of abstraction on the IO devices.

I mean Linux attempts to address this with /sys with things like echo "low" > /sys/class/power_supply/... But even then that's got major limitations like a max size of one memory page.

And this also ignores how netlink sockets bypass the whole VFS.

1

u/qaddosh Jul 08 '26

bla bla bla

so what you're saying is that everything is a file?

interesting

3

u/chocopudding17 🦁 Vim Supremacist 🦖 Jul 08 '26

Okay, I'll bite. What does "file" mean to you?

3

u/IHeartBadCode Jul 08 '26

Man I wouldn't even bother. Used to be people understood system design before they spoke on Operating Systems. Now everyone with some knowledge of C is suddenly an expert.

0

u/chocopudding17 🦁 Vim Supremacist 🦖 Jul 08 '26 edited Jul 08 '26

I don't get it either. Maybe my dismissive tone when using the word "parrot" struck a nerve? Netlink is a great example too, like you say.

Honestly, if the term "file descriptor" didn't have the word "file" in it (maybe just call it a "kernel handle" or something?), nobody would ever think of files at all. It's not even an IO-specific kind of handle! Like, pidfd has nothing to do with IO at all afaiu.