static void file_system_detach_disk_single(unsigned int unit) { vdrive_t *vdrive; vdrive = file_system_get_vdrive(unit); if (vdrive != NULL) detach_disk_image_and_free(vdrive->image, vdrive, (unsigned int)unit); set_file_system_device(file_system_device_enabled[unit - 8], (void *)unit); ui_display_drive_current_image(unit - 8, ""); }
void file_system_detach_disk_shutdown(void) { vdrive_t *vdrive; unsigned int i; for (i = 0; i <= 3; i++) { vdrive = file_system_get_vdrive(i + 8); if (vdrive != NULL) { if (file_system_device_enabled[i] == ATTACH_DEVICE_REAL) serial_realdevice_disable(); else detach_disk_image_and_free(vdrive->image, vdrive, i + 8); } } }
static int attach_disk_image(disk_image_t **imgptr, vdrive_t *floppy, const char *filename, unsigned int unit, int devicetype) { disk_image_t *image; disk_image_t new_image; int err = -1; if (filename == NULL) { log_error(attach_log, "No name, cannot attach floppy image."); return -1; } new_image.gcr = NULL; new_image.p64 = lib_calloc(1, sizeof(TP64Image)); new_image.read_only = (unsigned int)attach_device_readonly_enabled[unit - 8]; switch (devicetype) { case ATTACH_DEVICE_NONE: case ATTACH_DEVICE_VIRT: case ATTACH_DEVICE_FS: new_image.device = DISK_IMAGE_DEVICE_FS; break; case ATTACH_DEVICE_RAW: new_image.device = DISK_IMAGE_DEVICE_RAW; break; } disk_image_media_create(&new_image); switch (devicetype) { case ATTACH_DEVICE_NONE: case ATTACH_DEVICE_VIRT: case ATTACH_DEVICE_FS: disk_image_fsimage_name_set(&new_image, filename); break; case ATTACH_DEVICE_RAW: disk_image_rawimage_driver_name_set(&new_image); break; } if (disk_image_open(&new_image) < 0) { P64ImageDestroy((PP64Image) new_image.p64); lib_free(new_image.p64); disk_image_media_destroy(&new_image); return -1; } detach_disk_image_and_free(*imgptr, floppy, unit); *imgptr = disk_image_create(); image = *imgptr; memcpy(image, &new_image, sizeof(disk_image_t)); switch (unit) { case 8: case 9: case 10: case 11: err = drive_image_attach(image, unit); err &= vdrive_attach_image(image, unit, floppy); err &= machine_drive_image_attach(image, unit); break; } if (err) { disk_image_close(image); disk_image_media_destroy(image); disk_image_destroy(image); *imgptr = NULL; } return err; }
static int set_file_system_device(int val, void *param) { vdrive_t *vdrive; unsigned int unit = vice_ptr_to_uint(param); unsigned int idx; int old_device_enabled; if ((unit < 8) || (unit > 11)) { DBG(("set_file_system_device invalid dev #%d\n", unit)); return -1; } idx = unit - 8; old_device_enabled = file_system_device_enabled[idx]; vdrive = file_system_get_vdrive(unit); DBG(("set_file_system_device dev #%d old dev:%d new dev:%d\n", unit, old_device_enabled, val)); switch (val) { case ATTACH_DEVICE_NONE: if (old_device_enabled == ATTACH_DEVICE_REAL) { serial_realdevice_disable(); } if (old_device_enabled == ATTACH_DEVICE_RAW) { detach_disk_image(vdrive->image, vdrive, unit); } if (vdrive != NULL && vdrive->image == NULL) { vdrive_device_setup(vdrive, unit); serial_device_type_set(SERIAL_DEVICE_NONE, unit); file_system_set_serial_hooks(unit, 0); } break; case ATTACH_DEVICE_VIRT: if (old_device_enabled == ATTACH_DEVICE_REAL) { serial_realdevice_disable(); } if (old_device_enabled == ATTACH_DEVICE_RAW) { detach_disk_image(vdrive->image, vdrive, unit); } if (vdrive != NULL && vdrive->image == NULL) { vdrive_device_setup(vdrive, unit); serial_device_type_set(SERIAL_DEVICE_VIRT, unit); file_system_set_serial_hooks(unit, 0); } break; case ATTACH_DEVICE_FS: if (old_device_enabled == ATTACH_DEVICE_REAL) { serial_realdevice_disable(); } if (old_device_enabled == ATTACH_DEVICE_RAW) { detach_disk_image(vdrive->image, vdrive, unit); } if (vdrive != NULL && vdrive->image != NULL) { detach_disk_image_and_free(vdrive->image, vdrive, unit); ui_display_drive_current_image(idx, ""); } if (vdrive != NULL && vdrive->image == NULL) { vdrive_device_setup(vdrive, unit); serial_device_type_set(SERIAL_DEVICE_FS, unit); file_system_set_serial_hooks(unit, 1); } break; #ifdef HAVE_OPENCBM case ATTACH_DEVICE_REAL: if (old_device_enabled == ATTACH_DEVICE_RAW) { detach_disk_image(vdrive->image, vdrive, unit); } if (serial_realdevice_enable() < 0) { log_warning(attach_log, "Falling back to fs device."); return set_file_system_device(ATTACH_DEVICE_FS, param); } if (vdrive != NULL && vdrive->image != NULL) { detach_disk_image_and_free(vdrive->image, vdrive, unit); ui_display_drive_current_image(idx, ""); vdrive_device_setup(vdrive, unit); } serial_device_type_set(SERIAL_DEVICE_REAL, unit); break; #endif #ifdef HAVE_RAWDRIVE case ATTACH_DEVICE_RAW: if (old_device_enabled == ATTACH_DEVICE_REAL) { serial_realdevice_disable(); } if (vdrive != NULL && vdrive->image != NULL) { detach_disk_image_and_free(vdrive->image, vdrive, unit); ui_display_drive_current_image(idx, ""); vdrive_device_setup(vdrive, unit); } attach_disk_image(&(vdrive->image), vdrive, "DUMMY", unit, ATTACH_DEVICE_RAW); file_system_set_serial_hooks(unit, 0); serial_device_type_set(SERIAL_DEVICE_RAW, unit); break; #endif default: return -1; } file_system_device_enabled[idx] = val; return 0; }
static int set_file_system_device(int val, void *param) { vdrive_t *vdrive; unsigned int unit; int old_device_enabled; unit = (unsigned int)param; old_device_enabled = file_system_device_enabled[unit - 8]; vdrive = file_system_get_vdrive(unit); switch (val) { case ATTACH_DEVICE_NONE: if (old_device_enabled == ATTACH_DEVICE_REAL) serial_realdevice_disable(); if (old_device_enabled == ATTACH_DEVICE_RAW) detach_disk_image(vdrive->image, vdrive, unit); if (vdrive != NULL && vdrive->image == NULL) { vdrive_device_setup(vdrive, unit); serial_device_type_set(SERIAL_DEVICE_VIRT, unit); file_system_set_serial_hooks(unit, 0); } break; case ATTACH_DEVICE_FS: if (old_device_enabled == ATTACH_DEVICE_REAL) serial_realdevice_disable(); if (old_device_enabled == ATTACH_DEVICE_RAW) detach_disk_image(vdrive->image, vdrive, unit); if (vdrive != NULL && vdrive->image == NULL) { vdrive_device_setup(vdrive, unit); serial_device_type_set(SERIAL_DEVICE_FS, unit); file_system_set_serial_hooks(unit, 1); } break; #ifdef HAVE_OPENCBM case ATTACH_DEVICE_REAL: if (old_device_enabled == ATTACH_DEVICE_RAW) detach_disk_image(vdrive->image, vdrive, unit); if (serial_realdevice_enable() < 0) { log_warning(attach_log, "Falling back to fs device."); return set_file_system_device(ATTACH_DEVICE_FS, param); } if (vdrive != NULL && vdrive->image != NULL) { detach_disk_image_and_free(vdrive->image, vdrive, unit); ui_display_drive_current_image(unit - 8, ""); vdrive_device_setup(vdrive, unit); } serial_device_type_set(SERIAL_DEVICE_REAL, unit); break; #endif #ifdef HAVE_RAWDRIVE case ATTACH_DEVICE_RAW: if (old_device_enabled == ATTACH_DEVICE_REAL) serial_realdevice_disable(); if (vdrive != NULL && vdrive->image != NULL) { detach_disk_image_and_free(vdrive->image, vdrive, unit); ui_display_drive_current_image(unit - 8, ""); vdrive_device_setup(vdrive, unit); } attach_disk_image(&(vdrive->image), vdrive, "DUMMY", unit, ATTACH_DEVICE_RAW); file_system_set_serial_hooks(unit, 0); serial_device_type_set(SERIAL_DEVICE_RAW, unit); break; #endif default: return -1; } file_system_device_enabled[unit - 8] = val; return 0; }