3 # Edit an existing partition, or create a new one
5 require './fdisk-lib.pl';
7 @dlist = &list_disks_partitions();
8 $dinfo = $dlist[$in{'disk'}];
9 &can_edit_disk($dinfo->{'device'}) ||
10 &error($text{'edit_ecannot'});
12 &ui_print_header($dinfo->{'desc'}, $text{'create_title'}, "");
15 &ui_print_header($dinfo->{'desc'}, $text{'edit_title'}, "");
18 print &ui_form_start("save_part.cgi");
19 print &ui_table_start($text{'edit_details'}, "width=100%", 4);
20 print &ui_hidden("disk", $in{'disk'});
21 print &ui_hidden("part", $in{'part'});
22 print &ui_hidden("new", $in{'new'});
24 # Work out the start and end for the new partition
25 @plist = @{$dinfo->{'parts'}};
27 if ($in{'new'} == 1 || $in{'new'} == 3) {
28 # Adding a new primary or extended partition
30 for($i=0; $i<@plist; $i++) {
31 if ($plist[$i]->{'number'} == $np) { $np++; }
32 push(@start, $plist[$i]->{'start'});
33 push(@end, $plist[$i]->{'end'});
36 $max = $dinfo->{'cylinders'};
39 # Adding a new logical partition (inside the extended partition)
41 for($i=0; $i<@plist; $i++) {
42 if ($plist[$i]->{'number'} == $np) { $np++; }
43 if ($plist[$i]->{'extended'}) {
44 $min = $plist[$i]->{'start'};
45 $max = $plist[$i]->{'end'};
48 push(@start, $plist[$i]->{'start'});
49 push(@end, $plist[$i]->{'end'});
53 print &ui_hidden("newpart", $np);
54 print &ui_hidden("min", $min);
55 print &ui_hidden("max", $max);
57 # find a gap in the partition map
58 for($start=$min; $start<=$max; $start++) {
60 for($i=0; $i<@start; $i++) {
61 if ($start >= $start[$i] && $start <= $end[$i]) {
69 # starting place found.. find the end
71 for($end=$start; $end<=$max; $end++) {
72 for($i=0; $i<@start; $i++) {
73 if ($end >= $start[$i] && $end <= $end[$i]) {
83 # no place for new partition!
88 # Just editing an existing partition
89 $pinfo = $plist[$in{'part'}];
90 $np = $pinfo->{'number'};
92 print &ui_hidden("np", $np);
95 print &ui_table_row($text{'edit_location'},
96 $dinfo->{'device'} =~ /^\/dev\/(s|h)d([a-z])$/ ?
97 &text('select_part', $1 eq 's' ? 'SCSI' : 'IDE', uc($2), $np) :
98 $dinfo->{'device'} =~ /rd\/c(\d+)d(\d+)$/ ?
99 &text('select_mpart', "$1", "$2", $np) :
100 $dinfo->{'device'} =~ /ida\/c(\d+)d(\d+)$/ ?
101 &text('select_cpart', "$1", "$2", $np) :
102 $dinfo->{'device'} =~ /scsi\/host(\d+)\/bus(\d+)\/target(\d+)\/lun(\d+)\/disc/ ?
103 &text('select_spart', "$1", "$2", "$3", "$4", $np) :
104 $dinfo->{'device'} =~ /ide\/host(\d+)\/bus(\d+)\/target(\d+)\/lun(\d+)\/disc/ ?
105 &text('select_snewide', "$1", "$2", "$3", "$4", $np) :
109 $dev = $dinfo->{'prefix'}.$np;
110 print &ui_table_row($text{'edit_device'}, $dev);
113 if ($pinfo->{'extended'} || $in{'new'} == 3) {
114 # Extended, cannot change
115 print &ui_table_row($text{'edit_type'}, $text{'extended'});
117 elsif ($pinfo->{'edittype'} || $in{'new'}) {
119 print &ui_table_row($text{'edit_type'},
121 $in{'new'} ? &default_tag() : $pinfo->{'type'},
122 [ map { [ $_, &tag_name($_) ] }
123 (sort { &tag_name($a) cmp &tag_name($b) }
127 # Tool doesn't allow change
128 print &ui_table_row($text{'edit_type'},
129 &tag_name($pinfo->{'type'}));
133 # Extent and cylinders
135 $ext = &ui_textbox("start", $start, 4)." - ".&ui_textbox("end", $end, 4);
138 $ext = "$pinfo->{'start'} - $pinfo->{'end'}";
140 $ext .= " ".$text{'edit_of'}." ".$dinfo->{'cylinders'};
141 print &ui_table_row($text{'edit_extent'}, $ext);
144 if ($pinfo->{'extended'}) {
145 foreach $p (@plist) {
146 $ecount++ if ($p->{'number'} > 4);
149 $stat = $text{'edit_cont1'};
153 $stat = &text('edit_cont5', $ecount);
156 $stat = &text('edit_cont234', $ecount);
160 elsif (!$in{'new'}) {
161 @stat = &device_status($dev);
163 $msg = $stat[2] ? 'edit_mount' : 'edit_umount';
164 $msg .= 'vm' if ($stat[1] eq 'swap');
165 $msg .= 'raid' if ($stat[1] eq 'raid');
166 $msg .= 'lvm' if ($stat[1] eq 'lvm');
167 $stat = &text($msg, "<tt>$stat[0]</tt>",
168 "<tt>$stat[1]</tt>");
171 $stat = $text{'edit_notused'};
175 print &ui_table_row($text{'edit_status'}, $stat);
180 print &ui_table_row($text{'edit_size'},
181 $dinfo->{'cylsize'} ? &nice_size(($pinfo->{'end'} - $pinfo->{'start'} + 1) * $dinfo->{'cylsize'}) : &text('edit_blocks', $pinfo->{'blocks'}));
184 # Show field for editing filesystem label
185 if (($has_e2label || $has_xfs_db) && &supports_label($pinfo) && !$in{'new'}) {
186 local $label = $in{'new'} ? undef : &get_label($pinfo->{'device'});
188 print &ui_table_row($text{'edit_label'},
189 $label ? "<tt>$label</tt>" : $text{'edit_none'});
192 print &ui_table_row($text{'edit_label'},
193 &ui_textbox("label", $label, 16));
197 # Show field for partition name
198 if (&supports_name($dinfo)) {
199 print &ui_table_row($text{'edit_name'},
200 &ui_textbox("name", $pinfo->{'name'}, 20));
204 if ($has_volid && !$in{'new'}) {
205 local $volid = &get_volid($pinfo->{'device'});
206 print &ui_table_row($text{'edit_volid'}, "<tt>$volid</tt>", 3);
209 print &ui_table_end();
211 print &ui_form_end([ [ undef, $text{'create'} ] ]);
213 elsif (@stat && $stat[2]) {
214 print &ui_form_end();
215 print "<b>$text{'edit_inuse'}</b><p>\n";
218 print &ui_form_end([ $pinfo->{'extended'} ? ( ) :
219 ( [ undef, $text{'save'} ] ),
220 [ 'delete', $text{'delete'} ] ]);
223 if (!$in{'new'} && !$pinfo->{'extended'}) {
225 print &ui_buttons_start();
227 if (!@stat || $stat[2] == 0) {
228 # Show form for creating filesystem
229 local $rt = @stat ? $stat[1] : &conv_type($pinfo->{'type'});
230 print &ui_buttons_row("mkfs_form.cgi",
231 $text{'edit_mkfs2'}, $text{'edit_mkfsmsg2'},
232 &ui_hidden("dev", $dev),
233 &ui_select("type", $rt,
234 [ map { [ $_, $fdisk::text{"fs_".$_}." ($_)" ] }
235 &fdisk::supported_filesystems() ]));
238 if (!$in{'new'} && @stat && $stat[2] == 0 && &can_fsck($stat[1])) {
239 # Show form to fsck filesystem
240 print &ui_buttons_row("fsck_form.cgi",
241 $text{'edit_fsck'},&text('edit_fsckmsg', "<tt>fsck</tt>"),
242 &ui_hidden("dev", $dev)." ".
243 &ui_hidden("type", $stat[1]));
246 if (!$in{'new'} && @stat && $stat[2] == 0 && &can_tune($stat[1])) {
247 # Show form to tune filesystem
248 print &ui_buttons_row("tunefs_form.cgi",
249 $text{'edit_tune'}, $text{'edit_tunemsg'},
250 &ui_hidden("dev", $dev)." ".
251 &ui_hidden("type", $stat[1]));
254 @types = &conv_type($pinfo->{'type'});
255 if (!$in{'new'} && !@stat && @types) {
256 # Show form to mount filesystem
257 if ($types[0] eq "swap") {
259 print &ui_buttons_row("../mount/edit_mount.cgi",
260 $text{'edit_newmount2'}, $text{'edit_mountmsg2'},
261 &ui_hidden("type", $types[0]));
264 # For some filesystem
265 $dirsel = &ui_textbox("newdir", undef, 20);
267 $dirsel .= $text{'edit_mountas'}." ".
268 &ui_select("type", undef, \@types);
271 $dirsel .= &ui_hidden("type", $types[0]);
273 print &ui_buttons_row("../mount/edit_mount.cgi",
274 $text{'edit_newmount'}, $text{'edit_mountmsg'},
279 print &ui_buttons_end();
282 &ui_print_footer("edit_disk.cgi?device=$dinfo->{'device'}",
283 $text{'disk_return'});