Support block devices in @-syntax #94
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: a-j-wood/pv#94
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "alexanderperlis/pv:support-block-device-size"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Previously,
pv -s @/dev/sda
behaved likepv -s 0
becausestat
on a block device returned a size of 0. Now, additional steps are taken (namely: open device, seek to end) to calculate block device size. Thus, in addition to the prior support forpv -s @<file>
there is now also support forpv -s @<device>
.On Linux, instead of seek-to-end, one could use
ioctl(..., BLKGETSIZE64, ...)
, but the seek-to-end approach is presumably more universal, and anyhow was already being used elsewhere in the project, namely inpv_calc_total_bytes()
to calculate the size of an output block device.WIP: Support block devices in @-syntaxto Support block devices in @-syntaxHello, thank you for this.
I did not know about that
ioctl()
call, but agree that using the same approach as used elsewhere in the code seems reasonable and generic.I did find a snag in that approach, which is that you can't use "
--size @/dev/vda
" if you don't have read permissions on/dev/vda
, whereas "lsblk /dev/vda
" works in that case. Following what "lsblk
" does usingstrace
suggests a Linux-specific way to get the size by reading from/sys/dev/block/253:0/size
where 253:0 is the device's major:minor pair.So maybe I'll change it a bit. I'm dithering over it because it then means that the command allows something on Linux that it won't on other operating systems, but maybe that's worrying a bit too much. Anyway, either way I'll commit some small changes to this shortly. Thanks again!
My initial thought was that someone would likely only want to use
--size @<device>
if that same device were either the input or output somewhere else in the chain, implying a strong likelihood of already having read permission. However, with the possibility of virtual devices referring to other devices but with perhaps different permissions (I believe that's the essential aspect of your example), or say there being a write-only device that doesn't allow reading, there evidently could be common situations where one doesn't have read permission yet would still be able to determine the device size via other (perhaps more OS-specific) methods. Supporting that is nice for users who would otherwise by stymied. Even if such support happens initially only for specific systems, that's still a net gain, and doesn't preclude future support for additional systems.