###### -*-perl-*- # routines to format partitions # This variable will be used later to determine the # filesystem type for each partition formatted here %fsformat = (); @selected_devices = (); $fstype = "ext2"; $badblock_check = ""; sub select_format_disks { local ( %fsinfolist, $dev, $devsize ); local ( %fsmenu, $msg ); local ( $p, $r ); if ($fs_mounted) { &rhs_msgbox("Error", < Your filesystems are already mounted (and thus, they are most likely formatted). If you still wish to format them, unmount them first. > EOM , 60); return 0; } &rhs_infobox ( "Filesystems", < Looking for Linux partitions... > EOM , 60); %fsinfolist = (); open(SAVEERR, ">&STDERR"); open(STDERR, ">/dev/null"); open(PROC, "fdisk -l |") || &newdie("Can't call fdisk!"); while () { if (/^(.{10}).{5}(.{31}).*Linux native$/) { $p = $1; $r = $2; $p =~ s/\s$//; $fsinfolist{$p} = "$r"; } } close PROC; open(STDERR, ">&SAVEERR"); if (keys(%fsinfolist) == 0) { &rhs_msgbox ( "Filesystems", < You do not appear to have any Linux partitions on your system. You must create at least one before continuing. > EOM , 60); return 0; } do { %fsformat = (); %fs_menu = %fsinfolist; foreach $dev (keys %fs_menu) { $fs_menu{$dev} = sprintf("%7s %s", $fsformat{$dev}, $fs_menu{$dev}); } if (! &rhs_checklista("Filesystems", < Use the spacebar to select all partitions to format. Then select OK. > > Device Type Begin Start End Blocks EOM , 65, %fs_menu)) { return 0; } if (! scalar(@dialog_result)) { next; } @selected_devices = sort @dialog_result; foreach $dev (@selected_devices) { $fsformat{$dev} = $fstype; } if ($express_install) { $dialog_result = "No"; } else { if (! &rhs_menu("Filesystems", < Check for bad blocks on the hard drive during formatting? > EOM , 50, 2, "Yes", "Check for bad blocks", "No", "Do not check for bad blocks")) { next; } } if ($dialog_result eq "Yes") { $badblock_check = "-c"; } else { $badblock_check = ""; } $msg = < Are you absolutely certain that you want to format? > EOM ; foreach $dev (@selected_devices) { $msg .= <$dev EOM ; } $msg .= < All data on these partitions will be lost! > EOM ; } while (! &rhs_yesno("Filesystems", $msg, 70)); return 1; } sub format_disks { local ( $dev, $devsize, %fsinfolist, $msg, $res, $retval ); $retval = 1; %fsinfolist = (); open(SAVEERR, ">&STDERR"); open(STDERR, ">/dev/null"); open(PROC, "fdisk -l |") || &newdie("Can't call fdisk!"); while () { if (/^(.{10}).{5}(.{31}).*Linux native$/) { $p = $1; $r = $2; $p =~ s/\s$//; $fsinfolist{$p} = "$r"; } } close PROC; open(STDERR, ">&SAVEERR"); if (keys(%fsinfolist) == 0) { &rhs_msgbox ( "Filesystems", < Your Linux partitions have disappeared. > You must create at least one before continuing. > EOM , 60); return 0; } foreach $dev (@selected_devices) { $fsinfolist{$dev} =~ /^.*(.{9})$/; $devsize = $1; chop($devsize); $msg = < Formatting $dev with $fstype filesystem. > EOM ; if ($badblock_check eq "-c") { $msg .= < EOM ; } &rhs_infobox("Formatting Filesystems", $msg, 65); if ($express_install) { $res = &invoke_no_output("mke2fs $badblock_check $dev"); } else { $res = &invoke("mke2fs $badblock_check $dev"); } if ($res) { $retval = 0; &rhs_msgbox("Error", < An error occurred while formatting $dev. > EOM , 60); delete $fsformat{$dev}; } } return $retval; } ############# 1;