1.\"
2.\" Copyright (c) 1992, 1993
3.\"	The Regents of the University of California.  All rights reserved.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software donated to Berkeley by
7.\" Jan-Simon Pendry.
8.\"
9.\" %sccs.include.redist.roff%
10.\"
11.\"	@(#)mount_fdesc.8	8.1 (Berkeley) 06/09/93
12.\"
13.\"
14.Dd
15.Dt MOUNT_FDESC 8
16.Os BSD 4.4
17.Sh NAME
18.Nm mount_fdesc
19.Nd mount the file-descriptor file system
20.Sh SYNOPSIS
21.Nm mount_fdesc
22.Op Fl F Ar fsoptions
23.Pa fdesc
24.Pa mount_point
25.Sh DESCRIPTION
26The
27.Nm mount_fdesc
28command attaches an instance of the per-process file descriptor
29namespace to the global filesystem namespace.
30The conventional mount point is
31.Pa /dev
32and the filesystem should be union mounted in order to augment,
33rather than replace, the existing entries in
34.Pa /dev .
35This command is normally executed by
36.Xr mount 8
37at boot time.
38.Pp
39The contents of the mount point are
40.Pa fd ,
41.Pa stderr ,
42.Pa stdin ,
43.Pa stdout
44and
45.Pa tty .
46.Pp
47.Pa fd
48is a directory whose contents
49appear as a list of numbered files
50which correspond to the open files of the process reading the
51directory.
52The files
53.Pa /dev/fd/0
54through
55.Pa /dev/fd/#
56refer to file descriptors which can be accessed through the file
57system.
58If the file descriptor is open and the mode the file is being opened
59with is a subset of the mode of the existing descriptor, the call:
60.Bd -literal -offset indent
61fd = open("/dev/fd/0", mode);
62.Ed
63.Pp
64and the call:
65.Bd -literal -offset indent
66fd = fcntl(0, F_DUPFD, 0);
67.Ed
68.Pp
69are equivalent.
70.Pp
71The files
72.Pa /dev/stdin ,
73.Pa /dev/stdout
74and
75.Pa /dev/stderr
76appear as symlinks to the relevant entry in the
77.Pa /dev/fd
78sub-directory.
79Opening them is equivalent to the following calls:
80.Bd -literal -offset indent
81fd = fcntl(STDIN_FILENO,  F_DUPFD, 0);
82fd = fcntl(STDOUT_FILENO, F_DUPFD, 0);
83fd = fcntl(STDERR_FILENO, F_DUPFD, 0);
84.Ed
85.Pp
86Flags to the
87.Xr open 2
88call other than
89.Dv O_RDONLY ,
90.Dv O_WRONLY
91and
92.Dv O_RDWR
93are ignored.
94.Pp
95The
96.Pa /dev/tty
97entry is an indirect reference to the current process's controlling terminal.
98It appears as a named pipe (FIFO) but behaves in exactly the same way as
99the real controlling terminal device.
100.Sh FILES
101.Bl -tag -width /dev/stderr -compact
102.It Pa /dev/fd/#
103.It Pa /dev/stdin
104.It Pa /dev/stdout
105.It Pa /dev/stderr
106.It Pa /dev/tty
107.El
108.Sh SEE ALSO
109.Xr mount 2 ,
110.Xr unmount 2 ,
111.Xr tty 4 ,
112.Xr fstab 5
113.Sh CAVEATS
114No
115.Pa .
116and
117.Pa ..
118entries appear when listing the contents of the
119.Pa /dev/fd
120directory.
121This makes sense in the context of this filesystem, but is inconsistent
122with usual filesystem conventions.
123However, it is still possible to refer to both
124.Pa .
125and
126.Pa ..
127in a pathname.
128.Pp
129This filesystem may not be NFS-exported.
130.Sh HISTORY
131The
132.Nm mount_fdesc
133utility first appeared in 4.4BSD.
134