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

static bool freeBlock ( struct Image image,
byte_t  track,
byte_t  sector 
) [static]

Free the block at the specified track and sector.

Parameters:
image the disk image
track track number of the block
sector sector number of the block
Returns:
true on success

Definition at line 1082 of file image.c.

References Image::buf, Image::dirtrack, getBlock(), getGeometry(), Im1541, Im1571, Im1581, ImUnknown, isFreeBlock(), mapInode(), Image::partTops, and Image::type.

Referenced by deleteInode().

{
  const struct DiskGeometry* geom;

  if (!image || !image->buf || !(geom = getGeometry (image->type)))
    return false;

  if (track < 1 || track > geom->tracks || sector >= geom->sectors[track])
    return false; /* illegal track or sector */

  if (isFreeBlock (image, track, sector))
    return false; /* already freed */

  switch (image->type) {
    byte_t* BAM;

  case ImUnknown:
    return false;
  case Im1571:
    if (track > 35) {
      byte_t tr = track - 35;
      byte_t* BAM2;

      if (!(BAM = getBlock ((struct Image*) image, image->dirtrack, 0)) ||
        !(BAM2 = getBlock ((struct Image*) image, 35 + image->dirtrack, 0)))
      return false;

      /* increment the count of free sectors per track */
      BAM[0xDC + tr]++;
      /* free the block */
      BAM2[((tr - 1) * 3) + (sector >> 3)] |= (1 << (sector & 7));
      return true;
    }
    /* fall through: track <= 35 */
  case Im1541:
    if (!(BAM = getBlock ((struct Image*) image, image->dirtrack, 0)))
      return false;

    /* increment the count of free sectors per track */
    BAM[track << 2]++;
    /* free the block */
    BAM[(track << 2) + 1 + (sector >> 3)] |= (1 << (sector & 7));
    return true;

  case Im1581:
    {
      byte_t** BAMblocks = 0;

      if(track > image->partTops[image->dirtrack - 1] ||
       track < image->partBots[image->dirtrack - 1])
      return false;

      if (2 != mapInode (&BAMblocks, image, image->dirtrack, 1, 0, 0)) {
      if (BAMblocks) free (BAMblocks);
      return false;
      }

      if(track > 40) {
      BAM = BAMblocks[1];

      track -= 40;
      }
      else
      BAM = BAMblocks[0];

      free (BAMblocks);

      BAM[16 + (track - 1) * 6] += 1;
      BAM[16 + (track - 1) * 6 + (sector >> 3) + 1] |= (1 << (sector & 7));
      return true;
    }
  }

  return false;
}


Generated by  Doxygen 1.6.0   Back to index