action: chmod: fix mode setting if octal value specified for mode

The set code incorrectly did (st_mode & ~S_IFMT) | mode, which is the
exact inverse of what it should have been, i.e.  (st_mode & S_IFMT) | mode

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
action: change expression logging to use atom->args

Previously it used atom->test->args which is the arg count in the "generic"
test function.

Now that test function parsing has been improved to add variable arguments,
we should be using the new atom->args field which is the number of actual
arguments in the particular parsed test - i.e. the instance rather than
the definition.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: change expression logging to not print brackets if test has no arguments

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
actions: add new noop action

This action does exactly what it says, i.e. nothing.

It's designed to be used in conjunction with the verbose action
options to enable debugging of the test expression.

In otherwords, it allows you to check which files match on
your test expression but without doing anything to the filesystem.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: fix progressbar for sort files

The progressbar was incorrectly enabled *after* writing files
if sort files were used.  This meant the progressbar would not
be updated whilst files were being written to the filesystem.

As this is the bulk of the work for Mksquashfs, this means
the progressbar basically didn't appear to update whilst
Mksquashfs was running, and then suddenly updated to 100%
at the end of Mksquashfs.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
mksquashfs: fix rare race in fragment waiting in filesystem finalisation

Fix a rare race condition in fragment waiting when finalising the
filesystem.  This is a race condition that was initially fixed in 2009,
but inadvertantly re-introduced in the latest release when the code
was rewritten.

Background:

When finalising the filesystem, the main control thread needs to ensure
all the in-flight fragments have been queued to the writer thread before
asking the writer thread to finish, and then writing the metadata.

It does this by waiting on the fragments_outstanding counter.  Once this
counter reaches 0, it synchronises with the writer thread, waiting until
the writer thread reports no outstanding data to be written.

However, the main thread can race with the fragment deflator thread(s)
because the fragment deflator thread(s) decrement the fragments_outstanding
counter and release the mutex before queueing the compressed fragment
to the writer thread, i.e. the offending code is:

                        fragments_outstanding --;
                        pthread_mutex_unlock(&fragment_mutex);
                        queue_put(to_writer, write_buffer);

In extremely rare circumstances, the main thread may see the
fragments_outstanding counter is zero before the fragment
deflator sends the fragment buffer to the writer thread, and synchronise
with the writer thread, and finalise before the fragment has been written.

The fix is to ensure the fragment is queued to the writer thread
before releasing the mutex.

Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Fix 2GB-limit of the is_fragment(...) function.

Applies to squashfs-tools 4.3.

Reported-by: Bruno Wolff III <bruno@wolff.to>
Signed-off-by: Guan, Xin <guanx.bac@gmail.com>
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>