xref: /netbsd-src/lib/libc/sys/mknod.2 (revision e92fdad11f5e99e5be2d642d22ae9f7c1bfbf35a)
1.\"	$NetBSD: mknod.2,v 1.31 2019/06/20 06:59:32 wiz Exp $
2.\"
3.\" Copyright (c) 1980, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)mknod.2	8.1 (Berkeley) 6/4/93
31.\"
32.Dd June 20, 2019
33.Dt MKNOD 2
34.Os
35.Sh NAME
36.Nm mknod ,
37.Nm mknodat
38.Nd make a special file node
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In sys/stat.h
43.Ft int
44.Fn mknod "const char *path" "mode_t mode" "dev_t dev"
45.In sys/stat.h
46.In fcntl.h
47.Ft int
48.Fn mknodat "int fd" "const char *path" "mode_t mode" "dev_t dev"
49.Sh DESCRIPTION
50.Nm
51with
52.Dv S_IFIFO
53specified in
54.Fa mode
55and 0 in
56.Fa dev
57makes a FIFO file.
58This call is respectively a portable alias for
59.Xr mkfifo 2
60and
61.Xr mkfifoat 2 .
62.Pp
63.Nm
64with
65.Dv S_IFCHR
66or
67.Dv S_IFBLK
68in
69.Fa mode
70makes a device special file.
71The file
72.Fa path
73is created with the major and minor
74device numbers specified by
75.Fa dev .
76The access permissions of
77.Fa path
78are extracted from
79.Fa mode ,
80modified by the
81.Xr umask 2
82of the parent process.
83.Pp
84.Fn mknodat
85works the same way as
86.Fn mknod
87except if
88.Fa path
89is relative.
90In that case, it is looked up from a directory whose file
91descriptor was passed as
92.Fa fd .
93Search permission is required on this directory.
94.\"    (These alternatives await a decision about the semantics of O_SEARCH)
95.\" Search permission is required on this directory
96.\" except if
97.\" .Fa fd
98.\" was opened with the
99.\" .Dv O_SEARCH
100.\" flag.
101.\"    - or -
102.\" This file descriptor must have been opened with the
103.\" .Dv O_SEARCH
104.\" flag.
105.Fa fd
106can be set to
107.Dv AT_FDCWD
108in order to specify the current directory.
109.Pp
110.Fn mknod
111requires super-user privileges for creating device special files.
112.Sh RETURN VALUES
113.Rv -std mknod mknodat
114.Sh ERRORS
115.Fn mknod
116and
117.Fn mknodat
118will fail and the file will be not created if:
119.Bl -tag -width Er
120.It Bq Er EACCES
121Search permission is denied for a component of the path prefix.
122.It Bq Er EDQUOT
123The directory in which the entry for the new node
124is being placed cannot be extended because the
125user's quota of disk blocks on the file system
126containing the directory has been exhausted; or
127the user's quota of inodes on the file system on
128which the node is being created has been exhausted.
129.It Bq Er EEXIST
130The named file exists.
131.It Bq Er EFAULT
132.Fa path
133points outside the process's allocated address space.
134.It Bq Er EINVAL
135The supplied
136.Fa mode
137or
138.Fa dev
139is invalid.
140.It Bq Er EIO
141An I/O error occurred while making the directory entry or allocating the inode.
142.It Bq Er ELOOP
143Too many symbolic links were encountered in translating the pathname.
144.It Bq Er ENAMETOOLONG
145A component of a pathname exceeded
146.Brq Dv NAME_MAX
147characters, or an entire path name exceeded
148.Brq Dv PATH_MAX
149characters.
150.It Bq Er ENOENT
151A component of the path prefix does not exist.
152.It Bq Er ENOSPC
153The directory in which the entry for the new node is being placed
154cannot be extended because there is no space left on the file
155system containing the directory; or
156there are no free inodes on the file system on which the
157node is being created.
158.It Bq Er ENOTDIR
159A component of the path prefix is not a directory.
160.It Bq Er EOPNOTSUPP
161The kernel has not been configured to support FIFOs.
162.It Bq Er EPERM
163The process's effective user ID is not super-user.
164.It Bq Er EROFS
165The named file resides on a read-only file system.
166.El
167.Pp
168In addition,
169.Fn mknodat
170will fail if:
171.Bl -tag -width Er
172.It Bq Er EBADF
173.Fa path
174does not specify an absolute path and
175.Fa fd
176is neither
177.Dv AT_FDCWD
178nor a valid file descriptor open for reading or searching.
179.It Bq Er ENOTDIR
180.Fa path
181is not an absolute path and
182.Fa fd
183is a file descriptor associated with a non-directory file.
184.El
185.Sh SEE ALSO
186.Xr chmod 2 ,
187.Xr mkfifo 2 ,
188.Xr stat 2 ,
189.Xr umask 2 ,
190.Xr makedev 3
191.Sh STANDARDS
192The
193.Fn mknod
194function conforms to
195.St -p1003.1-90 .
196.Fn mknodat
197conforms to
198.St -p1003.1-2008 .
199.Sh HISTORY
200A
201.Fn mknod
202function call appeared in
203.At v6 .
204.Pp
205The alias mode for
206.Xr mkfifo 2
207and
208.Xr mkfifoat 2
209first appeared in
210.Nx 9 .
211