Add definitions for LONG_BIT and WORD_BIT.
[dragonfly.git] / sbin / newfs_hammer / super_alist.c
1 /*
2  * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * $DragonFly: src/sbin/newfs_hammer/Attic/super_alist.c,v 1.3 2007/11/27 07:44:38 dillon Exp $
35  */
36 /*
37  * Implement the super-cluster A-list recursion for the cluster allocator.
38  *
39  * Volume A-list -> supercluster A-list -> cluster
40  */
41
42 #include "newfs_hammer.h"
43
44 static int
45 super_alist_init(void *info, int32_t blk, int32_t radix)
46 {
47         struct volume_info *vol = info;
48         struct supercl_info *supercl;
49         int32_t sclno;
50
51         /*
52          * Calculate the super-cluster number containing the cluster (blk)
53          * and obtain the super-cluster buffer.
54          */
55         sclno = blk / HAMMER_SCL_MAXCLUSTERS;
56         supercl = get_supercl(vol, sclno);
57         return(0);
58 }
59
60 static int
61 super_alist_destroy(void *info, int32_t blk, int32_t radix)
62 {
63         return(0);
64 }
65
66 static int
67 super_alist_alloc_fwd(void *info, int32_t blk, int32_t radix,
68                       int32_t count, int32_t atblk, int32_t *fullp)
69 {
70         struct volume_info *vol = info;
71         struct supercl_info *supercl;
72         int32_t sclno;
73         int32_t r;
74
75         sclno = blk / HAMMER_SCL_MAXCLUSTERS;
76         supercl = get_supercl(vol, sclno);
77         r = hammer_alist_alloc_fwd(&supercl->clu_alist, count, atblk - blk);
78         if (r != HAMMER_ALIST_BLOCK_NONE)
79                 r += blk;
80         *fullp = hammer_alist_isfull(&supercl->clu_alist);
81         return(r);
82 }
83
84 static int
85 super_alist_alloc_rev(void *info, int32_t blk, int32_t radix,
86                       int32_t count, int32_t atblk, int32_t *fullp)
87 {
88         struct volume_info *vol = info;
89         struct supercl_info *supercl;
90         int32_t sclno;
91         int32_t r;
92
93         sclno = blk / HAMMER_SCL_MAXCLUSTERS;
94         supercl = get_supercl(vol, sclno);
95         r = hammer_alist_alloc_rev(&supercl->clu_alist, count, atblk - blk);
96         if (r != HAMMER_ALIST_BLOCK_NONE)
97                 r += blk;
98         *fullp = hammer_alist_isfull(&supercl->clu_alist);
99         return(r);
100 }
101
102 static void
103 super_alist_free(void *info, int32_t blk, int32_t radix,
104                  int32_t base_blk, int32_t count, int32_t *emptyp)
105 {
106         struct volume_info *vol = info;
107         struct supercl_info *supercl;
108         int32_t sclno;
109
110         sclno = blk / HAMMER_SCL_MAXCLUSTERS;
111         supercl = get_supercl(vol, sclno);
112         hammer_alist_free(&supercl->clu_alist, base_blk, count);
113         *emptyp = hammer_alist_isempty(&supercl->clu_alist);
114 }
115
116 static void
117 super_alist_print(void *info, int32_t blk, int32_t radix, int tab)
118 {
119 }
120
121 void
122 hammer_super_alist_template(hammer_alist_config_t config)
123 {
124         config->bl_radix_init = super_alist_init;
125         config->bl_radix_destroy = super_alist_destroy;
126         config->bl_radix_alloc_fwd = super_alist_alloc_fwd;
127         config->bl_radix_alloc_rev = super_alist_alloc_rev;
128         config->bl_radix_free = super_alist_free;
129         config->bl_radix_print = super_alist_print;
130 }
131