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

static size_t readInode ( byte_t **  buf,
const struct Image image,
byte_t  track,
byte_t  sector 
) [static]

Read a file starting at the specified track and sector to a buffer

Parameters:
buf the buffer
image the disk image
track track number of the file's first block
sector sector number of the file's first block
Returns:
the file length, or 0 on error

Definition at line 827 of file image.c.

References Image::buf, getBlock(), getGeometry(), isFreeBlock(), and Image::type.

Referenced by ReadImage().

{
  const struct DiskGeometry* geom;
  int t, s;
  size_t size;

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

  /* Determine the file size. */
  for (t = track, s = sector, size = 0; t; size += 254) {
    const byte_t* block;

    if (size > 254 * geom->blocks)
      return 0; /* endless file */

    if (!(block = getBlock ((struct Image*) image, t, s)))
      return 0;

    if (isFreeBlock (image, t, s))
      return 0;

    t = block[0];
    s = block[1];
  }

  if (s < 2)
    return 0; /* The last byte pointer must be at least 2. */

  size += s - 255;
  if (!(*buf = malloc (size)))
    return 0;

  /* Read the file. */
  for (t = track, s = sector, size = 0; t; size += 254) {
    const byte_t* block = getBlock ((struct Image*) image, t, s);
    t = block[0];
    s = block[1];
    memcpy (&(*buf)[size], &block[2], t ? 254 : s - 1);
  }

  return size += s - 255;
}


Generated by  Doxygen 1.6.0   Back to index