/* * adfCheckFile * */ RETCODE adfCheckFile(struct Volume* vol, SECTNUM nSect, struct bFileHeaderBlock* file, int level) { struct bFileExtBlock extBlock; struct bOFSDataBlock dataBlock; struct FileBlocks fileBlocks; int n; adfGetFileBlocks(vol,file,&fileBlocks); //printf("data %ld ext %ld\n",fileBlocks.nbData,fileBlocks.nbExtens); if (isOFS(vol->dosType)) { /* checks OFS datablocks */ for(n=0; n<fileBlocks.nbData; n++) { //printf("%ld\n",fileBlocks.data[n]); adfReadDataBlock(vol,fileBlocks.data[n],&dataBlock); if (dataBlock.headerKey!=fileBlocks.header) (*adfEnv.wFct)("adfCheckFile : headerKey incorrect"); if (dataBlock.seqNum!=n+1) (*adfEnv.wFct)("adfCheckFile : seqNum incorrect"); if (n<fileBlocks.nbData-1) { if (dataBlock.nextData!=fileBlocks.data[n+1]) (*adfEnv.wFct)("adfCheckFile : nextData incorrect"); if (dataBlock.dataSize!=vol->datablockSize) (*adfEnv.wFct)("adfCheckFile : dataSize incorrect"); } else { /* last datablock */ if (dataBlock.nextData!=0) (*adfEnv.wFct)("adfCheckFile : nextData incorrect"); } } } for(n=0; n<fileBlocks.nbExtens; n++) { adfReadFileExtBlock(vol,fileBlocks.extens[n],&extBlock); if (extBlock.parent!=file->headerKey) (*adfEnv.wFct)("adfCheckFile : extBlock parent incorrect"); if (n<fileBlocks.nbExtens-1) { if (extBlock.extension!=fileBlocks.extens[n+1]) (*adfEnv.wFct)("adfCheckFile : nextData incorrect"); } else if (extBlock.extension!=0) (*adfEnv.wFct)("adfCheckFile : nextData incorrect"); } free(fileBlocks.data); free(fileBlocks.extens); return RC_OK; }
/* * adfUndelFile * */ RETCODE adfUndelFile(struct Volume* vol, SECTNUM pSect, SECTNUM nSect, struct bFileHeaderBlock* entry) { long i; char name[MAXNAMELEN+1]; struct bEntryBlock parent; RETCODE rc; struct FileBlocks fileBlocks; /* check if the given parent sector pointer seems OK */ if ( (rc=adfCheckParent(vol,pSect)) != RC_OK) return rc; if (pSect!=entry->parent) { (*adfEnv.wFct)("adfUndelFile : the given parent sector isn't the entry parent"); return RC_ERROR; } adfGetFileBlocks(vol, entry, &fileBlocks); for(i=0; i<fileBlocks.nbData; i++) if ( !adfIsBlockFree(vol,fileBlocks.data[i]) ) return RC_ERROR; else adfSetBlockUsed(vol, fileBlocks.data[i]); for(i=0; i<fileBlocks.nbExtens; i++) if ( !adfIsBlockFree(vol,fileBlocks.extens[i]) ) return RC_ERROR; else adfSetBlockUsed(vol, fileBlocks.extens[i]); free(fileBlocks.data); free(fileBlocks.extens); if (adfReadEntryBlock(vol, pSect, &parent)!=RC_OK) return RC_ERROR; strncpy(name, entry->fileName, entry->nameLen); name[(int)entry->nameLen] = '\0'; /* insert the entry in the parent hashTable, with the headerKey sector pointer */ adfCreateEntry(vol, &parent, name, entry->headerKey); if (isDIRCACHE(vol->dosType)) adfAddInCache(vol, &parent, (struct bEntryBlock *)entry); adfUpdateBitmap(vol); return RC_OK; }
/* * adfFreeFileBlocks * */ RETCODE adfFreeFileBlocks(struct Volume* vol, struct bFileHeaderBlock *entry) { int i; struct FileBlocks fileBlocks; RETCODE rc = RC_OK; adfGetFileBlocks(vol,entry,&fileBlocks); for(i=0; i<fileBlocks.nbData; i++) { adfSetBlockFree(vol, fileBlocks.data[i]); } for(i=0; i<fileBlocks.nbExtens; i++) { adfSetBlockFree(vol, fileBlocks.extens[i]); } free(fileBlocks.data); free(fileBlocks.extens); return rc; }