blkdiscard: fail on sector misalignment
This commit is contained in:
parent
f4822fdfc5
commit
d7ce9acb33
|
@ -144,9 +144,10 @@ int main(int argc, char **argv)
|
||||||
if (ioctl(fd, BLKSSZGET, &secsize))
|
if (ioctl(fd, BLKSSZGET, &secsize))
|
||||||
err(EXIT_FAILURE, _("%s: BLKSSZGET ioctl failed"), path);
|
err(EXIT_FAILURE, _("%s: BLKSSZGET ioctl failed"), path);
|
||||||
|
|
||||||
/* align range to the sector size */
|
/* check offset alignment to the sector size */
|
||||||
range[0] = (range[0] + secsize - 1) & ~(secsize - 1);
|
if (range[0] % secsize)
|
||||||
range[1] &= ~(secsize - 1);
|
errx(EXIT_FAILURE, _("%s: offset %" PRIu64 " is not aligned "
|
||||||
|
"to sector size %i"), path, range[0], secsize);
|
||||||
|
|
||||||
/* is the range end behind the end of the device ?*/
|
/* is the range end behind the end of the device ?*/
|
||||||
if (range[0] > blksize)
|
if (range[0] > blksize)
|
||||||
|
@ -155,6 +156,11 @@ int main(int argc, char **argv)
|
||||||
if (end < range[0] || end > blksize)
|
if (end < range[0] || end > blksize)
|
||||||
range[1] = blksize - range[0];
|
range[1] = blksize - range[0];
|
||||||
|
|
||||||
|
/* check length alignment to the sector size */
|
||||||
|
if (range[1] % secsize)
|
||||||
|
errx(EXIT_FAILURE, _("%s: length %" PRIu64 " is not aligned "
|
||||||
|
"to sector size %i"), path, range[1], secsize);
|
||||||
|
|
||||||
if (secure) {
|
if (secure) {
|
||||||
if (ioctl(fd, BLKSECDISCARD, &range))
|
if (ioctl(fd, BLKSECDISCARD, &range))
|
||||||
err(EXIT_FAILURE, _("%s: BLKSECDISCARD ioctl failed"), path);
|
err(EXIT_FAILURE, _("%s: BLKSECDISCARD ioctl failed"), path);
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
create loop device from image
|
create loop device from image
|
||||||
testing offsets with full block size
|
testing offsets with full block size
|
||||||
Discarded 10485760 bytes from the offset 0
|
Discarded 10485760 bytes from the offset 0
|
||||||
Discarded 10485248 bytes from the offset 512
|
blkdiscard: offset 1 is not aligned to sector size 512
|
||||||
Discarded 10485248 bytes from the offset 512
|
blkdiscard: offset 511 is not aligned to sector size 512
|
||||||
Discarded 10485248 bytes from the offset 512
|
Discarded 10485248 bytes from the offset 512
|
||||||
Discarded 10484736 bytes from the offset 1024
|
Discarded 10484736 bytes from the offset 1024
|
||||||
testing offsets with specific length
|
testing offsets with specific length
|
||||||
Discarded 5242880 bytes from the offset 0
|
Discarded 5242880 bytes from the offset 0
|
||||||
Discarded 5242880 bytes from the offset 0
|
blkdiscard: length 5242881 is not aligned to sector size 512
|
||||||
Discarded 5242880 bytes from the offset 0
|
blkdiscard: length 5243391 is not aligned to sector size 512
|
||||||
Discarded 5242880 bytes from the offset 512
|
blkdiscard: offset 1 is not aligned to sector size 512
|
||||||
Discarded 5242880 bytes from the offset 512
|
blkdiscard: offset 511 is not aligned to sector size 512
|
||||||
Discarded 5242880 bytes from the offset 512
|
Discarded 5242880 bytes from the offset 512
|
||||||
Discarded 5242880 bytes from the offset 1024
|
Discarded 5242880 bytes from the offset 1024
|
||||||
detach loop device from image
|
detach loop device from image
|
||||||
|
|
Loading…
Reference in New Issue