Exemple #1
0
/*
 * This function is called by mksquashfs to dump the parsed
 * compressor options in a format suitable for writing to the
 * compressor options field in the filesystem (stored immediately
 * after the superblock).
 *
 * This function returns a pointer to the compression options structure
 * to be stored (and the size), or NULL if there are no compression
 * options
 *
 */
static void *gzip_dump_options(int block_size, int *size)
{
	static struct gzip_comp_opts comp_opts;
	int i, strategies = 0;

	/*
	 * If default compression options of:
	 * compression-level: 8 and
	 * window-size: 15 and
	 * strategy_count == 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)
		return NULL;

	for(i = 0; strategy[i].name; i++)
		strategies |= strategy[i].selected << i;

	comp_opts.compression_level = compression_level;
	comp_opts.window_size = window_size;
	comp_opts.strategy = strategies;

	SQUASHFS_INSWAP_COMP_OPTS(&comp_opts);

	*size = sizeof(comp_opts);
	return &comp_opts;
}
static void zstd_display_options(void *buffer, int size)
{
	struct zstd_comp_opts *comp_opts = buffer;

	/* we expect a comp_opts structure of sufficient size to be present */
	if (size < sizeof(*comp_opts))
		goto failed;

	SQUASHFS_INSWAP_COMP_OPTS(comp_opts);

	if (comp_opts->compression_level < 1 ||
	    comp_opts->compression_level > ZSTD_maxCLevel()) {
		fprintf(stderr, "zstd: bad compression level in compression "
			"options structure\n");
		goto failed;
	}

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

	return;

failed:
	fprintf(stderr, "zstd: error reading stored compressor options from "
		"filesystem!\n");
}
/*
 * This function is a helper specifically for the append mode of
 * mksquashfs.  Its purpose is to set the internal compressor state
 * to the stored compressor options in the passed compressor options
 * structure.
 *
 * In effect this function sets up the compressor options
 * to the same state they were when the filesystem was originally
 * generated, this is to ensure on appending, the compressor uses
 * the same compression options that were used to generate the
 * original filesystem.
 *
 * Note, even if there are no compressor options, this function is still
 * called with an empty compressor structure (size == 0), to explicitly
 * set the default options, this is to ensure any user supplied
 * -X options on the appending mksquashfs command line are over-ridden.
 *
 * This function returns 0 on sucessful extraction of options, and -1 on error.
 */
static int zstd_extract_options(int block_size, void *buffer, int size)
{
	struct zstd_comp_opts *comp_opts = buffer;

	if (size == 0) {
		/* Set default values */
		compression_level = ZSTD_DEFAULT_COMPRESSION_LEVEL;
		return 0;
	}

	/* we expect a comp_opts structure of sufficient size to be present */
	if (size < sizeof(*comp_opts))
		goto failed;

	SQUASHFS_INSWAP_COMP_OPTS(comp_opts);

	if (comp_opts->compression_level < 1 ||
	    comp_opts->compression_level > ZSTD_maxCLevel()) {
		fprintf(stderr, "zstd: bad compression level in compression "
			"options structure\n");
		goto failed;
	}

	compression_level = comp_opts->compression_level;

	return 0;

failed:
	fprintf(stderr, "zstd: error reading stored compressor options from "
		"filesystem!\n");

	return -1;
}
Exemple #4
0
void lz4_display_options(void *buffer, int size)
{
	struct lz4_comp_opts *comp_opts = buffer;

	/* check passed comp opts struct is of the correct length */
	if(size < sizeof(*comp_opts))
		goto failed;

	SQUASHFS_INSWAP_COMP_OPTS(comp_opts);

	/* we expect the stream format to be LZ4_LEGACY */
	if(comp_opts->version != LZ4_LEGACY) {
		fprintf(stderr, "lz4: unknown LZ4 version\n");
		goto failed;
	}

	/*
	 * Check compression flags, currently only LZ4_HC ("high compression")
	 * can be set.
	 */
	if(comp_opts->flags & ~LZ4_FLAGS_MASK) {
		fprintf(stderr, "lz4: unknown LZ4 flags\n");
		goto failed;
	}

	if(comp_opts->flags & LZ4_HC)
		printf("\tHigh Compression option specified (-Xhc)\n");

	return;

failed:
	fprintf(stderr, "lz4: error reading stored compressor options from "
		"filesystem!\n");
}	
Exemple #5
0
/*
 * This function is a helper specifically for the append mode of
 * mksquashfs.  Its purpose is to set the internal compressor state
 * to the stored compressor options in the passed compressor options
 * structure.
 *
 * In effect this function sets up the compressor options
 * to the same state they were when the filesystem was originally
 * generated, this is to ensure on appending, the compressor uses
 * the same compression options that were used to generate the
 * original filesystem.
 *
 * Note, even if there are no compressor options, this function is still
 * called with an empty compressor structure (size == 0), to explicitly
 * set the default options, this is to ensure any user supplied
 * -X options on the appending mksquashfs command line are over-ridden
 *
 * This function returns 0 on sucessful extraction of options, and
 *			-1 on error
 */
static int lz4_extract_options(int block_size, void *buffer, int size)
{
	struct lz4_comp_opts *comp_opts = buffer;

	/* we expect a comp_opts structure to be present */
	if(size < sizeof(*comp_opts))
		goto failed;

	SQUASHFS_INSWAP_COMP_OPTS(comp_opts);

	/* we expect the stream format to be LZ4_LEGACY */
	if(comp_opts->version != LZ4_LEGACY) {
		fprintf(stderr, "lz4: unknown LZ4 version\n");
		goto failed;
	}

	/*
	 * Check compression flags, currently only LZ4_HC ("high compression")
	 * can be set.
	 */
	if(comp_opts->flags == LZ4_HC)
		hc = 1;
	else if(comp_opts->flags != 0) {
		fprintf(stderr, "lz4: unknown LZ4 flags\n");
		goto failed;
	}

	return 0;

failed:
	fprintf(stderr, "lz4: error reading stored compressor options from "
		"filesystem!\n");

	return -1;
}
Exemple #6
0
/*
 * This function is called by mksquashfs to dump the parsed
 * compressor options in a format suitable for writing to the
 * compressor options field in the filesystem (stored immediately
 * after the superblock).
 *
 * This function returns a pointer to the compression options structure
 * to be stored (and the size), or NULL if there are no compression
 * options
 *
 * Currently LZ4 always returns a comp_opts structure, with
 * the version indicating LZ4_LEGACY stream fomat.  This is to
 * easily accomodate changes in the kernel code to different
 * stream formats 
 */
static void *lz4_dump_options(int block_size, int *size)
{
	static struct lz4_comp_opts comp_opts;

	comp_opts.version = LZ4_LEGACY;
	comp_opts.flags = hc ? LZ4_HC : 0;
	SQUASHFS_INSWAP_COMP_OPTS(&comp_opts);

	*size = sizeof(comp_opts);
	return &comp_opts;
}
/*
 * This function is called by mksquashfs to dump the parsed
 * compressor options in a format suitable for writing to the
 * compressor options field in the filesystem (stored immediately
 * after the superblock).
 *
 * This function returns a pointer to the compression options structure
 * to be stored (and the size), or NULL if there are no compression
 * options.
 */
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)
		return NULL;

	comp_opts.compression_level = compression_level;

	SQUASHFS_INSWAP_COMP_OPTS(&comp_opts);

	*size = sizeof(comp_opts);
	return &comp_opts;
}
Exemple #8
0
/*
 * This function is a helper specifically for the append mode of
 * mksquashfs.  Its purpose is to set the internal compressor state
 * to the stored compressor options in the passed compressor options
 * structure.
 *
 * In effect this function sets up the compressor options
 * to the same state they were when the filesystem was originally
 * generated, this is to ensure on appending, the compressor uses
 * the same compression options that were used to generate the
 * original filesystem.
 *
 * Note, even if there are no compressor options, this function is still
 * called with an empty compressor structure (size == 0), to explicitly
 * set the default options, this is to ensure any user supplied
 * -X options on the appending mksquashfs command line are over-ridden
 *
 * This function returns 0 on sucessful extraction of options, and
 *			-1 on error
 */
static int gzip_extract_options(int block_size, void *buffer, int size)
{
	struct gzip_comp_opts *comp_opts = buffer;
	int i;

	if(size == 0) {
		/* Set default values */
		compression_level = GZIP_DEFAULT_COMPRESSION_LEVEL;
		window_size = GZIP_DEFAULT_WINDOW_SIZE;
		strategy_count = 0;
		return 0;
	}

	/* we expect a comp_opts structure of sufficient size to be present */
	if(size < sizeof(*comp_opts))
		goto failed;

	SQUASHFS_INSWAP_COMP_OPTS(comp_opts);

	/* Check comp_opts structure for correctness */
	if(comp_opts->compression_level < 1 ||
			comp_opts->compression_level > 9) {
		fprintf(stderr, "gzip: bad compression level in "
			"compression options structure\n");
		goto failed;
	}
	compression_level = comp_opts->compression_level;

	if(comp_opts->window_size < 8 ||
			comp_opts->window_size > 15) {
		fprintf(stderr, "gzip: bad window size in "
			"compression options structure\n");
		goto failed;
	}
	window_size = comp_opts->window_size;

	strategy_count = 0;
	for(i = 0; strategy[i].name; i++) {
		if((comp_opts->strategy >> i) & 1) {
			strategy[i].selected = 1;
			strategy_count ++;
		} else
			strategy[i].selected = 0;
	}
Exemple #9
0
/*
 * This function is a helper specifically for unsquashfs.
 * Its purpose is to check that the compression options are
 * understood by this version of LZ4.
 *
 * This is important for LZ4 because the format understood by the
 * Linux kernel may change from the already obsolete legacy format
 * currently supported.
 *
 * If this does happen, then this version of LZ4 will not be able to decode
 * the newer format.  So we need to check for this.
 *
 * This function returns 0 on sucessful checking of options, and
 *			-1 on error
 */
static int lz4_check_options(int block_size, void *buffer, int size)
{
	struct lz4_comp_opts *comp_opts = buffer;

	/* we expect a comp_opts structure to be present */
	if(size < sizeof(*comp_opts))
		goto failed;

	SQUASHFS_INSWAP_COMP_OPTS(comp_opts);

	/* we expect the stream format to be LZ4_LEGACY */
	if(comp_opts->version != LZ4_LEGACY) {
		fprintf(stderr, "lz4: unknown LZ4 version\n");
		goto failed;
	}

	return 0;

failed:
	fprintf(stderr, "lz4: error reading stored compressor options from "
		"filesystem!\n");
	return -1;
}