]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - repair/incore_ext.c
libxfs: refactor manage_zones()
[thirdparty/xfsprogs-dev.git] / repair / incore_ext.c
index 28648d1066894ec5480288e3458b2588e6e44ee4..e7ef9eb234b3deabd605d0de9957adadaace8576 100644 (file)
@@ -1,22 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  * 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 "avl.h"
 #include "btree.h"
 #include "globals.h"
@@ -156,7 +144,7 @@ release_extent_tree_node(extent_tree_node_t *node)
  * reused.  the duplicate and bno/bcnt extent trees for each AG
  * are recycled after they're no longer needed to save memory
  */
-void
+static void
 release_extent_tree(avltree_desc_t *tree)
 {
        extent_tree_node_t      *ext;
@@ -266,14 +254,6 @@ get_bno_extent(xfs_agnumber_t agno, extent_tree_node_t *ext)
        return;
 }
 
-/*
- * normalizing constant for bcnt size -> address conversion (see avl ops)
- * used by the AVL tree code to convert sizes and must be used when
- * doing an AVL search in the tree (e.g. avl_findrange(s))
- */
-#define MAXBCNT                0xFFFFFFFF
-#define BCNT_ADDR(cnt) ((unsigned int) MAXBCNT - (cnt))
-
 /*
  * the next 4 routines manage the trees of free extents -- 2 trees
  * per AG.  The first tree is sorted by block number.  The second
@@ -386,8 +366,6 @@ findfirst_bcnt_extent(xfs_agnumber_t agno)
 extent_tree_node_t *
 findbiggest_bcnt_extent(xfs_agnumber_t agno)
 {
-       extern avlnode_t *avl_lastino(avlnode_t *root);
-
        ASSERT(extent_bcnt_ptrs != NULL);
        ASSERT(extent_bcnt_ptrs[agno] != NULL);
 
@@ -500,17 +478,17 @@ get_bcnt_extent(xfs_agnumber_t agno, xfs_agblock_t startblock,
        return(ext);
 }
 
-static __psunsigned_t
+static uintptr_t
 avl_ext_start(avlnode_t *node)
 {
-       return((__psunsigned_t)
+       return((uintptr_t)
                ((extent_tree_node_t *) node)->ex_startblock);
 }
 
-static __psunsigned_t
+static uintptr_t
 avl_ext_end(avlnode_t *node)
 {
-       return((__psunsigned_t) (
+       return((uintptr_t) (
                ((extent_tree_node_t *) node)->ex_startblock +
                ((extent_tree_node_t *) node)->ex_blockcount));
 }
@@ -519,32 +497,32 @@ avl_ext_end(avlnode_t *node)
  * convert size to an address for the AVL tree code -- the bigger the size,
  * the lower the address so the biggest extent will be first in the tree
  */
-static __psunsigned_t
+static uintptr_t
 avl_ext_bcnt_start(avlnode_t *node)
 {
 /*
-       return((__psunsigned_t) (BCNT_ADDR(((extent_tree_node_t *)
+       return((uintptr_t) (BCNT_ADDR(((extent_tree_node_t *)
                                                node)->ex_blockcount)));
 */
-       return((__psunsigned_t) ((extent_tree_node_t *)node)->ex_blockcount);
+       return((uintptr_t) ((extent_tree_node_t *)node)->ex_blockcount);
 }
 
-static __psunsigned_t
+static uintptr_t
 avl_ext_bcnt_end(avlnode_t *node)
 {
 /*
-       return((__psunsigned_t) (BCNT_ADDR(((extent_tree_node_t *)
+       return((uintptr_t) (BCNT_ADDR(((extent_tree_node_t *)
                                                node)->ex_blockcount)));
 */
-       return((__psunsigned_t) ((extent_tree_node_t *)node)->ex_blockcount);
+       return((uintptr_t) ((extent_tree_node_t *)node)->ex_blockcount);
 }
 
-avlops_t avl_extent_bcnt_tree_ops = {
+static avlops_t avl_extent_bcnt_tree_ops = {
        avl_ext_bcnt_start,
        avl_ext_bcnt_end
 };
 
-avlops_t avl_extent_tree_ops = {
+static avlops_t avl_extent_tree_ops = {
        avl_ext_start,
        avl_ext_end
 };
@@ -554,7 +532,7 @@ avlops_t avl_extent_tree_ops = {
  * startblocks can be 64-bit values.
  */
 static rt_extent_tree_node_t *
-mk_rt_extent_tree_nodes(xfs_drtbno_t new_startblock,
+mk_rt_extent_tree_nodes(xfs_rtblock_t new_startblock,
        xfs_extlen_t new_blockcount, extent_state_t new_state)
 {
        rt_extent_tree_node_t *new;
@@ -622,10 +600,10 @@ free_rt_dup_extent_tree(xfs_mount_t *mp)
  * add a duplicate real-time extent
  */
 void
-add_rt_dup_extent(xfs_drtbno_t startblock, xfs_extlen_t blockcount)
+add_rt_dup_extent(xfs_rtblock_t startblock, xfs_extlen_t blockcount)
 {
        rt_extent_tree_node_t *first, *last, *ext, *next_ext;
-       xfs_drtbno_t new_startblock;
+       xfs_rtblock_t new_startblock;
        xfs_extlen_t new_blockcount;
 
        pthread_mutex_lock(&rt_ext_tree_lock);
@@ -710,7 +688,7 @@ add_rt_dup_extent(xfs_drtbno_t startblock, xfs_extlen_t blockcount)
  */
 /* ARGSUSED */
 int
-search_rt_dup_extent(xfs_mount_t *mp, xfs_drtbno_t bno)
+search_rt_dup_extent(xfs_mount_t *mp, xfs_rtblock_t bno)
 {
        int ret;
 
@@ -723,20 +701,20 @@ search_rt_dup_extent(xfs_mount_t *mp, xfs_drtbno_t bno)
        return(ret);
 }
 
-static __uint64_t
+static uint64_t
 avl64_rt_ext_start(avl64node_t *node)
 {
        return(((rt_extent_tree_node_t *) node)->rt_startblock);
 }
 
-static __uint64_t
+static uint64_t
 avl64_ext_end(avl64node_t *node)
 {
        return(((rt_extent_tree_node_t *) node)->rt_startblock +
                ((rt_extent_tree_node_t *) node)->rt_blockcount);
 }
 
-avl64ops_t avl64_extent_tree_ops = {
+static avl64ops_t avl64_extent_tree_ops = {
        avl64_rt_ext_start,
        avl64_ext_end
 };
@@ -785,7 +763,7 @@ incore_ext_init(xfs_mount_t *mp)
                avl_init_tree(extent_bcnt_ptrs[i], &avl_extent_bcnt_tree_ops);
        }
 
-       if ((rt_ext_tree_ptr = malloc(sizeof(avltree_desc_t))) == NULL)
+       if ((rt_ext_tree_ptr = malloc(sizeof(avl64tree_desc_t))) == NULL)
                do_error(_("couldn't malloc dup rt extent tree descriptor\n"));
 
        avl64_init_tree(rt_ext_tree_ptr, &avl64_extent_tree_ops);
@@ -814,7 +792,7 @@ incore_ext_teardown(xfs_mount_t *mp)
        extent_bno_ptrs = NULL;
 }
 
-int
+static int
 count_extents(xfs_agnumber_t agno, avltree_desc_t *tree, int whichtree)
 {
        extent_tree_node_t *node;
@@ -836,7 +814,7 @@ count_extents(xfs_agnumber_t agno, avltree_desc_t *tree, int whichtree)
 int
 count_bno_extents_blocks(xfs_agnumber_t agno, uint *numblocks)
 {
-       __uint64_t nblocks;
+       uint64_t nblocks;
        extent_tree_node_t *node;
        int i = 0;