* adfRemoveEntry * */
| 204 | * |
| 205 | */ |
| 206 | RETCODE adfRemoveEntry(struct Volume *vol, SECTNUM pSect, char *name) |
| 207 | { |
| 208 | struct bEntryBlock parent, previous, entry; |
| 209 | SECTNUM nSect2, nSect; |
| 210 | int hashVal; |
| 211 | BOOL intl; |
| 212 | char buf[200]; |
| 213 | |
| 214 | if (adfReadEntryBlock( vol, pSect, &parent )!=RC_OK) |
| 215 | return RC_ERROR; |
| 216 | nSect = adfNameToEntryBlk(vol, parent.hashTable, name, &entry, &nSect2); |
| 217 | if (nSect==-1) { |
| 218 | sprintf(buf, "adfRemoveEntry : entry '%s' not found", name); |
| 219 | (*adfEnv.wFct)(buf); |
| 220 | return RC_ERROR; |
| 221 | } |
| 222 | /* if it is a directory, is it empty ? */ |
| 223 | if ( entry.secType==ST_DIR && !isDirEmpty((struct bDirBlock*)&entry) ) { |
| 224 | sprintf(buf, "adfRemoveEntry : directory '%s' not empty", name); |
| 225 | (*adfEnv.wFct)(buf); |
| 226 | return RC_ERROR; |
| 227 | } |
| 228 | /* printf("name=%s nSect2=%ld\n",name, nSect2);*/ |
| 229 | |
| 230 | /* in parent hashTable */ |
| 231 | if (nSect2==0) { |
| 232 | intl = isINTL(vol->dosType) || isDIRCACHE(vol->dosType); |
| 233 | hashVal = adfGetHashValue( (uint8_t*)name, intl ); |
| 234 | /*printf("hashTable=%d nexthash=%d\n",parent.hashTable[hashVal], |
| 235 | entry.nextSameHash);*/ |
| 236 | parent.hashTable[hashVal] = entry.nextSameHash; |
| 237 | if (adfWriteEntryBlock(vol, pSect, &parent)!=RC_OK) |
| 238 | return RC_ERROR; |
| 239 | } |
| 240 | /* in linked list */ |
| 241 | else { |
| 242 | if (adfReadEntryBlock(vol, nSect2, &previous)!=RC_OK) |
| 243 | return RC_ERROR; |
| 244 | previous.nextSameHash = entry.nextSameHash; |
| 245 | if (adfWriteEntryBlock(vol, nSect2, &previous)!=RC_OK) |
| 246 | return RC_ERROR; |
| 247 | } |
| 248 | |
| 249 | if (entry.secType==ST_FILE) { |
| 250 | adfFreeFileBlocks(vol, (struct bFileHeaderBlock*)&entry); |
| 251 | adfSetBlockFree(vol, nSect); //marks the FileHeaderBlock as free in BitmapBlock |
| 252 | if (adfEnv.useNotify) |
| 253 | (*adfEnv.notifyFct)(pSect,ST_FILE); |
| 254 | } |
| 255 | else if (entry.secType==ST_DIR) { |
| 256 | adfSetBlockFree(vol, nSect); |
| 257 | /* free dir cache block : the directory must be empty, so there's only one cache block */ |
| 258 | if (isDIRCACHE(vol->dosType)) |
| 259 | adfSetBlockFree(vol, entry.extension); |
| 260 | if (adfEnv.useNotify) |
| 261 | (*adfEnv.notifyFct)(pSect,ST_DIR); |
| 262 | } |
| 263 | else { |
no test coverage detected