From 30e8abe86cc604672dff3896cdea2a75ed622a4f Mon Sep 17 00:00:00 2001
From: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Date: Thu, 24 Sep 2020 20:19:52 +0200
Subject: Update tar2sqfs/sqfs2tar documentation

Modify the man pages and help texts to mention compression support, make
the help option display a list of supported compressors.

Also clarify the squashfs compressor list in the help text to state that
the list shows block compressors supported for SquashFS compression.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
---
 bin/sqfs2tar/options.c  |  8 +-------
 bin/sqfs2tar/sqfs2tar.1 | 21 +++++++++++++++++----
 bin/tar2sqfs/options.c  | 30 ++++++++++++++++++++++--------
 bin/tar2sqfs/tar2sqfs.1 | 26 +++++++++++++-------------
 lib/common/compress.c   | 21 +++++++++++++++------
 5 files changed, 68 insertions(+), 38 deletions(-)

diff --git a/bin/sqfs2tar/options.c b/bin/sqfs2tar/options.c
index 356913a..a84fcd4 100644
--- a/bin/sqfs2tar/options.c
+++ b/bin/sqfs2tar/options.c
@@ -62,13 +62,7 @@ static const char *usagestr =
 "  --help, -h                Print help text and exit.\n"
 "  --version, -V             Print version information and exit.\n"
 "\n"
-"Examples:\n"
-"\n"
-"\tsqfs2tar rootfs.sqfs > rootfs.tar\n"
-"\tsqfs2tar rootfs.sqfs | gzip > rootfs.tar.gz\n"
-"\tsqfs2tar rootfs.sqfs | xz > rootfs.tar.xz\n"
-"\n"
-"Available compressors:\n";
+"Supported tar compression formats:\n";
 
 bool dont_skip = false;
 bool keep_as_dir = false;
diff --git a/bin/sqfs2tar/sqfs2tar.1 b/bin/sqfs2tar/sqfs2tar.1
index 0fc69f6..be79312 100644
--- a/bin/sqfs2tar/sqfs2tar.1
+++ b/bin/sqfs2tar/sqfs2tar.1
@@ -11,6 +11,13 @@ archives. The resulting archive is written to stdout.
 .PP
 Possible options:
 .TP
+\fB\-\-compressor\fR, \fB\-c\fR <name>
+By default the result is a raw, uncompressed tar ball. Using this option
+it is possible to select a stream compression format (such as \fBgzip\fR,
+\fBxz\fR, \fBzstd\fR or \fBbzip2\fR) to use for the output archive.
+
+Run \fBsqfs2tar \-\-help\fR to get a list of all available compressors.
+.TP
 \fB\-\-root\-becomes\fR, \fB\-r\fR <dir>
 Prefix all paths in the tarball with the given directory name and add an
 entry for this directory that receives all meta data (permissions, ownership,
@@ -69,18 +76,24 @@ Since the tar format contains a sequence of files with absolute names, it has
 no direct concept of a tree or an unnamed root node. Consequently, meta data
 from the SquashFS root inode is lost, unless the \fB\-\-root\-becomes\fR option
 is used.
+
+The output archive can optionally be compressed. Default settings are used for
+the supported compressors and there is currently no intention to expose finer
+grained control over them. To set custom compressor flags, create an
+uncompressed archive and pipe it into a dedicated compressor process.
+
 .SH EXAMPLES
 Turn a SquashFS image into a tar archive:
 .IP
 sqfs2tar rootfs.sqfs > rootfs.tar
 .TP
-Turn a SquashFS image into a gzip'ed tar archive:
+Creating a compressed archive with gzip headers:
 .IP
-sqfs2tar rootfs.sqfs | gzip > rootfs.tar.gz
+sqfs2tar --compressor gzip rootfs.sqfs > rootfs.tar.gz
 .TP
-Turn a SquashFS image into an LZMA2 compressed tar archive:
+Compressing the output archive, but using custom compressor flags:
 .IP
-sqfs2tar rootfs.sqfs | xz > rootfs.tar.xz
+sqfs2tar rootfs.sqfs | xz -9e > rootfs.tar.xz
 .SH SEE ALSO
 rdsquashfs(1), tar2sqfs(1)
 .SH AUTHOR
diff --git a/bin/tar2sqfs/options.c b/bin/tar2sqfs/options.c
index 19017a9..b631a1e 100644
--- a/bin/tar2sqfs/options.c
+++ b/bin/tar2sqfs/options.c
@@ -32,8 +32,7 @@ static const char *short_opts = "r:c:b:B:d:X:j:Q:sxekfqThV";
 static const char *usagestr =
 "Usage: tar2sqfs [OPTIONS...] <sqfsfile>\n"
 "\n"
-"Read an uncompressed tar archive from stdin and turn it into a squashfs\n"
-"filesystem image.\n"
+"Read a tar archive from stdin and turn it into a squashfs filesystem image.\n"
 "\n"
 "Possible options:\n"
 "\n"
@@ -79,12 +78,6 @@ static const char *usagestr =
 "  --quiet, -q                 Do not print out progress reports.\n"
 "  --help, -h                  Print help text and exit.\n"
 "  --version, -V               Print version information and exit.\n"
-"\n"
-"Examples:\n"
-"\n"
-"\ttar2sqfs rootfs.sqfs < rootfs.tar\n"
-"\tzcat rootfs.tar.gz | tar2sqfs rootfs.sqfs\n"
-"\txzcat rootfs.tar.xz | tar2sqfs rootfs.sqfs\n"
 "\n";
 
 bool dont_skip = false;
@@ -93,6 +86,26 @@ bool no_tail_pack = false;
 sqfs_writer_cfg_t cfg;
 char *root_becomes = NULL;
 
+static void input_compressor_print_available(void)
+{
+	int i = FSTREAM_COMPRESSOR_MIN;
+	const char *name;
+
+	fputs("\nSupported tar compression formats:\n", stdout);
+
+	while (i <= FSTREAM_COMPRESSOR_MAX) {
+		name = fstream_compressor_name_from_id(i);
+
+		if (fstream_compressor_exists(i))
+			printf("\t%s\n", name);
+
+		++i;
+	}
+
+	fputs("\tuncompressed\n", stdout);
+	fputc('\n', stdout);
+}
+
 void process_args(int argc, char **argv)
 {
 	bool have_compressor;
@@ -196,6 +209,7 @@ void process_args(int argc, char **argv)
 			printf(usagestr, SQFS_DEFAULT_BLOCK_SIZE,
 			       SQFS_DEVBLK_SIZE);
 			compressor_print_available();
+			input_compressor_print_available();
 			exit(EXIT_SUCCESS);
 		case 'V':
 			print_version("tar2sqfs");
diff --git a/bin/tar2sqfs/tar2sqfs.1 b/bin/tar2sqfs/tar2sqfs.1
index da344ec..300ab81 100644
--- a/bin/tar2sqfs/tar2sqfs.1
+++ b/bin/tar2sqfs/tar2sqfs.1
@@ -7,6 +7,9 @@ tar2sqfs \- create a SquashFS image from a tar archive
 .SH DESCRIPTION
 Quickly and painlessly turn a tar ball into a SquashFS filesystem image.
 .PP
+By default, the program reads the archive from standard input. Compressed
+archives are supported.
+.PP
 Possible options:
 .TP
 \fB\-\-root\-becomes\fR, \fB\-r\fR <dir>
@@ -107,12 +110,17 @@ Currently the program can process v7 format, pre-POSIX ustar, POSIX tar and GNU
 tar archives. PAX extension headers are also supported. Global PAX headers are
 ignored.
 
-The support for GNU tar is limited to commonly used subset (i.e. some legacy
+The support for GNU tar is limited to a commonly used subset (i.e. some legacy
 extensions that GNU tar itself no longer generates are not supported; neither
-are mutli volume archives).
+are multi volume archives).
+
+The input tar file can either be uncompressed, or stream compressed using
+\fBgzip\fR, \fBxz\fR, \fBzstd\fR or \fBbzip2\fR. The program transparently
+auto-detects and unpacks any stream compressed archive. The exact list of
+supported compressors depends on the compile configuration.
 
-Extended attributes are supported through the SCHILY.xattr PAX extension
-(favoured by GNU tar and star) or through the LIBARCHIVE.xattr PAX extension.
+Extended attributes are supported through the \fBSCHILY.xattr\fR extension
+(favoured by GNU tar and star) or through the \fBLIBARCHIVE.xattr\fR extension.
 
 If any unsupported section or extended attribute key is encountered in an
 archive, a warning message is written to stderr. If the \fB\-\-no\-skip\fR
@@ -133,15 +141,7 @@ environment variables.
 .TP
 Turn an uncompressed tar archive into a SquashFS image:
 .IP
-tar2sqfs rootfs.sqfs < rootfs.tar
-.TP
-Turn a gzip'ed tar archive into a SquashFS image:
-.IP
-zcat rootfs.tar.gz | tar2sqfs rootfs.sqfs
-.TP
-Turn an LZMA2 compressed tar archive into a SquashFS image:
-.IP
-xzcat rootfs.tar.xz | tar2sqfs rootfs.sqfs
+tar2sqfs rootfs.sqfs < rootfs.tar.gz
 .SH SEE ALSO
 gensquashfs(1), rdsquashfs(1), sqfs2tar(1)
 .SH AUTHOR
diff --git a/lib/common/compress.c b/lib/common/compress.c
index f16f080..9a66095 100644
--- a/lib/common/compress.c
+++ b/lib/common/compress.c
@@ -46,9 +46,12 @@ void compressor_print_available(void)
 	sqfs_compressor_config_t cfg;
 	sqfs_compressor_t *temp;
 	bool have_compressor;
-	int i, ret;
+	int i, ret, defcomp;
+	const char *name;
 
-	fputs("Available compressors:\n", stdout);
+	defcomp = compressor_get_default();
+
+	fputs("Available SquashFS block compressors:\n", stdout);
 
 	for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) {
 		sqfs_compressor_config_init(&cfg, i,
@@ -67,10 +70,16 @@ void compressor_print_available(void)
 #endif
 		}
 
-		if (have_compressor)
-			printf("\t%s\n", sqfs_compressor_name_from_id(i));
+		if (have_compressor) {
+			name = sqfs_compressor_name_from_id(i);
+
+			if (defcomp == i) {
+				printf("\t%s (default)\n", name);
+			} else {
+				printf("\t%s\n", name);
+			}
+		}
 	}
 
-	printf("\nDefault compressor: %s\n",
-	       sqfs_compressor_name_from_id(compressor_get_default()));
+	fputc('\n', stdout);
 }
-- 
cgit v1.2.3