Subject: Multiple issues with partx
Hello,
I have encounted a few issues with 'partx'.
1. 'partx --nr 1:' does not work.
If you leave the upper range empty, partx uses 0 instead. So instead of the list of all partitions -- which you should get according to the manual -- you get an error:
partx: specified range <1:0> does not make sense
Changing the default to -1 in parse_range() would fix this, but see issue #2 below.
Also note that while *upper is set to 'def' in parse_range:
*upper = *lower = def;
this value is not actually used, because a few lines below there is:
if (*end == ':' && !*(end + 1)) /* <M:> */
*upper = 0;If the possibility to override the default value is desired, it would imho be best to have separate default values for the lower and upper range.
2. 'partx --nr <M:N>' does not take empty partition table entries into account when using negative indexes.
I have created a test file with a partition table with the first and third entry used, but the second entry open:
$ partx testfile
NR START END SECTORS SIZE NAME UUID
1 2048 10000 7953 3.9M 4fafc399-01
3 10001 20479 10479 5.1M 4fafc399-03One might expect that 'partx --nr 1:-1' would list all partitions (i.e. from the first to the last partition), but this is currently not true in this case:
$ partx --nr 1:-1 testfile
NR START END SECTORS SIZE NAME UUID
1 2048 10000 7953 3.9M 4fafc399-01In fact, 'partx --nr -1:-1' returns no output at all.
This is because negative values are offset against the number of partitions, which is less than the number of the partition with the highest number.
One approach to solving this would be to offset against the number of the last partition in the partition table, but this would not work as expected when the partitions are our of order.
Another approach would be to offset negative numbers against the number of the partition with the highest partition number.
In the case that there are holes in the partition table, this would not necessarily return the same number of partitions as would be expected by looking at the range. e.g. Using the same test file as above, 'partx --nr -2:-1' would produce only one entry:
NR START END SECTORS SIZE NAME UUID
3 10001 20479 10479 5.1M 4fafc399-03
Yet another approach may be to consider the list of partitions in the order in which they are normally shown by partx, and consider negative numbers to be indices offset against the length of the list. The disadvantage here is that negative numbers don't mean the same thing as positive numbers; positive numbers refer to partition numbers, while negative numbers refer to indices in a sorted list. 'partx --nr 1:-1' would then mean 'the partitions in the sorted list of partitions, starting with the one with number 1, up to the last partition in the list.
Then there are the options to add a separate option with a different meaning for negative indices, or to remove the support for negative numbers altogether.
3. It is not always clear whether a single partition table entry refers to the partition table on the block device, or to a partition table entry of the block device of which the specified block device is a part.
When the specified block device contains a partition table, that partition table is shown. When it does not contain a partition table, but the block device is a partition itself, its entry on its parent block device is shown. When you don't know whether a given block device contains is a full disk or a partition (because you're calling partx from a script) special logic would be required. Also, nested partition tables are theoretically possible, though unusual.
My preferred solution would be to only show the partition table on the specified block device, unless a partition is explicitly specified. Perhaps the behaviour could also be modified using added parameters.
As a work-around, something like 'partx --nr 1:65535' may be used if you are interested in the partitions of the specified block device itself. 'partx --nr 1:' would avoid the arbitrary upper bound, but does not work because of issue 1, and 'partx --nr 1:-1' would too, but does not work because of issue 2.
4. It is possible to specify a partition by the device name of a partition on another block device.
The command 'partx /dev/sdb2 /dev/sda' makes no sense, but still produces output, namely the second partition of /dev/sda.
Regards,
Serge
Karel Zak
maintainerQuoted 1 line · Serge van den Boom
1. 'partx --nr 1:' does not work.
Fixed.
# partx --show --nr 1: /dev/sdc NR START END SECTORS SIZE NAME UUID 1 2048 22527 20480 10M fa3974fc-40a2-402a-941a-7d26b32e126d 2 22528 43007 20480 10M 808a2e20-7109-4f2f-9727-f474f5119231 4 63488 83967 20480 10M 8fe134d1-af94-48d0-94f2-9b757da8731f
Quoted 2 lines
2. 'partx --nr <M:N>' does not take empty partition table entries into account when using negative indexes.
...
Quoted 7 lines
One might expect that 'partx --nr 1:-1' would list all partitions (i.e. from the first to the last partition), but this is currently not true in this case:
$ partx --nr 1:-1 testfile NR START END SECTORS SIZE NAME UUID 1 2048 10000 7953 3.9M 4fafc399-01
Fixed.
Note that --nr specifies partno (column NR), rather than seq.number. Unfortunately, code mixed partno and seq.number of the partition.
# partx --show --nr 1:-1 /dev/sdc NR START END SECTORS SIZE NAME UUID 1 2048 22527 20480 10M fa3974fc-40a2-402a-941a-7d26b32e126d 2 22528 43007 20480 10M 808a2e20-7109-4f2f-9727-f474f5119231 4 63488 83967 20480 10M 8fe134d1-af94-48d0-94f2-9b757da8731f
Quoted 1 line
In fact, 'partx --nr -1:-1' returns no output at all.
Fixed.
# partx --show --nr -1:-1 /dev/sdc NR START END SECTORS SIZE NAME UUID 4 63488 83967 20480 10M 8fe134d1-af94-48d0-94f2-9b757da8731f
Quoted 11 lines
3. It is not always clear whether a single partition table entry refers to the partition table on the block device, or to a partition table entry of the block device of which the specified block device is a part.
When the specified block device contains a partition table, that partition table is shown. When it does not contain a partition table, but the block device is a partition itself, its entry on its parent block device is shown. When you don't know whether a given block device contains is a full disk or a partition (because you're calling partx from a script) special logic would be required. Also, nested partition tables are theoretically possible, though unusual.
You have to always specify partition (-nr or devname), whole-disk is optional. If you want to read partitioned partition (nested PT) then you can use '-' instead of partition name:
partx --show - /dev/sdc1
Anyway, my suggestion is to use sfdisk if you want complicated things like nested partitions.
Quoted 5 lines
As a work-around, something like 'partx --nr 1:65535' may be used if you are interested in the partitions of the specified block device itself. 'partx --nr 1:' would avoid the arbitrary upper bound, but does not work because of issue 1, and 'partx --nr 1:-1' would too, but does not work because of issue 2.
--nr 1: and --nr 1:-1 works now
Quoted 5 lines
4. It is possible to specify a partition by the device name of a partition on another block device.
The command 'partx
/dev/sdb2/dev/sda' makes no sense, but still produces output, namely the second partition of/dev/sda.
Fixed,
# partx --show /dev/sdx1 /dev/sdc partx: partition and disk name do not match
I'll prepare regression test for partx....
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Thanks. Fast resolution.
Quoted 5 lines · Karel Zak
Quoted 4 lines · Serge van den Boom
4. It is possible to specify a partition by the device name of a partition on another block device.
Quoted 7 lines
Quoted 2 lines
The command 'partx
/dev/sdb2/dev/sda' makes no sense, but still produces output, namely the second partition of/dev/sda.Fixed,
# partx --show /dev/sdx1 /dev/sdc partx: partition and disk name do not match
Strictly speaking, it should be the devices themselves which would need to match, not their names. I could create a few symlinks, and 'partx x0 x' would work, even when x0 and x refer to unrelated devices:
ln -s /dev/sda x
ln -s /dev/sdb2 x0
Regards,
Serge
Karel Zak
maintainerQuoted 16 lines · Serge van den Boom
Thanks. Fast resolution.
Quoted 5 lines · Karel Zak
Quoted 4 lines · Serge van den Boom
4. It is possible to specify a partition by the device name of a partition on another block device.
Quoted 7 lines
Quoted 2 lines
The command 'partx
/dev/sdb2/dev/sda' makes no sense, but still produces output, namely the second partition of/dev/sda.Fixed,
# partx --show /dev/sdx1 /dev/sdc partx: partition and disk name do not match
Quoted 6 lines
Strictly speaking, it should be the devices themselves which would need to match, not their names. I could create a few symlinks, and 'partx x0 x' would work, even when x0 and x refer to unrelated devices:
ln -s
/dev/sdax
ln -s/dev/sdb2x0
This is about identification, partx does not use the device for anything.... not sure if we have to make it more complicated.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com