smart / freebsd integration

This commit is contained in:
Jamie Cameron
2013-03-20 16:20:04 -07:00
parent 581fe25037
commit bfb3a9a5ed
4 changed files with 50 additions and 15 deletions

View File

@@ -3,6 +3,9 @@
# XXX call from mount module
# XXX include in makedist.pl
# XXX exclude from Solaris, RPM, Deb
# XXX editing parititions and slices
# XXX top-level is really called slice?
# XXX disk cylinders don't match slice size
use strict;
use warnings;
@@ -33,10 +36,16 @@ foreach my $dev (glob("/dev/ada[0-9]"),
next if (!-r $dev || -l $dev);
my $disk = { 'device' => $dev,
'prefix' => $dev,
'type' => $dev =~ /^\/dev\/da/ ? 'scsi' : 'ide',
'parts' => [ ] };
if ($dev =~ /^\/dev\/(.*)/) {
$disk->{'short'} = $1;
}
if ($dev =~ /^\/dev\/([a-z]+)(\d+)/) {
$disk->{'desc'} = &text('select_device',
uc($disk->{'type'}), "$2");
}
$disk->{'index'} = scalar(@rv);
push(@rv, $disk);
# Get size and partitions
@@ -44,26 +53,28 @@ foreach my $dev (glob("/dev/ada[0-9]"),
my @lines = split(/\r?\n/, $out);
my $part;
for(my $i=0; $i<@lines; $i++) {
if ($lines[$i] =~ /cylinders=(\d+)\s+heads=(\d+)\s+sectors\/tracks=(\d+)\s+\((\d+)/) {
if ($lines[$i] =~ /cylinders=(\d+)\s+heads=(\d+)\s+sectors\/track=(\d+)\s+\((\d+)/) {
# Disk information
# XXX model and size?
$disk->{'cylinders'} = $1;
$disk->{'heads'} = $2;
$disk->{'sectors'} = $3;
$disk->{'blksper'} = $4;
$disk->{'size'} = $disk->{'cylinders'} *
$disk->{'blksper'} * 512;
$disk->{'index'} = scalar(@rv);
}
elsif ($lines[$i] =~ /data\s+for\s+partition\s+(\d+)/ &&
$lines[$i+1] !~ /<UNUSED>/) {
elsif ($lines[$i+1] !~ /<UNUSED>/ &&
$lines[$i] =~ /data\s+for\s+partition\s+(\d+)/) {
# Start of a partition
$part = { 'number' => $2,
'device' => $dev."p".$2,
$part = { 'number' => $1,
'device' => $dev."s".$1,
'index' => scalar(@{$disk->{'parts'}}) };
if ($part->{'device'} =~ /^\/dev\/([a-z]+)(\d+)s(\d+)/){
$part->{'desc'} = &text('select_part',
uc($disk->{'type'}), "$2", "$3");
}
push(@{$disk->{'parts'}}, $part);
}
elsif ($lines[$i] =~ /sysid\s+(\d+)/ && $part) {
elsif ($lines[$i] =~ /sysid\s+(\d+)\s+\(0x([0-9a-f]+)/ && $part) {
# Partition type
$part->{'type'} = $2;
}

View File

@@ -13,15 +13,15 @@ my @disks = &list_disks_partitions();
my ($disk) = grep { $_->{'device'} eq $in{'device'} } @disks;
$disk || &error($text{'disk_egone'});
&ui_print_header($disk->{'device'}, $text{'disk_title'}, "");
&ui_print_header($disk->{'desc'}, $text{'disk_title'}, "");
# Show disk details
my @info = ( );
push(@info, &text('disk_dsize', &nice_size($d->{'size'}));
if ($d->{'model'}) {
push(@info, &text('disk_model', $d->{'model'}));
push(@info, &text('disk_dsize', &nice_size($disk->{'size'})));
if ($disk->{'model'}) {
push(@info, &text('disk_model', $disk->{'model'}));
}
push(@info, &text('disk_cylinders', $d->{'cylinders'}));
push(@info, &text('disk_cylinders', $disk->{'cylinders'}));
print &ui_links_row(\@info),"<p>\n";
# Show partitions table
@@ -54,7 +54,7 @@ if (@{$disk->{'parts'}}) {
# Create usage description
my @stat = &fdisk::device_status($p->{'device'});
my $stat = &device_status_link(@stat);
my $stat = &fdisk::device_status_link(@stat);
# Add row for the partition
my $url = "edit_part.cgi?device=".&urlize($disk->{'device'}).

View File

@@ -28,3 +28,5 @@ disk_table=<b>Partition format:</b> $1
disk_return=list of partitions
disk_add=Add primary partition.
select_device=$1 device $2
select_part=$1 device $2 partition $3

View File

@@ -34,6 +34,9 @@ sub list_smart_disks_partitions
if (&foreign_check("fdisk")) {
return &list_smart_disks_partitions_fdisk();
}
elsif (&foreign_check("bsdfdisk")) {
return &list_smart_disks_partitions_bsdfdisk();
}
elsif (&foreign_check("mount")) {
return &list_smart_disks_partitions_fstab();
}
@@ -185,7 +188,7 @@ sub list_smart_disks_partitions_fstab
&foreign_require("mount");
my @rv;
foreach my $m (&mount::list_mounted(1)) {
if ($m->[1] =~ /^(\/dev\/(da|ad)([0-9]+))/ &&
if ($m->[1] =~ /^(\/dev\/(da|ad|ada)([0-9]+))/ &&
$m->[2] ne 'cd9660') {
# FreeBSD-style disk name
push(@rv, { 'device' => $1,
@@ -211,6 +214,25 @@ my %done;
return @rv;
}
=head2 list_smart_disks_partitions_bsdfdisk
Returns a sorted list of disks that can support SMART, using the FreeBSD
fdisk module
=cut
sub list_smart_disks_partitions_bsdfdisk
{
&foreign_require("bsdfdisk");
local @rv;
foreach my $d (sort { $a->{'device'} cmp $b->{'device'} }
&bsdfdisk::list_disks_partitions()) {
if ($d->{'type'} eq 'scsi' || $d->{'type'} eq 'ide') {
push(@rv, $d);
}
}
return sort { $a->{'device'} cmp $b->{'device'} } @rv;
}
=head2 get_drive_status(device-name, [&drive])
Returns a hash reference containing the status of some drive