I was reading about SockFS, and I'm wondering why there seems to be no mount driver for it. That is, if SockFS implements the VFS API for UDP and TCP sockets, why is there no userspace filesystem representation of sockets, such that I could cat /net/tcp/151.101.65.69/80
and echo "GET /v1/users/some-id HTTP/1.1" > /net/tcp/192.168.0.5/8000
or something?
In fact, with Unix socket implementing the same socket API as TCP and UDP sockets, and also having filesystem representations, this makes even less sense.
EDIT: Found out about /proc/*/fd/*
socket files/symlinks from What's the meaning of [socket:number] in /proc/pid/fd, though they don't seem very useful since you can't read or write from/to them.
root@drpyser-thinkpad[192.168.8.224] in /proc/1
❯ ll fd/18
lrwx------ root root 64 B Fri Feb 24 13:54:16 2023 fd/18 ⇒ socket:[14810]
root@drpyser-thinkpad[192.168.8.224] in /proc/1
❯ file fd/18
fd/18: symbolic link to socket:[14810]
root@drpyser-thinkpad[192.168.8.224] in /proc/1
❯ socket:[14810]^C
root@drpyser-thinkpad[192.168.8.224] in /proc/1
❯ cat fd/18
cat: fd/18: No such device or address
root@drpyser-thinkpad[192.168.8.224] in /proc/1
✖1 ❯ cat > fd/18
warning: An error occurred while redirecting file 'fd/18'
open: No such device or address
EDIT2: Beside Plan 9, I also found this implementation of the concept for FreeBSD: http://csr.bu.edu/icnp2005/posters/netfs_abstract.pdf.
cat
and such. Creating sockets would be done with existing socket-creation utilities. – Charles Langlois Feb 28 '23 at 22:42It does get a bit confusing, though! Multiple processes could both open /net/tcp/192.168.0.5/8000, and would you expect that to be the same connection, or two separate connections?
That's a good point. How does SockFS work is the question. I can find very little documentation on SockFS, which is suspicious.
– Charles Langlois Feb 28 '23 at 22:58open
syscall implemented for sockfs? What does it do? – Charles Langlois Mar 01 '23 at 20:25socket
call, you get a socket descriptor that behaves a lot like a file descriptor. File descriptors are part of some file system hierarchy. Sockfs is basically nothing but the "do nothing" file system hierarchy, so that socket descriptors really can be handled like file descriptors. It literally has nothing to do with what you want to achieve. – Marcus Müller Mar 01 '23 at 20:27sockfs
. If it was calledhelper_data_structure_so_that_we_dont_have_to_do_if_else_in_every_read_and_write_call_to_treat_file_descriptors_differently_from_socket_descriptors_fs
, you would have no problem understanding it :) – Marcus Müller Mar 01 '23 at 20:42