5 ms·
In the order I happen to think of them: Filenames may be straightforward on the filesystem level, but a lot of UNIX programs do weird things with them. Many pro
by jerf 10y ago
In the order I happen to think of them: Filenames may be straightforward on the filesystem level, but a lot of UNIX programs do weird things with them. Many programs use "-" to mean STDIN or STDOUT as appropriate where it is used. Bash has a somewhat ill-conceived feature where it synthesizes a /dev/tcp/$host/$port filesystem that will write to TCP or UDP sockets. Most people don't know about this, a few people think it's a UNIX feature rather than a bash-ism.
The fact that multiple /s will be normalized to be the same as one sometimes trips up security code or code trying to validate that some particular file isn't used (i.e., checking that the filename doesn't start with /dev or a list of other blacklisted directories will fail if the user passes //dev).
Symlinks! Oh, gosh, symlinks. Were this not a stream-of-consciousness dump they probably should come first. You can do terrible things with symlinks, like upload a tarball or zip file that creates a symlink to an arbitrary location in the system, then use that symlink reference as a directory reference to plop a file down. (Some archivers prevent this, others don't.)
Also, /dev is just a convention, it's possible to place device nodes anywhere you want.
You can also pretty much mount arbitrary things in arbitrary places via bind mounts. Hard links can also cause some fun with code that assumes file systems aren't cyclic. Windows technically has a lot of these features but they're harder to get to and less well known whereas UNIX uses the various links in base Linux installs and they're readily available.
- int_19h 10y agoSymlinks are a poor example, IMO. Yes, they need to be carefully handled for security reasons. But they also offer great flexibility that is actually widely used, and that wouldn't be available through other mechanisms.
- annnnd 10y agoTo paraphrase: Windows NUL is a poor example, IMO. Yes, it needs to be carefully handled for reasons. But it also offers great flexibility that is actually widely used, and that wouldn't be available through other mechanisms. I rest my case. ;-)
- luca_ing 10y agoWhile your reply is genuinely amusing (thank you), how is it actually true? What do we gain from having NUL everywhere, as opposed to having it in only one specific location, e.g. root? Also, as an aside, I thought it wasn't a magic file (nul), but rather a magic device (NUL:), which IMO makes a lot of sense.
- fnord123 10y agoBut that's just not true. They offer less flexibility that would be available through a special namespace prefix like /dev.
- leshow 10y agoIt doesn't offer great flexibility though. It has characteristics that made it useful on ancient versions of DOS and now it only offers annoyances that we have to deal with.
- marvy 10y agoIs there any particular reason not to have something like /dev/tcp as a real filesystem, rather than a pretend game that bash likes to play?
- tjalfi 10y agoThere were several implementations of that idea in the early 1980s. The following paper describes one of them. More Taste: Less Greed? or Sending UNIX to the Fat Farm[0] describes a V7 derivative that had /dev/deuna, /dev/arp, /dev/ip, and /dev/udp. [0] http://www.collyer.net/who/geoff/taste.pdf http://www.collyer.net/who/geoff/taste.pdf
- marvy 10y agoNot much details though. Oh well.
- tjalfi 10y agoThe code in Research Unix V8, V9, and V10 is available. Alcaltel-Lucent made them public a couple months ago[0]. Here are the relevant URLs and file paths within the archives. I already had them on my hard drive and it was easy to grep them. I removed a few columns from the output of tar. V8 http://www.tuhs.org/Archive/Distributions/Research/Dan_Cross_v8/v8.tar.bz2 http://www.tuhs.org/Archive/Distributions/Research/Dan_Cross... 12738 Jul 25 1985 usr/sys/inet/tcp_device.c V9 http://www.tuhs.org/Archive/Distributions/Research/Norman_v9/batterpudding.tar.gz http://www.tuhs.org/Archive/Distributions/Research/Norman_v9... 13461 Aug 6 1986 ./sys/inet.old/old/tcp_device.c 13457 Feb 3 1987 ./sys/inet.old/tcp_device.c 13457 Feb 24 1987 ./sys/inet/tcp_device.c V10 http://www.tuhs.org/Archive/Distributions/Research/Dan_Cross_v10/v10src.tar.bz2 http://www.tuhs.org/Archive/Distributions/Research/Dan_Cross... 13542 Feb 20 1990 lsys/inet/tcp_device.c 13622 Mar 9 1992 sys/inet/tcp_device.c [0]https://news.ycombinator.com/item?id=13971909 https://news.ycombinator.com/item?id=13971909 Edited to fix formatting.
- marvy 10y agoOh, nice! But I can't find the right man page.