#include <linux/btrfs_tree.h>
#include <linux/magic.h>
#include <sys/statfs.h>
+#include <stdbool.h>
#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",