/*! \brief Mount a volume. * \param dev - The device containing the volume to mount. * \param nPart - The volume number to mount. * \param readOnly - TRUE if read only access is desired, FALSE otherwise. * \return The Volume, NULL in case of error. * * Mounts a designated volume (nPart) of the Device (dev), with specified read/write access (readOnly). * The first partition is #0. The current working directory is the root block. * * \b Internals \n * 1. Read the bootblock to determine vol->dosType and vol->datablockSize. \n * 2. Read the rootblock, fills vol->curDirPtr. \n * 3. Read and allocate the bitmap : vol->bitmapBlocks[], vol->bitmapTable[], vol->bitmapSize, vol->bitmapBlocksChg[]. \n */ struct Volume* adfMount( struct Device *dev, int nPart, BOOL readOnly ) { long nBlock; struct bRootBlock root; struct bBootBlock boot; struct Volume* vol; if (dev==NULL || nPart<nPart || nPart >= dev->nVol) { (*adfEnv.eFct)("adfMount : invalid parameter(s)"); return NULL; } vol = dev->volList[nPart]; vol->dev = dev; vol->mounted = TRUE; #ifdef _DEBUG_PRINTF_ printf("first=%ld last=%ld root=%ld\n",vol->firstBlock, vol->lastBlock, vol->rootBlock); #endif /*_DEBUG_PRINTF_*/ if (adfReadBootBlock(vol, &boot)!=RC_OK) { (*adfEnv.wFct)("adfMount : BootBlock invalid"); return NULL; } vol->dosType = boot.dosType[3]; if (isFFS(vol->dosType)) vol->datablockSize=512; else vol->datablockSize=488; if (dev->readOnly /*|| isDIRCACHE(vol->dosType)*/) vol->readOnly = TRUE; else vol->readOnly = readOnly; if (adfReadRootBlock(vol, vol->rootBlock, &root)!=RC_OK) { (*adfEnv.wFct)("adfMount : RootBlock invalid"); return NULL; } nBlock = vol->lastBlock - vol->firstBlock +1 - 2; adfReadBitmap( vol, nBlock, &root ); vol->curDirPtr = vol->rootBlock; #ifdef _DEBUG_PRINTF_ printf("blockSize=%d\n",vol->blockSize); #endif /*_DEBUG_PRINTF_*/ return( vol ); }
RETCODE adfInstallBootBlock(struct Volume *vol, unsigned char* code) { int i; struct bBootBlock boot; if (vol->dev->devType!=DEVTYPE_FLOPDD && vol->dev->devType!=DEVTYPE_FLOPHD) return RC_ERROR; if (adfReadBootBlock(vol, &boot)!=RC_OK) return RC_ERROR; boot.rootBlock = 880; for(i=0; i<1024-12; i++) /* bootcode */ boot.data[i] = code[i+12]; if (adfWriteBootBlock(vol, &boot)!=RC_OK) return RC_ERROR; vol->bootCode = TRUE; return RC_OK; }