static TUI_MENU_CALLBACK(current_extend_string_callback) { int drive = (int)param; int type = get_drive_type(drive); int extend_support = drive_check_extend_policy(type); int res_value; char *s; if (!extend_support) { return "N/A"; } resources_get_int_sprintf("Drive%iExtendImagePolicy", &res_value, drive); switch (res_value) { case DRIVE_EXTEND_NEVER: default: s = "Never extend"; break; case DRIVE_EXTEND_ASK: s = "Ask to extend"; break; case DRIVE_EXTEND_ACCESS: s = "Extend on access"; break; } return s; }
static HANDLE get_handler(WCHAR drive) { static const WCHAR deviceW[] = {'\\', '\\', '.', '\\', 'a', ':', 0}; WCHAR buffer[16]; HANDLE handle; if (get_drive_type(drive) != DRIVE_CDROM) { printf("Drive %c: is not a CD or is not mounted\n", (char)drive); exit(1); } memcpy(buffer, deviceW, sizeof(deviceW)); buffer[4] = drive; handle = CreateFileW(buffer, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); if (handle == INVALID_HANDLE_VALUE) { printf("Cannot get_handler device for drive %c:\n", (char)drive); exit(1); } cdrom_io_control(handle, FSCTL_LOCK_VOLUME, NULL); return handle; }
static TUI_MENU_CALLBACK(current_idle_string_callback) { int drive = (int)param; int type = get_drive_type(drive); int idle_support = drive_check_idle_method(type); int res_value; char *s; if (!idle_support) { return "N/A"; } resources_get_int_sprintf("Drive%iIdleMethod", &res_value, drive); switch (res_value) { default: case DRIVE_IDLE_NO_IDLE: s = "None"; break; case DRIVE_IDLE_SKIP_CYCLES: s = "Skip cycles"; break; case DRIVE_IDLE_TRAP_IDLE: s = "Trap idle"; break; } return s; }
int main( int argc, char *argv[] ) { parse_options( &argc, argv ); if (eject_all) { WCHAR drive; for (drive = 'c'; drive <= 'z'; drive++) { if (get_drive_type( drive ) != DRIVE_CDROM) continue; if (!eject_cd( drive )) exit(1); } } else if (argc > 1) { int i; for (i = 1; i < argc; i++) if (!eject_cd( argv[i][0] )) exit(1); } else { WCHAR drive = find_cd_drive(); if (!drive) { WINE_MESSAGE( "No CD drive found\n" ); exit(1); } if (!eject_cd( drive )) exit(1); } exit(0); }
static TUI_MENU_CALLBACK(current_type_string_callback) { int drive = (int)param; int type = get_drive_type(drive); int i; for (i = 0; uidrives[i].type != type; i++) {} return uidrives[i].name; }
static TUI_MENU_CALLBACK(current_expansion_string_callback) { int drive = (int)param; int type = get_drive_type(drive); int i; char *s = NULL; for (i = 0; uidrives[i].type != type; i++) {} if (!uidrives[i].ram) { s = "N/A"; } return s; }
/* Load currently defined drives into the drives array */ BOOL load_drives(void) { DWORD i, size = 1024; HANDLE mgr; WCHAR root[] = {'A',':','\\',0}; if ((mgr = open_mountmgr()) == INVALID_HANDLE_VALUE) return FALSE; while (root[0] <= 'Z') { struct mountmgr_unix_drive input; struct mountmgr_unix_drive *data; if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) break; memset( &input, 0, sizeof(input) ); input.letter = root[0]; if (DeviceIoControl( mgr, IOCTL_MOUNTMGR_QUERY_UNIX_DRIVE, &input, sizeof(input), data, size, NULL, NULL )) { char *unixpath = NULL, *device = NULL; WCHAR volname[MAX_PATH]; DWORD serial; if (data->mount_point_offset) unixpath = (char *)data + data->mount_point_offset; if (data->device_offset) device = (char *)data + data->device_offset; if (!GetVolumeInformationW( root, volname, sizeof(volname)/sizeof(WCHAR), &serial, NULL, NULL, NULL, 0 )) { volname[0] = 0; serial = 0; } add_drive( root[0], unixpath, device, volname, serial, get_drive_type(root[0]) ); root[0]++; } else { if (GetLastError() == ERROR_MORE_DATA) size = data->size; else root[0]++; /* skip this drive */ } HeapFree( GetProcessHeap(), 0, data ); } /* reset modified flags */ for (i = 0; i < 26; i++) drives[i].modified = FALSE; CloseHandle( mgr ); return TRUE; }
/* find the CD drive, and die if we find more than one */ static WCHAR find_cd_drive(void) { WCHAR ret = 0, drive; for (drive = 'c'; drive <= 'z'; drive++) { if (get_drive_type( drive ) != DRIVE_CDROM) continue; if (ret) { WINE_MESSAGE( "Multiple CD drives found (%c: and %c:), you need to specify the one you want.\n", (char)ret, (char)drive ); exit(1); } ret = drive; } return ret; }
static TUI_MENU_CALLBACK(radio_expansion_check_callback) { int drive = (int)param >> 16; int value = (int)param & 0xffff; int type = get_drive_type(drive); int ram_support; int res_value; int i; for (i = 0; uidrives[i].type != type; i++) {} switch (value) { default: case 0x2000: ram_support = uidrives[i].ram2000; break; case 0x4000: ram_support = uidrives[i].ram4000; break; case 0x6000: ram_support = uidrives[i].ram6000; break; case 0x8000: ram_support = uidrives[i].ram8000; break; case 0xA000: ram_support = uidrives[i].rama000; break; } if (!ram_support) { return "N/A"; } if (been_activated) { resources_get_int_sprintf("Drive%iRAM%X", &res_value, drive, value); resources_set_int_sprintf("Drive%iRAM%X", !res_value, drive, value); ui_update_menus(); } resources_get_int_sprintf("Drive%iRAM%X", &res_value, drive, value); return (res_value) ? "On" : "Off"; }
static BOOL eject_cd( WCHAR drive ) { static const WCHAR deviceW[] = {'\\','\\','.','\\','a',':',0}; PREVENT_MEDIA_REMOVAL removal; WCHAR buffer[16]; HANDLE handle; DWORD result; if (get_drive_type( drive ) != DRIVE_CDROM) { WINE_MESSAGE( "Drive %c: is not a CD or is not mounted\n", (char)drive ); return FALSE; } memcpy( buffer, deviceW, sizeof(deviceW) ); buffer[4] = drive; handle = CreateFileW( buffer, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); if (handle == INVALID_HANDLE_VALUE) { WINE_MESSAGE( "Cannot open device for drive %c:\n", (char)drive ); return FALSE; } WINE_TRACE( "ejecting %c:\n", (char)drive ); if (!DeviceIoControl( handle, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &result, NULL )) WINE_WARN( "FSCTL_DISMOUNT_VOLUME failed with err %d\n", GetLastError() ); removal.PreventMediaRemoval = FALSE; if (!DeviceIoControl( handle, IOCTL_STORAGE_MEDIA_REMOVAL, &removal, sizeof(removal), NULL, 0, &result, NULL )) WINE_WARN( "IOCTL_STORAGE_MEDIA_REMOVAL failed with err %d\n", GetLastError() ); if (!unmount_only) { if (!DeviceIoControl( handle, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &result, NULL )) WINE_WARN( "IOCTL_STORAGE_EJECT_MEDIA failed with err %d\n", GetLastError() ); } CloseHandle( handle ); return TRUE; }
static TUI_MENU_CALLBACK(toggle_par_callback) { int drive = (int)param; int type = get_drive_type(drive); int par_support = drive_check_parallel_cable(type); int par; if (!par_support || machine_class == VICE_MACHINE_VIC20) { return "N/A"; } if (been_activated) { resources_get_int_sprintf("Drive%iParallelCable", &par, drive); resources_set_int_sprintf("Drive%iParallelCable", !par, drive); ui_update_menus(); } resources_get_int_sprintf("Drive%iParallelCable", &par, drive); return (par) ? "On" : "Off"; }
static TUI_MENU_CALLBACK(radio_idle_check_callback) { int drive = (int)param >> 16; int value = (int)param & 0xffff; int type = get_drive_type(drive); int idle_support = drive_check_idle_method(type); int res_value; if (!idle_support) { return "N/A"; } if (been_activated) { resources_set_int_sprintf("Drive%iIdleMethod", value, drive); *become_default = 1; ui_update_menus(); } else { resources_get_int_sprintf("Drive%iIdleMethod", &res_value, drive); if (res_value == value) { *become_default = 1; } } }
static int get_attrs(disk_t *diskp, int fd, char *opath, nvlist_t *attrs) { if (diskp->removable) { struct dk_minfo minfo; if (nvlist_add_boolean(attrs, DM_REMOVABLE) != 0) { return (ENOMEM); } /* Make sure media is inserted and spun up. */ if (fd >= 0 && media_read_info(fd, &minfo)) { if (nvlist_add_boolean(attrs, DM_LOADED) != 0) { return (ENOMEM); } } /* can't tell diff between dead & no media on removable drives */ if (nvlist_add_uint32(attrs, DM_STATUS, DM_DISK_UP) != 0) { return (ENOMEM); } get_drive_type(diskp, fd); } else { struct dk_minfo minfo; /* check if the fixed drive is up or not */ if (fd >= 0 && media_read_info(fd, &minfo)) { if (nvlist_add_uint32(attrs, DM_STATUS, DM_DISK_UP) != 0) { return (ENOMEM); } } else { if (nvlist_add_uint32(attrs, DM_STATUS, DM_DISK_DOWN) != 0) { return (ENOMEM); } } get_drive_type(diskp, fd); } if (nvlist_add_uint32(attrs, DM_DRVTYPE, diskp->drv_type) != 0) { return (ENOMEM); } if (diskp->product_id != NULL) { if (nvlist_add_string(attrs, DM_PRODUCT_ID, diskp->product_id) != 0) { return (ENOMEM); } } if (diskp->vendor_id != NULL) { if (nvlist_add_string(attrs, DM_VENDOR_ID, diskp->vendor_id) != 0) { return (ENOMEM); } } if (diskp->sync_speed != -1) { if (nvlist_add_uint32(attrs, DM_SYNC_SPEED, diskp->sync_speed) != 0) { return (ENOMEM); } } if (diskp->wide == 1) { if (nvlist_add_boolean(attrs, DM_WIDE) != 0) { return (ENOMEM); } } if (diskp->rpm == 0) { diskp->rpm = get_rpm(diskp, fd); } if (diskp->rpm > 0) { if (nvlist_add_uint32(attrs, DM_RPM, diskp->rpm) != 0) { return (ENOMEM); } } if (diskp->aliases != NULL && diskp->aliases->cluster) { if (nvlist_add_boolean(attrs, DM_CLUSTERED) != 0) { return (ENOMEM); } } if (strlen(opath) > 0) { if (nvlist_add_string(attrs, DM_OPATH, opath) != 0) { return (ENOMEM); } } if (diskp->solid_state < 0) { diskp->solid_state = get_solidstate(diskp, fd); } if (diskp->solid_state > 0) { if (nvlist_add_boolean(attrs, DM_SOLIDSTATE) != 0) { return (ENOMEM); } } return (0); }