hop siup z /dev/sd{a,b}... [testcase]
Paweł Sikora
pluto at agmk.net
Thu Feb 16 10:52:26 CET 2012
$ sh -x test.sh
+ ROOT=/dev/sda1
+ device=/dev/no_partition_found
+ awk -v c=/dev/sda1
BEGIN {
num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
num_pattern = "[0-9a-f]" num_pattern_short;
dev_pattern = "[hms][a-z][a-z]([0-9])+";
partition = "no_partition_found";
min = -1; maj = -1;
sub("^0x", "", c);
if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
if (c ~ "^" num_pattern "$") {
maj = sprintf("%s",substr(c,1,2));
min = sprintf("%s",substr(c,3));
}
if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
if (c ~ "^" dev_pattern "$") partition = c;
}
$4 ~ partition { maj = $1; min = $2; }
$1 ~ maj && $2 ~ min { partition = $4; }
END {
printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
}
./test.partitions
+ eval device=/dev/sdb; maj=8; min=1;
+ device=/dev/sdb
+ maj=8
+ min=1
jak widac z ROOT=/dev/sda1 wyszlo /dev/sdb :>
uprasza sie autorow tego awk-owego cuda o poprawke ;)
-------------- nast�pna cz��� ---------
A non-text attachment was scrubbed...
Name: test.sh
Type: application/x-shellscript
Size: 820 bytes
Desc: nie znany
URL: </mailman/pipermail/pld-devel-pl/attachments/20120216/7df0f2b7/attachment.bin>
-------------- nast�pna cz��� ---------
major minor #blocks name
8 0 195359927 sda
8 1 16000708 sda1
8 2 4000185 sda2
8 3 175359002 sda3
8 16 976758455 sdb
11 0 1048575 sr0
254 0 976756736 dm-0
254 1 175357952 dm-1
More information about the pld-devel-pl
mailing list