summaryrefslogtreecommitdiffstats
path: root/isomd5sum
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2005-04-27 03:37:16 +0000
committerJeremy Katz <katzj@redhat.com>2005-04-27 03:37:16 +0000
commit51281e95f087a81111e69d21834d67e6e97b0d62 (patch)
tree22e59c199161b757fc4f656f6dc6d8eb595b9a12 /isomd5sum
parentb84e93eb79f9238e72bf004652c7e81b5b781fa3 (diff)
downloadanaconda-51281e95f087a81111e69d21834d67e6e97b0d62.tar.gz
anaconda-51281e95f087a81111e69d21834d67e6e97b0d62.tar.xz
anaconda-51281e95f087a81111e69d21834d67e6e97b0d62.zip
2005-04-26 Jeremy Katz <katzj@redhat.com>
* isomd5sum/libimplantisomd5.c: Add Dustin Kirkland's patch for implanting the isomd5 fragments. * isomd5sum/libcheckisomd5.c: Add Dustin's patch to give slightly more verbose output.
Diffstat (limited to 'isomd5sum')
-rw-r--r--isomd5sum/libcheckisomd5.c16
-rw-r--r--isomd5sum/libimplantisomd5.c65
2 files changed, 73 insertions, 8 deletions
diff --git a/isomd5sum/libcheckisomd5.c b/isomd5sum/libcheckisomd5.c
index 552055634..b7ab1e9e2 100644
--- a/isomd5sum/libcheckisomd5.c
+++ b/isomd5sum/libcheckisomd5.c
@@ -167,6 +167,7 @@ static int checkmd5sum(int isofd, char *mediasum, char *computedsum, int quiet)
int supported;
int current_fragment = 0;
int previous_fragment = 0;
+ int printed_frag_status = 0;
unsigned int bufsize = 32768;
unsigned char md5sum[16];
unsigned char fragmd5sum[16];
@@ -246,10 +247,17 @@ static int checkmd5sum(int isofd, char *mediasum, char *computedsum, int quiet)
thisfragsum[i] = fragmentsums[j++];
}
thisfragsum[j] = '\0';
- /* printf("\nFragment [%i]: %s ?= %s\n", previous_fragment, computedsum, thisfragsum); */
+ if (!quiet) {
+ printf(" Fragment[%02i/%02lld] -> OK", previous_fragment+1, fragmentcount);
+ printed_frag_status = 1;
+ fflush(stdout);
+ }
previous_fragment = current_fragment;
- /* Exit immediatiately if current fragment sum is incorrect */
+ /* Exit immediately if current fragment sum is incorrect */
if (strcmp(thisfragsum, computedsum) != 0) {
+ if (!quiet) {
+ printf("\nFragment %02i of %02lld is BAD!\n", previous_fragment+1, fragmentcount);
+ }
free(buf);
return 0;
}
@@ -258,6 +266,10 @@ static int checkmd5sum(int isofd, char *mediasum, char *computedsum, int quiet)
offset = offset + nread;
if (!quiet) {
+ if (printed_frag_status) {
+ printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
+ printed_frag_status = 0;
+ }
printf("\b\b\b\b\b\b%05.1f%%", (100.0*offset)/(isosize-skipsectors*2048.0));
fflush(stdout);
}
diff --git a/isomd5sum/libimplantisomd5.c b/isomd5sum/libimplantisomd5.c
index 67a9fda5c..e78032184 100644
--- a/isomd5sum/libimplantisomd5.c
+++ b/isomd5sum/libimplantisomd5.c
@@ -1,6 +1,10 @@
/* Copyright 2001 Red Hat, Inc. */
/* Michael Fulbright msf@redhat.com */
+/* 4/2005 Dustin Kirkland (dustin.kirkland@gmail.com) */
+/* Added support for checkpoint fragment sums; */
+/* Allows for exiting media check when bad fragment md5sum'ed */
+
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -15,6 +19,12 @@
#define APPDATA_OFFSET 883
#define SIZE_OFFSET 84
+/* Length in characters of string used for fragment md5sum checking */
+#define FRAGMENT_SUM_LENGTH 60
+/* FRAGMENT_COUNT must be an integral divisor or FRAGMENT_SUM_LENGTH */
+/* 60 => 2, 3, 4, 5, 6, 10, 12, 15, 20, or 30 */
+#define FRAGMENT_COUNT 20
+
/* number of sectors to ignore at end of iso when computing sum */
#define SKIPSECTORS 15
@@ -87,15 +97,21 @@ int implantISOFile(char *fname, int supported, int forceit, int quiet, char **er
int nread;
int dirty;
int pvd_offset;
+ int current_fragment = 0;
+ int previous_fragment = 0;
+ int nattempt;
long long isosize, total;
unsigned char md5sum[16];
+ unsigned char fragmd5sum[16];
unsigned int loc;
- unsigned char buf[2048];
+ unsigned int bufsize = 32768;
+ unsigned char *buf;
unsigned char orig_appdata[512];
unsigned char new_appdata[512];
char mediasum[33];
char md5str[40];
- MD5_CTX md5ctx;
+ char fragstr[FRAGMENT_SUM_LENGTH+1];
+ MD5_CTX md5ctx, fragmd5ctx;
isofd = open(fname, O_RDWR);
@@ -138,18 +154,38 @@ int implantISOFile(char *fname, int supported, int forceit, int quiet, char **er
lseek(isofd, 0L, SEEK_SET);
MD5_Init(&md5ctx);
+ *fragstr = '\0';
+ buf = malloc(bufsize * sizeof(unsigned char));
total = 0;
/* read up to 15 sectors from end, due to problems reading last few */
/* sectors on burned CDs */
while (total < isosize - SKIPSECTORS*2048) {
- nread = read(isofd, buf, 2048);
+ nattempt = MIN(isosize - SKIPSECTORS*2048 - total, bufsize);
+ nread = read(isofd, buf, nattempt);
+
if (nread <= 0)
break;
-
+
MD5_Update(&md5ctx, buf, nread);
+
+ /* if we're onto the next fragment, calculate the previous sum and write */
+ current_fragment = total * (FRAGMENT_COUNT+1) / (isosize - SKIPSECTORS*2048);
+ if ( current_fragment != previous_fragment ) {
+ memcpy(&fragmd5ctx, &md5ctx, sizeof(MD5_CTX));
+ MD5_Final(fragmd5sum, &fragmd5ctx);
+ for (i=0; i<FRAGMENT_SUM_LENGTH/FRAGMENT_COUNT; i++) {
+ char tmpstr[2];
+ snprintf(tmpstr, 2, "%01x", fragmd5sum[i]);
+ strncat(fragstr, tmpstr, 2);
+ }
+ /* printf("\nFragment [%i]: %s\n", previous_fragment, fragstr); */
+ previous_fragment = current_fragment;
+ }
+
total = total + nread;
}
+ free(buf);
MD5_Final(md5sum, &md5ctx);
@@ -157,12 +193,15 @@ int implantISOFile(char *fname, int supported, int forceit, int quiet, char **er
for (i=0; i<16; i++) {
char tmpstr[4];
snprintf (tmpstr, 4, "%02x", md5sum[i]);
- strcat(md5str, tmpstr);
+ strncat(md5str, tmpstr, 2);
}
if (!quiet) {
printf("Inserting md5sum into iso image...\n");
printf("md5 = %s\n", md5str);
+ printf("Inserting fragment md5sums into iso image...\n");
+ printf("fragmd5 = %s\n", fragstr);
+ printf("frags = %d\n", FRAGMENT_COUNT);
}
/* memcpy(new_appdata, orig_appdata, 512); */
memset(new_appdata, ' ', 512);
@@ -171,9 +210,13 @@ int implantISOFile(char *fname, int supported, int forceit, int quiet, char **er
loc = writeAppData(new_appdata, "ISO MD5SUM = ", loc);
loc = writeAppData(new_appdata, md5str, loc);
loc = writeAppData(new_appdata, ";", loc);
- snprintf((char *)buf, sizeof(buf), "SKIPSECTORS = %d", SKIPSECTORS);
+
+ buf = malloc(512 * sizeof(unsigned char));
+ snprintf((char *)buf, 512, "SKIPSECTORS = %d", SKIPSECTORS);
+
loc = writeAppData(new_appdata, (char *)buf, loc);
loc = writeAppData(new_appdata, ";", loc);
+ free(buf);
if (supported) {
if (!quiet)
@@ -187,6 +230,16 @@ int implantISOFile(char *fname, int supported, int forceit, int quiet, char **er
loc = writeAppData(new_appdata, ";", loc);
+ loc = writeAppData(new_appdata, "FRAGMENT SUMS = ", loc);
+ loc = writeAppData(new_appdata, fragstr, loc);
+ loc = writeAppData(new_appdata, ";", loc);
+
+ buf = malloc(512 * sizeof(unsigned char));
+ snprintf((char *)buf, 512, "FRAGMENT COUNT = %d", FRAGMENT_COUNT);
+ loc = writeAppData(new_appdata, (char *)buf, loc);
+ loc = writeAppData(new_appdata, ";", loc);
+ free(buf);
+
loc = writeAppData(new_appdata, "THIS IS NOT THE SAME AS RUNNING MD5SUM ON THIS ISO!!", loc);
i = lseek(isofd, pvd_offset + APPDATA_OFFSET, SEEK_SET);