* adfDelFromCache * * delete one cache entry from its block. don't do 'records garbage collecting' */
| 281 | * delete one cache entry from its block. don't do 'records garbage collecting' |
| 282 | */ |
| 283 | RETCODE adfDelFromCache(struct Volume *vol, struct bEntryBlock *parent, |
| 284 | SECTNUM headerKey) |
| 285 | { |
| 286 | struct bDirCacheBlock dirc; |
| 287 | SECTNUM nSect, prevSect; |
| 288 | struct CacheEntry caEntry; |
| 289 | int offset, oldOffset, n; |
| 290 | BOOL found; |
| 291 | int entryLen; |
| 292 | int i; |
| 293 | RETCODE rc = RC_OK; |
| 294 | |
| 295 | prevSect = -1; |
| 296 | nSect = parent->extension; |
| 297 | found = FALSE; |
| 298 | do { |
| 299 | adfReadDirCBlock(vol, nSect, &dirc); |
| 300 | offset = 0; n = 0; |
| 301 | while(n < dirc.recordsNb && !found) { |
| 302 | oldOffset = offset; |
| 303 | adfGetCacheEntry(&dirc, &offset, &caEntry); |
| 304 | found = (caEntry.header==headerKey); |
| 305 | if (found) { |
| 306 | entryLen = offset-oldOffset; |
| 307 | if (dirc.recordsNb>1 || prevSect==-1) { |
| 308 | if (n<dirc.recordsNb-1) { |
| 309 | /* not the last of the block : switch the following records */ |
| 310 | for(i=oldOffset; i<(488-entryLen); i++) |
| 311 | dirc.records[i] = dirc.records[i+entryLen]; |
| 312 | /* and clear the following bytes */ |
| 313 | for(i=488-entryLen; i<488; i++) |
| 314 | dirc.records[i] = 0; |
| 315 | } |
| 316 | else { |
| 317 | /* the last record of this cache block */ |
| 318 | for(i=oldOffset; i<offset; i++) |
| 319 | dirc.records[i] = 0; |
| 320 | } |
| 321 | dirc.recordsNb--; |
| 322 | if (adfWriteDirCBlock(vol, dirc.headerKey, &dirc)!=RC_OK) |
| 323 | return -1; |
| 324 | } |
| 325 | else { |
| 326 | /* dirc.recordsNb ==1 or == 0 , prevSect!=-1 : |
| 327 | * the only record in this dirc block and a previous dirc block exists |
| 328 | */ |
| 329 | adfSetBlockFree(vol, dirc.headerKey); |
| 330 | adfReadDirCBlock(vol, prevSect, &dirc); |
| 331 | dirc.nextDirC = 0L; |
| 332 | adfWriteDirCBlock(vol, prevSect, &dirc); |
| 333 | |
| 334 | adfUpdateBitmap(vol); |
| 335 | } |
| 336 | } |
| 337 | n++; |
| 338 | } |
| 339 | prevSect = nSect; |
| 340 | nSect = dirc.nextDirC; |
no test coverage detected