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

static enum WrStatus writeInode ( struct Image image,
byte_t  track,
byte_t  sector,
const byte_t buf,
size_t  size 
) [static]

Write a file to the disk, starting from the specified track and sector.

image the disk image
track track number of the first file block
sector sector number of the first file block
buf the file contents
size length of the file contnets
status of the operation

Definition at line 1029 of file image.c.

References allocBlock(), backupBAM(), Image::buf, getBlock(), restoreBAM(), WrFail, WrNoSpace, and WrOK.

Referenced by setupSideSectors(), and WriteImage().

  byte_t t, s;
  size_t count;
  byte_t* oldBAM = 0;

  if (!buf || !image || !image->buf)
    return WrFail;

  /* Make a copy of the BAM. */

  if (!backupBAM (image, &oldBAM))
    return WrFail;

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

    if (!(block = getBlock (image, t, s))) {
      restoreBAM (image, &oldBAM);
      return WrFail;

    if (!allocBlock (image, &t, &s)) {
      restoreBAM (image, &oldBAM);
      return WrNoSpace;

    if (count + 254 < size) { /* not yet last block */
      block[0] = t;
      block[1] = s;
      memcpy (&block[2], &buf[count], 254);
    else {
      block[0] = 0;
      block[1] = size - count + 1;
      memcpy (&block[2], &buf[count], size - count);

  free (oldBAM);
  return WrOK;

Generated by  Doxygen 1.6.0   Back to index