summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-06-06 08:02:33 -0400
committerAndrew Cady <d@jerkface.net>2023-06-06 08:02:33 -0400
commit362dd9f4432417929614f86dcc670146e963a0c5 (patch)
treedbebb66c98428ec718b119f213861ca8f64d79dc
parentb6c994d5060a2ab0ac6bb80117f5ac1741df46e6 (diff)
detect rootfs path and mark it with /./
-rwxr-xr-xlist-all-subvolumes27
1 files changed, 21 insertions, 6 deletions
diff --git a/list-all-subvolumes b/list-all-subvolumes
index 2acf772..ec042c7 100755
--- a/list-all-subvolumes
+++ b/list-all-subvolumes
@@ -7,15 +7,18 @@ list_all_subvolumes()
7 for dev in $(list_btrfs) 7 for dev in $(list_btrfs)
8 do 8 do
9 [ -b "$dev" ] || return 9 [ -b "$dev" ] || return
10 d=btrfs/$$/$(systemd-escape "$dev") 10 d=btrfs/pid-$$/$(systemd-escape "$dev")
11 ( 11 (
12 cd /run 12 cd /run
13 mkdir -p "$d" || exit 13 mkdir -p "$d" || exit
14 trap 'umount "$d"; rmdir -p "$d" 2>/dev/null' EXIT 14 trap 'umount "$d"; rmdir -p "$d" 2>/dev/null' EXIT
15 set -x 15 root=
16 mountpoint -q "$d" || mount -o ro,subvol=/ "$dev" "$d" || return 16 (
17 btrfs subvolume list "$@" "$d" 17 set -x
18 ) | extract_subvolume_path "${d##*/}" || return 18 mountpoint -q "$d" || mount -o ro,subvol=/ "$dev" "$d" || return
19 btrfs subvolume list "$@" "$d"
20 ) | extract_subvolume_path "/run/$d" || return
21 )
19 done 22 done
20} 23}
21 24
@@ -25,7 +28,19 @@ extract_subvolume_path()
25 do 28 do
26 path=${REPLY#* path } 29 path=${REPLY#* path }
27 [ "$path" != "$REPLY" ] 30 [ "$path" != "$REPLY" ]
28 printf '%s/%s\n' "$1" "${path#<FS_TREE>/}" 31 path=${path#<FS_TREE>/}
32
33 abspath=$1/$path
34 [ -d "$abspath" ] || exit
35
36 if [ ! "$root" -a "$abspath" -ef / ]
37 then
38 root=$path
39 fi
40 case "$path" in
41 "$root" | "$root"/*) path=$root/.${path#$root} ;;
42 esac
43 printf '%s//%s\n' "${1##*/}" "$path"
29 done 44 done
30} 45}
31 46