Disk labels in setup_harddisks
Devlin
devlin at softhome.net
Tue Jul 9 02:10:59 CEST 2002
The following patch makes setup_harddisks handle alphanumeric labels.
At a code level, it also generalizes the ParseConfigFile subroutine's
"extra option" checking. The previous patch I submitted only works with
numeric labels.
This patch changes the way to check if an option is present for a
partition in ParseConfigFile. Instead of checking with
($options =~ /\boption\b/i)
, check [after applying this patch] with
CheckOption($options, "option")
. "option" can be a regex with setup_harddisks patched, as it can be
without the patch.
I generalized so the patch doesn't complicate ParseConfigFile. The
patch complicates option checking, by introducing possible conflict
between extra option names and -L parameters. With the CheckOption
subroutine, it is still easy to add options (like -L) that take a string
parameter, and to add new checks for extra options.
--- setup_harddisks.orig Mon Jun 24 20:38:38 2002
+++ setup_harddisks Mon Jul 8 18:02:07 2002
@@ -37,6 +37,7 @@
# [-d] default: no DOS alignment
#
#---------------------------------------------------
+# Last changes: 08.07.2002 by Devlin <devlin at softhome.net>
# Last changes: 14.05.2002 by Thomas Lange use strict
# Last changes: 04.05.2002 by Thomas Lange use strict
# Last changes: 29.04.2002 by Thomas Lange add swaplist
@@ -110,25 +111,24 @@
# default is "default"
#
# After the semicolon there could be extra options like:
-# -i <bytes> : Bytes per inodes
-# (only ext2/3 filesystem)
-# -m <blocks>% : reserved blocks percentage for superuser
-# (only ext2/3 filesystem)
-# -j : format in ext3
-# -c : check for bad blocks
-# format : Always format this partition even if preserve
-# lazyformat : Do not format if partition has not moved
-# (useful for testing the installation)
-# boot : make this partition the boot-partition (the
-# linux root filesystem is the default)
-# ext2 : Extended 2 filesystem (this is the default)
-# swap : swap partition
-# dosfat16 : DOS 16bit FAT file system
-# winfat32 : Win95 FAT32 file system
-# writable : mounts a preserved partition writable
-# reiser : reiserfs
-# -h <hash> : set reiserfs hash
-# -v <ver> : set reiserfs version
+# -c : check for bad blocks
+# format : Always format this partition even if preserve
+# lazyformat : Do not format if partition has not moved
+# (useful for testing the installation)
+# boot : make this partition the boot-partition (the
+# linux root filesystem is the default)
+# ext2 : Extended 2 filesystem (this is the default)
+# -i <bytes> : Bytes per inodes
+# -m <blocks>% : reserved blocks percentage for superuser
+# -j : format in ext3
+# -L <label> : use a disk label
+# swap : swap partition
+# dosfat16 : DOS 16bit FAT file system
+# winfat32 : Win95 FAT32 file system
+# writable : mounts a preserved partition writable
+# reiser : reiserfs
+# -h <hash> : set reiserfs hash
+# -v <ver> : set reiserfs version
#
use strict;
# getopts variables:
@@ -310,6 +310,17 @@
}
#****************************************************
+# check for an option
+#****************************************************
+sub CheckOption{
+ # a list of all options that take string parameters
+ my $stringopts = "L";
+
+ if ( $_[1] == "" ) { return 1==0; }
+ return $_[0] =~ /\b(?<!-[$stringopts] )(?i:$_[1])\b/;
+}
+
+#****************************************************
# parse config-file
#****************************************************
sub ParseConfigFile{
@@ -325,6 +336,7 @@
my $a = 1, my $paras ="", my $number=0;
while (my $line = <FILE>){
chomp($line);
+ $line =~ s/\s+/ /g;
$a++;
next if( $line =~ /^#|^\s*$/ );
@@ -383,7 +395,7 @@
if($mountpoint eq "swap"){
$NofSwapPart++;
$mountpoint = "swap$NofSwapPart";
- ($options !~ /\bswap\b/i) && ($options .= " swap");
+ !CheckOption($options, "swap") && ($options .= "
swap");
($fstaboptions) || ($fstaboptions = "sw");
}
if($mountpoint =~ m#^/#){
@@ -397,7 +409,7 @@
($PrimPartNo >4 ) && die "ERROR: Too much primary
partitions (max 4).".
" All logicals together need one
primary too.\n";
$MountpointPart{$mountpoint} =
PartName($disk,$PrimPartNo);
- if($options =~ /\bboot\b/i){
+ if(CheckOption($options, "boot")){
($BootPartition) && die "ERROR: only one
partition can be bootable at a time.";
$BootPartition = $MountpointPart{$mountpoint};
$BOOT_DEVICE = $disk;
@@ -421,7 +433,7 @@
$MountpointPart{$extmp} =
PartName($disk,$PrimPartNo);
$DiskMountpoints{$disk} .= " $extmp";
}
- ($options =~ /\bboot\b/i) && die "ERROR: line $a,
only primary partitions can be bootable.\n";
+ CheckOption($options, "boot") && die "ERROR: line
$a, only primary partitions can be bootable.\n";
}
($DiskMountpoints{$disk} =~ /\b$mountpoint\b/)
&& die "ERROR in config file line $a, Mountpoint
redefined: $mountpoint\n$line\n";
@@ -461,7 +473,7 @@
&& die "ERROR: unable to preserve partitions of
size 0.\n$line\n ";
} else {
# If not preserve we must know the filesystemtype
- ($options !~
/\b(ext2|ext3|auto|swap|dosfat16|winfat32|reiser)\b/i ) &&
($options .= " auto");
+ CheckOption($options,
"(ext2|ext3|auto|swap|dosfat16|winfat32|reiser)" ) && ($options .= "
auto");
}
if($size =~ /^(\d*)(\-?)(\d*)$/){
$Min = $1;
@@ -488,10 +500,10 @@
# fstaboptions
$MPfstaboptions{$mountpoint} = $fstaboptions;
# extra options
- ($options =~ /\b(ext[23]|auto)\b/i) &&
($MPID{$mountpoint} = 83); # Linux native
- ($options =~ /\bswap\b/i) && ($MPID{$mountpoint} =
82); # Linux swap
- ($options =~ /\bdosfat16\b/i) && ($MPID{$mountpoint} =
6); # DOS FAT 16bit (>=32MB, will be changed later)
- ($options =~ /\bwinfat32\b/i) && ($MPID{$mountpoint} =
"b"); # Win 95 FAT 32
+ CheckOption($options, "(ext[23]|auto)") &&
($MPID{$mountpoint} = 83); # Linux native
+ CheckOption($options, "swap") && ($MPID{$mountpoint} =
82); # Linux swap
+ CheckOption($options, "dosfat16") &&
($MPID{$mountpoint} = 6); # DOS FAT 16bit (>=32MB, will be changed later)
+ CheckOption($options, "winfat32") &&
($MPID{$mountpoint} = "b"); # Win 95 FAT 32
$MPOptions{$mountpoint} = $options;
if($test == 1){
print
"$mountpoint,$MPMinSize{$mountpoint}-$MPMaxSize{$mountpoint},";
@@ -801,6 +813,7 @@
($MPOptions{$mountpoint} =~ /(\-i\s*\d+)\b/) &&
($command .= " $1");
($MPOptions{$mountpoint} =~ /(\-m\s*\d+)\b/) &&
($command .= " $1");
($MPOptions{$mountpoint} =~ /(\-j)\b/) && ($command .= "
$1");
+ ($MPOptions{$mountpoint} =~ /(\-L\s*\S+)\b/) &&
($command .= " $1");
$command .= " /dev/$device";
print " $command\n";
if ($test != 1){
More information about the linux-fai
mailing list