static void _xferentry(Nptr srcNode, int srcEntry, Nptr destNode, int destEntry);
static void _setentry(Nptr node, int entry, keyT key, Nptr downNode);
+/* access key and data values for B+tree methods */
+/* pass values to getSlot(), descend...() */
+static keyT getfunkey(Tree *B);
+static dataT getfundata(Tree *B);
+static void setfunkey(Tree *B, keyT v);
+static void setfundata(Tree *B, dataT v);
+
+
#ifdef DEBUG_BTREE
static int _isRoot(Tree *B, Nptr n)
{
- int flagset = (n->flags & isROOT) == isROOT);
+ int flagset = ((n->flags & isROOT) == isROOT);
if (!isnode(n))
return 0;
static int _isFew(Tree *B, Nptr n)
{
- int flagset = (n->flags & FEWEST) == FEWEST);
+ int flagset = ((n->flags & FEWEST) == FEWEST);
int fanout = getminfanout(B, n);
int entries = numentries(n);
int mincnt = entries <= fanout;
static int _isFull(Tree *B, Nptr n)
{
- int flagset = (n->flags & isFULL) == isFULL);
+ int flagset = ((n->flags & isFULL) == isFULL);
int maxcnt = numentries(n) == getfanout(B);
if (!isnode(n))
/***********************************************************************\
| B+tree Initialization and Cleanup Routines |
\***********************************************************************/
+static DWORD TlsKeyIndex;
+static DWORD TlsDataIndex;
+
+long cm_InitBPlusDir(void)
+{
+ if ((TlsKeyIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)
+ return 0;
+
+ if ((TlsDataIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)
+ return 0;
+
+ return 1;
+}
/******************** Set up B+tree structure **********************/
Tree *initBtree(unsigned int poolsz, unsigned int fanout, KeyCmp keyCmp)
{
Tree *B;
keyT empty = {NULL};
- dataT data = {0,0,0,0};
+ dataT data = {0,0,0,0,0,0,0};
if (fanout > MAX_FANOUT)
fanout = MAX_FANOUT;
}
+/* access key and data values for B+tree methods */
+/* pass values to getSlot(), descend...() */
+static keyT getfunkey(Tree *B) {
+ keyT *tlsKey;
+
+ // Retrieve a data pointer for the current thread.
+ tlsKey = (keyT *) TlsGetValue(TlsKeyIndex);
+ if (tlsKey == NULL) {
+ if (GetLastError() != ERROR_SUCCESS)
+ osi_panic("TlsGetValue failed", __FILE__, __LINE__);
+ else
+ osi_panic("get before set", __FILE__, __LINE__);
+ }
+
+ return *tlsKey;
+}
+
+static dataT getfundata(Tree *B) {
+ dataT *tlsData;
+
+ // Retrieve a data pointer for the current thread.
+ tlsData = (dataT *) TlsGetValue(TlsDataIndex);
+ if (tlsData == NULL) {
+ if (GetLastError() != ERROR_SUCCESS)
+ osi_panic("TlsGetValue failed", __FILE__, __LINE__);
+ else
+ osi_panic("get before set", __FILE__, __LINE__);
+ }
+
+ return *tlsData;
+}
+
+static void setfunkey(Tree *B, keyT theKey) {
+ keyT *tlsKey;
+
+ tlsKey = (keyT *) TlsGetValue(TlsKeyIndex);
+ if (tlsKey == NULL) {
+ if (GetLastError() != ERROR_SUCCESS)
+ osi_panic("TlsGetValue failed", __FILE__, __LINE__);
+
+ tlsKey = malloc(sizeof(keyT));
+
+ if (!TlsSetValue(TlsKeyIndex, tlsKey))
+ osi_panic("TlsSetValue failed", __FILE__, __LINE__);
+ }
+
+ *tlsKey = theKey;
+}
+
+static void setfundata(Tree *B, dataT theData) {
+ dataT *tlsData;
+
+ tlsData = (dataT *) TlsGetValue(TlsDataIndex);
+ if (tlsData == NULL) {
+ if (GetLastError() != ERROR_SUCCESS)
+ osi_panic("TlsGetValue failed", __FILE__, __LINE__);
+
+ tlsData = malloc(sizeof(dataT));
+
+ if (!TlsSetValue(TlsDataIndex, tlsData))
+ osi_panic("TlsSetValue failed", __FILE__, __LINE__);
+ }
+
+ *tlsData = theData;
+}
+
+
/***********************************************************************\
-| Find location for data |
+| Find leaf node in which data nodes can be found |
\***********************************************************************/
/********************** top level lookup **********************/
Nptr bplus_Lookup(Tree *B, keyT key)
{
- Nptr findNode;
+ Nptr leafNode;
#ifdef DEBUG_BTREE
sprintf(B->message, "LOOKUP: key %s.\n", key.name);
#endif
setfunkey(B, key); /* set search key */
- findNode = descendToLeaf(B, getroot(B)); /* start search from root node */
+ leafNode = descendToLeaf(B, getroot(B)); /* start search from root node */
#ifdef DEBUG_BTREE
- if (findNode) {
+ if (leafNode) {
int slot;
Nptr dataNode;
dataT data;
- slot = findKey(B, findNode, 1, numentries(findNode));
- dataNode = getnode(findNode, slot);
+ slot = getSlot(B, leafNode);
+ if (slot <= BTERROR)
+ return NONODE;
+
+ dataNode = getnode(leafNode, slot);
data = getdatavalue(dataNode);
sprintf(B->message, "LOOKUP: %s found on page %d value (%d.%d.%d).\n",
key.name,
- getnodenumber(B, findNode),
- data.volume,
- data.vnode,
- data.unique);
+ getnodenumber(B, leafNode),
+ data.fid.volume,
+ data.fid.vnode,
+ data.fid.unique);
} else
sprintf(B->message, "LOOKUP: not found!\n");
OutputDebugString(B->message);
#endif
- return findNode;
+ return leafNode;
}
/********************** `recurse' down B+tree **********************/
memset(prev, 0, sizeof(prev));
- for (depth = 0, slot = getSlot(B, curr); isinternal(curr); depth++, slot = getSlot(B, curr)) {
+ for (depth = 0, slot = getSlot(B, curr); (slot >= 0) && isinternal(curr); depth++, slot = getSlot(B, curr)) {
prev[depth] = curr;
if (slot == 0)
curr = getfirstnode(curr);
- else
+ else if (slot > 0)
curr = getnode(curr, slot);
+ else /* BTERROR, BTLOWER, BTUPPER */ {
+ curr = NONODE;
+ break;
+ }
#ifdef DEBUG_BTREE
if ( !isnode(curr) )
DebugBreak();
#ifdef DEBUG_BTREE
if (findslot == BTERROR) {
- sprintf(B->message, "Bad key ordering on node %d\n", getnodenumber(B, curr));
- OutputDebugString(B->message);
+ sprintf(B->message, "FINDKEY: (lo %d hi %d) Bad key ordering on node %d (0x%p)\n",
+ lo, hi, getnodenumber(B, curr), curr);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
}
#endif
} else {
mid = (lo + hi) >> 1;
switch (findslot = bestMatch(B, curr, mid)) {
case BTLOWER: /* check lower half of range */
- findslot = findKey(B, curr, lo, mid - 1); /* never in 2-3+trees */
+ if (mid > 1)
+ findslot = findKey(B, curr, lo, mid - 1); /* never in 2-3+trees */
break;
case BTUPPER: /* check upper half of range */
- findslot = findKey(B, curr, mid + 1, hi);
+ if (mid < getfanout(B))
+ findslot = findKey(B, curr, mid + 1, hi);
break;
case BTERROR:
- sprintf(B->message, "Bad key ordering on node %d\n", getnodenumber(B, curr));
- OutputDebugString(B->message);
+ sprintf(B->message, "FINDKEY: (lo %d hi %d) Bad key ordering on node %d (0x%p)\n",
+ lo, hi, getnodenumber(B, curr), curr);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
}
}
+
+ if (isleaf(curr) && findslot == 0)
+ {
+ sprintf(B->message, "FINDKEY: (lo %d hi %d) findslot %d is invalid for leaf nodes, bad key ordering on node %d (0x%p)\n",
+ lo, hi, findslot, getnodenumber(B, curr), curr);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
+ }
return findslot;
}
/************ comparison of key with a target key slot *************/
static int bestMatch(Tree *B, Nptr curr, int slot)
{
- int diff, comp, findslot;
+ int diff, comp=2, findslot;
diff = comparekeys(B)(getfunkey(B), getkey(curr, slot), 0);
- if (diff < 0) { /* also check previous slot */
- if ((slot == 1) ||
- ((comp = comparekeys(B)(getfunkey(B), getkey(curr, slot - 1), 0)) >= 0))
- {
+ if (diff == 0) {
+ findslot = slot;
+ } else if (diff < 0) { /* also check previous slot */
+ if (slot == 1) {
+ if (isleaf(curr))
+ findslot = BTLOWER; /* not found in the tree */
+ else
+ findslot = 0;
+ }
+ else if ((comp = comparekeys(B)(getfunkey(B), getkey(curr, slot - 1), 0)) >= 0) {
findslot = slot - 1;
- }
- else if (comp < diff) {
+ } else if (comp < diff) {
findslot = BTERROR; /* inconsistent ordering of keys */
#ifdef DEBUG_BTREE
DebugBreak();
#endif
- }
- else {
+ } else {
findslot = BTLOWER; /* key must be below in node ordering */
}
} else { /* or check following slot */
- if ((slot == numentries(curr)) ||
- ((comp = comparekeys(B)(getfunkey(B), getkey(curr, slot + 1), 0)) < 0))
- {
+ if (slot == numentries(curr)) {
+ if (isleaf(curr) && numentries(curr) == getfanout(B))
+ findslot = BTUPPER;
+ else
+ findslot = slot;
+ } else if ((comp = comparekeys(B)(getfunkey(B), getkey(curr, slot + 1), 0)) < 0) {
findslot = slot;
- }
- else if (comp == 0) {
+ } else if (comp == 0) {
findslot = slot + 1;
- }
- else if (comp > diff) {
+ } else if (comp > diff) {
findslot = BTERROR; /* inconsistent ordering of keys */
#ifdef DEBUG_BTREE
DebugBreak();
#endif
- }
- else {
+ } else {
findslot = BTUPPER; /* key must be above in node ordering */
}
}
+
+ if (findslot == BTERROR || isleaf(curr) && findslot == 0)
+ {
+ sprintf(B->message, "BESTMATCH: node %d (0x%p) slot %d diff %d comp %d findslot %d\n",
+ getnodenumber(B, curr), curr, slot, diff, comp, findslot);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
+ }
return findslot;
}
#ifdef DEBUG_BTREE
sprintf(B->message, "INSERT: key %s.\n", key.name);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#endif
setfunkey(B, key); /* set insertion key */
setsplitpath(B, curr); /* indicates where nodes must split */
slot = getSlot(B, curr); /* is null only if the root is empty */
+ if (slot == BTERROR)
+ return NONODE;
+
+ if (isleaf(curr)) {
+ if (slot == BTLOWER)
+ slot = 0;
+ else if (slot == BTUPPER)
+ slot = getfanout(B);
+ }
+
if (isinternal(curr)) { /* continue recursion to leaves */
if (slot == 0)
downNode = descendSplit(B, getfirstnode(curr));
#ifdef DEBUG_BTREE
sprintf(B->message, "INSERT: slot %d, down node %d.\n", slot, getnodenumber(B, downPtr));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#endif
if (sibling == NONODE) { /* no split occurred */
clrentry(currNode, x);
decentries(currNode);
incentries(sibling);
+
+#ifdef DEBUG_BTREE
+ if (getkey(sibling, numentries(sibling)).name == NULL)
+ DebugBreak();
+#endif
}
clrflag(currNode, isFULL);
if (numentries(currNode) == getminfanout(B, currNode))
DebugBreak();
#endif
- for (x = numentries(node); x >= slot; x--) /* make room for new entry */
+#ifdef DEBUG_BTREE
+ if (numentries(node) != 0 && getkey(node, numentries(node)).name == NULL)
+ DebugBreak();
+#endif
+ for (x = numentries(node); x >= slot && x != 0; x--) /* make room for new entry */
pushentry(node, x, 1);
setentry(node, slot, getfunkey(B), downPtr);/* place it in correct slot */
incentries(node); /* adjust entry counter */
+#ifdef DEBUG_BTREE
+ if (getkey(node, numentries(node)).name == NULL)
+ DebugBreak();
+#endif
+
if (numentries(node) == getfanout(B))
setflag(node, isFULL);
if (numentries(node) > getminfanout(B, node))
#ifdef DEBUG_BTREE
sprintf(B->message, "DELETE: key %s.\n", key.name);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#endif
setfunkey(B, key); /* set deletion key */
if (isnode(newNode)) {
#ifdef DEBUG_BTREE
sprintf(B->message, "DELETE: collapsing node %d", getnodenumber(B, newNode));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#endif
collapseRoot(B, getroot(B), newNode); /* remove root when superfluous */
}
#ifdef DEBUG_BTREE
sprintf(B->message, "COLLAPSE: old %d, new %d.\n", getnodenumber(B, oldRoot), getnodenumber(B, newRoot));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
showNode(B, "collapseRoot oldRoot", oldRoot);
showNode(B, "collapseRoot newRoot", newRoot);
#endif
lAnc ? getnodenumber(B, lAnc) : -1,
rAnc ? getnodenumber(B, rAnc) : -1,
parent ? getnodenumber(B, parent) : -1);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#endif
if (!isfew(curr))
setmergepath(B, curr); /* mark which nodes may need rebalancing */
slot = getSlot(B, curr);
+ if (slot == BTERROR)
+ return NONODE;
+
+ if (isleaf(curr)) {
+ if (slot == BTLOWER)
+ slot = 0;
+ else if (slot == BTUPPER)
+ slot = getfanout(B);
+ }
if (isinternal(curr)) /* set up next recursion call's parameters */
{
* options. So we must determine if any of the next nodes
* are the one we are looking for.
*/
- Nptr dataNode = newNode;
+ Nptr prev = newNode;
while ( next ) {
if (!comparekeys(B)(getfunkey(B), getdatakey(next), EXACT_MATCH)) {
/* we found the one to delete */
- getdatanext(dataNode) = getdatanext(next);
+ getdatanext(prev) = getdatanext(next);
putFreeNode(B, next);
+ break;
}
+ prev = next;
+ next = getdatanext(next);
}
/* do not delete the key */
if (newMe != NONODE) { /* this node removal doesn't consider duplicates */
#ifdef DEBUG_BTREE
sprintf(B->message, "descendBalance DELETE: slot %d, node %d.\n", slot, getnodenumber(B, curr));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#endif
removeEntry(B, curr, slot + (newMe != newNode)); /* removes one of two */
#ifdef DEBUG_BTREE
sprintf(B->message, "descendBalance returns %d\n", getnodenumber(B, newNode));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#endif
return newNode;
}
#ifdef DEBUG_BTREE
sprintf(B->message, "MERGE: left %d, right %d.\n", getnodenumber(B, left), getnodenumber(B, right));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
showNode(B, "pre-merge anchor", anchor);
showNode(B, "pre-merge left", left);
showNode(B, "pre-merge right", right);
#endif
setfunkey(B, getkey(right, 1)); /* defined but maybe just deleted */
z = getSlot(B, anchor); /* needs the just calculated key */
+ if (z <= BTERROR)
+ return NONODE;
setfunkey(B, getkey(anchor, z)); /* set slot to delete in anchor */
setentry(left, numentries(left), getfunkey(B), getfirstnode(right));
}
getnodenumber(B, left),
getnodenumber(B, right),
getnodenumber(B, anchor));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
showNode(B, "pre-shift anchor", anchor);
showNode(B, "pre-shift left", left);
showNode(B, "pre-shift right", right);
x = numentries(left) + y;
setfunkey(B, getkey(right, y + 1 - i)); /* set new anchor key value */
z = getSlot(B, anchor); /* find slot in anchor node */
+ if (z <= BTERROR)
+ return NONODE;
#ifdef DEBUG_BTREE
if (z == 0 && !isroot(anchor))
DebugBreak();
pushentry(right, z, y);
setfunkey(B, getkey(left, x)); /* set new anchor key value */
- z = getSlot(B, anchor) + 1;
+ z = getSlot(B, anchor);
+ if (z <= BTERROR)
+ return NONODE;
+ z += 1;
+
if (i) {
decentries(left);
incentries(right);
#ifdef DEBUG_BTREE
sprintf(B->message, "SHIFT: left %d, right %d.\n", getnodenumber(B, left), getnodenumber(B, right));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
showNode(B, "post-shift anchor", anchor);
showNode(B, "post-shift left", left);
showNode(B, "post-shift right", right);
{
if (getkey(node,entry + offset).name != NULL)
free(getkey(node,entry + offset).name);
+#ifdef DEBUG_BTREE
+ if (entry == 0)
+ DebugBreak();
+#endif
getkey(node,entry + offset).name = strdup(getkey(node,entry).name);
#ifdef DEBUG_BTREE
if ( getnode(node, entry) == NONODE )
for ( i=0, node = getfirstallnode(B); node != NONODE && i<getpoolsize(B); node = next, i++ ) {
if (isdata(node)) {
- if ( getdatakey(node).name )
+ if ( getdatakey(node).name ) {
free(getdatakey(node).name);
+ getdatakey(node).name = NULL;
+ }
+ if ( getdatavalue(node).longname ) {
+ free(getdatavalue(node).longname);
+ getdatavalue(node).longname = NULL;
+ }
+ if ( getdatavalue(node).origname ) {
+ free(getdatavalue(node).origname);
+ getdatavalue(node).origname = NULL;
+ }
} else { /* data node */
for ( j=1; j<=getfanout(B); j++ ) {
if (getkey(node, j).name)
if (isdata(node)) {
if ( getdatakey(node).name )
free(getdatakey(node).name);
+ if ( getdatavalue(node).longname )
+ free(getdatavalue(node).longname);
} else { /* data node */
for ( i=1; i<=getfanout(B); i++ ) {
if (getkey(node, i).name)
int x;
sprintf(B->message, "- -- -- -- -- -- -- -- -- -- -- -- -\n");
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| %-20s |\n", where);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| node %6d ", getnodenumber(B, n));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, " magic %4x |\n", getmagic(n));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "- -- -- -- -- -- -- -- -- -- -- -- -\n");
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| flags %1d%1d%1d%1d ", isfew(n), isfull(n), isroot(n), isleaf(n));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| keys = %5d ", numentries(n));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| node = %6d |\n", getnodenumber(B, getfirstnode(n)));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
for (x = 1; x <= numentries(n); x++) {
sprintf(B->message, "| entry %6d ", x);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| key = %6s ", getkey(n, x).name);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| node = %6d |\n", getnodenumber(B, getnode(n, x)));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
}
sprintf(B->message, "- -- -- -- -- -- -- -- -- -- -- -- -\n");
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
}
/****************** B+tree class variable printer ******************/
void showBtree(Tree *B)
{
sprintf(B->message, "- -- -- -- -- -- -\n");
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| B+tree %10p |\n", (void *) B);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "- -- -- -- -- -- -\n");
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| root %6d |\n", getnodenumber(B, getroot(B)));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| leaf %6d |\n", getnodenumber(B, getleaf(B)));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| fanout %3d |\n", getfanout(B) + 1);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| minfanout %3d |\n", getminfanout(B, getroot(B)) + 1);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| height %3d |\n", gettreeheight(B));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| freenode %6d |\n", getnodenumber(B, getfirstfreenode(B)));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| theKey %6s |\n", getfunkey(B).name);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "| theData %d.%d.%d |\n", getfundata(B).volume,
getfundata(B).vnode, getfundata(B).unique);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
sprintf(B->message, "- -- -- -- -- -- -\n");
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
}
void
if (isntnode(node)) {
sprintf(B->message, "%s - NoNode!!!\n");
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
return;
}
data = getdatavalue(node);
sprintf(B->message, "%s - data node %d (%d.%d.%d)\n",
parent_desc, getnodenumber(B, node),
- data.volume, data.vnode, data.unique);
- OutputDebugString(B->message);
+ data.fid.volume, data.fid.vnode, data.fid.unique);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
return;
} else
showNode(B, parent_desc, node);
if ( isinternal(node) || isroot(node) ) {
sprintf(thisnode, "parent %6d", getnodenumber(B , node));
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
for ( i= isinternal(node) ? 0 : 1; i <= numentries(node); i++ ) {
listBtreeNodes(B, thisnode, i == 0 ? getfirstnode(node) : getnode(node, i));
}
for (slot = 1; (n != NONODE) && num && numentries(n); num--) {
if (comparekeys(B)(getkey(n, slot),prev, 0) < 0) {
sprintf(B->message, "BOMB %8s\n", getkey(n, slot).name);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
DebugBreak();
}
prev = getkey(n, slot);
data = getdatavalue(getnode(n, slot));
sprintf(B->message, "%8s (%d.%d.%d)\n",
- prev.name, data.volume, data.vnode, data.unique);
- OutputDebugString(B->message);
+ prev.name, data.fid.volume, data.fid.vnode, data.fid.unique);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
if (++slot > numentries(n))
n = getnextnode(n), slot = 1;
}
sprintf(B->message, "\n\n");
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
}
/******************** entire B+tree data printer *******************/
for (slot = 1; (n != NONODE) && num && numentries(n); num--) {
if (comparekeys(B)(getkey(n, slot),prev, 0) < 0) {
sprintf(B->message,"BOMB %8s\n", getkey(n, slot).name);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#ifdef DEBUG_BTREE
DebugBreak();
#endif
sprintf(B->message,"BOMB %8s cannot be found\n", prev.name);
else
sprintf(B->message,"BOMB lookup(%8s) finds wrong node\n", prev.name);
- OutputDebugString(B->message);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, B->message));
#ifdef DEBUG_BTREE
DebugBreak();
#endif
}
}
+/*
+ * the return must be -1, 0, or 1. stricmp() in MSVC 8.0
+ * does not return only those values.
+ *
+ * the sorting of the tree is by case insensitive sort order
+ * therefore, unless the strings actually match via a case
+ * insensitive search do we want to perform the case sensitive
+ * match. Otherwise, the search order might be considered
+ * to be inconsistent when the EXACT_MATCH flag is set.
+ */
static int
compareKeys(keyT key1, keyT key2, int flags)
{
- if (flags & EXACT_MATCH)
- return strcmp(key1.name, key2.name);
- else
- return stricmp(key1.name, key2.name);
+ int comp;
+
+ comp = cm_stricmp_utf8(key1.name, key2.name);
+ if (comp == 0 && (flags & EXACT_MATCH))
+ comp = strcmp(key1.name, key2.name);
+ return (comp < 0 ? -1 : (comp > 0 ? 1 : 0));
+}
+
+int
+cm_BPlusDirLookupOriginalName(cm_dirOp_t * op, char * entry,
+ char ** originalNameRetp)
+{
+ int rc = EINVAL;
+ keyT key = {entry};
+ Nptr leafNode = NONODE;
+ LARGE_INTEGER start, end;
+ char * originalName = NULL;
+
+ if (op->scp->dirBplus == NULL ||
+ op->dataVersion != op->scp->dirDataVersion) {
+ rc = EINVAL;
+ goto done;
+ }
+
+ lock_AssertAny(&op->scp->dirlock);
+
+ QueryPerformanceCounter(&start);
+
+ leafNode = bplus_Lookup(op->scp->dirBplus, key);
+ if (leafNode != NONODE) {
+ int slot;
+ Nptr firstDataNode, dataNode, nextDataNode;
+ int exact = 0;
+ int count = 0;
+
+ /* Found a leaf that matches the key via a case-insensitive
+ * match. There may be one or more data nodes that match.
+ * If we have an exact match, return that.
+ * If we have an ambiguous match, return an error.
+ * If we have only one inexact match, return that.
+ */
+ slot = getSlot(op->scp->dirBplus, leafNode);
+ if (slot <= BTERROR) {
+ op->scp->dirDataVersion = 0;
+ rc = (slot == BTERROR ? EINVAL : ENOENT);
+ goto done;
+ }
+ firstDataNode = getnode(leafNode, slot);
+
+ for ( dataNode = firstDataNode; dataNode; dataNode = nextDataNode) {
+ count++;
+ if (!comparekeys(op->scp->dirBplus)(key, getdatakey(dataNode), EXACT_MATCH) ) {
+ exact = 1;
+ break;
+ }
+ nextDataNode = getdatanext(dataNode);
+ }
+
+ if (exact) {
+ originalName = getdatavalue(dataNode).origname;
+ rc = 0;
+ bplus_lookup_hits++;
+ } else if (count == 1) {
+ originalName = getdatavalue(firstDataNode).origname;
+ rc = CM_ERROR_INEXACT_MATCH;
+ bplus_lookup_hits_inexact++;
+ } else {
+ rc = CM_ERROR_AMBIGUOUS_FILENAME;
+ bplus_lookup_ambiguous++;
+ }
+ } else {
+ rc = ENOENT;
+ bplus_lookup_misses++;
+ }
+
+ if (originalName)
+ *originalNameRetp = strdup(originalName);
+
+ QueryPerformanceCounter(&end);
+
+ bplus_lookup_time += (end.QuadPart - start.QuadPart);
+
+ done:
+ return rc;
+
}
/* Look up a file name in directory.
goto done;
}
+ lock_AssertAny(&op->scp->dirlock);
+
QueryPerformanceCounter(&start);
leafNode = bplus_Lookup(op->scp->dirBplus, key);
* If we have an ambiguous match, return an error.
* If we have only one inexact match, return that.
*/
- slot = findKey(op->scp->dirBplus, leafNode, 1, numentries(leafNode));
+ slot = getSlot(op->scp->dirBplus, leafNode);
+ if (slot <= BTERROR) {
+ op->scp->dirDataVersion = 0;
+ rc = (slot == BTERROR ? EINVAL : ENOENT);
+ goto done;
+ }
firstDataNode = getnode(leafNode, slot);
for ( dataNode = firstDataNode; dataNode; dataNode = nextDataNode) {
}
if (exact) {
- *cfid = getdatavalue(dataNode);
+ *cfid = getdatavalue(dataNode).fid;
rc = 0;
bplus_lookup_hits++;
} else if (count == 1) {
- *cfid = getdatavalue(firstDataNode);
+ *cfid = getdatavalue(firstDataNode).fid;
rc = CM_ERROR_INEXACT_MATCH;
bplus_lookup_hits_inexact++;
} else {
- rc = CM_ERROR_AMBIGUOUS_FILENAME;
+ rc = CM_ERROR_AMBIGUOUS_FILENAME;
bplus_lookup_ambiguous++;
}
} else {
{
long rc = 0;
keyT key = {entry};
+ dataT data;
LARGE_INTEGER start, end;
+ char shortName[13];
if (op->scp->dirBplus == NULL ||
op->dataVersion != op->scp->dirDataVersion) {
goto done;
}
+
+ lock_AssertWrite(&op->scp->dirlock);
+
+ cm_SetFid(&data.fid, cfid->cell, cfid->volume, cfid->vnode, cfid->unique);
+ data.longname = NULL;
+ data.origname = NULL;
+
QueryPerformanceCounter(&start);
bplus_create_entry++;
- insert(op->scp->dirBplus, key, *cfid);
+ insert(op->scp->dirBplus, key, data);
+ if (!cm_Is8Dot3(entry)) {
+ cm_dirFid_t dfid;
+ dfid.vnode = htonl(data.fid.vnode);
+ dfid.unique = htonl(data.fid.unique);
+
+ cm_Gen8Dot3NameInt(entry, &dfid, shortName, NULL);
+
+ key.name = shortName;
+ data.longname = strdup(entry);
+ insert(op->scp->dirBplus, key, data);
+ }
QueryPerformanceCounter(&end);
{
long rc = 0;
keyT key = {entry};
+ Nptr leafNode = NONODE;
LARGE_INTEGER start, end;
if (op->scp->dirBplus == NULL ||
goto done;
}
+ lock_AssertWrite(&op->scp->dirlock);
+
QueryPerformanceCounter(&start);
bplus_remove_entry++;
if (op->scp->dirBplus) {
- delete(op->scp->dirBplus, key);
+ if (!cm_Is8Dot3(entry)) {
+ cm_dirFid_t dfid;
+ cm_fid_t fid;
+ char shortName[13];
+
+ leafNode = bplus_Lookup(op->scp->dirBplus, key);
+ if (leafNode != NONODE) {
+ int slot;
+ Nptr firstDataNode, dataNode, nextDataNode;
+ int exact = 0;
+ int count = 0;
+
+ /* Found a leaf that matches the key via a case-insensitive
+ * match. There may be one or more data nodes that match.
+ * If we have an exact match, return that.
+ * If we have an ambiguous match, return an error.
+ * If we have only one inexact match, return that.
+ */
+ slot = getSlot(op->scp->dirBplus, leafNode);
+ if (slot <= BTERROR) {
+ op->scp->dirDataVersion = 0;
+ rc = EINVAL;
+ goto done;
+ }
+ firstDataNode = getnode(leafNode, slot);
+
+ for ( dataNode = firstDataNode; dataNode; dataNode = nextDataNode) {
+ count++;
+ if (!comparekeys(op->scp->dirBplus)(key, getdatakey(dataNode), EXACT_MATCH) ) {
+ exact = 1;
+ break;
+ }
+ nextDataNode = getdatanext(dataNode);
+ }
+
+ if (exact) {
+ fid = getdatavalue(dataNode).fid;
+ rc = 0;
+ } else if (count == 1) {
+ fid = getdatavalue(firstDataNode).fid;
+ rc = CM_ERROR_INEXACT_MATCH;
+ } else {
+ rc = CM_ERROR_AMBIGUOUS_FILENAME;
+ }
+ }
+
+
+ if (rc != CM_ERROR_AMBIGUOUS_FILENAME) {
+ dfid.vnode = htonl(fid.vnode);
+ dfid.unique = htonl(fid.unique);
+ cm_Gen8Dot3NameInt(entry, &dfid, shortName, NULL);
+
+ /* delete first the long name and then the short name */
+ delete(op->scp->dirBplus, key);
+ key.name = shortName;
+ delete(op->scp->dirBplus, key);
+ }
+ } else {
+ char * longname = NULL;
+ /* We need to lookup the 8dot3 name to determine what the
+ * matching long name is
+ */
+ leafNode = bplus_Lookup(op->scp->dirBplus, key);
+ if (leafNode != NONODE) {
+ int slot;
+ Nptr firstDataNode, dataNode, nextDataNode;
+ int exact = 0;
+ int count = 0;
+
+ /* Found a leaf that matches the key via a case-insensitive
+ * match. There may be one or more data nodes that match.
+ * If we have an exact match, return that.
+ * If we have an ambiguous match, return an error.
+ * If we have only one inexact match, return that.
+ */
+ slot = getSlot(op->scp->dirBplus, leafNode);
+ if (slot <= BTERROR) {
+ op->scp->dirDataVersion = 0;
+ rc = EINVAL;
+ goto done;
+
+ }
+ firstDataNode = getnode(leafNode, slot);
+
+ for ( dataNode = firstDataNode; dataNode; dataNode = nextDataNode) {
+ count++;
+ if (!comparekeys(op->scp->dirBplus)(key, getdatakey(dataNode), EXACT_MATCH) ) {
+ exact = 1;
+ break;
+ }
+ nextDataNode = getdatanext(dataNode);
+ }
+
+ if (exact) {
+ longname = getdatavalue(dataNode).longname;
+ rc = 0;
+ } else if (count == 1) {
+ longname = getdatavalue(firstDataNode).longname;
+ rc = CM_ERROR_INEXACT_MATCH;
+ } else {
+ rc = CM_ERROR_AMBIGUOUS_FILENAME;
+ }
+ }
+
+ if (rc != CM_ERROR_AMBIGUOUS_FILENAME) {
+ if (longname) {
+ key.name = longname;
+ delete(op->scp->dirBplus, key);
+ key.name = entry;
+ }
+ delete(op->scp->dirBplus, key);
+ }
+ }
}
QueryPerformanceCounter(&end);
void *dummy, osi_hyper_t *entryOffsetp)
{
keyT key = {dep->name};
- dataT data = {scp->fid.cell, scp->fid.volume, ntohl(dep->fid.vnode), ntohl(dep->fid.unique)};
+ dataT data;
+ char shortName[13];
+ long normalized_len;
+ char *normalized_name=NULL;
+ cm_SetFid(&data.fid, scp->fid.cell, scp->fid.volume, ntohl(dep->fid.vnode), ntohl(dep->fid.unique));
+ data.longname = NULL;
+ data.origname = NULL;
+
+ normalized_len = cm_NormalizeUtf8String(dep->name, -1, NULL, 0);
+ if (normalized_len)
+ normalized_name = malloc(normalized_len);
+ if (normalized_name) {
+ cm_NormalizeUtf8String(dep->name, -1, normalized_name, normalized_len);
+ key.name = normalized_name;
+ if (strcmp(normalized_name, dep->name))
+ data.origname = strdup(dep->name);
+ } else {
+ key.name = dep->name;
+ }
/* the Write lock is held in cm_BPlusDirBuildTree() */
insert(scp->dirBplus, key, data);
+ if (!cm_Is8Dot3(dep->name)) {
+ cm_dirFid_t dfid;
+ dfid.vnode = dep->fid.vnode;
+ dfid.unique = dep->fid.unique;
+
+ cm_Gen8Dot3NameInt(dep->name, &dfid, shortName, NULL);
+
+ data.longname = strdup(key.name);
+ data.origname = NULL;
+ key.name = shortName;
+ insert(scp->dirBplus, key, data);
+ }
+
+ if (normalized_name)
+ free(normalized_name);
+#ifdef BTREE_DEBUG
+ findAllBtreeValues(scp->dirBplus);
+#endif
return 0;
}
osi_hyper_t thyper;
LARGE_INTEGER start, end;
- osi_assert(scp->dirBplus == NULL);
+ osi_assertx(scp->dirBplus == NULL, "cm_BPlusDirBuildTree called on non-empty tree");
+
+ lock_AssertWrite(&scp->dirlock);
QueryPerformanceCounter(&start);
bplus_build_tree++;
bplus_build_time += (end.QuadPart - start.QuadPart);
+#if 0
+ cm_BPlusDirEnumTest(scp, 1);
+#endif
return rc;
}
+int cm_MemDumpBPlusStats(FILE *outputFile, char *cookie, int lock)
+{
+ int zilch;
+ char output[128];
+
+ sprintf(output, "%s - B+ Lookup Hits: %-8d\r\n", cookie, bplus_lookup_hits);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Inexact Hits: %-8d\r\n", cookie, bplus_lookup_hits_inexact);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Ambiguous Hits: %-8d\r\n", cookie, bplus_lookup_ambiguous);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Misses: %-8d\r\n", cookie, bplus_lookup_misses);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Create: %-8d\r\n", cookie, bplus_create_entry);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Remove: %-8d\r\n", cookie, bplus_remove_entry);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Build Tree: %-8d\r\n", cookie, bplus_build_tree);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Free Tree: %-8d\r\n", cookie, bplus_free_tree);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - DV Error: %-8d\r\n", cookie, bplus_dv_error);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+
+ sprintf(output, "%s - B+ Time Lookup: %-16I64d\r\n", cookie, bplus_lookup_time);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Create: %-16I64d\r\n", cookie, bplus_create_time);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Remove: %-16I64d\r\n", cookie, bplus_remove_time);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Build: %-16I64d\r\n", cookie, bplus_build_time);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+ sprintf(output, "%s - Free: %-16I64d\r\n", cookie, bplus_free_time);
+ WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
+
+ return(0);
+}
+
void cm_BPlusDumpStats(void)
{
afsi_log("B+ Lookup Hits: %-8d", bplus_lookup_hits);
afsi_log(" Build: %-16I64d", bplus_build_time);
afsi_log(" Free: %-16I64d", bplus_free_time);
}
+
+static cm_direnum_t *
+cm_BPlusEnumAlloc(afs_uint32 entries)
+{
+ cm_direnum_t * enump;
+ size_t size;
+
+ if (entries == 0)
+ return NULL;
+
+ size = sizeof(cm_direnum_t)+(entries-1)*sizeof(cm_direnum_entry_t);
+ enump = (cm_direnum_t *)malloc(size);
+ memset(enump, 0, size);
+ enump->count = entries;
+ return enump;
+}
+
+long
+cm_BPlusDirEnumerate(cm_scache_t *scp, afs_uint32 locked,
+ char * maskp, cm_direnum_t **enumpp)
+{
+ afs_uint32 count = 0, slot, numentries;
+ Nptr leafNode = NONODE, nextLeafNode;
+ Nptr firstDataNode, dataNode, nextDataNode;
+ cm_direnum_t * enump;
+ long rc = 0;
+ char buffer[512];
+
+ osi_Log0(afsd_logp, "cm_BPlusDirEnumerate start");
+
+ /* Read lock the bplus tree so the data can't change */
+ if (!locked)
+ lock_ObtainRead(&scp->dirlock);
+
+ if (scp->dirBplus == NULL) {
+ osi_Log0(afsd_logp, "cm_BPlusDirEnumerate No BPlus Tree");
+ goto done;
+ }
+
+ /* Compute the number of entries */
+ for (count = 0, leafNode = getleaf(scp->dirBplus); leafNode; leafNode = nextLeafNode) {
+
+ for ( slot = 1, numentries = numentries(leafNode); slot <= numentries; slot++) {
+ firstDataNode = getnode(leafNode, slot);
+
+ for ( dataNode = firstDataNode; dataNode; dataNode = nextDataNode) {
+ if (maskp == NULL) {
+ /* name is in getdatakey(dataNode) */
+ if (getdatavalue(dataNode).longname != NULL ||
+ cm_Is8Dot3(getdatakey(dataNode).name))
+ count++;
+ } else {
+ if (cm_Is8Dot3(getdatakey(dataNode).name) &&
+ smb_V3MatchMask(getdatakey(dataNode).name, maskp, CM_FLAG_CASEFOLD) ||
+ getdatavalue(dataNode).longname == NULL &&
+ smb_V3MatchMask(getdatavalue(dataNode).longname, maskp, CM_FLAG_CASEFOLD))
+ count++;
+ }
+ nextDataNode = getdatanext(dataNode);
+ }
+ }
+
+ nextLeafNode = getnextnode(leafNode);
+ }
+
+ sprintf(buffer, "BPlusTreeEnumerate count = %d", count);
+ osi_Log1(afsd_logp, "BPlus: %s", osi_LogSaveString(afsd_logp, buffer));
+
+ /* Allocate the enumeration object */
+ enump = cm_BPlusEnumAlloc(count);
+ if (enump == NULL) {
+ osi_Log0(afsd_logp, "cm_BPlusDirEnumerate Alloc failed");
+ rc = ENOMEM;
+ goto done;
+ }
+
+ /* Copy the name and fid for each longname entry into the enumeration */
+ for (count = 0, leafNode = getleaf(scp->dirBplus); leafNode; leafNode = nextLeafNode) {
+
+ for ( slot = 1, numentries = numentries(leafNode); slot <= numentries; slot++) {
+ firstDataNode = getnode(leafNode, slot);
+
+ for ( dataNode = firstDataNode; dataNode; dataNode = nextDataNode) {
+ char * name;
+ int hasShortName;
+ int includeIt = 0;
+
+ if (maskp == NULL) {
+ if (getdatavalue(dataNode).longname != NULL ||
+ cm_Is8Dot3(getdatakey(dataNode).name))
+ {
+ includeIt = 1;
+ }
+ } else {
+ if (cm_Is8Dot3(getdatakey(dataNode).name) &&
+ smb_V3MatchMask(getdatakey(dataNode).name, maskp, CM_FLAG_CASEFOLD) ||
+ getdatavalue(dataNode).longname == NULL &&
+ smb_V3MatchMask(getdatavalue(dataNode).longname, maskp, CM_FLAG_CASEFOLD))
+ {
+ includeIt = 1;
+ }
+ }
+
+ if (includeIt) {
+ if (getdatavalue(dataNode).longname) {
+ name = strdup(getdatavalue(dataNode).longname);
+ hasShortName = 1;
+ } else {
+ name = strdup(getdatakey(dataNode).name);
+ hasShortName = 0;
+ }
+
+ if (name == NULL) {
+ osi_Log0(afsd_logp, "cm_BPlusDirEnumerate strdup failed");
+ rc = ENOMEM;
+ goto done;
+ }
+ enump->entry[count].name = name;
+ enump->entry[count].fid = getdatavalue(dataNode).fid;
+ if (hasShortName)
+ strncpy(enump->entry[count].shortName, getdatakey(dataNode).name,
+ sizeof(enump->entry[count].shortName));
+ else
+ enump->entry[count].shortName[0] = '\0';
+ count++;
+ }
+ nextDataNode = getdatanext(dataNode);
+ }
+ }
+
+ nextLeafNode = getnextnode(leafNode);
+ }
+
+ done:
+ if (!locked)
+ lock_ReleaseRead(&scp->dirlock);
+
+ /* if we failed, cleanup any mess */
+ if (rc != 0) {
+ osi_Log0(afsd_logp, "cm_BPlusDirEnumerate rc != 0");
+ if (enump) {
+ for ( count = 0; count < enump->count && enump->entry[count].name; count++ ) {
+ free(enump->entry[count].name);
+ }
+ free(enump);
+ enump = NULL;
+ }
+ }
+
+ osi_Log0(afsd_logp, "cm_BPlusDirEnumerate end");
+ *enumpp = enump;
+ return rc;
+}
+
+long
+cm_BPlusDirNextEnumEntry(cm_direnum_t *enump, cm_direnum_entry_t **entrypp)
+{
+ if (enump == NULL || entrypp == NULL || enump->next > enump->count) {
+ if (entrypp)
+ *entrypp = NULL;
+ osi_Log0(afsd_logp, "cm_BPlusDirNextEnumEntry invalid input");
+ return CM_ERROR_INVAL; \
+ }
+
+ *entrypp = &enump->entry[enump->next++];
+ if ( enump->next == enump->count ) {
+ osi_Log0(afsd_logp, "cm_BPlusDirNextEnumEntry STOPNOW");
+ return CM_ERROR_STOPNOW;
+ }
+ else {
+ osi_Log0(afsd_logp, "cm_BPlusDirNextEnumEntry SUCCESS");
+ return 0;
+ }
+}
+
+long
+cm_BPlusDirFreeEnumeration(cm_direnum_t *enump)
+{
+ afs_uint32 count;
+
+ osi_Log0(afsd_logp, "cm_BPlusDirFreeEnumeration");
+
+ if (enump) {
+ for ( count = 0; count < enump->count && enump->entry[count].name; count++ ) {
+ free(enump->entry[count].name);
+ }
+ free(enump);
+ }
+ return 0;
+}
+
+long
+cm_BPlusDirEnumTest(cm_scache_t * dscp, afs_uint32 locked)
+{
+ cm_direnum_t * enump = NULL;
+ cm_direnum_entry_t * entryp;
+ long code;
+
+ osi_Log0(afsd_logp, "cm_BPlusDirEnumTest start");
+
+ for (code = cm_BPlusDirEnumerate(dscp, locked, NULL, &enump); code == 0; ) {
+ code = cm_BPlusDirNextEnumEntry(enump, &entryp);
+ if (code == 0 || code == CM_ERROR_STOPNOW) {
+ char buffer[1024];
+ cm_scache_t *scp;
+ char * type = "ScpNotFound";
+ afs_uint64 dv = -1;
+
+ scp = cm_FindSCache(&entryp->fid);
+ if (scp) {
+ switch (scp->fileType) {
+ case CM_SCACHETYPE_FILE :
+ type = "File";
+ break;
+ case CM_SCACHETYPE_DIRECTORY :
+ type = "Directory";
+ break;
+ case CM_SCACHETYPE_SYMLINK :
+ type = "Symlink";
+ break;
+ case CM_SCACHETYPE_MOUNTPOINT:
+ type = "MountPoint";
+ break;
+ case CM_SCACHETYPE_DFSLINK :
+ type = "Dfs";
+ break;
+ case CM_SCACHETYPE_INVALID :
+ type = "Invalid";
+ break;
+ default:
+ type = "Unknown";
+ break;
+ }
+
+ dv = scp->dataVersion;
+ cm_ReleaseSCache(scp);
+ }
+
+ sprintf(buffer, "'%s' Fid = (%d,%d,%d,%d) Short = '%s' Type %s DV %I64d",
+ entryp->name,
+ entryp->fid.cell, entryp->fid.volume, entryp->fid.vnode, entryp->fid.unique,
+ entryp->shortName,
+ type,
+ dv);
+
+ osi_Log0(afsd_logp, osi_LogSaveString(afsd_logp, buffer));
+ }
+ }
+
+ if (enump)
+ cm_BPlusDirFreeEnumeration(enump);
+
+ osi_Log0(afsd_logp, "cm_BPlusDirEnumTest end");
+
+ return 0;
+}
#endif /* USE_BPLUS */