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

enum ImStatus OpenImage ( const char *  filename,
struct Image **  image,
enum ImageType  type,
enum DirEntOpts  direntOpts 
)

Open an existing disk image or create a new one.

Parameters:
filename name of 1541 disk image on the host system
image address of the disk image buffer pointer (will be allocated by this function)
type type of the disk image
direntOpts directory entry handling options
Returns:
Status of the operation

Definition at line 2938 of file image.c.

References FormatImage(), getGeometry(), ImFail, and ImOK.

Referenced by main(), and writeFile().

{
  FILE* f;
  const struct DiskGeometry* geom;

  /* The image buffer may not have been allocated. */
  if (!image || *image)
    return ImFail;

  if (!(geom = getGeometry (type)))
    return ImFail;

  /* Allocate and initialize the image structure. */

  if (!(*image = calloc (1, sizeof (**image))))
    return ImFail;

  if (!((*image)->buf = malloc (geom->blocks * 256))) {
  Failed:
    free ((*image)->name);
    free ((*image)->buf);
    free (*image);
    *image = 0;
    return ImFail;
  }

  if (!((*image)->name = malloc (strlen (filename) + 1)))
    goto Failed;

  strcpy ((char*)(*image)->name, filename);
  (*image)->type = type;
  (*image)->direntOpts = direntOpts;
  (*image)->dirtrack = geom->dirtrack;

  if (!(f = fopen (filename, "rb"))) {
    if (errno != ENOENT) /* It is OK if the file was not found. */
      goto Failed;

    /* Initialize the image */
    FormatImage (*image);
  }
  else {
    /* Read in the disk image */

    if (1 != fread ((*image)->buf, geom->blocks * 256, 1, f) ||
      EOF != fgetc (f)) {
      fclose (f);
      goto Failed;
    }

    fclose (f);
  }

  (*image)->partTops[(*image)->dirtrack - 1] = geom->tracks;
  (*image)->partBots[(*image)->dirtrack - 1] = 1;
  (*image)->partUpper[(*image)->dirtrack - 1] = 0;

  return ImOK;
}


Generated by  Doxygen 1.6.0   Back to index