blob: 9046a3fd5a67427dc33f8bc8f44ad807eff54c1e [file] [log] [blame]
/*
* 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,
};