new file mode 100755
@@ -0,0 +1,82 @@
+#!/bin/bash
+#
+# Check if "mkfs.btrfs --rootdir" exit gracefully for different error cases
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+prepare_test_dev 128M
+check_prereq mkfs.btrfs
+check_global_prereq fallocate
+
+no_permission() {
+ local dir_path
+ local bad_file
+
+ dir_path=$(mktemp --tmpdir --directory btrfs-progs-mkfs-rootdir.XXXXXX)
+ bad_file="$dir_path/no_read_permission"
+
+ echo " [TEST/mkfs_rootdir] error handler for -EPERM"
+ echo "creating test dir at $src_dir" >> "$RESULTS"
+
+ run_check fallocate -l 4k "$bad_file"
+ run_check chmod 000 "$bad_file"
+
+ run_mustfail "no permission to read" "$TOP/mkfs.btrfs" \
+ --rootdir "$dir_path" "$TEST_DEV"
+ rm -rf -- "$dir_path"
+}
+
+too_small_dest() {
+ local dir_path
+ local bad_file
+
+ dir_path=$(mktemp --tmpdir --directory btrfs-progs-mkfs-rootdir.XXXXXX)
+ bad_file="$dir_path/no_space"
+
+ echo " [TEST/mkfs_rootdir] error handler for -ENOSPC"
+ echo "creating test dir at $src_dir" >> "$RESULTS"
+
+ run_check fallocate -l 256M "$bad_file"
+
+ run_mustfail "too small destination file" "$TOP/mkfs.btrfs" \
+ --rootdir "$dir_path" "$TEST_DEV"
+ rm -rf -- "$dir_path"
+}
+
+non_existent_dest() {
+ local dir_path
+ local dest_file
+
+ dir_path=$(mktemp --tmpdir --directory btrfs-progs-mkfs-rootdir.XXXXXX)
+ dest_file=$(mktemp --tmpdir btrfs-progs-mkfs-dest-file.XXXX)
+ run_check rm -- "$dest_file"
+
+ echo " [TEST/mkfs_rootdir] error handler for non-existent destination file"
+ echo "creating test dir at $src_dir" >> "$RESULTS"
+
+ run_mustfail "non-existent destination file" "$TOP/mkfs.btrfs" \
+ --rootdir "$dir_path" "$dest_file"
+ rm -rf -- "$dir_path"
+}
+
+zero_sized_dest() {
+ local dir_path
+ local dest_file
+
+ dir_path=$(mktemp --tmpdir --directory btrfs-progs-mkfs-rootdir.XXXXXX)
+ dest_file=$(mktemp --tmpdir btrfs-progs-mkfs-dest-file.XXXX)
+
+ echo " [TEST/mkfs_rootdir] error handler for zero-sized destination file"
+ echo "creating test dir at $src_dir" >> "$RESULTS"
+
+ run_mustfail "zero-sized destination file" "$TOP/mkfs.btrfs" \
+ --rootdir "$dir_path" "$dest_file"
+ rm -rf -- "$dir_path"
+ rm -- "$dest_file"
+}
+
+no_permission
+too_small_dest
+non_existent_dest
+zero_sized_dest
Error handlers for the following case must fail gracefully: 1) No permission to read content of rootdir 2) Too small destination file 3) Non-existent destination file 4) Zero sized destination file Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com> --- .../mkfs-tests/011-rootdir-fail-condition/test.sh | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 tests/mkfs-tests/011-rootdir-fail-condition/test.sh