+int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid)
+{
+ struct btrfs_path *path;
+ int ret;
+ struct btrfs_leaf *l;
+ struct btrfs_root *root = fs_root->fs_info->inode_root;
+ struct btrfs_key search_key;
+ int slot;
+
+ path = btrfs_alloc_path();
+ BUG_ON(!path);
+
+ search_key.objectid = (u64)-1;
+ search_key.offset = (u64)-1;
+ ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
+ if (ret < 0)
+ goto error;
+ BUG_ON(ret == 0);
+ if (path->slots[0] > 0) {
+ slot = path->slots[0] - 1;
+ l = btrfs_buffer_leaf(path->nodes[0]);
+ *objectid = btrfs_disk_key_objectid(&l->items[slot].key);
+ } else {
+ *objectid = BTRFS_FIRST_FREE_OBJECTID;
+ }
+ ret = 0;
+error:
+ btrfs_free_path(path);
+ return ret;
+}
+