3 * Copyright (C) 1998-2002 A.J. van Os; Released under GPL
6 * Functions to compute the depot offset
11 #define SIZE_RATIO (BIG_BLOCK_SIZE/SMALL_BLOCK_SIZE)
13 static ULONG
*aulSmallBlockList
= NULL
;
14 static size_t tSmallBlockListLen
= 0;
18 * vDestroySmallBlockList - destroy the small block list
21 vDestroySmallBlockList(void)
23 DBG_MSG("vDestroySmallBlockList");
25 aulSmallBlockList
= xfree(aulSmallBlockList
);
26 tSmallBlockListLen
= 0;
27 } /* end of vDestroySmalBlockList */
30 * vCreateSmallBlockList - create the small block list
32 * returns: TRUE when successful, otherwise FALSE
35 bCreateSmallBlockList(ULONG ulStartblock
, const ULONG
*aulBBD
, size_t tBBDLen
)
41 fail(aulSmallBlockList
!= NULL
);
42 fail(tSmallBlockListLen
!= 0);
43 fail(ulStartblock
> MAX_BLOCKNUMBER
&& ulStartblock
!= END_OF_CHAIN
);
47 /* Find the length of the small block list */
48 for (tSmallBlockListLen
= 0, ulTmp
= ulStartblock
;
49 tSmallBlockListLen
< tBBDLen
&& ulTmp
!= END_OF_CHAIN
;
50 tSmallBlockListLen
++, ulTmp
= aulBBD
[ulTmp
]) {
51 if (ulTmp
>= (ULONG
)tBBDLen
) {
54 werr(1, "The Big Block Depot is damaged");
57 DBG_DEC(tSmallBlockListLen
);
59 if (tSmallBlockListLen
== 0) {
60 /* There is no small block list */
61 fail(ulStartblock
!= END_OF_CHAIN
);
62 aulSmallBlockList
= NULL
;
66 /* Create the small block list */
67 tSize
= tSmallBlockListLen
* sizeof(ULONG
);
68 aulSmallBlockList
= xmalloc(tSize
);
69 for (iIndex
= 0, ulTmp
= ulStartblock
;
70 iIndex
< (int)tBBDLen
&& ulTmp
!= END_OF_CHAIN
;
71 iIndex
++, ulTmp
= aulBBD
[ulTmp
]) {
72 if (ulTmp
>= (ULONG
)tBBDLen
) {
75 werr(1, "The Big Block Depot is damaged");
77 aulSmallBlockList
[iIndex
] = ulTmp
;
78 NO_DBG_DEC(aulSmallBlockList
[iIndex
]);
81 } /* end of bCreateSmallBlockList */
84 * ulDepotOffset - get the depot offset the block list
87 ulDepotOffset(ULONG ulIndex
, size_t tBlockSize
)
92 fail(ulIndex
>= ULONG_MAX
/ BIG_BLOCK_SIZE
);
96 return (ulIndex
+ 1) * BIG_BLOCK_SIZE
;
97 case SMALL_BLOCK_SIZE
:
98 tTmp
= (size_t)(ulIndex
/ SIZE_RATIO
);
99 ulTmp
= ulIndex
% SIZE_RATIO
;
100 if (aulSmallBlockList
== NULL
||
101 tTmp
>= tSmallBlockListLen
) {
102 DBG_HEX(aulSmallBlockList
);
103 DBG_DEC(tSmallBlockListLen
);
107 return ((aulSmallBlockList
[tTmp
] + 1) * SIZE_RATIO
+
108 ulTmp
) * SMALL_BLOCK_SIZE
;
114 } /* end of ulDepotOffset */