1#!/usr/local/bin/perl
2# Show details of a slice, and partitions on it
3
4use strict;
5use warnings;
6require './bsdfdisk-lib.pl';
7our (%in, %text, $module_name);
8&ReadParse();
9my $extwidth = 300;
10
11# Get the disk and slice
12my @disks = &list_disks_partitions();
13my ($disk) = grep { $_->{'device'} eq $in{'device'} } @disks;
14$disk || &error($text{'disk_egone'});
15my ($slice) = grep { $_->{'number'} eq $in{'slice'} } @{$disk->{'slices'}};
16$slice || &error($text{'slice_egone'});
17
18&ui_print_header($slice->{'desc'}, $text{'slice_title'}, "");
19
20# Show slice details
21my @st = &fdisk::device_status($slice->{'device'});
22my $use = &fdisk::device_status_link(@st);
23my $canedit = !@st || !$st[2];
24my $hiddens = &ui_hidden("device", $in{'device'})."\n".
25	      &ui_hidden("slice", $in{'slice'})."\n";
26print &ui_form_start("save_slice.cgi");
27print $hiddens;
28print &ui_table_start($text{'slice_header'}, undef, 2);
29
30print &ui_table_row($text{'part_device'},
31	"<tt>$slice->{'device'}</tt>");
32
33print &ui_table_row($text{'slice_ssize'},
34	&nice_size($slice->{'size'}));
35
36print &ui_table_row($text{'slice_sstart'},
37	$slice->{'startblock'});
38
39print &ui_table_row($text{'slice_send'},
40	$slice->{'startblock'} + $slice->{'blocks'} - 1);
41
42print &ui_table_row($text{'slice_stype'},
43	&ui_select("type", $slice->{'type'},
44		   [ sort { $a->[1] cmp $b->[1] }
45			  map { [ $_, &fdisk::tag_name($_) ] }
46			      &fdisk::list_tags() ]));
47
48print &ui_table_row($text{'slice_sactive'},
49	$slice->{'active'} ? $text{'yes'} :
50		&ui_yesno_radio("active", $slice->{'active'}));
51
52print &ui_table_row($text{'slice_suse'},
53	!@st ? $text{'part_nouse'} :
54	$st[2] ? &text('part_inuse', $use) :
55		 &text('part_foruse', $use));
56
57print &ui_table_end();
58print &ui_form_end([ [ undef, $text{'save'} ] ]);
59
60print &ui_hr();
61
62# Show partitions table
63my @links = ( "<a href='part_form.cgi?device=".&urlize($disk->{'device'}).
64	      "&slice=$in{'slice'}'>".$text{'slice_add'}."</a>" );
65if (@{$slice->{'parts'}}) {
66	print &ui_links_row(\@links);
67	print &ui_columns_start([
68		$text{'slice_letter'},
69		$text{'slice_type'},
70		$text{'slice_extent'},
71		$text{'slice_size'},
72		$text{'slice_start'},
73		$text{'slice_end'},
74		$text{'slice_use'},
75		]);
76	foreach my $p (@{$slice->{'parts'}}) {
77		# Create images for the extent
78                my $ext = "";
79                $ext .= sprintf "<img src=images/gap.gif height=10 width=%d>",
80                        $extwidth*($p->{'startblock'} - 1) /
81                        $slice->{'blocks'};
82                $ext .= sprintf "<img src=images/%s.gif height=10 width=%d>",
83                        $p->{'extended'} ? "ext" : "use",
84                        $extwidth*($p->{'blocks'}) /
85                        $slice->{'blocks'};
86                $ext .= sprintf "<img src=images/gap.gif height=10 width=%d>",
87                  $extwidth*($slice->{'blocks'} - $p->{'startblock'} -
88			     $p->{'blocks'}) / $slice->{'blocks'};
89
90		# Work out use
91		my @st = &fdisk::device_status($p->{'device'});
92		my $use = &fdisk::device_status_link(@st);
93
94		# Add row for the partition
95		my $url = "edit_part.cgi?device=".&urlize($disk->{'device'}).
96			  "&slice=".$slice->{'number'}."&part=".$p->{'letter'};
97		print &ui_columns_row([
98			"<a href='$url'>".uc($p->{'letter'})."</a>",
99			"<a href='$url'>$p->{'type'}</a>",
100			$ext,
101			&nice_size($p->{'size'}),
102			$p->{'startblock'},
103			$p->{'startblock'} + $p->{'blocks'} - 1,
104			$use,
105			]);
106		}
107	print &ui_columns_end();
108	print &ui_links_row(\@links);
109	}
110else {
111	# No partitions yet
112	if (@st) {
113		# And directly in use, so none can be created
114		print "<b>$text{'slice_none2'}</b><p>\n";
115		}
116	else {
117		# Show link to add first partition
118		print "<b>$text{'slice_none'}</b><p>\n";
119		print &ui_links_row(\@links);
120		}
121	}
122
123if ($canedit) {
124	print &ui_hr();
125	print &ui_buttons_start();
126
127	if (!@{$slice->{'parts'}}) {
128		&show_filesystem_buttons($hiddens, \@st, $slice);
129		}
130
131	# Button to delete slice
132	print &ui_buttons_row(
133		'delete_slice.cgi',
134		$text{'slice_delete'},
135		$text{'slice_deletedesc'},
136		&ui_hidden("device", $in{'device'})."\n".
137		&ui_hidden("slice", $in{'slice'}));
138
139	print &ui_buttons_end();
140	}
141
142
143&ui_print_footer("edit_disk.cgi?device=$in{'device'}",
144		 $text{'disk_return'});
145