ioctl06: Add BLKRAGET/BLKRASET test

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
diff --git a/runtest/syscalls b/runtest/syscalls
index 46602a4..c3ea212 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -454,6 +454,7 @@
 ioctl03      ioctl03
 ioctl04      ioctl04
 ioctl05      ioctl05
+ioctl05      ioctl06
 
 inotify_init1_01 inotify_init1_01
 inotify_init1_02 inotify_init1_02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 5e69f5a..9d7b947 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -386,6 +386,7 @@
 /ioctl/ioctl03
 /ioctl/ioctl04
 /ioctl/ioctl05
+/ioctl/ioctl06
 /ioperm/ioperm01
 /ioperm/ioperm02
 /iopl/iopl01
diff --git a/testcases/kernel/syscalls/ioctl/ioctl06.c b/testcases/kernel/syscalls/ioctl/ioctl06.c
new file mode 100644
index 0000000..9046a3f
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl06.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * 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 2 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/>.
+ */
+/*
+ * Basic test for the BLKROSET and BLKROGET ioctls.
+ *
+ * - Set the device read only, read the value back.
+ * - Try to mount the device read write, expect failure.
+ * - Try to mount the device read only, expect success.
+ */
+
+#include <errno.h>
+#include <sys/mount.h>
+#include "tst_test.h"
+
+static int fd;
+
+static void verify_ioctl(void)
+{
+	unsigned long ra, rab, rao;
+
+	SAFE_IOCTL(fd, BLKRAGET, &rao);
+
+	tst_res(TINFO, "BLKRAGET original value %lu", rao);
+
+	for (ra = 0; ra <= 512; ra += 64) {
+		SAFE_IOCTL(fd, BLKRASET, ra);
+		SAFE_IOCTL(fd, BLKRAGET, &rab);
+
+		if (ra == rab)
+			tst_res(TPASS, "BLKRASET %lu read back correctly", ra);
+		else
+			tst_res(TFAIL, "BLKRASET %lu read back %lu", ra, rab);
+	}
+
+	tst_res(TINFO, "BLKRASET restoring original value %lu", rao);
+
+	SAFE_IOCTL(fd, BLKRASET, rao);
+}
+
+static void setup(void)
+{
+	fd = SAFE_OPEN(tst_device->dev, O_RDONLY);
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tid = "ioctl07",
+	.needs_device = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_ioctl,
+};