issubvolume (Btrfs)

LES on 2023-07-03: I thought it would be nice if we had a [file is subvolume] option in the file command so I made my own:

  proc issubvolume {path}        {
        set path [file normalize $path]
        if {![file exists $path]} {puts 0; return}
        if {[catch {exec btrfs subvolume show $path} error]}        {
                #puts $error
                if {[regexp "not a subvolume" $error]}        {
                        puts 0; return
                } else {puts 1; return}
        } else {puts 1; return}

Note that you need to be root to run btrfs subvolume show $path, but my code works around that. It works for regular users too.

Problem: it may generate incorrect output if you don't have btrfs-progs installed, which is possible. I am not quite sure of how to handle that.

I (or you?) may contribute other Btrfs related procs in the future. Dealing with snapshots seems to be the most obvious candidate to me.