use fs::proc_partitions;
package fs::proc_partitions;

log::l("PATCH: not checking /proc/partitions for partition_table::lvm");

my $real_compare = \&compare;
undef *compare;
*compare = sub {
    my ($hd) = @_;

    eval { $hd->isa('partition_table::lvm') } and return;

    &$real_compare;
};

use partition_table;
package partition_table;

log::l("PATCH: looking for partition_table::lvm before partition_table::dos ");

undef *read_primary;
*read_primary = sub {
    my ($hd) = @_;

    #- it can be safely considered that the first sector is used to probe the partition table
    #- but other sectors (typically for extended partition ones) have to match this type!
	my @parttype = (
	  if_(arch() =~ /^ia64/, 'gpt'),
	  arch() =~ /^sparc/ ? ('sun', 'bsd') : ('lvm', 'dos', 'bsd', 'sun', 'mac'),
	);
	foreach ('empty', @parttype, 'unknown') {
	    /unknown/ and die "unknown partition table format on disk " . $hd->{file};

		# perl_checker: require partition_table::bsd
		# perl_checker: require partition_table::dos
		# perl_checker: require partition_table::empty
		# perl_checker: require partition_table::lvm
		# perl_checker: require partition_table::gpt
		# perl_checker: require partition_table::mac
		# perl_checker: require partition_table::sun
		require "partition_table/$_.pm";
		bless $hd, "partition_table::$_";
	        if ($hd->read_primary) {
		    log::l("found a $_ partition table on $hd->{file} at sector 0");
		    return 1;
		}
	}
    0;
};
