The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/blist.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: cf32ed5d7576a816ffb37f9586df6be9


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.