📄 fdisk-lib.pl
字号:
elsif ($_[0] eq "minix") { local(@plist, $disk, $part, $i, @pinfo); $cmd = "mkfs -t minix"; $cmd .= &opt_check("minix_n", '14|30', "-n "); $cmd .= &opt_check("minix_i", '\d+', "-i "); $cmd .= $in{'minix_c'} ? " -c" : ""; $cmd .= " $_[1]"; $cmd .= &opt_check("minix_b", '\d+', " "); }return $cmd;}# can_tune(type)# Returns 1 if this filesystem type can be tunedsub can_tune{return ($_[0] eq "ext2");}# tunefs_options(type)# Output HTML for tuning options for some filesystem typesub tunefs_options{if ($_[0] eq "ext2") { &opt_input("tunefs_c", "", 1); print "<td align=right><b>$text{'tunefs_e'}</b></td> <td>\n"; print "<input type=radio name=tunefs_e_def value=1 checked> ", "$text{'opt_default'}\n"; print " <input type=radio name=tunefs_e_def value=0>\n"; print "<select name=tunefs_e>\n"; print "<option value=continue> $text{'tunefs_continue'}\n"; print "<option value=remount-ro> $text{'tunefs_remount'}\n"; print "<option value=panic> $text{'tunefs_panic'}\n"; print "</select></td> </tr>\n"; print "<tr> <td align=right><b>$text{'tunefs_u'}</b></td> <td>\n"; print "<input type=radio name=tunefs_u_def value=1 checked> ", "$text{'opt_default'}\n"; print " <input type=radio name=tunefs_u_def value=0>\n"; print "<input name=tunefs_u size=8> ", &user_chooser_button("tunefs_u", 0),"</td>\n"; print "<td align=right><b>$text{'tunefs_g'}</b></td> <td>\n"; print "<input type=radio name=tunefs_g_def value=1 checked> ", "$text{'opt_default'}\n"; print " <input type=radio name=tunefs_g_def value=0>\n"; print "<input name=tunefs_g size=8> ", &group_chooser_button("tunefs_g", 0),"</td> </tr>\n"; &opt_input("tunefs_m", "%", 1); $tsel = "<select name=tunefs_i_unit>\n". "<option value=d> $text{'tunefs_days'}\n". "<option value=w> $text{'tunefs_weeks'}\n". "<option value=m> $text{'tunefs_months'}\n". "</select>\n"; &opt_input("tunefs_i", $tsel, 0); }}# tunefs_parse(type, device)# Returns the tuning command based on user inputssub tunefs_parse{if ($_[0] eq "ext2") { $cmd = "tune2fs"; $cmd .= &opt_check("tunefs_c", '\d+', "-c"); $cmd .= $in{'tunefs_e_def'} ? "" : " -e$in{'tunefs_e'}"; $cmd .= $in{'tunefs_u_def'} ? "" : " -u".getpwnam($in{'tunefs_u'}); $cmd .= $in{'tunefs_g_def'} ? "" : " -g".getgrnam($in{'tunefs_g'}); $cmd .= &opt_check("tunefs_m",'\d+',"-m"); $cmd .= &opt_check("tunefs_i", '\d+', "-i"). ($in{'tunefs_i_def'} ? "" : $in{'tunefs_i_unit'}); $cmd .= " $_[1]"; }return $cmd;}# need_reboot(disk)# Returns 1 if a reboot is needed after changing the partitions on some disksub need_reboot{local $un = `uname -r`;return $un =~ /^2\.0\./ || $un =~ /^1\./ || $un =~ /^0\./;}# device_status(device)# Returns an array of directory, type, mountedsub device_status{local ($mounted) = grep { $_->[1] eq $_[0] } &foreign_call("mount", "list_mounted");local ($mount) = grep { $_->[1] eq $_[0] } &foreign_call("mount", "list_mounts");if ($mounted) { return ($mounted->[0], $mounted->[2], 1); }elsif ($mount) { return ($mount->[0], $mount->[2], 0); }else { return (); }}# can_fsck(type)# Returns 1 if some filesystem type can fsck'dsub can_fsck{return ($_[0] eq "ext2" && &has_command("fsck.ext2") || $_[0] eq "minix" && &has_command("fsck.minix"));}# fsck_command(type, device)# Returns the fsck command to unconditionally check a filesystemsub fsck_command{if ($_[0] eq "ext2") { return "fsck -t ext2 -p $_[1]"; }elsif ($_[0] eq "minix") { return "fsck -t minix -a $_[1]"; }}# fsck_error(code)# Returns a description of an exit code from fscksub fsck_error{return $text{"fsck_err$_[0]"} ? $text{"fsck_err$_[0]"} : &text("fsck_unknown", $_[0]);}# partition_select(name, value, mode, &found)# Returns HTML for selecting a disk or partition# mode 0 = floppies and disk partitions# 1 = disks# 2 = floppies and disks and disk partitions# 3 = disk partitionssub partition_select{local $rv = "<select name=$_[0]>\n";local ($found, $d, $p);if ($_[2] == 0 || $_[2] == 2) { $rv .= sprintf "<option %s value=/dev/fd0>%s\n", $_[1] eq "/dev/fd0" ? "selected" : "", &text('select_fd', 0); $rv .= sprintf "<option %s value=/dev/fd1>%s\n", $_[1] eq "/dev/fd1" ? "selected" : "", &text('select_fd', 1); $found++ if ($_[1] =~ /^\/dev\/fd[01]$/); }local @dlist = &list_disks();foreach $d (@dlist) { local $dev = $d->{'device'}; if ($_[2] == 1 || $_[2] == 2) { local $name = &text('select_device', uc($d->{'type'}), uc(substr($dev, -1))); $name .= " ($d->{'model'})" if ($d->{'model'}); $rv .= sprintf "<option value=%s %s>%s\n", $dev, $_[1] eq $dev ? "selected" : "", $name; $found++ if ($dev eq $_[1]); } if ($_[2] == 0 || $_[2] == 2 || $_[2] == 3) { local @parts = &list_partitions($dev); foreach $p (@parts) { next if ($p->{'extended'}); local $pdev = $dev.$p->{'number'}; local $name = &text('select_part', uc($d->{'type'}), uc(substr($dev, -1)), $p->{'number'}); $name .= " (".&tag_name($p->{'type'}).")" if (&tag_name($p->{'type'})); $rv .= sprintf "<option %s value=%s>%s\n", $_[1] eq $pdev ? "selected" : "", $pdev, $name; $found++ if ($_[1] eq $pdev); } } }if (!$found && $_[1] && !$_[3]) { $rv .= "<option selected>$_[1]\n"; }if ($_[3]) { ${$_[3]} = $found; }$rv .= "</select>\n";return $rv;}############################################################################## Internal functions#############################################################################sub open_fdisk{local $fpath = &has_command("fdisk");&error("<tt>fdisk</tt> command not found") if (!$fpath);($fh, $fpid) = &foreign_call("proc", "pty_process_exec", $fpath, @_);}sub close_fdisk{close($fh); kill('TERM', $fpid);}sub wprint{syswrite($fh, $_[0], length($_[0]));}sub opt_input{print $_[2] ? "<tr>" : "";print "<td align=right><b>$text{$_[0]}</b></td>\n";print "<td nowrap><input type=radio name=$_[0]_def value=1 checked> ", $text{'opt_default'},"\n";print " <input type=radio name=$_[0]_def value=0>\n";print "<input name=$_[0] size=6> $_[1]</td>";print $_[2] ? "\n" : "</tr>\n";}sub opt_check{if ($in{"$_[0]_def"}) { return ""; }elsif ($in{$_[0]} !~ /^$_[1]$/) { &error(&text('opt_error', $in{$_[0]}, $text{$_[0]})); }else { return " $_[2] $in{$_[0]}"; }}%tags = ('0', 'Empty', '1', 'FAT12', '2', 'XENIX root', '3', 'XENIX usr', '4', 'FAT16 <32M', '6', 'FAT16', '7', 'HPFS/NTFS', '8', 'AIX', '9', 'AIX bootable', 'a', 'OS/2 boot manager', 'b', 'Win95 FAT32', 'c', 'Win95 FAT32 LBA', 'e', 'Win95 FAT16 LBA', '10', 'OPUS', '11', 'Hidden FAT12', '12', 'Compaq diagnostic', '14', 'Hidden FAT16 < 32M', '16', 'Hidden FAT16', '17', 'Hidden HPFS/NTFS', '18', 'AST Windows swapfile', '1b', 'Hidden Win95 FAT (1b)', '1c', 'Hidden Win95 FAT (1c)', '1e', 'Hidden Win95 FAT (1e)', '24', 'NEC DOS', '3c', 'PartitionMagic recovery', '40', 'Venix 80286', '41', 'PPC PReP boot', '42', 'SFS', '4d', 'QNX 4.x', '4e', 'QNX 4.x 2nd partition', '4f', 'QNX 4.x 3rd partition', '50', 'OnTrack DM', '51', 'OnTrack DM6 Aux1', '52', 'CP/M', '53', 'OnTrack DM6 Aux3', '54', 'OnTrack DM6', '55', 'EZ-Drive', '56', 'Golden Bow', '5c', 'Priam Edisk', '61', 'SpeedStor', '63', 'GNU HURD or SysV', '64', 'Novell Netware 286', '65', 'Novell Netware 386', '70', 'DiskSecure Multi-Boot', '75', 'PC/IX', '80', 'Old Minix', '81', 'Minix / Old Linux / Solaris', '82', 'Linux swap', '83', 'Linux', '84', 'OS/2 hidden C: drive', '85', 'Linux extended', '86', 'NTFS volume set (86)', '87', 'NTFS volume set (87)', '93', 'Amoeba', '94', 'Amoeba BBT', 'a0', 'IBM Thinkpad hibernation', 'a5', 'BSD/386', 'a6', 'OpenBSD', 'a7', 'NeXTSTEP', 'b7', 'BSDI filesystem', 'b8', 'BSDI swap', 'c1', 'DRDOS/sec FAT12', 'c4', 'DRDOS/sec FAT16 <32M', 'c6', 'DRDOS/sec FAT16', 'c7', 'Syrinx', 'db', 'CP/M / CTOS', 'e1', 'DOS access', 'e3', 'DOS read-only', 'e4', 'SpeedStor', 'eb', 'BeOS', 'f1', 'SpeedStor', 'f4', 'SpeedStor large partition', 'f2', 'DOS secondary', 'fd', 'Linux raid', 'fe', 'LANstep', 'ff', 'BBT' );%hidden_tags = ( '5', 'Extended', 'f', 'Win95 extended LBA', ); %fstypes = ("ext2","Linux Native", "minix","Minix", "msdos","MS-DOS", "vfat","Windows 95");# can_edit_disk(device)sub can_edit_disk{foreach (split(/\s+/, $access{'disks'})) { return 1 if ($_ eq "*" || $_ eq $_[0]); }return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -