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

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

Find the next free block that is closest to the specified track and sector.

Parameters:
image the disk image
track (input/output) the track number
sector (input/output) the sector number
Returns:
true if a block was found

Definition at line 353 of file image.c.

References Image::buf, Image::dirtrack, getGeometry(), isFreeBlock(), Image::partBots, Image::partTops, and Image::type.

Referenced by allocBlock(), setupSideSectors(), and WriteImage().

{
  const struct DiskGeometry* geom;
  int t, s, i;
  t = *track;
  s = *sector;

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

  if (t < 1 || t > geom->tracks || s < 0 || s >= geom->sectors[t])
    return false;

  if (t >= image->dirtrack) {
    /* search from the current track upwards */

    for (; t <= image->partTops[image->dirtrack - 1]; t++)
      for (i = geom->sectors[t]; i; i--) {
      if (isFreeBlock (image, t, s)) {
        *track = t;
        *sector = s;
        return true;
      }
      s += geom->interleave[t];
      s %= geom->sectors[t];
      }

    /* search from lower tracks (from the directory track downwards) */

    for (t = image->dirtrack - 1;
       t >= image->partBots[image->dirtrack - 1]; t--)
      for (i = geom->sectors[t]; i; i--) {
      if (isFreeBlock (image, t, s)) {
        *track = t;
        *sector = s;
        return true;
      }
      s += geom->interleave[t];
      s %= geom->sectors[t];
      }
  }
  else {
    /* search from the current track downwards */

    for (; t >= image->partBots[image->dirtrack - 1]; t--)
      for (i = geom->sectors[t]; i; i--) {
      if (isFreeBlock (image, t, s)) {
        *track = t;
        *sector = s;
        return true;
      }
      s += geom->interleave[t];
      s %= geom->sectors[t];
      }

    /* search from upper tracks (from the directory track upwards) */

    for (t = image->dirtrack + 1;
       t <= image->partTops[image->dirtrack - 1]; t++)
      for (i = geom->sectors[t]; i; i--) {
      if (isFreeBlock (image, t, s)) {
        *track = t;
        *sector = s;
        return true;
      }
      s += geom->interleave[t];
      s %= geom->sectors[t];
      }

    /* last resort: search from the directory track */
    t = image->dirtrack;

    for (i = geom->sectors[t]; i; i--) {
      if (isFreeBlock (image, t, s)) {
      *track = t;
      *sector = s;
      return true;
      }
      s += geom->interleave[t];
      s %= geom->sectors[t];
    }
  }

  return false;
}


Generated by  Doxygen 1.6.0   Back to index