lib/blkdev: use off_t for max values

The off_t datatype is signed. Use it for high and low boundaries as
well to support also very large block devices close to its limits.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
This commit is contained in:
Samanta Navarro 2023-01-13 11:52:36 +00:00
parent 2f7450f6cb
commit ce621f1668

View file

@ -58,25 +58,25 @@ int is_blkdev(int fd)
off_t
blkdev_find_size (int fd) {
uintmax_t high, low = 0;
off_t high, low = 0;
for (high = 1024; blkdev_valid_offset (fd, high); ) {
if (high == UINTMAX_MAX) {
if (high == SINT_MAX(off_t)) {
errno = EFBIG;
return -1;
}
low = high;
if (high >= UINTMAX_MAX/2)
high = UINTMAX_MAX;
if (high >= SINT_MAX(off_t)/2)
high = SINT_MAX(off_t);
else
high *= 2;
}
while (low < high - 1)
{
uintmax_t mid = (low + high) / 2;
off_t mid = (low + high) / 2;
if (blkdev_valid_offset (fd, mid))
low = mid;