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/fs/jfs/jfs_btree.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) International Business Machines Corp., 2000-2001
    3  *
    4  *   This program is free software;  you can redistribute it and/or modify
    5  *   it under the terms of the GNU General Public License as published by
    6  *   the Free Software Foundation; either version 2 of the License, or 
    7  *   (at your option) any later version.
    8  * 
    9  *   This program is distributed in the hope that it will be useful,
   10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
   11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
   12  *   the GNU General Public License for more details.
   13  *
   14  *   You should have received a copy of the GNU General Public License
   15  *   along with this program;  if not, write to the Free Software 
   16  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   17  */
   18 #ifndef _H_JFS_BTREE
   19 #define _H_JFS_BTREE
   20 
   21 /*
   22  *      jfs_btree.h: B+-tree
   23  *
   24  * JFS B+-tree (dtree and xtree) common definitions
   25  */
   26 
   27 /*
   28  *      basic btree page - btpage
   29  *
   30 struct btpage {
   31         s64 next;               right sibling bn
   32         s64 prev;               left sibling bn
   33 
   34         u8 flag;
   35         u8 rsrvd[7];            type specific
   36         s64 self;               self address
   37 
   38         u8 entry[4064];
   39 };                                              */
   40 
   41 /* btpaget_t flag */
   42 #define BT_TYPE         0x07    /* B+-tree index */
   43 #define BT_ROOT         0x01    /* root page */
   44 #define BT_LEAF         0x02    /* leaf page */
   45 #define BT_INTERNAL     0x04    /* internal page */
   46 #define BT_RIGHTMOST    0x10    /* rightmost page */
   47 #define BT_LEFTMOST     0x20    /* leftmost page */
   48 #define BT_SWAPPED      0x80    /* used by fsck for endian swapping */
   49 
   50 /* btorder (in inode) */
   51 #define BT_RANDOM               0x0000
   52 #define BT_SEQUENTIAL           0x0001
   53 #define BT_LOOKUP               0x0010
   54 #define BT_INSERT               0x0020
   55 #define BT_DELETE               0x0040
   56 
   57 /*
   58  *      btree page buffer cache access
   59  */
   60 #define BT_IS_ROOT(MP) (((MP)->xflag & COMMIT_PAGE) == 0)
   61 
   62 /* get page from buffer page */
   63 #define BT_PAGE(IP, MP, TYPE, ROOT)\
   64         (BT_IS_ROOT(MP) ? (TYPE *)&JFS_IP(IP)->ROOT : (TYPE *)(MP)->data)
   65 
   66 /* get the page buffer and the page for specified block address */
   67 #define BT_GETPAGE(IP, BN, MP, TYPE, SIZE, P, RC, ROOT)\
   68 {\
   69         if ((BN) == 0)\
   70         {\
   71                 MP = (struct metapage *)&JFS_IP(IP)->bxflag;\
   72                 P = (TYPE *)&JFS_IP(IP)->ROOT;\
   73                 RC = 0;\
   74         }\
   75         else\
   76         {\
   77                 MP = read_metapage((IP), BN, SIZE, 1);\
   78                 if (MP) {\
   79                         RC = 0;\
   80                         P = (MP)->data;\
   81                 } else {\
   82                         P = NULL;\
   83                         jfs_err("bread failed!");\
   84                         RC = EIO;\
   85                 }\
   86         }\
   87 }
   88 
   89 #define BT_MARK_DIRTY(MP, IP)\
   90 {\
   91         if (BT_IS_ROOT(MP))\
   92                 mark_inode_dirty(IP);\
   93         else\
   94                 mark_metapage_dirty(MP);\
   95 }
   96 
   97 /* put the page buffer */
   98 #define BT_PUTPAGE(MP)\
   99 {\
  100         if (! BT_IS_ROOT(MP)) \
  101                 release_metapage(MP); \
  102 }
  103 
  104 
  105 /*
  106  *      btree traversal stack
  107  *
  108  * record the path traversed during the search;
  109  * top frame record the leaf page/entry selected.
  110  */
  111 #define MAXTREEHEIGHT           8
  112 struct btframe {        /* stack frame */
  113         s64 bn;                 /* 8: */
  114         s16 index;              /* 2: */
  115         s16 lastindex;          /* 2: */
  116         struct metapage *mp;    /* 4: */
  117 };                              /* (16) */
  118 
  119 struct btstack {
  120         struct btframe *top;
  121         int nsplit;
  122         struct btframe stack[MAXTREEHEIGHT];
  123 };
  124 
  125 #define BT_CLR(btstack)\
  126         (btstack)->top = (btstack)->stack
  127 
  128 #define BT_PUSH(BTSTACK, BN, INDEX)\
  129 {\
  130         (BTSTACK)->top->bn = BN;\
  131         (BTSTACK)->top->index = INDEX;\
  132         ++(BTSTACK)->top;\
  133         assert((BTSTACK)->top != &((BTSTACK)->stack[MAXTREEHEIGHT]));\
  134 }
  135 
  136 #define BT_POP(btstack)\
  137         ( (btstack)->top == (btstack)->stack ? NULL : --(btstack)->top )
  138 
  139 #define BT_STACK(btstack)\
  140         ( (btstack)->top == (btstack)->stack ? NULL : (btstack)->top )
  141 
  142 /* retrieve search results */
  143 #define BT_GETSEARCH(IP, LEAF, BN, MP, TYPE, P, INDEX, ROOT)\
  144 {\
  145         BN = (LEAF)->bn;\
  146         MP = (LEAF)->mp;\
  147         if (BN)\
  148                 P = (TYPE *)MP->data;\
  149         else\
  150                 P = (TYPE *)&JFS_IP(IP)->ROOT;\
  151         INDEX = (LEAF)->index;\
  152 }
  153 
  154 /* put the page buffer of search */
  155 #define BT_PUTSEARCH(BTSTACK)\
  156 {\
  157         if (! BT_IS_ROOT((BTSTACK)->top->mp))\
  158                 release_metapage((BTSTACK)->top->mp);\
  159 }
  160 #endif                          /* _H_JFS_BTREE */

Cache object: fc19a44147b54a721f1822dd4916f2c6


[ 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.