diff options
author | David Sterba <dsterba@suse.com> | 2016-11-23 10:36:43 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-11-24 13:06:36 +0100 |
commit | e5362f5feb6b526ff3145bb0d7ce164e4d501edd (patch) | |
tree | db54866a0750264746d417e6146d462ef8b9c3ce /utils-lib.c | |
parent | f8278f94ffffcbea1a6be79936aa51640c7cebc5 (diff) |
btrfs-progs: move lookup_path_rootid to library utils
The refactoring in commit 1c85c3de5aab997ff66ea95cb0f2c9f79726ec40 has
broken use of libbtrfs that does not exhibit during build but at the run
time.
Fixes: 1c85c3de5aab997ff66ea95cb0f2c9f79726ec40
Bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=600078
Reported-by: Mike Gilbert <floppymaster@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'utils-lib.c')
-rw-r--r-- | utils-lib.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/utils-lib.c b/utils-lib.c index 79ef35e3..044f93fc 100644 --- a/utils-lib.c +++ b/utils-lib.c @@ -2,9 +2,13 @@ #include <unistd.h> #include <stdlib.h> #include <limits.h> +#include <sys/ioctl.h> +#include <ioctl.h> #if BTRFS_FLAT_INCLUDES +#include "ctree.h" #else +#include <btrfs/ctree.h> #endif /* BTRFS_FLAT_INCLUDES */ /* @@ -38,3 +42,29 @@ u64 arg_strtou64(const char *str) } return value; } + +/* + * For a given: + * - file or directory return the containing tree root id + * - subvolume return its own tree id + * - BTRFS_EMPTY_SUBVOL_DIR_OBJECTID (directory with ino == 2) the result is + * undefined and function returns -1 + */ +int lookup_path_rootid(int fd, u64 *rootid) +{ + struct btrfs_ioctl_ino_lookup_args args; + int ret; + + memset(&args, 0, sizeof(args)); + args.treeid = 0; + args.objectid = BTRFS_FIRST_FREE_OBJECTID; + + ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); + if (ret < 0) + return -errno; + + *rootid = args.treeid; + + return 0; +} + |