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

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

Allocate the block at the specified track and sector. Set the track and sector to the next block candidate.

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

Definition at line 519 of file image.c.

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

Referenced by FormatImage(), and writeInode().

{
  const struct DiskGeometry* geom;

  if (!track || !sector ||
      !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 */

  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;

      if (!(BAM2[((tr - 1) * 3) + (*sector >> 3)] & (1 << (*sector & 7))))
      return false; /* already allocated */

      /* decrement the count of free sectors per track */
      BAM[0xDC + tr]--;
      /* allocate the block */
      BAM2[((tr - 1) * 3) + (*sector >> 3)] &= ~(1 << (*sector & 7));

      /* find next free block */
      findNextFree (image, track, sector);
      return true;
    }
    /* fall through: track <= 35 */
  case Im1541:
    if (!(BAM = getBlock ((struct Image*) image, image->dirtrack, 0)))
      return false;

    if (!(BAM[(*track << 2) + 1 + (*sector >> 3)] & (1 << (*sector & 7))))
      return false; /* already allocated */

    /* decrement the count of free sectors per track */
    BAM[*track << 2]--;
    /* allocate the block */
    BAM[(*track << 2) + 1 + (*sector >> 3)] &= ~(1 << (*sector & 7));

    /* find next free block */
    findNextFree (image, track, sector);

    return true;

  case Im1581:
    {
      byte_t** BAMblocks = 0;
      byte_t offset;

      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;
      }

      offset = *track;
      if(offset > 40) {
      BAM = BAMblocks[1];
      offset -= 40;
      }
      else
      BAM = BAMblocks[0];

      free (BAMblocks);

      if (!(BAM[16 + (offset - 1) * 6 + (*sector >> 3) + 1] &
          (1 << (*sector & 7))))
      return false; /* already allocated */

      BAM[16 + (offset - 1) * 6] -= 1;
      BAM[16 + (offset - 1) * 6 + (*sector >> 3) + 1] &= ~(1 << (*sector & 7));

      /* find next free block */
      findNextFree (image, track, sector);

      return true;
    }
  }

  return false;
}


Generated by  Doxygen 1.6.0   Back to index