src/mess/devices/harddriv.c
| r2568 | r2569 | |
| 76 | 76 | |
| 77 | 77 | struct mess_hd |
| 78 | 78 | { |
| 79 | chd_file *chd; |
| 79 | 80 | hard_disk_file *hard_disk_handle; |
| 80 | 81 | }; |
| 81 | 82 | |
| r2568 | r2569 | |
| 116 | 117 | { |
| 117 | 118 | chd_error err = 0; |
| 118 | 119 | struct mess_hd *hd; |
| 119 | | chd_file *chd; |
| 120 | 120 | int is_writeable; |
| 121 | 121 | int id = image_index_in_device(image); |
| 122 | 122 | |
| r2568 | r2569 | |
| 126 | 126 | do |
| 127 | 127 | { |
| 128 | 128 | is_writeable = image_is_writable(image); |
| 129 | | chd = NULL; |
| 130 | | err = chd_open_file(image_core_file(image), is_writeable ? CHD_OPEN_READWRITE : CHD_OPEN_READ, NULL, &chd); |
| 129 | hd->chd = NULL; |
| 130 | err = chd_open_file(image_core_file(image), is_writeable ? CHD_OPEN_READWRITE : CHD_OPEN_READ, NULL, &hd->chd); |
| 131 | 131 | |
| 132 | 132 | /* special case; if we get CHDERR_FILE_NOT_WRITEABLE, make the |
| 133 | 133 | * image read only and repeat */ |
| 134 | 134 | if (err == CHDERR_FILE_NOT_WRITEABLE) |
| 135 | 135 | image_make_readonly(image); |
| 136 | 136 | } |
| 137 | | while(!chd && is_writeable && (err == CHDERR_FILE_NOT_WRITEABLE)); |
| 138 | | if (!chd) |
| 137 | while(!hd->chd && is_writeable && (err == CHDERR_FILE_NOT_WRITEABLE)); |
| 138 | if (!hd->chd) |
| 139 | 139 | goto done; |
| 140 | 140 | |
| 141 | 141 | /* if we created the image and hence, have metadata to set, set the metadata */ |
| 142 | 142 | if (metadata) |
| 143 | 143 | { |
| 144 | | err = chd_set_metadata(chd, HARD_DISK_METADATA_TAG, 0, metadata, strlen(metadata) + 1); |
| 144 | err = chd_set_metadata(hd->chd, HARD_DISK_METADATA_TAG, 0, metadata, strlen(metadata) + 1); |
| 145 | 145 | if (err != CHDERR_NONE) |
| 146 | 146 | goto done; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /* open the hard disk file */ |
| 150 | | hd->hard_disk_handle = hard_disk_open(chd); |
| 150 | hd->hard_disk_handle = hard_disk_open(hd->chd); |
| 151 | 151 | if (!hd->hard_disk_handle) |
| 152 | 152 | goto done; |
| 153 | 153 | |
| r2568 | r2569 | |
| 156 | 156 | done: |
| 157 | 157 | if (err) |
| 158 | 158 | { |
| 159 | | if (chd) |
| 160 | | chd_close(chd); |
| 159 | /* if we had an error, close out the CHD */ |
| 160 | if (hd->chd != NULL) |
| 161 | { |
| 162 | chd_close(hd->chd); |
| 163 | hd->chd = NULL; |
| 164 | } |
| 161 | 165 | |
| 162 | 166 | image_seterror(image, IMAGE_ERROR_UNSPECIFIED, chd_get_error_string(err)); |
| 163 | 167 | } |
| r2568 | r2569 | |
| 212 | 216 | DEVICE_IMAGE_UNLOAD( mess_hd ) |
| 213 | 217 | { |
| 214 | 218 | struct mess_hd *hd = get_drive(image); |
| 215 | | assert(hd->hard_disk_handle); |
| 216 | | hard_disk_close(hd->hard_disk_handle); |
| 217 | | hd->hard_disk_handle = NULL; |
| 219 | |
| 220 | if (hd->hard_disk_handle != NULL) |
| 221 | { |
| 222 | hard_disk_close(hd->hard_disk_handle); |
| 223 | hd->hard_disk_handle = NULL; |
| 224 | } |
| 225 | |
| 226 | if (hd->chd != NULL) |
| 227 | { |
| 228 | chd_close(hd->chd); |
| 229 | hd->chd = NULL; |
| 230 | } |
| 231 | |
| 218 | 232 | drive_handles[image_index_in_device(image)] = NULL; |
| 219 | 233 | } |
| 220 | 234 | |