home *** CD-ROM | disk | FTP | other *** search
/ Caldera Network Desktop 1.0 / caldera-network-desktop-1.0.bin / images / ramdisk2-beta.img / usr / lib / perl / fdisk < prev    next >
Text File  |  1995-12-04  |  5KB  |  209 lines

  1. # Handles partitioning disks
  2.  
  3. sub get_partitions {
  4.     local ($type) = @_;
  5.     local ($bsdtype, $parttype);
  6.     local ($device, $start, $stop, $blocks, %partinfo, $lastbsddev);
  7.  
  8.     $type eq "swap" && ($bsdtype = "swap", $parttype = "Linux swap");
  9.     $type eq "ext2" && ($bsdtype = "ext2", $parttype = "Linux native");
  10.  
  11.     open(SAVEERR, ">&STDERR");
  12.     open(STDERR, ">/dev/null");
  13.     open(PROC, "fdisk -l |") || die "Can't call fdisk!";
  14.     while (<PROC>) {
  15.     if (/^\/dev\/([a-z0-9]+) *([0-9]+) *[0-9]+ *([0-9]+) *([0-9]+).*$parttype/) {
  16.         $device = "/dev/$1";
  17.         $start = $2;
  18.         $stop = $3;
  19.         $blocks = $4;
  20.         $partinfo{$device} = "$start $stop $blocks";
  21.     } elsif (/^BSD label for device: *\/dev\/([a-z0-9]+)/) {
  22.         $lastbsddev = $1;
  23.         } elsif (/([a-z]): +([0-9]+) +([0-9]+) *$bsdtype/) {
  24.         $device = ord($1) - ord("a") + 1;
  25.         $device = "/dev/$lastbsddev$device";
  26.         $start = $3;
  27.         $blocks = $2;
  28.         $stop = $start + $blocks;
  29.         $partinfo{$device} = "$start $stop $blocks";
  30.     }
  31.     }
  32.  
  33.     close PROC;
  34.     open(STDERR, ">&SAVEERR");
  35.  
  36.     return %partinfo;
  37. }
  38.  
  39. sub partition_disks {
  40.     local ( $ret );
  41.  
  42.     if (! &rhs_yesno ( "Disk Partitions",
  43. <<EOM
  44. You must have one or more free partitions for your
  45. Linux filesystem.  In addition, you may want to create
  46. a swap partition.  If you have already created partitions
  47. for your new Linux system you can skip this step.
  48. >
  49. Do you need to partition your disks?
  50. >
  51. EOM
  52.               , 70)) {
  53.     return 1;
  54.     }
  55.  
  56.     if ($instarch eq "i386") {
  57.     if (! &rhs_yesno ( "Disk Partitions",
  58. <<EOM
  59. >
  60. If you will be using OS/2 on your system in addition
  61. to Linux, you must use the OS/2 partitioning
  62. software.  OS/2 will not recognize partitions created
  63. by the Linux partitioning software.
  64. >
  65. If you have not done this, choose the Reboot option,
  66. partition your drives with the OS/2 software, and
  67. restart the Red Hat installation.
  68. >
  69. Continue?
  70. >
  71. EOM
  72.                   , 70)) {
  73.         return 0;
  74.         }
  75.     }
  76.  
  77.     if ($instarch eq "i386") {
  78.         &rhs_msgbox ( "Disk Partitions",
  79. <<EOM
  80. >
  81. Each partition used for the Linux filesystem must be set as
  82. type 83. Each partition used for a Linux swap partition
  83. must be set as type 82.
  84. >
  85. EOM
  86.              , 70);
  87.     } else {
  88.         &rhs_msgbox ( "Disk Partitions",
  89. <<EOM
  90. >
  91. There are two styles of disk partitioning available. The first
  92. is PC style partitioning, which is done with fdisk. If you are
  93. using the ARC firmware, you must use this.
  94.  
  95. BSD style disk labeling is also available. You may manipulate
  96. disk labels with fdisk by typing 'b<Enter>' as the first command
  97. in fdisk. Another program, minlabel, also allows you to use
  98. disk labels.
  99. >
  100. EOM
  101.              , 70);
  102.     }
  103.  
  104.     &_partition_disks;
  105. }
  106.  
  107. sub _partition_disks {
  108.     local ( $ret, $snarf, $disklist, $diskinfolist, $msg, $ent );
  109.     local ( @choices );
  110.  
  111.     $ret = &rhs_infobox ( "Disk Partitioning",
  112. <<EOM
  113. >
  114. Discovering what hard drives are attached to the system...
  115. >
  116. EOM
  117.                         , 70);
  118.  
  119.     @disklist = ();
  120.     @diskinfolist = ();
  121.     open(SAVEERR, ">&STDERR");
  122.     open(STDERR, ">/dev/null");
  123.     open(PROC, "fdisk -l |") || &newdie("Can't call fdisk!");
  124.     while (<PROC>) {
  125.         if (/^Disk (.*):(.*)$/) {
  126.             $disklist[@disklist] = $1;
  127.             $diskinfolist[@diskinfolist] = "$1:$2";
  128.     } elsif (/^BSD label for device: *\/dev\/([a-z0-9]+)/) {
  129.         $disklist[@disklist] = "/dev/$1";
  130.             $diskinfolist[@diskinfolist] = "/dev/$1:hard disk";
  131.     }
  132.     }
  133.     close PROC;
  134.     open(STDERR, ">&SAVEERR");
  135.  
  136.     $msg =
  137. <<EOM
  138. The following disks were found:
  139. >
  140. EOM
  141.     ;
  142.     foreach $ent (@diskinfolist) {
  143.         $msg .= ">" . $ent . "\n";
  144.     }
  145.  
  146.     if ($instarch eq "i386") {
  147.     @choices = ("fdisk", "Partition a disk with fdisk (command line)",
  148.                 "cfdisk", "Partition a disk with cfdisk (full screen)");
  149.     } else {
  150.     @choices = ("fdisk", "Partition a disk with fdisk",
  151.                 "minlabel", "Partition a disk with minlabel");
  152.     }
  153.  
  154.     while (1) {
  155.         if (! &rhs_menu("Disk Partitioning", $msg,
  156.             70, (($#choices + 1) / 2) + 1,
  157.             @choices,
  158.             "done", "Done with partitioning")) {
  159.         last;
  160.     }
  161.     last if ($dialog_result eq "done");
  162.         &partition_disk ("fdisk", @disklist) if ($dialog_result eq "fdisk");
  163.         &partition_disk ("cfdisk", @disklist) if ($dialog_result eq "cfdisk");
  164.         &partition_disk ("minlabel", @disklist) if ($dialog_result eq "minlabel");
  165.     }
  166.  
  167.     &rhs_menu("Disk Partitioning",
  168. <<EOM
  169. >
  170. If fdisk (or cfdisk) complained about not being able
  171. to reload the partition tables or you are using disk
  172. labeling, you should reinstall now.
  173. >
  174. After rebooting skip the partitioning step and continue
  175. with the rest of the installation.
  176. >
  177. EOM
  178.           , 70, 2,
  179.           "Reboot", "Reboot now",
  180.           "Continue", "Continue the install process");
  181.  
  182.     exit(0) if ($dialog_result eq "Reboot");
  183.  
  184.     return 1;
  185. }
  186.  
  187. sub partition_disk {
  188.     local ( $fdisk, @disklist ) = @_;
  189.     local ( $ret );
  190.  
  191.     if (! &rhs_menul ( "Disk Partitioning",
  192. <<EOM
  193. >
  194. Which disk do you want to partition?
  195. >
  196. EOM
  197.               , 50, scalar(@disklist), @disklist)) {
  198.     return 1;
  199.     }
  200.  
  201.     &invoke("$fdisk $dialog_result");
  202.  
  203.     print "\nHit enter to continue";
  204.     <STDIN>;
  205. }
  206.  
  207. ############
  208. 1;
  209.