OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / mkdir.2
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Michael Haardt
3 .\"             and Copyright (C) 1993,1994 Ian Jackson
4 .\"             and Copyright (C) 2006, 2014 Michael Kerrisk
5 .\"
6 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
7 .\" You may distribute it under the terms of the GNU General
8 .\" Public License. It comes with NO WARRANTY.
9 .\" %%%LICENSE_END
10 .\"
11 .TH MKDIR 2 2014-08-19 "Linux" "Linux Programmer's Manual"
12 .SH NAME
13 mkdir, mkdirat \- create a directory
14 .SH SYNOPSIS
15 .nf
16 .B #include <sys/stat.h>
17 .B #include <sys/types.h>
18 .\" .B #include <unistd.h>
19 .sp
20 .BI "int mkdir(const char *" pathname ", mode_t " mode );
21 .sp
22 .BR "#include <fcntl.h>           " "/* Definition of AT_* constants */"
23 .B #include <sys/stat.h>
24 .sp
25 .BI "int mkdirat(int " dirfd ", const char *" pathname ", mode_t " mode );
26 .fi
27 .sp
28 .in -4n
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
31 .in
32 .sp
33 .BR mkdirat ():
34 .PD 0
35 .ad l
36 .RS 4
37 .TP 4
38 Since glibc 2.10:
39 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
40 .TP
41 Before glibc 2.10:
42 _ATFILE_SOURCE
43 .RE
44 .ad
45 .PD
46 .fi
47 .SH DESCRIPTION
48 .BR mkdir ()
49 attempts to create a directory named
50 .IR pathname .
51
52 The argument
53 .I mode
54 specifies the permissions to use.
55 It is modified by the process's
56 .I umask
57 in the usual way: the permissions of the created directory are
58 .RI ( mode " & ~" umask " & 0777)."
59 Other mode bits of the created directory depend on the operating system.
60 For Linux, see below.
61
62 The newly created directory will be owned by the effective user ID of the
63 process.
64 If the directory containing the file has the set-group-ID
65 bit set, or if the filesystem is mounted with BSD group semantics
66 .RI ( "mount -o bsdgroups"
67 or, synonymously
68 .IR "mount -o grpid" ),
69 the new directory will inherit the group ownership from its parent;
70 otherwise it will be owned by the effective group ID of the process.
71
72 If the parent directory has the set-group-ID bit set, then so will the
73 newly created directory.
74 .\"
75 .\"
76 .SS mkdirat()
77 The
78 .BR mkdirat ()
79 system call operates in exactly the same way as
80 .BR mkdir (),
81 except for the differences described here.
82
83 If the pathname given in
84 .I pathname
85 is relative, then it is interpreted relative to the directory
86 referred to by the file descriptor
87 .I dirfd
88 (rather than relative to the current working directory of
89 the calling process, as is done by
90 .BR mkdir ()
91 for a relative pathname).
92
93 If
94 .I pathname
95 is relative and
96 .I dirfd
97 is the special value
98 .BR AT_FDCWD ,
99 then
100 .I pathname
101 is interpreted relative to the current working
102 directory of the calling process (like
103 .BR mkdir ()).
104
105 If
106 .I pathname
107 is absolute, then
108 .I dirfd
109 is ignored.
110 .PP
111 See
112 .BR openat (2)
113 for an explanation of the need for
114 .BR mkdirat ().
115 .SH RETURN VALUE
116 .BR mkdir ()
117 and
118 .BR mkdirat ()
119 return zero on success, or \-1 if an error occurred (in which case,
120 .I errno
121 is set appropriately).
122 .SH ERRORS
123 .TP
124 .B EACCES
125 The parent directory does not allow write permission to the process,
126 or one of the directories in
127 .I pathname
128 did not allow search permission.
129 (See also
130 .BR path_resolution (7).)
131 .TP
132 .B EDQUOT
133 The user's quota of disk blocks or inodes on the filesystem has been
134 exhausted.
135 .TP
136 .B EEXIST
137 .I pathname
138 already exists (not necessarily as a directory).
139 This includes the case where
140 .I pathname
141 is a symbolic link, dangling or not.
142 .TP
143 .B EFAULT
144 .IR pathname " points outside your accessible address space."
145 .TP
146 .B ELOOP
147 Too many symbolic links were encountered in resolving
148 .IR pathname .
149 .TP
150 .B EMLINK
151 The number of links to the parent directory would exceed
152 .BR LINK_MAX .
153 .TP
154 .B ENAMETOOLONG
155 .IR pathname " was too long."
156 .TP
157 .B ENOENT
158 A directory component in
159 .I pathname
160 does not exist or is a dangling symbolic link.
161 .TP
162 .B ENOMEM
163 Insufficient kernel memory was available.
164 .TP
165 .B ENOSPC
166 The device containing
167 .I pathname
168 has no room for the new directory.
169 .TP
170 .B ENOSPC
171 The new directory cannot be created because the user's disk quota is
172 exhausted.
173 .TP
174 .B ENOTDIR
175 A component used as a directory in
176 .I pathname
177 is not, in fact, a directory.
178 .TP
179 .B EPERM
180 The filesystem containing
181 .I pathname
182 does not support the creation of directories.
183 .TP
184 .B EROFS
185 .I pathname
186 refers to a file on a read-only filesystem.
187 .PP
188 The following additional errors can occur for
189 .BR mkdirat ():
190 .TP
191 .B EBADF
192 .I dirfd
193 is not a valid file descriptor.
194 .TP
195 .B ENOTDIR
196 .I pathname
197 is relative and
198 .I dirfd
199 is a file descriptor referring to a file other than a directory.
200 .SH VERSIONS
201 .BR mkdirat ()
202 was added to Linux in kernel 2.6.16;
203 library support was added to glibc in version 2.4.
204 .SH CONFORMING TO
205 .BR mkdir ():
206 SVr4, BSD, POSIX.1-2001, POSIX.1-2008.
207 .\" SVr4 documents additional EIO, EMULTIHOP
208
209 .BR mkdirat ():
210 POSIX.1-2008.
211 .SH NOTES
212 Under Linux, apart from the permission bits, only the
213 .B S_ISVTX
214 mode bit is honored.
215 That is, under Linux the created directory actually gets mode
216 .RI ( mode " & ~" umask " & 01777)."
217 See also
218 .BR stat (2).
219 .PP
220 There are many infelicities in the protocol underlying NFS.
221 Some of these affect
222 .BR mkdir ().
223 .SS Glibc notes
224 On older kernels where
225 .BR mkdirat ()
226 is unavailable, the glibc wrapper function falls back to the use of
227 .BR mkdir ().
228 When
229 .I pathname
230 is a relative pathname,
231 glibc constructs a pathname based on the symbolic link in
232 .IR /proc/self/fd
233 that corresponds to the
234 .IR dirfd
235 argument.
236 .SH SEE ALSO
237 .BR mkdir (1),
238 .BR chmod (2),
239 .BR chown (2),
240 .BR mknod (2),
241 .BR mount (2),
242 .BR rmdir (2),
243 .BR stat (2),
244 .BR umask (2),
245 .BR unlink (2),
246 .BR path_resolution (7)
247 .SH COLOPHON
248 This page is part of release 3.79 of the Linux
249 .I man-pages
250 project.
251 A description of the project,
252 information about reporting bugs,
253 and the latest version of this page,
254 can be found at
255 \%http://www.kernel.org/doc/man\-pages/.