diff options
author | Yan <yanzheng@21cn.com> | 2008-01-04 10:38:22 -0500 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2008-01-04 10:38:22 -0500 |
commit | 7777e63b425f1444d2472ea05a6b2b9cf865f35b (patch) | |
tree | 257d9645b094cd3bae9051f7bb5b24d862764bf4 /inode-map.c | |
parent | 088f78aeaadac6cc877975c6974731968c0093d1 (diff) | |
download | btrfs-progs-7777e63b425f1444d2472ea05a6b2b9cf865f35b.tar.gz |
Update btrfs-progs to match kernel sources
Diffstat (limited to 'inode-map.c')
-rw-r--r-- | inode-map.c | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/inode-map.c b/inode-map.c index 3c4ec9d..ab74977 100644 --- a/inode-map.c +++ b/inode-map.c @@ -16,14 +16,42 @@ * Boston, MA 021110-1307, USA. */ -#include <stdio.h> -#include <stdlib.h> -#include "kerncompat.h" -#include "radix-tree.h" #include "ctree.h" #include "disk-io.h" #include "transaction.h" +int btrfs_find_highest_inode(struct btrfs_root *root, u64 *objectid) +{ + struct btrfs_path *path; + int ret; + struct extent_buffer *l; + struct btrfs_key search_key; + struct btrfs_key found_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 = path->nodes[0]; + btrfs_item_key_to_cpu(l, &found_key, slot); + *objectid = found_key.objectid; + } else { + *objectid = BTRFS_FIRST_FREE_OBJECTID; + } + ret = 0; +error: + btrfs_free_path(path); + return ret; +} + /* * walks the btree of allocated inodes and find a hole. */ @@ -31,40 +59,38 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 dirid, u64 *objectid) { - struct btrfs_path path; + struct btrfs_path *path; struct btrfs_key key; int ret; u64 hole_size = 0; int slot = 0; u64 last_ino = 0; int start_found; - struct btrfs_leaf *l; + struct extent_buffer *l; struct btrfs_key search_key; u64 search_start = dirid; - if (root->fs_info->last_inode_alloc_dirid == dirid) - search_start = root->fs_info->last_inode_alloc; - - if (search_start < BTRFS_FIRST_FREE_OBJECTID) - search_start = BTRFS_FIRST_FREE_OBJECTID; + path = btrfs_alloc_path(); + BUG_ON(!path); + search_start = root->last_inode_alloc; + search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID); search_key.objectid = search_start; - search_key.type = 0; search_key.offset = 0; - btrfs_init_path(&path); + btrfs_init_path(path); start_found = 0; - ret = btrfs_search_slot(trans, root, &search_key, &path, 0, 0); + ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0); if (ret < 0) goto error; - if (path.slots[0] > 0) - path.slots[0]--; + if (path->slots[0] > 0) + path->slots[0]--; while (1) { - l = &path.nodes[0]->leaf; - slot = path.slots[0]; - if (slot >= btrfs_header_nritems(&l->header)) { - ret = btrfs_next_leaf(root, &path); + l = path->nodes[0]; + slot = path->slots[0]; + if (slot >= btrfs_header_nritems(l)) { + ret = btrfs_next_leaf(root, path); if (ret == 0) continue; if (ret < 0) @@ -78,7 +104,7 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, last_ino : search_start; goto found; } - btrfs_disk_key_to_cpu(&key, &l->items[slot].key); + btrfs_item_key_to_cpu(l, &key, slot); if (key.objectid >= search_start) { if (start_found) { if (last_ino < search_start) @@ -92,16 +118,17 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, } start_found = 1; last_ino = key.objectid + 1; - path.slots[0]++; + path->slots[0]++; } // FIXME -ENOSPC found: - root->fs_info->last_inode_alloc = *objectid; - root->fs_info->last_inode_alloc_dirid = dirid; - btrfs_release_path(root, &path); + root->last_inode_alloc = *objectid; + btrfs_release_path(root, path); + btrfs_free_path(path); BUG_ON(*objectid < search_start); return 0; error: - btrfs_release_path(root, &path); + btrfs_release_path(root, path); + btrfs_free_path(path); return ret; } |