uint32_t FindFreeCluster() { char* buffer = new char[bpb->bytesPerSector]; uint32_t sector, i = fsInfo->nextFreeCluster; sector = GetFATSector(fsInfo->nextFreeCluster); ReadSector(buffer, sector); for (; i < bpb->sectorsPerFATLarge * bpb->bytesPerSector; i++) { // Read next FAT sector if required if (sector != GetFATSector(i)) { sector = GetFATSector(i); ReadSector(buffer, sector); } // Check if this entry is free if (*(uint32_t*)(buffer + GetFATOffset(i)) == FAT_FREE) break; } if (i >= ((bpb->sectorsPerFATLarge * bpb->bytesPerSector) / 4)) { std::cout << "No free clusters!" << std::endl; return FAT_EOF; } // Update fsInfo, since we found a new free cluster fsInfo->nextFreeCluster = i; fsInfo->freeClusterCount--; delete[] buffer; //std::cout << "FAT i = " << i << ", spFATL = " << ((bpb->sectorsPerFATLarge * bpb->bytesPerSector) / 4) << std::endl; return i; }
void CCPCSystemDisc::ReadBlock(const unsigned char i_idBlock, void* o_buffer) const { unsigned int bloc = i_idBlock+9; unsigned char track1 = (bloc*2 - (bloc*2 % _geometry.dg_sectors)) / _geometry.dg_sectors; unsigned char sector1 = _geometry.dg_secbase+(bloc*2 % _geometry.dg_sectors); unsigned char track2 = ((bloc*2+1) - ((bloc*2+1) % _geometry.dg_sectors)) / _geometry.dg_sectors; unsigned char sector2 = _geometry.dg_secbase+((bloc*2+1) % _geometry.dg_sectors); ReadSector(track1,0,sector1,o_buffer); ReadSector(track2,0,sector2,(char*)o_buffer+_geometry.dg_secsize); }
int GetBlock(int blk_num,char *ptr) { int sec_num,len=0; int j,k; char *dir; if(blk_num<0 || blk_num>max_block_num||ptr==NULL) return ERROR; dir=(char *) malloc(SECTORSIZE*sizeof(char)); sec_num=(blk_num*BLOCKSIZE)/SECTORSIZE; for(j=0;j<BLOCKSIZE/SECTORSIZE;j++) { ReadSector(sec_num,(void *)dir); for(k=0;k<(SECTORSIZE/sizeof(char));k++) { ptr[len++]=dir[k]; } sec_num++; } return (dir); return len; }
void DirectoryRead(Directory* dir) { char* buffer = new char[bpb->bytesPerSector]; FatEntry fatEntry; fatEntry.buffer = new char[bpb->bytesPerSector]; fatEntry.cluster = dir->cluster; fatEntry.sector = GetFATSector(fatEntry.cluster); ReadSector(fatEntry.buffer, fatEntry.sector); Sector* sector; while (ReadCluster(&fatEntry, buffer)) { // Allocate a new sector sector = new Sector; sector->buffer = new char[512]; sector->sector = ClusterToSector(fatEntry.cluster); memcpy(sector->buffer, buffer, 512); // Add to list directory.sectors[directory.count] = sector; directory.count++; } // Allocate a new sector sector = new Sector; sector->buffer = new char[512]; sector->sector = ClusterToSector(fatEntry.cluster); memcpy(sector->buffer, buffer, 512); // Add to list directory.sectors[directory.count] = sector; directory.count++; delete[] buffer; delete[] fatEntry.buffer; }
//DeviceRead for WINHD driver. static DWORD DeviceRead(__COMMON_OBJECT* lpDrv, __COMMON_OBJECT* lpDev, __DRCB* lpDrcb) { __PARTITION_EXTENSION* pPe = NULL; __DEVICE_OBJECT* pDevice = (__DEVICE_OBJECT*)lpDev; DWORD dwResult = 0; DWORD dwStart = 0; DWORD dwFlags; if((NULL == lpDev) || (NULL == lpDrcb)) //Invalid parameters. { goto __TERMINAL; } pPe = (__PARTITION_EXTENSION*)pDevice->lpDevExtension; if(NULL == pPe) //Should not occur,or else the OS kernel may have fatal error. { goto __TERMINAL; } //Check the validity of DRCB object transferred. if(DRCB_REQUEST_MODE_READ != lpDrcb->dwRequestMode) //Invalid operation action. { goto __TERMINAL; } if((NULL == lpDrcb->lpOutputBuffer) || (0 == lpDrcb->dwOutputLen)) { goto __TERMINAL; } if(0 != lpDrcb->dwOutputLen % pDevice->dwBlockSize) //Only block size request is //legally. { goto __TERMINAL; } __ENTER_CRITICAL_SECTION(NULL,dwFlags); //Check if current position is in device end. if(pPe->dwCurrPos == pPe->dwSectorNum) { __LEAVE_CRITICAL_SECTION(NULL,dwFlags); goto __TERMINAL; } dwResult = lpDrcb->dwOutputLen / pDevice->dwBlockSize; //Check if exceed the device boundry after read. if(pPe->dwCurrPos + dwResult >= pPe->dwSectorNum) //Exceed end boundry. { dwResult = pPe->dwSectorNum - pPe->dwCurrPos; //Only partial data of the //requested can be read. } dwStart = pPe->dwCurrPos + pPe->dwStartSector; //Read start this position,in sector number. pPe->dwCurrPos += dwResult; //Adjust current pointer. __LEAVE_CRITICAL_SECTION(NULL,dwFlags); //Now issue read command to read data from device. if(!ReadSector(0,dwStart,dwResult,(BYTE*)lpDrcb->lpOutputBuffer)) //Can not read data. { dwResult = 0; goto __TERMINAL; } dwResult *= pDevice->dwBlockSize; //dwResult now is the byte number just read. __TERMINAL: return dwResult; }
int FloppyDrive::ReadSectorLBA(int drive, uint32_t lba) { uint8_t sector = (lba % 18) + 1; uint8_t cylinder = (lba / 18) / 2; uint8_t head = (lba / 18) % 2; return ReadSector(drive ,cylinder, head, sector); }
exp bool Open(const char* fname, unsigned int pO, unsigned int pLen) { partitionOffset = pO; partitionLength = pLen; // Open the image f.open(fname, std::ios::in | std::ios::out | std::ios::binary); if (!f.is_open()) { LastError("Open", "Failed to open disk"); return false; } f.seekg(0, std::ios::end); fsize = (size_t)f.tellg(); f.seekg(0); // Allocate a buffer sectorBuffer = new char[SECTOR_SIZE]; // Read the BPB if (!ReadBPB()) { LastError("Open", "Failed to read the BPB"); return false; } // Read filesystem info fsInfo = new FileSystemInfo; ReadSector((char*)fsInfo, bpb->clusterFSInfo); // Load the root directory if (!DirOpenRoot()) { LastError("Open", "Failed to load the root directory"); return false; } volumeId = new char[DOS83_MAX_LEN + 1]; ReadSector(sectorBuffer, ClusterToSector(bpb->clusterRoot)); DirectoryEntry* entry = FindEntryAttribute(ATTRIB_VOLUME_ID, &directory); if (entry) { memcpy(volumeId, entry->name, DOS83_MAX_LEN); volumeId[11] = 0; } return true; }
inline bool ReadBPB() { bpb = new Bpb(); ReadSector((char*)bpb, 0); // The 1000 years of dirty no good shameful disgusting shame hack bpb->hiddenSectors = 1; return true; }
//read a block block_cache* read_block(int block_num) { block_cache* ret = get_blockLRU(block_num); if (ret!=NULL) return ret; ret = init_block_cache(block_num); if (ReadSector(block_num, (void*)(ret->data))==ERROR) perror("read sector error!"); ret->dirty = 0; set_blockLRU(block_num,ret); return ret; }
// ------------------------------------------------------------------------------------------------ int main(int argc, const char** argv) { // Parse arguments if (argc < 3) { Usage(); return EXIT_FAILURE; } const char* diskPath = argv[1]; const char* bootSectorPath = argv[2]; // Read boot loader char bootLoader[SECTOR_SIZE]; if (!ReadSector(bootSectorPath, bootLoader)) { fprintf(stderr, "Failed to read boot loader: %lu\n", GetLastError()); return EXIT_FAILURE; } // Read sector 0 char curSector[SECTOR_SIZE]; if (!ReadSector(diskPath, curSector)) { fprintf(stderr, "Failed to read current boot sector: %lu\n", GetLastError()); return EXIT_FAILURE; } // Prepare new boot sector preserving the bios parameter block char newSector[SECTOR_SIZE]; memcpy(newSector, bootLoader, SECTOR_SIZE); memcpy(newSector + JMP_CODE_SIZE, curSector + JMP_CODE_SIZE, BIOS_PARAM_BLOCK_SIZE - JMP_CODE_SIZE); // Write sector 0 if (!WriteSector(diskPath, newSector)) { fprintf(stderr, "Failed to write new boot sector: %lu\n", GetLastError()); return EXIT_FAILURE; } // Success! return EXIT_SUCCESS; }
/****************************************************************************** * Function: BYTE SectorRead(DWORD sector_addr, BYTE *buffer) * * Input: sector_addr - Sector address, each sector contains 512-byte * buffer - Buffer where data will be stored * * Output: Returns TRUE if read successful, false otherwise * * Overview: SectorRead reads 512 bytes of data from the card starting * at the sector address specified by sector_addr and stores * them in the location pointed to by 'buffer'. * * Note: The device expects the address field in the command packet * to be byte address. Therefore the sector_addr must first * be converted to byte address. This is accomplished by * shifting the address left 9 times. *****************************************************************************/ BYTE MDD_AT45D_SectorRead(DWORD sector_addr, BYTE* buffer) { // printf("MDD_AT45D_SectorRead %u\r\n", (unsigned int)sector_addr); if (sector_addr >= MDD_AT45D_FLASH_TOTAL_DISK_SIZE) { return FALSE; } ReadSector((uint16_t)sector_addr, buffer); return TRUE; }
bool ReadCluster(FatEntry* entry, char* buffer) { // Load FAT sector if needed - Update FatEntry sector if (entry->sector != GetFATSector(entry->cluster)) { entry->sector = GetFATSector(entry->cluster); ReadSector(entry->buffer, entry->sector); } // Check if we're done if (*(uint32_t*)(entry->buffer + GetFATOffset(entry->cluster)) >= FAT_EOF) { ReadSector(buffer, ClusterToSector(entry->cluster)); return false; } // Read sector ReadSector(buffer, ClusterToSector(entry->cluster)); // Update cluster entry->cluster = *(uint32_t*)(entry->buffer + GetFATOffset(entry->cluster)); return true; }
void *CdrThread(void *arg) { unsigned char curTime[3]; int i; for (;;) { pthread_mutex_lock(&mut); locked = 1; pthread_cond_wait(&cond, &mut); if (stopth == 2) pthread_exit(NULL); // refill the buffer cacheaddr = msf_to_lba(cr.msf.cdmsf_min0, cr.msf.cdmsf_sec0, cr.msf.cdmsf_frame0); memcpy(curTime, &cr.msf, 3); PRINTF("start thc %d:%d:%d\n", curTime[0], curTime[1], curTime[2]); for (i = 0; i < CacheSize; i++) { cdcache[i].cr.msf.cdmsf_min0 = curTime[0]; cdcache[i].cr.msf.cdmsf_sec0 = curTime[1]; cdcache[i].cr.msf.cdmsf_frame0 = curTime[2]; PRINTF("reading %d:%d:%d\n", curTime[0], curTime[1], curTime[2]); cdcache[i].ret = ReadSector((crdata *)&cdcache[i].cr); if (cdcache[i].ret == -1) break; PRINTF("readed %x:%x:%x\n", cdcache[i].cr.buf[12], cdcache[i].cr.buf[13], cdcache[i].cr.buf[14]); cdcache[i].msf[0] = curTime[0]; cdcache[i].msf[1] = curTime[1]; cdcache[i].msf[2] = curTime[2]; curTime[2]++; if (curTime[2] == 75) { curTime[2] = 0; curTime[1]++; if (curTime[1] == 60) { curTime[1] = 0; curTime[0]++; } } if (stopth) break; } pthread_mutex_unlock(&mut); } return NULL; }
//Several helper routines used by DeviceCtrl. static DWORD __CtrlSectorRead(__COMMON_OBJECT* lpDrv, __COMMON_OBJECT* lpDev, __DRCB* lpDrcb) { __PARTITION_EXTENSION* pPe = NULL; __DEVICE_OBJECT* pDevice = (__DEVICE_OBJECT*)lpDev; DWORD dwStartSector = 0; DWORD dwSectorNum = 0; int nDiskNum = 0; DWORD i; DWORD dwFlags; //Parameter validity checking. if((NULL == lpDrcb->lpOutputBuffer) || (0 == lpDrcb->dwOutputLen)) { return 0; } if((NULL == lpDrcb->lpInputBuffer) || (0 == lpDrcb->dwInputLen)) { return 0; } //Get start sector and sector number to read. __ENTER_CRITICAL_SECTION(NULL,dwFlags); pPe = (__PARTITION_EXTENSION*)pDevice->lpDevExtension; dwStartSector = *(DWORD*)(lpDrcb->lpInputBuffer); //Input buffer stores the start pos. if(lpDrcb->dwOutputLen % pDevice->dwBlockSize) //Always integral block size times is valid. { __LEAVE_CRITICAL_SECTION(NULL,dwFlags); return 0; } dwSectorNum = lpDrcb->dwOutputLen / pDevice->dwBlockSize; //Check if the reading data exceed the device boundry. //if((dwStartSector + dwSectorNum) > (pPe->dwStartSector + pPe->dwSectorNum)) if((dwStartSector + dwSectorNum) > pPe->dwSectorNum) { __LEAVE_CRITICAL_SECTION(NULL,dwFlags); return 0; } dwStartSector += pPe->dwStartSector; nDiskNum = pPe->nDiskNum; __LEAVE_CRITICAL_SECTION(NULL,dwFlags); //Now issue the reading command. for(i = 0;i < dwSectorNum;i ++) { if(!ReadSector(nDiskNum,dwStartSector + i,1,((BYTE*)lpDrcb->lpOutputBuffer) + 512*i)) { return FALSE; } } //return ReadSector(nDiskNum,dwStartSector,dwSectorNum,(BYTE*)lpDrcb->lpOutputBuffer); return TRUE; }
exp bool CopyOut(const char* source, const char* dest) { // Convert the filename into DOS8.3 format char* dosName = new char[12]; ToDos83Name(source, dosName); // Find the file on the disk DirectoryEntry* entry = FindEntry(dosName, &directory); if (!entry) { LastError("CopyOut", "File doesn't exist"); return false; } if (!(entry->attrib & ATTRIB_ARCHIVE)) { LastError("CopyOut", "This is not a file"); return false; } // Update the entry UpdateEntry(entry, 0, 0); std::ofstream outHandle(dest, std::ios::out | std::ios::binary); if (!outHandle.is_open()) return false; // Set up a FatEntry FatEntry fatEntry; fatEntry.cluster = GetClusterFromEntry(entry); fatEntry.sector = GetFATSector(fatEntry.cluster); fatEntry.buffer = new char[bpb->bytesPerSector]; ReadSector(fatEntry.buffer, fatEntry.sector); char* sectorData = new char[bpb->bytesPerSector]; // Read Data while (ReadCluster(&fatEntry, sectorData)) outHandle.write(sectorData, 512); if (!(entry->size % bpb->bytesPerSector)) outHandle.write(sectorData, 512); else outHandle.write(sectorData, entry->size % bpb->bytesPerSector); delete[] fatEntry.buffer; delete[] sectorData; delete[] dosName; outHandle.close(); return true; }
BOOL ShowSectorInfo(cwindow *pwin,DWORD dwSec,int nSelDisk,BIOS_DRIVE_PARAM *pDriveParam,int *nErr) { int i,j; int nBufOffset = 0; BYTE btSecBuf[SECTOR_SIZE]; char szitem[80]; char szch; pwin->emptyitem(); pwin->emptyscreen(); if(!ReadSector(dwSec,1,btSecBuf,nSelDisk,pDriveParam)) { *nErr = 1; return FALSE; } for(i=0; i<32; i++) { sprintf(szitem, SECTORINFO, nBufOffset, btSecBuf[nBufOffset],btSecBuf[nBufOffset+1], btSecBuf[nBufOffset+2],btSecBuf[nBufOffset+3], btSecBuf[nBufOffset+4],btSecBuf[nBufOffset+5], btSecBuf[nBufOffset+6],btSecBuf[nBufOffset+7], btSecBuf[nBufOffset+8],btSecBuf[nBufOffset+9], btSecBuf[nBufOffset+10],btSecBuf[nBufOffset+11], btSecBuf[nBufOffset+12],btSecBuf[nBufOffset+13], btSecBuf[nBufOffset+14],btSecBuf[nBufOffset+15]); for(j=0; j<16; j++) { szch = btSecBuf[nBufOffset+j]; if( szch == 0x0a || szch == 0x0d ) { //szch = szch; szch = 0x00; } if(szch == 0) szch = 0x2e; sprintf(szitem,"%s%c",szitem,szch); } pwin->additem(szitem); nBufOffset += 16; } return TRUE; }
BOOL SD_BS_Driver::Read(void *context, ByteAddress phyAddress, UINT32 NumBytes, BYTE *pSectorBuff) { __IO SD_Error errorstatus = SD_OK; NATIVE_PROFILE_HAL_DRIVERS_FLASH(); UINT32 RangeIndex; UINT32 RegionIndex; UINT32 BytesPerSector; BLOCK_CONFIG* pConfig = (BLOCK_CONFIG*)context; if(pConfig->BlockDeviceInformation->FindRegionFromAddress(phyAddress, RegionIndex, RangeIndex)) { ByteAddress StartSector = pConfig->BlockDeviceInformation->PhysicalToSectorAddress( &pConfig->BlockDeviceInformation->Regions[RegionIndex], phyAddress); BytesPerSector = pConfig->BlockDeviceInformation->BytesPerSector; CHIP_WORD *pBuf = (CHIP_WORD*)pSectorBuff; UINT32 offset = phyAddress - (StartSector * pConfig->BlockDeviceInformation->BytesPerSector); UINT32 bytes = (NumBytes + offset > BytesPerSector ? BytesPerSector - offset : NumBytes); while(NumBytes > 0) { if(!ReadSector(StartSector, offset, bytes, pBuf, BytesPerSector)) { errorstatus = SD_StopTransfer(); return FALSE; } offset = 0; pBuf = (CHIP_WORD*)((UINT32)pBuf + bytes); NumBytes -= bytes; StartSector++; bytes = __min(BytesPerSector, NumBytes); } return TRUE; } else { return FALSE; } return TRUE; }
/* * entry->cluster = last cluster (current EOF) * entry->sector = current FAT sector to read/write * entry->buffer = FAT buffer * cluster = new EOF cluster */ void UpdateFAT(FatEntry* entry, uint32_t cluster) { // Update old EOF to point to new cluster *(uint32_t*)(entry->buffer + GetFATOffset(entry->cluster)) = cluster; // Check if we need to load a new FAT sector if (entry->sector != GetFATSector(cluster)) { WriteSector(entry->buffer, entry->sector); entry->sector = GetFATSector(cluster); ReadSector(entry->buffer, entry->sector); } // Set new cluster to EOF *(uint32_t*)(entry->buffer + GetFATOffset(cluster)) = FAT_EOF; WriteSector(entry->buffer, entry->sector); // Update FS Info here? }
BOOL SF_BS_Driver::Read(void *context, ByteAddress phyAddress, UINT32 NumBytes, BYTE *pSectorBuff) { NATIVE_PROFILE_HAL_DRIVERS_FLASH(); UINT32 RangeIndex; UINT32 RegionIndex; UINT32 BytesPerSector; MEMORY_MAPPED_SERIAL_BLOCK_CONFIG* pConfig = (MEMORY_MAPPED_SERIAL_BLOCK_CONFIG*)context; const BlockDeviceInfo * deviceInfo = pConfig->BlockConfig.BlockDeviceInformation; if(deviceInfo->FindRegionFromAddress(phyAddress, RegionIndex, RangeIndex)) { BytesPerSector = deviceInfo->BytesPerSector; SERIAL_WORD *pBuf = (SERIAL_WORD*)pSectorBuff; BlockRegionInfo* pRegion = (BlockRegionInfo*)&deviceInfo->Regions[RegionIndex]; ByteAddress StartSector = phyAddress / deviceInfo->BytesPerSector; UINT32 offset = phyAddress - (StartSector * deviceInfo->BytesPerSector); UINT32 bytes = (NumBytes + offset > BytesPerSector ? BytesPerSector - offset : NumBytes); while(NumBytes > 0) { if(!ReadSector(StartSector, offset, bytes, pBuf, BytesPerSector)) { return FALSE; } offset = 0; pBuf = (SERIAL_WORD*)((UINT32)pBuf + bytes); NumBytes -= bytes; StartSector++; bytes = __min(BytesPerSector, NumBytes); } return TRUE; } else { return FALSE; } }
//The main entry point of WINHD driver. BOOL IDEHdDriverEntry(__DRIVER_OBJECT* lpDrvObj) { __PARTITION_EXTENSION *pPe = NULL; UCHAR Buff[512]; //Set operating functions for lpDrvObj first. lpDrvObj->DeviceRead = DeviceRead; lpDrvObj->DeviceWrite = DeviceWrite; lpDrvObj->DeviceCtrl = DeviceCtrl; //Read the MBR from first HD. if(!ReadSector(0,0,1,(BYTE*)&Buff[0])) { _hx_printf("Can not read MBR from HD [0].\r\n"); return FALSE; } //Analyze the MBR and try to find any file partitions in HD. InitPartitions(0,(BYTE*)&Buff[0],lpDrvObj); return TRUE; }
bool WriteCluster(FatEntry* fatEntry, char* buffer) { // Load FAT sector if needed - Update FatEntry sector if (fatEntry->sector != GetFATSector(fatEntry->cluster)) { fatEntry->sector = GetFATSector(fatEntry->cluster); ReadSector(fatEntry->buffer, fatEntry->sector); } // Write that sector WriteSector(buffer, ClusterToSector(fatEntry->cluster)); // Find a new cluster uint32_t tmpCluster = FindFreeCluster(); UpdateFAT(fatEntry, tmpCluster); fatEntry->cluster = tmpCluster; fsInfo->nextFreeCluster = tmpCluster; fsInfo->freeClusterCount--; return true; }
int GetInode(int inode_num,struct inode *curr_inode) { //printf("\nGetInode Reached Inside"); //print_inode(inode_num,curr_inode); int res,i,sec_num; struct inode *fs=(struct inode *)malloc(SECTORSIZE); if(fs==NULL) { printf("\nNot enough memory available "); return ERROR; } //printf("\nGetInode:Reached 1 "); sec_num=BLOCKSIZE/SECTORSIZE+((inode_num*INODESIZE)/SECTORSIZE); //printf("\nGetInode: Reached 2"); i=(inode_num*INODESIZE)%(SECTORSIZE); i=i/INODESIZE; res=ReadSector(sec_num,(void *)fs); if(res==0) { memcpy(curr_inode,&(fs[i]),INODESIZE); //printf("\fs[i].type=%d",fs[i].type); } else { printf("\nUnsuccessful ReadSector"); free(fs); return ERROR; } //printf("\nGetInode: Reached end"); free(fs); return 0; }
int write_inode(int inode_num,struct inode *curr_inode) { int sec_num,res,i; struct inode *fs; //printf("\nInside Write_inode:Reached"); fs=(struct inode *)malloc(SECTORSIZE); if(fs==NULL) { printf("\nNot enough space in memory"); return ERROR; } sec_num=BLOCKSIZE/SECTORSIZE+((inode_num*INODESIZE)/SECTORSIZE); i=(inode_num*INODESIZE)%SECTORSIZE; i=i/INODESIZE; //printf("\nvalue of written inode is %d",i); res=ReadSector(sec_num,(void *)fs); if(!res) { memcpy((fs+i),curr_inode,INODESIZE); WriteSector(sec_num,(void *)fs); } else printf("\nReadSector Unsuccessful!"); free(fs); return 0; }
exp bool Delete(const char* filename) { // Convert the filename into DOS8.3 format char* dosName = new char[12]; ToDos83Name(filename, dosName); // Find entry DirectoryEntry* entry = FindEntry(dosName, &directory); if (!entry) { LastError("Delete", "Failed to find file"); return false; } if (!(entry->attrib & ATTRIB_ARCHIVE) || (entry->attrib & ATTRIB_DIRECTORY)) { LastError("Delete", "This is not a file"); return false; } entry->name[0] = (char)ATTRIB_DELETED; DirectoryWrite(&directory); //WriteSector(directoryBuffer + ((((char*)entry - directoryBuffer) / 512) * 512),directorySector + (((char*)entry - directoryBuffer) / 512)); // Unlink all clusters FatEntry fatEntry; fatEntry.buffer = new char[bpb->bytesPerSector]; fatEntry.cluster = GetClusterFromEntry(entry); fatEntry.sector = GetFATSector(fatEntry.cluster); ReadSector(fatEntry.buffer, fatEntry.sector); while (DeleteCluster(&fatEntry)) Sleep(1); WriteSector(fatEntry.buffer, fatEntry.sector); delete[] fatEntry.buffer; return false; }
bool DeleteCluster(FatEntry* entry) { // Load FAT sector if needed - Update FatEntry sector if (entry->sector != GetFATSector(entry->cluster)) { WriteSector(entry->buffer, entry->sector); entry->sector = GetFATSector(entry->cluster); ReadSector(entry->buffer, entry->sector); } // Find a new cluster uint32_t tmpCluster = *(uint32_t*)(entry->buffer + GetFATOffset(entry->cluster)); *(uint32_t*)(entry->buffer + GetFATOffset(entry->cluster)) = FAT_FREE; entry->cluster = tmpCluster; WriteSector(entry->buffer, entry->sector); // Update FS Info if (tmpCluster < fsInfo->nextFreeCluster) fsInfo->nextFreeCluster = tmpCluster - 1; fsInfo->freeClusterCount++; return (tmpCluster < FAT_EOF); }
Initialize_Server() { void *fs=malloc(SECTORSIZE); int nfree_block; int i,k; int sec_num=BLOCKSIZE/SECTORSIZE; int size,fsec_num,inum,blk_num,index,nblocks; struct inode *inode_entry; int *free_blocks=NULL; int *free_inodes=NULL; ReadSector(sec_num,fs); num_inodes=(((struct fs_header *)fs)->num_inodes); num_blocks=((struct fs_header *)fs)->num_blocks; nfree_block= num_blocks-2-((num_inodes*INODESIZE)/BLOCKSIZE); max_inode_num=num_inodes; max_block_num=num_blocks-1; num_inodes++; free_blocks=(int *)malloc(sizeof(int)*num_blocks); free_inodes=(int *)malloc(sizeof(int)*num_inodes); for(i=0;i<num_blocks;i++) if(i<(num_blocks-nfree_block)) free_blocks[i]=0; else free_blocks[i]=1; free_inodes[0]=0; sec_num=BLOCKSIZE/SECTORSIZE; fsec_num=BLOCKSIZE/SECTORSIZE+(num_inodes*INODESIZE)/SECTORSIZE; inum=1; while(sec_num<fsec_num) { ReadSector(sec_num,fs); inode_entry=(struct inode *)fs; for(i=0;i<(SECTORSIZE/INODESIZE);i++) { index=inum%(SECTORSIZE/INODESIZE); free_inodes[inum]=1; if(inode_entry[index].type!=INODE_FREE) { free_inodes[inum]=0; size=inode_entry[index].size; nblocks=size/BLOCKSIZE; for(k=0;k<=nblocks;k++) { if(k<NUM_DIRECT) blk_num=inode_entry[index].direct[k]; else blk_num=GetIndirectBlk(inode_entry[index].indirect,k-NUM_DIRECT); free_blocks[blk_num]=0; } } inum++; } sec_num++; } free(fs); for(i=num_inodes-1;i>1;i--) if(free_inodes[i]==1) Add_free_inode(i); for(i=num_blocks-1;i>=num_blocks-nfree_block;i--) if(free_blocks[i]==1) Add_free_blknum(i); free(free_inodes); free(free_blocks); printf("\nValue returned by register is %d\n",Register(FILE_SERVER)); return 0; }
int far pascal __loadds FS_MOUNT(unsigned short usFlag, /* flag */ struct vpfsi far * pvpfsi, /* pvpfsi */ struct vpfsd far * pvpfsd, /* pvpfsd */ unsigned short hVBP, /* hVPB */ char far * pBoot /* pBoot */) { PBOOTSECT pSect; PVOLINFO pVolInfo; PVOLINFO pNext, pPrev; USHORT usVolCount; USHORT hDupVBP; USHORT rc; P_DriverCaps pDevCaps; P_VolChars pVolChars; _asm push es; //_asm push bx; if (f32Parms.fMessageActive & LOG_FS) Message("FS_MOUNT for %c (%d):, flag = %d", pvpfsi->vpi_drive + 'A', pvpfsi->vpi_unit, usFlag); switch (usFlag) { case MOUNT_MOUNT : if (FSH_FINDDUPHVPB(hVBP, &hDupVBP)) hDupVBP = 0; pSect = (PBOOTSECT)pBoot; if (memicmp(pSect->FileSystem, "FAT32", 5)) { rc = ERROR_VOLUME_NOT_MOUNTED; goto FS_MOUNT_EXIT; } if (pSect->bpb.BytesPerSector != SECTOR_SIZE) { rc = ERROR_VOLUME_NOT_MOUNTED; goto FS_MOUNT_EXIT; } if(( ULONG )pSect->bpb.BytesPerSector * pSect->bpb.SectorsPerCluster > MAX_CLUSTER_SIZE ) { rc = ERROR_VOLUME_NOT_MOUNTED; goto FS_MOUNT_EXIT; } pvpfsi->vpi_vid = pSect->ulVolSerial; pvpfsi->vpi_bsize = pSect->bpb.BytesPerSector; pvpfsi->vpi_totsec = pSect->bpb.BigTotalSectors; pvpfsi->vpi_trksec = pSect->bpb.SectorsPerTrack; pvpfsi->vpi_nhead = pSect->bpb.Heads; memset(pvpfsi->vpi_text, 0, sizeof pvpfsi->vpi_text); memcpy(pvpfsi->vpi_text, pSect->VolumeLabel, sizeof pSect->VolumeLabel); pVolInfo = gdtAlloc(STORAGE_NEEDED, FALSE); if (!pVolInfo) { rc = ERROR_NOT_ENOUGH_MEMORY; goto FS_MOUNT_EXIT; } rc = FSH_FORCENOSWAP(SELECTOROF(pVolInfo)); if (rc) FatalMessage("FSH_FORCENOSWAP on VOLINFO Segment failed, rc=%u", rc); memset(pVolInfo, 0, (size_t)STORAGE_NEEDED); InitCache(ulCacheSectors); memcpy(&pVolInfo->BootSect, pSect, sizeof (BOOTSECT)); pVolInfo->ulActiveFatStart = pSect->bpb.ReservedSectors; if (pSect->bpb.ExtFlags & 0x0080) pVolInfo->ulActiveFatStart += pSect->bpb.BigSectorsPerFat * (pSect->bpb.ExtFlags & 0x000F); pVolInfo->ulStartOfData = pSect->bpb.ReservedSectors + pSect->bpb.BigSectorsPerFat * pSect->bpb.NumberOfFATs; pVolInfo->pBootFSInfo = (PBOOTFSINFO)(pVolInfo + 1); pVolInfo->pbFatSector = (PBYTE)(pVolInfo->pBootFSInfo + 1); pVolInfo->ulCurFatSector = -1L; pVolInfo->usClusterSize = pSect->bpb.BytesPerSector * pSect->bpb.SectorsPerCluster; pVolInfo->ulTotalClusters = (pSect->bpb.BigTotalSectors - pVolInfo->ulStartOfData) / pSect->bpb.SectorsPerCluster; pVolInfo->hVBP = hVBP; pVolInfo->hDupVBP = hDupVBP; pVolInfo->bDrive = pvpfsi->vpi_drive; pVolInfo->bUnit = pvpfsi->vpi_unit; pVolInfo->pNextVolInfo = NULL; pVolInfo->fFormatInProgress = FALSE; if (usDefaultRASectors == 0xFFFF) pVolInfo->usRASectors = (pVolInfo->usClusterSize / SECTOR_SIZE ) * 2; else pVolInfo->usRASectors = usDefaultRASectors; #if 1 if( pVolInfo->usRASectors > MAX_RASECTORS ) pVolInfo->usRASectors = MAX_RASECTORS; #else if (pVolInfo->usRASectors > (pVolInfo->usClusterSize / SECTOR_SIZE) * 4) pVolInfo->usRASectors = (pVolInfo->usClusterSize / SECTOR_SIZE ) * 4; #endif if (pSect->bpb.FSinfoSec != 0xFFFF) { ReadSector(pVolInfo, pSect->bpb.FSinfoSec, 1, pVolInfo->pbFatSector, DVIO_OPNCACHE); memcpy(pVolInfo->pBootFSInfo, pVolInfo->pbFatSector + FSINFO_OFFSET, sizeof (BOOTFSINFO)); } else memset(pVolInfo->pBootFSInfo, 0, sizeof (BOOTFSINFO)); *((PVOLINFO *)(pvpfsd->vpd_work)) = pVolInfo; if (!pGlobVolInfo) { pGlobVolInfo = pVolInfo; usVolCount = 1; } else { pNext = pGlobVolInfo; usVolCount = 1; if (pNext->bDrive == pvpfsi->vpi_drive && !pVolInfo->hDupVBP) pVolInfo->hDupVBP = pNext->hVBP; while (pNext->pNextVolInfo) { pNext = (PVOLINFO)pNext->pNextVolInfo; if (pNext->bDrive == pvpfsi->vpi_drive && !pVolInfo->hDupVBP) pVolInfo->hDupVBP = pNext->hVBP; usVolCount++; } pNext->pNextVolInfo = pVolInfo; usVolCount++; } if (f32Parms.fMessageActive & LOG_FS) Message("%u Volumes mounted!", usVolCount); rc = CheckWriteProtect(pVolInfo); if (rc && rc != ERROR_WRITE_PROTECT) { Message("Cannot access drive, rc = %u", rc); goto FS_MOUNT_EXIT; } if (rc == ERROR_WRITE_PROTECT) pVolInfo->fWriteProtected = TRUE; pVolInfo->fDiskCleanOnMount = pVolInfo->fDiskClean = GetDiskStatus(pVolInfo); if (!pVolInfo->fDiskCleanOnMount) Message("DISK IS DIRTY!"); if (pVolInfo->fWriteProtected) pVolInfo->fDiskCleanOnMount = TRUE; if (!pVolInfo->hDupVBP && (f32Parms.fCalcFree || pVolInfo->pBootFSInfo->ulFreeClusters == 0xFFFFFFFF || /*!pVolInfo->fDiskClean ||*/ pVolInfo->BootSect.bpb.FSinfoSec == 0xFFFF)) GetFreeSpace(pVolInfo); pDevCaps = pvpfsi->vpi_pDCS; pVolChars = pvpfsi->vpi_pVCS; if (pDevCaps->Capabilities & GDC_DD_Read2) Message("Read2 supported"); if (pDevCaps->Capabilities & GDC_DD_DMA_Word) Message("DMA on word alligned buffers supported"); if (pDevCaps->Capabilities & GDC_DD_DMA_Byte) Message("DMA on byte alligned buffers supported"); if (pDevCaps->Capabilities & GDC_DD_Mirror) Message("Disk Mirroring supported"); if (pDevCaps->Capabilities & GDC_DD_Duplex) Message("Disk Duplexing supported"); if (pDevCaps->Capabilities & GDC_DD_No_Block) Message("Strategy2 does not block"); if (pDevCaps->Capabilities & GDC_DD_16M) Message(">16M supported"); if (pDevCaps->Strategy2) { Message("Strategy2 address at %lX", pDevCaps->Strategy2); Message("ChgPriority address at %lX", pDevCaps->ChgPriority); pVolInfo->pfnStrategy = (STRATFUNC)pDevCaps->Strategy2; pVolInfo->pfnPriority = (STRATFUNC)pDevCaps->ChgPriority; } rc = 0; break; case MOUNT_ACCEPT : if (FSH_FINDDUPHVPB(hVBP, &hDupVBP)) hDupVBP = 0; if (pvpfsi->vpi_bsize != SECTOR_SIZE) { rc = ERROR_VOLUME_NOT_MOUNTED; goto FS_MOUNT_EXIT; } pVolInfo = gdtAlloc(STORAGE_NEEDED, FALSE); if (!pVolInfo) { rc = ERROR_NOT_ENOUGH_MEMORY; goto FS_MOUNT_EXIT; } rc = FSH_FORCENOSWAP(SELECTOROF(pVolInfo)); if (rc) FatalMessage("FSH_FORCENOSWAP on VOLINFO Segment failed, rc=%u", rc); memset(pVolInfo, 0, (size_t)STORAGE_NEEDED); //InitCache(ulCacheSectors); memset(&pVolInfo->BootSect, 0, sizeof (BOOTSECT)); pVolInfo->BootSect.bpb.BigTotalSectors = pvpfsi->vpi_totsec; pVolInfo->BootSect.bpb.BytesPerSector = pvpfsi->vpi_bsize; pVolInfo->fWriteProtected = FALSE; pVolInfo->fDiskCleanOnMount = FALSE; pVolInfo->hVBP = hVBP; pVolInfo->hDupVBP = hDupVBP; pVolInfo->bDrive = pvpfsi->vpi_drive; pVolInfo->bUnit = pvpfsi->vpi_unit; pVolInfo->pNextVolInfo = NULL; // the volume is being formatted pVolInfo->fFormatInProgress = TRUE; // fake values assuming sector == cluster pVolInfo->usClusterSize = pvpfsi->vpi_bsize; pVolInfo->ulTotalClusters = pvpfsi->vpi_totsec; pVolInfo->usRASectors = usDefaultRASectors; // undefined pVolInfo->ulStartOfData = 0; //*((PVOLINFO *)(pvpfsd->vpd_work)) = pVolInfo; if (!pGlobVolInfo) { pGlobVolInfo = pVolInfo; usVolCount = 1; } else { pNext = pGlobVolInfo; usVolCount = 1; if (pNext->bDrive == pvpfsi->vpi_drive && !pVolInfo->hDupVBP) pVolInfo->hDupVBP = pNext->hVBP; while (pNext->pNextVolInfo) { pNext = (PVOLINFO)pNext->pNextVolInfo; if (pNext->bDrive == pvpfsi->vpi_drive && !pVolInfo->hDupVBP) pVolInfo->hDupVBP = pNext->hVBP; usVolCount++; } pNext->pNextVolInfo = pVolInfo; usVolCount++; } if (f32Parms.fMessageActive & LOG_FS) Message("%u Volumes mounted!", usVolCount); pDevCaps = pvpfsi->vpi_pDCS; pVolChars = pvpfsi->vpi_pVCS; if (pDevCaps->Capabilities & GDC_DD_Read2) Message("Read2 supported"); if (pDevCaps->Capabilities & GDC_DD_DMA_Word) Message("DMA on word alligned buffers supported"); if (pDevCaps->Capabilities & GDC_DD_DMA_Byte) Message("DMA on byte alligned buffers supported"); if (pDevCaps->Capabilities & GDC_DD_Mirror) Message("Disk Mirroring supported"); if (pDevCaps->Capabilities & GDC_DD_Duplex) Message("Disk Duplexing supported"); if (pDevCaps->Capabilities & GDC_DD_No_Block) Message("Strategy2 does not block"); if (pDevCaps->Capabilities & GDC_DD_16M) Message(">16M supported"); if (pDevCaps->Strategy2) { Message("Strategy2 address at %lX", pDevCaps->Strategy2); Message("ChgPriority address at %lX", pDevCaps->ChgPriority); pVolInfo->pfnStrategy = (STRATFUNC)pDevCaps->Strategy2; pVolInfo->pfnPriority = (STRATFUNC)pDevCaps->ChgPriority; } rc = 0; break; case MOUNT_VOL_REMOVED: case MOUNT_RELEASE: pVolInfo = GetVolInfo(hVBP); if (!pVolInfo) { rc = ERROR_VOLUME_NOT_MOUNTED; goto FS_MOUNT_EXIT; } //if (!pVolInfo->hDupVBP) //{ usFlushVolume( pVolInfo, FLUSH_DISCARD, TRUE, PRIO_URGENT ); if (f32Parms.usDirtySectors) // vs UpdateFSInfo(pVolInfo); // MarkDiskStatus(pVolInfo, TRUE); //} // delete pVolInfo from the list if (pGlobVolInfo) { pNext = pPrev = pGlobVolInfo; // search for pVolInfo in the list while (pNext != pVolInfo) { pPrev = pNext; pNext = (PVOLINFO)pNext->pNextVolInfo; } // found if (pNext == pVolInfo) { if (pPrev == pVolInfo) // the very 1st list item pGlobVolInfo = NULL; else { // delete it pNext = pNext->pNextVolInfo; pPrev->pNextVolInfo = pNext; } usVolCount--; } } RemoveVolume(pVolInfo); freeseg(pVolInfo); rc = 0; break; default : rc = ERROR_NOT_SUPPORTED; break; } FS_MOUNT_EXIT: if (f32Parms.fMessageActive & LOG_FS) Message("FS_MOUNT returned %u\n", rc); //_asm int 3 //_asm pop bx; _asm pop es; return rc; }
BOOL SF_BS_Driver::WriteX(void *context, ByteAddress phyAddr, UINT32 NumBytes, BYTE *pSectorBuff, BOOL ReadModifyWrite, BOOL fIncrementDataPtr ) { NATIVE_PROFILE_PAL_FLASH(); UINT32 RangeIndex; UINT32 RegionIndex; UINT32 BytesPerSector; UINT32 offset; UINT32 bytes; BLOCK_CONFIG* pConfig = (BLOCK_CONFIG*)context; SERIAL_WORD *pData, *pWrite; // find the corresponding region if(!pConfig->BlockDeviceInformation->FindRegionFromAddress(phyAddr, RegionIndex, RangeIndex)) return FALSE; pData = (SERIAL_WORD*)pSectorBuff; BytesPerSector = pConfig->BlockDeviceInformation->BytesPerSector; const BlockDeviceInfo * deviceInfo = pConfig->BlockDeviceInformation; BlockRegionInfo* pRegion = (BlockRegionInfo*)&deviceInfo->Regions[RegionIndex]; ByteAddress StartSector = phyAddr / BytesPerSector; offset = phyAddr - (StartSector * BytesPerSector); bytes = (NumBytes + offset > BytesPerSector ? BytesPerSector - offset : NumBytes); while(NumBytes > 0) { // if we are using memset, or if the bytes written are less than the BytesPerSector then do read/modify/write if(!fIncrementDataPtr || (bytes != BytesPerSector)) { if(bytes != BytesPerSector) { if(!ReadSector(StartSector, 0, BytesPerSector, s_sectorBuff, BytesPerSector)) { return FALSE; } } pWrite = (SERIAL_WORD*)&s_sectorBuff[0]; if(fIncrementDataPtr) { memcpy(&pWrite[offset], pData, bytes); } else { memset(&pWrite[offset], *pData, bytes); } } else { pWrite = pData; } SF_Byte_Program((UINT32)(StartSector*BytesPerSector), (unsigned char *)pWrite, BytesPerSector); if(fIncrementDataPtr) pData = (SERIAL_WORD*)((UINT32)pData + bytes); NumBytes -= bytes; offset = 0; StartSector++ ; bytes = __min(BytesPerSector, NumBytes); } return TRUE; }
int far pascal FS_MOUNT(unsigned short usFlag, /* flag */ struct vpfsi far * pvpfsi, /* pvpfsi */ struct vpfsd far * pvpfsd, /* pvpfsd */ unsigned short hVBP, /* hVPB */ char far * pBoot /* pBoot */) { PBOOTSECT pSect; PVOLINFO pVolInfo; PVOLINFO pNext; USHORT usVolCount; USHORT hDupVBP; USHORT rc; P_DriverCaps pDevCaps; P_VolChars pVolChars; if (f32Parms.fMessageActive & LOG_FS) Message("FS_MOUNT for %c (%d):, flag = %d", pvpfsi->vpi_drive + 'A', pvpfsi->vpi_unit, usFlag); switch (usFlag) { case MOUNT_MOUNT : if (FSH_FINDDUPHVPB(hVBP, &hDupVBP)) hDupVBP = 0; pSect = (PBOOTSECT)pBoot; if (memicmp(pSect->FileSystem, "FAT32", 5)) { rc = ERROR_VOLUME_NOT_MOUNTED; goto FS_MOUNT_EXIT; } if (pSect->bpb.BytesPerSector != SECTOR_SIZE) { rc = ERROR_VOLUME_NOT_MOUNTED; goto FS_MOUNT_EXIT; } pvpfsi->vpi_vid = pSect->ulVolSerial; pvpfsi->vpi_bsize = pSect->bpb.BytesPerSector; pvpfsi->vpi_totsec = pSect->bpb.BigTotalSectors; pvpfsi->vpi_trksec = pSect->bpb.SectorsPerTrack; pvpfsi->vpi_nhead = pSect->bpb.Heads; memset(pvpfsi->vpi_text, 0, sizeof pvpfsi->vpi_text); memcpy(pvpfsi->vpi_text, pSect->VolumeLabel, sizeof pSect->VolumeLabel); pVolInfo = gdtAlloc(STORAGE_NEEDED, FALSE); if (!pVolInfo) { rc = ERROR_NOT_ENOUGH_MEMORY; goto FS_MOUNT_EXIT; } rc = FSH_FORCENOSWAP(SELECTOROF(pVolInfo)); if (rc) FatalMessage("FSH_FORCENOSWAP on VOLINFO Segment failed, rc=%u", rc); memset(pVolInfo, 0, (size_t)STORAGE_NEEDED); InitCache(ulCacheSectors); memcpy(&pVolInfo->BootSect, pSect, sizeof (BOOTSECT)); pVolInfo->ulActiveFatStart = pSect->bpb.ReservedSectors; if (pSect->bpb.ExtFlags & 0x0080) pVolInfo->ulActiveFatStart += pSect->bpb.BigSectorsPerFat * (pSect->bpb.ExtFlags & 0x000F); pVolInfo->ulStartOfData = pSect->bpb.ReservedSectors + pSect->bpb.BigSectorsPerFat * pSect->bpb.NumberOfFATs; pVolInfo->pBootFSInfo = (PBOOTFSINFO)(pVolInfo + 1); pVolInfo->pbFatSector = (PBYTE)(pVolInfo->pBootFSInfo + 1); pVolInfo->ulCurFatSector = -1L; pVolInfo->usClusterSize = pSect->bpb.BytesPerSector * pSect->bpb.SectorsPerCluster; pVolInfo->ulTotalClusters = (pSect->bpb.BigTotalSectors - pVolInfo->ulStartOfData) / pSect->bpb.SectorsPerCluster; pVolInfo->hVBP = hVBP; pVolInfo->hDupVBP = hDupVBP; pVolInfo->bDrive = pvpfsi->vpi_drive; pVolInfo->bUnit = pvpfsi->vpi_unit; pVolInfo->pNextVolInfo = NULL; if (usDefaultRASectors == 0xFFFF) pVolInfo->usRASectors = (pVolInfo->usClusterSize * 2) / SECTOR_SIZE; else pVolInfo->usRASectors = usDefaultRASectors; if (pVolInfo->usRASectors > (pVolInfo->usClusterSize * 4) / SECTOR_SIZE) pVolInfo->usRASectors = (pVolInfo->usClusterSize * 4) / SECTOR_SIZE; if (pSect->bpb.FSinfoSec != 0xFFFF) { ReadSector(pVolInfo, pSect->bpb.FSinfoSec, 1, pVolInfo->pbFatSector, DVIO_OPNCACHE); memcpy(pVolInfo->pBootFSInfo, pVolInfo->pbFatSector + FSINFO_OFFSET, sizeof (BOOTFSINFO)); } else memset(pVolInfo->pBootFSInfo, 0, sizeof (BOOTFSINFO)); *((PVOLINFO *)(pvpfsd->vpd_work)) = pVolInfo; if (!pGlobVolInfo) { pGlobVolInfo = pVolInfo; usVolCount = 1; } else { pNext = pGlobVolInfo; usVolCount = 1; if (pNext->bDrive == pvpfsi->vpi_drive && !pVolInfo->hDupVBP) pVolInfo->hDupVBP = pNext->hVBP; while (pNext->pNextVolInfo) { pNext = (PVOLINFO)pNext->pNextVolInfo; if (pNext->bDrive == pvpfsi->vpi_drive && !pVolInfo->hDupVBP) pVolInfo->hDupVBP = pNext->hVBP; usVolCount++; } pNext->pNextVolInfo = pVolInfo; usVolCount++; } if (f32Parms.fMessageActive & LOG_FS) Message("%u Volumes mounted!", usVolCount); rc = CheckWriteProtect(pVolInfo); if (rc && rc != ERROR_WRITE_PROTECT) { Message("Cannot access drive, rc = %u", rc); goto FS_MOUNT_EXIT; } if (rc == ERROR_WRITE_PROTECT) pVolInfo->fWriteProtected = TRUE; pVolInfo->fDiskCleanOnMount = pVolInfo->fDiskClean = GetDiskStatus(pVolInfo); if (!pVolInfo->fDiskCleanOnMount) Message("DISK IS DIRTY!"); if (pVolInfo->fWriteProtected) pVolInfo->fDiskCleanOnMount = TRUE; if (!pVolInfo->hDupVBP && (pVolInfo->pBootFSInfo->ulFreeClusters == 0xFFFFFFFF || !pVolInfo->fDiskClean || pVolInfo->BootSect.bpb.FSinfoSec == 0xFFFF)) GetFreeSpace(pVolInfo); pDevCaps = pvpfsi->vpi_pDCS; pVolChars = pvpfsi->vpi_pVCS; if (pDevCaps->Capabilities & GDC_DD_Read2) Message("Read2 supported"); if (pDevCaps->Capabilities & GDC_DD_DMA_Word) Message("DMA on word alligned buffers supported"); if (pDevCaps->Capabilities & GDC_DD_DMA_Byte) Message("DMA on byte alligned buffers supported"); if (pDevCaps->Capabilities & GDC_DD_Mirror) Message("Disk Mirroring supported"); if (pDevCaps->Capabilities & GDC_DD_Duplex) Message("Disk Duplexing supported"); if (pDevCaps->Capabilities & GDC_DD_No_Block) Message("Strategy2 does not block"); if (pDevCaps->Capabilities & GDC_DD_16M) Message(">16M supported"); if (pDevCaps->Strategy2) { Message("Strategy2 address at %lX", pDevCaps->Strategy2); Message("ChgPriority address at %lX", pDevCaps->ChgPriority); pVolInfo->pfnStrategy = (STRATFUNC)pDevCaps->Strategy2; pVolInfo->pfnPriority = (STRATFUNC)pDevCaps->ChgPriority; } rc = 0; break; case MOUNT_VOL_REMOVED: case MOUNT_RELEASE: pVolInfo = GetVolInfo(hVBP); if (!pVolInfo->hDupVBP) UpdateFSInfo(pVolInfo); RemoveVolume(pVolInfo); freeseg(pVolInfo); rc = 0; break; default : rc = ERROR_NOT_SUPPORTED; break; } FS_MOUNT_EXIT: if (f32Parms.fMessageActive & LOG_FS) Message("FS_MOUNT returned %u\n", rc); return rc; }
/******************************************************************************* * Function Name : MainTrim * Description : STC3115 internal register configuration function * This function has to be called at stable battery voltage during the application magnufacturing * This function is checking itself the propper configuration of the device. *******************************************************************************/ int MainTrim(struct i2c_client *client) { unsigned char IDCode; int ii,error,testnbr; if (client) sav_client = client; else return STC_CONFIG_CLIENT_FAIL; //Check the cut v ersion I2C_ReadByte(0xE0,0x18,&IDCode,1); //read IDcode if(IDCode == 0x13) { return STC_CONFIG_IDCODE_NOTMATCH; } ReadRAM(); //Enter test mode ReadSector(0, Sector0); //read sector 0 ExitTest(); //exit test mode if ( (Sector0[1] & 0x01) == 0 ) { testnbr=0; do { ReadRAM(); //Enter test mode ReadSector(0, Sector0); //read sector 0 ExitTest(); //exit test mode Sector0 [1] = Sector0[1] | 0x01 ; PreWriteNVN(0x40); //Enter test mode WriteSector(6,Sector0);//write sector 0 in 6 ExitTest(); ReadRAM(); //Enter test mode ReadSector(6, Sector6); //read sector 6 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector0[ii] != Sector6[ii]) error++; } testnbr++; } while(error > 0 && testnbr < 5); if (testnbr >= 3) return STC_CONFIG_TEST_FAIL; testnbr=0; do { PreWriteNVN(0x01); //Enter test mode WriteSector(0,Sector6);//write sector 0 in 0 ExitTest(); ReadRAM(); //Enter test mode ReadSector(0, Sector0); //read sector 0 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector0[ii] != Sector6[ii]) error++; } testnbr++; } while(error > 0 && testnbr < 5); } //Check sector 6 status #if defined (CONFIG_MACH_HENDRIX) || \ defined (CONFIG_MACH_LT02) || \ defined (CONFIG_MACH_COCOA7) Sector3 [ 0 ]=0x82 ; Sector3 [ 1 ]=0x8C ; Sector3 [ 2 ]=0xA0 ; Sector3 [ 3 ]=0xB4 ; Sector3 [ 4 ]=0xC8 ; Sector3 [ 5 ]=0x70 ; Sector3 [ 6 ]=0x17 ; Sector3 [ 7 ]=0x27 ; Sector4 [ 0 ]=0x19 ; Sector4 [ 1 ]=0xB2 ; Sector4 [ 2 ]=0x19 ; Sector4 [ 3 ]=0xFA ; Sector4 [ 4 ]=0x19 ; Sector4 [ 5 ]=0x3E ; Sector4 [ 6 ]=0x1A ; Sector4 [ 7 ]=0x6D ; Sector5 [ 0 ]=0x1A ; Sector5 [ 1 ]=0x9D ; Sector5 [ 2 ]=0x1A ; Sector5 [ 3 ]=0xB7 ; Sector5 [ 4 ]=0x1A ; Sector5 [ 5 ]=0xD5 ; Sector5 [ 6 ]=0x1A ; Sector5 [ 7 ]=0x01 ; Sector6 [ 0 ]=0x1B ; Sector6 [ 1 ]=0x6F ; Sector6 [ 2 ]=0x1B ; Sector6 [ 3 ]=0xB1 ; Sector6 [ 4 ]=0x1B ; Sector6 [ 5 ]=0xE7 ; Sector6 [ 6 ]=0x1B ; Sector6 [ 7 ]=0x59 ; ReadRAM(); //Enter test mode ReadSector(7, Sector0); //read sector 7 ReadSector(7, Sector7); //read sector 7 ExitTest(); //exit test mode Sector7 [ 0 ]=0x1C ; Sector7 [ 1 ]=0xF3 ; Sector7 [ 2 ]=0x1C ; Sector7 [ 3 ]=0xA8 ; Sector7 [ 4 ]=0x1D ; error=0; for(ii=0;ii<8;ii++) { if(Sector0[ii] != Sector7[ii]) error++; } testnbr=0; while(error > 0 && testnbr < 5) { PreWriteNVN(0x80); //Enter test mode WriteSector(7,Sector7);//write sector 7 in 7 ExitTest(); ReadRAM(); //Enter test mode ReadSector(7, Sector0); //read sector 7 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector7[ii] != Sector0[ii]) error++; } testnbr++; } //write sector 3 in 3 ReadRAM(); //Enter test mode ReadSector(3, Sector0); //read sector 3 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector0[ii] != Sector3[ii]) error++; } testnbr=0; while(error > 0 && testnbr < 5) { PreWriteNVN(0x08); //Enter test mode WriteSector(3,Sector3);//write sector 3 in 3 ExitTest(); ReadRAM(); //Enter test mode ReadSector(3, Sector0); //read sector 3 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector3[ii] != Sector0[ii]) error++; } testnbr++; } //write sector 4 in 4 ReadRAM(); //Enter test mode ReadSector(4, Sector0); //read sector 4 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector0[ii] != Sector4[ii]) error++; } testnbr=0; while(error > 0 && testnbr < 5) { PreWriteNVN(0x10); //Enter test mode WriteSector(4,Sector4);//write sector 4 in 4 ExitTest(); ReadRAM(); //Enter test mode ReadSector(4, Sector0); //read sector 4 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector4[ii] != Sector0[ii]) error++; } testnbr++; } //write sector 5 in 5 ReadRAM(); //Enter test mode ReadSector(5, Sector0); //read sector 5 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector0[ii] != Sector5[ii]) error++; } testnbr=0; while(error > 0 && testnbr < 5) { PreWriteNVN(0x20); //Enter test mode WriteSector(5,Sector5);//write sector 5 in 5 ExitTest(); ReadRAM(); //Enter test mode ReadSector(5, Sector0); //read sector 5 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector5[ii] != Sector0[ii]) error++; } testnbr++; } //write sector 6 in 6 ReadRAM(); //Enter test mode ReadSector(6, Sector0); //read sector 6 ExitTest(); //exit test mode #else Sector6 [ 0 ]=0x1B ; Sector6 [ 1 ]=0xCD ; Sector6 [ 2 ]=0x1B ; Sector6 [ 3 ]=0x13 ; Sector6 [ 4 ]=0x1C ; Sector6 [ 5 ]=0x57 ; Sector6 [ 6 ]=0x1C ; Sector6 [ 7 ]=0x09 ; ReadRAM(); //Enter test mode ReadSector(6, Sector0); //read sector 0 ExitTest(); //exit test mode #endif error=0; for(ii=0;ii<8;ii++) { if(Sector0[ii] != Sector6[ii]) error++; } testnbr=0; while(error > 0 && testnbr < 5) { PreWriteNVN(0x40); //Enter test mode WriteSector(6,Sector6);//write sector 6 in 6 ExitTest(); ReadRAM(); //Enter test mode ReadSector(6, Sector0); //read sector 0 ExitTest(); //exit test mode error=0; for(ii=0;ii<8;ii++) { if(Sector0[ii] != Sector6[ii]) error++; } testnbr++; } return -1; }