diff options
author | David Sterba <dsterba@suse.cz> | 2013-09-18 18:19:30 +0200 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2013-10-16 08:23:11 -0400 |
commit | 7fbcc39c3075b88718bcb3e8e6f3ff599a4e9f86 (patch) | |
tree | 50c7072f9a53f9270b0077206ad38ec5be14a2f4 /utils.c | |
parent | 8e937074a4ecc1a70f4a10cfff94e60a916ce82f (diff) |
btrfs-progs: look up the containing tree root id
Find the tree id of the containing subvolume for a given file or
directory. For subvolume return it's own id.
$ btrfs inspect-internal rootid <path>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -1975,3 +1975,33 @@ int ask_user(char *question) (answer = strtok_r(buf, " \t\n\r", &saveptr)) && (!strcasecmp(answer, "yes") || !strcasecmp(answer, "y")); } + +/* + * For a given: + * - file or directory return the containing tree root id + * - subvolume return it's own tree id + * - BTRFS_EMPTY_SUBVOL_DIR_OBJECTID (directory with ino == 2) the result is + * undefined and function returns -1 + */ +int lookup_ino_rootid(int fd, u64 *rootid) +{ + struct btrfs_ioctl_ino_lookup_args args; + int ret; + int e; + + memset(&args, 0, sizeof(args)); + args.treeid = 0; + args.objectid = BTRFS_FIRST_FREE_OBJECTID; + + ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); + e = errno; + if (ret) { + fprintf(stderr, "ERROR: Failed to lookup root id - %s\n", + strerror(e)); + return ret; + } + + *rootid = args.treeid; + + return 0; +} |