]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
block/012: add test for BLKROSET/BLKROGET ioctls
authorDavid Disseldorp <ddiss@suse.de>
Wed, 8 Nov 2017 18:07:46 +0000 (19:07 +0100)
committerDavid Disseldorp <ddiss@suse.de>
Wed, 8 Nov 2017 23:42:13 +0000 (00:42 +0100)
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 <ddiss@suse.de>
tests/block/012 [new file with mode: 0755]
tests/block/012.out [new file with mode: 0644]

diff --git a/tests/block/012 b/tests/block/012
new file mode 100755 (executable)
index 0000000..cc85d2d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+
+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 (file)
index 0000000..fc6fc00
--- /dev/null
@@ -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