From 5e8bfcb42cbb3652238fec2dbe1c1d65bc2c1ccd Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Fri, 12 Apr 2013 01:09:13 -0400 Subject: [PATCH] Windows: cm_BPlusDirIsEmpty Provide a function to determine if a directory is empty or not. Change-Id: Ib1fa642b02ad67ffdba73da1b7c6091a799de0c3 Reviewed-on: http://gerrit.openafs.org/9777 Tested-by: BuildBot Reviewed-by: Jeffrey Altman --- src/WINNT/afsd/cm_btree.c | 51 +++++++++++++++++++++++++++++++++++++++ src/WINNT/afsd/cm_btree.h | 1 + 2 files changed, 52 insertions(+) diff --git a/src/WINNT/afsd/cm_btree.c b/src/WINNT/afsd/cm_btree.c index 48e1027b0..82cd9d378 100644 --- a/src/WINNT/afsd/cm_btree.c +++ b/src/WINNT/afsd/cm_btree.c @@ -1997,6 +1997,57 @@ int cm_BPlusDirDeleteEntry(cm_dirOp_t * op, clientchar_t *centry) } +/* + On entry: + op->scp->dirlock is read locked + + On exit: + op->scp->dirlock is read locked + + Return: + +*/ +int cm_BPlusDirIsEmpty(cm_dirOp_t *op, afs_uint32 *pbEmpty) +{ + int rc = 0; + afs_uint32 count = 0, slot, numentries; + Nptr leafNode = NONODE, nextLeafNode; + Nptr firstDataNode, dataNode, nextDataNode; + + if (op->scp->dirBplus == NULL || + op->dataVersion != op->scp->dirDataVersion) { + rc = EINVAL; + goto done; + } + + /* If we find any entry that is not "." or "..", the directory is not empty */ + + for (count = 0, leafNode = getleaf(op->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 ( cm_ClientStrCmp(getdatavalue(dataNode).cname, L".") && + cm_ClientStrCmp(getdatavalue(dataNode).cname, L"..")) + { + + *pbEmpty = 0; + goto done; + } + + nextDataNode = getdatanext(dataNode); + } + } + nextLeafNode = getnextnode(leafNode); + } + + *pbEmpty = 1; + + done: + return rc; +} int cm_BPlusDirFoo(struct cm_scache *scp, struct cm_dirEntry *dep, void *dummy, osi_hyper_t *entryOffsetp) diff --git a/src/WINNT/afsd/cm_btree.h b/src/WINNT/afsd/cm_btree.h index 9a61da6c2..358bcfb49 100644 --- a/src/WINNT/afsd/cm_btree.h +++ b/src/WINNT/afsd/cm_btree.h @@ -151,6 +151,7 @@ long cm_BPlusDirBuildTree(cm_scache_t *scp, cm_user_t *userp, cm_req_t* reqp); int cm_BPlusDirFoo(struct cm_scache *scp, struct cm_dirEntry *dep, void *dummy, osi_hyper_t *entryOffsetp); void cm_BPlusDumpStats(void); int cm_MemDumpBPlusStats(FILE *outputFile, char *cookie, int lock); +int cm_BPlusDirIsEmpty(cm_dirOp_t *op, afs_uint32 *pbEmpty); /******************* directory enumeration operations ****************/ typedef struct cm_direnum_entry { -- 2.39.5