]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/mknod.2
Fix redundant formatting macros
[thirdparty/man-pages.git] / man2 / mknod.2
CommitLineData
fea681da
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4.\" 1993 Michael Haardt
5.\" 1993,1994 Ian Jackson.
6.\" You may distribute it under the terms of the GNU General
d9bfdb9c 7.\" Public License. It comes with NO WARRANTY.
fea681da
MK
8.\"
9.\" Modified 1996-08-18 by urs
10.\" Modified 2003-04-23 by Michael Kerrisk
c11b1abf 11.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 12.\"
cc4615cc 13.TH MKNOD 2 2007-07-26 "Linux" "Linux Programmer's Manual"
fea681da
MK
14.SH NAME
15mknod \- create a special or ordinary file
16.SH SYNOPSIS
17.nf
18.B #include <sys/types.h>
19.B #include <sys/stat.h>
20.B #include <fcntl.h>
21.B #include <unistd.h>
22.sp
23.BI "int mknod(const char *" pathname ", mode_t " mode ", dev_t " dev );
24.fi
cc4615cc
MK
25.sp
26.in -4n
27Feature Test Macro Requirements for glibc (see
28.BR feature_test_macros (7)):
29.in
30.sp
31.BR mknod ():
32_BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
fea681da
MK
33.SH DESCRIPTION
34The system call
e511ffb6 35.BR mknod ()
fea681da
MK
36creates a filesystem node (file, device special file or
37named pipe) named
38.IR pathname ,
39with attributes specified by
40.I mode
41and
42.IR dev .
43
44The
45.I mode
46argument specifies both the permissions to use and the type of node
47to be created.
48It should be a combination (using bitwise OR) of one of the file types
49listed below and the permissions for the new node.
50
51The permissions are modified by the process's
0daa9e92 52.I umask
fea681da 53in the usual way: the permissions of the created node are
66ee0c7e 54.IR "(mode & ~umask)" .
fea681da
MK
55
56The file type must be one of
57.BR S_IFREG ,
58.BR S_IFCHR ,
59.BR S_IFBLK ,
0daa9e92 60.B S_IFIFO
fea681da 61or
0daa9e92 62.B S_IFSOCK
fea681da
MK
63.\" (S_IFSOCK since Linux 1.2.4)
64to specify a normal file (which will be created empty), character
65special file, block special file, FIFO (named pipe), or Unix domain socket,
66respectively.
682edefb
MK
67(Zero file type is equivalent to type
68.BR S_IFREG .)
fea681da
MK
69
70If the file type is
71.BR S_IFCHR " or " S_IFBLK
72then
73.I dev
74specifies the major and minor numbers of the newly created device
75special file; otherwise it is ignored.
76
77If
78.I pathname
682edefb
MK
79already exists, or is a symbolic link, this call fails with an
80.B EEXIST
81error.
fea681da
MK
82
83The newly created node will be owned by the effective user ID of the
c13182ef
MK
84process.
85If the directory containing the node has the set-group-ID
fea681da
MK
86bit set, or if the filesystem is mounted with BSD group semantics, the
87new node will inherit the group ownership from its parent directory;
88otherwise it will be owned by the effective group ID of the process.
89.SH "RETURN VALUE"
e511ffb6 90.BR mknod ()
fea681da
MK
91returns zero on success, or \-1 if an error occurred (in which case,
92.I errno
93is set appropriately).
94.SH ERRORS
95.TP
96.B EACCES
97The parent directory does not allow write permission to the process,
98or one of the directories in the path prefix of
0daa9e92 99.I pathname
fea681da
MK
100did not allow search permission.
101(See also
ad7cc990 102.BR path_resolution (7).)
fea681da
MK
103.TP
104.B EEXIST
105.I pathname
106already exists.
107.TP
108.B EFAULT
109.IR pathname " points outside your accessible address space."
110.TP
111.B EINVAL
112.I mode
113requested creation of something other than a normal file, device
114special file, FIFO or socket.
115.TP
116.B ELOOP
117Too many symbolic links were encountered in resolving
118.IR pathname .
119.TP
120.B ENAMETOOLONG
121.IR pathname " was too long."
122.TP
123.B ENOENT
124A directory component in
125.I pathname
126does not exist or is a dangling symbolic link.
127.TP
128.B ENOMEM
129Insufficient kernel memory was available.
130.TP
131.B ENOSPC
132The device containing
133.I pathname
134has no room for the new node.
135.TP
136.B ENOTDIR
137A component used as a directory in
138.I pathname
139is not, in fact, a directory.
140.TP
141.B EPERM
142.I mode
143requested creation of something other than a regular file,
144FIFO (named pipe), or Unix domain socket, and the caller
145is not privileged (Linux: does not have the
146.B CAP_MKNOD
6e5a7309
MK
147capability);
148.\" For Unix domain sockets and regular files, EPERM is only returned in
149.\" Linux 2.2 and earlier; in Linux 2.4 and later, unprivileged can
150.\" use mknod() to make these files.
151also returned if the filesystem containing
fea681da
MK
152.I pathname
153does not support the type of node requested.
154.TP
155.B EROFS
156.I pathname
157refers to a file on a read-only filesystem.
158.SH "CONFORMING TO"
c13182ef 159SVr4, 4.4BSD, POSIX.1-2001 (but see below).
97c1eac8
MK
160.\" The Linux version differs from the SVr4 version in that it
161.\" does not require root permission to create pipes, also in that no
162.\" EMULTIHOP, ENOLINK, or EINTR error is documented.
fea681da 163.SH NOTES
97c1eac8 164POSIX.1-2001 says: "The only portable use of
fea681da 165.BR mknod ()
c13182ef
MK
166is to create a FIFO-special file.
167If
fea681da
MK
168.I mode
169is not S_IFIFO or
170.I dev
171is not 0, the behavior of
172.BR mknod ()
173is unspecified."
174
175Under Linux, this call cannot be used to create directories.
176One should make directories with
8478ee02 177.BR mkdir (2),
fea681da 178and FIFOs with
28dfb19d 179.BR mkfifo (3).
fea681da
MK
180.\" Unix domain sockets with .BR socket " (and " bind ),
181
c13182ef
MK
182There are many infelicities in the protocol underlying NFS.
183Some of these affect
e511ffb6 184.BR mknod ().
fea681da
MK
185.SH "SEE ALSO"
186.BR fcntl (2),
187.BR mkdir (2),
5b425567 188.BR mknodat (2),
fea681da 189.BR mount (2),
fea681da
MK
190.BR socket (2),
191.BR stat (2),
192.BR umask (2),
193.BR unlink (2),
ad7cc990
MK
194.BR mkfifo (3),
195.BR path_resolution (7)