Esempio n. 1
0
/* Read an extent of sectors into the cache. */
static CoreResult readSectorExtent(CryptedFile * pFile,
   SectorNumber sStart, SectorNumber csExtent, unsigned int flFlags)
{
   CoreResult cr, crfinal = CORERC_OK;
   octet * pabBuffer, * p;
   SectorNumber i;
   CryptedSector * pSector;
   
   pabBuffer = malloc(csExtent * SECTOR_SIZE);
   if (!pabBuffer) return CORERC_NOT_ENOUGH_MEMORY;

   cr = readBuffer(pFile, sStart, csExtent, pabBuffer);
   if (cr) {
      free(pabBuffer);
      return cr;
   }

   for (i = sStart, p = pabBuffer;
        i < sStart + csExtent;
        i++, p += SECTOR_SIZE)
   {
      cr = addSector(pFile, i, &pSector);
      if (cr) {
         free(pabBuffer);
         return cr;
      }

      cr = coreDecryptSectorData(p, &pSector->data,
         pFile->pVolume->pKey, pFile->pVolume->parms.flCryptoFlags);
      if (cr) {
         if (flFlags & CFETCH_ADD_BAD)
            crfinal = cr;
         else {
            deleteSector(pSector);
            free(pabBuffer);
            return cr;
         }
      }
   }
   
   free(pabBuffer);
   return crfinal;
}
Esempio n. 2
0
/* Read the specified sectors of the specified file into the cache.
   Adjacent sectors are read in a single read operation. */
static CoreResult readSectors(CryptedFile * pFile,
   unsigned int csRead, SectorNumber * pasRead, unsigned int flFlags)
{
   CoreResult cr, crfinal = CORERC_OK;
   CryptedSector * pSector;
   unsigned int c;
   
   while (csRead) {

      if (flFlags & CFETCH_NO_READ) {

         cr = addSector(pFile, *pasRead, &pSector);
         if (cr) return cr;

         dirtySector(pFile->pVolume, pSector);
         memset(&pSector->data, 0, sizeof(CryptedSectorData));
         
         c = 1;
         
      } else {
      
         /* How many adjacent sectors? */
         for (c = 1;
              (c < csRead) && (pasRead[c] == *pasRead + c);
              c++);

         cr = readSectorExtent(pFile, *pasRead, c, flFlags);
         if (cr) {
            if ((cr == CORERC_BAD_CHECKSUM) &&
               (flFlags & CFETCH_ADD_BAD))
               crfinal = cr;
            else
               return cr;
         }
      }
      
      csRead -= c, pasRead += c;
   }

   return crfinal;
}
void PICWeeklySettings::addScenarioData(const QString& scenario, const QString& geography, const QString& sector, const QString& Rating, int shock)
{
    addSector(sector);
    addGeog(geography);
    for (int i = 0; i < m_ShocksModel->rowCount();++i){
        const QModelIndex currIdx = m_ShocksModel->index(i, 0);
        if(currIdx.data().toString().compare(scenario,Qt::CaseInsensitive)==0){
            int shockRow = 0;
            for (; shockRow < m_ShocksModel->rowCount(currIdx); ++shockRow) {
                if (m_ShocksModel->index(shockRow, 0, currIdx).data().toString().compare(sector, Qt::CaseInsensitive) == 0 || (sector.isEmpty() && m_ShocksModel->index(shockRow, 0, currIdx).data(Qt::UserRole).toBool())) {
                    if (m_ShocksModel->index(shockRow, 1, currIdx).data().toString().compare(geography, Qt::CaseInsensitive) == 0 || (geography.isEmpty() && m_ShocksModel->index(shockRow, 1, currIdx).data(Qt::UserRole).toBool()))
                        break;
                }
            }
            if (shockRow == m_ShocksModel->rowCount(currIdx)) {
                m_ShocksModel->insertRow(shockRow, currIdx);
                if (sector.isEmpty()){
                    m_ShocksModel->setData(m_ShocksModel->index(shockRow, 0, currIdx), tr("Any"));
                    m_ShocksModel->setData(m_ShocksModel->index(shockRow, 0, currIdx), true, Qt::UserRole);
                }
                else {
                    m_ShocksModel->setData(m_ShocksModel->index(shockRow, 0, currIdx), sector);
                }
                if (geography.isEmpty()) {
                    m_ShocksModel->setData(m_ShocksModel->index(shockRow, 1, currIdx), tr("Any"));
                    m_ShocksModel->setData(m_ShocksModel->index(shockRow, 1, currIdx), true, Qt::UserRole);
                }
                else {
                    m_ShocksModel->setData(m_ShocksModel->index(shockRow, 1, currIdx), geography);
                }
            }
            const int shockCol = findRating(Rating);
            m_ShocksModel->setData(m_ShocksModel->index(shockRow, shockCol, currIdx), shock);
            return;
        }
    }
    addScenario(scenario);
    addScenarioData(scenario, geography, sector, Rating, shock);
}