| 155 | static int driver_installed[NUM_DEVICE_TABLE_ENTRIES]; |
| 156 | |
| 157 | static void install_driver (int flags) |
| 158 | { |
| 159 | for (int i = 0; i < MAX_TOTAL_SCSI_DEVICES; i++) { |
| 160 | struct blkdevstate *st = &state[i]; |
| 161 | st->scsiemu = false; |
| 162 | st->type = -1; |
| 163 | st->device_func = NULL; |
| 164 | } |
| 165 | if (flags > 0) { |
| 166 | state[0].device_func = devicetable[flags]; |
| 167 | state[0].scsiemu = true; |
| 168 | } else { |
| 169 | for (int i = 0; i < MAX_TOTAL_SCSI_DEVICES; i++) { |
| 170 | struct blkdevstate *st = &state[i]; |
| 171 | st->scsiemu = false; |
| 172 | st->device_func = NULL; |
| 173 | switch (cdscsidevicetype[i]) |
| 174 | { |
| 175 | case SCSI_UNIT_IMAGE: |
| 176 | st->device_func = devicetable[SCSI_UNIT_IMAGE]; |
| 177 | st->scsiemu = true; |
| 178 | break; |
| 179 | case SCSI_UNIT_IOCTL: |
| 180 | st->device_func = devicetable[SCSI_UNIT_IOCTL]; |
| 181 | st->scsiemu = true; |
| 182 | break; |
| 183 | case SCSI_UNIT_SPTI: |
| 184 | if (currprefs.uaescsimode == UAESCSI_CDEMU) { |
| 185 | st->device_func = devicetable[SCSI_UNIT_IOCTL]; |
| 186 | st->scsiemu = true; |
| 187 | } else { |
| 188 | st->device_func = devicetable[SCSI_UNIT_SPTI]; |
| 189 | } |
| 190 | break; |
| 191 | } |
| 192 | // do not default to image mode if unit 1+ and automount |
| 193 | if (i == 0 || !currprefs.automount_cddrives) { |
| 194 | // use image mode if driver disabled |
| 195 | for (int j = 1; j < NUM_DEVICE_TABLE_ENTRIES; j++) { |
| 196 | if (devicetable[j] == st->device_func && driver_installed[j] < 0) { |
| 197 | st->device_func = devicetable[SCSI_UNIT_IMAGE]; |
| 198 | st->scsiemu = true; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | for (int j = 1; j < NUM_DEVICE_TABLE_ENTRIES; j++) { |
| 206 | if (devicetable[j] == NULL) { |
| 207 | continue; |
| 208 | } |
| 209 | if (!driver_installed[j]) { |
| 210 | for (int i = 0; i < MAX_TOTAL_SCSI_DEVICES; i++) { |
| 211 | struct blkdevstate *st = &state[i]; |
| 212 | if (st->device_func == devicetable[j]) { |
| 213 | int ok = st->device_func->openbus (0); |
| 214 | if (!ok && st->device_func != devicetable[SCSI_UNIT_IMAGE]) { |
no test coverage detected