1
1
#!/usr/bin/env perl
2
2
BEGIN { require 5.022 }
3
- package Squashmount v19.1 .0;
3
+ package Squashmount v20.0 .0;
4
4
5
5
use strict;
6
6
use warnings;
@@ -730,6 +730,16 @@ so that this happens for all subsequent umounts/remounts.
730
730
If used with B<status> or B<print*> act as if mount-point was correspondingly
731
731
configured (without actually changing the configuration, of course).
732
732
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
+
733
743
=item B<--compression=>I<mode>, B<--comp=>I<mode>, or B<-x> I<mode>
734
744
735
745
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
1626
1636
directories (minus one) is removed (if nonempty). If the number is negative,
1627
1637
all parent directories are removed (if nonempty).
1628
1638
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
-
1638
1639
=item B<MKSQUASHFS>, B<COMPOPT_{XZ,LZMA,GZIP,LZO,LZ4,ZSTD,}>
1639
1640
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:
1641
1642
These strings are used as additional options when calling B<mksquashfs>
1642
1643
(the latter only if the corresponding B<COMPRESSION> option is used;
1643
1644
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.
1660
1661
1661
1662
=back
1662
1663
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
+
1663
1696
=item B<MOUNT_OVERLAY>
1664
1697
1665
1698
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>;
1745
1778
typically B<xz>, B<lzma>, B<gzip>, B<lzo>, B<lz4>, and B<zstd> are available
1746
1779
(ordered in increasing compression ratio, i.e. B<xz> is usually the slowest but
1747
1780
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).
1749
1782
If the value is empty, no B<-comp> parameter is passed,
1750
1783
that is, the default of the installed B<mksquashfs> is chosen
1751
1784
(which is usually B<gzip> but might depend on your version of B<mksquashfs>).
@@ -2514,6 +2547,7 @@ my $lsof_ro = undef;
2514
2547
my $opt_lsof_ro = undef;
2515
2548
my $squashfuse_ll = undef;
2516
2549
my $locking = undef;
2550
+ my $use_tar2sqfs = undef;
2517
2551
my $force = '';
2518
2552
my $ignore_state = '';
2519
2553
my $reset = '';
@@ -2549,6 +2583,8 @@ my $funionfs = undef;
2549
2583
my $unionfs_fuse = undef;
2550
2584
my $squashfuse = undef;
2551
2585
my $mksquashfs = undef;
2586
+ my $tar = undef;
2587
+ my $tar2sqfs = undef;
2552
2588
my $lsof_bin = undef;
2553
2589
my $mount = undef;
2554
2590
my $umount = undef;
@@ -2765,7 +2801,12 @@ sub cmd_status {
2765
2801
push(@status, "TEMPDIR: $tempdir") if (&is_abspath($tempdir));
2766
2802
push(@status, "BACKUP: $backup") if (&is_nonempty($backup));
2767
2803
&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()));
2769
2810
my $chmod = &get_chmod();
2770
2811
push(@status, 'CHMOD: ' . (($chmod eq '') ? 'unchanged (0400)' :
2771
2812
sprintf('%#o', $chmod)));
@@ -2963,7 +3004,7 @@ sub umount_main {
2963
3004
} else {
2964
3005
$tempfile = File::Temp->new();
2965
3006
}
2966
- return '' unless (&mksquashfs ($tempfile->filename, $dir));
3007
+ return '' unless (&createsquashfs ($tempfile->filename, $dir));
2967
3008
$created = 1
2968
3009
}
2969
3010
&info('umounting...') unless ($quiet);
@@ -3125,7 +3166,7 @@ sub first_create {
3125
3166
&info('It seems this is mounted for the first time:',
3126
3167
"The squash-file $squashfile does not exist yet;",
3127
3168
"it will be initialized now from $dir") unless ($quiet);
3128
- return '' unless (&mksquashfs ($squashfile, $dir));
3169
+ return '' unless (&createsquashfs ($squashfile, $dir));
3129
3170
&set_permissions($squashfile);
3130
3171
# Sanity check: do not wipe if e.g. kernel has no squashfs support
3131
3172
my $success = 1; {
@@ -3456,7 +3497,7 @@ sub mount_squashfuse {
3456
3497
3457
3498
# Create the squash-file:
3458
3499
3459
- sub mksquashfs {
3500
+ sub createsquashfs {
3460
3501
my ($squashfile, $dir) = @_;
3461
3502
unless (-d $dir) {
3462
3503
&error("no directory $dir");
@@ -3469,6 +3510,47 @@ sub mksquashfs {
3469
3510
if (($parent ne '') && !(-d $parent)) {
3470
3511
return '' unless (&make_directory($parent))
3471
3512
}
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) = @_;
3472
3554
my $redirect = &mksquashfs_options(\my @options);
3473
3555
my $oldout = undef;
3474
3556
my $ret = (&my_system($redirect, \$mksquashfs, 'mksquashfs', $dir, $squashfile, @options) == 0);
@@ -3477,6 +3559,22 @@ sub mksquashfs {
3477
3559
$ret
3478
3560
}
3479
3561
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
+
3480
3578
# Set array of options for mksquashfs and return redirection for &my_system()
3481
3579
# Defines/uses $mksquash_symbols for the calculation, using $mksquash_verbose.
3482
3580
@@ -3536,6 +3634,34 @@ sub calc_mksquash_symbols {
3536
3634
$squash_symbols
3537
3635
}
3538
3636
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
+
3539
3665
# Set $know_quiet:
3540
3666
3541
3667
sub set_know_quiet {
@@ -3738,6 +3864,7 @@ sub kernelprobe {
3738
3864
our $rm_workdir = 1;
3739
3865
our $rm_readonly = 1;
3740
3866
our $locking = undef;
3867
+ our $tar2sqfs = undef;
3741
3868
our $obsolete_overlayfs = '';
3742
3869
our @order = ();
3743
3870
our @squashorder = ();
@@ -3797,6 +3924,7 @@ sub read_config_file {
3797
3924
our $rm_workdir;
3798
3925
our $rm_readonly;
3799
3926
our $locking;
3927
+ our $tar2sqfs;
3800
3928
our $obsolete_overlayfs;
3801
3929
our @order;
3802
3930
our @squashorder;
@@ -4677,8 +4805,18 @@ sub my_system {
4677
4805
&error(join(', ', @$b) . ' not found in $PATH');
4678
4806
return -1
4679
4807
}
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();
4680
4818
if ($verbose > 2) {
4681
- print(&shell_quote_best_effort($$a, @_), "\n");
4819
+ print((@_ > 1) ? &shell_quote_best_effort(@_) : @_ , "\n");
4682
4820
$redirect = ''
4683
4821
}
4684
4822
my $oldout = undef;
@@ -4689,7 +4827,7 @@ sub my_system {
4689
4827
}
4690
4828
$oldout = undef unless (open($oldout, '>&', \*STDOUT) && open(STDOUT, '>', $devnull))
4691
4829
}
4692
- my $ret = system($$a, @_);
4830
+ my $ret = system(@_);
4693
4831
open(STDERR, '>&', $olderr) if (defined($olderr));
4694
4832
open(STDOUT, '>&', $oldout) if (defined($oldout));
4695
4833
($ret >= 0) ? ($ret >> 8) : $ret
@@ -5178,6 +5316,8 @@ sub get_options() {
5178
5316
'kill-or-resquash|R', sub { $opt_kill = -1 },
5179
5317
'kill|k', sub { $opt_kill = 1 },
5180
5318
'no-kill|nokill|K', sub { $opt_kill = 0 },
5319
+ 'tar2sqfs|tar', \$use_tar2sqfs,
5320
+ 'no-tar2sqfs|notar2sqfs|no-tar|notar', sub { $use_tar2sqfs = '' },
5181
5321
'compression|comp|x=s', \$opt_compression,
5182
5322
'tempdir|D=s', \$opt_tempdir,
5183
5323
'backup|b=s', \$opt_backup,
@@ -5426,6 +5566,7 @@ $lsof = $CFG::lsof;
5426
5566
$lsof_ro = $CFG::lsof_ro;
5427
5567
$squashfuse_ll = $CFG::squashfuse_ll unless (defined($squashfuse_ll));
5428
5568
$locking = $CFG::locking unless (defined($locking));
5569
+ $use_tar2sqfs = $CFG::tar2sqfs unless (defined($use_tar2sqfs));
5429
5570
$modprobe_loop = $CFG::modprobe_loop;
5430
5571
$resquash_on_start = $CFG::resquash_on_start;
5431
5572
$rm_rundir = $CFG::rm_rundir;
0 commit comments