xref: /openbsd-src/lib/libc/sys/mknod.2 (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1.\"	$OpenBSD: mknod.2,v 1.18 2013/07/17 05:42:11 schwarze Exp $
2.\"	$NetBSD: mknod.2,v 1.6 1995/02/27 12:34:33 cgd Exp $
3.\"
4.\" Copyright (c) 1980, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)mknod.2	8.1 (Berkeley) 6/4/93
32.\"
33.Dd $Mdocdate: July 17 2013 $
34.Dt MKNOD 2
35.Os
36.Sh NAME
37.Nm mknod ,
38.Nm mknodat
39.Nd make a special file node
40.Sh SYNOPSIS
41.Fd #include <sys/stat.h>
42.Ft int
43.Fn mknod "const char *path" "mode_t mode" "dev_t dev"
44.Fd #include <sys/stat.h>
45.Fd #include <fcntl.h>
46.Ft int
47.Fn mknodat "int fd" "const char *path" "mode_t mode" "dev_t dev"
48.Sh DESCRIPTION
49The device special file
50.Fa path
51is created with the major and minor
52device numbers extracted from
53.Fa mode .
54The access permissions of
55.Fa path
56are descendant from the
57.Xr umask 2
58of the parent process.
59.Pp
60If
61.Fa mode
62indicates a block or character special file,
63.Fa dev
64is a configuration dependent specification of a character or block
65I/O device and the superblock of the device.
66If
67.Fa mode
68does not indicate a block special or character special device,
69.Fa dev
70is ignored.
71.Pp
72.Fn mknod
73requires superuser privileges.
74.Pp
75The
76.Fn mknodat
77function is equivalent to
78.Fn mknod
79except that where
80.Fa path
81specifies a relative path,
82the newly created device special file is created relative to
83the directory associated with file descriptor
84.Fa fd
85instead of the current working directory.
86.Pp
87If
88.Fn mknodat
89is passed the special value
90.Dv AT_FDCWD
91(defined in
92.In fcntl.h )
93in the
94.Fa fd
95parameter, the current working directory is used
96and the behavior is identical to a call to
97.Fn mknod .
98.Sh RETURN VALUES
99Upon successful completion a value of 0 is returned.
100Otherwise, a value of \-1 is returned and
101.Va errno
102is set to indicate the error.
103.Sh ERRORS
104.Fn mknod
105and
106.Fn mknodat
107will fail and the file will be not created if:
108.Bl -tag -width Er
109.It Bq Er ENOTDIR
110A component of the path prefix is not a directory.
111.It Bq Er ENAMETOOLONG
112A component of a pathname exceeded
113.Dv {NAME_MAX}
114characters, or an entire path name exceeded
115.Dv {PATH_MAX}
116characters.
117.It Bq Er ENOENT
118A component of the path prefix does not exist.
119.It Bq Er EACCES
120Search permission is denied for a component of the path prefix.
121.It Bq Er ELOOP
122Too many symbolic links were encountered in translating the pathname.
123.It Bq Er EPERM
124The process's effective user ID is not superuser.
125.It Bq Er EIO
126An I/O error occurred while making the directory entry or allocating the inode.
127.It Bq Er ENOSPC
128The directory in which the entry for the new node is being placed
129cannot be extended because there is no space left on the file
130system containing the directory.
131.It Bq Er ENOSPC
132There are no free inodes on the file system on which the
133node is being created.
134.It Bq Er EDQUOT
135The directory in which the entry for the new node
136is being placed cannot be extended because the
137user's quota of disk blocks on the file system
138containing the directory has been exhausted.
139.It Bq Er EDQUOT
140The user's quota of inodes on the file system on
141which the node is being created has been exhausted.
142.It Bq Er EROFS
143The named file resides on a read-only file system.
144.It Bq Er EEXIST
145The named file exists.
146.It Bq Er EFAULT
147.Fa path
148points outside the process's allocated address space.
149.It Bq Er EINVAL
150The process is running within an alternate root directory, as
151created by
152.Xr chroot 2 .
153.El
154.Pp
155Additionally,
156.Fn mknodat
157will fail if:
158.Bl -tag -width Er
159.It Bq Er EBADF
160The
161.Fa path
162argument specifies a relative path and the
163.Fa fd
164argument is neither
165.Dv AT_FDCWD
166nor a valid file descriptor.
167.It Bq Er ENOTDIR
168The
169.Fa path
170argument specifies a relative path and the
171.Fa fd
172argument is a valid file descriptor but it does not reference a directory.
173.It Bq Er EACCES
174The
175.Fa path
176argument specifies a relative path but search permission is denied
177for the directory which the
178.Fa fd
179file descriptor references.
180.El
181.Sh SEE ALSO
182.Xr chmod 2 ,
183.Xr chroot 2 ,
184.Xr stat 2 ,
185.Xr umask 2
186.Sh STANDARDS
187The
188.Fn mknod
189and
190.Fn mknodat
191functions conform to
192.St -p1003.1-2008 .
193.Sh HISTORY
194The
195.Fn mknod
196system call first appeared in
197.At v4 ,
198and
199.Fn mknodat
200has been available since
201.Ox 5.0 .
202