Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions squashfs-tools/gzip_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static int compression_level = GZIP_DEFAULT_COMPRESSION_LEVEL;
/* default window size */
static int window_size = GZIP_DEFAULT_WINDOW_SIZE;

static int rsyncable = 0;

/*
* This function is called by the options parsing code in mksquashfs.c
* to parse any -X compressor option.
Expand Down Expand Up @@ -132,6 +134,14 @@ static int gzip_options(char *argv[], int argc)
}

return 1;
} else if(strcmp(argv[0], "-Xrsyncable") == 0) {
#ifdef Z_RSYNCABLE
rsyncable = 1;
return 0;
#else
fprintf(stderr, "gzip: -Xrsyncable requires rsyncable support\n");
goto failed;
#endif
}

return -1;
Expand Down Expand Up @@ -180,13 +190,14 @@ static void *gzip_dump_options(int block_size, int *size)
* If default compression options of:
* compression-level: 8 and
* window-size: 15 and
* strategy_count == 0 then
* strategy_count == 0 and
* rsyncable == 0 then
* don't store a compression options structure (this is compatible
* with the legacy implementation of GZIP for Squashfs)
*/
if(compression_level == GZIP_DEFAULT_COMPRESSION_LEVEL &&
window_size == GZIP_DEFAULT_WINDOW_SIZE &&
strategy_count == 0)
strategy_count == 0 && rsyncable == 0)
return NULL;

for(i = 0; strategy[i].name; i++)
Expand All @@ -195,6 +206,7 @@ static void *gzip_dump_options(int block_size, int *size)
comp_opts.compression_level = compression_level;
comp_opts.window_size = window_size;
comp_opts.strategy = strategies;
comp_opts.rsyncable = rsyncable;

SQUASHFS_INSWAP_COMP_OPTS(&comp_opts);

Expand Down Expand Up @@ -267,6 +279,8 @@ static int gzip_extract_options(int block_size, void *buffer, int size)
} else
strategy[i].selected = 0;
}

rsyncable = comp_opts->rsyncable;

return 0;

Expand Down Expand Up @@ -369,6 +383,11 @@ static int gzip_init(void **strm, int block_size, int datablock)
stream->stream.zfree = Z_NULL;
stream->stream.opaque = 0;

#ifdef Z_RSYNCABLE
if(rsyncable)
stream->strategy[0].strategy |= Z_RSYNCABLE;
#endif

res = deflateInit2(&stream->stream, compression_level, Z_DEFLATED,
window_size, 8, stream->strategy[0].strategy);
if(res == Z_OK) {
Expand Down Expand Up @@ -473,14 +492,17 @@ static void gzip_usage(FILE *stream, int cols)
"strategyN in turn and choose the best compression. Available "
"strategies: default, filtered, huffman_only, "
"run_length_encoded and fixed\n", cols);
autowrap_print(stream, "\t -Xrsyncable\n", cols);
autowrap_print(stream, "\t\tCompress rsync-friendly\n", cols);
}


static int option_args(char *option)
{
if(strcmp(option, "-Xcompression-level") == 0 ||
strcmp(option, "-Xwindow-size") == 0 ||
strcmp(option, "-Xstrategy") == 0)
strcmp(option, "-Xstrategy") == 0 ||
strcmp(option, "-Xrsyncable") == 0)
return 1;

return 0;
Expand Down
2 changes: 2 additions & 0 deletions squashfs-tools/gzip_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern unsigned int inswap_le32(unsigned int);
(s)->compression_level = inswap_le32((s)->compression_level); \
(s)->window_size = inswap_le16((s)->window_size); \
(s)->strategy = inswap_le16((s)->strategy); \
(s)->rsyncable = inswap_le32((s)->rsyncable); \
}
#else
#define SQUASHFS_INSWAP_COMP_OPTS(s)
Expand All @@ -47,6 +48,7 @@ struct gzip_comp_opts {
int compression_level;
short window_size;
short strategy;
int rsyncable;
};

struct strategy {
Expand Down
29 changes: 27 additions & 2 deletions squashfs-tools/zstd_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

static int compression_level = ZSTD_DEFAULT_COMPRESSION_LEVEL;

static int rsyncable = 0;

/*
* This function is called by the options parsing code in mksquashfs.c
* to parse any -X compressor option.
Expand Down Expand Up @@ -78,6 +80,14 @@ static int zstd_options(char *argv[], int argc)
}

return 1;
} else if(strcmp(argv[0], "-Xrsyncable") == 0) {
#ifdef ZSTD_c_rsyncable
rsyncable = 1;
return 0;
#else
fprintf(stderr, "zstd: -Xrsyncable requires rsyncable support\n");
goto failed;
#endif
}

return -1;
Expand All @@ -100,10 +110,11 @@ static void *zstd_dump_options(int block_size, int *size)
static struct zstd_comp_opts comp_opts;

/* don't return anything if the options are all default */
if (compression_level == ZSTD_DEFAULT_COMPRESSION_LEVEL)
if (compression_level == ZSTD_DEFAULT_COMPRESSION_LEVEL && rsyncable == 0)
return NULL;

comp_opts.compression_level = compression_level;
comp_opts.rsyncable = rsyncable;

SQUASHFS_INSWAP_COMP_OPTS(&comp_opts);

Expand Down Expand Up @@ -137,6 +148,7 @@ static int zstd_extract_options(int block_size, void *buffer, int size)
if (size == 0) {
/* Set default values */
compression_level = ZSTD_DEFAULT_COMPRESSION_LEVEL;
rsyncable = 0;
return 0;
}

Expand All @@ -155,6 +167,7 @@ static int zstd_extract_options(int block_size, void *buffer, int size)
}

compression_level = comp_opts->compression_level;
rsyncable = comp_opts->rsyncable;

return 0;

Expand Down Expand Up @@ -184,6 +197,7 @@ static void zstd_display_options(void *buffer, int size)
}

printf("\tcompression-level %d\n", comp_opts->compression_level);
printf("\trsyncable %d\n", comp_opts->rsyncable);

return;

Expand All @@ -208,6 +222,14 @@ static int zstd_init(void **strm, int block_size, int datablock)
return -1;
}

#ifdef ZSTD_c_rsyncable
const size_t res = ZSTD_CCtx_setParameter(cctx, ZSTD_c_rsyncable, rsyncable);
if (ZSTD_isError(res)) {
fprintf(stderr, "zstd: failed to set rsyncable\n");
return -1;
}
#endif

*strm = cctx;
return 0;
}
Expand Down Expand Up @@ -256,12 +278,15 @@ static void zstd_usage(FILE *stream, int cols)
"-1 or 1 .. %d (default %d). Negative compression levels "
"correspond to the zstd --fast option.\n", ZSTD_minCLevel(),
ZSTD_maxCLevel(), ZSTD_DEFAULT_COMPRESSION_LEVEL);
autowrap_print(stream, "\t -Xrsyncable\n", cols);
autowrap_print(stream, "\t\tCompress rsync-friendly\n", cols);
}


static int option_args(char *option)
{
if(strcmp(option, "-Xcompression-level") == 0)
if(strcmp(option, "-Xcompression-level") == 0 ||
strcmp(option, "-Xrsyncable") == 0)
return 1;

return 0;
Expand Down
2 changes: 2 additions & 0 deletions squashfs-tools/zstd_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern unsigned int inswap_le32(unsigned int);

#define SQUASHFS_INSWAP_COMP_OPTS(s) { \
(s)->compression_level = inswap_le32((s)->compression_level); \
(s)->rsyncable = inswap_le32((s)->rsyncable); \
}
#else
#define SQUASHFS_INSWAP_COMP_OPTS(s)
Expand All @@ -38,5 +39,6 @@ extern unsigned int inswap_le32(unsigned int);

struct zstd_comp_opts {
int compression_level;
int rsyncable;
};
#endif