X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=utils-lib.c;h=044f93fc4446db7fd8918a5909856fd7fbc5391c;hb=e460ccd6d13bb2cc4939fb860b50964dfbd3c247;hp=9d53c6e5c7105f57534b9b27833b68f505d5ee94;hpb=aa46922c09159d8315a35b81cacf30dcfb9243a5;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/utils-lib.c b/utils-lib.c index 9d53c6e..044f93f 100644 --- a/utils-lib.c +++ b/utils-lib.c @@ -1,12 +1,14 @@ -#define _GNU_SOURCE - #include "kerncompat.h" #include #include #include +#include +#include #if BTRFS_FLAT_INCLUDES +#include "ctree.h" #else +#include #endif /* BTRFS_FLAT_INCLUDES */ /* @@ -40,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; +} +