summaryrefslogtreecommitdiffstats
path: root/tests/mkdir
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 17:39:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 17:39:29 +0000
commit8ffec2a3aba6f114784e11f89ef1d57a096ae540 (patch)
treeccebcbad06203e8241a8e7249f8e6c478a3682ea /tests/mkdir
parentInitial commit. (diff)
downloadcoreutils-upstream.tar.xz
coreutils-upstream.zip
Adding upstream version 8.32.upstream/8.32upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/mkdir')
-rwxr-xr-xtests/mkdir/p-1.sh25
-rwxr-xr-xtests/mkdir/p-2.sh25
-rwxr-xr-xtests/mkdir/p-3.sh52
-rwxr-xr-xtests/mkdir/p-acl.sh35
-rwxr-xr-xtests/mkdir/p-slashdot.sh29
-rwxr-xr-xtests/mkdir/p-thru-slink.sh27
-rwxr-xr-xtests/mkdir/p-v.sh32
-rwxr-xr-xtests/mkdir/parents.sh52
-rwxr-xr-xtests/mkdir/perm.sh84
-rwxr-xr-xtests/mkdir/restorecon.sh72
-rwxr-xr-xtests/mkdir/selinux.sh56
-rwxr-xr-xtests/mkdir/smack-no-root.sh39
-rwxr-xr-xtests/mkdir/smack-root.sh36
-rwxr-xr-xtests/mkdir/special-1.sh51
-rwxr-xr-xtests/mkdir/t-slash.sh31
-rwxr-xr-xtests/mkdir/writable-under-readonly.sh52
16 files changed, 698 insertions, 0 deletions
diff --git a/tests/mkdir/p-1.sh b/tests/mkdir/p-1.sh
new file mode 100755
index 0000000..654ffd4
--- /dev/null
+++ b/tests/mkdir/p-1.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# Test "mkdir -p".
+
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+
+mkdir --parents "$(pwd)/t" || fail=1
+test -d t || fail=1
+
+Exit $fail
diff --git a/tests/mkdir/p-2.sh b/tests/mkdir/p-2.sh
new file mode 100755
index 0000000..902f177
--- /dev/null
+++ b/tests/mkdir/p-2.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# Just like p-1, but with an absolute path.
+
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+
+mkdir --parents "$(pwd)/t/u" || fail=1
+test -d t/u || fail=1
+
+Exit $fail
diff --git a/tests/mkdir/p-3.sh b/tests/mkdir/p-3.sh
new file mode 100755
index 0000000..31a671e
--- /dev/null
+++ b/tests/mkdir/p-3.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Ensure that mkdir-p.c's fail-to-return-to-initial-working-directory
+# causes immediate failure. Also, ensure that we don't create
+# subsequent, relative command-line arguments in the wrong place.
+
+# Copyright (C) 2005-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+skip_if_root_
+
+mkdir no-access || framework_failure_
+mkdir no-acce2s || framework_failure_
+mkdir -p no-acce3s/d || framework_failure_
+
+p=$(pwd)
+(cd no-access && chmod 0 . && mkdir -p "$p/a/b" u/v) 2> /dev/null
+test $? -eq 1 || fail=1
+test -d "$p/a/b" || fail=1
+
+# Same as above, but with a following *absolute* name, it should succeed
+(cd no-acce2s && chmod 0 . && mkdir -p "$p/b/b" "$p/z") || fail=1
+test -d "$p/b/b" && test -d "$p/z" || fail=1
+
+# Same as above, but a trailing relative name in an unreadable directory
+# whose parent is inaccessible. coreutils 5.97 fails this test.
+# Perform this test only if "." is on a local file system.
+# Otherwise, it would fail e.g., on an NFS-mounted file system.
+if is_local_dir_ .; then
+ (cd no-acce3s/d && chmod a-r . && chmod a-rx .. &&
+ mkdir -p a/b "$p/b/c" d/e && test -d a/b && test -d d/e) || fail=1
+ test -d "$p/b/c" || fail=1
+fi
+
+b=$(ls "$p/a" | tr -d '\n')
+# With coreutils-5.3.0, this would fail with $b=bu.
+test "x$b" = xb || fail=1
+
+Exit $fail
diff --git a/tests/mkdir/p-acl.sh b/tests/mkdir/p-acl.sh
new file mode 100755
index 0000000..894c353
--- /dev/null
+++ b/tests/mkdir/p-acl.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# Test "mkdir -p" with default ACLs.
+
+# Copyright (C) 1997-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+
+require_setfacl_
+
+mkdir d || framework_failure_
+setfacl -d -m group::rwx d || framework_failure_
+umask 077
+
+mkdir --parents d/e || fail=1
+ls_l=$(ls -ld d/e) || fail=1
+case $ls_l in
+ d???rw[sx]*) ;;
+ *) fail=1 ;;
+esac
+
+Exit $fail
diff --git a/tests/mkdir/p-slashdot.sh b/tests/mkdir/p-slashdot.sh
new file mode 100755
index 0000000..cd832f0
--- /dev/null
+++ b/tests/mkdir/p-slashdot.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+# Ensure that mkdir -p works with arguments specified with a trailing "/.".
+
+# Copyright (C) 2005-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+
+
+mkdir -p d1/. || fail=1
+test -d d1 || fail=1
+
+mkdir -p d2/.. || fail=1
+test -d d2 || fail=1
+
+Exit $fail
diff --git a/tests/mkdir/p-thru-slink.sh b/tests/mkdir/p-thru-slink.sh
new file mode 100755
index 0000000..a32be39
--- /dev/null
+++ b/tests/mkdir/p-thru-slink.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Ensure that mkdir -p foo/bar works when foo is a symbolic link to a directory
+
+# Copyright (C) 2005-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+
+ln -s . slink || framework_failure_
+
+mkdir -p slink/x || fail=1
+test -d x || fail=1
+
+Exit $fail
diff --git a/tests/mkdir/p-v.sh b/tests/mkdir/p-v.sh
new file mode 100755
index 0000000..38b112a
--- /dev/null
+++ b/tests/mkdir/p-v.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Test mkdir -pv.
+
+# Copyright (C) 2006-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+
+mkdir -pv foo/a/b/c/d >out || fail=1
+
+compare - out <<\EOF || fail=1
+mkdir: created directory 'foo'
+mkdir: created directory 'foo/a'
+mkdir: created directory 'foo/a/b'
+mkdir: created directory 'foo/a/b/c'
+mkdir: created directory 'foo/a/b/c/d'
+EOF
+
+Exit $fail
diff --git a/tests/mkdir/parents.sh b/tests/mkdir/parents.sh
new file mode 100755
index 0000000..aaa2588
--- /dev/null
+++ b/tests/mkdir/parents.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# make sure mkdir's -p options works properly
+
+# Copyright (C) 2000-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+skip_if_setgid_
+require_no_default_acl_ .
+
+mkdir -m 700 e-dir || framework_failure_
+
+
+# Make sure 'mkdir -p existing-dir' succeeds
+# and that 'mkdir existing-dir' fails.
+mkdir -p e-dir || fail=1
+returns_ 1 mkdir e-dir > /dev/null 2>&1 || fail=1
+
+# Create an existing directory.
+umask 077
+mode_str=drwxr-x-wx
+mode_arg=$(rwx_to_mode_ $mode_str)
+mkdir -m $mode_arg a || fail=1
+
+# this 'mkdir -p ...' shouldn't change perms of existing dir 'a'.
+d_mode_str=drwx-w--wx
+d_mode_arg=$(rwx_to_mode_ $d_mode_str)
+mkdir -p -m $d_mode_arg a/b/c/d
+
+# Make sure the permissions of 'a' haven't been changed.
+p=$(ls -ld a|cut -b-10); case $p in $mode_str);; *) fail=1;; esac
+# 'b's and 'c's should reflect the umask
+p=$(ls -ld a/b|cut -b-10); case $p in drwx------);; *) fail=1;; esac
+p=$(ls -ld a/b/c|cut -b-10); case $p in drwx------);; *) fail=1;; esac
+
+# 'd's perms are determined by the -m argument.
+p=$(ls -ld a/b/c/d|cut -b-10); case $p in $d_mode_str);; *) fail=1;; esac
+
+Exit $fail
diff --git a/tests/mkdir/perm.sh b/tests/mkdir/perm.sh
new file mode 100755
index 0000000..a0f9272
--- /dev/null
+++ b/tests/mkdir/perm.sh
@@ -0,0 +1,84 @@
+#!/bin/sh
+# Verify that mkdir's '-m MODE' option works properly
+# with various umask settings.
+
+# Copyright (C) 2000-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+skip_if_setgid_
+require_no_default_acl_ .
+
+working_umask_or_skip_
+
+
+# parent parent/dir
+# umask -m option resulting perm resulting perm
+tests='
+ 000 : empty : drwxrwxrwx : drwxrwxrwx :
+ 000 : -m 016 : drwxrwxrwx : d-----xrw- :
+ 077 : empty : drwx------ : drwx------ :
+ 050 : empty : drwx-w-rwx : drwx-w-rwx :
+ 050 : -m 312 : drwx-w-rwx : d-wx--x-w- :
+ 160 : empty : drwx--xrwx : drw---xrwx :
+ 160 : -m 743 : drwx--xrwx : drwxr---wx :
+ 027 : -m =+x : drwxr-x--- : d--x--x--- :
+ 027 : -m =+X : drwxr-x--- : d--x--x--- :
+ - : - : last : last :
+ '
+colon_tests=$(echo $tests | sed 's/^ *//; s/ *: */:/g')
+
+for p in empty -p; do
+ test _$p = _empty && p=
+
+ old_IFS=$IFS
+ IFS=':'
+ set $colon_tests
+ IFS=$old_IFS
+
+ while :; do
+ test "$VERBOSE" = yes && set -x
+ umask=$1 mode=$2 parent_perms=$3 sub_perms=$4
+ test "_$mode" = _empty && mode=
+ test $sub_perms = last && break
+ # echo p=$p umask=$1 mode=$2 parent_perms=$3 sub_perms=$4
+ shift; shift; shift; shift
+ umask $umask
+
+ # If we're not using -p, then create the parent manually,
+ # and adjust expectations accordingly.
+ test x$p = x &&
+ {
+ mkdir -m =,u=rwx parent || fail=1
+ parent_perms=drwx------
+ }
+
+ mkdir $p $mode parent/sub || fail=1
+
+ perms=$(stat --printf %A parent)
+ test "$parent_perms" = "$perms" \
+ || { fail=1; echo parent: expected $parent_perms, got $perms; }
+
+ perms=$(stat --printf %A parent/sub)
+ test "$sub_perms" = "$perms" \
+ || { fail=1; echo parent/sub: expected $sub_perms, got $perms; }
+
+ chmod -R u+rwx parent
+ rm -rf parent || fail=1
+ done
+done
+
+Exit $fail
diff --git a/tests/mkdir/restorecon.sh b/tests/mkdir/restorecon.sh
new file mode 100755
index 0000000..0570b3d
--- /dev/null
+++ b/tests/mkdir/restorecon.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+# test mkdir, mknod, mkfifo -Z
+
+# Copyright (C) 2013-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir mknod mkfifo
+require_selinux_
+
+mkdir subdir || framework_failure_
+ctx='root:object_r:tmp_t'
+mls_enabled_ && ctx="$ctx:s0"
+chcon "$ctx" subdir || skip_ "Failed to set context: $ctx"
+cd subdir
+
+# --- mkdir -Z ---
+# Since in a tmp_t dir, dirs can be created as user_tmp_t ...
+mkdir standard || framework_failure_
+mkdir restored || framework_failure_
+if restorecon restored 2>/dev/null; then
+ # ... but when restored can be set to user_home_t
+ # So ensure the type for these mkdir -Z cases matches
+ # the directory type as set by restorecon.
+ mkdir -Z single || fail=1
+ # Run these as separate processes in case global context
+ # set for an arg, impacts on another arg
+ # TODO: Have the defaultcon() vary over these directories
+ for dir in single_p single_p/existing multi/ple; do
+ mkdir -Zp "$dir" || fail=1
+ done
+ restored_type=$(get_selinux_type 'restored')
+ test "$(get_selinux_type 'single')" = "$restored_type" || fail=1
+ test "$(get_selinux_type 'single_p')" = "$restored_type" || fail=1
+ test "$(get_selinux_type 'single_p/existing')" = "$restored_type" || fail=1
+ test "$(get_selinux_type 'multi')" = "$restored_type" || fail=1
+ test "$(get_selinux_type 'multi/ple')" = "$restored_type" || fail=1
+fi
+if test "$fail" = '1'; then
+ ls -UZd standard restored
+ ls -UZd single single_p single_p/existing multi multi/ple
+fi
+
+# --- mknod -Z and mkfifo -Z ---
+# Assume if selinux present that we can create fifos
+for cmd_w_arg in 'mknod' 'mkfifo'; do
+ # In OpenBSD's /bin/sh, mknod is a shell built-in.
+ # Running via "env" ensures we run our program and not the built-in.
+ basename="$cmd_w_arg"
+ test "$basename" = 'mknod' && nt='p' || nt=''
+ env -- $cmd_w_arg $basename $nt || fail=1
+ env -- $cmd_w_arg ${basename}_restore $nt || fail=1
+ if restorecon ${basename}_restore 2>/dev/null; then
+ env -- $cmd_w_arg -Z ${basename}_Z $nt || fail=1
+ restored_type=$(get_selinux_type "${basename}_restore")
+ test "$(get_selinux_type ${basename}_Z)" = "$restored_type" || fail=1
+ fi
+done
+
+Exit $fail
diff --git a/tests/mkdir/selinux.sh b/tests/mkdir/selinux.sh
new file mode 100755
index 0000000..dbdd0a6
--- /dev/null
+++ b/tests/mkdir/selinux.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# ensure that an invalid context doesn't cause a segfault
+
+# Copyright (C) 2008-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir mkfifo mknod
+
+# Note: on an SELinux/enforcing system running mcstransd older than
+# mcstrans-0.2.8-1.fc9, the following commands may mistakenly exit
+# successfully, in spite of the invalid context string.
+require_selinux_enforcing_
+
+c=invalid-selinux-context
+msg="failed to set default file creation context to '$c':"
+
+# Test each of mkdir, mknod, mkfifo with "-Z invalid-context".
+
+for cmd_w_arg in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
+ # In OpenBSD's /bin/sh, mknod is a shell built-in.
+ # Running via "env" ensures we run our program and not the built-in.
+ env -- $cmd_w_arg --context=$c 2> out && fail=1
+ set $cmd_w_arg; cmd=$1
+ echo "$cmd: $msg" > exp || framework_failure_
+
+ # Some systems fail with ENOTSUP, EINVAL, ENOENT, or even
+ # "Unknown system error", or "Function not implemented".
+ # For AIX 5.3: "Unsupported attribute value"
+ # For HP-UX 11.23: Unknown error (252)
+ sed \
+ -e 's/ Not supported$//' \
+ -e 's/ Invalid argument$//' \
+ -e 's/ Unknown system error$//' \
+ -e 's/ Operation not supported$//' \
+ -e 's/ Function not implemented$//' \
+ -e 's/ Unsupported attribute value$//' \
+ -e 's/ Unknown error .*$//' \
+ -e 's/ No such file or directory$//' out > k || framework_failure_
+ mv k out || fail=1
+ compare exp out || fail=1
+done
+
+Exit $fail
diff --git a/tests/mkdir/smack-no-root.sh b/tests/mkdir/smack-no-root.sh
new file mode 100755
index 0000000..11016bf
--- /dev/null
+++ b/tests/mkdir/smack-no-root.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# SMACK test for the mkdir,mknod, mkfifo commands.
+# Derived from tests/mkdir/selinux.sh.
+# Ensure that an unsettable SMACK label doesn't cause a segfault.
+
+# Copyright (C) 2014-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir mkfifo mknod
+
+require_smack_
+
+c=arbitrary-smack-label
+msg="failed to set default file creation context to '$c':"
+
+for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
+ $cmd --context="$c" 2> out && fail=1
+ set $cmd
+ echo "$1: $msg" > exp || framework_failure_
+
+ sed -e 's/ Operation not permitted$//' out > k || framework_failure_
+ mv k out || fail=1
+ compare exp out || fail=1
+done
+
+Exit $fail
diff --git a/tests/mkdir/smack-root.sh b/tests/mkdir/smack-root.sh
new file mode 100755
index 0000000..526a1d6
--- /dev/null
+++ b/tests/mkdir/smack-root.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# SMACK test for the mkdir,mknod, mkfifo commands.
+# Derived from tests/mkdir/selinux.sh.
+# Ensure that SMACK label gets set.
+
+# Copyright (C) 2014-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir mkfifo mknod
+
+require_smack_
+require_root_
+
+c=arbitrary-smack-label
+
+for cmd in 'mkdir dir' 'mknod b p' 'mkfifo f'; do
+ $cmd --context="$c" || { fail=1; continue; }
+ set $cmd
+ ls -dZ $2 > out || fail=1
+ test "$(cut -f1 -d' ' out)" = "$c" || { cat out; fail=1; }
+done
+
+Exit $fail
diff --git a/tests/mkdir/special-1.sh b/tests/mkdir/special-1.sh
new file mode 100755
index 0000000..d571ef2
--- /dev/null
+++ b/tests/mkdir/special-1.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+# verify that mkdir honors special bits in MODE
+
+# Copyright (C) 2000-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+
+set_mode_string=u=rwx,g=rx,o=w,-s,+t
+output_mode_string=drwxr-x-wT
+
+tmp=t
+mkdir -m$set_mode_string $tmp || fail=1
+
+test -d $tmp || fail=1
+mode=$(ls -ld $tmp|cut -b-10)
+case "$mode" in
+ $output_mode_string) ;;
+ *) fail=1 ;;
+esac
+
+rmdir $tmp || fail=1
+tmp2=$tmp/sub
+
+# This should fail.
+returns_ 1 mkdir -m$set_mode_string $tmp2 2> /dev/null || fail=1
+
+# Now test the --parents option.
+mkdir --parents -m$set_mode_string $tmp2 || fail=1
+
+test -d $tmp2 || fail=1
+mode=$(ls -ld $tmp2|cut -b-10)
+case "$mode" in
+ $output_mode_string) ;;
+ *) fail=1 ;;
+esac
+
+Exit $fail
diff --git a/tests/mkdir/t-slash.sh b/tests/mkdir/t-slash.sh
new file mode 100755
index 0000000..6603172
--- /dev/null
+++ b/tests/mkdir/t-slash.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Ensure that mkdir works with arguments specified with and without
+# a trailing slash.
+
+# Copyright (C) 2000-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+
+
+mkdir -p dir/ || fail=1
+test -d dir || fail=1
+
+# This failed on NetBSD for fileutils-4.0.33.
+mkdir d2/ || fail=1
+test -d d2 || fail=1
+
+Exit $fail
diff --git a/tests/mkdir/writable-under-readonly.sh b/tests/mkdir/writable-under-readonly.sh
new file mode 100755
index 0000000..0711c9f
--- /dev/null
+++ b/tests/mkdir/writable-under-readonly.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# FIXME: convert this to a root-only test.
+
+# Copyright (C) 2005-2020 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Test for the 2005-10-13 patch to lib/mkdir-p.c that fixed this sort
+# of bug in mkdir:
+#
+# "mkdir -p /a/b/c" no longer fails merely because a leading prefix
+# directory (e.g., /a or /a/b) exists on a read-only file system.
+#
+# Demonstrate the problem, as root:
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ mkdir
+require_root_
+
+# FIXME: for now, skip it unconditionally
+skip_ temporarily disabled
+
+# FIXME: define cleanup_ to do the umount
+
+# FIXME: use mktemp
+cd /tmp \
+ && dd if=/dev/zero of=1 bs=8192 count=50 \
+ && dd if=/dev/zero of=2 bs=8192 count=50 \
+ && mkdir -p mnt-ro && mkfs -t ext2 1 && mkfs -t ext2 2 \
+ && mount -o loop=/dev/loop3 1 mnt-ro \
+ && mkdir -p mnt-ro/rw \
+ && mount -o remount,ro mnt-ro \
+ && mount -o loop=/dev/loop4 2 mnt-ro/rw
+
+mkdir -p mnt-ro/rw/sub || fail=1
+
+# To clean up
+umount /tmp/2
+umount /tmp/1
+
+Exit $fail