diff --git a/libmisc/btrfs.c b/libmisc/btrfs.c index 7236454a..f6024bfb 100644 --- a/libmisc/btrfs.c +++ b/libmisc/btrfs.c @@ -1,14 +1,36 @@ #include #include #include +#include #include "prototypes.h" +static bool path_exists(const char *p) +{ + int ret; + struct stat sb; + + return stat(p, &sb) == 0; +} + +static const char *btrfs_cmd(void) +{ + const char *btrfs_paths[] = {"/sbin/btrfs", + "/bin/btrfs", "/usr/sbin/btrfs", "/usr/bin/btrfs", NULL}; + const char *p; + int i; + + for (i = 0, p = btrfs_paths[i]; p; i++, p = btrfs_paths[i]) + if (path_exists(p)) + return p; + + return NULL; +} static int run_btrfs_subvolume_cmd(const char *subcmd, const char *arg1, const char *arg2) { int status = 0; - const char *cmd = "/sbin/btrfs"; + const char *cmd = btrfs_cmd(); const char *argv[] = { strrchr(cmd, '/'), "subvolume",