losetup: don't require 512-byte aligned offsets
Kernel aligns the device size, but the offset where the device starts is not required to be aligned. # losetup --offset 32 -f file.img is just fine, the final size of the look device will be (in sectors) (backing_file_size - offset) >> 9 so we have to do the same in userspace when we check for successful set capacity ioctl. Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
c1d26ddbe7
commit
a7d5202b5e
|
@ -1129,6 +1129,12 @@ static int loopcxt_check_size(struct loopdev_cxt *lc, int file_fd)
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* It's block device, so, align to 512-byte sectors */
|
||||||
|
if (expected_size % 512) {
|
||||||
|
DBG(lc, loopdev_debug("expected size misaligned to 512-byte sectors"));
|
||||||
|
expected_size = (expected_size >> 9) << 9;
|
||||||
|
}
|
||||||
|
|
||||||
if (expected_size != size) {
|
if (expected_size != size) {
|
||||||
DBG(lc, loopdev_debug("warning: loopdev and expected "
|
DBG(lc, loopdev_debug("warning: loopdev and expected "
|
||||||
"size dismatch (%ju/%ju)",
|
"size dismatch (%ju/%ju)",
|
||||||
|
|
|
@ -673,11 +673,7 @@ int main(int argc, char **argv)
|
||||||
/* errors */
|
/* errors */
|
||||||
errpre = hasdev && loopcxt_get_fd(&lc) < 0 ?
|
errpre = hasdev && loopcxt_get_fd(&lc) < 0 ?
|
||||||
loopcxt_get_device(&lc) : file;
|
loopcxt_get_device(&lc) : file;
|
||||||
if (errno == ERANGE && offset && offset % 512)
|
warn(_("%s: failed to set up loop device"), errpre);
|
||||||
warnx(_("%s: failed to set up loop device, "
|
|
||||||
"offset is not 512-byte aligned."), errpre);
|
|
||||||
else
|
|
||||||
warn(_("%s: failed to set up loop device"), errpre);
|
|
||||||
break;
|
break;
|
||||||
} while (hasdev == 0);
|
} while (hasdev == 0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue