Skip to content

Commit 6f61a5d

Browse files
committed
Support squashfs-tools-ng (might not work)
1 parent 4af837a commit 6f61a5d

File tree

3 files changed

+173
-19
lines changed

3 files changed

+173
-19
lines changed

ChangeLog

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# ChangeLog for squashmount
22

3+
*squashmount-20.0:
4+
Martin Väth <martin at mvath.de>:
5+
- Support https://github.com/AgentD/squashfs-tools-ng
6+
BEWARE: For me, this new tool does not work for unknown reasons:
7+
tar2sqfs produces files unreadable by the kernel or by unsquashfs
8+
(no matter whether squashfs-root is a parent directory), and
9+
sqfs2tar segfaults on files generated by mksquashfs.
10+
However, I added (untested) support for users without such problems.
11+
312
*squashmount-19.1:
413
Martin Väth <martin at mvath.de>:
514
- Introduce print-mtime

bin/squashmount

+159-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env perl
22
BEGIN { require 5.022 }
3-
package Squashmount v19.1.0;
3+
package Squashmount v20.0.0;
44

55
use strict;
66
use warnings;
@@ -730,6 +730,16 @@ so that this happens for all subsequent umounts/remounts.
730730
If used with B<status> or B<print*> act as if mount-point was correspondingly
731731
configured (without actually changing the configuration, of course).
732732

733+
=item B<--tar2sqfs> or B<--tar>
734+
735+
Use tar -> tar2sqfs for compression instead of squashfs.
736+
737+
=item B<--no-tar2sqfs>, B<--notar2sqfs>, B<--no-tar>, or B<--notar>
738+
739+
This is the opposite of B<--tar>.
740+
Whether B<--tar> or B<--no-tar> is the default depends on the
741+
variable B<$tar2sqfs> in F</etc/squashmount.pl>.
742+
733743
=item B<--compression=>I<mode>, B<--comp=>I<mode>, or B<-x> I<mode>
734744

735745
Override the value of B<COMPRESSION> for all specified mount-points.
@@ -1626,18 +1636,9 @@ If the number is bigger than 1, also the corresponding number of parent
16261636
directories (minus one) is removed (if nonempty). If the number is negative,
16271637
all parent directories are removed (if nonempty).
16281638

1629-
=item B<MKSQUASHFS>
1630-
1631-
This should be a (possibly empty) string or a reference to an array of strings:
1632-
These strings are used as additional options when calling B<mksquashfs>.
1633-
The option B<-noappend> is used automatically.
1634-
Depending on B<$squashfs_verbose>, B<COMPRESSION>, B<DEFAULT_FRAGMENTS>
1635-
also the options B<-no-progress>, B<-comp>, or B<-always-use-fragments>
1636-
are appended automatically.
1637-
16381639
=item B<MKSQUASHFS>, B<COMPOPT_{XZ,LZMA,GZIP,LZO,LZ4,ZSTD,}>
16391640

1640-
These should be a (possibly empty) strings or references arrays of strings:
1641+
These should be (possibly empty) strings or references to arrays of strings:
16411642
These strings are used as additional options when calling B<mksquashfs>
16421643
(the latter only if the corresponding B<COMPRESSION> option is used;
16431644
B<COMPOPT_> is used if B<COMPRESSION> is empty).
@@ -1660,6 +1661,38 @@ Set it to the empty string if you want fastest B<lz4> compression instead.
16601661

16611662
=back
16621663

1664+
=item B<TAR>
1665+
1666+
This should be a (possibly empty) string or a reference to an array of strings:
1667+
These strings are used as additional options when calling B<tar>
1668+
If the corresponding variable is not defined, it is assumed to be
1669+
B<--numeric-owner>.
1670+
1671+
=item B<TAR2SQFS>, B<COMPEXTRA_{XZ,LZMA,GZIP,LZO,LZ4,ZSTD,}>
1672+
1673+
These should be (possibly empty) strings or references to arrays of strings:
1674+
These strings are used as additional options when calling B<tar2sqfs>
1675+
(the latter only if the corresponding B<COMPRESSION> option is used;
1676+
B<COMPEXTRA_> is used if B<COMPRESSION> is empty).
1677+
The option B<-f> is used automatically.
1678+
Depending on B<COMPRESSION>, also the option B<-c> is appended automatically.
1679+
If the corresponding variable is not defined, it is assumed to be empty
1680+
with the following exception:
1681+
1682+
=over 16
1683+
1684+
=item b<TAR2SQFS>: If undefined, defaults to C<-q>.
1685+
Set it to the empty string if you want to see all files listed on compression
1686+
1687+
=item B<COMPEXTRA_ZSTD>: If undefined, defaults to C<'level=22'>.
1688+
Set it to the empty string if you want the fast B<zstd> compression default
1689+
used by tar2sqfs.
1690+
1691+
=item B<COMPEXTRA_LZ4>: If undefined, defaults to C<'hc'>.
1692+
Set it to the empty string if you want fastest B<lz4> compression instead.
1693+
1694+
=back
1695+
16631696
=item B<MOUNT_OVERLAY>
16641697

16651698
This should be a (possibly empty) string or a reference to an array of strings:
@@ -1745,7 +1778,7 @@ The available values depend on the installed version of B<mksquashfs>;
17451778
typically B<xz>, B<lzma>, B<gzip>, B<lzo>, B<lz4>, and B<zstd> are available
17461779
(ordered in increasing compression ratio, i.e. B<xz> is usually the slowest but
17471780
best in compression ratio while B<lz4> is the quickest; B<zstd> can be both,
1748-
depending on the value of B<COMPOPT_STD>, see above).
1781+
depending on the value of B<COMPOPT_STD> or B<COMPOPT_EXTRA>, see above).
17491782
If the value is empty, no B<-comp> parameter is passed,
17501783
that is, the default of the installed B<mksquashfs> is chosen
17511784
(which is usually B<gzip> but might depend on your version of B<mksquashfs>).
@@ -2514,6 +2547,7 @@ my $lsof_ro = undef;
25142547
my $opt_lsof_ro = undef;
25152548
my $squashfuse_ll = undef;
25162549
my $locking = undef;
2550+
my $use_tar2sqfs = undef;
25172551
my $force = '';
25182552
my $ignore_state = '';
25192553
my $reset = '';
@@ -2549,6 +2583,8 @@ my $funionfs = undef;
25492583
my $unionfs_fuse = undef;
25502584
my $squashfuse = undef;
25512585
my $mksquashfs = undef;
2586+
my $tar = undef;
2587+
my $tar2sqfs = undef;
25522588
my $lsof_bin = undef;
25532589
my $mount = undef;
25542590
my $umount = undef;
@@ -2765,7 +2801,12 @@ sub cmd_status {
27652801
push(@status, "TEMPDIR: $tempdir") if (&is_abspath($tempdir));
27662802
push(@status, "BACKUP: $backup") if (&is_nonempty($backup));
27672803
&mksquashfs_options(\my @options);
2768-
push(@status, &shell_quote_best_effort('mksquashfs-options:', @options));
2804+
push(@status, &shell_quote_best_effort('mksquashfs-options:',
2805+
@options));
2806+
push(@status, &shell_quote_best_effort('tar-options:',
2807+
&tar_options()));
2808+
push(@status, &shell_quote_best_effort('tar2sqfs-options:',
2809+
&tar2sqfs_options()));
27692810
my $chmod = &get_chmod();
27702811
push(@status, 'CHMOD: ' . (($chmod eq '') ? 'unchanged (0400)' :
27712812
sprintf('%#o', $chmod)));
@@ -2963,7 +3004,7 @@ sub umount_main {
29633004
} else {
29643005
$tempfile = File::Temp->new();
29653006
}
2966-
return '' unless (&mksquashfs($tempfile->filename, $dir));
3007+
return '' unless (&createsquashfs($tempfile->filename, $dir));
29673008
$created = 1
29683009
}
29693010
&info('umounting...') unless ($quiet);
@@ -3125,7 +3166,7 @@ sub first_create {
31253166
&info('It seems this is mounted for the first time:',
31263167
"The squash-file $squashfile does not exist yet;",
31273168
"it will be initialized now from $dir") unless ($quiet);
3128-
return '' unless (&mksquashfs($squashfile, $dir));
3169+
return '' unless (&createsquashfs($squashfile, $dir));
31293170
&set_permissions($squashfile);
31303171
# Sanity check: do not wipe if e.g. kernel has no squashfs support
31313172
my $success = 1; {
@@ -3456,7 +3497,7 @@ sub mount_squashfuse {
34563497

34573498
# Create the squash-file:
34583499

3459-
sub mksquashfs {
3500+
sub createsquashfs {
34603501
my ($squashfile, $dir) = @_;
34613502
unless (-d $dir) {
34623503
&error("no directory $dir");
@@ -3469,6 +3510,47 @@ sub mksquashfs {
34693510
if (($parent ne '') && !(-d $parent)) {
34703511
return '' unless (&make_directory($parent))
34713512
}
3513+
my $bad = '';
3514+
my $unavailable;
3515+
if ($use_tar2sqfs) {
3516+
$unavailable = &unavailable_tar2sqfs();
3517+
if ($unavailable ne '') {
3518+
if (&which_store(\$mksquashfs, 'mksquashfs')) {
3519+
$use_tar2sqfs = '';
3520+
&warning($unavailable .
3521+
' not available; using --no-tar')
3522+
} else {
3523+
$bad = 1
3524+
}
3525+
}
3526+
} elsif (!&which_store(\$mksquashfs, 'mksquashfs')) {
3527+
$unavailable = &unavailable_tar2sqfs();
3528+
if ($unavailable eq '') {
3529+
$use_tar2sqfs = 1;
3530+
&warning('mksquashfs not available; using --tar',
3531+
$quiet ?
3532+
'To make this the default: $tar2sqfs = 1;' : ())
3533+
unless ($quiet > 1)
3534+
} else {
3535+
$bad = 1;
3536+
}
3537+
}
3538+
if ($bad) {
3539+
&error('Neither mksquashfs nor ' . $unavailable . ' are in $PATH');
3540+
return ''
3541+
}
3542+
$use_tar2sqfs ? &tar2sqfs($squashfile, $dir)
3543+
: &mksquashfs($squashfile, $dir)
3544+
}
3545+
3546+
sub unavailable_tar2sqfs {
3547+
&which_store(\$tar, 'tar', 'gtar', 'star') ?
3548+
(&which_store(\$tar2sqfs, 'tar2sqfs') ? '' : 'tar2sqfs')
3549+
: '{,g,s}tar'
3550+
}
3551+
3552+
sub mksquashfs {
3553+
my ($squashfile, $dir) = @_;
34723554
my $redirect = &mksquashfs_options(\my @options);
34733555
my $oldout = undef;
34743556
my $ret = (&my_system($redirect, \$mksquashfs, 'mksquashfs', $dir, $squashfile, @options) == 0);
@@ -3477,6 +3559,22 @@ sub mksquashfs {
34773559
$ret
34783560
}
34793561

3562+
sub tar2sqfs {
3563+
my ($squashfile, $dir) = @_;
3564+
my $cd = &shell_quote_best_effort('cd', '--', $dir) . ' && ';
3565+
my @tar = ('-c', &tar_options(), '.');
3566+
my $tarcmd = &shell_quote_best_effort($tar, @tar) . ' | ';
3567+
my @tar2sqfs = (&tar2sqfs_options(), '--', $squashfile);
3568+
my $tar2sqfscmd = &shell_quote_best_effort($tar2sqfs, @tar2sqfs);
3569+
my $ret = (&my_system_cmd('', $cd . $tarcmd . $tar2sqfscmd) == 0);
3570+
&error($verbose ? 'failed: ' . $cd .
3571+
&shell_quote_best_effort((File::Spec->splitpath($tar))[2],
3572+
@tar) . ' | ' .
3573+
&shell_quote_best_effort('tar2sqfs', @tar2sqfs)
3574+
: 'tar->tar2sqfs failed') unless ($ret);
3575+
$ret
3576+
}
3577+
34803578
# Set array of options for mksquashfs and return redirection for &my_system()
34813579
# Defines/uses $mksquash_symbols for the calculation, using $mksquash_verbose.
34823580

@@ -3536,6 +3634,34 @@ sub calc_mksquash_symbols {
35363634
$squash_symbols
35373635
}
35383636

3637+
# Set array of options for tar:
3638+
3639+
sub tar_options {
3640+
my @options = ();
3641+
&push_ref(\@options, $user_config->{'TAR'} // '--numeric-owner', undef);
3642+
(@options)
3643+
}
3644+
3645+
# Set array of options for tar2sqfs:
3646+
3647+
sub tar2sqfs_options {
3648+
my @options = ('-f');
3649+
my $comp = (defined($compression) ? lc($compression) : 'zstd');
3650+
my $compextra = $user_config->{'COMPEXTRA_' . uc($comp)};
3651+
unless (defined($compextra)) {
3652+
$compextra = 'level=22' if ($comp eq 'zstd');
3653+
$compextra = 'hc' if ($comp eq 'lz4')
3654+
}
3655+
push(@options, '-c', $comp) if ($comp ne '');
3656+
if (defined($compextra)) {
3657+
$compextra = join(',', $compextra) if ($compextra eq 'ARRAY');
3658+
&push_ref(\@options, ['-X', $compextra], undef)
3659+
if ($compextra ne '')
3660+
}
3661+
&push_ref(\@options, $user_config->{'TAR2SQFS'}, '-q');
3662+
(@options)
3663+
}
3664+
35393665
# Set $know_quiet:
35403666

35413667
sub set_know_quiet {
@@ -3738,6 +3864,7 @@ sub kernelprobe {
37383864
our $rm_workdir = 1;
37393865
our $rm_readonly = 1;
37403866
our $locking = undef;
3867+
our $tar2sqfs = undef;
37413868
our $obsolete_overlayfs = '';
37423869
our @order = ();
37433870
our @squashorder = ();
@@ -3797,6 +3924,7 @@ sub read_config_file {
37973924
our $rm_workdir;
37983925
our $rm_readonly;
37993926
our $locking;
3927+
our $tar2sqfs;
38003928
our $obsolete_overlayfs;
38013929
our @order;
38023930
our @squashorder;
@@ -4677,8 +4805,18 @@ sub my_system {
46774805
&error(join(', ', @$b) . ' not found in $PATH');
46784806
return -1
46794807
}
4808+
&my_system_cmd($redirect, $$a, @_)
4809+
}
4810+
4811+
# Calls system() with appropriate messages
4812+
# The first argument is special:
4813+
# '' or 0: Default mode
4814+
# 1: suppress stdout
4815+
# 2: suppress stdout and stderr
4816+
sub my_system_cmd {
4817+
my $redirect = shift();
46804818
if ($verbose > 2) {
4681-
print(&shell_quote_best_effort($$a, @_), "\n");
4819+
print((@_ > 1) ? &shell_quote_best_effort(@_) : @_, "\n");
46824820
$redirect = ''
46834821
}
46844822
my $oldout = undef;
@@ -4689,7 +4827,7 @@ sub my_system {
46894827
}
46904828
$oldout = undef unless (open($oldout, '>&', \*STDOUT) && open(STDOUT, '>', $devnull))
46914829
}
4692-
my $ret = system($$a, @_);
4830+
my $ret = system(@_);
46934831
open(STDERR, '>&', $olderr) if (defined($olderr));
46944832
open(STDOUT, '>&', $oldout) if (defined($oldout));
46954833
($ret >= 0) ? ($ret >> 8) : $ret
@@ -5178,6 +5316,8 @@ sub get_options() {
51785316
'kill-or-resquash|R', sub { $opt_kill = -1 },
51795317
'kill|k', sub { $opt_kill = 1 },
51805318
'no-kill|nokill|K', sub { $opt_kill = 0 },
5319+
'tar2sqfs|tar', \$use_tar2sqfs,
5320+
'no-tar2sqfs|notar2sqfs|no-tar|notar', sub { $use_tar2sqfs = '' },
51815321
'compression|comp|x=s', \$opt_compression,
51825322
'tempdir|D=s', \$opt_tempdir,
51835323
'backup|b=s', \$opt_backup,
@@ -5426,6 +5566,7 @@ $lsof = $CFG::lsof;
54265566
$lsof_ro = $CFG::lsof_ro;
54275567
$squashfuse_ll = $CFG::squashfuse_ll unless (defined($squashfuse_ll));
54285568
$locking = $CFG::locking unless (defined($locking));
5569+
$use_tar2sqfs = $CFG::tar2sqfs unless (defined($use_tar2sqfs));
54295570
$modprobe_loop = $CFG::modprobe_loop;
54305571
$resquash_on_start = $CFG::resquash_on_start;
54315572
$rm_rundir = $CFG::rm_rundir;

lib/squashmount.pl

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
# These are the defaults:
7373
# $lsof = 1;
7474
# $lsof_ro = 0;
75+
# $tar2sqfs = undef;
7576

7677
# Uncomment the following if you prefer (globally) resquashing on start
7778
# instead of resquashing on umount/stop. You can override this individually
@@ -129,15 +130,18 @@
129130

130131
my $defaults = {
131132
COMPRESSION => 'lz4', # We could omit this line as lz4 is default.
132-
COMPOPT_LZ4 => '-Xhc', # We could omit this line as -Xhc is default
133+
COMPOPT_LZ4 => '-Xhc', # We could omit this line as -Xhc is default.
134+
COMPEXTRA_LZ4 = > 'hc', # We could omit this line as hc is default.
133135
# In case of COMPRESSION => 'xz', we use the following option.
134136
# Note that this option roughly doubles the squashing time for only
135137
# slightly better compression of binaries.
136138
COMPOPT_XZ => ['-Xbcj', 'x86'],
139+
COMPEXTRA_XZ => ['x86', 'powerpc', 'ia64', 'arm', 'armthumb', 'sparc']
137140
};
138141
# Add $pure_text, if the archive is essentially pure text:
139142
my $pure_text = {
140143
COMPOPT_XZ => undef, # "-Xbcj x86" is slower for pure text archives
144+
COMPEXTRA_XZ => undef,
141145
};
142146
# Add $git to avoid recompression of git-compressed data.
143147
# The archive will usually be slightly larger, but speed gain can be huge.

0 commit comments

Comments
 (0)