1.\" $OpenBSD: mknod.2,v 1.21 2015/09/10 17:55:21 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: September 10 2015 $ 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.In sys/stat.h 42.Ft int 43.Fn mknod "const char *path" "mode_t mode" "dev_t dev" 44.In sys/stat.h 45.In fcntl.h 46.Ft int 47.Fn mknodat "int fd" "const char *path" "mode_t mode" "dev_t dev" 48.Sh DESCRIPTION 49The 50.Fn mknod 51function creates 52.Fa path 53with a file type and mode of 54.Fa mode , 55as modified by 56.Xr umask 2 . 57Only FIFO and device special files are supported by this implementation. 58.Pp 59If 60.Fa mode 61is the bitwise OR of 62.Dv S_IFIFO 63and zero or more file permissions, and 64.Fa dev 65is zero, then a FIFO is created. 66If 67.Fa mode 68is the bitwise OR of 69.Dv S_IFCHR 70or 71.Dv S_IFBLK 72and zero or more file permissions, then a character or block device 73special (respectively) is created with major and minor device numbers 74extracted from 75.Fa dev . 76.Pp 77The 78.Fn mknodat 79function is equivalent to 80.Fn mknod 81except that where 82.Fa path 83specifies a relative path, 84the newly created device special file is created relative to 85the directory associated with file descriptor 86.Fa fd 87instead of the current working directory. 88.Pp 89If 90.Fn mknodat 91is passed the special value 92.Dv AT_FDCWD 93(defined in 94.In fcntl.h ) 95in the 96.Fa fd 97parameter, the current working directory is used 98and the behavior is identical to a call to 99.Fn mknod . 100.Pp 101Creating a device special file with 102.Fn mknod 103or 104.Fn mknodat 105requires superuser privileges. 106.Sh RETURN VALUES 107.Rv -std 108.Sh ERRORS 109.Fn mknod 110and 111.Fn mknodat 112will fail and the file will be not created if: 113.Bl -tag -width Er 114.It Bq Er EINVAL 115.Fa mode 116is an invalid file type or 117.Fa dev 118is an invalid value for that file type. 119.It Bq Er ENOTDIR 120A component of the path prefix is not a directory. 121.It Bq Er ENAMETOOLONG 122A component of a pathname exceeded 123.Dv NAME_MAX 124characters, or an entire pathname (including the terminating NUL) 125exceeded 126.Dv PATH_MAX 127bytes. 128.It Bq Er ENOENT 129A component of the path prefix does not exist. 130.It Bq Er EACCES 131Search permission is denied for a component of the path prefix. 132.It Bq Er ELOOP 133Too many symbolic links were encountered in translating the pathname. 134.It Bq Er EPERM 135.Fa mode 136is a device special and the process's effective user ID is not superuser. 137.It Bq Er EIO 138An I/O error occurred while making the directory entry or allocating the inode. 139.It Bq Er ENOSPC 140The directory in which the entry for the new node is being placed 141cannot be extended because there is no space left on the file 142system containing the directory. 143.It Bq Er ENOSPC 144There are no free inodes on the file system on which the 145node is being created. 146.It Bq Er EDQUOT 147The directory in which the entry for the new node 148is being placed cannot be extended because the 149user's quota of disk blocks on the file system 150containing the directory has been exhausted. 151.It Bq Er EDQUOT 152The user's quota of inodes on the file system on 153which the node is being created has been exhausted. 154.It Bq Er EROFS 155The named file resides on a read-only file system. 156.It Bq Er EEXIST 157The named file exists. 158.It Bq Er EFAULT 159.Fa path 160points outside the process's allocated address space. 161.It Bq Er EINVAL 162The process is running within an alternate root directory, as 163created by 164.Xr chroot 2 . 165.El 166.Pp 167Additionally, 168.Fn mknodat 169will fail if: 170.Bl -tag -width Er 171.It Bq Er EBADF 172The 173.Fa path 174argument specifies a relative path and the 175.Fa fd 176argument is neither 177.Dv AT_FDCWD 178nor a valid file descriptor. 179.It Bq Er ENOTDIR 180The 181.Fa path 182argument specifies a relative path and the 183.Fa fd 184argument is a valid file descriptor but it does not reference a directory. 185.It Bq Er EACCES 186The 187.Fa path 188argument specifies a relative path but search permission is denied 189for the directory which the 190.Fa fd 191file descriptor references. 192.El 193.Sh SEE ALSO 194.Xr chmod 2 , 195.Xr chroot 2 , 196.Xr mkfifo 2 , 197.Xr stat 2 , 198.Xr umask 2 199.Sh STANDARDS 200The 201.Fn mknod 202and 203.Fn mknodat 204functions conform to 205.St -p1003.1-2008 . 206.Sh HISTORY 207The 208.Fn mknod 209system call first appeared in 210.At v4 , 211and 212.Fn mknodat 213has been available since 214.Ox 5.0 . 215