1 /* vi: set sw=4 ts=4: */
3 * Mini mkdir implementation for busybox
5 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
10 /* BB_AUDIT SUSv3 compliant */
11 /* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
13 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
15 * Fixed broken permission setting when -p was used; especially in
16 * conjunction with -m.
19 /* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
22 //usage:#define mkdir_trivial_usage
23 //usage: "[OPTIONS] DIRECTORY..."
24 //usage:#define mkdir_full_usage "\n\n"
25 //usage: "Create DIRECTORY\n"
26 //usage: "\n -m MODE Mode"
27 //usage: "\n -p No error if exists; make parent directories as needed"
29 //usage: "\n -Z Set security context"
32 //usage:#define mkdir_example_usage
33 //usage: "$ mkdir /tmp/foo\n"
34 //usage: "$ mkdir /tmp/foo\n"
35 //usage: "/tmp/foo: File exists\n"
36 //usage: "$ mkdir /tmp/foo/bar/baz\n"
37 //usage: "/tmp/foo/bar/baz: No such file or directory\n"
38 //usage: "$ mkdir -p /tmp/foo/bar/baz\n"
42 /* This is a NOFORK applet. Be very careful! */
44 #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
45 static const char mkdir_longopts
[] ALIGN1
=
46 "mode\0" Required_argument
"m"
47 "parents\0" No_argument
"p"
49 "context\0" Required_argument
"Z"
54 int mkdir_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
55 int mkdir_main(int argc UNUSED_PARAM
, char **argv
)
58 int status
= EXIT_SUCCESS
;
63 security_context_t scontext
;
66 #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
67 applet_long_options
= mkdir_longopts
;
69 opt
= getopt32(argv
, "m:p" IF_SELINUX("Z:"), &smode
IF_SELINUX(,&scontext
));
72 if (!bb_parse_mode(smode
, &mmode
)) {
73 bb_error_msg_and_die("invalid mode '%s'", smode
);
78 flags
|= FILEUTILS_RECUR
;
82 setfscreatecon_or_die(scontext
);
91 if (bb_make_directory(*argv
, mode
, flags
)) {
92 status
= EXIT_FAILURE
;