mirror of
https://github.com/webmin/webmin.git
synced 2026-05-06 07:10:29 +01:00
Finished off FreeBSD fdisk module
This commit is contained in:
@@ -2,11 +2,6 @@
|
||||
#
|
||||
# XXX include in makedist.pl
|
||||
# XXX exclude from Solaris, RPM, Deb
|
||||
# XXX editing parititions and slices
|
||||
# XXX active slice
|
||||
# XXX change slice type
|
||||
# XXX slice start and end overlap?
|
||||
# XXX logging
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
@@ -69,7 +64,8 @@ foreach my $dev (glob("/dev/ada[0-9]"),
|
||||
$disk->{'size'} = $disk->{'blocks'} *
|
||||
$disk->{'blocksize'};
|
||||
}
|
||||
elsif ($lines[$i+1] !~ /<UNUSED>/ &&
|
||||
elsif ($i+1 < @lines &&
|
||||
$lines[$i+1] !~ /<UNUSED>/ &&
|
||||
$lines[$i] =~ /data\s+for\s+partition\s+(\d+)/) {
|
||||
# Start of a slice
|
||||
$slice = { 'number' => $1,
|
||||
@@ -90,6 +86,7 @@ foreach my $dev (glob("/dev/ada[0-9]"),
|
||||
$slice->{'startblock'} = $1;
|
||||
$slice->{'blocks'} = $2;
|
||||
$slice->{'size'} = &string_to_size("$3");
|
||||
$slice->{'active'} = $lines[$i] =~ /\(active\)/ ? 1 : 0;
|
||||
}
|
||||
elsif ($lines[$i] =~ /beg:\s+cyl\s+(\d+)/ && $slice) {
|
||||
# Slice start
|
||||
@@ -121,8 +118,7 @@ foreach my $dev (glob("/dev/ada[0-9]"),
|
||||
my $out = &backquote_command("disklabel ".$slice->{'device'});
|
||||
my @lines = split(/\r?\n/, $out);
|
||||
foreach my $l (@lines) {
|
||||
if ($l =~ /^\s*([a-z]):\s+(\d+)\s+(\d+)\s+(\S+)/ &&
|
||||
$4 ne 'unused') {
|
||||
if ($l =~ /^\s*([a-z]):\s+(\d+)\s+(\d+)\s+(\S+)/) {
|
||||
my $part = { 'letter' => $1,
|
||||
'blocks' => $2,
|
||||
'startblock' => $3,
|
||||
@@ -135,6 +131,8 @@ foreach my $dev (glob("/dev/ada[0-9]"),
|
||||
$disk->{'number'},
|
||||
$slice->{'number'},
|
||||
uc($part->{'letter'}));
|
||||
next if ($part->{'type'} eq 'unused' &&
|
||||
$part->{'startblock'} == 0);
|
||||
push(@{$slice->{'parts'}}, $part);
|
||||
}
|
||||
}
|
||||
@@ -256,17 +254,40 @@ sub create_slice
|
||||
{
|
||||
my ($disk, $slice) = @_;
|
||||
my $type = hex($slice->{'type'});
|
||||
my $start = int(($slice->{'startblock'} * $disk->{'blocksize'}) / 1024);
|
||||
my $end = int((($slice->{'startblock'} + $slice->{'blocks'}) *
|
||||
$disk->{'blocksize'}) / 1024);
|
||||
my $start = int($slice->{'startblock'} * $disk->{'blocksize'} / 1024);
|
||||
my $length = int($slice->{'blocks'} * $disk->{'blocksize'} / 1024);
|
||||
my $err = &execute_fdisk_commands($disk,
|
||||
[ "p $slice->{'number'} $type ${start}K ${end}K" ]);
|
||||
[ "p $slice->{'number'} $type ${start}K ${length}K" ]);
|
||||
if (!$err) {
|
||||
$slice->{'device'} = $disk->{'device'}."s".$slice->{'number'};
|
||||
}
|
||||
return $err;
|
||||
}
|
||||
|
||||
# modify_slice(&disk, &old-slice, &slice)
|
||||
# Apply type or size changes to a slice
|
||||
sub modify_slice
|
||||
{
|
||||
my ($disk, $oldslice, $slice) = @_;
|
||||
if ($oldslice->{'type'} ne $slice->{'type'}) {
|
||||
# Change the type
|
||||
my $type = hex($slice->{'type'});
|
||||
my $start = int(($slice->{'startblock'} * $disk->{'blocksize'}) / 1024);
|
||||
my $end = int((($slice->{'startblock'} + $slice->{'blocks'}) *
|
||||
$disk->{'blocksize'}) / 1024);
|
||||
my $err = &execute_fdisk_commands($disk,
|
||||
[ "p $slice->{'number'} $type ${start}K ${end}K" ]);
|
||||
return $err if ($err);
|
||||
}
|
||||
if (!$oldslice->{'active'} && $slice->{'active'}) {
|
||||
# Make active
|
||||
my $err = &execute_fdisk_commands($disk,
|
||||
[ "a $slice->{'number'}" ]);
|
||||
return $err if ($err);
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
# initialize_slice(&disk, &slice)
|
||||
# After a slice is created, put a default label on it
|
||||
sub initialize_slice
|
||||
@@ -380,4 +401,30 @@ push(@cmd, $part->{'device'});
|
||||
return join(" ", @cmd);
|
||||
}
|
||||
|
||||
# check_filesystem(&disk, &slice, &part)
|
||||
# Checks the filesystem on some partition, and returns undef on success or
|
||||
# the error output on failure.
|
||||
sub check_filesystem
|
||||
{
|
||||
my ($disk, $slice, $part) = @_;
|
||||
my $cmd = &get_check_filesystem_command($disk, $slice, $part);
|
||||
my $out = &backquote_logged("$cmd 2>&1 </dev/null");
|
||||
return $? ? $out : undef;
|
||||
}
|
||||
|
||||
# get_check_filesystem_command(&disk, &slice, &part)
|
||||
# Returns the command to check a filesystem on some partition
|
||||
sub get_check_filesystem_command
|
||||
{
|
||||
my ($disk, $slice, $part) = @_;
|
||||
my @cmd = "fsck";
|
||||
my @st = &fdisk::device_status($part->{'device'});
|
||||
if (!@st) {
|
||||
# Assume UFS type
|
||||
push(@cmd, "-t", "ufs");
|
||||
}
|
||||
push(@cmd, $part->{'device'});
|
||||
return join(" ", @cmd);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -43,6 +43,7 @@ if ($err) {
|
||||
}
|
||||
else {
|
||||
print &text('npart_done'),"<p>\n";
|
||||
&webmin_log("create", "part", $part->{'device'}, $part);
|
||||
}
|
||||
|
||||
&ui_print_footer("edit_slice.cgi?device=$in{'device'}&slice=$in{'slice'}",
|
||||
|
||||
@@ -54,6 +54,10 @@ if (!$err && $in{'makepart'}) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$err) {
|
||||
&webmin_log("create", "slice", $slice->{'device'}, $slice);
|
||||
}
|
||||
|
||||
&ui_print_footer("edit_disk.cgi?device=$in{'device'}",
|
||||
$text{'disk_return'});
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ if ($in{'confirm'}) {
|
||||
}
|
||||
else {
|
||||
print $text{'dpart_done'},"<p>\n";
|
||||
&webmin_log("delete", "part", $part->{'device'}, $part);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -25,6 +25,7 @@ if ($in{'confirm'}) {
|
||||
}
|
||||
else {
|
||||
print $text{'dslice_done'},"<p>\n";
|
||||
&webmin_log("delete", "slice", $slice->{'device'}, $slice);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -57,13 +57,15 @@ if (@{$disk->{'slices'}}) {
|
||||
# Add row for the slice
|
||||
my $url = "edit_slice.cgi?device=".&urlize($disk->{'device'}).
|
||||
"&slice=".$p->{'number'};
|
||||
my $nlink = "<a href='$url'>$p->{'number'}</a>";
|
||||
$nlink = "<b>$nlink</b>" if ($p->{'active'});
|
||||
print &ui_columns_row([
|
||||
"<a href='$url'>$p->{'number'}</a>",
|
||||
$nlink,
|
||||
"<a href='$url'>".&fdisk::tag_name($p->{'type'})."</a>",
|
||||
$ext,
|
||||
&nice_size($p->{'size'}),
|
||||
$p->{'startblock'},
|
||||
$p->{'startblock'} + $p->{'blocks'},
|
||||
$p->{'startblock'} + $p->{'blocks'} - 1,
|
||||
scalar(@{$p->{'parts'}}),
|
||||
]);
|
||||
}
|
||||
@@ -74,4 +76,17 @@ else {
|
||||
}
|
||||
print &ui_links_row(\@links);
|
||||
|
||||
print &ui_hr();
|
||||
print &ui_buttons_start();
|
||||
|
||||
if (&foreign_installed("smart-status")) {
|
||||
print &ui_buttons_row(
|
||||
"../smart-status/index.cgi",
|
||||
$text{'disk_smart'},
|
||||
$text{'disk_smartdesc'},
|
||||
&ui_hidden("drive", $disk->{'device'}.":"));
|
||||
}
|
||||
|
||||
print &ui_buttons_end();
|
||||
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
|
||||
@@ -51,10 +51,12 @@ print &ui_table_row($text{'part_start'},
|
||||
$part->{'startblock'});
|
||||
|
||||
print &ui_table_row($text{'part_end'},
|
||||
$part->{'startblock'} + $part->{'blocks'});
|
||||
$part->{'startblock'} + $part->{'blocks'} - 1);
|
||||
|
||||
print &ui_table_row($text{'part_use'},
|
||||
@st ? $use : $text{'part_nouse'});
|
||||
!@st ? $text{'part_nouse'} :
|
||||
$st[2] ? &text('part_inuse', $use) :
|
||||
&text('part_foruse', $use));
|
||||
|
||||
print &ui_table_end();
|
||||
if ($canedit) {
|
||||
@@ -71,9 +73,27 @@ if ($canedit) {
|
||||
"newfs_form.cgi", $text{'part_newfs'}, $text{'part_newfsdesc'},
|
||||
$hiddens);
|
||||
|
||||
print &ui_buttons_row(
|
||||
"fsck.cgi", $text{'part_fsck'}, $text{'part_fsckdesc'},
|
||||
$hiddens);
|
||||
if (!@st || $st[1] ne 'swap') {
|
||||
print &ui_buttons_row(
|
||||
"fsck.cgi", $text{'part_fsck'}, $text{'part_fsckdesc'},
|
||||
$hiddens);
|
||||
}
|
||||
|
||||
if (!@st) {
|
||||
if ($part->{'type'} eq 'swap') {
|
||||
print &ui_buttons_row("../mount/edit_mount.cgi",
|
||||
$text{'part_newmount2'}, $text{'part_mountmsg2'},
|
||||
&ui_hidden("newdev", $part->{'device'}).
|
||||
&ui_hidden("type", "swap"));
|
||||
}
|
||||
else {
|
||||
print &ui_buttons_row("../mount/edit_mount.cgi",
|
||||
$text{'part_newmount'}, $text{'part_mountmsg'},
|
||||
&ui_hidden("newdev", $part->{'device'}).
|
||||
&ui_hidden("type", "ufs"),
|
||||
&ui_textbox("newdir", undef, 20));
|
||||
}
|
||||
}
|
||||
|
||||
print &ui_buttons_row(
|
||||
"delete_part.cgi", $text{'part_delete'},
|
||||
@@ -81,6 +101,9 @@ if ($canedit) {
|
||||
|
||||
print &ui_buttons_end();
|
||||
}
|
||||
else {
|
||||
print "<b>$text{'part_cannotedit'}</b><p>\n";
|
||||
}
|
||||
|
||||
&ui_print_footer("edit_slice.cgi?device=$in{'device'}&slice=$in{'slice'}",
|
||||
$text{'slice_return'});
|
||||
|
||||
@@ -6,7 +6,8 @@ use warnings;
|
||||
require './bsdfdisk-lib.pl';
|
||||
our (%in, %text, %config, $module_name);
|
||||
|
||||
&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0);
|
||||
&ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
|
||||
&help_search_link("fdisk", "man"));
|
||||
|
||||
my $err = &check_fdisk();
|
||||
if ($err) {
|
||||
|
||||
@@ -28,6 +28,8 @@ disk_blocks=<b>Blocks:</b> $1
|
||||
disk_device=<b>Device file:</b> $1
|
||||
disk_return=disk details and list of slices
|
||||
disk_add=Create a new slice.
|
||||
disk_smart=Show SMART Status
|
||||
disk_smartdesc=Show the current status of this drive as detected by SMART, and check it for disk errors.
|
||||
|
||||
select_device=$1 device $2
|
||||
select_slice=$1 device $2 slice $3
|
||||
@@ -35,10 +37,12 @@ select_part=$1 device $2 slice $3 partition $4
|
||||
|
||||
slice_title=Edit Slice
|
||||
slice_egone=Selected slice does not exist!
|
||||
slice_ssize=<b>Slice size:</b> $1
|
||||
slice_sstart=<b>Starting block:</b> $1
|
||||
slice_sblocks=<b>Number of blocks:</b> $1
|
||||
slice_stype=<b>Slice type:</b> $1
|
||||
slice_ssize=Slice size
|
||||
slice_sstart=Starting block
|
||||
slice_send=Ending block
|
||||
slice_sblocks=Number of blocks
|
||||
slice_stype=Slice type
|
||||
slice_sactive=Active slice?
|
||||
slice_add=Create a new partition.
|
||||
slice_letter=Partition
|
||||
slice_type=Type
|
||||
@@ -51,6 +55,8 @@ slice_none=This slice has no partitions yet.
|
||||
slice_delete=Delete Slice
|
||||
slice_deletedesc=Delete this slice and all partitions and filesystems within it. Any data on those filesystem will be almost certainly unrecoverable.
|
||||
slice_return=slice details and list of partitions
|
||||
slice_err=Failed to modify slice
|
||||
slice_header=Slice details
|
||||
|
||||
dslice_title=Delete Slice
|
||||
dslice_rusure=Are you sure you want to delete the slice $1? Any partitions and filesystems within it will also be deleted.
|
||||
@@ -105,6 +111,8 @@ part_start=Starting block
|
||||
part_end=Ending block
|
||||
part_use=Currently used by
|
||||
part_nouse=Nothing
|
||||
part_inuse=In use by $1
|
||||
part_foruse=For use by $1
|
||||
part_newfs=Create Filesystem
|
||||
part_newfsdesc=Click this button to create a new UFS filesystem on this partition. Any data that was previously on the partition will be erased.
|
||||
part_fsck=Check Filesystem
|
||||
@@ -114,6 +122,11 @@ part_deletedesc=Click this button to remove this partition from the slice. Any d
|
||||
part_return=partition details
|
||||
part_err=Failed to save partition
|
||||
part_esave=Currently in use by $1
|
||||
part_newmount=Mount Partition On:
|
||||
part_newmount2=Mount Partition
|
||||
part_mountmsg=Mount this partition on new directory on your system, so that it can be used to store files. A filesystem must have been already created on the partition.
|
||||
part_mountmsg2=Mount this partition as virtual memory on your system, to increase the amount of memory available.
|
||||
part_cannotedit=This partition cannot be modified as it is currently in use.
|
||||
|
||||
dpart_title=Delete Partition
|
||||
dpart_rusure=Are you sure you want to delete the partition $1? Any filesystems within it will also be deleted.
|
||||
@@ -137,3 +150,17 @@ newfs_elabel=Missing or invalid label
|
||||
newfs_creating=Creating filesystem on $1 ..
|
||||
newfs_failed=.. creation failed!
|
||||
newfs_done=.. created successfully
|
||||
|
||||
fsck_err=Failed to check filesystem
|
||||
fsck_checking=Checking filesystem on $1 ..
|
||||
fsck_failed=.. check failed!
|
||||
fsck_done=.. check completed with no errors found
|
||||
|
||||
log_create_slice=Created slice $1
|
||||
log_delete_slice=Deleted slice $1
|
||||
log_modify_slice=Modified slice $1
|
||||
log_create_part=Created partition $1
|
||||
log_delete_part=Deleted partition $1
|
||||
log_modify_part=Modified partition $1
|
||||
log_newfs_part=Created filesystem on partition $1
|
||||
log_fsck_part=Checked filesystem on partition $1
|
||||
|
||||
@@ -33,6 +33,7 @@ $newfs->{'label'} = $in{'label_def'} ? undef : $in{'label'};
|
||||
print &text('newfs_creating', "<tt>$part->{'device'}</tt>"),"<br>\n";
|
||||
print "<pre>\n";
|
||||
my $cmd = &get_create_filesystem_command($disk, $slice, $part, $newfs);
|
||||
&additional_log('exec', undef, $cmd);
|
||||
my $fh = "CMD";
|
||||
&open_execute_command($fh, $cmd, 2);
|
||||
while(<$fh>) {
|
||||
@@ -45,6 +46,7 @@ if ($?) {
|
||||
}
|
||||
else {
|
||||
print $text{'newfs_done'},"<p>\n";
|
||||
&webmin_log("newfs", "part", $part->{'device'}, $part);
|
||||
}
|
||||
|
||||
&ui_print_footer(
|
||||
|
||||
@@ -29,4 +29,5 @@ $part->{'type'} = $in{'type'};
|
||||
my $err = &save_partition($disk, $slice, $part);
|
||||
&error($err) if ($err);
|
||||
|
||||
&webmin_log("modify", "part", $part->{'device'}, $part);
|
||||
&redirect("edit_slice.cgi?device=$in{'device'}&slice=$in{'slice'}");
|
||||
|
||||
@@ -15,10 +15,14 @@ $disk || &error($text{'disk_egone'});
|
||||
my ($slice) = grep { $_->{'number'} eq $in{'slice'} } @{$disk->{'slices'}};
|
||||
$slice || &error($text{'slice_egone'});
|
||||
|
||||
# Change the type
|
||||
# Apply changes
|
||||
my $oldslice = { %$slice };
|
||||
$slice->{'type'} = $in{'type'};
|
||||
if (!$slice->{'active'}) {
|
||||
$slice->{'active'} = $in{'active'};
|
||||
}
|
||||
my $err = &modify_slice($disk, $oldslice, $slice);
|
||||
&error($err) if ($err);
|
||||
|
||||
&redirect("edit_disk.cgi?device=$in{'device'});
|
||||
&webmin_log("modify", "slice", $slice->{'device'}, $slice);
|
||||
&redirect("edit_disk.cgi?device=$in{'device'}");
|
||||
|
||||
@@ -45,9 +45,9 @@ print &ui_table_row($text{'nslice_end'},
|
||||
# Slice type
|
||||
print &ui_table_row($text{'nslice_type'},
|
||||
&ui_select("type", 'a5',
|
||||
[ map { [ $_, &fdisk::tag_name($_) ] }
|
||||
(sort { &fdisk::tag_name($a) cmp &fdisk::tag_name($b) }
|
||||
&fdisk::list_tags()) ]));
|
||||
[ sort { $a->[1] cmp $b->[1] }
|
||||
map { [ $_, &fdisk::tag_name($_) ] }
|
||||
&fdisk::list_tags() ]));
|
||||
|
||||
# Also create partition?
|
||||
print &ui_table_row($text{'nslice_makepart'},
|
||||
|
||||
Reference in New Issue
Block a user