blockdev-util: add simple wrapper around BLKSSZGET
Just adds some typesafety and generates an error if the field is not initialized in the block device yet.
This commit is contained in:
@@ -762,3 +762,18 @@ int blockdev_reread_partition_table(sd_device *dev) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int blockdev_get_sector_size(int fd, uint32_t *ret) {
|
||||
int ssz = 0;
|
||||
|
||||
assert(fd >= 0);
|
||||
assert(ret);
|
||||
|
||||
if (ioctl(fd, BLKSSZGET, &ssz) < 0)
|
||||
return -errno;
|
||||
if (ssz <= 0) /* make sure the field is initialized */
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Block device reported invalid sector size %i.", ssz);
|
||||
|
||||
*ret = ssz;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user