/* * adfUpdateBitmap * */ RETCODE adfUpdateBitmap(struct Volume *vol) { int i; struct bRootBlock root; /*printf("adfUpdateBitmap\n");*/ if (adfReadRootBlock(vol, vol->rootBlock,&root)!=RC_OK) return RC_ERROR; root.bmFlag = BM_INVALID; if (adfWriteRootBlock(vol,vol->rootBlock,&root)!=RC_OK) return RC_ERROR; for(i=0; i<vol->bitmapSize; i++) if (vol->bitmapBlocksChg[i]) { if (adfWriteBitmapBlock(vol, vol->bitmapBlocks[i], vol->bitmapTable[i])!=RC_OK) return RC_ERROR; vol->bitmapBlocksChg[i] = FALSE; } root.bmFlag = BM_VALID; adfTime2AmigaTime(adfGiveCurrentTime(),&(root.days),&(root.mins),&(root.ticks)); if (adfWriteRootBlock(vol,vol->rootBlock,&root)!=RC_OK) return RC_ERROR; return RC_OK; }
/* * adfVolumeInfo * */ void adfVolumeInfo(struct Volume *vol) { struct bRootBlock root; char diskName[35]; int days,month,year; if (adfReadRootBlock(vol, vol->rootBlock, &root)!=RC_OK) return; memset(diskName, 0, 35); memcpy(diskName, root.diskName, root.nameLen); printf ("Name : %-30s\n",vol->volName); printf ("Type : "); switch(vol->dev->devType) { case DEVTYPE_FLOPDD: printf ("Floppy Double Density : 880 KBytes\n"); break; case DEVTYPE_FLOPHD: printf ("Floppy High Density : 1760 KBytes\n"); break; case DEVTYPE_HARDDISK: printf ("Hard Disk partition : %3.1f KBytes\n", (vol->lastBlock - vol->firstBlock +1) * 512.0/1024.0); break; case DEVTYPE_HARDFILE: printf ("HardFile : %3.1f KBytes\n", (vol->lastBlock - vol->firstBlock +1) * 512.0/1024.0); break; default: printf ("Unknown devType!\n"); } printf ("Filesystem : "); printf("%s ",isFFS(vol->dosType) ? "FFS" : "OFS"); if (isINTL(vol->dosType)) printf ("INTL "); if (isDIRCACHE(vol->dosType)) printf ("DIRCACHE "); putchar('\n'); printf("Free blocks = %d\n", adfCountFreeBlocks(vol)); if (vol->readOnly) printf("Read only\n"); else printf("Read/Write\n"); /* created */ adfDays2Date(root.coDays, &year, &month, &days); printf ("created %d/%02d/%02d %d:%02d:%02d\n",days,month,year, root.coMins/60,root.coMins%60,root.coTicks/50); adfDays2Date(root.days, &year, &month, &days); printf ("last access %d/%02d/%02d %d:%02d:%02d, ",days,month,year, root.mins/60,root.mins%60,root.ticks/50); adfDays2Date(root.cDays, &year, &month, &days); printf ("%d/%02d/%02d %d:%02d:%02d\n",days,month,year, root.cMins/60,root.cMins%60,root.cTicks/50); }
/*! \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 ); }
/* * adfMountFlop * * normaly not used directly, called directly by adfMount() * * use dev->devType to choose between DD and HD * fills geometry and the volume list with one volume */ RETCODE adfMountFlop(struct Device* dev) { struct Volume *vol; struct bRootBlock root; char diskName[35]; dev->cylinders = 80; dev->heads = 2; if (dev->devType==DEVTYPE_FLOPDD) dev->sectors = 11; else dev->sectors = 22; vol=(struct Volume*)malloc(sizeof(struct Volume)); if (!vol) { (*adfEnv.eFct)("adfMount : malloc"); return RC_ERROR; } vol->mounted = TRUE; vol->firstBlock = 0; vol->lastBlock =(dev->cylinders * dev->heads * dev->sectors)-1; vol->rootBlock = (vol->lastBlock+1 - vol->firstBlock)/2; vol->blockSize = 512; vol->dev = dev; if (adfReadRootBlock(vol, vol->rootBlock, &root)!=RC_OK) return RC_ERROR; memset(diskName, 0, 35); memcpy(diskName, root.diskName, root.nameLen); vol->volName = strdup(diskName); dev->volList =(struct Volume**) malloc(sizeof(struct Volume*)); if (!dev->volList) { free(vol); (*adfEnv.eFct)("adfMount : malloc"); return RC_ERROR; } dev->volList[0] = vol; dev->nVol = 1; /*printf("root=%d\n",vol->rootBlock); */ return RC_OK; }
/* * adfWriteNewBitmap * * write ext blocks and bitmap * * uses vol->bitmapSize, */ RETCODE adfWriteNewBitmap(struct Volume *vol) { struct bBitmapExtBlock bitme; SECTNUM *bitExtBlock; int n, i, k; int nExtBlock; int nBlock; SECTNUM *sectList; struct bRootBlock root; sectList=(SECTNUM*)malloc(sizeof(SECTNUM)*vol->bitmapSize); if (!sectList) { (*adfEnv.eFct)("adfCreateBitmap : sectList"); return RC_MALLOC; } if (!adfGetFreeBlocks(vol, vol->bitmapSize, sectList)) { free(sectList); return RC_ERROR; } if (adfReadRootBlock(vol, vol->rootBlock, &root)!=RC_OK) { free(sectList); return RC_ERROR; } nBlock = 0; n = min( vol->bitmapSize, BM_SIZE ); for(i=0; i<n; i++) { root.bmPages[i] = vol->bitmapBlocks[i] = sectList[i]; } nBlock = n; /* for devices with more than 25*127 blocks == hards disks */ if (vol->bitmapSize>BM_SIZE) { nExtBlock = (vol->bitmapSize-BM_SIZE)/127; if ((vol->bitmapSize-BM_SIZE)%127) nExtBlock++; bitExtBlock=(SECTNUM*)malloc(sizeof(SECTNUM)*nExtBlock); if (!bitExtBlock) { free(sectList); adfEnv.eFct("adfWriteNewBitmap : malloc failed"); return RC_MALLOC; } if (!adfGetFreeBlocks(vol, nExtBlock, bitExtBlock)) { free(sectList); free(bitExtBlock); return RC_MALLOC; } k = 0; root.bmExt = bitExtBlock[ k ]; while( nBlock<vol->bitmapSize ) { i=0; while( i<127 && nBlock<vol->bitmapSize ) { bitme.bmPages[i] = vol->bitmapBlocks[nBlock] = sectList[i]; i++; nBlock++; } if ( k+1<nExtBlock ) bitme.nextBlock = bitExtBlock[ k+1 ]; else bitme.nextBlock = 0; if (adfWriteBitmapExtBlock(vol, bitExtBlock[ k ], &bitme)!=RC_OK) { free(sectList); free(bitExtBlock); return RC_ERROR; } k++; } free( bitExtBlock ); } free( sectList); if (adfWriteRootBlock(vol,vol->rootBlock,&root)!=RC_OK) return RC_ERROR; return RC_OK; }