Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

static bool checkSideSectors ( const struct Image image,
const struct DirEnt *  dirent,
log_t  log 
) [static]

Check if the side sectors of a relative file are OK

Parameters:
image the disk image
dirent the directory entry
log Call-back function for diagnostic output
Returns:
true if the side sectors pass the integrity checks

Definition at line 1637 of file image.c.

References getFiletype(), mapInode(), REL, and rounddiv.

Referenced by ReadImage().

{
  unsigned ss, ssentry, sscount, i;
  byte_t** sidesect = 0;
  byte_t** datafile = 0;
  byte_t track, sector;

#ifdef DEBUG
  if (!isValidDirEnt (image, dirent))
    return false;
#endif

  if (getFiletype (image, dirent) != REL)
    return false;

  /* Map the data file and the side sectors. */

  if (!(i = mapInode (&datafile, (struct Image*) image,
                  dirent->firstTrack, dirent->firstSector, log, dirent)))
    return false;

  if (!(sscount = mapInode (&sidesect, (struct Image*) image,
                      dirent->ssTrack, dirent->ssSector,
                      log, dirent))) {
    free (datafile);
    return false;
  }

  /* Check the block counts */
  if (sscount != rounddiv(i, 120) ||
      i + sscount != dirent->blocksLow + (dirent->blocksHigh << 8) ||
      i != 120 * (sscount - 1) + (sidesect[sscount - 1][1] - 15) / 2) {
  Failed:
    free (datafile);
    free (sidesect);
    return false;
  }

  /* Check the side sector links */

  for (ss = 0; ss < sscount; ss++) {
    if (sidesect[ss][2] != ss ||
      sidesect[ss][3] != dirent->recordLength ||
      sidesect[ss][4] != dirent->ssTrack ||
      sidesect[ss][5] != dirent->ssSector)
      goto Failed;

    for (i = 1; i < sscount; i++)
      if (sidesect[ss][4 + i * 2] != sidesect[i - 1][0] ||
        sidesect[ss][5 + i * 2] != sidesect[i - 1][1])
      goto Failed;
  }

  /* Check the links to the data file */

  track = dirent->firstTrack;
  sector = dirent->firstSector;

  for (ss = ssentry = 0; track; ssentry++) {
    ss = ssentry / 120;

    if (ss >= sscount ||
      sidesect[ss][16 + (ssentry % 120) * 2] != track ||
      sidesect[ss][17 + (ssentry % 120) * 2] != sector)
      goto Failed;

    track = datafile[ssentry][0];
    sector = datafile[ssentry][1];
  }

  free (datafile);
  free (sidesect);

  return true;
}


Generated by  Doxygen 1.6.0   Back to index