audit_record *media_auditor::audit_one_disk(const rom_entry *rom) { // allocate and append a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(*rom, audit_record::MEDIA_DISK))); // open the disk emu_file *source_file; chd_file *source; chd_error err = open_disk_image(m_enumerator.options(), &m_enumerator.driver(), rom, &source_file, &source, NULL); // if we succeeded, get the hashes if (err == CHDERR_NONE) { static const UINT8 nullhash[20] = { 0 }; chd_header header = *chd_get_header(source); hash_collection hashes; // if there's an MD5 or SHA1 hash, add them to the output hash if (memcmp(nullhash, header.md5, sizeof(header.md5)) != 0) hashes.add_from_buffer(hash_collection::HASH_MD5, header.md5, sizeof(header.md5)); if (memcmp(nullhash, header.sha1, sizeof(header.sha1)) != 0) hashes.add_from_buffer(hash_collection::HASH_SHA1, header.sha1, sizeof(header.sha1)); // update the actual values record.set_actual(hashes); // close the file and release the source chd_close(source); global_free(source_file); } // compute the final status compute_status(record, rom, err == CHDERR_NONE); return &record; }
audit_record *media_auditor::audit_one_disk(const rom_entry *rom, const char *locationtag) { // allocate and append a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(*rom, audit_record::MEDIA_DISK))); // open the disk chd_file source; chd_error err = chd_error(open_disk_image(m_enumerator.options(), &m_enumerator.driver(), rom, source, locationtag)); // if we succeeded, get the hashes if (err == CHDERR_NONE) { hash_collection hashes; // if there's a SHA1 hash, add them to the output hash if (source.sha1() != sha1_t::null) hashes.add_sha1(source.sha1()); // update the actual values record.set_actual(hashes); } // compute the final status compute_status(record, rom, err == CHDERR_NONE); return &record; }
static int hw_disk_ioctl(device *me, cpu *processor, unsigned_word cia, device_ioctl_request request, va_list ap) { switch (request) { case device_ioctl_change_media: { hw_disk_device *disk = device_data(me); const char *name = va_arg(ap, const char *); if (name != NULL) { disk->name_index = -1; } else { disk->name_index = (disk->name_index + 1) % disk->nr_names; if (!device_find_string_array_property(me, "file", disk->name_index, &name)) device_error(me, "invalid file property"); } open_disk_image(me, disk, name); } break; default: device_error(me, "insupported ioctl request"); break; } return 0; }
static void hw_disk_init_address(device *me) { hw_disk_device *disk = device_data(me); unsigned_word address; int space; const char *name; /* attach to the parent. Since the bus is logical, attach using just the unit-address (size must be zero) */ device_address_to_attach_address(device_parent(me), device_unit_address(me), &space, &address, me); device_attach_address(device_parent(me), attach_callback, space, address, 0/*size*/, access_read_write_exec, me); /* Tell the world we are a disk. */ device_add_string_property(me, "device_type", "block"); /* get the name of the file specifying the disk image */ disk->name_index = 0; disk->nr_names = device_find_string_array_property(me, "file", disk->name_index, &name); if (!disk->nr_names) device_error(me, "invalid file property"); /* is it a RO device? */ disk->read_only = (strcmp(device_name(me), "disk") != 0 && strcmp(device_name(me), "floppy") != 0 && device_find_property(me, "read-only") == NULL); /* now open it */ open_disk_image(me, disk, name); }
static void process_disk_entries(romload_private *romdata, const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, const char *locationtag) { /* loop until we hit the end of this region */ for ( ; !ROMENTRY_ISREGIONEND(romp); romp++) { /* handle files */ if (ROMENTRY_ISFILE(romp)) { open_chd *chd = global_alloc(open_chd(regiontag)); hash_collection hashes(ROM_GETHASHDATA(romp)); chd_error err; /* make the filename of the source */ astring filename(ROM_GETNAME(romp), ".chd"); /* first open the source drive */ LOG(("Opening disk image: %s\n", filename.cstr())); err = chd_error(open_disk_image(romdata->machine().options(), &romdata->machine().system(), romp, chd->orig_chd(), locationtag)); if (err != CHDERR_NONE) { handle_missing_file(romdata, romp, astring(), err); global_free(chd); continue; } /* get the header and extract the SHA1 */ hash_collection acthashes; acthashes.add_sha1(chd->orig_chd().sha1()); /* verify the hash */ if (hashes != acthashes) { romdata->errorstring.catprintf("%s WRONG CHECKSUMS:\n", filename.cstr()); dump_wrong_and_correct_checksums(romdata, hashes, acthashes); romdata->warnings++; } else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) { romdata->errorstring.catprintf("%s CHD NEEDS REDUMP\n", filename.cstr()); romdata->knownbad++; } /* if not read-only, make the diff file */ if (!DISK_ISREADONLY(romp)) { /* try to open or create the diff */ err = open_disk_diff(romdata->machine().options(), romp, chd->orig_chd(), chd->diff_chd()); if (err != CHDERR_NONE) { romdata->errorstring.catprintf("%s DIFF CHD ERROR: %s\n", filename.cstr(), chd_file::error_string(err)); romdata->errors++; global_free(chd); continue; } } /* we're okay, add to the list of disks */ LOG(("Assigning to handle %d\n", DISK_GETINDEX(romp))); romdata->machine().romload_data->chd_list.append(*chd); } } }
void rom_load_manager::process_disk_entries(const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, const char *locationtag) { /* loop until we hit the end of this region */ for ( ; !ROMENTRY_ISREGIONEND(romp); romp++) { /* handle files */ if (ROMENTRY_ISFILE(romp)) { auto chd = std::make_unique<open_chd>(regiontag); hash_collection hashes(ROM_GETHASHDATA(romp)); chd_error err; /* make the filename of the source */ std::string filename = std::string(ROM_GETNAME(romp)).append(".chd"); /* first open the source drive */ LOG(("Opening disk image: %s\n", filename.c_str())); err = chd_error(open_disk_image(machine().options(), &machine().system(), romp, chd->orig_chd(), locationtag)); if (err != CHDERR_NONE) { handle_missing_file(romp, std::string(), err); chd = nullptr; continue; } /* get the header and extract the SHA1 */ hash_collection acthashes; acthashes.add_sha1(chd->orig_chd().sha1()); /* verify the hash */ if (hashes != acthashes) { strcatprintf(m_errorstring, "%s WRONG CHECKSUMS:\n", filename.c_str()); dump_wrong_and_correct_checksums(hashes, acthashes); m_warnings++; } else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) { strcatprintf(m_errorstring, "%s CHD NEEDS REDUMP\n", filename.c_str()); m_knownbad++; } /* if not read-only, make the diff file */ if (!DISK_ISREADONLY(romp)) { /* try to open or create the diff */ err = open_disk_diff(machine().options(), romp, chd->orig_chd(), chd->diff_chd()); if (err != CHDERR_NONE) { strcatprintf(m_errorstring, "%s DIFF CHD ERROR: %s\n", filename.c_str(), chd_file::error_string(err)); m_errors++; chd = nullptr; continue; } } /* we're okay, add to the list of disks */ LOG(("Assigning to handle %d\n", DISK_GETINDEX(romp))); m_chd_list.push_back(std::move(chd)); } } }
static void process_disk_entries(rom_load_data *romdata, const rom_entry *romp) { /* loop until we hit the end of this region */ while (!ROMENTRY_ISREGIONEND(romp)) { /* handle files */ if (ROMENTRY_ISFILE(romp)) { chd_file *source, *diff = NULL; chd_header header; char filename[1024]; char acthash[HASH_BUF_SIZE]; chd_error err; /* make the filename of the source */ sprintf(filename, "%s.chd", ROM_GETNAME(romp)); /* first open the source drive */ debugload("Opening disk image: %s\n", filename); err = open_disk_image(Machine->gamedrv, romp, &source); if (err != CHDERR_NONE) { if (err == CHDERR_UNSUPPORTED_VERSION) sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s UNSUPPORTED CHD VERSION\n", filename); else sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s NOT FOUND\n", filename); /* if this is NO_DUMP, keep going, though the system may not be able to handle it */ if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_NO_DUMP)) romdata->warnings++; else romdata->errors++; romp++; continue; } /* get the header and extract the MD5/SHA1 */ header = *chd_get_header(source); hash_data_clear(acthash); hash_data_insert_binary_checksum(acthash, HASH_MD5, header.md5); hash_data_insert_binary_checksum(acthash, HASH_SHA1, header.sha1); /* verify the MD5 */ if (!hash_data_is_equal(ROM_GETHASHDATA(romp), acthash, 0)) { sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s WRONG CHECKSUMS:\n", filename); dump_wrong_and_correct_checksums(romdata, ROM_GETHASHDATA(romp), acthash); romdata->warnings++; } else if (hash_data_has_info(ROM_GETHASHDATA(romp), HASH_INFO_BAD_DUMP)) { sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s CHD NEEDS REDUMP\n", filename); romdata->warnings++; } /* if not read-only, make the diff file */ if (!DISK_ISREADONLY(romp)) { /* make the filename of the diff */ sprintf(filename, "%s.dif", ROM_GETNAME(romp)); /* try to open the diff */ debugload("Opening differencing image: %s\n", filename); err = chd_open(filename, CHD_OPEN_READWRITE, source, &diff); if (err != CHDERR_NONE) { /* didn't work; try creating it instead */ debugload("Creating differencing image: %s\n", filename); err = chd_create(filename, 0, 0, CHDCOMPRESSION_NONE, source); if (err != CHDERR_NONE) { if (err == CHDERR_UNSUPPORTED_VERSION) sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s UNSUPPORTED CHD VERSION\n", filename); else sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s: CAN'T CREATE DIFF FILE\n", filename); romdata->errors++; romp++; continue; } /* open the newly-created diff file */ debugload("Opening differencing image: %s\n", filename); err = chd_open(filename, CHD_OPEN_READWRITE, source, &diff); if (err != CHDERR_NONE) { if (err == CHDERR_UNSUPPORTED_VERSION) sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s UNSUPPORTED CHD VERSION\n", filename); else sprintf(&romdata->errorbuf[strlen(romdata->errorbuf)], "%s: CAN'T OPEN DIFF FILE\n", filename); romdata->errors++; romp++; continue; } } } /* we're okay, set the handle */ debugload("Assigning to handle %d\n", DISK_GETINDEX(romp)); disk_handle[DISK_GETINDEX(romp)] = DISK_ISREADONLY(romp) ? source : diff; romp++; } } }
static int audit_one_disk(const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record) { chd_file *source; chd_error err; /* fill in the record basics */ record->type = AUDIT_FILE_DISK; record->name = ROM_GETNAME(rom); record->exphash = ROM_GETHASHDATA(rom); /* open the disk */ chd_gamedrv = gamedrv; chd_set_interface(&audit_chd_interface); err = open_disk_image(gamedrv, rom, &source); /* if we failed, report the error */ if (err != CHDERR_NONE) { /* out of memory */ if (err == CHDERR_OUT_OF_MEMORY) set_status(record, AUDIT_STATUS_ERROR, SUBSTATUS_ERROR); /* not found but it's not good anyway */ else if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP)) set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND_NODUMP); /* not found at all */ else set_status(record, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND); } /* if we succeeded, validate it */ else { static const UINT8 nullhash[HASH_BUF_SIZE] = { 0 }; chd_header header = *chd_get_header(source); /* if there's an MD5 or SHA1 hash, add them to the output hash */ if (memcmp(nullhash, header.md5, sizeof(header.md5)) != 0) hash_data_insert_binary_checksum(record->hash, HASH_MD5, header.md5); if (memcmp(nullhash, header.sha1, sizeof(header.sha1)) != 0) hash_data_insert_binary_checksum(record->hash, HASH_SHA1, header.sha1); /* found but needs a dump */ if (hash_data_has_info(record->exphash, HASH_INFO_NO_DUMP)) set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD_NEEDS_REDUMP); /* incorrect hash */ else if (!hash_data_is_equal(record->exphash, record->hash, 0)) set_status(record, AUDIT_STATUS_FOUND_INVALID, SUBSTATUS_FOUND_BAD_CHECKSUM); /* just plain good */ else set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD); chd_close(source); } /* return TRUE if we found anything at all */ return (source != NULL); }