source: rtems-libbsd/freebsd/sys/sys/blist.h @ 1b47c61

55-freebsd-126-freebsd-12
Last change on this file since 1b47c61 was 8d5fc9d, checked in by Sebastian Huber <sebastian.huber@…>, on 11/27/18 at 08:07:53

blist: Fix u_daddr_t for 32-bit targets

The daddr_t is defined in <sys/types.h> by Newlib as long.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1998 Matthew Dillon.  All Rights Reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/*
31 * Implements bitmap resource lists.
32 *
33 *      Usage:
34 *              blist = blist_create(blocks, flags)
35 *              (void)  blist_destroy(blist)
36 *              blkno = blist_alloc(blist, count)
37 *              (void)  blist_free(blist, blkno, count)
38 *              nblks = blist_fill(blist, blkno, count)
39 *              (void)  blist_resize(&blist, count, freeextra, flags)
40 *             
41 *
42 *      Notes:
43 *              on creation, the entire list is marked reserved.  You should
44 *              first blist_free() the sections you want to make available
45 *              for allocation before doing general blist_alloc()/free()
46 *              ops.
47 *
48 *              SWAPBLK_NONE is returned on failure.  This module is typically
49 *              capable of managing up to (2^63) blocks per blist, though
50 *              the memory utilization would be insane if you actually did
51 *              that.  Managing something like 512MB worth of 4K blocks
52 *              eats around 32 KBytes of memory.
53 *
54 * $FreeBSD$
55
56 */
57
58#ifndef _SYS_BLIST_H_
59#define _SYS_BLIST_H_
60
61#ifndef __rtems__
62typedef uint64_t        u_daddr_t;      /* unsigned disk address */
63#else /* __rtems__ */
64typedef unsigned long   u_daddr_t;      /* unsigned disk address */
65#endif /* __rtems__ */
66
67/*
68 * note: currently use SWAPBLK_NONE as an absolute value rather then
69 * a flag bit.
70 */
71
72#define SWAPBLK_MASK    ((daddr_t)((u_daddr_t)-1 >> 1))         /* mask */
73#define SWAPBLK_NONE    ((daddr_t)((u_daddr_t)SWAPBLK_MASK + 1))/* flag */
74
75/*
76 * Both blmeta and bmu_bitmap MUST be a power of 2 in size.
77 */
78
79typedef struct blmeta {
80        u_daddr_t       bm_bitmap;      /* bitmap if we are a leaf      */
81        daddr_t         bm_bighint;     /* biggest contiguous block hint*/
82} blmeta_t;
83
84typedef struct blist {
85        daddr_t         bl_blocks;      /* area of coverage             */
86        daddr_t         bl_avail;       /* # available blocks */
87        u_daddr_t       bl_radix;       /* coverage radix               */
88        daddr_t         bl_cursor;      /* next-fit search starts at    */
89        blmeta_t        bl_root[1];     /* root of radix tree           */
90} *blist_t;
91
92#define BLIST_BMAP_RADIX        (sizeof(u_daddr_t)*8)
93#define BLIST_META_RADIX        BLIST_BMAP_RADIX
94
95#define BLIST_MAX_ALLOC         BLIST_BMAP_RADIX
96
97struct sbuf;
98
99daddr_t blist_alloc(blist_t blist, daddr_t count);
100daddr_t blist_avail(blist_t blist);
101blist_t blist_create(daddr_t blocks, int flags);
102void    blist_destroy(blist_t blist);
103daddr_t blist_fill(blist_t bl, daddr_t blkno, daddr_t count);
104void    blist_free(blist_t blist, daddr_t blkno, daddr_t count);
105void    blist_print(blist_t blist);
106void    blist_resize(blist_t *pblist, daddr_t count, int freenew, int flags);
107void    blist_stats(blist_t blist, struct sbuf *s);
108
109#endif  /* _SYS_BLIST_H_ */
110
Note: See TracBrowser for help on using the repository browser.