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