diff options
author | Federico Simoncelli | 2014-10-24 17:13:54 +0200 |
---|---|---|
committer | Karel Zak | 2014-10-27 09:16:47 +0100 |
commit | d7ce9acb338f70e65712e1edfd34c13207a33d05 (patch) | |
tree | afe1e8bbcf861e485b854e60cb64409cfcedfead /sys-utils/blkdiscard.c | |
parent | tests: add blkdiscard offsets test (diff) | |
download | kernel-qcow2-util-linux-d7ce9acb338f70e65712e1edfd34c13207a33d05.tar.gz kernel-qcow2-util-linux-d7ce9acb338f70e65712e1edfd34c13207a33d05.tar.xz kernel-qcow2-util-linux-d7ce9acb338f70e65712e1edfd34c13207a33d05.zip |
blkdiscard: fail on sector misalignment
Diffstat (limited to 'sys-utils/blkdiscard.c')
-rw-r--r-- | sys-utils/blkdiscard.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/sys-utils/blkdiscard.c b/sys-utils/blkdiscard.c index 1eb2b2857..1504ee3b4 100644 --- a/sys-utils/blkdiscard.c +++ b/sys-utils/blkdiscard.c @@ -144,9 +144,10 @@ int main(int argc, char **argv) if (ioctl(fd, BLKSSZGET, &secsize)) err(EXIT_FAILURE, _("%s: BLKSSZGET ioctl failed"), path); - /* align range to the sector size */ - range[0] = (range[0] + secsize - 1) & ~(secsize - 1); - range[1] &= ~(secsize - 1); + /* check offset alignment to the sector size */ + if (range[0] % secsize) + 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 ?*/ if (range[0] > blksize) @@ -155,6 +156,11 @@ int main(int argc, char **argv) if (end < range[0] || end > blksize) 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 (ioctl(fd, BLKSECDISCARD, &range)) err(EXIT_FAILURE, _("%s: BLKSECDISCARD ioctl failed"), path); |