diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-11-25 12:07:44 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-11-25 12:07:44 +0000 |
commit | 21499786291db824f9745f4c0875eded9d44370d (patch) | |
tree | d05b38b64c55c268f78f7ee820f71fa8776f2447 /perl-install | |
parent | 07edf02d12388e941a375fe15769b706d18ff132 (diff) | |
download | drakx-21499786291db824f9745f4c0875eded9d44370d.tar drakx-21499786291db824f9745f4c0875eded9d44370d.tar.gz drakx-21499786291db824f9745f4c0875eded9d44370d.tar.bz2 drakx-21499786291db824f9745f4c0875eded9d44370d.tar.xz drakx-21499786291db824f9745f4c0875eded9d44370d.zip |
- create analyze_wild_device_name() out of subpart_from_wild_device_name()
- rename part2device() into part2wild_device_name(), change its prototype and use analyze_wild_device_name()
- new field {faked_device}
- for LABEL=..., {device} is not empty anymore and {faked_device} is set,
merge_fstabs() will take care of having the real {device} and {faked_device} unset
- for devfs_device, {device} is set to the devfs device,
merge_fstabs() will take care of having the non devfs device in {device}
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/diskdrake/interactive.pm | 3 | ||||
-rw-r--r-- | perl-install/fs.pm | 106 |
2 files changed, 69 insertions, 40 deletions
diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm index 2a440a4d4..9b28808e8 100644 --- a/perl-install/diskdrake/interactive.pm +++ b/perl-install/diskdrake/interactive.pm @@ -27,12 +27,15 @@ struct part { int size # in sectors int pt_type # 0x82, 0x83, 0x6 ... string fs_type # 'ext2', 'nfs', ... + int part_number # 1 for hda1... string device # 'hda5', 'sdc1' ... string devfs_device # 'ide/host0/bus0/target0/lun0/part5', ... string prefer_devfs_name # should the {devfs_device} or the {device} be used in fstab string device_LABEL # volume label. LABEL=xxx can be used in fstab instead of string prefer_device_LABEL # should the {device_LABEL} or the {device} be used in fstab + bool faked_device # false if {device} is a real device, true for nfs/smb/dav/none devices. If the field doesn't exist, we don't know + string rootDevice # 'sda', 'hdc' ... (can also be a VG_name) string real_mntpoint # directly on real /, '/tmp/hdimage' ... string mntpoint # '/', '/usr' ... diff --git a/perl-install/fs.pm b/perl-install/fs.pm index 47b290fd5..2839489ba 100644 --- a/perl-install/fs.pm +++ b/perl-install/fs.pm @@ -126,25 +126,36 @@ sub merge_fstabs { @l; } -sub subpart_from_wild_device_name { +sub analyze_wild_device_name { my ($dev) = @_; - if ($dev =~ /^LABEL=(.*)/) { - return { device_LABEL => $1 }; - } elsif ($dev eq 'none') { - } elsif ($dev eq 'rootfs') { + if ($dev =~ m!^/(tmp|u?dev)/(.*)!) { + 'dev', $dev; + } elsif ($dev !~ m!^/! && -e "$::prefix/dev/$dev") { + 'dev', "/dev/$dev"; + } elsif ($dev =~ /^LABEL=(.*)/) { + 'label', $1; + } elsif ($dev eq 'none' || $dev eq 'rootfs') { + 'virtual'; } elsif ($dev =~ m!^(\S+):/\w!) { - #- nfs + 'nfs'; } elsif ($dev =~ m!^//\w!) { - #- smb + 'smb'; } elsif ($dev =~ m!^http://!) { - #- http - } else { - if ($dev !~ m!^/! && -e "$::prefix/dev/$dev") { - $dev = "/dev/$dev"; - } - if ($dev =~ m!^/(tmp|u?dev)/(.*)!) { - my %part; + 'dav'; + } +} + +sub subpart_from_wild_device_name { + my ($dev) = @_; + + my $part = { device => $dev, faked_device => 1 }; #- default + + if (my ($kind, $val) = analyze_wild_device_name($dev)) { + if ($kind eq 'label') { + $part->{device_LABEL} = $val; + } elsif ($kind eq 'dev') { + my %part = (faked_device => 0); if (my $rdev = (stat "$::prefix$dev")[6]) { ($part{major}, $part{minor}) = unmakedev($rdev); } @@ -161,19 +172,47 @@ sub subpart_from_wild_device_name { $part{part_number} = $part_number if $part_number; $part{devfs_device} = $dev; } else { - $part{device} = $dev; my $part_number = devices::part_number(\%part); $part{part_number} = $part_number if $part_number; } + $part{device} = $dev; return \%part; - } elsif ($dev =~ m!^/! && -f "$::prefix$dev") { - #- loopback file or directory to bind + } + } else { + if ($dev =~ m!^/! && -f "$::prefix$dev") { + #- it must be a loopback file or directory to bind } else { log::l("part_from_wild_device_name: unknown device $dev"); } } - #- default - { device => $dev }; + $part; +} + +sub part2wild_device_name { + my ($prefix, $part) = @_; + + if ($part->{prefer_device_LABEL}) { + 'LABEL=' . $part->{device_LABEL}; + } elsif ($part->{prefer_devfs_name}) { + "/dev/$part->{devfs_device}"; + } elsif ($part->{device_alias}) { + "/dev/$part->{device_alias}"; + } else { + my $faked_device = exists $part->{faked_device} ? + $part->{faked_device} : + do { + #- in case $part has been created without using subpart_from_wild_device_name() + my ($kind) = analyze_wild_device_name($part->{device}); + $kind ? $kind ne 'dev' : $part->{device} =~ m!^/!; + }; + if ($faked_device) { + $part->{device}; + } else { + my $dev = "/dev/$part->{device}"; + eval { devices::make("$prefix$dev") }; + $dev; + } + } } sub add2all_hds { @@ -258,7 +297,7 @@ sub prepare_write_fstab { my $device = isLoopback($_) ? ($_->{mntpoint} eq '/' ? "/initrd/loopfs" : $_->{loopback_device}{mntpoint}) . $_->{loopback_file} : - part2device($o_prefix, $_->{prefer_devfs_name} ? $_->{devfs_device} : $_->{device}, $_->{fs_type}); + part2wild_device_name($o_prefix, $_); my $real_mntpoint = $_->{mntpoint} || ${{ '/tmp/hdimage' => '/mnt/hd' }}{$_->{real_mntpoint}}; mkdir_p("$o_prefix$real_mntpoint") if $real_mntpoint =~ m|^/|; @@ -288,28 +327,26 @@ sub prepare_write_fstab { my $fs_type = $_->{fs_type} || 'auto'; - my $dev = - $_->{prefer_device_LABEL} ? 'LABEL=' . $_->{device_LABEL} : - $_->{device_alias} ? "/dev/$_->{device_alias}" : $device; + my $dev = $device; $mntpoint =~ s/ /\\040/g; - $dev =~ s/ /\\040/g; + $device =~ s/ /\\040/g; # 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=$dev", "fs=$fs_type", @$l1, if_(@$l2, '--', @$l2)); - ($dev, $fs_type) = ('none', 'supermount'); + $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't be done without supermount, so switching to "auto" $fs_type = 'auto' if $fs_type =~ /:/; } - my $file_dep = $options =~ /\b(loop|bind)\b/ ? $dev : ''; + my $file_dep = $options =~ /\b(loop|bind)\b/ ? $device : ''; - [ $file_dep, $mntpoint, $_->{comment} . join(' ', $dev, $mntpoint, $fs_type, $options || 'defaults', $freq, $passno) . "\n" ]; + [ $file_dep, $mntpoint, $_->{comment} . join(' ', $device, $mntpoint, $fs_type, $options || 'defaults', $freq, $passno) . "\n" ]; } else { (); } @@ -351,17 +388,6 @@ sub write_fstab { network::smb::save_credentials($_) foreach @$smb_credentials; } -sub part2device { - my ($prefix, $dev, $fs_type) = @_; - $dev eq 'none' || member($fs_type, qw(nfs smbfs davfs)) ? - $dev : - do { - my $dir = $dev =~ m!^(/|LABEL=)! ? '' : '/dev/'; - eval { devices::make("$prefix$dir$dev") }; - "$dir$dev"; - }; -} - sub auto_fs() { grep { chop; $_ && !/nodev/ } cat_("/etc/filesystems"); } @@ -454,7 +480,7 @@ sub mount { -d $where or mkdir_p($where); - $dev = part2device('', $dev, $fs); + $dev = part2wild_device_name('', { device => $dev }); $fs or log::l("not mounting $dev partition"), return; |