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

static int blocksFree ( const struct Image image  )  [static]

Determine the number of free blocks on the disk image.

Parameters:
image the disk image
Returns:
the total number of available blocks

Definition at line 1464 of file image.c.

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

Referenced by setupSideSectors(), and WriteImage().

{
  unsigned sum = 0;
  const struct DiskGeometry* geom;

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

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

  case ImUnknown:
    return 0;

  case Im1541:
    if (!(BAM = getBlock ((struct Image*) image, image->dirtrack, 0)))
      return 0;

    for (track = 1; track <= geom->tracks; track++)
      sum += BAM[track << 2];

    return sum;

  case Im1571:
    if (!(BAM = getBlock ((struct Image*) image, image->dirtrack, 0)))
      return 0;

    for (track = 1; track <= 35; track++)
      sum += BAM[track << 2] + BAM[0xDC + track];

    return sum;

  case Im1581:
    {
      byte_t** BAMblocks = 0;

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

      for (track = image->partBots[image->dirtrack - 1];
         track <= image->partTops[image->dirtrack - 1] && track <= 40;
         track++)
      sum += BAMblocks[0][16 + (track - 1)*6];

      for (track = image->partTops[image->dirtrack - 1];
         track >= image->partBots[image->dirtrack - 1] && track > 40;
         track--)
      sum += BAMblocks[1][16 + (track - 41) * 6];

      free (BAMblocks);

      return sum;
    }
  }

  return 0;
}


Generated by  Doxygen 1.6.0   Back to index