summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-main.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3-main.h')
-rwxr-xr-xxdelta3/xdelta3-main.h69
1 files changed, 50 insertions, 19 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index d33ccd3..0a2592e 100755
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -234,6 +234,9 @@ struct _main_blklru
234 main_blklru_list link; 234 main_blklru_list link;
235}; 235};
236 236
237#define LRU_SIZE 32U
238#define XD3_MINSRCWINSZ XD3_ALLOCSIZE
239
237/* ... represented as a list (no cache index). */ 240/* ... represented as a list (no cache index). */
238XD3_MAKELIST(main_blklru_list,main_blklru,link); 241XD3_MAKELIST(main_blklru_list,main_blklru,link);
239 242
@@ -402,7 +405,7 @@ main_malloc1 (usize_t size)
402{ 405{
403 void* r = malloc (size); 406 void* r = malloc (size);
404 if (r == NULL) { XPR(NT "malloc: %s\n", xd3_mainerror (ENOMEM)); } 407 if (r == NULL) { XPR(NT "malloc: %s\n", xd3_mainerror (ENOMEM)); }
405 else if (option_verbose > 2) { XPR(NT "malloc: %u: %p\n", size, r); } 408 else if (option_verbose > 3) { XPR(NT "malloc: %u: %p\n", size, r); }
406 return r; 409 return r;
407} 410}
408 411
@@ -425,7 +428,7 @@ main_alloc (void *opaque,
425static void 428static void
426main_free1 (void *opaque, void *ptr) 429main_free1 (void *opaque, void *ptr)
427{ 430{
428 if (option_verbose > 2) { XPR(NT "free: %p\n", ptr); } 431 if (option_verbose > 3) { XPR(NT "free: %p\n", ptr); }
429 free (ptr); 432 free (ptr);
430} 433}
431 434
@@ -589,16 +592,25 @@ main_strtoxoff (const char* s, xoff_t *xo, char which)
589} 592}
590 593
591static int 594static int
592main_atou (const char* arg, usize_t *xo, usize_t low, char which) 595main_atou (const char* arg, usize_t *xo, usize_t low, usize_t high, char which)
593{ 596{
594 xoff_t x; 597 xoff_t x;
595 int ret; 598 int ret;
596 599
597 if ((ret = main_strtoxoff (arg, & x, which))) { return ret; } 600 if ((ret = main_strtoxoff (arg, & x, which))) { return ret; }
598 601
599 if (x > USIZE_T_MAX || x < low) 602 if (x < low)
603 {
604 XPR(NT "-%c: minimum value: %u\n", which, low);
605 return EXIT_FAILURE;
606 }
607 if (high == 0)
608 {
609 high = USIZE_T_MAX;
610 }
611 if (x > high)
600 { 612 {
601 XPR(NT "-%c: minimum value: %u", which, low); 613 XPR(NT "-%c: maximum value: %u\n", which, high);
602 return EXIT_FAILURE; 614 return EXIT_FAILURE;
603 } 615 }
604 (*xo) = (usize_t)x; 616 (*xo) = (usize_t)x;
@@ -863,7 +875,7 @@ main_file_read (main_file *ifile,
863 } 875 }
864 else 876 else
865 { 877 {
866 if (option_verbose > 2) { XPR(NT "main read: %s: %u\n", ifile->filename, (*nread)); } 878 if (option_verbose > 3) { XPR(NT "main read: %s: %u\n", ifile->filename, (*nread)); }
867 ifile->nread += (*nread); 879 ifile->nread += (*nread);
868 } 880 }
869 881
@@ -903,7 +915,7 @@ main_file_write (main_file *ofile, uint8_t *buf, usize_t size, const char *msg)
903 } 915 }
904 else 916 else
905 { 917 {
906 if (option_verbose > 2) { XPR(NT "main write: %s: %u\n", ofile->filename, size); } 918 if (option_verbose > 3) { XPR(NT "main write: %s: %u\n", ofile->filename, size); }
907 ofile->nwrite += size; 919 ofile->nwrite += size;
908 } 920 }
909 921
@@ -2035,16 +2047,16 @@ main_set_source (xd3_stream *stream, int cmd, main_file *sfile, xd3_source *sour
2035 else 2047 else
2036 { 2048 {
2037 /* Minimum size check */ 2049 /* Minimum size check */
2038 option_srcwinsz = max(option_srcwinsz, XD3_ALLOCSIZE); 2050 option_srcwinsz = max(option_srcwinsz, XD3_MINSRCWINSZ);
2039 2051
2040 if (!option_srcwinsz_set) 2052 if (!option_srcwinsz_set)
2041 { 2053 {
2042 /* If the flag was not set, scale srcwinsz up to 64MB. */ 2054 /* If the flag was not set, scale srcwinsz up to 64MB. */
2043 option_srcwinsz = min(1ULL<<26, source->size); 2055 option_srcwinsz = min((xoff_t) XD3_DEFAULT_SRCWINSZ, source->size);
2044 } 2056 }
2045 2057
2046 source->blksize = (option_srcwinsz / 32) & ~(XD3_ALLOCSIZE - 1);; 2058 source->blksize = (option_srcwinsz / LRU_SIZE);
2047 lru_size = 32; 2059 lru_size = LRU_SIZE;
2048 } 2060 }
2049 2061
2050 main_blklru_list_init (& lru_list); 2062 main_blklru_list_init (& lru_list);
@@ -2398,11 +2410,6 @@ main_input (xd3_cmd cmd,
2398 return EXIT_FAILURE; 2410 return EXIT_FAILURE;
2399 } 2411 }
2400 2412
2401 if (option_verbose > 1)
2402 {
2403 XPR(NT "scanner configuration: %s\n", stream.smatcher.name);
2404 }
2405
2406 /* This times each window. */ 2413 /* This times each window. */
2407 get_millisecs_since (); 2414 get_millisecs_since ();
2408 2415
@@ -2637,6 +2644,24 @@ done:
2637 return EXIT_FAILURE; 2644 return EXIT_FAILURE;
2638 } 2645 }
2639 2646
2647 if (option_verbose > 1)
2648 {
2649 XPR(NT "scanner configuration: %s\n", stream.smatcher.name);
2650 XPR(NT "target hash table size: %u\n", stream.small_hash.size);
2651 if (sfile->filename != NULL)
2652 {
2653 XPR(NT "source hash table size: %u\n", stream.large_hash.size);
2654 }
2655 }
2656
2657 if (option_verbose > 2)
2658 {
2659 XPR(NT "source copies: %"Q"u (%"Q"u bytes)\n", stream.n_scpy, stream.l_scpy);
2660 XPR(NT "target copies: %"Q"u (%"Q"u bytes)\n", stream.n_tcpy, stream.l_tcpy);
2661 XPR(NT "adds: %"Q"u (%"Q"u bytes)\n", stream.n_add, stream.l_add);
2662 XPR(NT "runs: %"Q"u (%"Q"u bytes)\n", stream.n_run, stream.l_run);
2663 }
2664
2640 xd3_free_stream (& stream); 2665 xd3_free_stream (& stream);
2641 2666
2642 if (option_verbose) 2667 if (option_verbose)
@@ -2870,7 +2895,10 @@ main (int argc, char **argv)
2870 /* only set profile count once, since... */ 2895 /* only set profile count once, since... */
2871 if (option_profile_cnt == 0) 2896 if (option_profile_cnt == 0)
2872 { 2897 {
2873 if ((ret = main_atou(my_optarg, (usize_t*) & option_profile_cnt, 0, 'P'))) { goto exit; } 2898 if ((ret = main_atou(my_optarg, (usize_t*) & option_profile_cnt, 0, 0, 'P')))
2899 {
2900 goto exit;
2901 }
2874 2902
2875 if (option_profile_cnt <= 0) 2903 if (option_profile_cnt <= 0)
2876 { 2904 {
@@ -2891,12 +2919,15 @@ main (int argc, char **argv)
2891 else { option_appheader = (uint8_t*) my_optarg; } break; 2919 else { option_appheader = (uint8_t*) my_optarg; } break;
2892 case 'B': 2920 case 'B':
2893 option_srcwinsz_set = 1; 2921 option_srcwinsz_set = 1;
2894 if ((ret = main_atou (my_optarg, & option_srcwinsz, XD3_ALLOCSIZE, 'B'))) 2922 if ((ret = main_atou (my_optarg, & option_srcwinsz, XD3_MINSRCWINSZ,
2923 0, 'B')))
2895 { 2924 {
2896 goto exit; 2925 goto exit;
2897 } 2926 }
2898 break; 2927 break;
2899 case 'W': if ((ret = main_atou (my_optarg, & option_winsize, XD3_ALLOCSIZE, 'W'))) 2928 case 'W':
2929 if ((ret = main_atou (my_optarg, & option_winsize, XD3_ALLOCSIZE,
2930 XD3_HARDMAXWINSIZE, 'W')))
2900 { 2931 {
2901 goto exit; 2932 goto exit;
2902 } 2933 }