1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
![]() |
index : drakx | |
Mageia Installer and base platform for many utilities | Thierry Vignaud [tv] |
summaryrefslogtreecommitdiffstats |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
package fs; # $Id$
use diagnostics;
use strict;
use MDK::Common::System;
use MDK::Common::Various;
use common;
use log;
use devices;
use fs::type;
use fs::get;
use fs::format;
use fs::mount_options;
use run_program;
use detect_devices;
use modules;
use fsedit;
use loopback;
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';
}
my %comments;
my $comment;
my @l = grep {
if (/^\s*#/) {
$comment .= chomp_($_) . "\n";
0;
} else {
$comments{$_} = $comment if $comment;
$comment = '';
1;
}
} cat_("$prefix$file");
#- attach comments at the end of fstab to the previous line
$comments{$l[-1]} = $comment if $comment;
map {
my ($dev, $mntpoint, $fs_type, $options, $freq, $passno) = split;
my $comment = $comments{$_};
$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';
}
$mntpoint =~ s/\\040/ /g;
$dev =~ s/\\040/ /g;
my $h = {
mntpoint => $mntpoint, fs_type => $fs_type,
options => $options, comment => $comment,
if_(member('keep_freq_passno', @reading_options), freq => $freq, passno => $passno),
};
put_in_hash($h, subpart_from_wild_device_name($dev));
if ($h->{device_LABEL} && 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;
}
if ($h->{options} =~ /credentials=/ && !member('verbatim_credentials', @reading_options)) {
require network::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);
if ($credentials->{username}) {
$options->{"$_="} = $credentials->{$_} foreach qw(username password domain);
fs::mount_options::pack($h, $options, $unknown);
}
}
$h;
} @l;
}
sub merge_fstabs {
my ($loose, $fstab, @l) = @_;
foreach my $p (@$fstab) {
my ($l1, $l2) = partition { fsedit::is_same_hd($_, $p) } @l;
my ($p2) = @$l1 or next;
@l = @$l2;
$p->{mntpoint} = $p2->{mntpoint} if delete $p->{unsafeMntpoint};
$p->{fs_type} = $p2->{fs_type} if $p2->{fs_type} && !$loose;
$p->{options} = $p2->{options} if $p2->{options} && !$loose;
#- important to get isMounted property else DrakX may try to mount already mounted partitions :-(
add2hash($p, $p2);
$p->{device_alias} ||= $p2->{device_alias} || $p2->{device} 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
log::l("err, fstab and partition table do not agree for $p->{device} type: $p->{fs_type} vs $p2->{fs_type}");
}
@l;
}
sub subpart_from_wild_device_name {
my ($dev) = @_;
if ($dev =~ /^LABEL=(.*)/) {
return { device_LABEL => $1 };
} elsif ($dev eq 'none') {
} elsif ($dev =~ m!^(\S+):/\w!) {
#- nfs
} elsif ($dev =~ m!^//\w!) {
#- smb
} elsif ($dev =~ m!^http://!) {
#- http
} else {
if ($dev !~ m!^/! && -e "$::prefix/dev/$dev") {
$dev = "/dev/$dev";
}
if ($dev =~ m!^/(tmp|dev)/(.*)!) {
my %part;
if (my $rdev = (stat "$::prefix$dev")[6]) {
($part{major}, $part{minor}) = unmakedev($rdev);
}
if (my $symlink = readlink("$::prefix$dev")) {
if ($symlink =~ m|^[^/]+$|) {
$part{device_alias} = $dev;
$dev = $symlink;
}
}
$dev =~ s!/(tmp|dev)/!!;
my $is_devfs = $dev =~ m!/(disc|part\d+)$!;
$part{$is_devfs ? 'devfs_device' : 'device'} = $dev;
return \%part;
} else {
log::l("part_from_wild_device_name: unknown device $dev");
}
}
#- default
{ device => $dev };
}
sub add2all_hds {
my ($all_hds, @l) = @_;
@l = merge_fstabs('', [ fs::get::really_all_fstab($all_hds) ], @l);
foreach (@l) {
my $s =
$_->{fs_type} eq 'nfs' ? 'nfss' :
$_->{fs_type} eq 'smbfs' ? 'smbs' :
$_->{fs_type} eq 'davfs' ? 'davs' :
isTrueLocalFS($_) || isSwap($_) || isOtherAvailableFS($_) ? '' :
'special';
push @{$all_hds->{$s}}, $_ if $s;
}