Improve seperation between kernel code and userland code by requiring
[dragonfly.git] / sys / sys / blist.h
CommitLineData
984263bc 1/*
8c10bfcf
MD
2 * Copyright (c) 2003,2004 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 *
984263bc
MD
34 * Implements bitmap resource lists.
35 *
36 * Usage:
37 * blist = blist_create(blocks)
38 * (void) blist_destroy(blist)
39 * blkno = blist_alloc(blist, count)
40 * (void) blist_free(blist, blkno, count)
41 * (void) blist_resize(&blist, count, freeextra)
42 *
43 *
44 * Notes:
45 * on creation, the entire list is marked reserved. You should
46 * first blist_free() the sections you want to make available
47 * for allocation before doing general blist_alloc()/free()
48 * ops.
49 *
50 * SWAPBLK_NONE is returned on failure. This module is typically
51 * capable of managing up to (2^31) blocks per blist, though
52 * the memory utilization would be insane if you actually did
53 * that. Managing something like 512MB worth of 4K blocks
54 * eats around 32 KBytes of memory.
55 *
56 * $FreeBSD: src/sys/sys/blist.h,v 1.2.2.1 2003/01/12 09:23:12 dillon Exp $
d9f3f6fa 57 * $DragonFly: src/sys/sys/blist.h,v 1.4 2004/12/30 07:01:52 cpressey Exp $
984263bc
MD
58 */
59
60#ifndef _SYS_BLIST_H_
61#define _SYS_BLIST_H_
62
d9f3f6fa
CP
63#if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
64#error "This file should not be included by userland programs."
65#endif
66
984263bc
MD
67/*
68 * blmeta and bl_bitmap_t MUST be a power of 2 in size.
69 */
70
71typedef struct blmeta {
72 union {
73 daddr_t bmu_avail; /* space available under us */
74 u_daddr_t bmu_bitmap; /* bitmap if we are a leaf */
75 } u;
76 daddr_t bm_bighint; /* biggest contiguous block hint*/
77} blmeta_t;
78
79typedef struct blist {
80 daddr_t bl_blocks; /* area of coverage */
81 daddr_t bl_radix; /* coverage radix */
82 daddr_t bl_skip; /* starting skip */
83 daddr_t bl_free; /* number of free blocks */
84 blmeta_t *bl_root; /* root of radix tree */
85 daddr_t bl_rootblks; /* daddr_t blks allocated for tree */
86} *blist_t;
87
88#define BLIST_META_RADIX 16
89#define BLIST_BMAP_RADIX (sizeof(u_daddr_t)*8)
90
91#define BLIST_MAX_ALLOC BLIST_BMAP_RADIX
92
d9f3f6fa 93#ifdef _KERNEL
984263bc
MD
94extern blist_t blist_create(daddr_t blocks);
95extern void blist_destroy(blist_t blist);
96extern daddr_t blist_alloc(blist_t blist, daddr_t count);
97extern void blist_free(blist_t blist, daddr_t blkno, daddr_t count);
98extern void blist_print(blist_t blist);
99extern void blist_resize(blist_t *pblist, daddr_t count, int freenew);
d9f3f6fa 100#endif /* _KERNEL */
984263bc
MD
101
102#endif /* _SYS_BLIST_H_ */