read_fs.c: fix missing space in ERROR message

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
compressor: Update comment referring to XZ implementation

Update the comment which states that the XZ compressor is the only
compressors that uses the compression options framework.  This
is no longer the case.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
lzo_wrapper.c: fix missing space in ERROR message

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
lzo_wrapper.c: fix missing tab in compression options display

Unsquashfs -stat dumps the algorithm selected using the
compression options display function.  If the compression
algorithm was not lzo1x_999, then the algorithm line was
incorrectly displayed without a leading tab.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
lzo_wrapper.c: improve -Xlzo_algo error messages

The lzo algorithms are quite easy to misspell, so when the
alogorthm is unrecognised, or is missing, display the list of
algorithms accepted.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
lzo_wrapper.c: improve -Xcompression_level error message

If the compression level is missing then display the compression
levels accepted.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
lzo_wrapper.c: fix URL

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
compressor: don't overload extract_options

When I added LZ4 support, I realised that Unsquashfs should
check the compression options (if any) to ensure that the decompressor
can decompress the filesystem.

This situation never occurred before because gzip and lzo doesn't
have any options, and I envisaged that xz will always implicitly be able
to *decompress* any filesystem irrespective of any hitherto unimplemented
compression features.  In otherwords I anticipated we should check the
options in mksquashfs (on append), but not on decompression with
unsquashfs.

LZ4 changed that because the kernel is currently using the LZ4
legacy format, and this may change, creating a situation where in
the future there may be a new format, which is *not* currently understood.
Therefore Unsquashfs needs to check the options too.

I initially used extract_options(), but this has thrown up subtle
differences in the handling of compression options between unsquashfs
and mksquashfs.  Specificallyx, in the handling of the presence of
compression options where the compressor hasn't got an extract_options
function.  This is clear indication that the filesystem is newer than
the code because it has compression options whereas the code hasn't
any support for them.

Now in mksquashfs where it is appending to the filesystem, this is a
definate fail because we obviously cannot extract the options and
set the compressor to the appropriate state.  But, this should not
be a fail for Unsquashfs, because in retro-fitting compression
options to a compressor which didn't originally have them (i.e. LZO),
we have to ensure that the new compression options are implicitly
decompressible by the original code, because the original code
doesn't check them.

So for instance with LZO, we cannot allow an old Mksquashfs to append
to an LZO filesystem compressed with the new compression options, but,
it is perfectly possible for an old version of Unsquashfs to decompress
this filesystem.

So don't overload extract_options, and instead introduce a new
check_options specifically for Unsquashfs, and specifically only
for the decompressors (LZ4) which need to check them.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
lzo_wrapper: Rename -Xlzo_algo option to -Xalgorithm

The compression specific options are directed to the
appropriate compressor using the -comp option, so the
lzo part of lzo_algorithm is unnecessary and redundant.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Update dates

Have not updated the version dates for a long time.  There's
been a couple of improvements since then.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
lzo_wrapper: Rename compression_option to compression-option

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
lzo_wrapper: Use SQUASHFS_LZO1X_999_COMP_DEFAULT rather than hard-coded const

In lzo_usage() where the default compression level for
LZO1X_999 compressed streams is printed, use
SQUASHFS_LZO1X_999_COMP_DEFAULT rather than the hard-coded constant.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs/read_fs: Always_use_fragments should be Always-use-fragments

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
gzip_wrapper: significantly improved implementation

Siginficantly improve the gzip compressor implementation
by adding support for two new compression options:

	-Xcompression-level <compression-level>
		<compression-level> should be 1 .. 9 (default 9)

	-Xwindow-size <window-size>
		<window-size> should be 8 .. 15 (default 15)

These two options allow the level of compression and window
size to be changed.  Changing these can improve compression
speed and/or compression time memory requirements.

The defaults match the original unchangable compression parameters
used previously.  These defaults represent maximum gzip compression
(at the expense of compresion speed and memory overhead), and so
alterring them will reduce compression achieved.

However, there are times where reduced compressed is desireable:

	- times where the build time for experimental images is
	  paramount
	- times where the build and/or target system is relatively weak,
	  and so will benefit from less aggressive compression
	  parameters.

It may well be the case that lower compression levels for gzip may
give better results than higher compression levels for algorithms which
are believed to be less demanding.

As usual, experimentation is the key to discovering which compression
algorithm and compression options are the best for your application.

Note: gzip compressed filesystems with the new options are
compatible with all earlier Squashfs implementations (kernel and unsquashfs),
back to the first release of Squashfs 4.0 in early 2009.

The only exception is appending: earlier versions of Mksquashfs will
*correctly* refuse to append to a gzipped filesystem created with the
above new compression options because it is unable to set the compression
options (i.e. it will use the unchangable default compression
parameters).

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: redo -comp <compressor> parsing

Previously, -X compression options were only supported by
xz, a non-default compressor.

This led to a perfectly acceptable parsing and error
message reporting strategy where -comp xz was needed to
be specified first on the command line - the -X options were
not understood by the default gzip compressor, and so Mksquashfs
needed -comp xz specified first to switch to the appropriate
compressor.

i.e.

phillip@ravolox:/tmp$ mksquashfs xxx xxx.sqsh -Xdict-size 8192 -comp xz
mksquashfs: Unrecognised compressor option -Xdict-size
mksquashfs: Did you forget to specify -comp, or specify it after the compressor specific option?

An acceptable error message saying -comp xz should be specified
first.  Despite the fact it implies a limitation in the parser such
that the appropriate compressor cannot be identified before parsing
the -X options.

But it led to some silly error messages too

phillip@ravolox:/tmp$ mksquashfs xxx xxx.sqsh -comp xz -Xdict-sze 8192
mksquashfs: Unrecognised compressor option -Xdict-sze
mksquashfs: Did you forget to specify -comp, or specify it after the compressor specific option?

The cause of the failure is the mistyping of the xz specific
compressor option, but it still assumes the cause of the failure
is the lack of an appropriate -comp xz first.

Again, repeated -comp xz's generate a misleading error message

phillip@ravolox:/tmp$ mksquashfs xxx xxx.sqsh -comp xz -Xdict-size 8192 -comp xz
mksquashfs: -comp must appear before -X options

The introduction of compression options for the default gzip compressor
exacerbates such misleading error messages.

phillip@ravolox:/tmp$ mksquashfs xxx xxx.sqsh -Xcompresson-level 6
mksquashfs: Unrecognised compressor option -Xcompresson-level
mksquashfs: Did you forget to specify -comp, or specify it after the compressor specific option?

The mistyping of the default compressor -Xcompression-level option
causes the error message did you specify -comp gzip after the
compressor specific option, when no such option is necessary, because
it's the default compressor.

Again, giving the -comp gzip option after the -X option ...

phillip@ravolox:/tmp$ mksquashfs xxx xxx.sqsh -Xcompression-level 6 -comp gzip
mksquashfs: -comp must appear before -X options

gives the misleading error message that -comp gzip should be specified
before -Xcompression-level, which is completely wrong, as
-Xcompression-level can be given before any -comp because it is
a compression option for the default compressor.

In short, the stateful -comp where it must appear before any
-X compression options previously caused some odd error messages,
but it is anticipated it will cause even more odd behaviour now
that compression options are understood by the default compressor.

So, remove the need to have -comp specified before any -X option, and allow
it to be specified anywhere.  Thereby removing the dependency and
the misleading error messages in one go.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: display compressor options when -X option is not recognised

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: add -Xhelp option

add -Xhelp option which prints the compressor options
for the selected compressor.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs/unsquashfs: fix mtime signedness

Since time-immemorial Squashfs has treated mtime as unsigned.
This is a bug, mtime is signed, and dates previous to the
epoch of 1 Jan 1970 should be treated negatively.

This bug does not affect mksquashfs, as it stores the mtime
in the filesystem correctly.  Unsquashfs, however, treats
mtime as unsigned, and it will report (-lls) and
set any file with a timestamp before the epoch incorrectly.

This is easily fixed by changing the definition of mtime
(and mkfs_time) to be "int" rather than "unsigned int".
Because the signedness is changing, the swap code also
has to be undated.

Reported-by: socketpair@gmail.com
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs: fix mtime signedness for legacy layouts

Since time-immemorial Squashfs has treated mtime as unsigned.
This is a bug, mtime is signed, and dates previous to the
epoch of 1 Jan 1970 should be treated negatively.

This bug has never affected Mksquashfs, and so there is a small but
unlikely possibility that there can exist legacy Squashfs filesystems
with timestamps prior to the epoch.

Due to this, This commit fixes mtime signedness for the legacy
1.x, 2.x and 3.x layouts, so negative mtime is correctly handled by
Unsquashfs.

Note the legacy swapping code does not have to be updated
because it never interprets signedness of the data.

signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>