summaryrefslogtreecommitdiffstats
path: root/perl-install/fs/wild_device.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2005-06-28 09:12:16 +0000
committerPascal Rigaux <pixel@mandriva.com>2005-06-28 09:12:16 +0000
commitf1323d79cc7dd3aa5f4ebde2e2744d7a7ad56180 (patch)
treec6a37cc1eadd4c1af23c7cda7924d1b42f500344 /perl-install/fs/wild_device.pm
parent48dc83bc2acf770ec4be3e4be5f74a9d49120f65 (diff)
downloaddrakx-backup-do-not-use-f1323d79cc7dd3aa5f4ebde2e2744d7a7ad56180.tar
drakx-backup-do-not-use-f1323d79cc7dd3aa5f4ebde2e2744d7a7ad56180.tar.gz
drakx-backup-do-not-use-f1323d79cc7dd3aa5f4ebde2e2744d7a7ad56180.tar.bz2
drakx-backup-do-not-use-f1323d79cc7dd3aa5f4ebde2e2744d7a7ad56180.tar.xz
drakx-backup-do-not-use-f1323d79cc7dd3aa5f4ebde2e2744d7a7ad56180.zip
try to cleanup fs.pm
(to have simpler dependencies between modules, esp. have some modules only required by diskdrake): - move some functions from fs to fs::mount (most keep their name, except mount_part and mount_usbfs) - move formatMount_part and formatMount_all from fs to fs::format - move some functions from fs to fs::wild_device (part2wild_device_name -> fs::wild_device::from_part) (subpart_from_wild_device_name -> fs::wild_device::to_subpart) (analyze_wild_device_name -> fs::wild_device::analyse) - formatMount_part(), formatMount_all(), fs::mount::part() don't take a prefix anymore the current situation was quite muddy we now rely on fs::get::mntpoint_prefixed() which will maybe depend on a field in $part for now, we mount every part in chroot, it seems to be what's wanted - fs::format::part() now expect $all_hds instead of $raids - fs::type::carryRootLoopback is now fs::get::carry_root_loopback() - in fs::loopback, most functions don't want a prefix anymore
Diffstat (limited to 'perl-install/fs/wild_device.pm')
-rw-r--r--perl-install/fs/wild_device.pm101
1 files changed, 101 insertions, 0 deletions
diff --git a/perl-install/fs/wild_device.pm b/perl-install/fs/wild_device.pm
new file mode 100644
index 000000000..8fd38b0ce
--- /dev/null
+++ b/perl-install/fs/wild_device.pm
@@ -0,0 +1,101 @@
+package fs::wild_device; # $Id$
+
+use diagnostics;
+use strict;
+
+use common;
+
+
+sub analyze {
+ my ($dev) = @_;
+
+ if ($dev =~ m!^/u?dev/(.*)!) {
+ 'dev', $dev;
+ } elsif ($dev !~ m!^/! && (-e "/dev/$dev" || -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';
+ } elsif ($dev =~ m!^//\w!) {
+ 'smb';
+ } elsif ($dev =~ m!^http://!) {
+ 'dav';
+ }
+}
+
+sub to_subpart {
+ my ($dev) = @_;
+
+ my $part = { device => $dev, faked_device => 1 }; #- default
+
+ if (my ($kind, $val) = analyze($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);
+ }
+
+ my $symlink = readlink("$::prefix$dev");
+ $dev =~ s!/u?dev/!!;
+
+ if ($symlink && $symlink =~ m|^[^/]+$|) {
+ $part{device_alias} = $dev;
+ $dev = $symlink;
+ }
+
+ if (my (undef, $part_number) = $dev =~ m!/(disc|part(\d+))$!) {
+ $part{part_number} = $part_number if $part_number;
+ $part{devfs_device} = $dev;
+ } else {
+ my $part_number = devices::part_number(\%part);
+ $part{part_number} = $part_number if $part_number;
+ }
+ $part{device} = $dev;
+ return \%part;
+ }
+ } 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");
+ }
+ }
+ $part;
+}
+
+sub from_part {
+ 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 fs::wild_device::to_subpart()
+ my ($kind) = analyze($part->{device});
+ $kind ? $kind ne 'dev' : $part->{device} =~ m!^/!;
+ };
+ if ($faked_device) {
+ $part->{device};
+ } elsif ($part->{device} =~ m!^/dev/!) {
+ log::l("ERROR: i have a full device $part->{device}, this should not happen. use fs::wild_device::to_subpart() instead of creating bad part data-structures!");
+ $part->{device};
+ } else {
+ my $dev = "/dev/$part->{device}";
+ eval { devices::make("$prefix$dev") };
+ $dev;
+ }
+ }
+}
+
+1;