xref: /freebsd/share/man/man4/fdescfs.4 (revision 1687d77197c01c6ffd5bb233c7a15c6ebb9319af)
1.\" Copyright (c) 2021 The FreeBSD Foundation, Inc.
2.\"
3.\" Copyright (c) 1996
4.\"	Mike Pritchard <mpp@FreeBSD.org>.  All rights reserved.
5.\"
6.\" Copyright (c) 1992, 1993, 1994
7.\"	The Regents of the University of California.  All rights reserved.
8.\" All rights reserved.
9.\"
10.\" This code is derived from software donated to Berkeley by
11.\" Jan-Simon Pendry.
12.\"
13.\" Parts of this documentation was written by
14.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
15.\" from the FreeBSD Foundation.
16.\"
17.\" Redistribution and use in source and binary forms, with or without
18.\" modification, are permitted provided that the following conditions
19.\" are met:
20.\" 1. Redistributions of source code must retain the above copyright
21.\"    notice, this list of conditions and the following disclaimer.
22.\" 2. Redistributions in binary form must reproduce the above copyright
23.\"    notice, this list of conditions and the following disclaimer in the
24.\"    documentation and/or other materials provided with the distribution.
25.\" 3. Neither the name of the University nor the names of its contributors
26.\"    may be used to endorse or promote products derived from this software
27.\"    without specific prior written permission.
28.\"
29.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39.\" SUCH DAMAGE.
40.\"
41.Dd Jul 11, 2023
42.Dt FDESCFS 4
43.Os
44.Sh NAME
45.Nm fdescfs
46.Nd file-descriptor file system
47.Sh SYNOPSIS
48.Bd -literal
49fdescfs	/dev/fd	fdescfs rw 0 0
50.Ed
51.Sh DESCRIPTION
52The file-descriptor file system, or
53.Nm ,
54provides access to the per-process file descriptor
55namespace in the global file system namespace.
56The conventional mount point is
57.Pa /dev/fd .
58.Pp
59The file system's contents
60appear as a list of numbered files
61which correspond to the open files of the process reading the
62directory.
63The files
64.Pa /dev/fd/0
65through
66.Pa /dev/fd/#
67refer to file descriptors which can be accessed through the file
68system.
69.Pp
70The following mount options can be used when mounting
71.Nm
72filesystem:
73.Bl -tag -width linrdlnk
74.It Cm nodup
75For file descriptors referencing vnodes, instead of the
76.Xr dup 2
77semantic described above, implement re-opening of the referenced vnode.
78See below for more details.
79.It Cm linrdlnk
80Report the type of the
81.Nm
82vnode as
83.Dv VLNK
84instead of
85.Fx
86traditional
87.Dv VCHR .
88For
89.Xr linux 4
90ABI compatibility mount
91.Nm
92volume with the
93.Cm linrdlnk
94option.
95.It Cm rdlnk
96Treat
97.Nm
98vnodes as symbolic links consistently, in particular, follow
99the resolved name for the name lookups.
100This option is strictly stronger than the
101.Cm linrdlnk
102option, it changes not only the type returned by
103.Xr stat 2 ,
104but also causes the
105.Nm
106files to behave as symlinks.
107.El
108.Pp
109For
110.Nm
111mounted without the
112.Cm nodup
113mount option,
114if the file descriptor is open and the mode the file is being opened
115with is a subset of the mode of the existing descriptor, the call:
116.Bd -literal -offset indent
117fd = open("/dev/fd/0", mode);
118.Ed
119.Pp
120and the call:
121.Bd -literal -offset indent
122fd = fcntl(0, F_DUPFD, 0);
123.Ed
124.Pp
125are equivalent.
126Flags to the
127.Xr open 2
128call other than
129.Dv O_RDONLY ,
130.Dv O_WRONLY
131and
132.Dv O_RDWR
133are ignored.
134.Pp
135For
136.Nm
137mounted with the
138.Cm nodup
139option, and file descriptor referencing a vnode, the call:
140.Bd -literal -offset indent
141fd = open("/dev/fd/0", mode);
142.Ed
143.Pp
144reopens the referenced vnode with the specified
145.Fa mode .
146In other words, the
147.Fn open
148call above is equivalent to
149.Bd -literal -offset indent
150fd = openat(0, "", O_EMPTY_PATH, mode);
151.Ed
152.Pp
153In particular, if the file descriptor was opened with the
154.Dv O_PATH
155flag, then either
156.Dv O_EMPTY_PATH
157or
158.Fn open
159over
160.Nm
161mount with
162.Cm nodup
163option allows one to convert it to a regularly opened file,
164assuming that the current permissions allow the requested
165.Fa mode .
166.Pp
167.Em "Note:"
168.Pa /dev/fd/0 ,
169.Pa /dev/fd/1
170and
171.Pa /dev/fd/2
172files are created by default when devfs alone is mounted.
173.Nm
174creates entries for all file descriptors opened by the process.
175.Sh FILES
176.Bl -tag -width /dev/stderr -compact
177.It Pa /dev/fd/#
178.El
179.Sh EXAMPLES
180To mount a
181.Nm
182volume located on
183.Pa /dev/fd :
184.Pp
185.Dl "mount -t fdescfs none /dev/fd"
186.Pp
187For
188.Xr linux 4
189ABI compatibility:
190.Pp
191.Dl "mount -t fdescfs -o linrdlnk none /compat/linux/dev/fd"
192.Pp
193For substitute of
194.Dv O_EMPTY_PATH
195flag use:
196.Pp
197.Dl "mount -t fdescfs -o nodup none /dev/fdpath"
198.Sh SEE ALSO
199.Xr devfs 5 ,
200.Xr mount 8
201.Sh HISTORY
202The
203.Nm
204file system first appeared in
205.Bx 4.4 .
206The
207.Nm
208manual page first appeared in
209.Fx 2.2 .
210.Sh AUTHORS
211.An -nosplit
212The
213.Nm
214manual page was written by
215.An Mike Pritchard Aq Mt mpp@FreeBSD.org ,
216and was based on the
217manual page written by
218.An Jan-Simon Pendry .
219