diff options
Diffstat (limited to 'perl-install/standalone/drakupdate_fstab')
| -rwxr-xr-x | perl-install/standalone/drakupdate_fstab | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/perl-install/standalone/drakupdate_fstab b/perl-install/standalone/drakupdate_fstab index ced536698..edb3a5663 100755 --- a/perl-install/standalone/drakupdate_fstab +++ b/perl-install/standalone/drakupdate_fstab @@ -1,7 +1,7 @@ #!/usr/bin/perl # drakupdate_fstab -# Copyright (C) 2002-2004 MandrakeSoft (pixel@mandrakesoft.com) +# Copyright (C) 2002-2008 Mandriva (pixel) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,77 +29,68 @@ use fs; $::isStandalone = 1; #- not using standalone.pm which generates too many logs for drakupdate_fstab purpose -$::testing = $ARGV[0] eq '--test' && shift @ARGV; -$::auto = $ARGV[0] eq '--auto' && shift @ARGV; -my $no_flag = $ARGV[0] eq '--no-flag' && shift @ARGV; -my ($raw_action, $device_name) = @ARGV; -my ($action) = $raw_action =~ /^--(add|del)/; +log::l("drakupdate_fstab called with @ARGV\n"); -@ARGV == 2 && $action or die "usage: drakupdate_fstab [--test] [--auto] [--no-flag] [--add | --del] <device>\n"; +my ($debug, $verbose, $removed); -main($action, $device_name); +my %args = ( + '--auto' => \$::auto, + '--debug' => \$debug, + '--test' => \$::testing, + '--verbose' => \$verbose, + ); +each_index { + if ($args{$_}) { + ${$args{$_}} = 1; + splice @ARGV, $::i - $removed, 1; + $removed++; + } +} @ARGV; -sub check_hard_drives { - my ($name) = @_; +my ($raw_action, $device_name) = @ARGV; +my ($action) = $raw_action =~ /^--(add|del)/; - #- do not do anything if there are many partitions - #- otherwise we may add main extended partitions - if ($name =~ s|/part\d+$||) { - my @parts = grep { /part/ } all($name); - @parts <= 1; - } else { - 1; - } -} +@ARGV == 2 && $action or die "usage: drakupdate_fstab [--test] [--verbose] [--auto] [--add | --del] <device>\n"; + +main($action, $device_name); sub device_name_to_entry { my ($name) = @_; $name =~ s|/dev/||; $name =~ /fd[01]/ && !$::auto and return { device => $name }; my @l = detect_devices::get(); + if ($debug) { + require Data::Dumper; + output("/tmp/drakdump_devices-$action", Data::Dumper->Dump([ \@l ], [ qw($l) ])); + } - my ($e, $nb); - if ((my $devfs_prefix, $nb) = $name =~ m,(.*)/(?:cd|disc|part(\d+))$,) { - ($e) = grep { $_->{devfs_prefix} eq $devfs_prefix } @l or return; - } else { - if (($e) = grep { $name eq $_->{device} } @l) { - $nb = ''; - } else { - (my $prefix, $nb) = $name =~ m/^(.*?)(\d*)$/; - ($e) = grep { $prefix eq ($_->{prefix} || $_->{device}) } @l or return; + my $e; + { + unless ($e = find { $name eq $_->{device} } @l) { + my ($prefix) = $name =~ m/^(.*?)\d*$/; + $e = find { $prefix eq ($_->{prefix} || $_->{device}) } @l; + $e->{device} = $name; } } - if ($nb) { - $e->{devfs_device} = $e->{devfs_prefix} . '/part' . $nb; - $e->{device} = ($e->{prefix} || $e->{device}) . $nb; - } + $e->{media_type} = 'fd' if $name =~ /fd[01]/; $e; } sub set_options { - my ($part, $useSupermount) = @_; - - fs::set_default_options($part, - is_removable => 1, - useSupermount => $useSupermount, - security => security::level::get(), - lang::fs_options(lang::read())); - - my ($options, $unknown) = fs::mount_options_unpack($part); - $options->{kudzu} = 1 if !$no_flag; - fs::mount_options_pack($part, $options, $unknown); + my ($part) = @_; + $part->{is_removable} = 1; } sub set_mount_point { - my ($part, $fstab) = @_; + my ($part, $fstab, $is_hd) = @_; - my $mntpoint = detect_devices::suggest_mount_point($part) or return; - $mntpoint = "/mnt/$mntpoint"; + my $mntpoint = $is_hd ? 'hd' : detect_devices::suggest_mount_point($part); + $mntpoint = "/media/$mntpoint"; foreach ('', 2 .. 10) { - next if fsedit::mntpoint2part("$mntpoint$_", $fstab); + next if fs::get::mntpoint2part("$mntpoint$_", $fstab); $part->{mntpoint} = "$mntpoint$_"; return 1; } @@ -107,55 +98,64 @@ sub set_mount_point { } sub main { - my ($action, $device_name) = @_; - - if ($::auto) { - check_hard_drives($device_name) or return; + my ($action, $device_name) = @_; + my $device = device_name_to_entry($device_name); + if ($device->{media_type} eq 'hd') { + my $all_hds = fsedit::get_hds(); + my $hd = find { fs::get::is_same_hd($_, $device) } fs::get::hds($all_hds); + $hd or die "unable to find hd for $device->{device}"; + my @parts = grep { !fsedit::isSwap($_) && fs::type::maybeFormatted($_) } partition_table::get_normal_parts($hd); + configure_part($action, $_, 'hd') foreach @parts; + } else { + configure_part($action, $device, undef); } +} - my $part = device_name_to_entry($device_name); +sub configure_part { + my ($action, $part, $is_hd) = @_; my $fstab_file = '/etc/fstab'; if (!$part) { - print STDERR "Can't find device $device_name\n" if $::testing; + print STDERR "Cannot find device $device_name\n" if $::testing; return; } elsif ($::testing) { cp_af('/etc/fstab', $fstab_file = '/tmp/fstab'); } my $fstab = [ fs::read_fstab('', '/etc/fstab', 'keep_freq_passno', 'verbatim_credentials') ]; - my ($existing_fstab_entries, $fstab_) = partition { $_->{device} eq $part->{device} || $_->{device} eq $part->{devfs_device} } @$fstab; + my ($existing_fstab_entries, $fstab_) = partition { fs::get::is_same_hd($_, $part) } @$fstab; + if ($debug) { + require Data::Dumper; + output("/tmp/drakdump_entries-$action", Data::Dumper->Dump([ \@ARGV, $part, $fstab, $fstab_, $existing_fstab_entries ], + [ qw($ARGV $part $fstab $fstab_ $existing_fstab_entries) ])); + } if ($action eq 'add') { if (@$existing_fstab_entries) { print STDERR "Already in fstab\n" if $::testing; return; } - my $useSupermount = cat_('/etc/fstab') =~ /supermount/; - set_options($part, $useSupermount); - set_mount_point($part, $fstab) or return; - + set_mount_point($part, $fstab, $is_hd) or return; + set_options($part); + my ($line) = fs::prepare_write_fstab([$part]); - append_to_file($fstab_file, $line) if $line; + if ($line) { + append_to_file($fstab_file, $line); + system("mount $part->{mntpoint}") if !$::testing && ($device_name =~ /^fd\d+/ || $is_hd); + } - if ($::auto) { - print $part->{mntpoint}, " ", $useSupermount ? 'supermount' : 'user', "\n"; + if ($verbose) { + print $part->{mntpoint}, " user\n"; } } else { if (!@$existing_fstab_entries) { print STDERR "Not found in fstab\n" if $::testing; return; } - foreach (@$existing_fstab_entries) { - if (!$no_flag && $_->{options} !~ /\bkudzu\b/) { - print STDERR "Not a 'kudzu'-flagged entry\n" if $::testing; - return; - } - } my ($s) = fs::prepare_write_fstab($fstab_, '', 'keep_smb_credentials'); output($fstab_file, $s); - if ($::auto) { + if ($verbose) { print "$_->{mntpoint}\n" foreach @$existing_fstab_entries; } } |
