FDESCFS(4)

πŸ“¦ version 15.1, in freebsd 15.1, nixpkgs unstable

🌸 NAME 🌸

okay bestie, say hi to fdescfs(4) β€” the file-descriptor file system. this is a kernel interfaces manual page, and honestly it's giving main character energy for something that lives in the kernel. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

fdescfs /dev/fd fdescfs rw 0 0

✨ DESCRIPTION ✨

so fdescfs is the file-descriptor file system, and it gives you access to the per-process file descriptor namespace right inside the global file system namespace. the conventional mount point is /dev/fd. no cap. 🫢

The file system's contents show up as a list of numbered files, and those correspond to the open files of the process that's reading the directory. the files /dev/fd/0 through /dev/fd/# refer to file descriptors that you can access through the file system. iconic behavior, honestly. ✨

The following mount options can be used when mounting an fdescfs filesystem:

  • nodup β€” for file descriptors referencing vnodes, instead of the dup(2) semantic described above, this implements re-opening of the referenced vnode. see below for more details. πŸ‘€
  • linrdlnk β€” reports the type of the fdescfs vnode as VLNK instead of the FreeBSD traditional VCHR. for linux(4) ABI compatibility, mount an fdescfs volume with the linrdlnk option. 🐧
  • rdlnk β€” treats fdescfs vnodes as symbolic links consistently; in particular, it follows the resolved name for name lookups. this option is strictly stronger than the linrdlnk option: it changes not only the type returned by stat(2), but also causes the fdescfs files to behave as symlinks. lowkey powerful. πŸ”₯

For an fdescfs mounted without the nodup mount option, if the file descriptor is open and the mode the file is being opened with is a subset of the mode of the existing descriptor, then this call:

fd = open("/dev/fd/0", mode);

and this call:

fd = fcntl(0, F_DUPFD, 0);

are equivalent. flags to the open(2) call other than O_RDONLY, O_WRONLY and O_RDWR are ignored. periodt. πŸ’…

For an fdescfs mounted with the nodup option, and a file descriptor referencing a vnode, this call:

fd = open("/dev/fd/0", mode);

reopens the referenced vnode with the specified mode. in other words, that open() call above is equivalent to:

fd = openat(0, "", O_EMPTY_PATH, mode);

In particular, if the file descriptor was opened with the O_PATH flag, then either O_EMPTY_PATH or open() over an fdescfs mount with the nodup option lets you convert it to a regularly opened file, assuming that the current permissions allow the requested mode. fr fr, permissions still run this. πŸ™ˆ

Note: /dev/fd/0, /dev/fd/1 and /dev/fd/2 files are created by default when devfs alone is mounted. fdescfs creates entries for all file descriptors opened by the process. πŸ‘‘

πŸŽ€ FILES πŸŽ€

  • /dev/fd/#

🌈 EXAMPLES 🌈

To mount an fdescfs volume located on /dev/fd:

mount -t fdescfs none /dev/fd

For linux(4) ABI compatibility:

mount -t fdescfs -o linrdlnk none /compat/linux/dev/fd

For substitute of the O_EMPTY_PATH flag, use:

mount -t fdescfs -o nodup none /dev/fdpath

πŸ¦‹ SEE ALSO πŸ¦‹

⭐ HISTORY ⭐

The fdescfs file system first appeared in 4.4BSD. the fdescfs manual page first appeared in FreeBSD 2.2. history really said "let there be fd files." 😭

πŸ‘‘ AUTHORS πŸ‘‘

The fdescfs manual page was written by Mike Pritchard <mpp@FreeBSD.org>, and was based on the manual page written by Jan-Simon Pendry. shoutout to the OGs. 🫢


mwah πŸ’‹ β€” source/version: Debian; date: Jul 11, 2023; manual: FDESCFS(4). bye bestie, go mount something cute. 🌸

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • nixpkgs unstable: source
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms