Add a simple log facility.
Refactor all printfs to use log facility.
This commit is contained in:
parent
fa78621cbf
commit
8c1f4ebe61
24 changed files with 286 additions and 211 deletions
|
@ -342,6 +342,7 @@ $(LIB): $(OBJS)
|
||||||
|
|
||||||
$(PROG): $(LIB) $(PROGOBJS)
|
$(PROG): $(LIB) $(PROGOBJS)
|
||||||
$(LINK.PROG) -o $@ $(PROGOBJS) $(LDLIBS) -L. -l$(LINKLIB)
|
$(LINK.PROG) -o $@ $(PROGOBJS) $(LDLIBS) -L. -l$(LINKLIB)
|
||||||
|
mkdir -p buildtmp
|
||||||
cp $@ buildtmp
|
cp $@ buildtmp
|
||||||
cat utils/pcompress.sh | sed "s#<PC_PATH>#`pwd`#" > pcompress
|
cat utils/pcompress.sh | sed "s#<PC_PATH>#`pwd`#" > pcompress
|
||||||
chmod +x pcompress
|
chmod +x pcompress
|
||||||
|
|
|
@ -85,13 +85,13 @@ adapt_stats(int show)
|
||||||
{
|
{
|
||||||
if (show) {
|
if (show) {
|
||||||
if (bzip2_count > 0 || bsc_count > 0 || ppmd_count > 0 || lzma_count > 0) {
|
if (bzip2_count > 0 || bsc_count > 0 || ppmd_count > 0 || lzma_count > 0) {
|
||||||
fprintf(stderr, "Adaptive mode stats:\n");
|
log_msg(LOG_INFO, 0, "Adaptive mode stats:\n");
|
||||||
fprintf(stderr, " BZIP2 chunk count: %u\n", bzip2_count);
|
log_msg(LOG_INFO, 0, " BZIP2 chunk count: %u\n", bzip2_count);
|
||||||
fprintf(stderr, " LIBBSC chunk count: %u\n", bsc_count);
|
log_msg(LOG_INFO, 0, " LIBBSC chunk count: %u\n", bsc_count);
|
||||||
fprintf(stderr, " PPMd chunk count: %u\n", ppmd_count);
|
log_msg(LOG_INFO, 0, " PPMd chunk count: %u\n", ppmd_count);
|
||||||
fprintf(stderr, " LZMA chunk count: %u\n\n", lzma_count);
|
log_msg(LOG_INFO, 0, " LZMA chunk count: %u\n\n", lzma_count);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "\n");
|
log_msg(LOG_INFO, 0, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lzma_count = 0;
|
lzma_count = 0;
|
||||||
|
@ -276,12 +276,12 @@ adapt_decompress(void *src, uint64_t srclen, void *dst,
|
||||||
#ifdef ENABLE_PC_LIBBSC
|
#ifdef ENABLE_PC_LIBBSC
|
||||||
return (libbsc_decompress(src, srclen, dst, dstlen, level, chdr, adat->bsc_data));
|
return (libbsc_decompress(src, srclen, dst, dstlen, level, chdr, adat->bsc_data));
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "Cannot decompress chunk. Libbsc support not present.\n");
|
log_msg(LOG_ERR, 0, "Cannot decompress chunk. Libbsc support not present.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unrecognized compression mode: %d, file corrupt.\n", cmp_flags);
|
log_msg(LOG_ERR, 0, "Unrecognized compression mode: %d, file corrupt.\n", cmp_flags);
|
||||||
}
|
}
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
34
allocator.c
34
allocator.c
|
@ -186,10 +186,10 @@ slab_cleanup(int quiet)
|
||||||
if (bypass) return;
|
if (bypass) return;
|
||||||
|
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
fprintf(stderr, "Slab Allocation Stats\n");
|
log_msg(LOG_INFO, 0, "Slab Allocation Stats\n");
|
||||||
fprintf(stderr, "==================================================================\n");
|
log_msg(LOG_INFO, 0, "==================================================================\n");
|
||||||
fprintf(stderr, " Slab Size | Allocations | Hits |\n");
|
log_msg(LOG_INFO, 0, " Slab Size | Allocations | Hits |\n");
|
||||||
fprintf(stderr, "==================================================================\n");
|
log_msg(LOG_INFO, 0, "==================================================================\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<NUM_SLABS; i++)
|
for (i=0; i<NUM_SLABS; i++)
|
||||||
|
@ -200,7 +200,7 @@ slab_cleanup(int quiet)
|
||||||
while (slab) {
|
while (slab) {
|
||||||
if (slab->avail) {
|
if (slab->avail) {
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
fprintf(stderr, "%21" PRIu64 " %21" PRIu64 " %21" PRIu64 "\n",slab->sz,
|
log_msg(LOG_INFO, 0, "%21" PRIu64 " %21" PRIu64 " %21" PRIu64 "\n",slab->sz,
|
||||||
slab->allocs, slab->hits);
|
slab->allocs, slab->hits);
|
||||||
}
|
}
|
||||||
slab->allocs = 0;
|
slab->allocs = 0;
|
||||||
|
@ -217,11 +217,11 @@ slab_cleanup(int quiet)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
fprintf(stderr, "==================================================================\n");
|
log_msg(LOG_INFO, 0, "==================================================================\n");
|
||||||
fprintf(stderr, "Oversize Allocations : %" PRIu64 "\n", oversize_allocs);
|
log_msg(LOG_INFO, 0, "Oversize Allocations : %" PRIu64 "\n", oversize_allocs);
|
||||||
fprintf(stderr, "Total Requests : %" PRIu64 "\n", total_allocs);
|
log_msg(LOG_INFO, 0, "Total Requests : %" PRIu64 "\n", total_allocs);
|
||||||
fprintf(stderr, "Hash collisions : %" PRIu64 "\n", hash_collisions);
|
log_msg(LOG_INFO, 0, "Hash collisions : %" PRIu64 "\n", hash_collisions);
|
||||||
fprintf(stderr, "Leaked allocations : %" PRIu64 "\n", hash_entries);
|
log_msg(LOG_INFO, 0, "Leaked allocations : %" PRIu64 "\n", hash_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hash_entries > 0) {
|
if (hash_entries > 0) {
|
||||||
|
@ -245,9 +245,9 @@ slab_cleanup(int quiet)
|
||||||
free(hbucket_locks);
|
free(hbucket_locks);
|
||||||
|
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
fprintf(stderr, "==================================================================\n");
|
log_msg(LOG_INFO, 0, "==================================================================\n");
|
||||||
fprintf(stderr, " Slab Size | Allocations: leaked |\n");
|
log_msg(LOG_INFO, 0, " Slab Size | Allocations: leaked |\n");
|
||||||
fprintf(stderr, "==================================================================\n");
|
log_msg(LOG_INFO, 0, "==================================================================\n");
|
||||||
for (i=0; i<NUM_SLABS; i++)
|
for (i=0; i<NUM_SLABS; i++)
|
||||||
{
|
{
|
||||||
struct slabentry *slab;
|
struct slabentry *slab;
|
||||||
|
@ -255,7 +255,7 @@ slab_cleanup(int quiet)
|
||||||
slab = &slabheads[i];
|
slab = &slabheads[i];
|
||||||
do {
|
do {
|
||||||
if (slab->allocs > 0)
|
if (slab->allocs > 0)
|
||||||
fprintf(stderr, "%21" PRIu64 " %21" PRIu64 "\n", \
|
log_msg(LOG_INFO, 0, "%21" PRIu64 " %21" PRIu64 "\n", \
|
||||||
slab->sz, slab->allocs);
|
slab->sz, slab->allocs);
|
||||||
slab = slab->next;
|
slab = slab->next;
|
||||||
} while (slab);
|
} while (slab);
|
||||||
|
@ -276,7 +276,7 @@ slab_cleanup(int quiet)
|
||||||
j++;
|
j++;
|
||||||
} while (slab);
|
} while (slab);
|
||||||
}
|
}
|
||||||
if (!quiet) fprintf(stderr, "\n\n");
|
if (!quiet) log_msg(LOG_INFO, 0, "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
@ -461,7 +461,7 @@ slab_free(void *p, void *address)
|
||||||
while (buf) {
|
while (buf) {
|
||||||
if (buf->ptr == address) {
|
if (buf->ptr == address) {
|
||||||
if (hash_entries <=0) {
|
if (hash_entries <=0) {
|
||||||
fprintf(stderr, "Inconsistent allocation hash\n");
|
log_msg(LOG_ERR, 0, "Inconsistent allocation hash\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
if (pbuf)
|
if (pbuf)
|
||||||
|
@ -490,7 +490,7 @@ slab_free(void *p, void *address)
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
pthread_mutex_unlock(&hbucket_locks[hindx]);
|
pthread_mutex_unlock(&hbucket_locks[hindx]);
|
||||||
fprintf(stderr, "Freed buf(%p) not in slab allocations!\n", address);
|
log_msg(LOG_ERR, 0, "Freed buf(%p) not in slab allocations!\n", address);
|
||||||
free(address);
|
free(address);
|
||||||
abort();
|
abort();
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
|
@ -280,7 +280,7 @@ bsdiff(u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t newsize,
|
||||||
|
|
||||||
if(((db=(u_char *)slab_alloc(NULL, newsize+1))==NULL) ||
|
if(((db=(u_char *)slab_alloc(NULL, newsize+1))==NULL) ||
|
||||||
((eb=(u_char *)slab_alloc(NULL, newsize+1))==NULL)) {
|
((eb=(u_char *)slab_alloc(NULL, newsize+1))==NULL)) {
|
||||||
fprintf(stderr, "bsdiff: Memory allocation error.\n");
|
log_msg(LOG_ERR, 0, "bsdiff: Memory allocation error.\n");
|
||||||
slab_free(NULL, I);
|
slab_free(NULL, I);
|
||||||
slab_free(NULL, V);
|
slab_free(NULL, V);
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -310,7 +310,7 @@ bsdiff(u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t newsize,
|
||||||
valouti32(0, header + 4*5);
|
valouti32(0, header + 4*5);
|
||||||
valouti32(newsize, header + 4*6);
|
valouti32(newsize, header + 4*6);
|
||||||
if (BUFWRITE(&pf, header, 4*7) != 4*7) {
|
if (BUFWRITE(&pf, header, 4*7) != 4*7) {
|
||||||
fprintf(stderr, "bsdiff: Write to compressed buffer failed.\n");
|
log_msg(LOG_ERR, 0, "bsdiff: Write to compressed buffer failed.\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,11 +134,11 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
newsize = valini32(pbuf+4*6);
|
newsize = valini32(pbuf+4*6);
|
||||||
|
|
||||||
if((ctrllen<0) || (lzdatalen<0) || (newsize<0) || (lzextralen<0)) {
|
if((ctrllen<0) || (lzdatalen<0) || (newsize<0) || (lzextralen<0)) {
|
||||||
fprintf(stderr, "1: Corrupt patch\n");
|
log_msg(LOG_ERR, 0, "1: Corrupt patch\n");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
if (newsize > *_newsize) {
|
if (newsize > *_newsize) {
|
||||||
fprintf(stderr, "Output buffer too small.\n");
|
log_msg(LOG_ERR, 0, "Output buffer too small.\n");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
*_newsize = newsize;
|
*_newsize = newsize;
|
||||||
|
@ -147,7 +147,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
diffdata = (u_char *)slab_alloc(NULL, datalen);
|
diffdata = (u_char *)slab_alloc(NULL, datalen);
|
||||||
extradata = (u_char *)slab_alloc(NULL, extralen);
|
extradata = (u_char *)slab_alloc(NULL, extralen);
|
||||||
if (diffdata == NULL || extradata == NULL) {
|
if (diffdata == NULL || extradata == NULL) {
|
||||||
fprintf(stderr, "bspatch: Out of memory.\n");
|
log_msg(LOG_ERR, 0, "bspatch: Out of memory.\n");
|
||||||
if (diffdata) slab_free(NULL, diffdata);
|
if (diffdata) slab_free(NULL, diffdata);
|
||||||
if (extradata) slab_free(NULL, extradata);
|
if (extradata) slab_free(NULL, extradata);
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -158,7 +158,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
/* Ctrl data will be RLE-d if RLE size is less. */
|
/* Ctrl data will be RLE-d if RLE size is less. */
|
||||||
ctrldata = (u_char *)slab_alloc(NULL, ctrllen);
|
ctrldata = (u_char *)slab_alloc(NULL, ctrllen);
|
||||||
if (ctrldata == NULL) {
|
if (ctrldata == NULL) {
|
||||||
fprintf(stderr, "bspatch: Out of memory.\n");
|
log_msg(LOG_ERR, 0, "bspatch: Out of memory.\n");
|
||||||
slab_free(NULL, diffdata);
|
slab_free(NULL, diffdata);
|
||||||
slab_free(NULL, extradata);
|
slab_free(NULL, extradata);
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -166,7 +166,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
len = ctrllen;
|
len = ctrllen;
|
||||||
if (zero_rle_decode(pbuf + hdrsz, lzctrllen, ctrldata, &len) == -1 ||
|
if (zero_rle_decode(pbuf + hdrsz, lzctrllen, ctrldata, &len) == -1 ||
|
||||||
len != ctrllen) {
|
len != ctrllen) {
|
||||||
fprintf(stderr, "bspatch: Failed to decompress control data.\n");
|
log_msg(LOG_ERR, 0, "bspatch: Failed to decompress control data.\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
len = datalen;
|
len = datalen;
|
||||||
if (zero_rle_decode(pbuf + hdrsz + lzctrllen, lzdatalen, diffdata, &len) == -1 ||
|
if (zero_rle_decode(pbuf + hdrsz + lzctrllen, lzdatalen, diffdata, &len) == -1 ||
|
||||||
len != datalen) {
|
len != datalen) {
|
||||||
fprintf(stderr, "bspatch: Failed to decompress diff data.\n");
|
log_msg(LOG_ERR, 0, "bspatch: Failed to decompress diff data.\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
|
|
||||||
} else if (zero_rle_decode(pbuf + hdrsz + lzctrllen + lzdatalen, lzextralen, extradata, &len) == -1 ||
|
} else if (zero_rle_decode(pbuf + hdrsz + lzctrllen + lzdatalen, lzextralen, extradata, &len) == -1 ||
|
||||||
len != extralen) {
|
len != extralen) {
|
||||||
fprintf(stderr, "bspatch: Failed to decompress extra data.\n");
|
log_msg(LOG_ERR, 0, "bspatch: Failed to decompress extra data.\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
for(i=0;i<=2;i++) {
|
for(i=0;i<=2;i++) {
|
||||||
lenread = BUFREAD(&cpf, buf, 4);
|
lenread = BUFREAD(&cpf, buf, 4);
|
||||||
if (lenread < 4) {
|
if (lenread < 4) {
|
||||||
fprintf(stderr, "2: Corrupt diff data\n");
|
log_msg(LOG_ERR, 0, "2: Corrupt diff data\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
|
|
||||||
/* Sanity-check */
|
/* Sanity-check */
|
||||||
if(newpos+ctrl[0]>newsize) {
|
if(newpos+ctrl[0]>newsize) {
|
||||||
fprintf(stderr, "3: Corrupt diff data\n");
|
log_msg(LOG_ERR, 0, "3: Corrupt diff data\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
/* Read diff string */
|
/* Read diff string */
|
||||||
lenread = BUFREAD(&dpf, newbuf + newpos, ctrl[0]);
|
lenread = BUFREAD(&dpf, newbuf + newpos, ctrl[0]);
|
||||||
if (lenread < ctrl[0]) {
|
if (lenread < ctrl[0]) {
|
||||||
fprintf(stderr, "4: Corrupt diff data\n");
|
log_msg(LOG_ERR, 0, "4: Corrupt diff data\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
|
|
||||||
/* Sanity-check */
|
/* Sanity-check */
|
||||||
if(newpos+ctrl[1]>newsize) {
|
if(newpos+ctrl[1]>newsize) {
|
||||||
fprintf(stderr, "5: Corrupt diff data\n");
|
log_msg(LOG_ERR, 0, "5: Corrupt diff data\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ bspatch(u_char *pbuf, u_char *oldbuf, bsize_t oldsize, u_char *newbuf, bsize_t *
|
||||||
/* Read extra string */
|
/* Read extra string */
|
||||||
lenread = BUFREAD(&epf, newbuf + newpos, ctrl[1]);
|
lenread = BUFREAD(&epf, newbuf + newpos, ctrl[1]);
|
||||||
if (lenread < ctrl[1]) {
|
if (lenread < ctrl[1]) {
|
||||||
fprintf(stderr, "6: Corrupt diff data\n");
|
log_msg(LOG_ERR, 0, "6: Corrupt diff data\n");
|
||||||
rv = 0;
|
rv = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,18 +110,18 @@ zero_rle_decode(const void* ibuf, unsigned int ilen,
|
||||||
if (count & ZERO_MASK) {
|
if (count & ZERO_MASK) {
|
||||||
count &= DATA_MASK;
|
count &= DATA_MASK;
|
||||||
if (pos2 + count > *olen) {
|
if (pos2 + count > *olen) {
|
||||||
fprintf(stderr, "Output buffer overflow in Zero RLE decode.\n");
|
log_msg(LOG_ERR, 0, "Output buffer overflow in Zero RLE decode.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
memset(ob+pos2, 0, count);
|
memset(ob+pos2, 0, count);
|
||||||
pos2 += count;
|
pos2 += count;
|
||||||
} else {
|
} else {
|
||||||
if (pos1 + count > ilen) {
|
if (pos1 + count > ilen) {
|
||||||
fprintf(stderr, "Input underflow in Zero RLE decode.\n");
|
log_msg(LOG_ERR, 0, "Input underflow in Zero RLE decode.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (pos2 + count > *olen) {
|
if (pos2 + count > *olen) {
|
||||||
fprintf(stderr, "Output buffer overflow in Zero RLE decode.\n");
|
log_msg(LOG_ERR, 0, "Output buffer overflow in Zero RLE decode.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
memcpy(ob+pos2, ib+pos1, count);
|
memcpy(ob+pos2, ib+pos1, count);
|
||||||
|
|
|
@ -68,28 +68,28 @@ bzerr(int err)
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case BZ_SEQUENCE_ERROR:
|
case BZ_SEQUENCE_ERROR:
|
||||||
fprintf(stderr, "Bzip2: Call sequence error, buggy code ?\n");
|
log_msg(LOG_ERR, 0, "Bzip2: Call sequence error, buggy code ?\n");
|
||||||
break;
|
break;
|
||||||
case BZ_PARAM_ERROR:
|
case BZ_PARAM_ERROR:
|
||||||
fprintf(stderr, "Bzip2: Invalid parameter\n");
|
log_msg(LOG_ERR, 0, "Bzip2: Invalid parameter\n");
|
||||||
break;
|
break;
|
||||||
case BZ_MEM_ERROR:
|
case BZ_MEM_ERROR:
|
||||||
fprintf(stderr, "Bzip2: Out of memory\n");
|
log_msg(LOG_ERR, 0, "Bzip2: Out of memory\n");
|
||||||
break;
|
break;
|
||||||
case BZ_DATA_ERROR:
|
case BZ_DATA_ERROR:
|
||||||
fprintf(stderr, "Bzip2: Data integrity checksum error\n");
|
log_msg(LOG_ERR, 0, "Bzip2: Data integrity checksum error\n");
|
||||||
break;
|
break;
|
||||||
case BZ_DATA_ERROR_MAGIC:
|
case BZ_DATA_ERROR_MAGIC:
|
||||||
fprintf(stderr, "Bzip2: Invalid magic number in compressed buf\n");
|
log_msg(LOG_ERR, 0, "Bzip2: Invalid magic number in compressed buf\n");
|
||||||
break;
|
break;
|
||||||
case BZ_OUTBUFF_FULL:
|
case BZ_OUTBUFF_FULL:
|
||||||
fprintf(stderr, "Bzip2: Output buffer overflow\n");
|
log_msg(LOG_ERR, 0, "Bzip2: Output buffer overflow\n");
|
||||||
break;
|
break;
|
||||||
case BZ_CONFIG_ERROR:
|
case BZ_CONFIG_ERROR:
|
||||||
fprintf(stderr, "Bzip2: Improper library config on platform\n");
|
log_msg(LOG_ERR, 0, "Bzip2: Improper library config on platform\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Bzip2: Unknown error code: %d\n", err);
|
log_msg(LOG_ERR, 0, "Bzip2: Unknown error code: %d\n", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,14 +113,14 @@ aes_init(aes_ctx_t *ctx, uchar_t *salt, int saltlen, uchar_t *pwd, int pwd_len,
|
||||||
pickparams(&logN, &r, &p);
|
pickparams(&logN, &r, &p);
|
||||||
N = (uint64_t)(1) << logN;
|
N = (uint64_t)(1) << logN;
|
||||||
if (crypto_scrypt(pwd, pwd_len, salt, saltlen, N, r, p, key, ctx->keylen)) {
|
if (crypto_scrypt(pwd, pwd_len, salt, saltlen, N, r, p, key, ctx->keylen)) {
|
||||||
fprintf(stderr, "Scrypt failed\n");
|
log_msg(LOG_ERR, 0, "Scrypt failed\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
rv = PKCS5_PBKDF2_HMAC(pwd, pwd_len, salt, saltlen, PBE_ROUNDS, EVP_sha256(),
|
rv = PKCS5_PBKDF2_HMAC(pwd, pwd_len, salt, saltlen, PBE_ROUNDS, EVP_sha256(),
|
||||||
ctx->keylen, key);
|
ctx->keylen, key);
|
||||||
if (rv != ctx->keylen) {
|
if (rv != ctx->keylen) {
|
||||||
fprintf(stderr, "Key size is %d bytes - should be %d bits\n", i, ctx->keylen);
|
log_msg(LOG_ERR, 0, "Key size is %d bytes - should be %d bits\n", i, ctx->keylen);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -177,7 +177,7 @@ aes_encrypt(aes_ctx_t *ctx, uchar_t *plaintext, uchar_t *ciphertext, uint64_t le
|
||||||
// Init counter mode AES from scrypt
|
// Init counter mode AES from scrypt
|
||||||
strm = crypto_aesctr_init(&key, ctx->nonce + id);
|
strm = crypto_aesctr_init(&key, ctx->nonce + id);
|
||||||
if (!strm) {
|
if (!strm) {
|
||||||
fprintf(stderr, "Failed to init counter mode AES\n");
|
log_msg(LOG_ERR, 0, "Failed to init counter mode AES\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
crypto_aesctr_stream(strm, plaintext, ciphertext, len);
|
crypto_aesctr_stream(strm, plaintext, ciphertext, len);
|
||||||
|
@ -204,7 +204,7 @@ aes_decrypt(aes_ctx_t *ctx, uchar_t *ciphertext, uchar_t *plaintext, uint64_t le
|
||||||
// Init counter mode AES from scrypt
|
// Init counter mode AES from scrypt
|
||||||
strm = crypto_aesctr_init(&key, ctx->nonce + id);
|
strm = crypto_aesctr_init(&key, ctx->nonce + id);
|
||||||
if (!strm) {
|
if (!strm) {
|
||||||
fprintf(stderr, "Failed to init counter mode AES\n");
|
log_msg(LOG_ERR, 0, "Failed to init counter mode AES\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
crypto_aesctr_stream(strm, ciphertext, plaintext, len);
|
crypto_aesctr_stream(strm, ciphertext, plaintext, len);
|
||||||
|
|
|
@ -801,12 +801,12 @@ init_crypto(crypto_ctx_t *cctx, uchar_t *pwd, int pwd_len, int crypto_alg,
|
||||||
*/
|
*/
|
||||||
if (crypto_alg == CRYPTO_ALG_AES) {
|
if (crypto_alg == CRYPTO_ALG_AES) {
|
||||||
if (aes_init(actx, salt, 32, pwd, pwd_len, 0, enc_dec) != 0) {
|
if (aes_init(actx, salt, 32, pwd, pwd_len, 0, enc_dec) != 0) {
|
||||||
fprintf(stderr, "Failed to initialize AES context\n");
|
log_msg(LOG_ERR, 0, "Failed to initialize AES context\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (salsa20_init(sctx, salt, 32, pwd, pwd_len, 0, enc_dec) != 0) {
|
if (salsa20_init(sctx, salt, 32, pwd, pwd_len, 0, enc_dec) != 0) {
|
||||||
fprintf(stderr, "Failed to initialize SALSA20 context\n");
|
log_msg(LOG_ERR, 0, "Failed to initialize SALSA20 context\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -816,7 +816,7 @@ init_crypto(crypto_ctx_t *cctx, uchar_t *pwd, int pwd_len, int crypto_alg,
|
||||||
* Pass given nonce and salt.
|
* Pass given nonce and salt.
|
||||||
*/
|
*/
|
||||||
if (saltlen > MAX_SALTLEN) {
|
if (saltlen > MAX_SALTLEN) {
|
||||||
fprintf(stderr, "Salt too long. Max allowed length is %d\n",
|
log_msg(LOG_ERR, 0, "Salt too long. Max allowed length is %d\n",
|
||||||
MAX_SALTLEN);
|
MAX_SALTLEN);
|
||||||
free(actx);
|
free(actx);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
@ -827,12 +827,12 @@ init_crypto(crypto_ctx_t *cctx, uchar_t *pwd, int pwd_len, int crypto_alg,
|
||||||
if (crypto_alg == CRYPTO_ALG_AES) {
|
if (crypto_alg == CRYPTO_ALG_AES) {
|
||||||
if (aes_init(actx, cctx->salt, saltlen, pwd, pwd_len, U64_P(nonce),
|
if (aes_init(actx, cctx->salt, saltlen, pwd, pwd_len, U64_P(nonce),
|
||||||
enc_dec) != 0) {
|
enc_dec) != 0) {
|
||||||
fprintf(stderr, "Failed to initialize AES context\n");
|
log_msg(LOG_ERR, 0, "Failed to initialize AES context\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (salsa20_init(sctx, salt, 32, pwd, pwd_len, nonce, enc_dec) != 0) {
|
if (salsa20_init(sctx, salt, 32, pwd, pwd_len, nonce, enc_dec) != 0) {
|
||||||
fprintf(stderr, "Failed to initialize SALSA20 context\n");
|
log_msg(LOG_ERR, 0, "Failed to initialize SALSA20 context\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -847,7 +847,7 @@ init_crypto(crypto_ctx_t *cctx, uchar_t *pwd, int pwd_len, int crypto_alg,
|
||||||
actx = NULL;
|
actx = NULL;
|
||||||
sctx = NULL;
|
sctx = NULL;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unrecognized algorithm code: %d\n", crypto_alg);
|
log_msg(LOG_ERR, 0, "Unrecognized algorithm code: %d\n", crypto_alg);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -869,7 +869,7 @@ crypto_buf(crypto_ctx_t *cctx, uchar_t *from, uchar_t *to, uint64_t bytes, uint6
|
||||||
return (salsa20_decrypt((salsa20_ctx_t *)(cctx->crypto_ctx), from, to, bytes, id));
|
return (salsa20_decrypt((salsa20_ctx_t *)(cctx->crypto_ctx), from, to, bytes, id));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unrecognized algorithm code: %d\n", cctx->crypto_alg);
|
log_msg(LOG_ERR, 0, "Unrecognized algorithm code: %d\n", cctx->crypto_alg);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
@ -75,20 +75,20 @@ salsa20_init(salsa20_ctx_t *ctx, uchar_t *salt, int saltlen, uchar_t *pwd, int p
|
||||||
uint64_t N;
|
uint64_t N;
|
||||||
|
|
||||||
if (XSALSA20_CRYPTO_NONCEBYTES % 8) {
|
if (XSALSA20_CRYPTO_NONCEBYTES % 8) {
|
||||||
fprintf(stderr, "XSALSA20_CRYPTO_NONCEBYTES is not a multiple of 8!\n");
|
log_msg(LOG_ERR, 0, "XSALSA20_CRYPTO_NONCEBYTES is not a multiple of 8!\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
pickparams(&logN, &r, &p);
|
pickparams(&logN, &r, &p);
|
||||||
N = (uint64_t)(1) << logN;
|
N = (uint64_t)(1) << logN;
|
||||||
if (crypto_scrypt(pwd, pwd_len, salt, saltlen, N, r, p, key, ctx->keylen)) {
|
if (crypto_scrypt(pwd, pwd_len, salt, saltlen, N, r, p, key, ctx->keylen)) {
|
||||||
fprintf(stderr, "Scrypt failed\n");
|
log_msg(LOG_ERR, 0, "Scrypt failed\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
rv = PKCS5_PBKDF2_HMAC(pwd, pwd_len, salt, saltlen, PBE_ROUNDS, EVP_sha256(),
|
rv = PKCS5_PBKDF2_HMAC(pwd, pwd_len, salt, saltlen, PBE_ROUNDS, EVP_sha256(),
|
||||||
ctx->keylen, key);
|
ctx->keylen, key);
|
||||||
if (rv != ctx->keylen) {
|
if (rv != ctx->keylen) {
|
||||||
fprintf(stderr, "Key size is %d bytes - should be %d bits\n", i, ctx->keylen);
|
log_msg(LOG_ERR, 0, "Key size is %d bytes - should be %d bits\n", i, ctx->keylen);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -449,7 +449,7 @@ delta2_decode(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen)
|
||||||
last = pos + srclen;
|
last = pos + srclen;
|
||||||
olen = LE64(U64_P(pos));
|
olen = LE64(U64_P(pos));
|
||||||
if (*dstlen < olen) {
|
if (*dstlen < olen) {
|
||||||
fprintf(stderr, "DELTA2 Decode: Destination buffer too small.\n");
|
log_msg(LOG_ERR, 0, "DELTA2 Decode: Destination buffer too small.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,7 +468,7 @@ delta2_decode(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen)
|
||||||
rcnt = val & MSB_SETZERO_MASK;
|
rcnt = val & MSB_SETZERO_MASK;
|
||||||
pos += sizeof (rcnt);
|
pos += sizeof (rcnt);
|
||||||
if (out + rcnt > *dstlen) {
|
if (out + rcnt > *dstlen) {
|
||||||
fprintf(stderr, "DELTA2 Decode(lit): Destination buffer overflow. Corrupt data.\n");
|
log_msg(LOG_ERR, 0, "DELTA2 Decode(lit): Destination buffer overflow. Corrupt data.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
memcpy(pos1, pos, rcnt);
|
memcpy(pos1, pos, rcnt);
|
||||||
|
@ -485,7 +485,7 @@ delta2_decode(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen)
|
||||||
delta = LE64(U64_P(pos));
|
delta = LE64(U64_P(pos));
|
||||||
pos += sizeof (delta);
|
pos += sizeof (delta);
|
||||||
if (out + rcnt > *dstlen) {
|
if (out + rcnt > *dstlen) {
|
||||||
fprintf(stderr, "DELTA2 Decode(delta): Destination buffer overflow. Corrupt data.\n");
|
log_msg(LOG_ERR, 0, "DELTA2 Decode(delta): Destination buffer overflow. Corrupt data.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,19 +46,19 @@ static void
|
||||||
libbsc_err(int err) {
|
libbsc_err(int err) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case LIBBSC_BAD_PARAMETER:
|
case LIBBSC_BAD_PARAMETER:
|
||||||
fprintf(stderr, "LIBBSC: Bad Parameter.\n");
|
log_msg(LOG_ERR, 0, "LIBBSC: Bad Parameter.\n");
|
||||||
break;
|
break;
|
||||||
case LIBBSC_NOT_ENOUGH_MEMORY:
|
case LIBBSC_NOT_ENOUGH_MEMORY:
|
||||||
fprintf(stderr, "LIBBSC: Out of memory.\n");
|
log_msg(LOG_ERR, 0, "LIBBSC: Out of memory.\n");
|
||||||
break;
|
break;
|
||||||
case LIBBSC_NOT_SUPPORTED:
|
case LIBBSC_NOT_SUPPORTED:
|
||||||
fprintf(stderr, "LIBBSC: Using unsupported feature.\n");
|
log_msg(LOG_ERR, 0, "LIBBSC: Using unsupported feature.\n");
|
||||||
break;
|
break;
|
||||||
case LIBBSC_UNEXPECTED_EOB:
|
case LIBBSC_UNEXPECTED_EOB:
|
||||||
fprintf(stderr, "LIBBSC: Unexpected end of block.\n");
|
log_msg(LOG_ERR, 0, "LIBBSC: Unexpected end of block.\n");
|
||||||
break;
|
break;
|
||||||
case LIBBSC_DATA_CORRUPT:
|
case LIBBSC_DATA_CORRUPT:
|
||||||
fprintf(stderr, "LIBBSC: Corrupt data.\n");
|
log_msg(LOG_ERR, 0, "LIBBSC: Corrupt data.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ libbsc_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
if (chunksize > BSC_MAX_CHUNK) {
|
if (chunksize > BSC_MAX_CHUNK) {
|
||||||
fprintf(stderr, "Max allowed chunk size for LIBBSC is: %s \n",
|
log_msg(LOG_ERR, 0, "Max allowed chunk size for LIBBSC is: %s \n",
|
||||||
bytes_to_size(BSC_MAX_CHUNK));
|
bytes_to_size(BSC_MAX_CHUNK));
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ lz4_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
||||||
int lev;
|
int lev;
|
||||||
|
|
||||||
if (chunksize > LZ4_MAX_CHUNK) {
|
if (chunksize > LZ4_MAX_CHUNK) {
|
||||||
fprintf(stderr, "Max allowed chunk size for LZ4 is: %ld \n",
|
log_msg(LOG_ERR, 0, "Max allowed chunk size for LZ4 is: %ld \n",
|
||||||
LZ4_MAX_CHUNK);
|
LZ4_MAX_CHUNK);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ lz_fx_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
||||||
int lev;
|
int lev;
|
||||||
|
|
||||||
if (chunksize > UINT_MAX) {
|
if (chunksize > UINT_MAX) {
|
||||||
fprintf(stderr, "Chunk size too big for LZFX.\n");
|
log_msg(LOG_ERR, 0, "Chunk size too big for LZFX.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
lzdat = (struct lzfx_params *)slab_alloc(NULL, sizeof (struct lzfx_params));
|
lzdat = (struct lzfx_params *)slab_alloc(NULL, sizeof (struct lzfx_params));
|
||||||
|
@ -86,19 +86,19 @@ lz_fx_err(int err)
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case LZFX_ESIZE:
|
case LZFX_ESIZE:
|
||||||
fprintf(stderr, "LZFX: Output buffer too small.\n");
|
log_msg(LOG_ERR, 0, "LZFX: Output buffer too small.\n");
|
||||||
break;
|
break;
|
||||||
case LZFX_ECORRUPT:
|
case LZFX_ECORRUPT:
|
||||||
fprintf(stderr, "LZFX: Corrupt data for decompression.\n");
|
log_msg(LOG_ERR, 0, "LZFX: Corrupt data for decompression.\n");
|
||||||
break;
|
break;
|
||||||
case LZFX_EARGS:
|
case LZFX_EARGS:
|
||||||
fprintf(stderr, "LZFX: Invalid arguments.\n");
|
log_msg(LOG_ERR, 0, "LZFX: Invalid arguments.\n");
|
||||||
break;
|
break;
|
||||||
case LZFX_ENOMEM:
|
case LZFX_ENOMEM:
|
||||||
fprintf(stderr, "LZFX: Out of memory when allocating hashtable.\n");
|
log_msg(LOG_ERR, 0, "LZFX: Out of memory when allocating hashtable.\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "LZFX: Unknown error code: %d\n", err);
|
log_msg(LOG_ERR, 0, "LZFX: Unknown error code: %d\n", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,36 +152,36 @@ lzerr(int err, int cmp)
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case SZ_ERROR_MEM:
|
case SZ_ERROR_MEM:
|
||||||
fprintf(stderr, "LZMA: Memory allocation error\n");
|
log_msg(LOG_ERR, 0, "LZMA: Memory allocation error\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_PARAM:
|
case SZ_ERROR_PARAM:
|
||||||
fprintf(stderr, "LZMA: Incorrect paramater\n");
|
log_msg(LOG_ERR, 0, "LZMA: Incorrect paramater\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_WRITE:
|
case SZ_ERROR_WRITE:
|
||||||
fprintf(stderr, "LZMA: Write callback error\n");
|
log_msg(LOG_ERR, 0, "LZMA: Write callback error\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_PROGRESS:
|
case SZ_ERROR_PROGRESS:
|
||||||
fprintf(stderr, "LZMA: Progress callback errored\n");
|
log_msg(LOG_ERR, 0, "LZMA: Progress callback errored\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_INPUT_EOF:
|
case SZ_ERROR_INPUT_EOF:
|
||||||
fprintf(stderr, "LZMA: More compressed input bytes expected\n");
|
log_msg(LOG_ERR, 0, "LZMA: More compressed input bytes expected\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_OUTPUT_EOF:
|
case SZ_ERROR_OUTPUT_EOF:
|
||||||
/* This error is non-fatal during compression */
|
/* This error is non-fatal during compression */
|
||||||
if (!cmp)
|
if (!cmp)
|
||||||
fprintf(stderr, "LZMA: Output buffer overflow\n");
|
log_msg(LOG_ERR, 0, "LZMA: Output buffer overflow\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_UNSUPPORTED:
|
case SZ_ERROR_UNSUPPORTED:
|
||||||
fprintf(stderr, "LZMA: Unsupported properties\n");
|
log_msg(LOG_ERR, 0, "LZMA: Unsupported properties\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_DESTLEN:
|
case SZ_ERROR_DESTLEN:
|
||||||
fprintf(stderr, "LZMA: Output chunk size too small\n");
|
log_msg(LOG_ERR, 0, "LZMA: Output chunk size too small\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_DATA:
|
case SZ_ERROR_DATA:
|
||||||
fprintf(stderr, "LZMA: Data Error\n");
|
log_msg(LOG_ERR, 0, "LZMA: Data Error\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "LZMA: Unknown error code: %d\n", err);
|
log_msg(LOG_ERR, 0, "LZMA: Unknown error code: %d\n", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
main.c
5
main.c
|
@ -37,6 +37,7 @@
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <pcompress.h>
|
#include <pcompress.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
|
@ -49,8 +50,8 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
err = init_pc_context(pctx, argc, argv);
|
err = init_pc_context(pctx, argc, argv);
|
||||||
if (err != 0 && err != 2) {
|
if (err != 0 && err != 2) {
|
||||||
fprintf(stderr, "Invalid arguments to pcompress.\n");
|
log_msg(LOG_ERR, 0, "Invalid arguments to pcompress.\n");
|
||||||
fprintf(stderr, "Please see usage.\n");
|
log_msg(LOG_ERR, 0, "Please see usage.\n");
|
||||||
destroy_pc_context(pctx);
|
destroy_pc_context(pctx);
|
||||||
return (err);
|
return (err);
|
||||||
|
|
||||||
|
|
172
pcompress.c
172
pcompress.c
|
@ -170,18 +170,18 @@ usage(pc_ctx_t *pctx)
|
||||||
static void
|
static void
|
||||||
show_compression_stats(pc_ctx_t *pctx)
|
show_compression_stats(pc_ctx_t *pctx)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nCompression Statistics\n");
|
log_msg(LOG_INFO, 0, "\nCompression Statistics\n");
|
||||||
fprintf(stderr, "======================\n");
|
log_msg(LOG_INFO, 0, "======================\n");
|
||||||
fprintf(stderr, "Total chunks : %u\n", pctx->chunk_num);
|
log_msg(LOG_INFO, 0, "Total chunks : %u\n", pctx->chunk_num);
|
||||||
if (pctx->chunk_num == 0) {
|
if (pctx->chunk_num == 0) {
|
||||||
fprintf(stderr, "No statistics to display.\n");
|
log_msg(LOG_INFO, 0, "No statistics to display.\n");
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Best compressed chunk : %s(%.2f%%)\n",
|
log_msg(LOG_INFO, 0, "Best compressed chunk : %s(%.2f%%)\n",
|
||||||
bytes_to_size(pctx->smallest_chunk), (double)pctx->smallest_chunk/(double)pctx->chunksize*100);
|
bytes_to_size(pctx->smallest_chunk), (double)pctx->smallest_chunk/(double)pctx->chunksize*100);
|
||||||
fprintf(stderr, "Worst compressed chunk : %s(%.2f%%)\n",
|
log_msg(LOG_INFO, 0, "Worst compressed chunk : %s(%.2f%%)\n",
|
||||||
bytes_to_size(pctx->largest_chunk), (double)pctx->largest_chunk/(double)pctx->chunksize*100);
|
bytes_to_size(pctx->largest_chunk), (double)pctx->largest_chunk/(double)pctx->chunksize*100);
|
||||||
pctx->avg_chunk /= pctx->chunk_num;
|
pctx->avg_chunk /= pctx->chunk_num;
|
||||||
fprintf(stderr, "Avg compressed chunk : %s(%.2f%%)\n\n",
|
log_msg(LOG_INFO, 0, "Avg compressed chunk : %s(%.2f%%)\n\n",
|
||||||
bytes_to_size(pctx->avg_chunk), (double)pctx->avg_chunk/(double)pctx->chunksize*100);
|
bytes_to_size(pctx->avg_chunk), (double)pctx->avg_chunk/(double)pctx->chunksize*100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ preproc_compress(pc_ctx_t *pctx, compress_func_ptr cmp_func, void *src, uint64_t
|
||||||
/*
|
/*
|
||||||
* Execution won't come here but just in case ...
|
* Execution won't come here but just in case ...
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "Invalid preprocessing mode\n");
|
log_msg(LOG_ERR, 0, "Invalid preprocessing mode\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,14 +360,14 @@ preproc_decompress(pc_ctx_t *pctx, compress_func_ptr dec_func, void *src, uint64
|
||||||
result = lzp_decompress((const uchar_t *)src, (uchar_t *)dst, srclen,
|
result = lzp_decompress((const uchar_t *)src, (uchar_t *)dst, srclen,
|
||||||
hashsize, LZP_DEFAULT_LZPMINLEN, 0);
|
hashsize, LZP_DEFAULT_LZPMINLEN, 0);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
fprintf(stderr, "LZP decompression failed.\n");
|
log_msg(LOG_ERR, 0, "LZP decompression failed.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
*dstlen = result;
|
*dstlen = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(type & (PREPROC_COMPRESSED | PREPROC_TYPE_DELTA2 | PREPROC_TYPE_LZP)) && type > 0) {
|
if (!(type & (PREPROC_COMPRESSED | PREPROC_TYPE_DELTA2 | PREPROC_TYPE_LZP)) && type > 0) {
|
||||||
fprintf(stderr, "Invalid preprocessing flags: %d\n", type);
|
log_msg(LOG_ERR, 0, "Invalid preprocessing flags: %d\n", type);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -447,7 +447,7 @@ redo:
|
||||||
/*
|
/*
|
||||||
* HMAC verification failure is fatal.
|
* HMAC verification failure is fatal.
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "Chunk %d, HMAC verification failed\n", tdat->id);
|
log_msg(LOG_ERR, 0, "Chunk %d, HMAC verification failed\n", tdat->id);
|
||||||
pctx->main_cancel = 1;
|
pctx->main_cancel = 1;
|
||||||
tdat->len_cmp = 0;
|
tdat->len_cmp = 0;
|
||||||
pctx->t_errored = 1;
|
pctx->t_errored = 1;
|
||||||
|
@ -497,7 +497,7 @@ redo:
|
||||||
/*
|
/*
|
||||||
* Header CRC32 verification failure is fatal.
|
* Header CRC32 verification failure is fatal.
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "Chunk %d, Header CRC verification failed\n", tdat->id);
|
log_msg(LOG_ERR, 0, "Chunk %d, Header CRC verification failed\n", tdat->id);
|
||||||
pctx->main_cancel = 1;
|
pctx->main_cancel = 1;
|
||||||
tdat->len_cmp = 0;
|
tdat->len_cmp = 0;
|
||||||
pctx->t_errored = 1;
|
pctx->t_errored = 1;
|
||||||
|
@ -545,7 +545,7 @@ redo:
|
||||||
}
|
}
|
||||||
if (rv == -1) {
|
if (rv == -1) {
|
||||||
tdat->len_cmp = 0;
|
tdat->len_cmp = 0;
|
||||||
fprintf(stderr, "ERROR: Chunk %d, decompression failed.\n", tdat->id);
|
log_msg(LOG_ERR, 0, "ERROR: Chunk %d, decompression failed.\n", tdat->id);
|
||||||
pctx->t_errored = 1;
|
pctx->t_errored = 1;
|
||||||
goto cont;
|
goto cont;
|
||||||
}
|
}
|
||||||
|
@ -595,7 +595,7 @@ redo:
|
||||||
|
|
||||||
if (rv == -1) {
|
if (rv == -1) {
|
||||||
tdat->len_cmp = 0;
|
tdat->len_cmp = 0;
|
||||||
fprintf(stderr, "ERROR: Chunk %d, decompression failed.\n", tdat->id);
|
log_msg(LOG_ERR, 0, "ERROR: Chunk %d, decompression failed.\n", tdat->id);
|
||||||
pctx->t_errored = 1;
|
pctx->t_errored = 1;
|
||||||
goto cont;
|
goto cont;
|
||||||
}
|
}
|
||||||
|
@ -609,7 +609,7 @@ redo:
|
||||||
rctx->cbuf = tdat->compressed_chunk;
|
rctx->cbuf = tdat->compressed_chunk;
|
||||||
dedupe_decompress(rctx, tdat->uncompressed_chunk, &(tdat->len_cmp));
|
dedupe_decompress(rctx, tdat->uncompressed_chunk, &(tdat->len_cmp));
|
||||||
if (!rctx->valid) {
|
if (!rctx->valid) {
|
||||||
fprintf(stderr, "ERROR: Chunk %d, dedup recovery failed.\n", tdat->id);
|
log_msg(LOG_ERR, 0, "ERROR: Chunk %d, dedup recovery failed.\n", tdat->id);
|
||||||
rv = -1;
|
rv = -1;
|
||||||
tdat->len_cmp = 0;
|
tdat->len_cmp = 0;
|
||||||
pctx->t_errored = 1;
|
pctx->t_errored = 1;
|
||||||
|
@ -641,7 +641,7 @@ redo:
|
||||||
compute_checksum(checksum, pctx->cksum, tdat->uncompressed_chunk, _chunksize, tdat->cksum_mt, 1);
|
compute_checksum(checksum, pctx->cksum, tdat->uncompressed_chunk, _chunksize, tdat->cksum_mt, 1);
|
||||||
if (memcmp(checksum, tdat->checksum, pctx->cksum_bytes) != 0) {
|
if (memcmp(checksum, tdat->checksum, pctx->cksum_bytes) != 0) {
|
||||||
tdat->len_cmp = 0;
|
tdat->len_cmp = 0;
|
||||||
fprintf(stderr, "ERROR: Chunk %d, checksums do not match.\n", tdat->id);
|
log_msg(LOG_ERR, 0, "ERROR: Chunk %d, checksums do not match.\n", tdat->id);
|
||||||
pctx->t_errored = 1;
|
pctx->t_errored = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -723,12 +723,12 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
sbuf.st_size = 0;
|
sbuf.st_size = 0;
|
||||||
} else {
|
} else {
|
||||||
if ((compfd = open(filename, O_RDONLY, 0)) == -1) {
|
if ((compfd = open(filename, O_RDONLY, 0)) == -1) {
|
||||||
err_print(1, "Cannot open: %s", filename);
|
log_msg(LOG_ERR, 1, "Cannot open: %s", filename);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(compfd, &sbuf) == -1) {
|
if (fstat(compfd, &sbuf) == -1) {
|
||||||
err_print(1, "Cannot stat: %s", filename);
|
log_msg(LOG_ERR, 1, "Cannot stat: %s", filename);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (sbuf.st_size == 0)
|
if (sbuf.st_size == 0)
|
||||||
|
@ -737,7 +737,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
|
|
||||||
if ((uncompfd = open(to_filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR)) == -1) {
|
if ((uncompfd = open(to_filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR)) == -1) {
|
||||||
close(compfd);
|
close(compfd);
|
||||||
err_print(1, "Cannot open: %s", to_filename);
|
log_msg(LOG_ERR, 1, "Cannot open: %s", to_filename);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -762,9 +762,9 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
}
|
}
|
||||||
if (init_algo(pctx, algorithm, 0) != 0) {
|
if (init_algo(pctx, algorithm, 0) != 0) {
|
||||||
if (pctx->pipe_mode || filename == NULL)
|
if (pctx->pipe_mode || filename == NULL)
|
||||||
fprintf(stderr, "Input stream is not pcompressed.\n");
|
log_msg(LOG_ERR, 0, "Input stream is not pcompressed.\n");
|
||||||
else
|
else
|
||||||
fprintf(stderr, "%s is not a pcompressed file.\n", filename);
|
log_msg(LOG_ERR, 0, "%s is not a pcompressed file.\n", filename);
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
pctx->algo = algorithm;
|
pctx->algo = algorithm;
|
||||||
|
@ -786,23 +786,23 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
* Check for ridiculous values (malicious tampering or otherwise).
|
* Check for ridiculous values (malicious tampering or otherwise).
|
||||||
*/
|
*/
|
||||||
if (version > VERSION) {
|
if (version > VERSION) {
|
||||||
fprintf(stderr, "Cannot handle newer archive version %d, capability %d\n",
|
log_msg(LOG_ERR, 0, "Cannot handle newer archive version %d, capability %d\n",
|
||||||
version, VERSION);
|
version, VERSION);
|
||||||
err = 1;
|
err = 1;
|
||||||
goto uncomp_done;
|
goto uncomp_done;
|
||||||
}
|
}
|
||||||
if (chunksize > EIGHTY_PCT(get_total_ram())) {
|
if (chunksize > EIGHTY_PCT(get_total_ram())) {
|
||||||
fprintf(stderr, "Chunk size must not exceed 80%% of total RAM.\n");
|
log_msg(LOG_ERR, 0, "Chunk size must not exceed 80%% of total RAM.\n");
|
||||||
err = 1;
|
err = 1;
|
||||||
goto uncomp_done;
|
goto uncomp_done;
|
||||||
}
|
}
|
||||||
if (level > MAX_LEVEL || level < 0) {
|
if (level > MAX_LEVEL || level < 0) {
|
||||||
fprintf(stderr, "Invalid compression level in header: %d\n", level);
|
log_msg(LOG_ERR, 0, "Invalid compression level in header: %d\n", level);
|
||||||
err = 1;
|
err = 1;
|
||||||
goto uncomp_done;
|
goto uncomp_done;
|
||||||
}
|
}
|
||||||
if (version < VERSION-3) {
|
if (version < VERSION-3) {
|
||||||
fprintf(stderr, "Unsupported version: %d\n", version);
|
log_msg(LOG_ERR, 0, "Unsupported version: %d\n", version);
|
||||||
err = 1;
|
err = 1;
|
||||||
goto uncomp_done;
|
goto uncomp_done;
|
||||||
}
|
}
|
||||||
|
@ -825,14 +825,14 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
if (flags & FLAG_DEDUP_FIXED) {
|
if (flags & FLAG_DEDUP_FIXED) {
|
||||||
if (version > 7) {
|
if (version > 7) {
|
||||||
if (pctx->pipe_mode) {
|
if (pctx->pipe_mode) {
|
||||||
fprintf(stderr, "Global Deduplication is not supported with pipe mode.\n");
|
log_msg(LOG_ERR, 0, "Global Deduplication is not supported with pipe mode.\n");
|
||||||
err = 1;
|
err = 1;
|
||||||
goto uncomp_done;
|
goto uncomp_done;
|
||||||
}
|
}
|
||||||
pctx->enable_rabin_global = 1;
|
pctx->enable_rabin_global = 1;
|
||||||
dedupe_flag = RABIN_DEDUPE_FILE_GLOBAL;
|
dedupe_flag = RABIN_DEDUPE_FILE_GLOBAL;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid file deduplication flags.\n");
|
log_msg(LOG_ERR, 0, "Invalid file deduplication flags.\n");
|
||||||
err = 1;
|
err = 1;
|
||||||
goto uncomp_done;
|
goto uncomp_done;
|
||||||
}
|
}
|
||||||
|
@ -857,7 +857,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
if (pctx->cksum == CKSUM_BLAKE512) pctx->cksum = CKSUM_SKEIN512;
|
if (pctx->cksum == CKSUM_BLAKE512) pctx->cksum = CKSUM_SKEIN512;
|
||||||
}
|
}
|
||||||
if (get_checksum_props(NULL, &(pctx->cksum), &(pctx->cksum_bytes), &(pctx->mac_bytes), 1) == -1) {
|
if (get_checksum_props(NULL, &(pctx->cksum), &(pctx->cksum_bytes), &(pctx->mac_bytes), 1) == -1) {
|
||||||
fprintf(stderr, "Invalid checksum algorithm code: %d. File corrupt ?\n", pctx->cksum);
|
log_msg(LOG_ERR, 0, "Invalid checksum algorithm code: %d. File corrupt ?\n", pctx->cksum);
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -899,7 +899,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
} else if (pctx->encrypt_type == CRYPTO_ALG_SALSA20) {
|
} else if (pctx->encrypt_type == CRYPTO_ALG_SALSA20) {
|
||||||
noncelen = XSALSA20_CRYPTO_NONCEBYTES;
|
noncelen = XSALSA20_CRYPTO_NONCEBYTES;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid Encryption algorithm code: %d. File corrupt ?\n",
|
log_msg(LOG_ERR, 0, "Invalid Encryption algorithm code: %d. File corrupt ?\n",
|
||||||
pctx->encrypt_type);
|
pctx->encrypt_type);
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
|
@ -963,7 +963,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
free(salt2);
|
free(salt2);
|
||||||
memset(salt1, 0, saltlen);
|
memset(salt1, 0, saltlen);
|
||||||
free(salt1);
|
free(salt1);
|
||||||
err_print(0, "Failed to get password.\n");
|
log_msg(LOG_ERR, 0, "Failed to get password.\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
} else if (!pctx->user_pw) {
|
} else if (!pctx->user_pw) {
|
||||||
|
@ -1001,7 +1001,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
memset(salt1, 0, saltlen);
|
memset(salt1, 0, saltlen);
|
||||||
free(salt1);
|
free(salt1);
|
||||||
close(uncompfd); unlink(to_filename);
|
close(uncompfd); unlink(to_filename);
|
||||||
err_print(0, "Failed to get password.\n");
|
log_msg(LOG_ERR, 0, "Failed to get password.\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -1016,7 +1016,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
free(salt1);
|
free(salt1);
|
||||||
memset(pctx->user_pw, 0, pctx->user_pw_len);
|
memset(pctx->user_pw, 0, pctx->user_pw_len);
|
||||||
close(uncompfd); unlink(to_filename);
|
close(uncompfd); unlink(to_filename);
|
||||||
err_print(0, "Failed to initialize crypto\n");
|
log_msg(LOG_ERR, 0, "Failed to initialize crypto\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
memset(pctx->user_pw, 0, pctx->user_pw_len);
|
memset(pctx->user_pw, 0, pctx->user_pw_len);
|
||||||
|
@ -1031,7 +1031,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
free(salt1);
|
free(salt1);
|
||||||
memset(pw, 0, MAX_PW_LEN);
|
memset(pw, 0, MAX_PW_LEN);
|
||||||
close(uncompfd); unlink(to_filename);
|
close(uncompfd); unlink(to_filename);
|
||||||
err_print(0, "Failed to initialize crypto\n");
|
log_msg(LOG_ERR, 0, "Failed to initialize crypto\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
memset(pw, 0, MAX_PW_LEN);
|
memset(pw, 0, MAX_PW_LEN);
|
||||||
|
@ -1045,7 +1045,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
*/
|
*/
|
||||||
if (hmac_init(&hdr_mac, pctx->cksum, &(pctx->crypto_ctx)) == -1) {
|
if (hmac_init(&hdr_mac, pctx->cksum, &(pctx->crypto_ctx)) == -1) {
|
||||||
close(uncompfd); unlink(to_filename);
|
close(uncompfd); unlink(to_filename);
|
||||||
err_print(0, "Cannot initialize header hmac.\n");
|
log_msg(LOG_ERR, 0, "Cannot initialize header hmac.\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
hmac_update(&hdr_mac, (uchar_t *)pctx->algo, ALGO_SZ);
|
hmac_update(&hdr_mac, (uchar_t *)pctx->algo, ALGO_SZ);
|
||||||
|
@ -1072,7 +1072,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
memset(n1, 0, noncelen);
|
memset(n1, 0, noncelen);
|
||||||
if (memcmp(hdr_hash2, hdr_hash1, pctx->mac_bytes) != 0) {
|
if (memcmp(hdr_hash2, hdr_hash1, pctx->mac_bytes) != 0) {
|
||||||
close(uncompfd); unlink(to_filename);
|
close(uncompfd); unlink(to_filename);
|
||||||
err_print(0, "Header verification failed! File tampered or wrong password.\n");
|
log_msg(LOG_ERR, 0, "Header verification failed! File tampered or wrong password.\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
} else if (version >= 5) {
|
} else if (version >= 5) {
|
||||||
|
@ -1102,7 +1102,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
crc2 = lzma_crc32((uchar_t *)&d2, sizeof (level), crc2);
|
crc2 = lzma_crc32((uchar_t *)&d2, sizeof (level), crc2);
|
||||||
if (crc1 != crc2) {
|
if (crc1 != crc2) {
|
||||||
close(uncompfd); unlink(to_filename);
|
close(uncompfd); unlink(to_filename);
|
||||||
err_print(0, "Header verification failed! File tampered or wrong password.\n");
|
log_msg(LOG_ERR, 0, "Header verification failed! File tampered or wrong password.\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1116,9 +1116,9 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
set_threadcounts(&props, &(pctx->nthreads), nprocs, DECOMPRESS_THREADS);
|
set_threadcounts(&props, &(pctx->nthreads), nprocs, DECOMPRESS_THREADS);
|
||||||
if (props.is_single_chunk)
|
if (props.is_single_chunk)
|
||||||
pctx->nthreads = 1;
|
pctx->nthreads = 1;
|
||||||
fprintf(stderr, "Scaling to %d thread", pctx->nthreads * props.nthreads);
|
log_msg(LOG_INFO, 0, "Scaling to %d thread", pctx->nthreads * props.nthreads);
|
||||||
if (pctx->nthreads * props.nthreads > 1) fprintf(stderr, "s");
|
if (pctx->nthreads * props.nthreads > 1) log_msg(LOG_INFO, 0, "s");
|
||||||
fprintf(stderr, "\n");
|
log_msg(LOG_INFO, 0, "\n");
|
||||||
nprocs = pctx->nthreads;
|
nprocs = pctx->nthreads;
|
||||||
slab_cache_add(compressed_chunksize);
|
slab_cache_add(compressed_chunksize);
|
||||||
slab_cache_add(chunksize);
|
slab_cache_add(chunksize);
|
||||||
|
@ -1128,7 +1128,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
for (i = 0; i < nprocs; i++) {
|
for (i = 0; i < nprocs; i++) {
|
||||||
dary[i] = (struct cmp_data *)slab_alloc(NULL, sizeof (struct cmp_data));
|
dary[i] = (struct cmp_data *)slab_alloc(NULL, sizeof (struct cmp_data));
|
||||||
if (!dary[i]) {
|
if (!dary[i]) {
|
||||||
fprintf(stderr, "1: Out of memory\n");
|
log_msg(LOG_ERR, 0, "1: Out of memory\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
tdat = dary[i];
|
tdat = dary[i];
|
||||||
|
@ -1182,7 +1182,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
|
|
||||||
if (pctx->encrypt_type) {
|
if (pctx->encrypt_type) {
|
||||||
if (hmac_init(&tdat->chunk_hmac, pctx->cksum, &(pctx->crypto_ctx)) == -1) {
|
if (hmac_init(&tdat->chunk_hmac, pctx->cksum, &(pctx->crypto_ctx)) == -1) {
|
||||||
fprintf(stderr, "Cannot initialize chunk hmac.\n");
|
log_msg(LOG_ERR, 0, "Cannot initialize chunk hmac.\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1246,7 +1246,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
if (rb != sizeof (tdat->len_cmp)) {
|
if (rb != sizeof (tdat->len_cmp)) {
|
||||||
if (rb < 0) perror("Read: ");
|
if (rb < 0) perror("Read: ");
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Incomplete chunk %d header,"
|
log_msg(LOG_ERR, 0, "Incomplete chunk %d header,"
|
||||||
"file corrupt\n", pctx->chunk_num);
|
"file corrupt\n", pctx->chunk_num);
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
|
@ -1257,7 +1257,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
* Check for ridiculous length.
|
* Check for ridiculous length.
|
||||||
*/
|
*/
|
||||||
if (tdat->len_cmp > chunksize + 256) {
|
if (tdat->len_cmp > chunksize + 256) {
|
||||||
fprintf(stderr, "Compressed length too big for chunk: %d\n",
|
log_msg(LOG_ERR, 0, "Compressed length too big for chunk: %d\n",
|
||||||
pctx->chunk_num);
|
pctx->chunk_num);
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
|
@ -1287,7 +1287,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
tdat->uncompressed_chunk = (uchar_t *)slab_alloc(NULL,
|
tdat->uncompressed_chunk = (uchar_t *)slab_alloc(NULL,
|
||||||
chunksize);
|
chunksize);
|
||||||
if (!tdat->compressed_chunk || !tdat->uncompressed_chunk) {
|
if (!tdat->compressed_chunk || !tdat->uncompressed_chunk) {
|
||||||
fprintf(stderr, "2: Out of memory\n");
|
log_msg(LOG_ERR, 0, "2: Out of memory\n");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
tdat->cmp_seg = tdat->uncompressed_chunk;
|
tdat->cmp_seg = tdat->uncompressed_chunk;
|
||||||
|
@ -1310,7 +1310,7 @@ start_decompress(pc_ctx_t *pctx, const char *filename, const char *to_filename)
|
||||||
perror("Read: ");
|
perror("Read: ");
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Incomplete chunk %d, file corrupt.\n",
|
log_msg(LOG_ERR, 0, "Incomplete chunk %d, file corrupt.\n",
|
||||||
pctx->chunk_num);
|
pctx->chunk_num);
|
||||||
UNCOMP_BAIL;
|
UNCOMP_BAIL;
|
||||||
}
|
}
|
||||||
|
@ -1739,7 +1739,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
pw_len = get_pw_string(pw,
|
pw_len = get_pw_string(pw,
|
||||||
"Please enter encryption password", 1);
|
"Please enter encryption password", 1);
|
||||||
if (pw_len == -1) {
|
if (pw_len == -1) {
|
||||||
err_print(0, "Failed to get password.\n");
|
log_msg(LOG_ERR, 0, "Failed to get password.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
} else if (!pctx->user_pw) {
|
} else if (!pctx->user_pw) {
|
||||||
|
@ -1769,7 +1769,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pw_len == -1) {
|
if (pw_len == -1) {
|
||||||
err_print(1, "Failed to get password.\n");
|
log_msg(LOG_ERR, 1, "Failed to get password.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -1778,7 +1778,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
if (init_crypto(&(pctx->crypto_ctx), pctx->user_pw, pctx->user_pw_len, pctx->encrypt_type,
|
if (init_crypto(&(pctx->crypto_ctx), pctx->user_pw, pctx->user_pw_len, pctx->encrypt_type,
|
||||||
NULL, 0, pctx->keylen, 0, ENCRYPT_FLAG) == -1) {
|
NULL, 0, pctx->keylen, 0, ENCRYPT_FLAG) == -1) {
|
||||||
memset(pctx->user_pw, 0, pctx->user_pw_len);
|
memset(pctx->user_pw, 0, pctx->user_pw_len);
|
||||||
err_print(0, "Failed to initialize crypto\n");
|
log_msg(LOG_ERR, 0, "Failed to initialize crypto\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
memset(pctx->user_pw, 0, pctx->user_pw_len);
|
memset(pctx->user_pw, 0, pctx->user_pw_len);
|
||||||
|
@ -1788,7 +1788,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
if (init_crypto(&(pctx->crypto_ctx), pw, pw_len, pctx->encrypt_type, NULL,
|
if (init_crypto(&(pctx->crypto_ctx), pw, pw_len, pctx->encrypt_type, NULL,
|
||||||
0, pctx->keylen, 0, ENCRYPT_FLAG) == -1) {
|
0, pctx->keylen, 0, ENCRYPT_FLAG) == -1) {
|
||||||
memset(pw, 0, MAX_PW_LEN);
|
memset(pw, 0, MAX_PW_LEN);
|
||||||
err_print(0, "Failed to initialize crypto\n");
|
log_msg(LOG_ERR, 0, "Failed to initialize crypto\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
memset(pw, 0, MAX_PW_LEN);
|
memset(pw, 0, MAX_PW_LEN);
|
||||||
|
@ -1808,19 +1808,19 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
if (!pctx->pipe_mode) {
|
if (!pctx->pipe_mode) {
|
||||||
char *tmp;
|
char *tmp;
|
||||||
if ((uncompfd = open(filename, O_RDONLY, 0)) == -1) {
|
if ((uncompfd = open(filename, O_RDONLY, 0)) == -1) {
|
||||||
err_print(1, "Cannot open: %s", filename);
|
log_msg(LOG_ERR, 1, "Cannot open: %s", filename);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(uncompfd, &sbuf) == -1) {
|
if (fstat(uncompfd, &sbuf) == -1) {
|
||||||
close(uncompfd);
|
close(uncompfd);
|
||||||
err_print(1, "Cannot stat: %s", filename);
|
log_msg(LOG_ERR, 1, "Cannot stat: %s", filename);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!S_ISREG(sbuf.st_mode)) {
|
if (!S_ISREG(sbuf.st_mode)) {
|
||||||
close(uncompfd);
|
close(uncompfd);
|
||||||
err_print(0, "File %s is not a regular file.\n", filename);
|
log_msg(LOG_ERR, 0, "File %s is not a regular file.\n", filename);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1991,24 +1991,24 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
flags |= pctx->encrypt_type;
|
flags |= pctx->encrypt_type;
|
||||||
|
|
||||||
set_threadcounts(&props, &(pctx->nthreads), nprocs, COMPRESS_THREADS);
|
set_threadcounts(&props, &(pctx->nthreads), nprocs, COMPRESS_THREADS);
|
||||||
fprintf(stderr, "Scaling to %d thread", pctx->nthreads * props.nthreads);
|
log_msg(LOG_INFO, 0, "Scaling to %d thread", pctx->nthreads * props.nthreads);
|
||||||
if (pctx->nthreads * props.nthreads > 1) fprintf(stderr, "s");
|
if (pctx->nthreads * props.nthreads > 1) log_msg(LOG_INFO, 0, "s");
|
||||||
nprocs = pctx->nthreads;
|
nprocs = pctx->nthreads;
|
||||||
fprintf(stderr, "\n");
|
log_msg(LOG_INFO, 0, "\n");
|
||||||
dary = (struct cmp_data **)slab_calloc(NULL, nprocs, sizeof (struct cmp_data *));
|
dary = (struct cmp_data **)slab_calloc(NULL, nprocs, sizeof (struct cmp_data *));
|
||||||
if ((pctx->enable_rabin_scan || pctx->enable_fixed_scan))
|
if ((pctx->enable_rabin_scan || pctx->enable_fixed_scan))
|
||||||
cread_buf = (uchar_t *)slab_alloc(NULL, compressed_chunksize);
|
cread_buf = (uchar_t *)slab_alloc(NULL, compressed_chunksize);
|
||||||
else
|
else
|
||||||
cread_buf = (uchar_t *)slab_alloc(NULL, chunksize);
|
cread_buf = (uchar_t *)slab_alloc(NULL, chunksize);
|
||||||
if (!cread_buf) {
|
if (!cread_buf) {
|
||||||
fprintf(stderr, "3: Out of memory\n");
|
log_msg(LOG_ERR, 0, "3: Out of memory\n");
|
||||||
COMP_BAIL;
|
COMP_BAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nprocs; i++) {
|
for (i = 0; i < nprocs; i++) {
|
||||||
dary[i] = (struct cmp_data *)slab_alloc(NULL, sizeof (struct cmp_data));
|
dary[i] = (struct cmp_data *)slab_alloc(NULL, sizeof (struct cmp_data));
|
||||||
if (!dary[i]) {
|
if (!dary[i]) {
|
||||||
fprintf(stderr, "4: Out of memory\n");
|
log_msg(LOG_ERR, 0, "4: Out of memory\n");
|
||||||
COMP_BAIL;
|
COMP_BAIL;
|
||||||
}
|
}
|
||||||
tdat = dary[i];
|
tdat = dary[i];
|
||||||
|
@ -2042,7 +2042,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
|
|
||||||
if (pctx->encrypt_type) {
|
if (pctx->encrypt_type) {
|
||||||
if (hmac_init(&tdat->chunk_hmac, pctx->cksum, &(pctx->crypto_ctx)) == -1) {
|
if (hmac_init(&tdat->chunk_hmac, pctx->cksum, &(pctx->crypto_ctx)) == -1) {
|
||||||
fprintf(stderr, "Cannot initialize chunk hmac.\n");
|
log_msg(LOG_ERR, 0, "Cannot initialize chunk hmac.\n");
|
||||||
COMP_BAIL;
|
COMP_BAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2146,7 +2146,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
unsigned int hlen;
|
unsigned int hlen;
|
||||||
|
|
||||||
if (hmac_init(&hdr_mac, pctx->cksum, &(pctx->crypto_ctx)) == -1) {
|
if (hmac_init(&hdr_mac, pctx->cksum, &(pctx->crypto_ctx)) == -1) {
|
||||||
fprintf(stderr, "Cannot initialize header hmac.\n");
|
log_msg(LOG_ERR, 0, "Cannot initialize header hmac.\n");
|
||||||
COMP_BAIL;
|
COMP_BAIL;
|
||||||
}
|
}
|
||||||
hmac_update(&hdr_mac, cread_buf, pos - cread_buf);
|
hmac_update(&hdr_mac, cread_buf, pos - cread_buf);
|
||||||
|
@ -2240,7 +2240,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
tdat->compressed_chunk = tdat->cmp_seg + COMPRESSED_CHUNKSZ +
|
tdat->compressed_chunk = tdat->cmp_seg + COMPRESSED_CHUNKSZ +
|
||||||
pctx->cksum_bytes + pctx->mac_bytes;
|
pctx->cksum_bytes + pctx->mac_bytes;
|
||||||
if (!tdat->cmp_seg || !tdat->uncompressed_chunk) {
|
if (!tdat->cmp_seg || !tdat->uncompressed_chunk) {
|
||||||
fprintf(stderr, "5: Out of memory\n");
|
log_msg(LOG_ERR, 0, "5: Out of memory\n");
|
||||||
COMP_BAIL;
|
COMP_BAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2344,9 +2344,9 @@ comp_done:
|
||||||
rm_fname(tmpfile1);
|
rm_fname(tmpfile1);
|
||||||
}
|
}
|
||||||
if (filename)
|
if (filename)
|
||||||
fprintf(stderr, "Error compressing file: %s\n", filename);
|
log_msg(LOG_ERR, 0, "Error compressing file: %s\n", filename);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Error compressing\n");
|
log_msg(LOG_ERR, 0, "Error compressing\n");
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Write a trailer of zero chunk length.
|
* Write a trailer of zero chunk length.
|
||||||
|
@ -2613,7 +2613,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
pctx->do_compress = 1;
|
pctx->do_compress = 1;
|
||||||
pctx->algo = optarg;
|
pctx->algo = optarg;
|
||||||
if (init_algo(pctx, pctx->algo, 1) != 0) {
|
if (init_algo(pctx, pctx->algo, 1) != 0) {
|
||||||
err_print(0, "Invalid algorithm %s\n", optarg);
|
log_msg(LOG_ERR, 0, "Invalid algorithm %s\n", optarg);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2621,21 +2621,21 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
case 's':
|
case 's':
|
||||||
ovr = parse_numeric(&chunksize, optarg);
|
ovr = parse_numeric(&chunksize, optarg);
|
||||||
if (ovr == 1) {
|
if (ovr == 1) {
|
||||||
err_print(0, "Chunk size too large %s\n", optarg);
|
log_msg(LOG_ERR, 0, "Chunk size too large %s\n", optarg);
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
} else if (ovr == 2) {
|
} else if (ovr == 2) {
|
||||||
err_print(0, "Invalid number %s\n", optarg);
|
log_msg(LOG_ERR, 0, "Invalid number %s\n", optarg);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
pctx->chunksize = chunksize;
|
pctx->chunksize = chunksize;
|
||||||
|
|
||||||
if (pctx->chunksize < MIN_CHUNK) {
|
if (pctx->chunksize < MIN_CHUNK) {
|
||||||
err_print(0, "Minimum chunk size is %ld\n", MIN_CHUNK);
|
log_msg(LOG_ERR, 0, "Minimum chunk size is %ld\n", MIN_CHUNK);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (pctx->chunksize > EIGHTY_PCT(get_total_ram())) {
|
if (pctx->chunksize > EIGHTY_PCT(get_total_ram())) {
|
||||||
err_print(0, "Chunk size must not exceed 80%% of total RAM.\n");
|
log_msg(LOG_ERR, 0, "Chunk size must not exceed 80%% of total RAM.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2643,7 +2643,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
case 'l':
|
case 'l':
|
||||||
pctx->level = atoi(optarg);
|
pctx->level = atoi(optarg);
|
||||||
if (pctx->level < 0 || pctx->level > MAX_LEVEL) {
|
if (pctx->level < 0 || pctx->level > MAX_LEVEL) {
|
||||||
err_print(0, "Compression level should be in range 0 - 14\n");
|
log_msg(LOG_ERR, 0, "Compression level should be in range 0 - 14\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2651,7 +2651,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
case 'B':
|
case 'B':
|
||||||
pctx->rab_blk_size = atoi(optarg);
|
pctx->rab_blk_size = atoi(optarg);
|
||||||
if (pctx->rab_blk_size < 0 || pctx->rab_blk_size > 5) {
|
if (pctx->rab_blk_size < 0 || pctx->rab_blk_size > 5) {
|
||||||
err_print(0, "Average Dedupe block size must be in range 0 (2k), 1 (4k) .. 5 (64k)\n");
|
log_msg(LOG_ERR, 0, "Average Dedupe block size must be in range 0 (2k), 1 (4k) .. 5 (64k)\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2663,7 +2663,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
case 't':
|
case 't':
|
||||||
pctx->nthreads = atoi(optarg);
|
pctx->nthreads = atoi(optarg);
|
||||||
if (pctx->nthreads < 1 || pctx->nthreads > 256) {
|
if (pctx->nthreads < 1 || pctx->nthreads > 256) {
|
||||||
err_print(0, "Thread count should be in range 1 - 256\n");
|
log_msg(LOG_ERR, 0, "Thread count should be in range 1 - 256\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2695,7 +2695,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
case 'e':
|
case 'e':
|
||||||
pctx->encrypt_type = get_crypto_alg(optarg);
|
pctx->encrypt_type = get_crypto_alg(optarg);
|
||||||
if (pctx->encrypt_type == 0) {
|
if (pctx->encrypt_type == 0) {
|
||||||
err_print(0, "Invalid encryption algorithm. Should be AES or SALSA20.\n", optarg);
|
log_msg(LOG_ERR, 0, "Invalid encryption algorithm. Should be AES or SALSA20.\n", optarg);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2720,7 +2720,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
case 'k':
|
case 'k':
|
||||||
pctx->keylen = atoi(optarg);
|
pctx->keylen = atoi(optarg);
|
||||||
if ((pctx->keylen != 16 && pctx->keylen != 32) || pctx->keylen > MAX_KEYLEN) {
|
if ((pctx->keylen != 16 && pctx->keylen != 32) || pctx->keylen > MAX_KEYLEN) {
|
||||||
err_print(0, "Encryption KEY length should be 16 or 32.\n", optarg);
|
log_msg(LOG_ERR, 0, "Encryption KEY length should be 16 or 32.\n", optarg);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2728,7 +2728,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
case 'S':
|
case 'S':
|
||||||
if (get_checksum_props(optarg, &(pctx->cksum), &(pctx->cksum_bytes),
|
if (get_checksum_props(optarg, &(pctx->cksum), &(pctx->cksum_bytes),
|
||||||
&(pctx->mac_bytes), 0) == -1) {
|
&(pctx->mac_bytes), 0) == -1) {
|
||||||
err_print(0, "Invalid checksum type %s\n", optarg);
|
log_msg(LOG_ERR, 0, "Invalid checksum type %s\n", optarg);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2766,28 +2766,28 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
num_rem = argc - my_optind;
|
num_rem = argc - my_optind;
|
||||||
if (pctx->pipe_mode && num_rem > 0 ) {
|
if (pctx->pipe_mode && num_rem > 0 ) {
|
||||||
fprintf(stderr, "Filename(s) unexpected for pipe mode\n");
|
log_msg(LOG_ERR, 0, "Filename(s) unexpected for pipe mode\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pctx->enable_rabin_scan || pctx->enable_fixed_scan) && !pctx->do_compress) {
|
if ((pctx->enable_rabin_scan || pctx->enable_fixed_scan) && !pctx->do_compress) {
|
||||||
fprintf(stderr, "Deduplication is only used during compression.\n");
|
log_msg(LOG_ERR, 0, "Deduplication is only used during compression.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (!pctx->enable_rabin_scan)
|
if (!pctx->enable_rabin_scan)
|
||||||
pctx->enable_rabin_split = 0;
|
pctx->enable_rabin_split = 0;
|
||||||
|
|
||||||
if (pctx->enable_fixed_scan && (pctx->enable_rabin_scan || pctx->enable_delta_encode || pctx->enable_rabin_split)) {
|
if (pctx->enable_fixed_scan && (pctx->enable_rabin_scan || pctx->enable_delta_encode || pctx->enable_rabin_split)) {
|
||||||
fprintf(stderr, "Rabin Deduplication and Fixed block Deduplication are mutually exclusive\n");
|
log_msg(LOG_ERR, 0, "Rabin Deduplication and Fixed block Deduplication are mutually exclusive\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pctx->do_compress && pctx->encrypt_type) {
|
if (!pctx->do_compress && pctx->encrypt_type) {
|
||||||
fprintf(stderr, "Encryption only makes sense when compressing!\n");
|
log_msg(LOG_ERR, 0, "Encryption only makes sense when compressing!\n");
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
} else if (pctx->pipe_mode && pctx->encrypt_type && !pctx->pwd_file) {
|
} else if (pctx->pipe_mode && pctx->encrypt_type && !pctx->pwd_file) {
|
||||||
fprintf(stderr, "Pipe mode requires password to be provided in a file.\n");
|
log_msg(LOG_ERR, 0, "Pipe mode requires password to be provided in a file.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2801,12 +2801,12 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pctx->enable_rabin_global && pctx->enable_delta_encode) {
|
if (pctx->enable_rabin_global && pctx->enable_delta_encode) {
|
||||||
fprintf(stderr, "Global Deduplication does not support Delta Compression.\n");
|
log_msg(LOG_ERR, 0, "Global Deduplication does not support Delta Compression.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_rem == 0 && !pctx->pipe_mode) {
|
if (num_rem == 0 && !pctx->pipe_mode) {
|
||||||
fprintf(stderr, "Expected at least one filename.\n");
|
log_msg(LOG_ERR, 0, "Expected at least one filename.\n");
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
} else if (num_rem == 1 || num_rem == 2) {
|
} else if (num_rem == 1 || num_rem == 2) {
|
||||||
|
@ -2814,7 +2814,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
char apath[MAXPATHLEN];
|
char apath[MAXPATHLEN];
|
||||||
|
|
||||||
if ((pctx->filename = realpath(argv[my_optind], NULL)) == NULL) {
|
if ((pctx->filename = realpath(argv[my_optind], NULL)) == NULL) {
|
||||||
err_print(1, "%s", argv[my_optind]);
|
log_msg(LOG_ERR, 1, "%s", argv[my_optind]);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2833,7 +2833,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
|
|
||||||
/* Check if compressed file exists */
|
/* Check if compressed file exists */
|
||||||
if (pctx->to_filename != NULL) {
|
if (pctx->to_filename != NULL) {
|
||||||
err_print(0, "Compressed file %s exists\n", pctx->to_filename);
|
log_msg(LOG_ERR, 0, "Compressed file %s exists\n", pctx->to_filename);
|
||||||
free((void *)(pctx->to_filename));
|
free((void *)(pctx->to_filename));
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -2845,14 +2845,14 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
pctx->filename = NULL;
|
pctx->filename = NULL;
|
||||||
} else {
|
} else {
|
||||||
if ((pctx->filename = realpath(argv[my_optind], NULL)) == NULL) {
|
if ((pctx->filename = realpath(argv[my_optind], NULL)) == NULL) {
|
||||||
err_print(1, "%s", argv[my_optind]);
|
log_msg(LOG_ERR, 1, "%s", argv[my_optind]);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my_optind++;
|
my_optind++;
|
||||||
if ((pctx->to_filename = realpath(argv[my_optind], NULL)) != NULL) {
|
if ((pctx->to_filename = realpath(argv[my_optind], NULL)) != NULL) {
|
||||||
free((void *)(pctx->to_filename));
|
free((void *)(pctx->to_filename));
|
||||||
err_print(0, "File %s exists\n", argv[my_optind]);
|
log_msg(LOG_ERR, 0, "File %s exists\n", argv[my_optind]);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
pctx->to_filename = argv[my_optind];
|
pctx->to_filename = argv[my_optind];
|
||||||
|
@ -2860,7 +2860,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
} else if (num_rem > 2) {
|
} else if (num_rem > 2) {
|
||||||
fprintf(stderr, "Too many filenames.\n");
|
log_msg(LOG_ERR, 0, "Too many filenames.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
pctx->main_cancel = 0;
|
pctx->main_cancel = 0;
|
||||||
|
@ -2869,7 +2869,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[])
|
||||||
get_checksum_props(DEFAULT_CKSUM, &(pctx->cksum), &(pctx->cksum_bytes), &(pctx->mac_bytes), 0);
|
get_checksum_props(DEFAULT_CKSUM, &(pctx->cksum), &(pctx->cksum_bytes), &(pctx->mac_bytes), 0);
|
||||||
|
|
||||||
if ((pctx->enable_rabin_scan || pctx->enable_fixed_scan) && pctx->cksum == CKSUM_CRC64) {
|
if ((pctx->enable_rabin_scan || pctx->enable_fixed_scan) && pctx->cksum == CKSUM_CRC64) {
|
||||||
fprintf(stderr, "CRC64 checksum is not suitable for Deduplication.\n");
|
log_msg(LOG_ERR, 0, "CRC64 checksum is not suitable for Deduplication.\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ ppmd_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
||||||
_ppmd->Base = 0;
|
_ppmd->Base = 0;
|
||||||
_ppmd->Size = 0;
|
_ppmd->Size = 0;
|
||||||
if (!Ppmd8_Alloc(_ppmd, ppmd8_mem_sz[*level], &g_Alloc)) {
|
if (!Ppmd8_Alloc(_ppmd, ppmd8_mem_sz[*level], &g_Alloc)) {
|
||||||
fprintf(stderr, "PPMD: Out of memory.\n");
|
log_msg(LOG_ERR, 0, "PPMD: Out of memory.\n");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
Ppmd8_Construct(_ppmd);
|
Ppmd8_Construct(_ppmd);
|
||||||
|
|
|
@ -222,7 +222,7 @@ read_config(char *configfile, archive_config_t *cfg)
|
||||||
if (strncmp(line, "CHUNKSZ", 7) == 0) {
|
if (strncmp(line, "CHUNKSZ", 7) == 0) {
|
||||||
int ck = atoi(pos);
|
int ck = atoi(pos);
|
||||||
if (ck < MIN_CK || ck > MAX_CK) {
|
if (ck < MIN_CK || ck > MAX_CK) {
|
||||||
fprintf(stderr, "Invalid Chunk Size: %d\n", ck);
|
log_msg(LOG_ERR, 0, "Invalid Chunk Size: %d\n", ck);
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ read_config(char *configfile, archive_config_t *cfg)
|
||||||
if (stat(pos, &sb) == -1) {
|
if (stat(pos, &sb) == -1) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
perror(" ");
|
perror(" ");
|
||||||
fprintf(stderr, "Invalid ROOTDIR.\n");
|
log_msg(LOG_ERR, 0, "Invalid ROOTDIR.\n");
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return (1);
|
return (1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -241,7 +241,7 @@ read_config(char *configfile, archive_config_t *cfg)
|
||||||
strncpy(cfg->rootdir, pos, PATH_MAX);
|
strncpy(cfg->rootdir, pos, PATH_MAX);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid ROOTDIR. It already exists.\n");
|
log_msg(LOG_ERR, 0, "Invalid ROOTDIR. It already exists.\n");
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -250,12 +250,12 @@ read_config(char *configfile, archive_config_t *cfg)
|
||||||
ssize_t arch_sz;
|
ssize_t arch_sz;
|
||||||
ovr = parse_numeric(&arch_sz, pos);
|
ovr = parse_numeric(&arch_sz, pos);
|
||||||
if (ovr == 1) {
|
if (ovr == 1) {
|
||||||
fprintf(stderr, "ARCHIVESZ value too large.\n");
|
log_msg(LOG_ERR, 0, "ARCHIVESZ value too large.\n");
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (ovr == 2) {
|
if (ovr == 2) {
|
||||||
fprintf(stderr, "Invalid ARCHIVESZ value.\n");
|
log_msg(LOG_ERR, 0, "Invalid ARCHIVESZ value.\n");
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -268,21 +268,21 @@ read_config(char *configfile, archive_config_t *cfg)
|
||||||
} else if (strcmp(pos, "yes") == 0) {
|
} else if (strcmp(pos, "yes") == 0) {
|
||||||
cfg->verify_chunks = 1;
|
cfg->verify_chunks = 1;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid VERIFY setting. Must be either yes or no.\n");
|
log_msg(LOG_ERR, 0, "Invalid VERIFY setting. Must be either yes or no.\n");
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
} else if (strncmp(line, "COMPRESS", 8) == 0) {
|
} else if (strncmp(line, "COMPRESS", 8) == 0) {
|
||||||
cfg->algo = get_compress_algo(pos);
|
cfg->algo = get_compress_algo(pos);
|
||||||
if (cfg->algo == COMPRESS_INVALID) {
|
if (cfg->algo == COMPRESS_INVALID) {
|
||||||
fprintf(stderr, "Invalid COMPRESS setting.\n");
|
log_msg(LOG_ERR, 0, "Invalid COMPRESS setting.\n");
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
} else if (strncmp(line, "CHUNK_CKSUM", 11) == 0) {
|
} else if (strncmp(line, "CHUNK_CKSUM", 11) == 0) {
|
||||||
cfg->chunk_cksum_type = get_cksum_type(pos);
|
cfg->chunk_cksum_type = get_cksum_type(pos);
|
||||||
if (cfg->chunk_cksum_type == CKSUM_INVALID) {
|
if (cfg->chunk_cksum_type == CKSUM_INVALID) {
|
||||||
fprintf(stderr, "Invalid CHUNK_CKSUM setting.\n");
|
log_msg(LOG_ERR, 0, "Invalid CHUNK_CKSUM setting.\n");
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ init_global_db(char *configfile)
|
||||||
|
|
||||||
cfg = calloc(1, sizeof (archive_config_t));
|
cfg = calloc(1, sizeof (archive_config_t));
|
||||||
if (!cfg) {
|
if (!cfg) {
|
||||||
fprintf(stderr, "Memory allocation failure\n");
|
log_msg(LOG_ERR, 0, "Memory allocation failure\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ init_global_db_s(char *path, char *tmppath, uint32_t chunksize, uint64_t user_ch
|
||||||
index_t *indx;
|
index_t *indx;
|
||||||
|
|
||||||
if (path != NULL) {
|
if (path != NULL) {
|
||||||
fprintf(stderr, "Disk based index not yet implemented.\n");
|
log_msg(LOG_WARN, 0, "Disk based index not yet implemented.\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
cfg = calloc(1, sizeof (archive_config_t));
|
cfg = calloc(1, sizeof (archive_config_t));
|
||||||
|
|
|
@ -226,7 +226,7 @@ create_dedupe_context(uint64_t chunksize, uint64_t real_chunksize, int rab_blk_s
|
||||||
if ((ck = getenv("PCOMPRESS_CHUNK_HASH_GLOBAL")) != NULL) {
|
if ((ck = getenv("PCOMPRESS_CHUNK_HASH_GLOBAL")) != NULL) {
|
||||||
if (get_checksum_props(ck, &chunk_cksum, &cksum_bytes, &mac_bytes, 1) != 0 ||
|
if (get_checksum_props(ck, &chunk_cksum, &cksum_bytes, &mac_bytes, 1) != 0 ||
|
||||||
strcmp(ck, "CRC64") == 0) {
|
strcmp(ck, "CRC64") == 0) {
|
||||||
fprintf(stderr, "Invalid PCOMPRESS_CHUNK_HASH_GLOBAL.\n");
|
log_msg(LOG_ERR, 0, "Invalid PCOMPRESS_CHUNK_HASH_GLOBAL.\n");
|
||||||
chunk_cksum = DEFAULT_CHUNK_CKSUM;
|
chunk_cksum = DEFAULT_CHUNK_CKSUM;
|
||||||
pthread_mutex_unlock(&init_lock);
|
pthread_mutex_unlock(&init_lock);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -235,7 +235,7 @@ create_dedupe_context(uint64_t chunksize, uint64_t real_chunksize, int rab_blk_s
|
||||||
if (chunk_cksum == 0) {
|
if (chunk_cksum == 0) {
|
||||||
chunk_cksum = DEFAULT_CHUNK_CKSUM;
|
chunk_cksum = DEFAULT_CHUNK_CKSUM;
|
||||||
if (get_checksum_props(NULL, &chunk_cksum, &cksum_bytes, &mac_bytes, 0) != 0) {
|
if (get_checksum_props(NULL, &chunk_cksum, &cksum_bytes, &mac_bytes, 0) != 0) {
|
||||||
fprintf(stderr, "Invalid default chunk checksum: %d\n", DEFAULT_CHUNK_CKSUM);
|
log_msg(LOG_ERR, 0, "Invalid default chunk checksum: %d\n", DEFAULT_CHUNK_CKSUM);
|
||||||
pthread_mutex_unlock(&init_lock);
|
pthread_mutex_unlock(&init_lock);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
@ -256,19 +256,19 @@ create_dedupe_context(uint64_t chunksize, uint64_t real_chunksize, int rab_blk_s
|
||||||
* Rabin window size must be power of 2 for optimization.
|
* Rabin window size must be power of 2 for optimization.
|
||||||
*/
|
*/
|
||||||
if (!ISP2(RAB_POLYNOMIAL_WIN_SIZE)) {
|
if (!ISP2(RAB_POLYNOMIAL_WIN_SIZE)) {
|
||||||
fprintf(stderr, "Rabin window size must be a power of 2 in range 4 <= x <= 64\n");
|
log_msg(LOG_ERR, 0, "Rabin window size must be a power of 2 in range 4 <= x <= 64\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arc) {
|
if (arc) {
|
||||||
if (chunksize < RAB_MIN_CHUNK_SIZE_GLOBAL) {
|
if (chunksize < RAB_MIN_CHUNK_SIZE_GLOBAL) {
|
||||||
fprintf(stderr, "Minimum chunk size for Global Dedup must be %" PRIu64 " bytes\n",
|
log_msg(LOG_ERR, 0, "Minimum chunk size for Global Dedup must be %" PRIu64 " bytes\n",
|
||||||
RAB_MIN_CHUNK_SIZE_GLOBAL);
|
RAB_MIN_CHUNK_SIZE_GLOBAL);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (chunksize < RAB_MIN_CHUNK_SIZE) {
|
if (chunksize < RAB_MIN_CHUNK_SIZE) {
|
||||||
fprintf(stderr, "Minimum chunk size for Dedup must be %" PRIu64 " bytes\n",
|
log_msg(LOG_ERR, 0, "Minimum chunk size for Dedup must be %" PRIu64 " bytes\n",
|
||||||
RAB_MIN_CHUNK_SIZE);
|
RAB_MIN_CHUNK_SIZE);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ create_dedupe_context(uint64_t chunksize, uint64_t real_chunksize, int rab_blk_s
|
||||||
++(ctx->blknum);
|
++(ctx->blknum);
|
||||||
|
|
||||||
if (ctx->blknum > RABIN_MAX_BLOCKS) {
|
if (ctx->blknum > RABIN_MAX_BLOCKS) {
|
||||||
fprintf(stderr, "Chunk size too large for dedup.\n");
|
log_msg(LOG_ERR, 0, "Chunk size too large for dedup.\n");
|
||||||
destroy_dedupe_context(ctx);
|
destroy_dedupe_context(ctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ create_dedupe_context(uint64_t chunksize, uint64_t real_chunksize, int rab_blk_s
|
||||||
}
|
}
|
||||||
if(ctx == NULL || ctx->current_window_data == NULL ||
|
if(ctx == NULL || ctx->current_window_data == NULL ||
|
||||||
(ctx->blocks == NULL && real_chunksize > 0 && dedupe_flag != RABIN_DEDUPE_FILE_GLOBAL)) {
|
(ctx->blocks == NULL && real_chunksize > 0 && dedupe_flag != RABIN_DEDUPE_FILE_GLOBAL)) {
|
||||||
fprintf(stderr,
|
log_msg(LOG_ERR, 0,
|
||||||
"Could not allocate rabin polynomial context, out of memory\n");
|
"Could not allocate rabin polynomial context, out of memory\n");
|
||||||
destroy_dedupe_context(ctx);
|
destroy_dedupe_context(ctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -351,7 +351,7 @@ create_dedupe_context(uint64_t chunksize, uint64_t real_chunksize, int rab_blk_s
|
||||||
arc->sub_intervals,
|
arc->sub_intervals,
|
||||||
arc->similarity_cksum_sz);
|
arc->similarity_cksum_sz);
|
||||||
if (!ctx->similarity_cksums) {
|
if (!ctx->similarity_cksums) {
|
||||||
fprintf(stderr,
|
log_msg(LOG_ERR, 0,
|
||||||
"Could not allocate dedupe context, out of memory\n");
|
"Could not allocate dedupe context, out of memory\n");
|
||||||
destroy_dedupe_context(ctx);
|
destroy_dedupe_context(ctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -365,7 +365,7 @@ create_dedupe_context(uint64_t chunksize, uint64_t real_chunksize, int rab_blk_s
|
||||||
|
|
||||||
// The lzma_data member is not needed during decompression
|
// The lzma_data member is not needed during decompression
|
||||||
if (!(ctx->lzma_data) && op == COMPRESS) {
|
if (!(ctx->lzma_data) && op == COMPRESS) {
|
||||||
fprintf(stderr,
|
log_msg(LOG_ERR, 0,
|
||||||
"Could not initialize LZMA data for dedupe index, out of memory\n");
|
"Could not initialize LZMA data for dedupe index, out of memory\n");
|
||||||
destroy_dedupe_context(ctx);
|
destroy_dedupe_context(ctx);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -1123,7 +1123,7 @@ process_blocks:
|
||||||
offset = U64_P(sim_ck);
|
offset = U64_P(sim_ck);
|
||||||
if (db_segcache_map(cfg, ctx->id, &o_blks, &offset,
|
if (db_segcache_map(cfg, ctx->id, &o_blks, &offset,
|
||||||
(uchar_t **)&seg_blocks) == -1) {
|
(uchar_t **)&seg_blocks) == -1) {
|
||||||
fprintf(stderr, "** Segment cache mmap failed.\n");
|
log_msg(LOG_ERR, 0, "** Segment cache mmap failed.\n");
|
||||||
ctx->valid = 0;
|
ctx->valid = 0;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -1575,7 +1575,7 @@ dedupe_decompress(dedupe_context_t *ctx, uchar_t *buf, uint64_t *size)
|
||||||
len &= RABIN_INDEX_VALUE;
|
len &= RABIN_INDEX_VALUE;
|
||||||
|
|
||||||
if (sz + len > data_sz) {
|
if (sz + len > data_sz) {
|
||||||
fprintf(stderr, "Dedup data overflows chunk.\n");
|
log_msg(LOG_ERR, 0, "Dedup data overflows chunk.\n");
|
||||||
ctx->valid = 0;
|
ctx->valid = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1675,14 +1675,14 @@ dedupe_decompress(dedupe_context_t *ctx, uchar_t *buf, uint64_t *size)
|
||||||
newsz = data_sz - sz;
|
newsz = data_sz - sz;
|
||||||
rv = bspatch(buf + ctx->blocks[blk]->offset, buf + pos1, len, pos2, &newsz);
|
rv = bspatch(buf + ctx->blocks[blk]->offset, buf + pos1, len, pos2, &newsz);
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
fprintf(stderr, "Failed to bspatch block.\n");
|
log_msg(LOG_ERR, 0, "Failed to bspatch block.\n");
|
||||||
ctx->valid = 0;
|
ctx->valid = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pos2 += newsz;
|
pos2 += newsz;
|
||||||
sz += newsz;
|
sz += newsz;
|
||||||
if (sz > data_sz) {
|
if (sz > data_sz) {
|
||||||
fprintf(stderr, "Dedup data overflows chunk.\n");
|
log_msg(LOG_ERR, 0, "Dedup data overflows chunk.\n");
|
||||||
ctx->valid = 0;
|
ctx->valid = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1696,13 +1696,13 @@ dedupe_decompress(dedupe_context_t *ctx, uchar_t *buf, uint64_t *size)
|
||||||
pos2 += len;
|
pos2 += len;
|
||||||
sz += len;
|
sz += len;
|
||||||
if (sz > data_sz) {
|
if (sz > data_sz) {
|
||||||
fprintf(stderr, "Dedup data overflows chunk.\n");
|
log_msg(LOG_ERR, 0, "Dedup data overflows chunk.\n");
|
||||||
ctx->valid = 0;
|
ctx->valid = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ctx->valid && sz < data_sz) {
|
if (ctx->valid && sz < data_sz) {
|
||||||
fprintf(stderr, "Too little dedup data processed.\n");
|
log_msg(LOG_ERR, 0, "Too little dedup data processed.\n");
|
||||||
ctx->valid = 0;
|
ctx->valid = 0;
|
||||||
}
|
}
|
||||||
*size = data_sz;
|
*size = data_sz;
|
||||||
|
|
|
@ -48,6 +48,8 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
processor_info_t proc_info;
|
processor_info_t proc_info;
|
||||||
|
static int cur_log_level = 1;
|
||||||
|
static log_dest_t ldest = {LOG_OUTPUT, LOG_INFO, NULL};
|
||||||
|
|
||||||
void
|
void
|
||||||
init_pcompress() {
|
init_pcompress() {
|
||||||
|
@ -55,6 +57,7 @@ init_pcompress() {
|
||||||
XXH32_module_init();
|
XXH32_module_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void
|
void
|
||||||
err_exit(int show_errno, const char *format, ...)
|
err_exit(int show_errno, const char *format, ...)
|
||||||
{
|
{
|
||||||
|
@ -83,6 +86,7 @@ err_print(int show_errno, const char *format, ...)
|
||||||
if (show_errno)
|
if (show_errno)
|
||||||
fprintf(stderr, "\nError: %s\n", strerror(err));
|
fprintf(stderr, "\nError: %s\n", strerror(err));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fetch the command name that started the current process.
|
* Fetch the command name that started the current process.
|
||||||
|
@ -448,3 +452,46 @@ chk_dir(char *dir)
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DLL_EXPORT
|
||||||
|
set_log_dest(log_dest_t *dest)
|
||||||
|
{
|
||||||
|
ldest.type = dest->type;
|
||||||
|
ldest.fd = dest->fd;
|
||||||
|
ldest.cb = dest->cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DLL_EXPORT
|
||||||
|
set_log_level(int level)
|
||||||
|
{
|
||||||
|
if (level >= 0 && level < 10)
|
||||||
|
cur_log_level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DLL_EXPORT
|
||||||
|
log_msg(log_level_t log_level, int show_errno, const char *format, ...)
|
||||||
|
{
|
||||||
|
int err = errno, written;
|
||||||
|
va_list args;
|
||||||
|
char msg[1024];
|
||||||
|
|
||||||
|
if (log_level <= cur_log_level) return;
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
|
written = vsnprintf(msg, 1024, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (written < 1024 && show_errno) {
|
||||||
|
snprintf(msg + written, 1024 - written, "\nError: %s\n", strerror(err));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ldest.type == LOG_OUTPUT) {
|
||||||
|
fputs(msg, stderr);
|
||||||
|
|
||||||
|
} else if (ldest.type == LOG_FILE) {
|
||||||
|
int rv;
|
||||||
|
rv = write(ldest.fd, msg, strlen(msg));
|
||||||
|
} else {
|
||||||
|
ldest.cb(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -260,6 +260,32 @@ typedef int (*deinit_func_ptr)(void **data);
|
||||||
typedef void (*stats_func_ptr)(int show);
|
typedef void (*stats_func_ptr)(int show);
|
||||||
typedef void (*props_func_ptr)(algo_props_t *data, int level, uint64_t chunksize);
|
typedef void (*props_func_ptr)(algo_props_t *data, int level, uint64_t chunksize);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logging definitions.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
LOG_OUTPUT,
|
||||||
|
LOG_FILE,
|
||||||
|
LOG_CALLBACK
|
||||||
|
} log_dest_type_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
LOG_ERR,
|
||||||
|
LOG_WARN,
|
||||||
|
LOG_INFO
|
||||||
|
} log_level_t;
|
||||||
|
|
||||||
|
typedef void (*log_callback_ptr)(char *msg);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
log_dest_type_t type;
|
||||||
|
int fd;
|
||||||
|
log_callback_ptr cb;
|
||||||
|
} log_dest_t;
|
||||||
|
|
||||||
|
void set_log_dest(log_dest_t *dest);
|
||||||
|
void set_log_level(int level);
|
||||||
|
void log_msg(log_level_t log_level, int show_errno, const char *format, ...);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Roundup v to the nearest power of 2. From Bit Twiddling Hacks:
|
* Roundup v to the nearest power of 2. From Bit Twiddling Hacks:
|
||||||
|
|
|
@ -116,27 +116,27 @@ void zerr(int ret, int cmp)
|
||||||
perror(" ");
|
perror(" ");
|
||||||
break;
|
break;
|
||||||
case Z_STREAM_ERROR:
|
case Z_STREAM_ERROR:
|
||||||
fprintf(stderr, "Zlib: Invalid stream structure\n");
|
log_msg(LOG_ERR, 0, "Zlib: Invalid stream structure\n");
|
||||||
break;
|
break;
|
||||||
case Z_DATA_ERROR:
|
case Z_DATA_ERROR:
|
||||||
fprintf(stderr, "Zlib: Invalid or incomplete deflate data\n");
|
log_msg(LOG_ERR, 0, "Zlib: Invalid or incomplete deflate data\n");
|
||||||
break;
|
break;
|
||||||
case Z_MEM_ERROR:
|
case Z_MEM_ERROR:
|
||||||
fprintf(stderr, "Zlib: Out of memory\n");
|
log_msg(LOG_ERR, 0, "Zlib: Out of memory\n");
|
||||||
break;
|
break;
|
||||||
case Z_VERSION_ERROR:
|
case Z_VERSION_ERROR:
|
||||||
fprintf(stderr, "Zlib: Version mismatch!\n");
|
log_msg(LOG_ERR, 0, "Zlib: Version mismatch!\n");
|
||||||
break;
|
break;
|
||||||
case Z_BUF_ERROR:
|
case Z_BUF_ERROR:
|
||||||
/* This error is non-fatal during compression. */
|
/* This error is non-fatal during compression. */
|
||||||
if (!cmp)
|
if (!cmp)
|
||||||
fprintf(stderr, "Zlib: Buffer error decompression failed.\n");
|
log_msg(LOG_ERR, 0, "Zlib: Buffer error decompression failed.\n");
|
||||||
break;
|
break;
|
||||||
case Z_NEED_DICT:
|
case Z_NEED_DICT:
|
||||||
fprintf(stderr, "Zlib: Need present dictionary.\n");
|
log_msg(LOG_ERR, 0, "Zlib: Need present dictionary.\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Zlib: Unknown error code: %d\n", ret);
|
log_msg(LOG_ERR, 0, "Zlib: Unknown error code: %d\n", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue