Пример #1
0
AtaError _AtaReadFatEntry(AtaCluster Cluster, AtaState *pAtaDrive, int *last_cluster, AtaCluster *NeededCluster)
{
    AtaSector ll;
    AtaUint16 jj, nn;
    AtaError ret_stat = ATA_ERROR_NONE;

    /* calculate physical sector and word offset of current cluster entry in FAT */
    /* ll is the sector
     * jj is the offset into the sector
     * kk is what is read in the sector + offset address
     * nn is the alignment of the FAT entry in the word */
    ll = _AtaCalculatePhySectorAndOffsetOfFatEntry(Cluster, pAtaDrive, &jj, &nn);
    ret_stat = _AtaReadFatEntryAtPhySector(ll, pAtaDrive, jj, nn, last_cluster, NeededCluster);
    return(ret_stat);
}
Пример #2
0
AtaUint32 ATA_diskUsed(AtaState *pAtaState, AtaError *ret_stat)
{  /*returns in KB.*/
  int i,j, LastCluster = 0;
  AtaUint32 size=0;
  AtaUint32 tempsize, fatmarker = 0;
  AtaCluster NumClusters = 0, tempCluster = 0;AtaSector PhySector = 0;
  AtaUint16 FatEntryOffset = 0, FatEntryAlignment = 0;
  AtaSector firstFat=pAtaState->FirstFatSector;
  AtaUint16 *_AtaWriteBuffer = pAtaState->_AtaWriteBuffer;
  if (pAtaState==NULL) *ret_stat = ATA_ERROR_INVALID_PARAM; //KR042610
  else                 *ret_stat = ATA_ERROR_NONE;

  *ret_stat = ATA_ERROR_NONE;
  switch(pAtaState->FatType) {
  	case ATA_FAT_TYPE_12:
		  NumClusters = (AtaCluster)((pAtaState->TotalSectors-pAtaState->RootDirSector)/pAtaState->LogSectorsPerCluster);
		  for(i=0;i<NumClusters;i++) {
			PhySector = _AtaCalculatePhySectorAndOffsetOfFatEntry((AtaCluster)i, pAtaState, &FatEntryOffset, &FatEntryAlignment);
			*ret_stat = _AtaReadFatEntryAtPhySector(PhySector, pAtaState, FatEntryOffset, FatEntryAlignment, &LastCluster, &tempCluster);
		  	if(tempCluster!=0) size++; }
		  break;
  	case ATA_FAT_TYPE_16:
		  for(i=0;i<pAtaState->LogSectorsPerFat;i++) {
		  *ret_stat = _AtaReadSector(firstFat++, pAtaState, &_AtaWriteBuffer[0], 0);
		  tempsize=0;
		  for(j=0;j<ATA_WORDS_PER_PHY_SECTOR;j++)
		  if(_AtaWriteBuffer[j]!=0) tempsize++;
		  size+=tempsize; }
		  break;
  	case ATA_FAT_TYPE_32:
		  for(i=0;i<pAtaState->LogSectorsPerFat;i++) {
		  *ret_stat = _AtaReadSector(firstFat++, pAtaState, &_AtaWriteBuffer[0], 0);
		  tempsize=0;
		  for(j=0;j<ATA_WORDS_PER_PHY_SECTOR;j+=2) {
		  	fatmarker = (AtaUint32)_AtaWriteBuffer[j];
		  	fatmarker = (fatmarker&0x0000ffff) << 16;
		  	fatmarker |= (AtaUint32)_AtaWriteBuffer[j+1];
		  	if(fatmarker!=0) tempsize++; }
		  size+=tempsize; }
		  break;
  	default:
		  break;
  }
/*  return ((size*pAtaState->WordsPerCluster)/512);*/ /*SUSMIT - Original Implementation*/
/*  return (size*(pAtaState->WordsPerCluster/512));*//*SUSMIT - Fails for disks with cluster size of 512 bytes*/
  return ((size*(pAtaState->WordsPerCluster/256))/2);
}
Пример #3
0
AtaError ATA_format(AtaState *pDrive, int flag)
{
	AtaSector testsector, testsector1;
	int x; AtaError ret_stat = ATA_ERROR_NONE;
    AtaUint16 *_AtaWriteBuffer = pDrive->_AtaWriteBuffer;
    AtaUint16 _AtaWriteBuffer1[256];
/*SUSMIT - FAT32 format fix*/
  AtaSector PhySector;
  AtaUint16 fOffset, fAlign;
  AtaCluster write_cluster, RootCluster;
  int LastCluster = 0;
  unsigned short FatNo;
/*SUSMIT - FAT32 format fix*/

    if (pDrive==NULL) return(ATA_ERROR_INVALID_PARAM); //KR042810

	for(x=0; x< 256; x++) _AtaWriteBuffer1[x] = 0;
/*Removed this on order to reduce memory, we won't remember boot records
so, our format won't be able to fix disks with Bad MBR/BR but will
be able to format*/
#if 0
	switch(pDrive->FatType) {
      case ATA_FAT_TYPE_12:
        /*write MBR*/
        ret_stat = _AtaReadSector((AtaSector)0, pDrive, &_AtaWriteBuffer[0], 0);
        if(ret_stat) return(ret_stat);
        ret_stat = pDrive->AtaWriteSector((AtaSector)0, pDrive->pAtaMediaState, &MBR_8MB_FAT12_MMC[0], 0);
        if(ret_stat) return(ret_stat);
        /*Write BR*/
        ret_stat = _AtaReadSector((AtaSector)pDrive->BootPhySector, pDrive, &_AtaWriteBuffer[0], 0);
        if(ret_stat) return(ret_stat);
        ret_stat = pDrive->AtaWriteSector((AtaSector)pDrive->BootPhySector, pDrive->pAtaMediaState, &BR_8MB_FAT12_MMC[0], 0);
        if(ret_stat) return(ret_stat);
        break;
      case ATA_FAT_TYPE_16:
        /*Write MBR*/
        ret_stat = _AtaReadSector((AtaSector)0, pDrive, &_AtaWriteBuffer[0], 0);
        if(ret_stat) return(ret_stat);
        ret_stat = pDrive->AtaWriteSector((AtaSector)0, pDrive->pAtaMediaState, &MBR_32MB_FAT16_MMC[0], 0);
        if(ret_stat) return(ret_stat);
        /*Write BR*/
        ret_stat = _AtaReadSector((AtaSector)pDrive->BootPhySector, pDrive, &_AtaWriteBuffer[0], 0);
        if(ret_stat) return(ret_stat);
        ret_stat = pDrive->AtaWriteSector((AtaSector)pDrive->BootPhySector, pDrive->pAtaMediaState, &BR_32MB_FAT16_MMC[0], 0);
        if(ret_stat) return(ret_stat);
        break;
      case ATA_FAT_TYPE_32:
        /*Write MBR*/
        ret_stat = _AtaReadSector((AtaSector)0, pDrive, &_AtaWriteBuffer[0], 0);
        if(ret_stat) return(ret_stat);
        ret_stat = pDrive->AtaWriteSector((AtaSector)0, pDrive->pAtaMediaState, &MBR_32MB_FAT16_MMC[0], 0);
        if(ret_stat) return(ret_stat);
        /*Write BR*/
        ret_stat = _AtaReadSector((AtaSector)pDrive->BootPhySector, pDrive, &_AtaWriteBuffer[0], 0);
        if(ret_stat) return(ret_stat);
        ret_stat = pDrive->AtaWriteSector((AtaSector)pDrive->BootPhySector, pDrive->pAtaMediaState, &BR_32MB_FAT16_MMC[0], 0);
        if(ret_stat) return(ret_stat);
        break;
      default: return(ATA_ERROR_BAD_MEDIA);
    }
#endif
	/*Clear FAT*/
	if(pDrive->FatType == ATA_FAT_TYPE_32) {
/*SUSMIT - FAT32 format fix*/
    RootCluster = _AtaReadDoubleWord(pDrive->BootPhySector, pDrive, 44);			/* Fat Size/Sector Count  byte 36 - 39 */
	ret_stat = _AtaReadSector((AtaSector)pDrive->RootDirSector, pDrive, &_AtaWriteBuffer[0], 0);
	if(ret_stat) return(ret_stat);
	_AtaWriteBuffer1[0] = 0xFFF8;
	_AtaWriteBuffer1[1] = 0xFFFF;
	_AtaWriteBuffer1[2] = 0xFFF8;
	_AtaWriteBuffer1[3] = 0xFFFF;
	_AtaWriteBuffer1[4] = 0xFFF8;
	_AtaWriteBuffer1[5] = 0xFFFF;
	ret_stat = pDrive->AtaWriteSector((AtaSector)pDrive->RootDirSector, pDrive->pAtaMediaState, &_AtaWriteBuffer1[0], 0);
	if(ret_stat) return(ret_stat);
    ret_stat = pDrive->AtaWriteSectorFlush(pDrive->pAtaMediaState);
    if(ret_stat) return(ret_stat);
	for(FatNo=0; FatNo<pDrive->NumberOfFats; FatNo++)
	{
      PhySector = _AtaCalculatePhySectorAndOffsetOfFatEntry(RootCluster, pDrive, &fOffset, &fAlign);
		PhySector +=
		(
		  (unsigned long)FatNo *
		  pDrive->LogSectorsPerFat *
		  (unsigned long)(pDrive->WordsPerLogSector/ATA_WORDS_PER_PHY_SECTOR)
		);
	  ret_stat = _AtaReadFatEntryAtPhySector(PhySector, pDrive, fOffset, fAlign, &LastCluster, &write_cluster);
	  if(ret_stat) return(ret_stat);
      ret_stat = _AtaWriteFatEntryAtPhySector(PhySector, pDrive, 0x0FFFFFFF, fOffset, fAlign, 1,1);
	  if(ret_stat) return(ret_stat);
	}
/*SUSMIT - FAT32 format fix*/
	}
	else {
	testsector=pDrive->FirstFatSector;
	ret_stat = _AtaReadSector((AtaSector)testsector, pDrive, &_AtaWriteBuffer[0], 0);
	if(ret_stat) return(ret_stat);
	_AtaWriteBuffer1[0] = 0xFFF8;
	_AtaWriteBuffer1[1] = 0xFFFF;
	ret_stat = pDrive->AtaWriteSector((AtaSector)testsector++, pDrive->pAtaMediaState, &_AtaWriteBuffer1[0], 0);
	if(ret_stat) return(ret_stat);
    ret_stat = pDrive->AtaWriteSectorFlush(pDrive->pAtaMediaState);
    if(ret_stat) return(ret_stat);
	_AtaWriteBuffer1[0] = 0;
	_AtaWriteBuffer1[1] = 0;
	testsector1 = pDrive->FirstFatSector+pDrive->LogSectorsPerFat;
	while(testsector<testsector1) {
      ret_stat = _AtaReadSector((AtaSector)testsector, pDrive, &_AtaWriteBuffer[0], 0);
      if(ret_stat) return(ret_stat);
      ret_stat = pDrive->AtaWriteSector((AtaSector)testsector++, pDrive->pAtaMediaState, &_AtaWriteBuffer1[0], 0);
      if(ret_stat) return(ret_stat);
      ret_stat = pDrive->AtaWriteSectorFlush(pDrive->pAtaMediaState);
      if(ret_stat) return(ret_stat);
    }
    ret_stat = _AtaReadSector((AtaSector)testsector, pDrive, &_AtaWriteBuffer[0], 0);
	if(ret_stat) return(ret_stat);
	_AtaWriteBuffer1[0] = 0xFFF8;
	_AtaWriteBuffer1[1] = 0xFFFF;
	ret_stat = pDrive->AtaWriteSector((AtaSector)testsector++, pDrive->pAtaMediaState, &_AtaWriteBuffer1[0], 0);
	if(ret_stat) return(ret_stat);
    ret_stat = pDrive->AtaWriteSectorFlush(pDrive->pAtaMediaState);
    if(ret_stat) return(ret_stat);
	_AtaWriteBuffer1[0] = 0;
	_AtaWriteBuffer1[1] = 0;
	testsector1 = pDrive->FirstDataSector;
	while(testsector<testsector1) {
      ret_stat = _AtaReadSector((AtaSector)testsector, pDrive, &_AtaWriteBuffer[0], 0);
      if(ret_stat) return(ret_stat);
      ret_stat = pDrive->AtaWriteSector((AtaSector)testsector++, pDrive->pAtaMediaState, &_AtaWriteBuffer1[0], 0);
      if(ret_stat) return(ret_stat);
      ret_stat = pDrive->AtaWriteSectorFlush(pDrive->pAtaMediaState);
      if(ret_stat) return(ret_stat);
    } }
	/*only for full format*/
	if (flag) {
	testsector = pDrive->FirstDataSector;
	while(testsector<=pDrive->TotalSectors) {
      ret_stat = _AtaReadSector((AtaSector)testsector, pDrive, &_AtaWriteBuffer[0], 0);
      if(ret_stat) return(ret_stat);
      ret_stat = pDrive->AtaWriteSector((AtaSector)testsector++, pDrive->pAtaMediaState, &_AtaWriteBuffer1[0], 0);
      if(ret_stat) return(ret_stat);
      ret_stat = pDrive->AtaWriteSectorFlush(pDrive->pAtaMediaState);
      if(ret_stat) return(ret_stat);
    } }
/* SUSMIT - 25 FEB 2003 - NMP*/
/*	ret_stat = ATA_systemInit(pDrive);*/
	ret_stat = ATA_systemInit(pDrive,0);
/* SUSMIT - 25 FEB 2003 - NMP*/
	return(ret_stat);
}