int main(int argc, char **argv) { int i; int rc; int verbose; int md5only; int filearg; if (argc < 2) { printf("Usage: checkisomd5 [--md5sumonly] [--verbose] <isofilename>|<blockdevice>\n\n"); exit(1); } md5only = 0; verbose = 0; filearg = 1; for (i=1; i < argc; i++) { if (strcmp(argv[i], "--md5sumonly") == 0) { md5only = 1; filearg++; } else if (strcmp(argv[i], "--verbose") == 0) { filearg++; verbose = 1; } else break; } if (md5only|verbose) printMD5SUM(argv[filearg]); if (md5only) exit(0); rc = mediaCheckFile(argv[filearg], !verbose); /* 1 means it passed, 0 means it failed, -1 means we couldnt find chksum */ if (rc == 1) exit(0); else exit(1); }
int doMediaCheck(char *file, char *descr) { struct progressCBdata data; newtComponent t, f, scale, label; int rc; int dlen; int llen; char tmpstr[1024]; if (access(file, R_OK) < 0) { newtWinMessage(_("Error"), _("OK"), _("Unable to find install image " "%s"), file); return -1; } if (descr) snprintf(tmpstr, sizeof(tmpstr), _("Checking \"%s\"..."), descr); else snprintf(tmpstr, sizeof(tmpstr), _("Checking media now...")); dlen = strlen(tmpstr); if (dlen > 65) dlen = 65; newtCenteredWindow(dlen+8, 6, _("Media Check")); t = newtTextbox(1, 1, dlen+4, 3, NEWT_TEXTBOX_WRAP); newtTextboxSetText(t, tmpstr); llen = strlen(tmpstr); label = newtLabel(llen+1, 1, "-"); f = newtForm(NULL, NULL, 0); newtFormAddComponent(f, t); scale = newtScale(3, 3, dlen, 100); newtFormAddComponent(f, scale); newtDrawForm(f); newtRefresh(); data.scale = scale; data.label = label; rc = mediaCheckFile(file, progressCallback, &data); newtFormDestroy(f); newtPopWindow(); if (rc == -1) { logMessage(WARNING, "mediacheck: %s (%s) has no checksum info", file, descr); newtWinMessage(_("Error"), _("OK"), _("Unable to read the disc checksum from the " "primary volume descriptor. This probably " "means the disc was created without adding the " "checksum.")); } else if (rc == 0) { logMessage(ERROR, "mediacheck: %s (%s) FAILED", file, descr); newtWinMessage(_("Error"), _("OK"), _("The image which was just tested has errors. " "This could be due to a " "corrupt download or a bad disc. " "If applicable, please clean the disc " "and try again. If this test continues to fail you " "should not continue the install.")); } else if (rc > 0) { logMessage(INFO, "mediacheck: %s (%s) PASSED", file, descr); newtWinMessage(_("Success"), _("OK"), _("The image which was just tested was successfully " "verified. It should be OK to install from this " "media. Note that not all media/drive errors can " "be detected by the media check.")); } return rc; }
/* * Given cd device cddriver, this function will attempt to check its internal * checksum. * * JKFIXME: this ignores "location", which should be fixed */ static char * mediaCheckCdrom(char *cddriver) { int rc; int first; devMakeInode(cddriver, "/tmp/cdrom"); first = 1; do { char *descr; char *tstamp; int ejectcd; /* init every pass */ ejectcd = 0; descr = NULL; /* if first time through, see if they want to eject the CD */ /* currently in the drive (most likely the CD they booted from) */ /* and test a different disk. Otherwise just test the disk in */ /* the drive since it was inserted in the previous pass through */ /* this loop, so they want it tested. */ if (first) { first = 0; rc = newtWinChoice(_("Media Check"), _("Test"), _("Eject CD"), _("Choose \"%s\" to test the CD currently in " "the drive, or \"%s\" to eject the CD and " "insert another for testing."), _("Test"), _("Eject CD")); if (rc == 2) ejectcd = 1; } if (!ejectcd) { /* XXX MSFFIXME: should check return code for error */ readStampFileFromIso("/tmp/cdrom", &tstamp, &descr); mediaCheckFile("/tmp/cdrom", descr); if (descr) free(descr); } if (!FL_NOEJECT(flags)) ejectCdrom(); else logMessage(INFO, "noeject in effect, not ejecting cdrom"); rc = newtWinChoice(_("Media Check"), _("Test"), _("Continue"), _("If you would like to test additional media, " "insert the next CD and press \"%s\". " "Testing each CD is not strictly required, however " "it is highly recommended. Minimally, the CDs should " "be tested prior to using them for the first time. " "After they have been successfully tested, it is not " "required to retest each CD prior to using it again."), _("Test"), _("Continue")); if (rc == 2) { if (!FL_NOEJECT(flags)) unlink("/tmp/cdrom"); else logMessage(INFO, "noeject in effect, not unmounting /tmp/cdrom"); return NULL; } else { continue; } } while (1); return NULL; }