73
76
static struct percents_t percents;
78
/* the hash functions, which needs to be reported first on mismatch */
79
#define REPORT_FIRST_MASK (RHASH_MD5 | RHASH_SHA256 | RHASH_SHA512)
82
* Print verbose error on hash sums mismatch.
84
* @param info file information with path and its hash sums.
86
static void print_verbose_error(struct file_info *info)
88
char actual[130], expected[130];
89
assert(HC_FAILED(info->hc.flags));
91
fprintf(rhash_data.out, "ERROR");
93
if(HC_WRONG_FILESIZE & info->hc.flags) {
94
sprintI64(actual, info->rctx->msg_size, 0);
95
sprintI64(expected, info->hc.file_size, 0);
96
fprintf(rhash_data.out, ", size is %s should be %s", actual, expected);
99
if(HC_WRONG_EMBCRC32 & info->hc.flags) {
100
rhash_print(expected, info->rctx, RHASH_CRC32, RHPR_UPPERCASE);
101
fprintf(rhash_data.out, ", embedded CRC32 should be %s", expected);
104
if(HC_WRONG_HASHES & info->hc.flags) {
106
unsigned reported = 0;
107
for(i = 0; i < info->hc.hashes_num; i++) {
108
hash_value *hv = &info->hc.hashes[i];
109
char *expected_hash = info->hc.data + hv->offset;
110
unsigned hid = hv->hash_id;
112
if((info->hc.wrong_hashes & (1 << i)) == 0) continue;
116
/* if can't detect precise hash */
117
if((hid & (hid - 1)) != 0) {
118
/* guess the hash id */
119
if(hid & opt.sum_flags) hid &= opt.sum_flags;
120
if(hid & ~info->hc.found_hash_ids) hid &= ~info->hc.found_hash_ids;
121
if(hid & ~reported) hid &= ~reported; /* avoiding repeating */
122
if(hid & REPORT_FIRST_MASK) hid &= REPORT_FIRST_MASK;
123
hid &= -(int)hid; /* take the lowest bit */
125
assert(hid != 0 && (hid & (hid - 1)) == 0); /* single bit only */
128
pflags = (hv->length == (rhash_get_digest_size(hid) * 2) ?
129
(RHPR_HEX | RHPR_UPPERCASE) : (RHPR_BASE32 | RHPR_UPPERCASE));
130
rhash_print(actual, info->rctx, hid, pflags);
131
fprintf(rhash_data.out, ", %s is %s should be %s",
132
rhash_get_name(hid), actual, expected_hash);
136
fprintf(rhash_data.out, "\n");
76
141
* Print file path and result of its verification by hash.
77
* Also if error occured, print error message.
142
* Also if error occurred, print error message.
79
144
* @param info pointer to the file-info structure
80
145
* @param print_name set to non-zero to print file path
89
154
if(info->error == -1) {
90
155
/* print error to stdout */
91
156
fprintf(rhash_data.out, "%s\n", strerror(errno));
92
} else if(info->wrong_sums == 0 || !(opt.flags & OPT_VERBOSE)) {
93
/* using 4 characters to overwrite percent */
94
fprintf(rhash_data.out, (info->wrong_sums == 0 ? "OK \n" : "ERR\n") );
157
} else if(!HC_FAILED(info->hc.flags) || !(opt.flags & OPT_VERBOSE)) {
158
/* using 3 characters to overwrite percent */
159
fprintf(rhash_data.out, (!HC_FAILED(info->hc.flags) ? "OK \n" : "ERR\n") );
97
char actual[130], expected[130];
99
/* print verbose info about wrong sums */
100
fprintf(rhash_data.out, "ERROR");
101
for(id = 1; id < RHASH_ALL_HASHES; id <<= 1) {
102
if(id & info->wrong_sums) {
103
int pflags = (rhash_is_base32(id) ? RHPR_BASE32 | RHPR_UPPERCASE : RHPR_HEX | RHPR_UPPERCASE);
104
rhash_print_bytes(expected, rhash_get_digest_ptr(info->orig_sums, id), rhash_get_digest_size(id), pflags);
106
rhash_print(actual, info->rctx, id, RHPR_UPPERCASE);
107
fprintf(rhash_data.out, ", %s is %s should be %s", rhash_get_name(id), actual, expected);
110
if(RHASH_EMBEDDED_CRC32 & info->wrong_sums) {
111
rhash_print(expected, info->rctx, RHASH_CRC32, RHPR_UPPERCASE);
112
fprintf(rhash_data.out, ", embedded sum should be %s", expected);
114
fprintf(rhash_data.out, "\n");
161
print_verbose_error(info);
117
164
fflush(rhash_data.out);
165
212
print_results_on_check(info, 0);
168
/* functions to output file info with simple multy-line wget-like percents */
215
/* functions to output file info with simple multi-line wget-like percents */
171
218
* Initialize dots percent mode.
173
220
* @param info pointer to the file-info structure
174
* @return non-zero, indicating that the output method succesfully initialized
221
* @return non-zero, indicating that the output method successfully initialized
176
223
static int dots_init_percents(struct file_info *info)
213
260
if( (offset % pt_size) != 0 ) return;
215
262
if(percents.points == 0) {
216
fprintf(rhash_data.log, "\n%s %s\n",
217
(opt.mode & (MODE_CHECK | MODE_CHECK_EMBEDDED) ? "Checking" : "Processing"),
263
fprintf(rhash_data.log, "\n%s %s\n",
264
(opt.mode & (MODE_CHECK | MODE_CHECK_EMBEDDED) ? "Checking" : "Processing"),
218
265
info->print_path);
219
266
fflush(rhash_data.log);
380
427
rhash_data.log = stderr;
382
429
if(opt.flags & OPT_PERCENTS) {
383
/* we don't use _fileno() cause it is not in ISO C90, and so undefined
384
when compiling with the GCC -ansi option */
430
/* we don't use _fileno() cause it is not in ISO C90, and so
431
* is incompatible with the GCC -ansi option */
385
432
if(rhash_data.log == stderr && isatty(2)) {
386
433
percents_output = &p_perc;
389
435
percents_output = &dots_perc;
443
489
* Print processing time statistics.
445
void print_time_stats(double time, uint64_t size, int total)
491
void print_time_stats(double time, uint64_t size, int total)
447
493
double speed = (time == 0 ? 0 : (double)(int64_t)size / 1048576.0 / time);
448
494
fprintf(rhash_data.log, "%s %.3f sec, %4.2f MBps\n",