Esempio n. 1
0
bool CDIF_ValidateRawSector(uint8 *buf)
{
 int mode = buf[12 + 3];

 if(mode != 0x1 && mode != 0x2)
  return(false);

 if(LEC_Eval || cdrfile_is_physical(p_cdrfile))
 {
  if(!ValidateRawSector(buf, mode == 2))
   return(false);
 }
 return(true);
}
int CDIF::ReadSector(uint8* pBuf, uint32 lba, uint32 nSectors)
{
   int ret = 0;

   if(UnrecoverableError)
      return(false);

   while(nSectors--)
   {
      int mode;
      uint8_t tmpbuf[2352 + 96];

      if(!ReadRawSector(tmpbuf, lba))
      {
         puts("CDIF Raw Read error");
         return(FALSE);
      }

      if(!ValidateRawSector(tmpbuf))
         return(false);

      mode = tmpbuf[12 + 3];

      if(!ret)
         ret = mode;

      switch (mode)
      {
         case 1:
            memcpy(pBuf, &tmpbuf[12 + 4], 2048);
            break;
         case 2:
            memcpy(pBuf, &tmpbuf[12 + 4 + 8], 2048);
            break;
         default:
            printf("CDIF_ReadSector() invalid sector type at LBA=%u\n", (unsigned int)lba);
            return(false);
      }

      pBuf += 2048;
      lba++;
   }

   return(ret);
}