]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - repair/btree.c
libxfs: refactor manage_zones()
[thirdparty/xfsprogs-dev.git] / repair / btree.c
index 31413888eca8300fb282f758d9967a642eacdb82..292fa518d0198f8851e2420816fbf68653303d11 100644 (file)
@@ -1,22 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2007, Silicon Graphics, Inc. Barry Naujok <bnaujok@sgi.com>
  * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <libxfs.h>
+#include "libxfs.h"
 #include "btree.h"
 
 /*
@@ -194,12 +182,14 @@ btree_get_prev(
        }
 
        /* else need to go up and back down the tree to find the previous */
-
-       while (cur->index == 0) {
-               if (++level == root->height)
-                       return NULL;
+       do {
+               if (cur->index)
+                       break;
                cur++;
-       }
+       } while (++level < root->height);
+
+       if (level == root->height)
+               return NULL;
 
        /* the key is in the current level */
        if (key)
@@ -454,29 +444,6 @@ btree_lookup_prev(
        return value;
 }
 
-void *
-btree_uncached_lookup(
-       struct btree_root       *root,
-       unsigned long           key)
-{
-       /* cursor-less (ie. uncached) lookup */
-       int                     height = root->height - 1;
-       struct btree_node       *node = root->root_node;
-       int                     i;
-       int                     key_found = 0;
-
-       while (height >= 0) {
-               for (i = 0; i < node->num_keys; i++)
-                       if (node->keys[i] >= key) {
-                               key_found = node->keys[i] == key;
-                               break;
-                       }
-               node = node->ptrs[i];
-               height--;
-       }
-       return key_found ? node : NULL;
-}
-
 /* Update functions */
 
 static inline void
@@ -518,6 +485,7 @@ btree_update_key(
                return EINVAL;
 
        btree_update_node_key(root, root->cursor, 0, new_key);
+       root->cur_key = new_key;
 
        return 0;
 }
@@ -855,7 +823,7 @@ btree_insert_shift_to_prev(
        if (!btree_copy_cursor_prev(root, tmp_cursor, level + 1))
                return -1;
 
-       n = MIN(*index, (BTREE_PTR_MAX - tmp_cursor[level].node->num_keys) / 2);
+       n = min(*index, (BTREE_PTR_MAX - tmp_cursor[level].node->num_keys) / 2);
        if (!n || !btree_shift_to_prev(root, level, tmp_cursor, n))
                return -1;
 
@@ -878,7 +846,7 @@ btree_insert_shift_to_next(
        if (!btree_copy_cursor_next(root, tmp_cursor, level + 1))
                return -1;
 
-       n = MIN(BTREE_KEY_MAX - *index,
+       n = min(BTREE_KEY_MAX - *index,
                (BTREE_PTR_MAX - tmp_cursor[level].node->num_keys) / 2);
        if (!n || !btree_shift_to_next(root, level, tmp_cursor, n))
                return -1;