1 /*
2 * Copyright (c) 2018 The strace developers.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "tests.h"
29
30 #include <fcntl.h>
31 #include <stdio.h>
32 #include <sys/ioctl.h>
33 #include <linux/types.h>
34 #include <linux/nbd.h>
35
36 #define XLAT_MACROS_ONLY
37 # include "xlat/nbd_ioctl_cmds.h"
38 # include "xlat/nbd_ioctl_flags.h"
39 #undef XLAT_MACROS_ONLY
40
41 #define RVAL_EBADF " = -1 EBADF (%m)\n"
42
43 int
main(void)44 main(void)
45 {
46 static const unsigned long ubeef = (unsigned long) 0xcafef00ddeadbeefULL;
47 static const char null_path[] = "/dev/null";
48
49 int fd = open(null_path, O_RDONLY);
50 if (fd < 0)
51 perror_msg_and_fail("open(\"%s\")", null_path);
52
53 skip_if_unavailable("/proc/self/fd/");
54
55 ioctl(-1, NBD_DISCONNECT, NULL);
56 printf("ioctl(-1, NBD_DISCONNECT)" RVAL_EBADF);
57 ioctl(-1, NBD_CLEAR_SOCK, NULL);
58 printf("ioctl(-1, NBD_CLEAR_SOCK)" RVAL_EBADF);
59 ioctl(-1, NBD_DO_IT, NULL);
60 printf("ioctl(-1, NBD_DO_IT)" RVAL_EBADF);
61 ioctl(-1, NBD_CLEAR_QUE, NULL);
62 printf("ioctl(-1, NBD_CLEAR_QUE)" RVAL_EBADF);
63 ioctl(-1, NBD_PRINT_DEBUG, NULL);
64 printf("ioctl(-1, NBD_PRINT_DEBUG)" RVAL_EBADF);
65 ioctl(-1, NBD_SET_SOCK, fd);
66 printf("ioctl(-1, NBD_SET_SOCK, %d</dev/null>)" RVAL_EBADF, fd);
67
68 ioctl(-1, NBD_SET_BLKSIZE, ubeef);
69 printf("ioctl(-1, NBD_SET_BLKSIZE, %lu)" RVAL_EBADF, ubeef);
70 ioctl(-1, NBD_SET_SIZE, ubeef);
71 printf("ioctl(-1, NBD_SET_SIZE, %lu)" RVAL_EBADF, ubeef);
72 ioctl(-1, NBD_SET_SIZE_BLOCKS, ubeef);
73 printf("ioctl(-1, NBD_SET_SIZE_BLOCKS, %lu)" RVAL_EBADF, ubeef);
74
75 ioctl(-1, NBD_SET_TIMEOUT, ubeef);
76 printf("ioctl(-1, NBD_SET_TIMEOUT, %lu)" RVAL_EBADF, ubeef);
77
78 ioctl(-1, NBD_SET_FLAGS, 0);
79 printf("ioctl(-1, NBD_SET_FLAGS, 0)" RVAL_EBADF);
80 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS);
81 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS)" RVAL_EBADF);
82 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_READ_ONLY);
83 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_READ_ONLY)" RVAL_EBADF);
84 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FLUSH);
85 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FLUSH)" RVAL_EBADF);
86 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FUA);
87 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FUA)" RVAL_EBADF);
88 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM);
89 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM)" RVAL_EBADF);
90 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_WRITE_ZEROES);
91 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_WRITE_ZEROES)" RVAL_EBADF);
92 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_DF);
93 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_DF)" RVAL_EBADF);
94 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_CAN_MULTI_CONN);
95 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_CAN_MULTI_CONN)" RVAL_EBADF);
96 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_RESIZE);
97 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_RESIZE)" RVAL_EBADF);
98 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_CACHE);
99 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_CACHE)" RVAL_EBADF);
100
101 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS|NBD_FLAG_READ_ONLY|
102 NBD_FLAG_SEND_FUA|NBD_FLAG_SEND_CACHE|
103 (1 << 15)|(1<<31));
104 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS|NBD_FLAG_READ_ONLY|"
105 "NBD_FLAG_SEND_FUA|NBD_FLAG_SEND_CACHE|0x80008000)" RVAL_EBADF);
106
107 ioctl(-1, _IOC(_IOC_NONE, 0xab, 0xb, 0), NULL);
108 printf("ioctl(-1, _IOC(_IOC_NONE, 0xab, 0xb, 0), 0)" RVAL_EBADF);
109
110 puts("+++ exited with 0 +++");
111 return 0;
112 }
113