-my %fses = map { $_ => check_fs ($_) } @devices;
-
-# Now the complex checking code itself.
-# check_fs takes a device name (LV or partition name) and returns
-# a hashref containing everything we can find out about the device.
-sub check_fs {
- local $_;
- my $dev = shift; # LV or partition name.
-
- my %r; # Result hash.
-
- # First try 'file(1)' on it.
- my $file = $g->file ($dev);
- if ($file =~ /ext2 filesystem data/) {
- $r{fstype} = "ext2";
- $r{fsos} = "linux";
- } elsif ($file =~ /ext3 filesystem data/) {
- $r{fstype} = "ext3";
- $r{fsos} = "linux";
- } elsif ($file =~ /ext4 filesystem data/) {
- $r{fstype} = "ext4";
- $r{fsos} = "linux";
- } elsif ($file =~ m{Linux/i386 swap file}) {
- $r{fstype} = "swap";
- $r{fsos} = "linux";
- $r{is_swap} = 1;
- }
-
- # If it's ext2/3/4, then we want the UUID and label.
- if (exists $r{fstype} && $r{fstype} =~ /^ext/) {
- $r{uuid} = $g->get_e2uuid ($dev);
- $r{label} = $g->get_e2label ($dev);
- }
-
- # Try mounting it, fnarrr.
- if (!$r{is_swap}) {
- $r{is_mountable} = 1;
- eval { $g->mount_ro ($dev, "/") };
- if ($@) {
- # It's not mountable, probably empty or some format
- # we don't understand.
- $r{is_mountable} = 0;
- goto OUT;
- }
-
- # Grub /boot?
- if ($g->is_file ("/grub/menu.lst") ||
- $g->is_file ("/grub/grub.conf")) {
- $r{content} = "linux-grub";
- check_grub (\%r);
- goto OUT;
- }
-
- # Linux root?
- if ($g->is_dir ("/etc") && $g->is_dir ("/bin") &&
- $g->is_file ("/etc/fstab")) {
- $r{content} = "linux-root";
- $r{is_root} = 1;
- check_linux_root (\%r);
- goto OUT;
- }
-
- # Linux /usr/local.
- if ($g->is_dir ("/etc") && $g->is_dir ("/bin") &&
- $g->is_dir ("/share") && !$g->exists ("/local") &&
- !$g->is_file ("/etc/fstab")) {
- $r{content} = "linux-usrlocal";
- goto OUT;
- }
-
- # Linux /usr.
- if ($g->is_dir ("/etc") && $g->is_dir ("/bin") &&
- $g->is_dir ("/share") && $g->exists ("/local") &&
- !$g->is_file ("/etc/fstab")) {
- $r{content} = "linux-usr";
- goto OUT;
- }
-
- # Windows root?
- if ($g->is_file ("/AUTOEXEC.BAT") ||
- $g->is_file ("/autoexec.bat") ||
- $g->is_dir ("/Program Files") ||
- $g->is_dir ("/WINDOWS") ||
- $g->is_file ("/ntldr")) {
- $r{fstype} = "ntfs"; # XXX this is a guess
- $r{fsos} = "windows";
- $r{content} = "windows-root";
- $r{is_root} = 1;
- check_windows_root (\%r);
- goto OUT;
- }
- }
-
- OUT:
- $g->umount_all ();
- return \%r;
-}
-
-sub check_linux_root
-{
- local $_;
- my $r = shift;
-
- # Look into /etc to see if we recognise the operating system.
- if ($g->is_file ("/etc/redhat-release")) {
- $_ = $g->cat ("/etc/redhat-release");
- if (/Fedora release (\d+\.\d+)/) {
- $r->{osdistro} = "fedora";
- $r->{osversion} = "$1"
- } elsif (/(Red Hat Enterprise Linux|CentOS|Scientific Linux).*release (\d+).*Update (\d+)/) {
- $r->{osdistro} = "redhat";
- $r->{osversion} = "$2.$3";
- } elsif (/(Red Hat Enterprise Linux|CentOS|Scientific Linux).*release (\d+(?:\.(\d+))?)/) {
- $r->{osdistro} = "redhat";
- $r->{osversion} = "$2";
- } else {
- $r->{osdistro} = "redhat";
- }
- } elsif ($g->is_file ("/etc/debian_version")) {
- $_ = $g->cat ("/etc/debian_version");
- if (/(\d+\.\d+)/) {
- $r->{osdistro} = "debian";
- $r->{osversion} = "$1";
- } else {
- $r->{osdistro} = "debian";
- }
- }
-
- # Parse the contents of /etc/fstab. This is pretty vital so
- # we can determine where filesystems are supposed to be mounted.
- eval "\$_ = \$g->cat ('/etc/fstab');";
- if (!$@ && $_) {
- my @lines = split /\n/;
- my @fstab;
- foreach (@lines) {
- my @fields = split /[ \t]+/;
- if (@fields >= 2) {
- my $spec = $fields[0]; # first column (dev/label/uuid)
- my $file = $fields[1]; # second column (mountpoint)
- if ($spec =~ m{^/} ||
- $spec =~ m{^LABEL=} ||
- $spec =~ m{^UUID=} ||
- $file eq "swap") {
- push @fstab, [$spec, $file]
- }
- }
- }
- $r->{fstab} = \@fstab if @fstab;
- }
-}