3 # Edit an IDE parameters for some disk
5 require './fdisk-lib.pl';
7 @dlist = &list_disks_partitions();
8 $d = $dlist[$in{'disk'}];
9 &can_edit_disk($d->{'device'}) ||
10 &error($text{'edit_ecannot'});
12 &ui_print_header($d->{'desc'}, $text{'hdparm_title'}, "");
13 if ( ! &has_command( "hdparm" ) ) {
14 print "<p>$text{ 'edit_ehdparm' }<p>\n";
15 &ui_print_footer( "", $text{ 'index_return' } );
19 %hdparm = ( 'A', "1", 'K', "0", 'P', "0", 'X', "0", 'W', "0", 'S', "0" );
20 @yesno = ( "1", $text{ 'hdparm_on' }, "0", $text{ 'hdparm_off' } );
22 foreach $argument ( 'a', 'd', 'r', 'k', 'u', 'm', 'c' )
24 $out = `hdparm -$argument $d->{'device'}`;
25 if ($out =~ /\s+=\s+(\S+)/) {
26 $hdparm{ $argument } = $1;
28 #( $_, $line ) = split( /=/, `hdparm -$argument $d->{'device'}` );
30 #( $hdparm{ $argument } ) = split( / /, $line );
33 # Javascript for slider
35 "<script type=\"text/javascript\" src=\"range.js\"></script>
36 <script type=\"text/javascript\" src=\"timer.js\"></script>
37 <script type=\"text/javascript\" src=\"slider.js\"></script>
38 <link type=\"text/css\" rel=\"StyleSheet\" href=\"winclassic.css\" />");
41 print &ui_form_start("apply_hdparm.cgi");
42 print &ui_hidden("drive", $d->{'device'});
43 print &ui_table_start($text{'hdparm_label'}, "width=100%", 4);
46 print &ui_table_row(&hlink($text{'hdparm_conf_X'}, 'X'),
47 &ui_select("X", $hdparm{'X'},
48 [ [ "0", $text{ 'hdparm_conf_X_defaut' } ], [ "1", $text{ 'hdparm_conf_X_disable' } ], [ "9", "PIO mode 1", ], [ "10", "PIO mode 2" ], [ "11", "PIO mode 3" ], [ "12", "PIO mode 4" ], [ "32", "Multimode DMA 0" ], [ "33", "Multimode DMA 1" ], [ "34", "Multimode DMA 2" ], [ "64", "Ultra DMA 0" ], [ "65", "Ultra DMA 1" ], [ "66", "Ultra DMA 2" ] ], 1, 0, 1));
51 print &ui_table_row(&hlink($text{'hdparm_conf_a'},"a"),
52 &ui_textbox("a", $hdparm{'a'}, 2));
54 # Other yes/no options
55 foreach $o ('d', 'A', 'W', 'u', 'k', 'K', 'r', 'P') {
56 print &ui_table_row(&hlink($text{'hdparm_conf_'.$o}, $o),
57 &ui_yesno_radio($o, $hdparm{$o}));
60 # Standby timeout (slider)
61 print &ui_table_row(&hlink($text{'hdparm_conf_S'}, 'S'),
62 &p_slider( "S", 0, 251, 0), 3);
65 print &ui_table_row(&hlink($text{'hdparm_conf_c'}, 'c'),
66 &ui_radio('c', $hdparm{'c'},
67 [ [ 0, $text{'hdparm_disable'} ],
68 [ 1, $text{'hdparm_enable'} ],
69 [ 3, $text{'hdparm_enable_special'} ] ]), 3);
71 # Sector count for multiple sector I/O
72 print &ui_table_row(&hlink($text{'hdparm_conf_m'}, 'm'),
73 &ui_radio('m', $hdparm{'m'},
74 [ [ 0, $text{'hdparm_disable'} ],
75 [ 2 ], [ 4 ], [ 8 ], [ 16 ], [ 32 ] ]), 3);
77 print &ui_table_end();
78 print &ui_form_end([ [ 'action', $text{'hdparm_apply'} ],
79 [ 'action', $text{'hdparm_speed'} ] ]);
81 &ui_print_footer( "", $text{ 'index_return' } );
83 # Javascript for slider
84 print "<script type=\"text/javascript\">
86 var sliderEl = document.getElementById ?
87 document.getElementById(\"S-slider\") : null;
88 var inputEl = document.forms[0][\"S\"];
90 var s = new Slider(sliderEl, inputEl);
92 function format_time(t_sec) {
94 if ( t_sec >= 3600 ) {
95 var t_hour = (t_sec - (t_sec % 3600))/3600;
96 return t_hour + \" hours \" + format_time(t_sec % 3600);
97 } else if ( t_sec >= 60 ){
98 var t_min = (t_sec - (t_sec % 60))/60;
99 return t_min + \" minutes \" + format_time(t_sec % 60);;
100 } else if ( t_sec > 0 ){
101 return t_sec + \" seconds \";
107 s.onchange = function () {
108 var flag = s.getValue();
113 t_sec = (flag -240) * 30 * 60;
117 document.getElementById(\"S-text-id\").value = \"always on\";
119 document.getElementById(\"S-text-id\").value = format_time(t_sec);
132 my ( $name, $min, $max, $default ) = @_;
135 $out .= "<div class=\"slider\" id=\"". $name ."-slider\" tabIndex=\"1\">";
136 $out .= "<input class=\"slider-input\" id=\"".$name."-slider-input\"";
137 $out .= " name=\"".$name."\"/></div>";
138 $out .= "<input type=text name=\"".$name."-text\" id=\"".$name."-text-id\" readonly value=\"This field is not used\" >";