/* * adfReadBootBlock * * ENDIAN DEPENDENT */ RETCODE adfReadBootBlock(struct Volume* vol, struct bBootBlock* boot) { unsigned char buf[1024]; /*puts("22");*/ if (adfReadBlock(vol, 0, buf)!=RC_OK) return RC_ERROR; /*puts("11");*/ if (adfReadBlock(vol, 1, buf+LOGICAL_BLOCK_SIZE)!=RC_OK) return RC_ERROR; memcpy(boot, buf, LOGICAL_BLOCK_SIZE*2); #ifdef LITT_ENDIAN swapEndian((unsigned char*)boot,SWBL_BOOT); #endif if ( strncmp("DOS",boot->dosType,3)!=0 ) { (*adfEnv.wFct)("adfReadBootBlock : DOS id not found"); return RC_ERROR; } if ( boot->data[0]!=0 && adfBootSum(buf)!=boot->checkSum ) { /*printf("compsum=%lx sum=%lx\n", adfBootSum(buf),boot->checkSum );*/ /* BV */ (*adfEnv.wFct)("adfReadBootBlock : incorrect checksum"); } return RC_OK; }
/* * adfReadFileExtBlock * */ RETCODE adfReadFileExtBlock(struct Volume *vol, SECTNUM nSect, struct bFileExtBlock* fext) { unsigned char buf[sizeof(struct bFileExtBlock)]; RETCODE rc = RC_OK; adfReadBlock(vol, nSect,buf); /*printf("read fext=%d\n",nSect);*/ memcpy(fext,buf,sizeof(struct bFileExtBlock)); #ifdef LITT_ENDIAN swapEndian((unsigned char*)fext, SWBL_FEXT); #endif if (fext->checkSum!=adfNormalSum(buf,20,sizeof(struct bFileExtBlock))) (*adfEnv.wFct)("adfReadFileExtBlock : invalid checksum"); if (fext->type!=T_LIST) (*adfEnv.wFct)("adfReadFileExtBlock : type T_LIST not found"); if (fext->secType!=ST_FILE) (*adfEnv.wFct)("adfReadFileExtBlock : stype ST_FILE not found"); if (fext->headerKey!=nSect) (*adfEnv.wFct)("adfReadFileExtBlock : headerKey!=nSect"); if (fext->highSeq<0 || fext->highSeq>MAX_DATABLK) (*adfEnv.wFct)("adfReadFileExtBlock : highSeq out of range"); if ( !isSectNumValid(vol, fext->parent) ) (*adfEnv.wFct)("adfReadFileExtBlock : parent out of range"); if ( fext->extension!=0 && !isSectNumValid(vol, fext->extension) ) (*adfEnv.wFct)("adfReadFileExtBlock : extension out of range"); return rc; }
/* * adfReadDataBlock * */ RETCODE adfReadDataBlock(struct Volume *vol, SECTNUM nSect, void *data) { unsigned char buf[512]; struct bOFSDataBlock *dBlock; RETCODE rc = RC_OK; adfReadBlock(vol, nSect,buf); memcpy(data,buf,512); if (isOFS(vol->dosType)) { #ifdef LITT_ENDIAN swapEndian(data, SWBL_DATA); #endif dBlock = (struct bOFSDataBlock*)data; /*printf("adfReadDataBlock %ld\n",nSect);*/ if (dBlock->checkSum!=adfNormalSum(buf,20,sizeof(struct bOFSDataBlock))) (*adfEnv.wFct)("adfReadDataBlock : invalid checksum"); if (dBlock->type!=T_DATA) (*adfEnv.wFct)("adfReadDataBlock : id T_DATA not found"); if (dBlock->dataSize<0 || dBlock->dataSize>488) (*adfEnv.wFct)("adfReadDataBlock : dataSize incorrect"); if ( !isSectNumValid(vol,dBlock->headerKey) ) (*adfEnv.wFct)("adfReadDataBlock : headerKey out of range"); if ( !isSectNumValid(vol,dBlock->nextData) ) (*adfEnv.wFct)("adfReadDataBlock : nextData out of range"); } return rc; }
/* * adfReadGenBlock * */ RETCODE adfReadGenBlock(struct Volume *vol, SECTNUM nSect, struct GenBlock *block) { unsigned char buf[LOGICAL_BLOCK_SIZE]; int len; char name[MAXNAMELEN+1]; if (adfReadBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; block->type =(int) swapLong(buf); block->secType =(int) swapLong(buf+vol->blockSize-4); block->sect = nSect; block->name = NULL; if (block->type==T_HEADER) { switch(block->secType) { case ST_FILE: case ST_DIR: case ST_LFILE: case ST_LDIR: len = min(MAXNAMELEN, buf[vol->blockSize-80]); strncpy(name, buf+vol->blockSize-79, len); name[len] = '\0'; block->name = strdup(name); block->parent = swapLong(buf+vol->blockSize-12); break; case ST_ROOT: break; default: ; } } return RC_OK; }
/* * adfReadEntryBlock * */ RETCODE adfReadEntryBlock(struct Volume* vol, SECTNUM nSect, struct bEntryBlock *ent) { unsigned char buf[512]; if (adfReadBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; memcpy(ent, buf, 512); #ifdef LITT_ENDIAN swapEndian((unsigned char*)ent, SWBL_ENTRY); #endif /*printf("readentry=%d\n",nSect);*/ if (ent->checkSum!=adfNormalSum((unsigned char*)buf,20,512)) { (*adfEnv.wFct)("adfReadEntryBlock : invalid checksum"); return RC_ERROR; } if (ent->type!=T_HEADER) { (*adfEnv.wFct)("adfReadEntryBlock : T_HEADER id not found"); return RC_ERROR; } if (ent->nameLen<0 || ent->nameLen>MAXNAMELEN || ent->commLen>MAXCMMTLEN) { (*adfEnv.wFct)("adfReadEntryBlock : nameLen or commLen incorrect"); printf("nameLen=%d, commLen=%d, name=%s sector%d\n", ent->nameLen,ent->commLen,ent->name, ent->headerKey); } return RC_OK; }
/* * adfReadBitmapExtBlock * * ENDIAN DEPENDENT */ RETCODE adfReadBitmapExtBlock(struct Volume* vol, SECTNUM nSect, struct bBitmapExtBlock* bitme) { uint8_t buf[LOGICAL_BLOCK_SIZE]; if (adfReadBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; memcpy(bitme, buf, LOGICAL_BLOCK_SIZE); #ifdef LITT_ENDIAN swapEndian((uint8_t*)bitme, SWBL_BITMAP); #endif return RC_OK; }
/* * adfReadDirCBlock * */ RETCODE adfReadDirCBlock(struct Volume *vol, SECTNUM nSect, struct bDirCacheBlock *dirc) { unsigned char buf[512]; if (adfReadBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; memcpy(dirc,buf,512); #ifdef LITT_ENDIAN swapEndian((unsigned char*)dirc,SWBL_CACHE); #endif if (dirc->checkSum!=adfNormalSum(buf,20,512)) (*adfEnv.wFct)("adfReadDirCBlock : invalid checksum"); if (dirc->type!=T_DIRC) (*adfEnv.wFct)("adfReadDirCBlock : T_DIRC not found"); if (dirc->headerKey!=nSect) (*adfEnv.wFct)("adfReadDirCBlock : headerKey!=nSect"); return RC_OK; }
/* * adfReadBitmapBlock * * ENDIAN DEPENDENT */ RETCODE adfReadBitmapBlock(struct Volume* vol, SECTNUM nSect, struct bBitmapBlock* bitm) { uint8_t buf[LOGICAL_BLOCK_SIZE]; /*printf("bitmap %ld\n",nSect);*/ if (adfReadBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; memcpy(bitm, buf, LOGICAL_BLOCK_SIZE); #ifdef LITT_ENDIAN /* big to little = 68000 to x86 */ swapEndian((uint8_t*)bitm, SWBL_BITMAP); #endif if (bitm->checkSum!=adfNormalSum(buf,0,LOGICAL_BLOCK_SIZE)) (*adfEnv.wFct)("adfReadBitmapBlock : invalid checksum"); return RC_OK; }
/* * adfReadRootBlock * * ENDIAN DEPENDENT */ RETCODE adfReadRootBlock(struct Volume* vol, long nSect, struct bRootBlock* root) { unsigned char buf[LOGICAL_BLOCK_SIZE]; if (adfReadBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; memcpy(root, buf, LOGICAL_BLOCK_SIZE); #ifdef LITT_ENDIAN swapEndian((unsigned char*)root, SWBL_ROOT); #endif if (root->type!=T_HEADER || root->secType!=ST_ROOT) { (*adfEnv.wFct)("adfReadRootBlock : id not found"); return RC_ERROR; } if (root->checkSum!=adfNormalSum(buf, 20, LOGICAL_BLOCK_SIZE)) { (*adfEnv.wFct)("adfReadRootBlock : invalid checksum"); return RC_ERROR; } return RC_OK; }