#!/usr/local/bin/perl # edit_part.cgi # Edit an existing partition, or create a new one require './fdisk-lib.pl'; &ReadParse(); @dlist = &list_disks_partitions(); $dinfo = $dlist[$in{'disk'}]; &can_edit_disk($dinfo->{'device'}) || &error($text{'edit_ecannot'}); if ($in{'new'}) { &ui_print_header(undef, $text{'create_title'}, ""); } else { &ui_print_header(undef, $text{'edit_title'}, ""); } print "\n"; print "\n"; print "
$text{'edit_details'}
\n"; print "\n"; print "\n"; print "\n"; @plist = @{$dinfo->{'parts'}}; if ($in{'new'}) { if ($in{'new'} == 1 || $in{'new'} == 3) { # Adding a new primary or extended partition $np = 1; for($i=0; $i<@plist; $i++) { if ($plist[$i]->{'number'} == $np) { $np++; } push(@start, $plist[$i]->{'start'}); push(@end, $plist[$i]->{'end'}); } $min = 1; $max = $dinfo->{'cylinders'}; } else { # Adding a new logical partition (inside the extended partition) $np = 5; for($i=0; $i<@plist; $i++) { if ($plist[$i]->{'number'} == $np) { $np++; } if ($plist[$i]->{'extended'}) { $min = $plist[$i]->{'start'}; $max = $plist[$i]->{'end'}; } else { push(@start, $plist[$i]->{'start'}); push(@end, $plist[$i]->{'end'}); } } } print "\n"; print "\n"; print "\n"; # find a gap in the partition map for($start=$min; $start<=$max; $start++) { $found = 1; for($i=0; $i<@start; $i++) { if ($start >= $start[$i] && $start <= $end[$i]) { $found = 0; last; } } if ($found) { last; } } if ($found) { # starting place found.. find the end $found = 0; for($end=$start; $end<=$max; $end++) { for($i=0; $i<@start; $i++) { if ($end >= $start[$i] && $end <= $end[$i]) { $found = 1; last; } } if ($found) { last; } } $end--; } else { # no place for new partition! $start = $end = 0; } } else { # Just editing an existing partition $pinfo = $plist[$in{'part'}]; $np = $pinfo->{'number'}; } print "\n"; print "\n"; print "\n"; print "\n"; $dev = $dinfo->{'prefix'}.$np; print "\n"; print "\n"; if ($pinfo->{'extended'} || $in{'new'} == 3) { print "\n"; } else { print "\n"; } print "\n"; if ($in{'new'}) { print "\n"; print "\n"; if ($pinfo->{'extended'}) { foreach $p (@plist) { $ecount++ if ($p->{'number'} > 4); } if ($ecount == 1) { print "\n"; } else { if ($ecount > 4) { print "\n"; } else { print "\n"; } } } else { @stat = &device_status($dev); if ($in{'new'}) { print "\n"; } elsif (@stat) { $msg = $stat[2] ? 'edit_mount' : 'edit_umount'; $msg .= 'vm' if ($stat[1] eq 'swap'); $msg .= 'raid' if ($stat[1] eq 'raid'); $msg .= 'lvm' if ($stat[1] eq 'lvm'); print "\n"; } else { print "\n"; } } print "\n"; if ($in{'new'}) { print "\n"; } elsif ($dinfo->{'cylsize'}) { print "\n"; } else { print "\n"; } # Show field for editing filesystem label print "\n"; if (($has_e2label || $has_xfs_db) && $pinfo->{'type'} eq '83' && !$in{'new'}) { local $label = $in{'new'} ? undef : &get_label($pinfo->{'device'}); print "\n"; } # Show current UUID if ($has_volid && !$in{'new'}) { local $volid = &get_volid($pinfo->{'device'}); print "\n"; print "\n"; } print "\n"; print "
$text{'edit_location'}",$dinfo->{'device'} =~ /^\/dev\/(s|h)d([a-z])$/ ? &text('select_part', $1 eq 's' ? 'SCSI' : 'IDE', uc($2), $np) : $dinfo->{'device'} =~ /rd\/c(\d+)d(\d+)$/ ? &text('select_mpart', "$1", "$2", $np) : $dinfo->{'device'} =~ /ida\/c(\d+)d(\d+)$/ ? &text('select_cpart', "$1", "$2", $np) : $dinfo->{'device'} =~ /scsi\/host(\d+)\/bus(\d+)\/target(\d+)\/lun(\d+)\/disc/ ? &text('select_spart', "$1", "$2", "$3", "$4", $np) : $dinfo->{'device'} =~ /ide\/host(\d+)\/bus(\d+)\/target(\d+)\/lun(\d+)\/disc/ ? &text('select_snewide', "$1", "$2", "$3", "$4", $np) : $dinfo->{'device'},"$text{'edit_device'}$dev
$text{'edit_type'}$text{'extended'}$text{'edit_extent'} - \n"; print "\n"; } else { print "$pinfo->{'start'} - $pinfo->{'end'}\n"; } print $text{'edit_of'}," $dinfo->{'cylinders'}
$text{'edit_status'}", $text{'edit_cont1'}, "", &text('edit_cont5', $ecount), "", &text('edit_cont234', $ecount), "$text{'edit_notexist'}",&text($msg, "$stat[0]", "$stat[1]"),"$text{'edit_notused'}$text{'edit_size'}$text{'edit_notexist'}
",&nice_size(($pinfo->{'end'} - $pinfo->{'start'} + 1) * $dinfo->{'cylsize'}),"
",&text('edit_blocks', $pinfo->{'blocks'}),"
$text{'edit_label'} \n"; if (@stat) { print $label ? "$label" : $text{'edit_none'}; } else { print "\n"; } print "$text{'edit_volid'}$volid
\n"; if ($in{'new'}) { print "\n"; } elsif (@stat && $stat[2]) { print "$text{'edit_inuse'}

\n"; } else { if (!$pinfo->{'extended'}) { print "\n"; } print "\n"; } print "

\n"; if (!$in{'new'} && !$pinfo->{'extended'}) { if (!@stat || $stat[2] == 0) { # Show form for creating filesystem print "


\n" if (!$donehead++); print "\n"; print "\n"; print "\n"; print "\n"; } if (!$in{'new'} && @stat && $stat[2] == 0 && &can_fsck($stat[1])) { # Show form to fsck filesystem print "
\n"; print "$text{'edit_mkfsmsg2'}
\n" if (!$donehead++); print "\n"; print "\n"; print "\n"; print "\n"; } if (!$in{'new'} && @stat && $stat[2] == 0 && &can_tune($stat[1])) { # Show form to tune filesystem print "
\n"; print "\n"; print "\n"; print "",&text('edit_fsckmsg', "fsck"),"
\n" if (!$donehead++); print "\n"; print "\n"; print "\n"; print "\n"; } @types = &conv_type($pinfo->{'type'}); if (!$in{'new'} && !@stat && @types) { # Show form to mount filesystem print "
\n"; print "\n"; print "\n"; print "$text{'edit_tunemsg'}
\n" if (!$donehead++); print "\n"; print "\n"; print "\n"; print &ui_hidden("type", $types[0]); print "\n"; } else { # For some filesystem print "\n"; print "\n"; if (@types > 1) { print "$text{'edit_mountas'} \n"; } else { print &ui_hidden("type", $types[0]); } print "\n"; print "\n"; } print "\n"; } print "
\n"; if ($types[0] eq "swap") { # Swap partition print "\n"; print "$text{'edit_mountmsg2'}
$text{'edit_mountmsg'}

\n" if ($donehead); } &ui_print_footer("", $text{'index_return'});