1
/* simple program to check implanted md5sum in an iso 9660 image */
2
/* Copyright 2001 Red Hat, Inc. */
3
/* Michael Fulbright msf@redhat.com */
2
* checkosmd5 - simple program to check implanted md5sum
3
* Copyright (C) 2001-2007 Red Hat, Inc.
4
* Michael Fulbright <msf@redhat.com>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
10
27
#include "libcheckisomd5.h"
29
struct progressCBData {
35
static void outputCB(void *co, long long offset, long long total) {
36
struct progressCBData *data = co;
40
printf("\rChecking: %05.1f%%", (100.0*offset)/(total));
44
gaugeval = (100.0*offset)/(total);
45
if (gaugeval != data->gaugeat) {
46
printf("%d\n", gaugeval);
48
data->gaugeat = gaugeval;
53
static void usage(void) {
54
fprintf(stderr, "Usage: checkisomd5 [--md5sumonly] [--verbose] [--gauge] <isofilename>|<blockdevice>\n\n");
12
58
int main(int argc, char **argv) {
63
struct progressCBData data;
22
printf("Usage: checkisomd5 [--md5sumonly] [--verbose] [--gauge] <isofilename>|<blockdevice>\n\n");
67
memset(&data, 0, sizeof(struct progressCBData));
27
flags = 1; /* mediaCheckFile defaults to verbose, not quiet, so prepopulate the "quiet" bit */
31
for (i=1; i < argc; i++) {
32
if (strcmp(argv[i], "--md5sumonly") == 0) {
35
} else if (strcmp(argv[i], "--verbose") == 0) {
39
} else if (strcmp(argv[i], "--gauge") == 0) {
74
struct poptOption options[] = {
75
{ "md5sumonly", 'o', POPT_ARG_NONE, &md5only, 0 },
76
{ "verbose", 'v', POPT_ARG_NONE, &data.verbose, 0 },
77
{ "gauge", 'g', POPT_ARG_NONE, &data.gauge, 0},
78
{ "help", 'h', POPT_ARG_NONE, &help, 0},
82
optCon = poptGetContext("checkisomd5", argc, (const char **)argv, options, 0);
84
if ((rc = poptGetNextOpt(optCon)) < -1) {
85
fprintf(stderr, "bad option %s: %s\n",
86
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
48
printMD5SUM(argv[filearg]);
94
args = poptGetArgs(optCon);
95
if (!args || !args[0] || !args[0][0])
98
if (md5only|data.verbose)
99
printMD5SUM((char *)args[0]);
53
rc = mediaCheckFile(argv[filearg], flags);
55
/* 1 means it passed, 0 means it failed, -1 means we couldnt find chksum */
104
rc = mediaCheckFile((char *)args[0], outputCB, &data);
110
result = "FAIL.\n\nIt is not recommended to use this media.";
112
result = "PASS.\n\nIt is OK to use this media.";
114
result = "NA.\n\nNo checksum information available, unable to verify media.";
116
fprintf(stderr, "\nThe media check is complete, the result is: %s\n", result);