# Partition type
if ($pinfo->{'extended'} || $in{'new'} == 3) {
+ # Extended, cannot change
print &ui_table_row($text{'edit_type'}, $text{'extended'});
}
-else {
+elsif ($pinfo->{'edittype'} || $in{'new'}) {
+ # Can change
print &ui_table_row($text{'edit_type'},
&ui_select("type",
$in{'new'} ? &default_tag() : $pinfo->{'type'},
(sort { &tag_name($a) cmp &tag_name($b) }
&list_tags()) ]));
}
+else {
+ # Tool doesn't allow change
+ print &ui_table_row($text{'edit_type'},
+ &tag_name($pinfo->{'type'}));
+
+ }
# Extent and cylinders
if ($in{'new'}) {
}
# Show field for editing filesystem label
-if (($has_e2label || $has_xfs_db) && $pinfo->{'type'} eq '83' && !$in{'new'}) {
+if (($has_e2label || $has_xfs_db) && &supports_label($pinfo) && !$in{'new'}) {
local $label = $in{'new'} ? undef : &get_label($pinfo->{'device'});
if (@stat) {
print &ui_table_row($text{'edit_label'},
}
}
+# Show field for partition name
+if (&supports_name($dinfo)) {
+ print &ui_table_row($text{'edit_name'},
+ &ui_textbox("name", $pinfo->{'name'}, 20));
+ }
+
# Show current UUID
if ($has_volid && !$in{'new'}) {
local $volid = &get_volid($pinfo->{'device'});
- print &ui_table_row($text{'edit_volid'}, "<tt>$volid</tt>");
+ print &ui_table_row($text{'edit_volid'}, "<tt>$volid</tt>", 3);
}
print &ui_table_end();
$has_volid = &has_command("vol_id");
$has_reiserfstune = &has_command("reiserfstune");
$uuid_directory = "/dev/disk/by-uuid";
-$has_parted = !$config{'noparted'} && &has_command("parted");
+if ($config{'mode'} eq 'parted') {
+ $has_parted = 1;
+ }
+elsif ($config{'mode'} eq 'fdisk') {
+ $has_parted = 0;
+ }
+else {
+ $has_parted = !$config{'noparted'} && &has_command("parted");
+ }
$| = 1;
# list_disks_partitions([include-cds])
'end' => $4,
'blocks' => int($5),
'extended' => $6 eq '5' || $6 eq 'f' ? 1 : 0,
- 'index' => scalar(@{$disk->{'parts'}}) };
+ 'index' => scalar(@{$disk->{'parts'}}),
+ 'edittype' => 1, };
$part->{'desc'} = &partition_description($part->{'device'});
push(@{$disk->{'parts'}}, $part);
}
- elsif (/^\s*(\d+)\s+(\d+)cyl\s+(\d+)cyl\s+(\d+)cyl\s+(primary|logical|extended)\s*(\S*)/) {
+ elsif (/^\s*(\d+)\s+(\d+)cyl\s+(\d+)cyl\s+(\d+)cyl(\s+(primary|logical|extended))?\s*(\S*)\s*(\S*)/) {
# Partition within the current disk from parted
local $part = { 'number' => $1,
'device' => $disk->{'device'}.$1,
- 'type' => $6,
+ 'type' => $7,
'start' => $2+1,
'end' => $3+1,
'blocks' => $4 * $disk->{'cylsize'},
- 'extended' => $5 eq 'extended' ? 1 : 0,
- 'index' => scalar(@{$disk->{'parts'}}) };
+ 'extended' => $6 eq 'extended' ? 1 : 0,
+ 'index' => scalar(@{$disk->{'parts'}}),
+ 'name' => $8,
+ 'edittype' => 0, };
+ $part->{'type'} = 'ext2' if ($part->{'type'} =~ /^ext/);
$part->{'desc'} = &partition_description($part->{'device'});
push(@{$disk->{'parts'}}, $part);
}
+ elsif (/Partition\s+Table:\s+(\S+)/) {
+ # Parted partition table type
+ $disk->{'table'} = $1;
+ }
}
close(FDISK);
my ($disk, $part) = @_;
if ($has_parted) {
# Using parted
- my $cmd = "parted ".$disk." rm ".$part;
+ my $cmd = "parted -s ".$disk." rm ".$part;
my $out = &backquote_logged("$cmd </dev/null 2>&1");
if ($?) {
&error("$cmd failed : $out");
if ($has_parted) {
# Using parted
my $pe = $part > 4 ? "logical" : "primary";
- my $cmd = "parted ".$disk." unit cyl mkpartfs ".$pe." ".$type." ".($start-1)." ".$end;
+ my $cmd;
+ if ($type) {
+ $cmd = "parted -s ".$disk." unit cyl mkpartfs ".$pe." ".
+ $type." ".($start-1)." ".$end;
+ }
+ else {
+ $cmd = "parted -s ".$disk." unit cyl mkpart ".$pe." ".
+ ($start-1)." ".$end;
+ }
my $out = &backquote_logged("$cmd </dev/null 2>&1");
if ($?) {
&error("$cmd failed : $out");
}
# create_extended(disk, partition, start, end)
+# Create a new extended partition
sub create_extended
{
-&open_fdisk("$_[0]");
-&wprint("n\n");
-&wait_for($fh, 'primary.*\r\n');
-&wprint("e\n");
-&wait_for($fh, 'Partition.*:');
-&wprint("$_[1]\n");
-&wait_for($fh, 'First.*:');
-&wprint("$_[2]\n");
-&wait_for($fh, 'Last.*:');
-&wprint("$_[3]\n");
-&wait_for($fh, 'Command.*:');
+my ($disk, $part, $start, $end) = @_;
+if ($has_parted) {
+ # Create using parted
+ my $cmd = "parted -s ".$disk." unit cyl mkpart extended ".
+ ($start-1)." ".$end;
+ my $out = &backquote_logged("$cmd </dev/null 2>&1");
+ if ($?) {
+ &error("$cmd failed : $out");
+ }
+ }
+else {
+ # Use classic fdisk
+ &open_fdisk($disk);
+ &wprint("n\n");
+ &wait_for($fh, 'primary.*\r\n');
+ &wprint("e\n");
+ &wait_for($fh, 'Partition.*:');
+ &wprint("$part\n");
+ &wait_for($fh, 'First.*:');
+ &wprint("$start\n");
+ &wait_for($fh, 'Last.*:');
+ &wprint("$end\n");
+ &wait_for($fh, 'Command.*:');
-&wprint("w\n");
-&wait_for($fh, 'Syncing'); sleep(3);
-&close_fdisk();
+ &wprint("w\n");
+ &wait_for($fh, 'Syncing');
+ sleep(3);
+ &close_fdisk();
+ }
undef(@list_disks_partitions_cache);
}
# Given a partition tag, returns the filesystem type (assuming it is supported)
sub conv_type
{
-local @rv;
-if ($_[0] eq "4" || $_[0] eq "6" ||
- $_[0] eq "1" || $_[0] eq "e") { @rv = ( "msdos" ); }
-elsif ($_[0] eq "b" || $_[0] eq "c") { @rv = ( "vfat" ); }
-elsif ($_[0] eq "83") { @rv = ( "ext3", "ext4", "ext2", "xfs", "reiserfs" ); }
-elsif ($_[0] eq "82") { @rv = ( "swap" ); }
-elsif ($_[0] eq "81") { @rv = ( "minix" ); }
-else { return ( ); }
+my ($tag) = @_;
+my @rv;
+if ($has_parted) {
+ # Use parted type names
+ if ($tag eq "fat16") {
+ @rv = ( "msdos" );
+ }
+ elsif ($tag eq "fat32") {
+ @rv = ( "vfat" );
+ }
+ elsif ($tag eq "ext2") {
+ @rv = ( "ext3", "ext4", "ext2", "xfs", "reiserfs" );
+ }
+ elsif ($tag eq "hfs") {
+ @rv = ( "hfs" );
+ }
+ elsif ($tag eq "linux-swap") {
+ @rv = ( "swap" );
+ }
+ elsif ($tag eq "NTFS") {
+ @rv = ( "ntfs" );
+ }
+ elsif ($tag eq "reiserfs") {
+ @rv = "reiserfs";
+ }
+ elsif ($tag eq "ufs") {
+ @rv = ( "ufs" );
+ }
+ else {
+ return ( );
+ }
+ }
+else {
+ # Use fdisk type IDs
+ if ($tag eq "4" || $tag eq "6" || $tag eq "1" || $tag eq "e") {
+ @rv = ( "msdos" );
+ }
+ elsif ($tag eq "b" || $tag eq "c") {
+ @rv = ( "vfat" );
+ }
+ elsif ($tag eq "83") {
+ @rv = ( "ext3", "ext4", "ext2", "xfs", "reiserfs" );
+ }
+ elsif ($tag eq "82") {
+ @rv = ( "swap" );
+ }
+ elsif ($tag eq "81") {
+ @rv = ( "minix" );
+ }
+ else {
+ return ( );
+ }
+ }
local %supp = map { $_, 1 } &mount::list_fstypes();
@rv = grep { $supp{$_} } @rv;
return wantarray ? @rv : $rv[0];
return 0;
}
+# supports_label(&partition)
+# Returns 1 if the label can be set on a partition
+sub supports_label
+{
+my ($part) = @_;
+return $part->{'type'} eq '83' || $part->{'type'} eq 'ext2';
+}
+
+# supports_name(&disk)
+# Returns 1 if the name can be set on a disk's partitions
+sub supports_name
+{
+my ($disk) = @_;
+return $disk->{'table'} eq 'gpt';
+}
+
# supports_hdparm(&disk)
sub supports_hdparm
{
$pinfo = $plist[$in{'part'}];
&delete_partition($dinfo->{'device'}, $pinfo->{'number'});
&webmin_log("delete", "part", $dinfo->{'device'}, \%in);
- &redirect("");
+ &redirect("edit_disk.cgi?device=$dinfo->{'device'}");
}
elsif ($in{'delete'}) {
# Ask the user if he really wants to delete the partition
print "<input type=submit name=confirm value='$text{'delete_ok'}'>\n";
print "</form></center>\n";
- &ui_print_footer("", $text{'index_return'});
+ &ui_print_footer("edit_disk.cgi?device=$dinfo->{'device'}",
+ $text{'disk_return'});
}
elsif (!$in{'new'}) {
- # changing existing partition
+ # Changing existing partition type and label
$pinfo = $plist[$in{'part'}];
- &change_type($dinfo->{'device'}, $pinfo->{'number'}, $in{'type'});
- if (defined($in{'label'}) && $in{'type'} eq '83') {
+ if ($pinfo->{'edittype'}) {
+ &change_type($dinfo->{'device'}, $pinfo->{'number'},
+ $in{'type'});
+ $pinfo->{'type'} = $in{'type'};
+ }
+ if (defined($in{'label'}) && &supports_label($pinfo)) {
&set_label($pinfo->{'device'}, $in{'label'});
}
&webmin_log("modify", "part", $dinfo->{'device'}, \%in);
- &redirect("");
+ &redirect("edit_disk.cgi?device=$dinfo->{'device'}");
}
else {
# Adding new partition
else {
&create_partition($dinfo->{'device'}, $in{'newpart'},
$in{'start'}, $in{'end'}, $in{'type'});
- if ($in{'label'} && $in{'type'} eq '83') {
+ $pinfo = { 'type' => $in{'type'} };
+ if ($in{'label'} && &supports_label($pinfo)) {
local $dev = $dinfo->{'prefix'}.$in{'newpart'};
&set_label($dev, $in{'label'});
}