summaryrefslogtreecommitdiffstats
path: root/isomd5sum/checkisomd5.c
diff options
context:
space:
mode:
authorMike Fulbright <msf@redhat.com>2002-08-08 05:08:46 +0000
committerMike Fulbright <msf@redhat.com>2002-08-08 05:08:46 +0000
commita794a5c4529953a0dc18a108d05349fa9dd3575e (patch)
tree83d2bbaa37ceadfd91a0174d49ec099e3b0f5b7d /isomd5sum/checkisomd5.c
parent5be372f6d1045277950d6f6eba9b371493ee8f5d (diff)
downloadanaconda-a794a5c4529953a0dc18a108d05349fa9dd3575e.tar.gz
anaconda-a794a5c4529953a0dc18a108d05349fa9dd3575e.tar.xz
anaconda-a794a5c4529953a0dc18a108d05349fa9dd3575e.zip
added info to header in app data area so we can read out skip we used
Diffstat (limited to 'isomd5sum/checkisomd5.c')
-rw-r--r--isomd5sum/checkisomd5.c81
1 files changed, 62 insertions, 19 deletions
diff --git a/isomd5sum/checkisomd5.c b/isomd5sum/checkisomd5.c
index dfaba9d42..539fcfd89 100644
--- a/isomd5sum/checkisomd5.c
+++ b/isomd5sum/checkisomd5.c
@@ -18,13 +18,14 @@
#define MAX(x, y) ((x > y) ? x : y)
#define MIN(x, y) ((x < y) ? x : y)
-/* number of sectors to ignore at end of iso when computing sum */
-#define SKIPSECTORS 15
-
/* finds primary volume descriptor and returns info from it */
/* mediasum must be a preallocated buffer at least 33 bytes long */
-int parsepvd(int isofd, char *mediasum, long long *isosize) {
+int parsepvd(int isofd, char *mediasum, int *skipsectors, long long *isosize) {
unsigned char buf[2048];
+ unsigned char buf2[512];
+ unsigned char tmpbuf[512];
+ int skipfnd, md5fnd;
+ unsigned int loc;
long long offset;
unsigned char *p;
@@ -44,15 +45,55 @@ int parsepvd(int isofd, char *mediasum, long long *isosize) {
}
/* read out md5sum */
- memcpy(mediasum, buf + APPDATA_OFFSET + 13, 32);
- mediasum[32] = '\0';
-
- for (p=mediasum; *p; p++)
- if (*p != ' ')
- break;
+ memcpy(buf2, buf + APPDATA_OFFSET, 512);
+ buf2[511] = '\0';
+
+ md5fnd = 0;
+ skipfnd = 0;
+ loc = 0;
+ while (loc < 512) {
+ if (!strncmp(buf2 + loc, "ISO MD5SUM = ", 13)) {
+
+ /* make sure we dont walk off end */
+ if ((loc + 32) > 511)
+ return -1;
+
+ memcpy(mediasum, buf2 + loc + 13, 32);
+ mediasum[32] = '\0';
+ md5fnd = 1;
+ loc += 45;
+ for (p=buf2+loc; *p != ';' && loc < 512; p++, loc++);
+ } else if (!strncmp(buf2 + loc, "SKIPSECTORS = ", 14)) {
+ char *errptr;
+
+ /* make sure we dont walk off end */
+ if ((loc + 14) > 511)
+ return -1;
+
+ loc = loc + 14;
+ for (p=tmpbuf; buf2[loc] != ';' && loc < 512; p++, loc++)
+ *p = buf2[loc];
+
+ *p = '\0';
+
+ *skipsectors = strtol(tmpbuf, &errptr, 10);
+ if (errptr && *errptr) {
+ return -1;
+ } else {
+ skipfnd = 1;
+ }
+
+ for (p=buf2+loc; *p != ';' && loc < 512; p++, loc++);
+ } else {
+ loc += 1;
+ }
- /* if the md5sum was all spaces, we didn't find md5sum */
- if (!*p)
+ if (skipfnd & md5fnd)
+ break;
+ }
+
+
+ if (!(skipfnd & md5fnd))
return -1;
/* get isosize */
@@ -70,6 +111,7 @@ int checkmd5sum(int isofd, char *mediasum, char *computedsum) {
int i;
int appdata_start_offset, appdata_end_offset;
int nattempt;
+ int skipsectors;
unsigned int bufsize = 32768;
unsigned char md5sum[16];
unsigned int len;
@@ -77,7 +119,7 @@ int checkmd5sum(int isofd, char *mediasum, char *computedsum) {
long long isosize, offset, pvd_offset, apoff;
MD5_CTX md5ctx;
- if ((pvd_offset = parsepvd(isofd, mediasum, &isosize)) < 0)
+ if ((pvd_offset = parsepvd(isofd, mediasum, &skipsectors, &isosize)) < 0)
return -1;
/* printf("Mediasum = %s\n",mediasum); */
@@ -91,10 +133,10 @@ int checkmd5sum(int isofd, char *mediasum, char *computedsum) {
apoff = pvd_offset + APPDATA_OFFSET;
buf = malloc(bufsize * sizeof(unsigned char));
- printf("Percent complete: %05.1f%%", (100.0*offset)/(isosize-SKIPSECTORS*2048.0));
+ printf("Percent complete: %05.1f%%", (100.0*offset)/(isosize-skipsectors*2048.0));
fflush(stdout);
- while (offset < isosize - SKIPSECTORS*2048) {
- nattempt = MIN(isosize - SKIPSECTORS*2048 - offset, bufsize);
+ while (offset < isosize - skipsectors*2048) {
+ nattempt = MIN(isosize - skipsectors*2048 - offset, bufsize);
/* printf("%lld %lld %lld %d\n", offset, isosize, isosize-SKIPSECTORS*2048, nattempt); */
@@ -124,11 +166,11 @@ int checkmd5sum(int isofd, char *mediasum, char *computedsum) {
MD5_Update(&md5ctx, buf, nread);
offset = offset + nread;
- printf("\b\b\b\b\b\b%05.1f%%", (100.0*offset)/(isosize-SKIPSECTORS*2048.0));
+ printf("\b\b\b\b\b\b%05.1f%%", (100.0*offset)/(isosize-skipsectors*2048.0));
fflush(stdout);
}
- printf("\b\b\b\b\b\b\n\n", (100.0*offset)/(isosize-SKIPSECTORS*2048.0));
+ printf("\b\b\b\b\b\b\n\n", (100.0*offset)/(isosize-skipsectors*2048.0));
sleep(1);
@@ -172,8 +214,9 @@ static void readCB(void *co, long long pos) {
int doMediaCheck(int isofd, char *mediasum, char *computedsum, long long *isosize) {
int rc;
int llen;
+ int skipsectors;
- if (parsepvd(isofd, mediasum, isosize) < 0) {
+ if (parsepvd(isofd, mediasum, &skipsectors, isosize) < 0) {
fprintf(stderr, "Unable to read the disc checksum from the "
"primary volume descriptor. This probably "
"means the disc was created without adding the "