btrfs-progs: add fd version of device_get_partition_size

The helper wraps a raw ioctl but some users may already have the fd and
not necessarily the path. Add a suitable helper for convenience.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-04-29 20:13:49 +02:00
parent 2cfd248ddf
commit 600d2dba6f
2 changed files with 11 additions and 0 deletions

View File

@ -289,6 +289,16 @@ u64 btrfs_device_size(int fd, struct stat *st)
/*
* Read partition size using the low-level ioctl
*/
u64 device_get_partition_size_fd(int fd)
{
u64 result;
if (ioctl(fd, BLKGETSIZE64, &result) < 0)
return 0;
return result;
}
u64 device_get_partition_size(const char *dev)
{
u64 result;

View File

@ -34,6 +34,7 @@
int device_discard_blocks(int fd, u64 start, u64 len);
int device_zero_blocks(int fd, off_t start, size_t len);
u64 device_get_partition_size(const char *dev);
u64 device_get_partition_size_fd(int fd);
int device_get_queue_param(const char *file, const char *param, char *buf, size_t len);
/*