1.\" $NetBSD: mknod.2,v 1.6 1995/02/27 12:34:33 cgd 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. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed by the University of 17.\" California, Berkeley and its contributors. 18.\" 4. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)mknod.2 8.1 (Berkeley) 6/4/93 35.\" 36.Dd June 4, 1993 37.Dt MKNOD 2 38.Os BSD 4 39.Sh NAME 40.Nm mknod , 41.Nm mknodat 42.Nd make a special file node 43.Sh SYNOPSIS 44.Fd #include <sys/stat.h> 45.Ft int 46.Fo mknod 47.Fa "const char *path" 48.Fa "mode_t mode" 49.Fa "dev_t dev" 50.Fc 51.Ft int 52.Fn mknodat "int fd" "const char *path" "mode_t mode" "dev_t dev" 53.Sh DESCRIPTION 54The device special file 55.Fa path 56is created with the major and minor 57device numbers extracted from 58.Fa mode . 59The access permissions of 60.Fa path 61are constrained by the 62.Xr umask 2 63of the parent process. 64.Pp 65If 66.Fa mode 67indicates a block or character special file, 68.Fa dev 69is a configuration-dependent specification of a character or block 70I/O device and the superblock of the device. If 71.Fa mode 72does not indicate a block special or character special device, 73.Fa dev 74is ignored. 75.Pp 76.Fn mknod 77requires super-user privileges. 78.Pp 79The 80.Fn mknodat 81system call is equivalent to 82.Fn mknod 83except in the case where 84.Fa path 85specifies a relative path. 86In this case the newly created fifo file is created relative to the 87directory associated with the file descriptor 88.Fa fd 89instead of the current working directory. 90If 91.Fn mknodat 92is passed the special value 93.Dv AT_FDCWD 94in the 95.Fa fd 96parameter, the current working directory is used and the behavior is 97identical to a call to 98.Fn mknod . 99.Sh RETURN VALUES 100Upon successful completion, a value of 0 is returned. 101Otherwise, a value of -1 is returned and 102.Va errno 103is set to indicate the error. 104.Sh ERRORS 105.Fn mknod 106will fail and the file will be not created if: 107.Bl -tag -width Er 108.\" ========== 109.It Bq Er EACCES 110Search permission is denied for a component of the path prefix. 111.\" ========== 112.It Bq Er EACCES 113Write permission is denied for the parent directory. 114.\" ========== 115.It Bq Er EDQUOT 116The directory in which the entry for the new node 117is being placed cannot be extended; 118the user's quota of disk blocks on the file system 119containing the directory has been exhausted. 120.\" ========== 121.It Bq Er EDQUOT 122The user's quota of inodes for the file system 123on which the node is being created has been exhausted. 124.\" ========== 125.It Bq Er EEXIST 126The named file exists. 127.\" ========== 128.It Bq Er EFAULT 129.Fa Path 130points outside the process's allocated address space. 131.\" ========== 132.It Bq Er EINVAL 133One or more of the arguments is invalid. 134.\" ========== 135.It Bq Er EIO 136An I/O error occurs while making the directory entry 137or allocating the inode. 138.\" ========== 139.It Bq Er ELOOP 140Too many symbolic links were encountered in translating the pathname. 141This is taken to be indicative of a looping symbolic link. 142.\" ========== 143.It Bq Er ENAMETOOLONG 144A component of a pathname exceeds 145.Dv {NAME_MAX} 146characters or an entire path name exceeds 147.Dv {PATH_MAX} 148characters. 149.\" ========== 150.It Bq Er ENOENT 151A component of the path prefix does not exist 152or path is an empty string. 153.\" ========== 154.It Bq Er ENOSPC 155The directory in which the entry for the new node is being placed 156cannot be extended, 157because there is no space left on the file system containing the directory. 158.\" ========== 159.It Bq Er ENOSPC 160There are no free inodes on the file system 161on which the node is being created. 162.\" ========== 163.It Bq Er ENOTDIR 164A component of the path prefix is not a directory. 165.\" ========== 166.It Bq Er EPERM 167The process's effective user ID is not super-user. 168.\" ========== 169.It Bq Er EROFS 170The created node would reside on a read-only file system. 171.El 172.Pp 173In addition to the errors returned by the 174.Fn mknod , 175the 176.Fn mknodat 177function may fail if: 178.Bl -tag -width Er 179.It Bq Er EBADF 180The 181.Fa path 182argument does not specify an absolute path and the 183.Fa fd 184argument is neither 185.Dv AT_FDCWD 186nor a valid file descriptor open for searching. 187.It Bq Er ENOTDIR 188The 189.Fa path 190argument is not an absolute path and 191.Fa fd 192is neither 193.Dv AT_FDCWD 194nor a file descriptor associated with a directory. 195.El 196.Sh LEGACY SYNOPSIS 197.Fd #include <unistd.h> 198.Pp 199The include file has changed. 200.Sh SEE ALSO 201.Xr chmod 2 , 202.Xr stat 2 , 203.Xr umask 2 , 204.Xr compat 5 205.Sh HISTORY 206A 207.Fn mknod 208function call appeared in 209.At v6 . 210The 211.Fn mknodat 212system call appeared in macOS 13.0. 213