Esempio n. 1
0
AtaError ATA_setDateTime(AtaFile *pAtaFile)
{
  AtaUint16 jj;
  AtaUint32 ll;
  AtaState *pAtaDrive=pAtaFile->pDrive;
  AtaError ret_stat = ATA_ERROR_NONE;
  AtaUint16 *_AtaWriteBuffer = pAtaDrive->_AtaWriteBuffer;

  if (pAtaFile==NULL) return(ATA_ERROR_INVALID_PARAM); //KR042610

  ll = _AtaCalculatePhySectorAndOffsetFromDirEntry((AtaUint32)pAtaFile->CurrentDirEntry, (AtaUint16 *)&jj, pAtaFile, &ret_stat);
  if(ret_stat) return(ret_stat);
  ret_stat = _AtaReadSector(ll, pAtaDrive, &_AtaWriteBuffer[0], 0);
  if(ret_stat) return(ret_stat);

  /*  Update directory entry*/
  jj+=11;
  _AtaWriteBuffer[jj++] = pAtaFile->Time = pAtaDrive->get_mod_time();
  _AtaWriteBuffer[jj] = pAtaFile->Date = pAtaDrive->get_mod_date();

  /*  Commit replacement directory entry sector to disk*/
  ret_stat = _AtaFlush(pAtaDrive);
  if(ret_stat) return(ret_stat);
  ret_stat = pAtaDrive->AtaWriteSector(ll, pAtaDrive->pAtaMediaState, &_AtaWriteBuffer[0], 0);
  if(ret_stat) return(ret_stat);
  ret_stat = pAtaDrive->AtaWriteSectorFlush(pAtaDrive->pAtaMediaState);
  return(ret_stat);
}
Esempio n. 2
0
AtaError ATA_setAttr(AtaFile *pAtaFile, AtaUint16 Attr)
{
  AtaUint16 jj;
  AtaUint32 ll;
  AtaState *pAtaDrive=pAtaFile->pDrive;
  AtaError ret_stat = ATA_ERROR_NONE;
  AtaUint16 *_AtaWriteBuffer = pAtaDrive->_AtaWriteBuffer;

  if (pAtaFile==NULL) return(ATA_ERROR_INVALID_PARAM); //KR042610

  ll = _AtaCalculatePhySectorAndOffsetFromDirEntry((AtaUint32)pAtaFile->CurrentDirEntry, (AtaUint16 *)&jj, pAtaFile, &ret_stat);
  if(ret_stat) return(ret_stat);
  ret_stat = _AtaReadSector(ll, pAtaDrive, &_AtaWriteBuffer[0], 0);
  if(ret_stat) return(ret_stat);

  /*  Update directory entry*/
  jj+=5;
/*  _AtaWriteBuffer[jj] |= Attr << 8;*/  /*SUSMIT - Absolute attribute setting BUGGIX*/
  _AtaWriteBuffer[jj] &= 0x00ff;
  _AtaWriteBuffer[jj] |= Attr << 8;
  pAtaFile->Attributes = Attr;

  /*  Commit replacement directory entry sector to disk*/
  ret_stat = _AtaFlush(pAtaDrive);
  if(ret_stat) return(ret_stat);
  ret_stat = pAtaDrive->AtaWriteSector(ll, pAtaDrive->pAtaMediaState, &_AtaWriteBuffer[0], 0);
  if(ret_stat) return(ret_stat);
  ret_stat = pAtaDrive->AtaWriteSectorFlush(pAtaDrive->pAtaMediaState);
  return(ret_stat);
}
Esempio n. 3
0
AtaError ATA_getLongName(AtaFile *pAtaFile, char *LongName, AtaUint16 StartOffset, AtaUint16 Length)
{
  register char *cc;
    AtaError ret_stat = ATA_ERROR_NONE;
    AtaUint32 ll;AtaUint16 kk;
    short jj = 0;long lll;
    AtaState *pAtaDrive = pAtaFile->pDrive;
    AtaUint16 *_AtaWriteBuffer = pAtaDrive->_AtaWriteBuffer;
    AtaUint16 exit_flag = 0;
    AtaUint16 NumLFNEntry = 0;
    int i,j;AtaUint16 icnt = 0;
    AtaUint16 file_cksum = _Ata_lfn_checksum(pAtaFile);

    if ((pAtaFile==NULL)||(pAtaDrive==NULL)) return(ATA_ERROR_INVALID_PARAM); //KR042610

    file_cksum = file_cksum<<8;
    file_cksum &= 0xff00;

    ll = _AtaCalculatePhySectorAndOffsetFromDirEntry((AtaUint32)pAtaFile->CurrentDirEntry, (AtaUint16 *)&jj, pAtaFile, &ret_stat);
    if(ret_stat) return(ret_stat);
    ret_stat = _AtaReadSector(ll, pAtaDrive, &_AtaWriteBuffer[0], 0);
    if(ret_stat) return(ret_stat);
    kk=jj;
    jj-=16;
/*SUSMIT - Fix for UNICODE*/
/*    while(((_AtaWriteBuffer[jj+5] == 0x0F00)||(_AtaWriteBuffer[jj+5] == 0x0FFF))&&(jj>=0)&&(!exit_flag)&&(_AtaWriteBuffer[jj+6] == file_cksum)) {*/
    while((((_AtaWriteBuffer[jj+5]&0xff00) == 0x0F00)||(_AtaWriteBuffer[jj+5] == 0x0FFF))&&(jj>=0)&&(!exit_flag)&&(_AtaWriteBuffer[jj+6] == file_cksum)) {
/*SUSMIT - Fix for UNICODE*/
      if(_AtaWriteBuffer[jj]&0x0040) exit_flag = 1;
      NumLFNEntry++;
      jj-=16; }
/*SUSMIT - Code to check for corner cases*/
	if((!exit_flag)&&((NumLFNEntry)||(kk==0))) {

     ret_stat = AtaGetLFN(ll, pAtaDrive, LongName, &icnt, kk, jj, Length, NumLFNEntry);
      		NumLFNEntry = 0;
    if(ret_stat) return(ret_stat);

/*Susmit - Fix for .*/
    lll = (AtaUint32)pAtaFile->CurrentDirEntry-16-(AtaUint16)(kk%16);
    if(lll<0) lll = (AtaUint32)pAtaFile->CurrentDirEntry;
    ll = _AtaCalculatePhySectorAndOffsetFromDirEntry((AtaUint32)(lll), (AtaUint16 *)&jj, pAtaFile, &ret_stat);
/*Susmit - Fix for .*/
/*    ll = _AtaCalculatePhySectorAndOffsetFromDirEntry(((AtaUint32)pAtaFile->CurrentDirEntry-16-(AtaUint16)(kk%16)), (AtaUint16 *)&jj, pAtaFile, &ret_stat);*/
    if(ret_stat) return(ret_stat);
    ret_stat = _AtaReadSector(ll, pAtaDrive, &_AtaWriteBuffer[0], 0);
    if(ret_stat) return(ret_stat);
    jj = 256;
    kk=jj;
    jj-=16;
/*SUSMIT - Fix for UNICODE*/
/*    while(((_AtaWriteBuffer[jj+5] == 0x0F00)||(_AtaWriteBuffer[jj+5] == 0x0FFF))&&(jj>=0)&&(!exit_flag)&&(_AtaWriteBuffer[jj+6] == file_cksum)) {*/
    while((((_AtaWriteBuffer[jj+5]&0xff00) == 0x0F00)||(_AtaWriteBuffer[jj+5] == 0x0FFF))&&(jj>=0)&&(!exit_flag)&&(_AtaWriteBuffer[jj+6] == file_cksum)) {
/*SUSMIT - Fix for UNICODE*/
      if(_AtaWriteBuffer[jj]&0x0040) exit_flag = 1;
      NumLFNEntry++;
      jj-=16; }
	}
/*SUSMIT - Code to check for corner cases*/
    if(NumLFNEntry) {
     ret_stat = AtaGetLFN(ll, pAtaDrive, LongName, &icnt, kk, jj, Length, NumLFNEntry);
      		NumLFNEntry = 0;
     if(ret_stat) return(ret_stat);
 /*End of filename collection, now need to put '\0' at proper place - SUSMIT*/
/*SUSMIT - Fix for UNICODE of more than 208 characters*/
	if(!exit_flag) {
    ll = _AtaCalculatePhySectorAndOffsetFromDirEntry((AtaUint32)(lll-16), (AtaUint16 *)&jj, pAtaFile, &ret_stat);
    if(ret_stat) return(ret_stat);
    ret_stat = _AtaReadSector(ll, pAtaDrive, &_AtaWriteBuffer[0], 0);
    if(ret_stat) return(ret_stat);
    jj = 256;
    kk=jj;
    jj-=16;
/*SUSMIT - Fix for UNICODE*/
/*    while(((_AtaWriteBuffer[jj+5] == 0x0F00)||(_AtaWriteBuffer[jj+5] == 0x0FFF))&&(jj>=0)&&(!exit_flag)&&(_AtaWriteBuffer[jj+6] == file_cksum)) {*/
    while((((_AtaWriteBuffer[jj+5]&0xff00) == 0x0F00)||(_AtaWriteBuffer[jj+5] == 0x0FFF))&&(jj>=0)&&(!exit_flag)&&(_AtaWriteBuffer[jj+6] == file_cksum)) {
/*SUSMIT - Fix for UNICODE*/
      if(_AtaWriteBuffer[jj]&0x0040) exit_flag = 1;
      NumLFNEntry++;
      jj-=16; }
	}
/*SUSMIT - Code to check for corner cases*/
    if(NumLFNEntry) {
     ret_stat = AtaGetLFN(ll, pAtaDrive, LongName, &icnt, kk, jj, Length, NumLFNEntry);
      		NumLFNEntry = 0;
     if(ret_stat) return(ret_stat);
	}
/*SUSMIT - Fix for UNICODE of more than 208 characters*/
      if(icnt < Length) LongName[icnt] = '\0';
/*SUSMIT - No need to worry about zeroes if we get the full LFN, they will come automatically from LFN entries*/
    }
    else {
       cc = pAtaFile->Filename;
       i = 0;j = 0;
       while((*cc!=' ')&&(i<Length)&&(*cc!='\0')) {LongName[i++] = pAtaFile->Filename[j++];cc++;}
       cc = pAtaFile->Ext; j = 0;
       if((i<Length)&&(*cc!=' ')&&(*cc!='\0')) LongName[i++] = '.';
       while((*cc!=' ')&&(i<Length)&&(*cc!='\0')) {LongName[i++] = pAtaFile->Ext[j++];cc++;}
      if(i<Length) LongName[i] = '\0'; }
  return(ret_stat);
}
Esempio n. 4
0
AtaError ATA_deleteLong(AtaFile *pAtaFile)
{
    int last_cluster;
    AtaError ret_stat = ATA_ERROR_NONE;
    AtaUint32 ll;
    unsigned short jj = 0;
/*SUSMIT - New LFN Fix*/
	AtaUint16 deleteflag = 0;
/*SUSMIT - New LFN Fix*/
    AtaState *pAtaDrive = pAtaFile->pDrive;
    AtaUint16 *_AtaWriteBuffer = pAtaDrive->_AtaWriteBuffer;
    AtaUint32 direntrycounter, dircounterstart = 0;
    AtaUint16 entriespersector = pAtaDrive->WordsPerLogSector/16;
    AtaUint16 file_cksum = _Ata_lfn_checksum(pAtaFile);

	if (pAtaFile==NULL) return(ATA_ERROR_INVALID_PARAM); //KR042610

    file_cksum = file_cksum<<8;
    file_cksum &= 0xff00;

  	if(pAtaFile->CurrentDirEntry>20) {dircounterstart = (AtaUint32)(pAtaFile->CurrentDirEntry-20);
  	dircounterstart-=(AtaUint32)(dircounterstart%entriespersector);}
/*SUSMIT - This magic number 20 comes from the limitation that an LFN can contain max 255
characters & all the entries are contiguous*/
  for(direntrycounter = dircounterstart; direntrycounter <= pAtaFile->CurrentDirEntry; direntrycounter += entriespersector) {
    ll = _AtaCalculatePhySectorAndOffsetFromDirEntry((AtaUint32)direntrycounter, (AtaUint16 *)&jj, pAtaFile, &ret_stat);
    if(ret_stat) return(ret_stat);
    ret_stat = _AtaReadSector(ll, pAtaDrive, &_AtaWriteBuffer[0], 0);
    if(ret_stat) return(ret_stat);
    while(jj<256) {
    if((((_AtaWriteBuffer[jj+5]&0xff00) == 0x0F00)||(_AtaWriteBuffer[jj+5] == 0x0FFF))&&(_AtaWriteBuffer[jj+6] == file_cksum))
/*SUSMIT - New LFN Fix*/
     { if(((_AtaWriteBuffer[jj]&0x0040)==0x0040)&&((_AtaWriteBuffer[jj]&0x000f)==(pAtaFile->CurrentDirEntry-(direntrycounter+jj/entriespersector)))) deleteflag = 1;
/*SUSMIT - New LFN deletion modification to save characters*/
/*     	if(deleteflag){ _AtaWriteBuffer[jj] = '\xE5'; }*/
     	if(deleteflag){ _AtaWriteBuffer[jj] = (_AtaWriteBuffer[jj]&0xff00)|0x00E5; }
/*SUSMIT - New LFN deletion modification to save characters*/
      }
    jj+=16;
/*SUSMIT - New LFN Fix*/
    }
    ret_stat = _AtaFlush(pAtaDrive);
    if(ret_stat) return(ret_stat);
    ret_stat = pAtaDrive->AtaWriteSector(ll, pAtaDrive->pAtaMediaState, &_AtaWriteBuffer[0], 0);
    if(ret_stat) return(ret_stat);
    ret_stat = pAtaDrive->AtaWriteSectorFlush(pAtaDrive->pAtaMediaState);
    if(ret_stat) return(ret_stat);
  }
/*Deletion of 8.3 directory entry & actual file - Susmit*/
    pAtaFile->PrevBrokenCluster = pAtaFile->NextBrokenCluster = pAtaFile->Cluster = pAtaFile->StartCluster;
    pAtaFile->Filename[0] = '\xE5';
    if(_AtaCreate(pAtaFile,2,0))
    {
      return(1);
    }
/*SUSMIT - Directory Delete FAT Updation Bug Fix*/
/* if(pAtaFile->Size!=0) {*/
/* if((pAtaFile->Size!=0)||(pAtaFile->Attributes == ATA_ATTR_DIRECTORY)) *//*SUSMIT - Directory Attribute Fix*/
 if((pAtaFile->Size!=0)||(ATA_isDir(pAtaFile))) 
/*SUSMIT - Directory Delete FAT Updation Bug Fix*/
    {
      do
      {
/*SUSMIT - New delete change due to modification in _AtaFindNextBrokenCluster*/
/*        ret_stat = _AtaFindNextBrokenCluster(pAtaFile,1);*/
        ret_stat = _AtaFindNextBrokenCluster(pAtaFile,0);
/*SUSMIT - New delete change due to modification in _AtaFindNextBrokenCluster*/
        if(ret_stat == ATA_ERROR_EOF) ret_stat = ATA_ERROR_NONE;
        if(ret_stat) return(ret_stat);

        ret_stat = _AtaReadFatEntry(pAtaFile->NextBrokenCluster, pAtaDrive, &last_cluster, &pAtaFile->Cluster);
        if(ret_stat) return(ret_stat);

        ret_stat = _AtaWriteFatEntry(pAtaFile,1);
        if(ret_stat) return(ret_stat);
      }
      while(!last_cluster);
    }
    return(ret_stat);
}