aboutsummaryrefslogtreecommitdiff
path: root/squashfs-tools
diff options
context:
space:
mode:
authorPhillip Lougher <phillip@squashfs.org.uk>2013-02-03 13:24:20 +0000
committerPhillip Lougher <phillip@squashfs.org.uk>2013-02-03 13:25:24 +0000
commit68d3828fb006503c5a4cbf437113fdc857788d55 (patch)
tree64ce83e152666d4c563b85fc40d916c4f7baca82 /squashfs-tools
parentfb527f0edf783e34233fe7440e188d430790c6cd (diff)
downloadsquashfs-tools-68d3828fb006503c5a4cbf437113fdc857788d55.tar.gz
unsquashfs: add support for displaying compression options
Add support to display the compression options used to compress the filesystem in -stat. Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Diffstat (limited to 'squashfs-tools')
-rw-r--r--squashfs-tools/compressor.h9
-rw-r--r--squashfs-tools/unsquashfs.c16
-rw-r--r--squashfs-tools/xz_wrapper.c52
3 files changed, 76 insertions, 1 deletions
diff --git a/squashfs-tools/compressor.h b/squashfs-tools/compressor.h
index 4679850..dba6d56 100644
--- a/squashfs-tools/compressor.h
+++ b/squashfs-tools/compressor.h
@@ -31,6 +31,7 @@ struct compressor {
int (*options_post)(int);
void *(*dump_options)(int, int *);
int (*extract_options)(int, void *, int);
+ void (*display_options)(void *, int);
void (*usage)();
};
@@ -101,3 +102,11 @@ static inline int compressor_extract_options(struct compressor *comp,
return size ? -1 : 0;
return comp->extract_options(block_size, buffer, size);
}
+
+
+static inline void compressor_display_options(struct compressor *comp,
+ void *buffer, int size)
+{
+ if(comp->display_options != NULL)
+ comp->display_options(buffer, size);
+}
diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
index 2a0ee0b..f599d74 100644
--- a/squashfs-tools/unsquashfs.c
+++ b/squashfs-tools/unsquashfs.c
@@ -1599,9 +1599,23 @@ void squashfs_stat(char *source)
sBlk.s.bytes_used / 1024.0, sBlk.s.bytes_used /
(1024.0 * 1024.0));
- if(sBlk.s.s_major == 4)
+ if(sBlk.s.s_major == 4) {
printf("Compression %s\n", comp->name);
+ if(SQUASHFS_COMP_OPTS(sBlk.s.flags)) {
+ char buffer[SQUASHFS_METADATA_SIZE];
+ int bytes;
+
+ bytes = read_block(fd, sizeof(sBlk.s), NULL, 0, buffer);
+ if(bytes == 0) {
+ ERROR("Failed to read compressor options\n");
+ return;
+ }
+
+ compressor_display_options(comp, buffer, bytes);
+ }
+ }
+
printf("Block size %d\n", sBlk.s.block_size);
printf("Filesystem is %sexportable via NFS\n",
SQUASHFS_EXPORTABLE(sBlk.s.flags) ? "" : "not ");
diff --git a/squashfs-tools/xz_wrapper.c b/squashfs-tools/xz_wrapper.c
index 8c2ab1c..44dfada 100644
--- a/squashfs-tools/xz_wrapper.c
+++ b/squashfs-tools/xz_wrapper.c
@@ -322,6 +322,57 @@ failed:
}
+void xz_display_options(void *buffer, int size)
+{
+ struct comp_opts *comp_opts = buffer;
+ int dictionary_size, flags, printed;
+ int i, n;
+
+ /* check passed comp opts struct is of the correct length */
+ if(size != sizeof(comp_opts))
+ goto failed;
+
+ SQUASHFS_INSWAP_COMP_OPTS(comp_opts);
+
+ dictionary_size = comp_opts->dictionary_size;
+ flags = comp_opts->flags;
+
+ /*
+ * check that the dictionary size seems correct - the dictionary
+ * size should 2^n or 2^n+2^(n+1)
+ */
+ n = ffs(dictionary_size) - 1;
+ if(dictionary_size != (1 << n) &&
+ dictionary_size != ((1 << n) + (1 << (n + 1))))
+ goto failed;
+
+ printf("\tDictionary size %d\n", dictionary_size);
+
+ printed = 0;
+ for(i = 0; bcj[i].name; i++) {
+ if((flags >> i) & 1) {
+ if(printed)
+ printf(", ");
+ else
+ printf("\tFilters selected: ");
+ printf("%s", bcj[i].name);
+ printed = 1;
+ }
+ }
+
+ if(!printed)
+ printf("\tNo filters specified\n");
+ else
+ printf("\n");
+
+ return;
+
+failed:
+ fprintf(stderr, "xz: error reading stored compressor options from "
+ "filesystem!\n");
+}
+
+
/*
* This function is called by mksquashfs to initialise the
* compressor, before compress() is called.
@@ -477,6 +528,7 @@ struct compressor xz_comp_ops = {
.options_post = xz_options_post,
.dump_options = xz_dump_options,
.extract_options = xz_extract_options,
+ .display_options = xz_display_options,
.usage = xz_usage,
.id = XZ_COMPRESSION,
.name = "xz",