/* * adfWriteDataBlock * */ RETCODE adfWriteDataBlock(struct Volume *vol, SECTNUM nSect, void *data) { unsigned char buf[512]; uint32_t newSum; struct bOFSDataBlock *dataB; RETCODE rc = RC_OK; newSum = 0L; if (isOFS(vol->dosType)) { dataB = (struct bOFSDataBlock *)data; dataB->type = T_DATA; memcpy(buf,dataB,512); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_DATA); #endif newSum = adfNormalSum(buf,20,512); swLong(buf+20,newSum); /* *(int32_t*)(buf+20) = swapLong((unsigned char*)&newSum);*/ adfWriteBlock(vol,nSect,buf); } else { adfWriteBlock(vol,nSect,data); } /*printf("adfWriteDataBlock %ld\n",nSect);*/ return rc; }
/* * 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; }
/* * ReadLSEGblock * */ RETCODE adfReadLSEGblock(struct Device* dev, int32_t nSect, struct bLSEGblock* blk) { UCHAR buf[sizeof(struct bLSEGblock)]; struct nativeFunctions *nFct; RETCODE rc; nFct = adfEnv.nativeFct; if (dev->isNativeDev) rc=(*nFct->adfNativeReadSector)(dev, nSect, sizeof(struct bLSEGblock), buf); else rc=adfReadDumpSector(dev, nSect, sizeof(struct bLSEGblock), buf); if (rc!=RC_OK) return RC_ERROR; memcpy(blk, buf, sizeof(struct bLSEGblock)); #ifdef LITT_ENDIAN /* big to little = 68000 to x86 */ swapEndian((uint8_t*)blk, SWBL_LSEG); #endif if ( strncmp(blk->id,"LSEG",4)!=0 ) { (*adfEnv.eFct)("ReadLSEGblock : LSEG id not found"); return RC_ERROR; } if ( blk->checksum != adfNormalSum(buf,8,sizeof(struct bLSEGblock)) ) (*adfEnv.wFct)("ReadLSEGBlock : incorrect checksum"); if ( blk->next!=-1 && blk->size != 128 ) (*adfEnv.wFct)("ReadLSEGBlock : size != 128"); return RC_OK; }
/* * 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; }
/* * 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; }
/* * adfWriteRootBlock * * */ RETCODE adfWriteRootBlock(struct Volume* vol, long nSect, struct bRootBlock* root) { unsigned char buf[LOGICAL_BLOCK_SIZE]; unsigned long newSum; root->type = T_HEADER; root->headerKey = 0L; root->highSeq = 0L; root->hashTableSize = HT_SIZE; root->firstData = 0L; /* checkSum, hashTable */ /* bmflag */ /* bmPages, bmExt */ root->nextSameHash = 0L; root->parent = 0L; root->secType = ST_ROOT; memcpy(buf, root, LOGICAL_BLOCK_SIZE); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_ROOT); #endif newSum = adfNormalSum(buf,20,LOGICAL_BLOCK_SIZE); swLong(buf+20, newSum); /* *(unsigned long*)(buf+20) = swapLong((unsigned char*)&newSum);*/ /* dumpBlock(buf);*/ if (adfWriteBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; /*printf("adfWriteRootBlock %ld\n",nSect);*/ return RC_OK; }
/* * ReadFSHDblock * */ RETCODE adfReadFSHDblock( struct Device* dev, long nSect, struct bFSHDblock* blk) { UCHAR buf[sizeof(struct bFSHDblock)]; struct nativeFunctions *nFct; RETCODE rc; nFct = adfEnv.nativeFct; if (dev->isNativeDev) rc = (*nFct->adfNativeReadSector)(dev, nSect, sizeof(struct bFSHDblock), buf); else rc = adfReadDumpSector(dev, nSect, sizeof(struct bFSHDblock), buf); if (rc!=RC_OK) return RC_ERROR; memcpy(blk, buf, sizeof(struct bFSHDblock)); #ifdef LITT_ENDIAN /* big to little = 68000 to x86 */ swapEndian((unsigned char*)blk, SWBL_FSHD); #endif if ( strncmp(blk->id,"FSHD",4)!=0 ) { (*adfEnv.eFct)("ReadFSHDblock : FSHD id not found"); return RC_ERROR; } if ( blk->size != 64 ) (*adfEnv.wFct)("ReadFSHDblock : size != 64"); if ( blk->checksum != adfNormalSum(buf,8,256) ) (*adfEnv.wFct)( "ReadFSHDblock : incorrect checksum"); return RC_OK; }
/* * ReadRDSKblock * */ RETCODE adfReadRDSKblock( struct Device* dev, struct bRDSKblock* blk ) { UCHAR buf[256]; struct nativeFunctions *nFct; RETCODE rc2; RETCODE rc = RC_OK; nFct = adfEnv.nativeFct; if (dev->isNativeDev) rc2 =(*nFct->adfNativeReadSector)(dev, 0, 256, buf); else rc2 = adfReadDumpSector(dev, 0, 256, buf); if (rc2!=RC_OK) return(RC_ERROR); memcpy(blk, buf, 256); #ifdef LITT_ENDIAN /* big to little = 68000 to x86 */ swapEndian((uint8_t*)blk, SWBL_RDSK); #endif if ( strncmp(blk->id,"RDSK",4)!=0 ) { (*adfEnv.eFct)("ReadRDSKblock : RDSK id not found"); return RC_ERROR; } if ( blk->size != 64 ) (*adfEnv.wFct)("ReadRDSKBlock : size != 64"); /* BV */ if ( blk->checksum != adfNormalSum(buf,8,256) ) { (*adfEnv.wFct)("ReadRDSKBlock : incorrect checksum"); /* BV FIX: Due to malicious Win98 write to sector rc|=RC_BLOCKSUM;*/ } if ( blk->blockSize != 512 ) (*adfEnv.wFct)("ReadRDSKBlock : blockSize != 512"); /* BV */ if ( blk->cylBlocks != blk->sectors*blk->heads ) (*adfEnv.wFct)( "ReadRDSKBlock : cylBlocks != sectors*heads"); return rc; }
/* * adfWriteRDSKblock * */ RETCODE adfWriteRDSKblock(struct Device *dev, struct bRDSKblock* rdsk) { uint8_t buf[LOGICAL_BLOCK_SIZE]; uint32_t newSum; struct nativeFunctions *nFct; RETCODE rc2, rc = RC_OK; if (dev->readOnly) { (*adfEnv.wFct)("adfWriteRDSKblock : can't write block, read only device"); return RC_ERROR; } memset(buf,0,LOGICAL_BLOCK_SIZE); strncpy(rdsk->id,"RDSK",4); rdsk->size = sizeof(struct bRDSKblock)/sizeof(int32_t); rdsk->blockSize = LOGICAL_BLOCK_SIZE; rdsk->badBlockList = -1; strncpy(rdsk->diskVendor,"ADFlib ",8); strncpy(rdsk->diskProduct,"harddisk.adf ",16); strncpy(rdsk->diskRevision,"v1.0",4); memcpy(buf, rdsk, sizeof(struct bRDSKblock)); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_RDSK); #endif newSum = adfNormalSum(buf, 8, LOGICAL_BLOCK_SIZE); swLong(buf+8, newSum); nFct = adfEnv.nativeFct; if (dev->isNativeDev) rc2=(*nFct->adfNativeWriteSector)(dev, 0, LOGICAL_BLOCK_SIZE, buf); else rc2=adfWriteDumpSector(dev, 0, LOGICAL_BLOCK_SIZE, buf); if (rc2!=RC_OK) return RC_ERROR; return rc; }
/* * adfWriteEntryBlock * */ RETCODE adfWriteEntryBlock(struct Volume* vol, SECTNUM nSect, struct bEntryBlock *ent) { unsigned char buf[512]; uint32_t newSum; memcpy(buf, ent, sizeof(struct bEntryBlock)); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_ENTRY); #endif newSum = adfNormalSum(buf,20,sizeof(struct bEntryBlock)); swLong(buf+20, newSum); if (adfWriteBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; return RC_OK; }
/* * adfWritePARTblock * */ RETCODE adfWritePARTblock(struct Device *dev, int32_t nSect, struct bPARTblock* part) { uint8_t buf[LOGICAL_BLOCK_SIZE]; uint32_t newSum; struct nativeFunctions *nFct; RETCODE rc2, rc = RC_OK; if (dev->readOnly) { (*adfEnv.wFct)("adfWritePARTblock : can't write block, read only device"); return RC_ERROR; } memset(buf,0,LOGICAL_BLOCK_SIZE); strncpy(part->id,"PART",4); part->size = sizeof(struct bPARTblock)/sizeof(int32_t); part->blockSize = LOGICAL_BLOCK_SIZE; part->vectorSize = 16; part->blockSize = 128; part->sectorsPerBlock = 1; part->dosReserved = 2; memcpy(buf, part, sizeof(struct bPARTblock)); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_PART); #endif newSum = adfNormalSum(buf, 8, LOGICAL_BLOCK_SIZE); swLong(buf+8, newSum); /* *(int32_t*)(buf+8) = swapLong((uint8_t*)&newSum);*/ nFct = adfEnv.nativeFct; if (dev->isNativeDev) rc2=(*nFct->adfNativeWriteSector)(dev, nSect, LOGICAL_BLOCK_SIZE, buf); else rc2=adfWriteDumpSector(dev, nSect, LOGICAL_BLOCK_SIZE, buf); if (rc2!=RC_OK) return RC_ERROR; return rc; }
/* * 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; }
/* * 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; }
/* * adfWriteBitmapBlock * * OK */ RETCODE adfWriteBitmapBlock(struct Volume* vol, SECTNUM nSect, struct bBitmapBlock* bitm) { uint8_t buf[LOGICAL_BLOCK_SIZE]; uint32_t newSum; memcpy(buf,bitm,LOGICAL_BLOCK_SIZE); #ifdef LITT_ENDIAN /* little to big */ swapEndian(buf, SWBL_BITMAP); #endif newSum = adfNormalSum(buf, 0, LOGICAL_BLOCK_SIZE); swLong(buf,newSum); /* dumpBlock((uint8_t*)buf);*/ if (adfWriteBlock(vol, nSect, (uint8_t*)buf)!=RC_OK) return RC_ERROR; return RC_OK; }
/* * ReadPARTblock * */ RETCODE adfReadPARTblock( struct Device* dev, int32_t nSect, struct bPARTblock* blk ) { UCHAR buf[ sizeof(struct bPARTblock) ]; struct nativeFunctions *nFct; RETCODE rc2, rc = RC_OK; nFct = adfEnv.nativeFct; if (dev->isNativeDev) rc2=(*nFct->adfNativeReadSector)(dev, nSect, sizeof(struct bPARTblock), buf); else rc2=adfReadDumpSector(dev, nSect, sizeof(struct bPARTblock), buf); if (rc2!=RC_OK) return RC_ERROR; memcpy(blk, buf, sizeof(struct bPARTblock)); #ifdef LITT_ENDIAN /* big to little = 68000 to x86 */ swapEndian((uint8_t*)blk, SWBL_PART); #endif if ( strncmp(blk->id,"PART",4)!=0 ) { (*adfEnv.eFct)("ReadPARTblock : PART id not found"); return RC_ERROR; } if ( blk->size != 64 ) (*adfEnv.wFct)("ReadPARTBlock : size != 64"); if ( blk->blockSize!=128 ) { (*adfEnv.eFct)("ReadPARTblock : blockSize!=512, not supported (yet)"); return RC_ERROR; } if ( blk->checksum != adfNormalSum(buf,8,256) ) (*adfEnv.wFct)( "ReadPARTBlock : incorrect checksum"); return rc; }
/* * adfWriteFileHdrBlock * */ RETCODE adfWriteFileHdrBlock(struct Volume *vol, SECTNUM nSect, struct bFileHeaderBlock* fhdr) { unsigned char buf[512]; uint32_t newSum; RETCODE rc = RC_OK; /*printf("adfWriteFileHdrBlock %ld\n",nSect);*/ fhdr->type = T_HEADER; fhdr->dataSize = 0; fhdr->secType = ST_FILE; memcpy(buf, fhdr, sizeof(struct bFileHeaderBlock)); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_FILE); #endif newSum = adfNormalSum(buf,20,sizeof(struct bFileHeaderBlock)); swLong(buf+20, newSum); /* *(uint32_t*)(buf+20) = swapLong((unsigned char*)&newSum);*/ adfWriteBlock(vol, nSect, buf); return rc; }
/* * adfWriteLSEGblock * */ RETCODE adfWriteLSEGblock(struct Device *dev, int32_t nSect, struct bLSEGblock* lseg) { uint8_t buf[LOGICAL_BLOCK_SIZE]; uint32_t newSum; struct nativeFunctions *nFct; RETCODE rc; if (dev->readOnly) { (*adfEnv.wFct)("adfWriteLSEGblock : can't write block, read only device"); return RC_ERROR; } memset(buf,0,LOGICAL_BLOCK_SIZE); strncpy(lseg->id,"LSEG",4); lseg->size = sizeof(struct bLSEGblock)/sizeof(int32_t); memcpy(buf, lseg, sizeof(struct bLSEGblock)); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_LSEG); #endif newSum = adfNormalSum(buf, 8, LOGICAL_BLOCK_SIZE); swLong(buf+8,newSum); /* *(int32_t*)(buf+8) = swapLong((uint8_t*)&newSum);*/ nFct = adfEnv.nativeFct; if (dev->isNativeDev) rc=(*nFct->adfNativeWriteSector)(dev, nSect, LOGICAL_BLOCK_SIZE, buf); else rc=adfWriteDumpSector(dev, nSect, LOGICAL_BLOCK_SIZE, buf); if (rc!=RC_OK) return RC_ERROR; return RC_OK; }
/* * adfWriteDirCblock * */ RETCODE adfWriteDirCBlock(struct Volume* vol, int32_t nSect, struct bDirCacheBlock* dirc) { unsigned char buf[LOGICAL_BLOCK_SIZE]; uint32_t newSum; dirc->type = T_DIRC; dirc->headerKey = nSect; memcpy(buf, dirc, LOGICAL_BLOCK_SIZE); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_CACHE); #endif newSum = adfNormalSum(buf, 20, LOGICAL_BLOCK_SIZE); swLong(buf+20,newSum); /* *(int32_t*)(buf+20) = swapLong((unsigned char*)&newSum);*/ if (adfWriteBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; /*puts("adfWriteDirCBlock");*/ return RC_OK; }
/* * adfWriteFileExtBlock * */ RETCODE adfWriteFileExtBlock(struct Volume *vol, SECTNUM nSect, struct bFileExtBlock* fext) { unsigned char buf[512]; uint32_t newSum; RETCODE rc = RC_OK; fext->type = T_LIST; fext->secType = ST_FILE; fext->dataSize = 0L; fext->firstData = 0L; memcpy(buf,fext,512); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_FEXT); #endif newSum = adfNormalSum(buf,20,512); swLong(buf+20,newSum); /* *(int32_t*)(buf+20) = swapLong((unsigned char*)&newSum);*/ adfWriteBlock(vol,nSect,buf); return rc; }
/* * adfWriteFSHDblock * */ RETCODE adfWriteFSHDblock(struct Device *dev, long nSect, struct bFSHDblock* fshd) { unsigned char buf[LOGICAL_BLOCK_SIZE]; unsigned long newSum; struct nativeFunctions *nFct; RETCODE rc = RC_OK; if (dev->readOnly) { (*adfEnv.wFct)("adfWriteFSHDblock : can't write block, read only device"); return RC_ERROR; } memset(buf,0,LOGICAL_BLOCK_SIZE); strncpy(fshd->id,"FSHD",4); fshd->size = sizeof(struct bFSHDblock)/sizeof(long); memcpy(buf, fshd, sizeof(struct bFSHDblock)); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_FSHD); #endif newSum = adfNormalSum(buf, 8, LOGICAL_BLOCK_SIZE); swLong(buf+8, newSum); /* *(long*)(buf+8) = swapLong((unsigned char*)&newSum);*/ nFct = adfEnv.nativeFct; if (dev->isNativeDev) rc=(*nFct->adfNativeWriteSector)(dev, nSect, LOGICAL_BLOCK_SIZE, buf); else rc=adfWriteDumpSector(dev, nSect, LOGICAL_BLOCK_SIZE, buf); if (rc!=RC_OK) return RC_ERROR; return RC_OK; }
/* * adfWriteDirBlock * */ RETCODE adfWriteDirBlock(struct Volume* vol, SECTNUM nSect, struct bDirBlock *dir) { unsigned char buf[512]; uint32_t newSum; /*printf("wdirblk=%d\n",nSect);*/ dir->type = T_HEADER; dir->highSeq = 0; dir->hashTableSize = 0; dir->secType = ST_DIR; memcpy(buf, dir, sizeof(struct bDirBlock)); #ifdef LITT_ENDIAN swapEndian(buf, SWBL_DIR); #endif newSum = adfNormalSum(buf,20,sizeof(struct bDirBlock)); swLong(buf+20, newSum); if (adfWriteBlock(vol, nSect, buf)!=RC_OK) return RC_ERROR; 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; }