mksquashfs: write_inode_lookup_table(), remove redundant initialisation of inode

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: sort_directory(), silence bogus cur NULL pointer dereference

Static analysis reports a cur NULL pointer dereference
at the cur->next=NULL line.

This is because static analysis is too stupid to realise we'll
always go around the loop at least once, assigning cur, iff
dir->count > 1, which is checked for.  In otherwords it does
not correlate dir->count > 1 with the fact dir->list will always
be non NULL.

Even though it is strictly unnecessary, it is easily to silence
static analysers by checking for dir->list == NULL as well as
dir->count > 1.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs: remove_free_list(), silence bogus NULL pointer dereference

Static analysis reports a NULL pointer dereference in
remove_free_list().

This is because static analysis is too stupid to realise
if free_prev and free_next are both not NULL, then both
pointers are guaranteed to contain values.  It instead
determines a not checked for situation where one pointer can
contain a value and the other contains NULL, and flags this
as a potential NULL pointer dereference, even though this
situation cannot occur.

Even though it is strictly unnecessary, it is easily to silence
static analysers by changing the check to be free_prev == NULL ||
free_next == NULL.  The fact being it is sufficient for either
pointer to be NULL to know we have an empty list.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
action: free parse tree on SYNTAX_ERROR

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
action: parse_file_arg(), fix memory leak on TEST_SYNTAX_ERROR()

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
read_fs: scan_inode_table(), fix memory leak on filesystem corruption

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
pseudo: add_pseudo(), fix use of freed variable

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
action: fix leak of stdup'ed value in SYNTAX_ERROR()

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
action: fix leak of stdup'ed value in TEST_SYNTAX_ERROR()

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: exclude files, fix handling of leaf name

If a pathname ended in "/" (i.e. "a/b/c/") the last pathname
component would not be recognised as a leaf name.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
unsquashfs: extract files, fix handling of leaf name

If a pathname ended in "/" (i.e. "a/b/c/") the last pathname
component would not be recognised as a leaf name.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: pseudo files, fix handling of leaf name

If a pathname ended in "/" (i.e. "a/b/c/") the last pathname
component would not be recognised as a leaf name.

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

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
pseudo: fix pseudo definition dumping and actually call it

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
action: only dump actions if SQUASHFS_TRACE defined

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
pseudo: only dump pseudos if SQUASHFS_TRACE defined

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
info: fix missing ')' in queue and cache dump

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: update date

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: rewrite default queue size code so it is based on physical memory

For many years Mksquashfs has used fixed size default queues.
This has made choosing a *usable* default set of queue sizes impossible
because, obviously, I have no idea what size physical memory
people have in their machines, or what what amount of memory they
want Mksquashfs to use by default.

Choose a too large set of queues, and this means Mksquashfs won't
be able to be used on machines with smaller RAM, and/or it
will go into swap and suffer extremely poor performance.

Choose a too small set of queues, and we don't maximise Mksquashfs
performance by using the available RAM on machines with lots
of memory.

My original decision was to choose an extremely conservative set of
queues, only 64Mbytes for Read-Queue and Fragment-Queue, and 512Mbytes
for the Write-Queue which because the writer thread is never the
bottleneck is not expected to grow beyond ~20% of the maximum.  So
a total queue size of less than 256Mbytes, which was conservative
when I made my estimate of the "usable RAM in a typical machine" in
2006 where I anticipated the typical machine might have 2Gbytes of RAM.
It is now rediculously small.

My expectation was most people would see that the defaults were
(deliberately) made small, and use the -XXX-queue options to increase
the queue sizes to something more usable.  This AFAIK has not
happened.  People just run Mksquashfs, and as if by magic, they expect
Mksquashfs to just use the right amount of memory.

One reason for this I suspect, is that I made a major mistake in
presenting 3 raw queue-size options to the user.  Most people have
no idea what the queues are, and have no idea what the right ratio is
between the 3 queue sizes... and obviously think changing them
"ramdomly" will break Mksquashfs and just leave well alone.

The moral of the story is if you expect/hope people will increase the
memory used by Mksquashfs, then make sure you give them options
they will understand.... and if they don't change the options make
sure your default memory size is at least sensible for their
machine.  I failed twice last time.

This commit is step 2.  Base the default queue sizes on the amount of
physical memory.  In this I have choosen to use a 1/4 of physical memory.
Any more than this and we can't guarantee we'll hit memory pressure on a
loaded machine, anything less than this, and we get back to the silly
amount of memory usage issue.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: add a new -mem <mbytes> option

Add a new -mem <mbytes> option, that sets the amount of memory
Mksquashfs uses to <mbytes>.  Internally, the <mbytes> is distributed
amongst the four caches: reader cache, fragment cache, block writer cache,
and fragment writer cache in an optimal ratio, as is already done
when deciding how to allocate the default physical memory amongst the
caches.

This option is intended to be much more understandable than the
previous -read-queue, -fragment-queue and -write-queue options, such
that people might actually use this option (whereas it is clear
nobody used the previous options, as they were evidently too difficult
to understand).

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