… | |
… | |
28 | |
28 | |
29 | 1.3 |
29 | 1.3 |
30 | - output of pbcdedit elements --json has changed, as it didn't |
30 | - output of pbcdedit elements --json has changed, as it didn't |
31 | take the reorganisation by classes fully into account. |
31 | take the reorganisation by classes fully into account. |
32 | - json schema bumped to 3. |
32 | - json schema bumped to 3. |
|
|
33 | - new "bcd-device" and "bcd-legacy-device" subcommands. |
33 | |
34 | |
34 | 1.2 Fri Aug 16 00:20:41 CEST 2019 |
35 | 1.2 Fri Aug 16 00:20:41 CEST 2019 |
35 | - bcde element names now depend on the bcd object type they are in, |
36 | - bcde element names now depend on the bcd object type they are in, |
36 | also affects "elements" output. |
37 | also affects "elements" output. |
37 | - json schema bumped to 2. |
38 | - json schema bumped to 2. |
… | |
… | |
151 | a mounted C</sys> file system. |
152 | a mounted C</sys> file system. |
152 | |
153 | |
153 | The output will be a list of all partitions in the system and C<partition> |
154 | The output will be a list of all partitions in the system and C<partition> |
154 | descriptors for GPT and both C<legacypartition> and C<partition> |
155 | descriptors for GPT and both C<legacypartition> and C<partition> |
155 | descriptors for MBR partitions. |
156 | descriptors for MBR partitions. |
|
|
157 | |
|
|
158 | =item C<bcd-device> F<path> |
|
|
159 | |
|
|
160 | Tries to find the BCD device element for the given device, which currently |
|
|
161 | must be a a partition of some kind. Prints the C<partition=> descriptor as |
|
|
162 | a result, or nothing. Exit status will be true on success, and false on |
|
|
163 | failure. |
|
|
164 | |
|
|
165 | Like C<lsblk>, above, this likely only works on GNU/Linux systems. |
|
|
166 | |
|
|
167 | Example: print the partition descriptor of tghe partition with label DATA. |
|
|
168 | |
|
|
169 | $ pbcdedit bcd-device /dev/disk/by-label/DATA |
|
|
170 | partition=<null>,harddisk,mbr,47cbc08a,213579202560 |
|
|
171 | |
|
|
172 | =item C<bcd-legacy-device> F<path> |
|
|
173 | |
|
|
174 | Like above, but uses a C<legacypartition> descriptor instead. |
156 | |
175 | |
157 | =item C<objects> [C<--json>] |
176 | =item C<objects> [C<--json>] |
158 | |
177 | |
159 | Outputs two tables: a table listing all type aliases with their hex BCD |
178 | Outputs two tables: a table listing all type aliases with their hex BCD |
160 | element ID, and all object name aliases with their GUID and default type |
179 | element ID, and all object name aliases with their GUID and default type |
… | |
… | |
2396 | } |
2415 | } |
2397 | |
2416 | |
2398 | } |
2417 | } |
2399 | |
2418 | |
2400 | ############################################################################# |
2419 | ############################################################################# |
2401 | # command line parser |
2420 | # other utilities |
2402 | |
2421 | |
2403 | # json to stdout |
2422 | # json to stdout |
2404 | sub prjson($) { |
2423 | sub prjson($) { |
2405 | print $json_coder->encode ($_[0]); |
2424 | print $json_coder->encode ($_[0]); |
2406 | } |
2425 | } |
… | |
… | |
2410 | my $json; |
2429 | my $json; |
2411 | 1 while read STDIN, $json, 65536, length $json; |
2430 | 1 while read STDIN, $json, 65536, length $json; |
2412 | $json_coder->decode ($json) |
2431 | $json_coder->decode ($json) |
2413 | } |
2432 | } |
2414 | |
2433 | |
2415 | # all subcommands |
2434 | sub lsblk() { |
|
|
2435 | my $lsblk = $json_coder->decode (scalar qx<lsblk --json -o PATH,KNAME,MAJ:MIN,TYPE,PTTYPE,PTUUID,PARTUUID,LABEL,FSTYPE>); |
|
|
2436 | |
|
|
2437 | for my $dev (@{ $lsblk->{blockdevices} }) { |
|
|
2438 | if ($dev->{type} eq "part") { |
|
|
2439 | if ($dev->{pttype} eq "gpt") { |
|
|
2440 | $dev->{bcd_device} = "partition=<null>,harddisk,gpt,$dev->{ptuuid},$dev->{partuuid}"; |
|
|
2441 | } elsif ($dev->{pttype} eq "dos") { # why not "mbr" :( |
|
|
2442 | if ($dev->{partuuid} =~ /^([0-9a-f]{8})-([0-9a-f]{2})\z/i) { |
|
|
2443 | my ($diskid, $partno) = ($1, hex $2); |
|
|
2444 | $dev->{bcd_legacy_device} = "legacypartition=<null>,harddisk,mbr,$diskid,$partno"; |
|
|
2445 | if (open my $fh, "/sys/class/block/$dev->{kname}/start") { |
|
|
2446 | my $start = 512 * readline $fh; |
|
|
2447 | $dev->{bcd_device} = "partition=<null>,harddisk,mbr,$diskid,$start"; |
|
|
2448 | } |
|
|
2449 | } |
|
|
2450 | } |
|
|
2451 | } |
|
|
2452 | } |
|
|
2453 | |
|
|
2454 | $lsblk->{blockdevices} |
|
|
2455 | } |
|
|
2456 | |
|
|
2457 | sub prdev($$) { |
|
|
2458 | my ($path, $attribute) = @_; |
|
|
2459 | |
|
|
2460 | # rather than stat'ing and guessing how devices are encoded, we use lsblk for this |
|
|
2461 | # unfortunately, there doesn't seem to be a way to restrict lsblk to just oned evice, |
|
|
2462 | # so we always assume the first one is it. |
|
|
2463 | my $mm = $json_coder->decode (scalar qx<lsblk -o MAJ:MIN -J \Q$path\E>)->{blockdevices}[0]{"maj:min"}; |
|
|
2464 | |
|
|
2465 | my $lsblk = lsblk; |
|
|
2466 | |
|
|
2467 | for my $dev (@$lsblk) { |
|
|
2468 | if ($dev->{"maj:min"} eq $mm && $dev->{$attribute}) { |
|
|
2469 | say $dev->{$attribute}; |
|
|
2470 | exit 0; |
|
|
2471 | } |
|
|
2472 | } |
|
|
2473 | |
|
|
2474 | exit 1; |
|
|
2475 | } |
|
|
2476 | |
|
|
2477 | ############################################################################# |
|
|
2478 | # command line parser |
|
|
2479 | |
2416 | our %CMD = ( |
2480 | our %CMD = ( |
2417 | help => sub { |
2481 | help => sub { |
2418 | require Pod::Usage; |
2482 | require Pod::Usage; |
2419 | Pod::Usage::pod2usage (-verbose => 2); |
2483 | Pod::Usage::pod2usage (-verbose => 2); |
2420 | }, |
2484 | }, |
… | |
… | |
2534 | "import-regf" => sub { |
2598 | "import-regf" => sub { |
2535 | regf_save shift, rdjson; |
2599 | regf_save shift, rdjson; |
2536 | }, |
2600 | }, |
2537 | |
2601 | |
2538 | lsblk => sub { |
2602 | lsblk => sub { |
|
|
2603 | my $lsblk = lsblk; |
|
|
2604 | |
2539 | printf "%-10s %-8.8s %-6.6s %-3s %s\n", "DEVICE", "LABEL", "FSTYPE", "PT", "DEVICE DESCRIPTOR"; |
2605 | printf "%-10s %-8.8s %-6.6s %-3s %s\n", "DEVICE", "LABEL", "FSTYPE", "PT", "DEVICE DESCRIPTOR"; |
2540 | |
2606 | for my $dev (@$lsblk) { |
2541 | my $lsblk = $json_coder->decode (scalar qx<lsblk --json -o PATH,KNAME,TYPE,PTTYPE,PTUUID,PARTUUID,LABEL,FSTYPE>); |
2607 | for my $bcd ($dev->{bcd_device}, $dev->{bcd_legacy_device}) { |
2542 | |
|
|
2543 | for my $dev (@{ $lsblk->{blockdevices} }) { |
|
|
2544 | my $pr = sub { |
|
|
2545 | printf "%-10s %-8.8s %-6.6s %-3s %s\n", |
2608 | printf "%-10s %-8.8s %-6.6s %-3s %s\n", |
2546 | $dev->{path}, $dev->{label}, $dev->{fstype}, $dev->{pttype}, $_[0]; |
2609 | $dev->{path}, $dev->{label}, $dev->{fstype}, $dev->{pttype}, $bcd |
2547 | }; |
|
|
2548 | |
|
|
2549 | if ($dev->{type} eq "part") { |
|
|
2550 | if ($dev->{pttype} eq "gpt") { |
|
|
2551 | $pr->("partition=<null>,harddisk,gpt,$dev->{ptuuid},$dev->{partuuid}"); |
|
|
2552 | } elsif ($dev->{pttype} eq "dos") { # why not "mbr" :( |
|
|
2553 | if ($dev->{partuuid} =~ /^([0-9a-f]{8})-([0-9a-f]{2})\z/i) { |
|
|
2554 | my ($diskid, $partno) = ($1, hex $2); |
|
|
2555 | $pr->("legacypartition=<null>,harddisk,mbr,$diskid,$partno"); |
|
|
2556 | if (open my $fh, "/sys/class/block/$dev->{kname}/start") { |
|
|
2557 | my $start = 512 * readline $fh; |
|
|
2558 | $pr->("partition=<null>,harddisk,mbr,$diskid,$start"); |
|
|
2559 | } |
|
|
2560 | } |
2610 | if $bcd; |
2561 | } |
|
|
2562 | } |
2611 | } |
2563 | } |
2612 | } |
|
|
2613 | }, |
|
|
2614 | |
|
|
2615 | "bcd-device" => sub { |
|
|
2616 | prdev shift, "bcd_device"; |
|
|
2617 | }, |
|
|
2618 | |
|
|
2619 | "bcd-legacy-device" => sub { |
|
|
2620 | prdev shift, "bcd_legacy_device"; |
2564 | }, |
2621 | }, |
2565 | |
2622 | |
2566 | version => sub { |
2623 | version => sub { |
2567 | print "\n", |
2624 | print "\n", |
2568 | "PBCDEDIT version $VERSION, copyright 2019 Marc A. Lehmann <pbcdedit\@schmorp.de>.\n", |
2625 | "PBCDEDIT version $VERSION, copyright 2019 Marc A. Lehmann <pbcdedit\@schmorp.de>.\n", |