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.
9 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
11 * Fixed broken permission setting when -p was used; especially in
12 * conjunction with -m.
14 /* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
17 //config: bool "mkdir (4.4 kb)"
20 //config: mkdir is used to create directories with the specified names.
22 //applet:IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir))
24 //kbuild:lib-$(CONFIG_MKDIR) += mkdir.o
26 /* BB_AUDIT SUSv3 compliant */
27 /* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
29 //usage:#define mkdir_trivial_usage
30 //usage: "[OPTIONS] DIRECTORY..."
31 //usage:#define mkdir_full_usage "\n\n"
32 //usage: "Create DIRECTORY\n"
33 //usage: "\n -m MODE Mode"
34 //usage: "\n -p No error if exists; make parent directories as needed"
36 //usage: "\n -Z Set security context"
39 //usage:#define mkdir_example_usage
40 //usage: "$ mkdir /tmp/foo\n"
41 //usage: "$ mkdir /tmp/foo\n"
42 //usage: "/tmp/foo: File exists\n"
43 //usage: "$ mkdir /tmp/foo/bar/baz\n"
44 //usage: "/tmp/foo/bar/baz: No such file or directory\n"
45 //usage: "$ mkdir -p /tmp/foo/bar/baz\n"
49 /* This is a NOFORK applet. Be very careful! */
51 int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
52 int mkdir_main(int argc UNUSED_PARAM, char **argv)
55 int status = EXIT_SUCCESS;
60 security_context_t scontext;
63 opt = getopt32long(argv, "m:pv" IF_SELINUX("Z:"),
64 "mode\0" Required_argument "m"
65 "parents\0" No_argument "p"
67 "context\0" Required_argument "Z"
69 # if ENABLE_FEATURE_VERBOSE
70 "verbose\0" No_argument "v"
72 , &smode IF_SELINUX(,&scontext)
75 mode_t mmode = bb_parse_mode(smode, 0777);
76 if (mmode == (mode_t)-1) {
77 bb_error_msg_and_die("invalid mode '%s'", smode);
82 flags |= FILEUTILS_RECUR;
83 if ((opt & 4) && FILEUTILS_VERBOSE)
84 flags |= FILEUTILS_VERBOSE;
88 setfscreatecon_or_die(scontext);
97 if (bb_make_directory(*argv, mode, flags)) {
98 status = EXIT_FAILURE;