Home | History | Annotate | Download | only in ioctl
      1 /*
      2  * Copyright (c) 2017 Cyril Hrubis <chrubis (at) suse.cz>
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 2 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 /*
     18  * Basic test for the BLKRASET and BLKRAGET ioctls.
     19  *
     20  * Sets device read-ahead, reads it back and compares the values.
     21  *
     22  * The read-ahead value was choosen to be multiple of 512, since it's rounded
     23  * based on page size on BLKRASET and 512 should be safe enough for everyone.
     24  */
     25 
     26 #include <errno.h>
     27 #include <sys/mount.h>
     28 #include "tst_test.h"
     29 
     30 static int fd;
     31 
     32 static void verify_ioctl(void)
     33 {
     34 	unsigned long ra, rab, rao;
     35 
     36 	SAFE_IOCTL(fd, BLKRAGET, &rao);
     37 
     38 	tst_res(TINFO, "BLKRAGET original value %lu", rao);
     39 
     40 	for (ra = 0; ra <= 4096; ra += 512) {
     41 		SAFE_IOCTL(fd, BLKRASET, ra);
     42 		SAFE_IOCTL(fd, BLKRAGET, &rab);
     43 
     44 		if (ra == rab)
     45 			tst_res(TPASS, "BLKRASET %lu read back correctly", ra);
     46 		else
     47 			tst_res(TFAIL, "BLKRASET %lu read back %lu", ra, rab);
     48 	}
     49 
     50 	tst_res(TINFO, "BLKRASET restoring original value %lu", rao);
     51 
     52 	SAFE_IOCTL(fd, BLKRASET, rao);
     53 }
     54 
     55 static void setup(void)
     56 {
     57 	fd = SAFE_OPEN(tst_device->dev, O_RDONLY);
     58 }
     59 
     60 static void cleanup(void)
     61 {
     62 	if (fd > 0)
     63 		SAFE_CLOSE(fd);
     64 }
     65 
     66 static struct tst_test test = {
     67 	.tid = "ioctl06",
     68 	.needs_root = 1,
     69 	.needs_device = 1,
     70 	.setup = setup,
     71 	.cleanup = cleanup,
     72 	.test_all = verify_ioctl,
     73 };
     74