From bfb3a9a5edb9de0fd29cd55aa51de74dff5f350f Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 20 Mar 2013 16:20:04 -0700 Subject: [PATCH] smart / freebsd integration --- bsdfdisk/bsdfdisk-lib.pl | 27 +++++++++++++++++++-------- bsdfdisk/edit_disk.cgi | 12 ++++++------ bsdfdisk/lang/en | 2 ++ smart-status/smart-status-lib.pl | 24 +++++++++++++++++++++++- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/bsdfdisk/bsdfdisk-lib.pl b/bsdfdisk/bsdfdisk-lib.pl index 7212d2b5d..1d71bfd2a 100644 --- a/bsdfdisk/bsdfdisk-lib.pl +++ b/bsdfdisk/bsdfdisk-lib.pl @@ -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] !~ //) { + elsif ($lines[$i+1] !~ // && + $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; } diff --git a/bsdfdisk/edit_disk.cgi b/bsdfdisk/edit_disk.cgi index f6ecfd2a3..e66d591a0 100644 --- a/bsdfdisk/edit_disk.cgi +++ b/bsdfdisk/edit_disk.cgi @@ -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),"

\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'}). diff --git a/bsdfdisk/lang/en b/bsdfdisk/lang/en index c1ca3904e..979cf97f7 100644 --- a/bsdfdisk/lang/en +++ b/bsdfdisk/lang/en @@ -28,3 +28,5 @@ disk_table=Partition format: $1 disk_return=list of partitions disk_add=Add primary partition. +select_device=$1 device $2 +select_part=$1 device $2 partition $3 diff --git a/smart-status/smart-status-lib.pl b/smart-status/smart-status-lib.pl index ed46e20db..f15a3ed10 100755 --- a/smart-status/smart-status-lib.pl +++ b/smart-status/smart-status-lib.pl @@ -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