/* Recursively enter all directories, adding all regular files to the dirlist array */ static void recurse_dirlist(char *indir, char **dirlist, int *entries) { char fname[MAX_PATH_LEN]; struct stat istat; struct dirent *dp; DIR *dirp; dirp = opendir(indir); if (unlikely(!dirp)) failure("Unable to open directory %s\n", indir); while ((dp = readdir(dirp)) != NULL) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; sprintf(fname, "%s/%s", indir, dp->d_name); if (unlikely(stat(fname, &istat))) failure("Unable to stat file %s\n", fname); if (S_ISDIR(istat.st_mode)) { recurse_dirlist(fname, dirlist, entries); continue; } if (!S_ISREG(istat.st_mode)) { print_err("Not regular file %s\n", fname); continue; } print_maxverbose("Added file %s\n", fname); *dirlist = realloc(*dirlist, MAX_PATH_LEN * (*entries + 1)); strcpy(*dirlist + MAX_PATH_LEN * (*entries)++, fname); } closedir(dirp); }
static void show_summary(void) { /* OK, if verbosity set, print summary of options selected */ if (!INFO) { if (!TEST_ONLY) print_verbose("The following options are in effect for this %s.\n", DECOMPRESS ? "DECOMPRESSION" : "COMPRESSION"); print_verbose("Threading is %s. Number of CPUs detected: %d\n", control->threads > 1? "ENABLED" : "DISABLED", control->threads); print_verbose("Detected %lld bytes ram\n", control->ramsize); print_verbose("Compression level %d\n", control->compression_level); print_verbose("Nice Value: %d\n", control->nice_val); print_verbose("Show Progress\n"); print_maxverbose("Max "); print_verbose("Verbose\n"); if (FORCE_REPLACE) print_verbose("Overwrite Files\n"); if (!KEEP_FILES) print_verbose("Remove input files on completion\n"); if (control->outdir) print_verbose("Output Directory Specified: %s\n", control->outdir); else if (control->outname) print_verbose("Output Filename Specified: %s\n", control->outname); if (TEST_ONLY) print_verbose("Test file integrity\n"); if (control->tmpdir) print_verbose("Temporary Directory set as: %s\n", control->tmpdir); /* show compression options */ if (!DECOMPRESS && !TEST_ONLY) { print_verbose("Compression mode is: "); if (LZMA_COMPRESS) print_verbose("LZMA. LZO Compressibility testing %s\n", (LZO_TEST? "enabled" : "disabled")); else if (LZO_COMPRESS) print_verbose("LZO\n"); else if (BZIP2_COMPRESS) print_verbose("BZIP2. LZO Compressibility testing %s\n", (LZO_TEST? "enabled" : "disabled")); else if (ZLIB_COMPRESS) print_verbose("GZIP\n"); else if (ZPAQ_COMPRESS) print_verbose("ZPAQ. LZO Compressibility testing %s\n", (LZO_TEST? "enabled" : "disabled")); else if (NO_COMPRESS) print_verbose("RZIP pre-processing only\n"); if (control->window) print_verbose("Compression Window: %lld = %lldMB\n", control->window, control->window * 100ull); /* show heuristically computed window size */ if (!control->window && !UNLIMITED) { i64 temp_chunk, temp_window; if (STDOUT || STDIN) temp_chunk = control->maxram; else temp_chunk = control->ramsize * 2 / 3; temp_window = temp_chunk / (100 * 1024 * 1024); print_verbose("Heuristically Computed Compression Window: %lld = %lldMB\n", temp_window, temp_window * 100ull); } if (UNLIMITED) print_verbose("Using Unlimited Window size\n"); } if (!DECOMPRESS && !TEST_ONLY) print_maxverbose("Storage time in seconds %lld\n", control->secs); if (ENCRYPT) print_maxverbose("Encryption hash loops %lld\n", control->encloops); } }
/* decompress a section of an open file. Call fatal_return(() on error return the number of bytes that have been retrieved */ static i64 runzip_chunk(rzip_control *control, int fd_in, i64 expected_size, i64 tally) { uint32 good_cksum, cksum = 0; i64 len, ofs, total = 0; int l = -1, p = 0; char chunk_bytes; struct stat st; uchar head; void *ss; bool err = false; /* for display of progress */ unsigned long divisor[] = {1,1024,1048576,1073741824U}; char *suffix[] = {"","KB","MB","GB"}; double prog_done, prog_tsize; int divisor_index; if (expected_size > (i64)10737418240ULL) /* > 10GB */ divisor_index = 3; else if (expected_size > 10485760) /* > 10MB */ divisor_index = 2; else if (expected_size > 10240) /* > 10KB */ divisor_index = 1; else divisor_index = 0; prog_tsize = (long double)expected_size / (long double)divisor[divisor_index]; /* Determine the chunk_byte width size. Versions < 0.4 used 4 * bytes for all offsets, version 0.4 used 8 bytes. Versions 0.5+ use * a variable number of bytes depending on chunk size.*/ if (control->major_version == 0 && control->minor_version < 4) chunk_bytes = 4; else if (control->major_version == 0 && control->minor_version == 4) chunk_bytes = 8; else { print_maxverbose("Reading chunk_bytes at %lld\n", get_readseek(control, fd_in)); /* Read in the stored chunk byte width from the file */ if (unlikely(read_1g(control, fd_in, &chunk_bytes, 1) != 1)) fatal_return(("Failed to read chunk_bytes size in runzip_chunk\n"), -1); if (unlikely(chunk_bytes < 1 || chunk_bytes > 8)) failure_return(("chunk_bytes %d is invalid in runzip_chunk\n", chunk_bytes), -1); } if (!tally && expected_size) print_maxverbose("Expected size: %lld\n", expected_size); print_maxverbose("Chunk byte width: %d\n", chunk_bytes); ofs = seekcur_fdin(control); if (unlikely(ofs == -1)) fatal_return(("Failed to seek input file in runzip_fd\n"), -1); if (fstat(fd_in, &st) || st.st_size - ofs == 0) return 0; ss = open_stream_in(control, fd_in, NUM_STREAMS, chunk_bytes); if (unlikely(!ss)) failure_return(("Failed to open_stream_in in runzip_chunk\n"), -1); /* All chunks were unnecessarily encoded 8 bytes wide version 0.4x */ if (control->major_version == 0 && control->minor_version == 4) control->chunk_bytes = 8; else control->chunk_bytes = 2; while ((len = read_header(control, ss, &head)) || head) { i64 u; if (unlikely(len == -1)) return -1; switch (head) { case 0: u = unzip_literal(control, ss, len, &cksum); if (unlikely(u == -1)) { close_stream_in(control, ss); return -1; } total += u; break; default: u = unzip_match(control, ss, len, &cksum, chunk_bytes); if (unlikely(u == -1)) { close_stream_in(control, ss); return -1; } total += u; break; } if (expected_size) { p = 100 * ((double)(tally + total) / (double)expected_size); if (p / 10 != l / 10) { prog_done = (double)(tally + total) / (double)divisor[divisor_index]; print_progress("%3d%% %9.2f / %9.2f %s\r", p, prog_done, prog_tsize, suffix[divisor_index] ); l = p; } } } if (!HAS_MD5) { good_cksum = read_u32(control, ss, 0, &err); if (unlikely(err)) { close_stream_in(control, ss); return -1; } if (unlikely(good_cksum != cksum)) { close_stream_in(control, ss); failure_return(("Bad checksum: 0x%08x - expected: 0x%08x\n", cksum, good_cksum), -1); } print_maxverbose("Checksum for block: 0x%08x\n", cksum); } if (unlikely(close_stream_in(control, ss))) fatal("Failed to close stream!\n"); return total; }