MCPcopy Create free account
hub / github.com/RsyncProject/rsync / file_checksum

Function file_checksum

checksum.c:401–538  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

399}
400
401void file_checksum(const char *fname, const STRUCT_STAT *st_p, char *sum)
402{
403 struct map_struct *buf;
404 OFF_T i, len = st_p->st_size;
405 int32 remainder;
406 int fd;
407
408 fd = do_open_checklinks(fname);
409 if (fd == -1) {
410 memset(sum, 0, file_sum_len);
411 return;
412 }
413
414 buf = map_file(fd, len, MAX_MAP_SIZE, CHUNK_SIZE);
415
416#ifdef USE_OPENSSL
417 if (file_sum_evp_md) {
418 static EVP_MD_CTX *evp = NULL;
419 if (!evp && !(evp = EVP_MD_CTX_create()))
420 out_of_memory("file_checksum");
421
422 EVP_DigestInit_ex(evp, file_sum_evp_md, NULL);
423
424 for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE)
425 EVP_DigestUpdate(evp, (uchar *)map_ptr(buf, i, CHUNK_SIZE), CHUNK_SIZE);
426
427 remainder = (int32)(len - i);
428 if (remainder > 0)
429 EVP_DigestUpdate(evp, (uchar *)map_ptr(buf, i, remainder), remainder);
430
431 EVP_DigestFinal_ex(evp, (uchar *)sum, NULL);
432 } else
433#endif
434 switch (file_sum_nni->num) {
435#ifdef SUPPORT_XXHASH
436 case CSUM_XXH64: {
437 static XXH64_state_t* state = NULL;
438 if (!state && !(state = XXH64_createState()))
439 out_of_memory("file_checksum");
440
441 XXH64_reset(state, 0);
442
443 for (i = 0; i + CHUNK_SIZE <= len; i += CHUNK_SIZE)
444 XXH64_update(state, (uchar *)map_ptr(buf, i, CHUNK_SIZE), CHUNK_SIZE);
445
446 remainder = (int32)(len - i);
447 if (remainder > 0)
448 XXH64_update(state, (uchar *)map_ptr(buf, i, remainder), remainder);
449
450 SIVAL64(sum, 0, XXH64_digest(state));
451 break;
452 }
453#endif
454#ifdef SUPPORT_XXH3
455 case CSUM_XXH3_64: {
456 static XXH3_state_t* state = NULL;
457 if (!state && !(state = XXH3_createState()))
458 out_of_memory("file_checksum");

Callers 2

make_fileFunction · 0.85
quick_check_okFunction · 0.85

Calls 12

do_open_checklinksFunction · 0.85
map_fileFunction · 0.85
map_ptrFunction · 0.85
SIVAL64Function · 0.85
md5_beginFunction · 0.85
md5_updateFunction · 0.85
md5_resultFunction · 0.85
mdfour_beginFunction · 0.85
mdfour_updateFunction · 0.85
mdfour_resultFunction · 0.85
unmap_fileFunction · 0.85
rprintfFunction · 0.70

Tested by

no test coverage detected