From: David Disseldorp Date: Wed, 8 Nov 2017 18:07:46 +0000 (+0100) Subject: block/012: add test for BLKROSET/BLKROGET ioctls X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3aeec46f048b26ab26684bb7cf4ffb814442dc61;p=users%2Fsagi%2Fblktests.git block/012: add test for BLKROSET/BLKROGET ioctls Use blockdev --setro/--getro to manipulate the read-only state of a test device, and confirm that writes fail while set. Signed-off-by: David Disseldorp --- diff --git a/tests/block/012 b/tests/block/012 new file mode 100755 index 0000000..cc85d2d --- /dev/null +++ b/tests/block/012 @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Test read-only state with BLKROSET and BLKROGET ioctls +# +# Copyright (C) 2017 David Disseldorp +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +DESCRIPTION="check read-only state" +TIMED=1 + +requires() { + _have_program xfs_io +} + +test_device() { + echo "Running ${TEST_NAME}" + + blockdev --getro "$TEST_DEV" + xfs_io -c "pwrite -w -S 0xaa -b 2M 0 2M" -d "$TEST_DEV" >>"$FULL" + dd if="$TEST_DEV" bs=2M count=1 2>>"$FULL" | hexdump + blockdev --setro "$TEST_DEV" + blockdev --setro "$TEST_DEV" + blockdev --getro "$TEST_DEV" + # writes should fail while device is read-only + xfs_io -c "pwrite -w -S 0xbb -b 2M 0 2M" -d "$TEST_DEV" >>"$FULL" + dd if="$TEST_DEV" bs=2M count=1 2>>"$FULL" | hexdump + blockdev --setrw "$TEST_DEV" + blockdev --getro "$TEST_DEV" + xfs_io -c "pwrite -w -S 0xcc -b 2M 0 2M" -d "$TEST_DEV" >>"$FULL" + dd if="$TEST_DEV" bs=2M count=1 2>>"$FULL" | hexdump + + echo "Test complete" +} diff --git a/tests/block/012.out b/tests/block/012.out new file mode 100644 index 0000000..fc6fc00 --- /dev/null +++ b/tests/block/012.out @@ -0,0 +1,15 @@ +Running block/012 +0 +0000000 aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa +* +0200000 +1 +pwrite64: Operation not permitted +0000000 aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa +* +0200000 +0 +0000000 cccc cccc cccc cccc cccc cccc cccc cccc +* +0200000 +Test complete