// ----------------------------------------------------------------------- void * dev_flop5_create(struct cfg_arg *args) { struct dev_flop5 *flop5 = (struct dev_flop5 *) malloc(sizeof(struct dev_flop5)); if (!flop5) { LOGERR("Memory allocation error while creating 5-inch floppy drive."); goto cleanup; } flop5->image = e4i_open(args->text); if (!flop5->image) { LOGERR("Failed to open 5-inch floppy image: \"%s\": %s.", args->text, e4i_get_err(e4i_err)); goto cleanup; } return flop5; cleanup: free(flop5); return NULL; }
// ----------------------------------------------------------------------- struct cmem_unit_proto_t * cmem_m9425_create(struct cfg_arg *args) { char *image_name[2] = { NULL, NULL }; struct cmem_unit_m9425_t *unit = calloc(1, sizeof(struct cmem_unit_m9425_t)); int res; if (!unit) { goto fail; } if ((image_name[0] || image_name[1]) && !strcmp(image_name[0], image_name[1])) { fprintf(stderr, "Error opening image: Trying to use the same image for fixed and removable disk"); res = E_IMAGE; goto fail; } res = cfg_args_decode(args, "ss", &image_name[0], &image_name[1]); if (res != E_OK) { gerr = res; goto fail; } for (int i=0 ; i<=1 ; i++) { UNIT->disk[i] = e4i_open(image_name[i]); if (!UNIT->disk[i]) { fprintf(stderr, "Error opening image %s: %s\n", image_name[i], e4i_get_err(e4i_err)); res = E_IMAGE; goto fail; } if (UNIT->disk[i]->img_type != E4I_T_HDD) { fprintf(stderr, "Error opening image %s: wrong image type, expecting hdd\n", image_name[i]); res = E_IMAGE; goto fail; } if ((UNIT->disk[i]->cylinders != 203) || (UNIT->disk[i]->heads != 2) || (UNIT->disk[i]->spt != 12) || (UNIT->disk[i]->block_size != 512)) { fprintf(stderr, "Error opening image %s: wrong geometry\n", image_name[i]); res = E_IMAGE; goto fail; } LOG(L_9425, 1, "MERA 9425 (plate %i): cyl=%i, head=%i, sectors=%i, spt=%i, image=%s", i, UNIT->disk[i]->cylinders, UNIT->disk[i]->heads, UNIT->disk[i]->spt, UNIT->disk[i]->block_size, image_name[i]); free(image_name[i]); image_name[i] = NULL; } res = pthread_create(&unit->worker, NULL, cmem_m9425_worker, (void*) unit); if (res != 0) { gerr = E_THREAD; goto fail; } return (struct cmem_unit_proto_t *) unit; fail: for (int i=0 ; i<=1 ; i++) { free(image_name[i]); } cmem_m9425_shutdown((struct cmem_unit_proto_t*) unit); return NULL; }