diff options
Diffstat (limited to 'perl-install/fs.pm')
| -rw-r--r-- | perl-install/fs.pm | 629 |
1 files changed, 273 insertions, 356 deletions
diff --git a/perl-install/fs.pm b/perl-install/fs.pm index 9d9180286..76cce10e7 100644 --- a/perl-install/fs.pm +++ b/perl-install/fs.pm @@ -1,448 +1,365 @@ -package fs; # $Id$ +package fs; use diagnostics; use strict; -use common qw(:common :file :system :functional); +use common; use log; use devices; -use partition_table qw(:types); +use fs::type; +use fs::get; +use fs::format; +use fs::mount_options; +use fs::loopback; +use fs::mount; use run_program; -use swap; use detect_devices; -use commands; use modules; use fsedit; -use loopback; -1; -sub add_options(\$@) { - my ($option, @options) = @_; - my %l; @l{split(',', $$option), @options} = (); delete $l{defaults}; - $$option = join(',', keys %l) || "defaults"; -} +sub read_fstab { + my ($prefix, $file, @reading_options) = @_; + + if (member('keep_default', @reading_options)) { + push @reading_options, 'freq_passno', 'keep_device_LABEL', 'keep_device_UUID'; + } -sub read_fstab($) { - my ($file) = @_; + my %comments; + my $comment; + my @l = grep { + if (/^Filename\s*Type\s*Size/) { + 0; #- when reading /proc/swaps + } elsif (/^\s*#/) { + $comment .= chomp_($_) . "\n"; + 0; + } else { + $comments{$_} = $comment if $comment; + $comment = ''; + 1; + } + } cat_("$prefix$file"); - local *F; - open F, $file or return; + #- attach comments at the end of fstab to the previous line + $comments{$l[-1]} = $comment if $comment; map { - my ($dev, @l) = split; - $dev =~ s,/(tmp|dev)/,,; - { device => $dev, mntpoint => $l[0], type => $l[1], options => $l[2] } - } <F>; -} + my ($dev, $mntpoint, $fs_type, $options, $freq, $passno) = split; + my $comment = $comments{$_}; -sub up_mount_point { - my ($mntpoint, $fstab) = @_; - while (1) { - $mntpoint = dirname($mntpoint); - $mntpoint ne "." or return; - $_->{mntpoint} eq $mntpoint and return $_ foreach @$fstab; - } -} + $options = 'defaults' if $options eq 'rw'; # clean-up for mtab read -sub check_mounted($) { - my ($fstab) = @_; + s/\\040/ /g foreach $mntpoint, $dev, $options; - local (*F, *G, *H); - open F, "/etc/mtab"; - open G, "/proc/mounts"; - open H, "/proc/swaps"; - foreach (<F>, <G>, <H>) { - foreach my $p (@$fstab) { - /$p->{device}\s+([^\s]*)\s+/ and $p->{mntpoint} = $1, $p->{isMounted} = $p->{isFormatted} = 1; + if ($fs_type eq 'ext4') { + $options = join(",", grep { !/extents/ } split(',', $options)) || 'defaults'; } - } -} -sub get_mntpoints_from_fstab { - my ($fstab, $prefix, $uniq) = @_; + my $h = { + mntpoint => $mntpoint, fs_type => $fs_type, + options => $options, comment => $comment, + if_(member('keep_freq_passno', @reading_options), freq => $freq, passno => $passno), + }; - log::l("reading fstab"); - foreach (read_fstab("$prefix/etc/fstab")) { - next if $uniq && fsedit::mntpoint2part($_->{mntpoint}, $fstab); + put_in_hash($h, fs::wild_device::to_subpart($dev)); - foreach my $p (@$fstab) { - $p->{device} eq $_->{device} or next; - $_->{type} ne 'auto' && $_->{type} ne type2fs($p->{type}) and - log::l("err, fstab and partition table do not agree for $_->{device} type: " . (type2fs($p->{type}) || type2name($p->{type})) . " vs $_->{type}"), next; - delete $p->{unsafeMntpoint} || !$p->{mntpoint} or next; - $p->{mntpoint} = $_->{mntpoint}; - $p->{options} = $_->{options}; + if ($h->{device_LABEL} && !$h->{device_alias} && member('keep_device_LABEL', @reading_options)) { + $h->{prefer_device_LABEL} = 1; + } elsif ($h->{device_UUID} && !$h->{device_alias} && member('keep_device_UUID', @reading_options)) { + $h->{prefer_device_UUID} = 1; + } else { + $h->{prefer_device} = 1; } - } -} - -#- mke2fs -b (1024|2048|4096) -c -i(1024 > 262144) -N (1 > 100000000) -m (0-100%) -L volume-label -#- tune2fs -sub format_ext2($@) { - my ($dev, @options) = @_; - $dev =~ m,(rd|ida|cciss)/, and push @options, qw(-b 4096 -R stride=16); #- For RAID only. - push @options, qw(-b 1024 -O none) if arch() =~ /alpha/; - - run_program::run("mke2fs", @options, devices::make($dev)) or die _("%s formatting of %s failed", "ext2", $dev); -} - -sub format_reiserfs($@) { - my ($dev, @options) = @_; + if ($h->{options} =~ /credentials=/ && !member('verbatim_credentials', @reading_options)) { + 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 = 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); + } + } - #TODO add -h tea - run_program::run("mkreiserfs", "-f", @options, devices::make($dev)) or die _("%s formatting of %s failed", "reiserfs", $dev); + $h; + } @l; } -sub format_dos($@) { - my ($dev, @options) = @_; +sub merge_fstabs { + my ($loose, $fstab, @l) = @_; - run_program::run("mkdosfs", @options, devices::make($dev)) or die _("%s formatting of %s failed", "dos", $dev); -} + foreach my $p (@$fstab) { + my ($l1, $l2) = partition { fs::get::is_same_hd($_, $p) } @l; + my ($p2) = @$l1 or next; + @l = @$l2; -sub format_hfs($@) { - my ($dev, @options) = @_; + $p->{mntpoint} = $p2->{mntpoint} if delete $p->{unsafeMntpoint}; - run_program::run("hformat", @options, devices::make($dev)) or die _("%s formatting of %s failed", "HFS", $dev); -} + if (!$loose) { + $p->{fs_type} = $p2->{fs_type} if $p2->{fs_type}; + $p->{options} = $p2->{options} if $p2->{options}; + add2hash_($p, $p2); + } else { + $p->{isMounted} ||= $p2->{isMounted}; + $p->{real_mntpoint} ||= $p2->{real_mntpoint}; + } + $p->{device_alias} ||= $p2->{device_alias} if $p->{device} ne $p2->{device} && $p2->{device} !~ m|/|; -sub real_format_part { - my ($part) = @_; - - $part->{isFormatted} and return; - - my @options = $part->{toFormatCheck} ? "-c" : (); - log::l("formatting device $part->{device} (type ", type2name($part->{type}), ")"); - - if (isExt2($part)) { - push @options, "-F" if isLoopback($part); - format_ext2($part->{device}, @options); - } elsif (isReiserfs($part)) { - format_reiserfs($part->{device}, @options); - } elsif (isDos($part)) { - format_dos($part->{device}, @options); - } elsif (isWin($part)) { - format_dos($part->{device}, @options, '-F', 32); - } elsif (isHFS($part)) { - format_hfs($part->{device}, @options, '-l', "Untitled"); - } elsif (isAppleBootstrap($part)) { - format_hfs($part->{device}, @options, '-l', "bootstrap"); - } elsif (isSwap($part)) { - my $check_blocks = grep { /^-c$/ } @options; - swap::make($part->{device}, $check_blocks); - } else { - die _("I don't know how to format %s in type %s", $_->{device}, type2name($_->{type})); - } - $part->{isFormatted} = 1; -} -sub format_part { - my ($raid, $part, $prefix) = @_; - if (isMDRAID($part)) { - require raid; - raid::format_part($raid, $part); - } elsif (isLoopback($part)) { - loopback::format_part($part, $prefix); - } else { - real_format_part($part); + $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 formatMount_part { - my ($part, $raid, $fstab, $prefix, $callback) = @_; +sub add2all_hds { + my ($all_hds, @l) = @_; - if (isLoopback($part)) { - formatMount_part($part->{device}, $raid, $fstab, $prefix, $callback); - } - if (my $p = up_mount_point($part->{mntpoint}, $fstab)) { - formatMount_part($p, $raid, $fstab, $prefix, $callback) unless loopback::carryRootLoopback($part); - } + @l = merge_fstabs('', [ fs::get::really_all_fstab($all_hds) ], @l); - if ($part->{toFormat}) { - $callback->($part) if $callback; - format_part($raid, $part, $prefix); + foreach (@l) { + my $s = + $_->{fs_type} eq 'nfs' ? 'nfss' : + $_->{fs_type} eq 'cifs' ? 'smbs' : + $_->{fs_type} eq 'davfs2' ? 'davs' : + isTrueLocalFS($_) || isSwap($_) || isOtherAvailableFS($_) ? '' : + 'special'; + push @{$all_hds->{$s}}, $_ if $s; } - mount_part($part, $prefix); } -sub formatMount_all { - my ($raid, $fstab, $prefix, $callback) = @_; - formatMount_part($_, $raid, $fstab, $prefix, $callback) - foreach sort { isLoopback($a) ? 1 : isSwap($a) ? -1 : 0 } grep { $_->{mntpoint} } @$fstab; - - #- ensure the link is there - loopback::carryRootCreateSymlink($_, $prefix) foreach @$fstab; - - #- for fun :) - #- that way, when install exits via ctrl-c, it gives hand to partition - eval { - local $SIG{__DIE__} = 'ignore'; - my ($type, $major, $minor) = devices::entry(fsedit::get_root($fstab)->{device}); - output "/proc/sys/kernel/real-root-dev", makedev($major, $minor); - }; +sub get_major_minor { + my ($fstab) = @_; + foreach (@$fstab) { + eval { + my (undef, $major, $minor) = devices::entry($_->{device}); + ($_->{major}, $_->{minor}) = ($major, $minor); + }; + } } -sub mount($$$;$) { - my ($dev, $where, $fs, $rdonly) = @_; - log::l("mounting $dev on $where as type $fs"); +sub merge_info_from_mtab { + my ($fstab) = @_; - -d $where or commands::mkdir_('-p', $where); + my @l1 = map { my $l = $_; + my $h = fs::type::fs_type2subpart('swap'); + $h->{$_} = $l->{$_} foreach qw(device major minor); + $h; + } read_fstab('', '/proc/swaps'); + + my @l2 = map { read_fstab('', $_) } '/etc/mtab', '/proc/mounts'; + + foreach (@l1, @l2) { + log::l("found mounted partition on $_->{device} with $_->{mntpoint}"); + if ($::isInstall && $_->{mntpoint} =~ m!^/tmp/\w*image$!) { + $_->{real_mntpoint} = delete $_->{mntpoint}; + } + $_->{isMounted} = 1; + set_isFormatted($_, 1); + } + merge_fstabs('loose', $fstab, @l1, @l2); +} - if ($fs eq 'nfs') { - log::l("calling nfs::mount($dev, $where)"); -# nfs::mount($dev, $where) or die _("nfs mount failed"); - } elsif ($fs eq 'smb') { - die "no smb yet..."; - } else { - $dev = devices::make($dev) if $fs ne 'proc' && $fs ne 'usbdevfs'; - - my $flag = c::MS_MGC_VAL(); - $flag |= c::MS_RDONLY() if $rdonly; - my $mount_opt = ""; - - if ($fs eq 'vfat') { - $mount_opt = 'check=relaxed'; - eval { modules::load('vfat') }; #- try using vfat - eval { modules::load('msdos') } if $@; #- otherwise msdos... - } elsif ($fs eq 'ufs') { - eval { modules::load('ufs') }; - } elsif ($fs eq 'reiserfs') { - #- could be better if we knew if there is a /boot or not - #- without knowing it, / is forced to be mounted with notail - $mount_opt = 'notail' if $where =~ m|/(boot)?$|; - eval { modules::load('reiserfs') }; - } elsif ($fs eq 'romfs') { - eval { modules::load('romfs') }; +# - when using "$loose", it does not merge in type&options from the fstab +sub merge_info_from_fstab { + my ($fstab, $prefix, $uniq, $loose) = @_; + + 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 mount point AND the same device + } else { + 1; } + } read_fstab($prefix, '/etc/fstab', 'keep_default'); - $where =~ s|/$||; - log::l("calling mount($dev, $where, $fs, $flag, $mount_opt)"); - syscall_('mount', $dev, $where, $fs, $flag, $mount_opt) or die _("mount failed: ") . "$!"; - } - local *F; - open F, ">>/etc/mtab" or return; #- fail silently, must be read-only /etc - print F "$dev $where $fs defaults 0 0\n"; + merge_fstabs($loose, $fstab, @l); } -#- takes the mount point to umount (can also be the device) -sub umount($) { - my ($mntpoint) = @_; - $mntpoint =~ s|/$||; - log::l("calling umount($mntpoint)"); - syscall_('umount', $mntpoint) or die _("error unmounting %s: %s", $mntpoint, "$!"); - - substInFile { $_ = '' if /(^|\s)$mntpoint\s/ } '/etc/mtab'; #- don't care about error, if we can't read, we won't manage to write... (and mess mtab) +sub get_info_from_fstab { + my ($all_hds) = @_; + my @l = read_fstab($::prefix, '/etc/fstab', 'keep_default'); + add2all_hds($all_hds, @l); } -sub mount_part($;$$) { - my ($part, $prefix, $rdonly) = @_; +sub prepare_write_fstab { + my ($fstab, $o_prefix, $b_keep_credentials) = @_; + $o_prefix ||= ''; - #- root carrier's link can't be mounted - loopback::carryRootCreateSymlink($part, $prefix); + my %new; + 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}}; + 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()); - return if $part->{isMounted}; + my ($freq, $passno) = + exists $_->{freq} ? + ($_->{freq}, $_->{passno}) : + isTrueLocalFS($_) && !$_->{dmcrypt_name} && $_->{options} !~ /encryption=/ && (!$_->{is_removable} || $needed_to_boot) ? + (1, $_->{mntpoint} eq '/' ? 1 : fs::type::carry_root_loopback($_) ? 0 : 2) : + (0, 0); - unless ($::testing) { - if (isSwap($part)) { - swap::swapon(isLoopback($part) ? $prefix . loopback::file($part) : $part->{device}); - } else { - $part->{mntpoint} or die "missing mount point"; - - my $dev = $part->{device}; - my $mntpoint = ($prefix || '') . $part->{mntpoint}; - if (isLoopback($part)) { - eval { modules::load('loop') }; - $dev = $part->{real_device} = devices::set_loop($prefix . loopback::file($part)) || die; - } elsif (loopback::carryRootLoopback($part)) { - $mntpoint = "/initrd/loopfs"; + if (($device eq 'none' || !$new{$device}) && ($mntpoint eq 'swap' || !$new{$mntpoint})) { + #- keep in mind the new line for fstab. + $new{$device} = 1; + $new{$mntpoint} = 1; + + 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 '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; + } } - mount(devices::make($dev), $mntpoint, type2fs($part->{type}), $rdonly); - rmdir "$mntpoint/lost+found"; - } - } - $part->{isMounted} = $part->{isFormatted} = 1; #- assume that if mount works, partition is formatted -} -sub umount_part($;$) { - my ($part, $prefix) = @_; + my $fs_type = $_->{fs_type} || 'auto'; + + s/ /\\040/g foreach $mntpoint, $device, $options; - $part->{isMounted} or return; + my $file_dep = $options =~ /\b(loop|bind)\b/ ? $device : ''; - unless ($::testing) { - if (isSwap($part)) { - swap::swapoff($part->{device}); - } elsif (loopback::carryRootLoopback($part)) { - umount("/initrd/loopfs"); + [ $file_dep, $mntpoint, $comment . join(' ', $device, $mntpoint, $fs_type, $options, $freq, $passno) . "\n" ]; } else { - umount(($prefix || '') . $part->{mntpoint} || devices::make($part->{device})); - c::del_loop(delete $part->{real_device}) if isLoopback($part); + (); } + } grep { $_->{device} && ($_->{mntpoint} || $_->{real_mntpoint}) && $_->{fs_type} && ($_->{isFormatted} || !$_->{notFormatted}) } @$fstab; + + sub sort_it { + my (@l) = @_; + + if (my $file_based = find { $_->[0] } @l) { + my ($before, $other) = partition { $file_based->[0] =~ /^\Q$_->[1]/ } @l; + $file_based->[0] = ''; #- all dependencies are now in before + if (@$other && @$before) { + sort_it(@$before), sort_it(@$other); + } else { + sort_it(@l); + } + } else { + sort { $a->[1] cmp $b->[1] } @l; + } } - $part->{isMounted} = 0; + @l = sort_it(@l); + + join('', map { $_->[2] } @l), \@smb_credentials, \@davfs_credentials; } -sub mount_all($;$$) { - my ($fstab, $prefix) = @_; +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_credentials'); + $s; +} - #- TODO fsck, create check_mount_all ? - log::l("mounting all filesystems"); +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, $davfs_credentials) = prepare_write_fstab($fstab, $o_prefix, ''); + renamef("$o_prefix/etc/fstab", "$o_prefix/etc/fstab.old"); + output("$o_prefix/etc/fstab", $s); + 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 { + my ($all_hds) = @_; - #- order mount by alphabetical ordre, that way / < /home < /home/httpd... - foreach (sort { $a->{mntpoint} cmp $b->{mntpoint} } grep { isSwap($_) || $_->{mntpoint} && isTrueFS($_) } @$fstab) { - mount_part($_, $prefix); + my %names; + foreach (@{$all_hds->{raw_hds}}) { + my $name = detect_devices::suggest_mount_point($_) or next; + member($name, qw(zip cdrom)) and next; + + my $s = ++$names{$name}; + $_->{mntpoint} ||= "/media/$name" . ($s == 1 ? '' : $s); } } -sub umount_all($;$) { - my ($fstab, $prefix) = @_; +sub get_raw_hds { + my ($prefix, $all_hds) = @_; - log::l("unmounting all filesystems"); + push @{$all_hds->{raw_hds}}, detect_devices::removables(); + $_->{is_removable} = 1 foreach @{$all_hds->{raw_hds}}; - foreach (sort { $b->{mntpoint} cmp $a->{mntpoint} } @$fstab) { - $_->{mntpoint} and umount_part($_, $prefix); - } + get_major_minor($all_hds->{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 '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' }, + ]; } +################################################################################ +# various functions +################################################################################ sub df { - my ($part, $prefix) = @_; + my ($part, $o_prefix) = @_; my $dir = "/tmp/tmp_fs_df"; return $part->{free} if exists $part->{free}; if ($part->{isMounted}) { - $dir = ($prefix || '') . $part->{mntpoint}; + $dir = ($o_prefix || '') . $part->{mntpoint}; } elsif ($part->{notFormatted} && !$part->{isFormatted}) { - return; #- won't even try! + return; #- will not even try! } else { - mkdir $dir; - eval { mount($part->{device}, $dir, type2fs($part->{type}), 'readonly') }; + mkdir_p($dir); + eval { fs::mount::mount(devices::make($part->{device}), $dir, $part->{fs_type}, 'readonly') }; if ($@) { - $part->{notFormatted} = 1; - $part->{isFormatted} = 0; + set_isFormatted($part, 0); unlink $dir; return; } } - my (undef, $free) = common::df($dir); + my (undef, $free) = MDK::Common::System::df($dir); if (!$part->{isMounted}) { - umount($dir); - unlink($dir) + fs::mount::umount($dir); + unlink($dir); } $part->{free} = 2 * $free if defined $free; $part->{free}; } -#- do some stuff before calling write_fstab -sub write($$$$) { - my ($prefix, $fstab, $manualFstab, $useSupermount) = @_; - $fstab = [ @{$fstab||[]}, @{$manualFstab||[]} ]; - - unless ($::live) { - log::l("resetting /etc/mtab"); - local *F; - open F, "> $prefix/etc/mtab" or die "error resetting $prefix/etc/mtab"; - } - - my $floppy = detect_devices::floppy(); - - my @to_add = ( - $useSupermount ? - [ split ' ', "/mnt/floppy /mnt/floppy supermount fs=vfat,dev=/dev/$floppy 0 0" ] : - [ split ' ', "/dev/$floppy /mnt/floppy auto sync,user,noauto,nosuid,nodev 0 0" ], - [ split ' ', 'none /proc proc defaults 0 0' ], - [ split ' ', 'none /dev/pts devpts mode=0620 0 0' ], - (map_index { - my $i = $::i ? $::i + 1 : ''; - mkdir "$prefix/mnt/cdrom$i", 0755;#- or log::l("failed to mkdir $prefix/mnt/cdrom$i: $!"); - symlinkf $_->{device}, "$prefix/dev/cdrom$i" or log::l("failed to symlink $prefix/dev/cdrom$i: $!"); - chown 0, 22, "$prefix/dev/$_->{device}"; - $useSupermount ? - [ "/mnt/cdrom$i", "/mnt/cdrom$i", "supermount", "fs=iso9660,dev=/dev/cdrom$i", 0, 0 ] : - [ "/dev/cdrom$i", "/mnt/cdrom$i", "auto", "user,noauto,nosuid,exec,nodev,ro", 0, 0 ]; - } detect_devices::cdroms()), - (map_index { #- for zip drives, the right partition is the 4th by default. - my $i = $::i ? $::i + 1 : ''; - mkdir "$prefix/mnt/zip$i", 0755 or log::l("failed to mkdir $prefix/mnt/zip$i: $!"); - symlinkf "$_->{device}4", "$prefix/dev/zip$i" or log::l("failed to symlink $prefix/dev/zip$i: $!"); - $useSupermount ? - [ "/mnt/zip$i", "/mnt/zip$i", "supermount", "fs=vfat,dev=/dev/zip$i", 0, 0 ] : - [ "/dev/zip$i", "/mnt/zip$i", "auto", "user,noauto,nosuid,exec,nodev", 0, 0 ]; - } detect_devices::zips())); - write_fstab($fstab, $prefix, @to_add); -} - -sub write_fstab($;$$) { - my ($fstab, $prefix, @to_add) = @_; - $prefix ||= ''; - - unshift @to_add, map { - my ($dir, $options, $freq, $passno) = qw(/dev/ defaults 0 0); - $options = $_->{options} || $options; - - isTrueFS($_) and ($freq, $passno) = (1, ($_->{mntpoint} eq '/') ? 1 : 2); - isNfs($_) and $dir = '', $options = $_->{options} || 'ro,nosuid,rsize=8192,wsize=8192'; - isFat($_) and $options = $_->{options} || "user,exec,umask=0"; - - isReiserfs($_) && $_ == fsedit::get_root($fstab, 'boot') and add_options($options, "notail"); - - my $dev = isLoopback($_) ? - ($_->{mntpoint} eq '/' ? "/initrd/loopfs$_->{loopback_file}" : loopback::file($_)) : - ($_->{device} =~ /^\// ? $_->{device} : "$dir$_->{device}"); - - local $_->{mntpoint} = do { - $passno = 0; - "/initrd/loopfs"; - } if loopback::carryRootLoopback($_); - - add_options($options, "loop") if isLoopback($_) && !isSwap($_); #- no need for loop option for swap files - - eval { devices::make("$prefix/$dev") } if $dir && !isLoopback($_); - mkdir "$prefix/$_->{mntpoint}", 0755 if $_->{mntpoint} && !isSwap($_); - - [ $dev, $_->{mntpoint}, type2fs($_->{type}), $options, $freq, $passno ]; - - } grep { $_->{mntpoint} && type2fs($_->{type}) } @$fstab; - - push @to_add, map { [ split ] } cat_("$prefix/etc/fstab"); - - my %new; - @to_add = grep { - if (($_->[0] eq 'none' || !$new{$_->[0]}) && !$new{$_->[1]}) { - #- keep in mind the new line for fstab. - @new{$_->[0], $_->[1]} = (1, 1); - 1; - } else { - 0; - } - } @to_add; - - log::l("writing $prefix/etc/fstab"); - local *F; - open F, "> $prefix/etc/fstab" or die "error writing $prefix/etc/fstab"; - print F join(" ", @$_), "\n" foreach sort { $a->[1] cmp $b->[1] } @to_add; -} - -sub merge_fstabs { - my ($fstab, $manualFstab) = @_; - my %l; $l{$_->{device}} = $_ foreach @$manualFstab; - put_in_hash($_, $l{$_->{device}}) foreach @$fstab; -} - -#sub check_mount_all_fstab($;$) { -# my ($fstab, $prefix) = @_; -# $prefix ||= ''; -# -# foreach (sort { ($a->{mntpoint} || '') cmp ($b->{mntpoint} || '') } @$fstab) { -# #- avoid unwanted mount in fstab. -# next if ($_->{device} =~ /none/ || $_->{type} =~ /nfs|smbfs|ncpfs|proc/ || $_->{options} =~ /noauto|ro/); -# -# #- TODO fsck -# -# eval { mount(devices::make($_->{device}), $prefix . $_->{mntpoint}, $_->{type}, 0); }; -# if ($@) { -# log::l("unable to mount partition $_->{device} on $prefix/$_->{mntpoint}"); -# } -# } -#} +1; |
