1*dab59af3SLi-Wen Hsu.\" Copyright (c) 2021 The FreeBSD Foundation 21687d771SAlexander Ziaee.\" 31687d771SAlexander Ziaee.\" Copyright (c) 1996 41687d771SAlexander Ziaee.\" Mike Pritchard <mpp@FreeBSD.org>. All rights reserved. 51687d771SAlexander Ziaee.\" 61687d771SAlexander Ziaee.\" Copyright (c) 1992, 1993, 1994 71687d771SAlexander Ziaee.\" The Regents of the University of California. All rights reserved. 81687d771SAlexander Ziaee.\" All rights reserved. 91687d771SAlexander Ziaee.\" 101687d771SAlexander Ziaee.\" This code is derived from software donated to Berkeley by 111687d771SAlexander Ziaee.\" Jan-Simon Pendry. 121687d771SAlexander Ziaee.\" 131687d771SAlexander Ziaee.\" Parts of this documentation was written by 141687d771SAlexander Ziaee.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship 151687d771SAlexander Ziaee.\" from the FreeBSD Foundation. 161687d771SAlexander Ziaee.\" 171687d771SAlexander Ziaee.\" Redistribution and use in source and binary forms, with or without 181687d771SAlexander Ziaee.\" modification, are permitted provided that the following conditions 191687d771SAlexander Ziaee.\" are met: 201687d771SAlexander Ziaee.\" 1. Redistributions of source code must retain the above copyright 211687d771SAlexander Ziaee.\" notice, this list of conditions and the following disclaimer. 221687d771SAlexander Ziaee.\" 2. Redistributions in binary form must reproduce the above copyright 231687d771SAlexander Ziaee.\" notice, this list of conditions and the following disclaimer in the 241687d771SAlexander Ziaee.\" documentation and/or other materials provided with the distribution. 251687d771SAlexander Ziaee.\" 3. Neither the name of the University nor the names of its contributors 261687d771SAlexander Ziaee.\" may be used to endorse or promote products derived from this software 271687d771SAlexander Ziaee.\" without specific prior written permission. 281687d771SAlexander Ziaee.\" 291687d771SAlexander Ziaee.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 301687d771SAlexander Ziaee.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 311687d771SAlexander Ziaee.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 321687d771SAlexander Ziaee.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 331687d771SAlexander Ziaee.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 341687d771SAlexander Ziaee.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 351687d771SAlexander Ziaee.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 361687d771SAlexander Ziaee.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 371687d771SAlexander Ziaee.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 381687d771SAlexander Ziaee.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 391687d771SAlexander Ziaee.\" SUCH DAMAGE. 401687d771SAlexander Ziaee.\" 411687d771SAlexander Ziaee.Dd Jul 11, 2023 421687d771SAlexander Ziaee.Dt FDESCFS 4 431687d771SAlexander Ziaee.Os 441687d771SAlexander Ziaee.Sh NAME 451687d771SAlexander Ziaee.Nm fdescfs 461687d771SAlexander Ziaee.Nd file-descriptor file system 471687d771SAlexander Ziaee.Sh SYNOPSIS 481687d771SAlexander Ziaee.Bd -literal 491687d771SAlexander Ziaeefdescfs /dev/fd fdescfs rw 0 0 501687d771SAlexander Ziaee.Ed 511687d771SAlexander Ziaee.Sh DESCRIPTION 521687d771SAlexander ZiaeeThe file-descriptor file system, or 531687d771SAlexander Ziaee.Nm , 541687d771SAlexander Ziaeeprovides access to the per-process file descriptor 551687d771SAlexander Ziaeenamespace in the global file system namespace. 561687d771SAlexander ZiaeeThe conventional mount point is 571687d771SAlexander Ziaee.Pa /dev/fd . 581687d771SAlexander Ziaee.Pp 591687d771SAlexander ZiaeeThe file system's contents 601687d771SAlexander Ziaeeappear as a list of numbered files 611687d771SAlexander Ziaeewhich correspond to the open files of the process reading the 621687d771SAlexander Ziaeedirectory. 631687d771SAlexander ZiaeeThe files 641687d771SAlexander Ziaee.Pa /dev/fd/0 651687d771SAlexander Ziaeethrough 661687d771SAlexander Ziaee.Pa /dev/fd/# 671687d771SAlexander Ziaeerefer to file descriptors which can be accessed through the file 681687d771SAlexander Ziaeesystem. 691687d771SAlexander Ziaee.Pp 701687d771SAlexander ZiaeeThe following mount options can be used when mounting 711687d771SAlexander Ziaee.Nm 721687d771SAlexander Ziaeefilesystem: 731687d771SAlexander Ziaee.Bl -tag -width linrdlnk 741687d771SAlexander Ziaee.It Cm nodup 751687d771SAlexander ZiaeeFor file descriptors referencing vnodes, instead of the 761687d771SAlexander Ziaee.Xr dup 2 771687d771SAlexander Ziaeesemantic described above, implement re-opening of the referenced vnode. 781687d771SAlexander ZiaeeSee below for more details. 791687d771SAlexander Ziaee.It Cm linrdlnk 801687d771SAlexander ZiaeeReport the type of the 811687d771SAlexander Ziaee.Nm 821687d771SAlexander Ziaeevnode as 831687d771SAlexander Ziaee.Dv VLNK 841687d771SAlexander Ziaeeinstead of 851687d771SAlexander Ziaee.Fx 861687d771SAlexander Ziaeetraditional 871687d771SAlexander Ziaee.Dv VCHR . 881687d771SAlexander ZiaeeFor 891687d771SAlexander Ziaee.Xr linux 4 901687d771SAlexander ZiaeeABI compatibility mount 911687d771SAlexander Ziaee.Nm 921687d771SAlexander Ziaeevolume with the 931687d771SAlexander Ziaee.Cm linrdlnk 941687d771SAlexander Ziaeeoption. 951687d771SAlexander Ziaee.It Cm rdlnk 961687d771SAlexander ZiaeeTreat 971687d771SAlexander Ziaee.Nm 981687d771SAlexander Ziaeevnodes as symbolic links consistently, in particular, follow 991687d771SAlexander Ziaeethe resolved name for the name lookups. 1001687d771SAlexander ZiaeeThis option is strictly stronger than the 1011687d771SAlexander Ziaee.Cm linrdlnk 1021687d771SAlexander Ziaeeoption, it changes not only the type returned by 1031687d771SAlexander Ziaee.Xr stat 2 , 1041687d771SAlexander Ziaeebut also causes the 1051687d771SAlexander Ziaee.Nm 1061687d771SAlexander Ziaeefiles to behave as symlinks. 1071687d771SAlexander Ziaee.El 1081687d771SAlexander Ziaee.Pp 1091687d771SAlexander ZiaeeFor 1101687d771SAlexander Ziaee.Nm 1111687d771SAlexander Ziaeemounted without the 1121687d771SAlexander Ziaee.Cm nodup 1131687d771SAlexander Ziaeemount option, 1141687d771SAlexander Ziaeeif the file descriptor is open and the mode the file is being opened 1151687d771SAlexander Ziaeewith is a subset of the mode of the existing descriptor, the call: 1161687d771SAlexander Ziaee.Bd -literal -offset indent 1171687d771SAlexander Ziaeefd = open("/dev/fd/0", mode); 1181687d771SAlexander Ziaee.Ed 1191687d771SAlexander Ziaee.Pp 1201687d771SAlexander Ziaeeand the call: 1211687d771SAlexander Ziaee.Bd -literal -offset indent 1221687d771SAlexander Ziaeefd = fcntl(0, F_DUPFD, 0); 1231687d771SAlexander Ziaee.Ed 1241687d771SAlexander Ziaee.Pp 1251687d771SAlexander Ziaeeare equivalent. 1261687d771SAlexander ZiaeeFlags to the 1271687d771SAlexander Ziaee.Xr open 2 1281687d771SAlexander Ziaeecall other than 1291687d771SAlexander Ziaee.Dv O_RDONLY , 1301687d771SAlexander Ziaee.Dv O_WRONLY 1311687d771SAlexander Ziaeeand 1321687d771SAlexander Ziaee.Dv O_RDWR 1331687d771SAlexander Ziaeeare ignored. 1341687d771SAlexander Ziaee.Pp 1351687d771SAlexander ZiaeeFor 1361687d771SAlexander Ziaee.Nm 1371687d771SAlexander Ziaeemounted with the 1381687d771SAlexander Ziaee.Cm nodup 1391687d771SAlexander Ziaeeoption, and file descriptor referencing a vnode, the call: 1401687d771SAlexander Ziaee.Bd -literal -offset indent 1411687d771SAlexander Ziaeefd = open("/dev/fd/0", mode); 1421687d771SAlexander Ziaee.Ed 1431687d771SAlexander Ziaee.Pp 1441687d771SAlexander Ziaeereopens the referenced vnode with the specified 1451687d771SAlexander Ziaee.Fa mode . 1461687d771SAlexander ZiaeeIn other words, the 1471687d771SAlexander Ziaee.Fn open 1481687d771SAlexander Ziaeecall above is equivalent to 1491687d771SAlexander Ziaee.Bd -literal -offset indent 1501687d771SAlexander Ziaeefd = openat(0, "", O_EMPTY_PATH, mode); 1511687d771SAlexander Ziaee.Ed 1521687d771SAlexander Ziaee.Pp 1531687d771SAlexander ZiaeeIn particular, if the file descriptor was opened with the 1541687d771SAlexander Ziaee.Dv O_PATH 1551687d771SAlexander Ziaeeflag, then either 1561687d771SAlexander Ziaee.Dv O_EMPTY_PATH 1571687d771SAlexander Ziaeeor 1581687d771SAlexander Ziaee.Fn open 1591687d771SAlexander Ziaeeover 1601687d771SAlexander Ziaee.Nm 1611687d771SAlexander Ziaeemount with 1621687d771SAlexander Ziaee.Cm nodup 1631687d771SAlexander Ziaeeoption allows one to convert it to a regularly opened file, 1641687d771SAlexander Ziaeeassuming that the current permissions allow the requested 1651687d771SAlexander Ziaee.Fa mode . 1661687d771SAlexander Ziaee.Pp 1671687d771SAlexander Ziaee.Em "Note:" 1681687d771SAlexander Ziaee.Pa /dev/fd/0 , 1691687d771SAlexander Ziaee.Pa /dev/fd/1 1701687d771SAlexander Ziaeeand 1711687d771SAlexander Ziaee.Pa /dev/fd/2 1721687d771SAlexander Ziaeefiles are created by default when devfs alone is mounted. 1731687d771SAlexander Ziaee.Nm 1741687d771SAlexander Ziaeecreates entries for all file descriptors opened by the process. 1751687d771SAlexander Ziaee.Sh FILES 1761687d771SAlexander Ziaee.Bl -tag -width /dev/stderr -compact 1771687d771SAlexander Ziaee.It Pa /dev/fd/# 1781687d771SAlexander Ziaee.El 1791687d771SAlexander Ziaee.Sh EXAMPLES 1801687d771SAlexander ZiaeeTo mount a 1811687d771SAlexander Ziaee.Nm 1821687d771SAlexander Ziaeevolume located on 1831687d771SAlexander Ziaee.Pa /dev/fd : 1841687d771SAlexander Ziaee.Pp 1851687d771SAlexander Ziaee.Dl "mount -t fdescfs none /dev/fd" 1861687d771SAlexander Ziaee.Pp 1871687d771SAlexander ZiaeeFor 1881687d771SAlexander Ziaee.Xr linux 4 1891687d771SAlexander ZiaeeABI compatibility: 1901687d771SAlexander Ziaee.Pp 1911687d771SAlexander Ziaee.Dl "mount -t fdescfs -o linrdlnk none /compat/linux/dev/fd" 1921687d771SAlexander Ziaee.Pp 1931687d771SAlexander ZiaeeFor substitute of 1941687d771SAlexander Ziaee.Dv O_EMPTY_PATH 1951687d771SAlexander Ziaeeflag use: 1961687d771SAlexander Ziaee.Pp 1971687d771SAlexander Ziaee.Dl "mount -t fdescfs -o nodup none /dev/fdpath" 1981687d771SAlexander Ziaee.Sh SEE ALSO 1991a720cbeSAlexander Ziaee.Xr devfs 4 , 2001687d771SAlexander Ziaee.Xr mount 8 2011687d771SAlexander Ziaee.Sh HISTORY 2021687d771SAlexander ZiaeeThe 2031687d771SAlexander Ziaee.Nm 2041687d771SAlexander Ziaeefile system first appeared in 2051687d771SAlexander Ziaee.Bx 4.4 . 2061687d771SAlexander ZiaeeThe 2071687d771SAlexander Ziaee.Nm 2081687d771SAlexander Ziaeemanual page first appeared in 2091687d771SAlexander Ziaee.Fx 2.2 . 2101687d771SAlexander Ziaee.Sh AUTHORS 2111687d771SAlexander Ziaee.An -nosplit 2121687d771SAlexander ZiaeeThe 2131687d771SAlexander Ziaee.Nm 2141687d771SAlexander Ziaeemanual page was written by 2151687d771SAlexander Ziaee.An Mike Pritchard Aq Mt mpp@FreeBSD.org , 2161687d771SAlexander Ziaeeand was based on the 2171687d771SAlexander Ziaeemanual page written by 2181687d771SAlexander Ziaee.An Jan-Simon Pendry . 219