Is there a convenient way to get information on all btrfs filesystems subvolumes without resorting to C, i.e. in POSIX shell ?
/sys/fs/btrfs contains info only on filesystems, nothing on subvolumes, so currently i end up mounting all filesystems in a temp folder, scanning them with
btrfs subvol list, then parsing the resulting output.
Needless to say, that is fairly ugly.
This is with a 3.16.x kernel and btrfs-progs v3.14.1 (from stock Ubuntu 14.10).
Below is the (ugly) script I'm currently using. I know I could get the info I need using pure C, and that's probably what I'll end up doing, but I was wondering if there was a simpler, more elegant way.
#!/bin/bash for i in /sys/fs/btrfs/*[!features]; do device="/dev/$(basename $i/devices/*)" mountpoint=/var/lib/btrfs/tmp/mnt/$(basename "$i") [ -d "$mountpoint" ] || mkdir "$mountpoint" grep -qs $mountpoint /proc/mounts [ $? -ne 0 ] && mount -v "$device" "$mountpoint" while read -r subvol; do # whatever you want done < <(btrfs subvolume list "$mountpoint") umount $mountpoint rmdir $mountpoint done