|
| 1 | +#!/bin/bash |
| 2 | +# Test how btrfs subvolume list prints paths, including all of the weird |
| 3 | +# accidental behavior. |
| 4 | + |
| 5 | +source "$TEST_TOP/common" || exit |
| 6 | + |
| 7 | +check_prereq btrfs |
| 8 | +check_prereq mkfs.btrfs |
| 9 | + |
| 10 | +setup_root_helper |
| 11 | +prepare_test_dev |
| 12 | + |
| 13 | +run_check_mkfs_test_dev |
| 14 | +run_check_mount_test_dev |
| 15 | + |
| 16 | +cd "$TEST_MNT" |
| 17 | + |
| 18 | +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "a" |
| 19 | +run_check $SUDO_HELPER mkdir "a/b" |
| 20 | +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "a/b/c" |
| 21 | +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "a/b/c/d" |
| 22 | +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "a/e" |
| 23 | + |
| 24 | +subvol_list_paths() { |
| 25 | + run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list "$@" | sed 's/.*path //' |
| 26 | +} |
| 27 | + |
| 28 | +expect_subvol_list_paths() { |
| 29 | + diff -u - <(subvol_list_paths "$@") || _fail "wrong output from btrfs subvolume list $*" |
| 30 | +} |
| 31 | + |
| 32 | +### No options ### |
| 33 | + |
| 34 | +# Paths are relative to the given subvolume if they are beneath it and relative |
| 35 | +# to the root of the filesystem otherwise. |
| 36 | +expect_subvol_list_paths . << EOF |
| 37 | +a |
| 38 | +a/b/c |
| 39 | +a/b/c/d |
| 40 | +a/e |
| 41 | +EOF |
| 42 | + |
| 43 | +expect_subvol_list_paths a << EOF |
| 44 | +a |
| 45 | +b/c |
| 46 | +b/c/d |
| 47 | +e |
| 48 | +EOF |
| 49 | + |
| 50 | +expect_subvol_list_paths a/b/c << EOF |
| 51 | +a |
| 52 | +a/b/c |
| 53 | +d |
| 54 | +a/e |
| 55 | +EOF |
| 56 | + |
| 57 | +# If passed a directory, it's treated as the containing subvolume. |
| 58 | +expect_subvol_list_paths a/b << EOF |
| 59 | +a |
| 60 | +b/c |
| 61 | +b/c/d |
| 62 | +e |
| 63 | +EOF |
| 64 | + |
| 65 | +### -a ### |
| 66 | + |
| 67 | +# Paths are relative to the root of the filesystem. Subvolumes that are not an |
| 68 | +# immediate child of the passed subvolume are prefixed with <FS_TREE>/. |
| 69 | +expect_subvol_list_paths -a . << EOF |
| 70 | +a |
| 71 | +<FS_TREE>/a/b/c |
| 72 | +<FS_TREE>/a/b/c/d |
| 73 | +<FS_TREE>/a/e |
| 74 | +EOF |
| 75 | + |
| 76 | +expect_subvol_list_paths -a a << EOF |
| 77 | +<FS_TREE>/a |
| 78 | +a/b/c |
| 79 | +<FS_TREE>/a/b/c/d |
| 80 | +a/e |
| 81 | +EOF |
| 82 | + |
| 83 | +# If passed a directory, it's treated as the containing subvolume. |
| 84 | +expect_subvol_list_paths -a a/b << EOF |
| 85 | +<FS_TREE>/a |
| 86 | +a/b/c |
| 87 | +<FS_TREE>/a/b/c/d |
| 88 | +a/e |
| 89 | +EOF |
| 90 | + |
| 91 | +### -o ### |
| 92 | + |
| 93 | +# Only immediate children of the passed subvolume are printed, and they are |
| 94 | +# printed relative to the root of the filesystem. |
| 95 | +expect_subvol_list_paths -o . << EOF |
| 96 | +a |
| 97 | +EOF |
| 98 | + |
| 99 | +expect_subvol_list_paths -o a << EOF |
| 100 | +a/b/c |
| 101 | +a/e |
| 102 | +EOF |
| 103 | + |
| 104 | +# If passed a directory, it's treated as the containing subvolume. |
| 105 | +expect_subvol_list_paths -o a/b << EOF |
| 106 | +a/b/c |
| 107 | +a/e |
| 108 | +EOF |
| 109 | + |
| 110 | +expect_subvol_list_paths -o a/b/c << EOF |
| 111 | +a/b/c/d |
| 112 | +EOF |
| 113 | + |
| 114 | +expect_subvol_list_paths -o a/b/c/d << EOF |
| 115 | +EOF |
| 116 | + |
| 117 | +cd .. |
| 118 | +run_check_umount_test_dev |
0 commit comments