summaryrefslogtreecommitdiffstats
path: root/perl-install/fs.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/fs.pm')
-rw-r--r--perl-install/fs.pm131
1 files changed, 65 insertions, 66 deletions
diff --git a/perl-install/fs.pm b/perl-install/fs.pm
index 850538db5..76cce10e7 100644
--- a/perl-install/fs.pm
+++ b/perl-install/fs.pm
@@ -1,4 +1,4 @@
-package fs; # $Id$
+package fs;
use diagnostics;
use strict;
@@ -22,7 +22,7 @@ sub read_fstab {
my ($prefix, $file, @reading_options) = @_;
if (member('keep_default', @reading_options)) {
- push @reading_options, 'freq_passno', 'keep_devfs_name', 'keep_device_LABEL';
+ push @reading_options, 'freq_passno', 'keep_device_LABEL', 'keep_device_UUID';
}
my %comments;
@@ -49,27 +49,12 @@ sub read_fstab {
$options = 'defaults' if $options eq 'rw'; # clean-up for mtab read
- if ($fs_type eq 'supermount') {
- # normalize this bloody supermount
- $options = join(",", 'supermount', grep {
- if (/fs=(.*)/) {
- $fs_type = $1;
- 0;
- } elsif (/dev=(.*)/) {
- $dev = $1;
- 0;
- } elsif ($_ eq '--') {
- 0;
- } else {
- 1;
- }
- } split(',', $options));
- } elsif ($fs_type eq 'smb') {
- # prefering type "smbfs" over "smb"
- $fs_type = 'smbfs';
- }
s/\\040/ /g foreach $mntpoint, $dev, $options;
+ if ($fs_type eq 'ext4') {
+ $options = join(",", grep { !/extents/ } split(',', $options)) || 'defaults';
+ }
+
my $h = {
mntpoint => $mntpoint, fs_type => $fs_type,
options => $options, comment => $comment,
@@ -78,23 +63,32 @@ sub read_fstab {
put_in_hash($h, fs::wild_device::to_subpart($dev));
- if ($h->{device_LABEL} && member('keep_device_LABEL', @reading_options)) {
+ if ($h->{device_LABEL} && !$h->{device_alias} && member('keep_device_LABEL', @reading_options)) {
$h->{prefer_device_LABEL} = 1;
- } elsif ($h->{devfs_device} && member('keep_devfs_name', @reading_options)) {
- $h->{prefer_devfs_name} = 1;
+ } elsif ($h->{device_UUID} && !$h->{device_alias} && member('keep_device_UUID', @reading_options)) {
+ $h->{prefer_device_UUID} = 1;
+ } else {
+ $h->{prefer_device} = 1;
}
if ($h->{options} =~ /credentials=/ && !member('verbatim_credentials', @reading_options)) {
- require network::smb;
+ require fs::remote::smb;
#- remove credentials=file with username=foo,password=bar,domain=zoo
#- the other way is done in fstab_to_string
my ($options, $unknown) = fs::mount_options::unpack($h);
my $file = delete $options->{'credentials='};
- my $credentials = network::smb::read_credentials_raw($file);
+ my $credentials = fs::remote::smb::read_credentials_raw($file);
if ($credentials->{username}) {
$options->{"$_="} = $credentials->{$_} foreach qw(username password domain);
fs::mount_options::pack($h, $options, $unknown);
}
+ } elsif ($h->{fs_type} eq 'davfs2' && !member('verbatim_credentials', @reading_options)) {
+ require fs::remote::davfs;
+ if (my $credentials = fs::remote::davfs::read_credentials($h->{mntpoint})) {
+ my ($options, $unknown) = fs::mount_options::unpack($h);
+ $options->{"$_="} = $credentials->{$_} foreach qw(username password);
+ fs::mount_options::pack($h, $options, $unknown);
+ }
}
$h;
@@ -114,11 +108,12 @@ sub merge_fstabs {
if (!$loose) {
$p->{fs_type} = $p2->{fs_type} if $p2->{fs_type};
$p->{options} = $p2->{options} if $p2->{options};
- add2hash($p, $p2);
+ add2hash_($p, $p2);
} else {
$p->{isMounted} ||= $p2->{isMounted};
+ $p->{real_mntpoint} ||= $p2->{real_mntpoint};
}
- $p->{device_alias} ||= $p2->{device_alias} || $p2->{device} if $p->{device} ne $p2->{device} && $p2->{device} !~ m|/|;
+ $p->{device_alias} ||= $p2->{device_alias} if $p->{device} ne $p2->{device} && $p2->{device} !~ m|/|;
$p->{fs_type} && $p2->{fs_type} && $p->{fs_type} ne $p2->{fs_type}
&& $p->{fs_type} ne 'auto' && $p2->{fs_type} ne 'auto' and
@@ -135,8 +130,8 @@ sub add2all_hds {
foreach (@l) {
my $s =
$_->{fs_type} eq 'nfs' ? 'nfss' :
- $_->{fs_type} eq 'smbfs' ? 'smbs' :
- $_->{fs_type} eq 'davfs' ? 'davs' :
+ $_->{fs_type} eq 'cifs' ? 'smbs' :
+ $_->{fs_type} eq 'davfs2' ? 'davs' :
isTrueLocalFS($_) || isSwap($_) || isOtherAvailableFS($_) ? '' :
'special';
push @{$all_hds->{$s}}, $_ if $s;
@@ -149,7 +144,7 @@ sub get_major_minor {
eval {
my (undef, $major, $minor) = devices::entry($_->{device});
($_->{major}, $_->{minor}) = ($major, $minor);
- } if !$_->{major};
+ };
}
}
@@ -166,12 +161,8 @@ sub merge_info_from_mtab {
foreach (@l1, @l2) {
log::l("found mounted partition on $_->{device} with $_->{mntpoint}");
- if ($::isInstall && $_->{mntpoint} =~ m!/tmp/(image|hdimage)!) {
+ if ($::isInstall && $_->{mntpoint} =~ m!^/tmp/\w*image$!) {
$_->{real_mntpoint} = delete $_->{mntpoint};
- if ($_->{real_mntpoint} eq '/tmp/hdimage') {
- log::l("found hdimage on $_->{device}");
- $_->{mntpoint} = "/mnt/hd"; #- remap for hd install.
- }
}
$_->{isMounted} = 1;
set_isFormatted($_, 1);
@@ -186,7 +177,7 @@ sub merge_info_from_fstab {
my @l = grep {
if ($uniq) {
my $part = fs::get::mntpoint2part($_->{mntpoint}, $fstab);
- !$part || fs::get::is_same_hd($part, $_); #- keep it only if it is the mountpoint AND the same device
+ !$part || fs::get::is_same_hd($part, $_); #- keep it only if it is the mount point AND the same device
} else {
1;
}
@@ -202,25 +193,32 @@ sub get_info_from_fstab {
}
sub prepare_write_fstab {
- my ($fstab, $o_prefix, $b_keep_smb_credentials) = @_;
+ my ($fstab, $o_prefix, $b_keep_credentials) = @_;
$o_prefix ||= '';
my %new;
- my @smb_credentials;
+ my (@smb_credentials, @davfs_credentials);
my @l = map {
my $device =
isLoopback($_) ?
($_->{mntpoint} eq '/' ? "/initrd/loopfs" : $_->{loopback_device}{mntpoint}) . $_->{loopback_file} :
fs::wild_device::from_part($o_prefix, $_);
+ my $comment = $_->{comment};
+ $comment = '' if $comment =~ m!^Entry for /dev/.* :!;
+ $comment ||= "# Entry for /dev/$_->{device} :\n" if $device =~ /^(UUID|LABEL)=/;
+
my $real_mntpoint = $_->{mntpoint} || ${{ '/tmp/hdimage' => '/mnt/hd' }}{$_->{real_mntpoint}};
- mkdir_p("$o_prefix$real_mntpoint") if $real_mntpoint =~ m|^/|;
+ if (!member('bind', split(',', $_->{options}))) {
+ mkdir_p("$o_prefix$real_mntpoint") if $real_mntpoint =~ m|^/|;
+ }
my $mntpoint = fs::type::carry_root_loopback($_) ? '/initrd/loopfs' : $real_mntpoint;
+ my $needed_to_boot = member($_->{mntpoint}, fs::type::directories_needed_to_boot());
my ($freq, $passno) =
exists $_->{freq} ?
($_->{freq}, $_->{passno}) :
- isTrueLocalFS($_) && $_->{options} !~ /encryption=/ && (!$_->{is_removable} || member($_->{mntpoint}, fs::type::directories_needed_to_boot())) ?
+ isTrueLocalFS($_) && !$_->{dmcrypt_name} && $_->{options} !~ /encryption=/ && (!$_->{is_removable} || $needed_to_boot) ?
(1, $_->{mntpoint} eq '/' ? 1 : fs::type::carry_root_loopback($_) ? 0 : 2) :
(0, 0);
@@ -229,35 +227,32 @@ sub prepare_write_fstab {
$new{$device} = 1;
$new{$mntpoint} = 1;
- my $options = $_->{options};
+ my $options = $_->{options} || 'defaults';
+ if (($_->{is_removable} || member($_->{fs_type}, qw(ntfs ntfs-3g))) && !$needed_to_boot && $_->{options} !~ /nofail/) {
+ $options .= ',nofail';
+ }
- if ($_->{fs_type} eq 'smbfs' && $options =~ /password=/ && !$b_keep_smb_credentials) {
- require network::smb;
- if (my ($opts, $smb_credentials) = network::smb::fstab_entry_to_credentials($_)) {
+ if ($_->{fs_type} eq 'cifs' && $options =~ /password=/ && !$b_keep_credentials) {
+ require fs::remote::smb;
+ if (my ($opts, $smb_credentials) = fs::remote::smb::fstab_entry_to_credentials($_)) {
$options = $opts;
push @smb_credentials, $smb_credentials;
}
+ } elsif ($_->{fs_type} eq 'davfs2' && !$b_keep_credentials) {
+ require fs::remote::davfs;
+ if (my ($opts, $davfs_credentials) = fs::remote::davfs::fstab_entry_to_credentials($_)) {
+ $options = $opts || 'defaults';
+ push @davfs_credentials, $davfs_credentials;
+ }
}
my $fs_type = $_->{fs_type} || 'auto';
s/ /\\040/g foreach $mntpoint, $device, $options;
- # handle bloody supermount special case
- if ($options =~ /supermount/) {
- my @l = grep { $_ ne 'supermount' } split(',', $options);
- my ($l1, $l2) = partition { member($_, 'ro', 'exec') } @l;
- $options = join(",", "dev=$device", "fs=$fs_type", @$l1, if_(@$l2, '--', @$l2));
- ($device, $fs_type) = ('none', 'supermount');
- } else {
- #- if we were using supermount, the type could be something like ext2:vfat
- #- but this can not be done without supermount, so switching to "auto"
- $fs_type = 'auto' if $fs_type =~ /:/;
- }
-
my $file_dep = $options =~ /\b(loop|bind)\b/ ? $device : '';
- [ $file_dep, $mntpoint, $_->{comment} . join(' ', $device, $mntpoint, $fs_type, $options || 'defaults', $freq, $passno) . "\n" ];
+ [ $file_dep, $mntpoint, $comment . join(' ', $device, $mntpoint, $fs_type, $options, $freq, $passno) . "\n" ];
} else {
();
}
@@ -280,13 +275,13 @@ sub prepare_write_fstab {
}
@l = sort_it(@l);
- join('', map { $_->[2] } @l), \@smb_credentials;
+ join('', map { $_->[2] } @l), \@smb_credentials, \@davfs_credentials;
}
sub fstab_to_string {
my ($all_hds, $o_prefix) = @_;
my $fstab = [ fs::get::really_all_fstab($all_hds), @{$all_hds->{special}} ];
- my ($s, undef) = prepare_write_fstab($fstab, $o_prefix, 'keep_smb_credentials');
+ my ($s, undef) = prepare_write_fstab($fstab, $o_prefix, 'keep_credentials');
$s;
}
@@ -294,9 +289,13 @@ sub write_fstab {
my ($all_hds, $o_prefix) = @_;
log::l("writing $o_prefix/etc/fstab");
my $fstab = [ fs::get::really_all_fstab($all_hds), @{$all_hds->{special}} ];
- my ($s, $smb_credentials) = prepare_write_fstab($fstab, $o_prefix, '');
+ my ($s, $smb_credentials, $davfs_credentials) = prepare_write_fstab($fstab, $o_prefix, '');
+ renamef("$o_prefix/etc/fstab", "$o_prefix/etc/fstab.old");
output("$o_prefix/etc/fstab", $s);
- network::smb::save_credentials($_) foreach @$smb_credentials;
+ require fs::remote::davfs;
+ fs::remote::smb::save_credentials($_) foreach @$smb_credentials;
+ fs::remote::davfs::save_credentials($davfs_credentials);
+ fs::dmcrypt::save_crypttab($all_hds) if @{$all_hds->{dmcrypts}};
}
sub set_removable_mntpoints {
@@ -305,10 +304,10 @@ sub set_removable_mntpoints {
my %names;
foreach (@{$all_hds->{raw_hds}}) {
my $name = detect_devices::suggest_mount_point($_) or next;
- $name eq 'zip' and next;
+ member($name, qw(zip cdrom)) and next;
my $s = ++$names{$name};
- $_->{mntpoint} ||= "/mnt/$name" . ($s == 1 ? '' : $s);
+ $_->{mntpoint} ||= "/media/$name" . ($s == 1 ? '' : $s);
}
}
@@ -322,8 +321,8 @@ sub get_raw_hds {
my @fstab = read_fstab($prefix, '/etc/fstab', 'keep_default');
$all_hds->{nfss} = [ grep { $_->{fs_type} eq 'nfs' } @fstab ];
- $all_hds->{smbs} = [ grep { $_->{fs_type} eq 'smbfs' } @fstab ];
- $all_hds->{davs} = [ grep { $_->{fs_type} eq 'davfs' } @fstab ];
+ $all_hds->{smbs} = [ grep { $_->{fs_type} eq 'cifs' } @fstab ];
+ $all_hds->{davs} = [ grep { $_->{fs_type} eq 'davfs2' } @fstab ];
$all_hds->{special} = [
(grep { $_->{fs_type} eq 'tmpfs' } @fstab),
{ device => 'none', mntpoint => '/proc', fs_type => 'proc' },