2 * Copyright (c) 2018 The strace developers.
5 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include <sys/ioctl.h>
13 #include <linux/types.h>
14 #include <linux/nbd.h>
16 #define XLAT_MACROS_ONLY
17 #include "xlat/nbd_ioctl_cmds.h"
18 #include "xlat/nbd_ioctl_flags.h"
19 #undef XLAT_MACROS_ONLY
21 #define RVAL_EBADF " = -1 EBADF (%m)\n"
26 static const unsigned long ubeef = (unsigned long) 0xcafef00ddeadbeefULL;
27 static const char null_path[] = "/dev/null";
29 int fd = open(null_path, O_RDONLY);
31 perror_msg_and_fail("open(\"%s\")", null_path);
33 skip_if_unavailable("/proc/self/fd/");
35 ioctl(-1, NBD_DISCONNECT, NULL);
36 printf("ioctl(-1, NBD_DISCONNECT)" RVAL_EBADF);
37 ioctl(-1, NBD_CLEAR_SOCK, NULL);
38 printf("ioctl(-1, NBD_CLEAR_SOCK)" RVAL_EBADF);
39 ioctl(-1, NBD_DO_IT, NULL);
40 printf("ioctl(-1, NBD_DO_IT)" RVAL_EBADF);
41 ioctl(-1, NBD_CLEAR_QUE, NULL);
42 printf("ioctl(-1, NBD_CLEAR_QUE)" RVAL_EBADF);
43 ioctl(-1, NBD_PRINT_DEBUG, NULL);
44 printf("ioctl(-1, NBD_PRINT_DEBUG)" RVAL_EBADF);
45 ioctl(-1, NBD_SET_SOCK, fd);
46 printf("ioctl(-1, NBD_SET_SOCK, %d</dev/null>)" RVAL_EBADF, fd);
48 ioctl(-1, NBD_SET_BLKSIZE, ubeef);
49 printf("ioctl(-1, NBD_SET_BLKSIZE, %lu)" RVAL_EBADF, ubeef);
50 ioctl(-1, NBD_SET_SIZE, ubeef);
51 printf("ioctl(-1, NBD_SET_SIZE, %lu)" RVAL_EBADF, ubeef);
52 ioctl(-1, NBD_SET_SIZE_BLOCKS, ubeef);
53 printf("ioctl(-1, NBD_SET_SIZE_BLOCKS, %lu)" RVAL_EBADF, ubeef);
55 ioctl(-1, NBD_SET_TIMEOUT, ubeef);
56 printf("ioctl(-1, NBD_SET_TIMEOUT, %lu)" RVAL_EBADF, ubeef);
58 ioctl(-1, NBD_SET_FLAGS, 0);
59 printf("ioctl(-1, NBD_SET_FLAGS, 0)" RVAL_EBADF);
60 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS);
61 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS)" RVAL_EBADF);
62 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_READ_ONLY);
63 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_READ_ONLY)" RVAL_EBADF);
64 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FLUSH);
65 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FLUSH)" RVAL_EBADF);
66 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FUA);
67 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FUA)" RVAL_EBADF);
68 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM);
69 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM)" RVAL_EBADF);
70 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_WRITE_ZEROES);
71 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_WRITE_ZEROES)" RVAL_EBADF);
72 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_DF);
73 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_DF)" RVAL_EBADF);
74 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_CAN_MULTI_CONN);
75 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_CAN_MULTI_CONN)" RVAL_EBADF);
76 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_RESIZE);
77 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_RESIZE)" RVAL_EBADF);
78 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_CACHE);
79 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_CACHE)" RVAL_EBADF);
81 ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS|NBD_FLAG_READ_ONLY|
82 NBD_FLAG_SEND_FUA|NBD_FLAG_SEND_CACHE|
84 printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS|NBD_FLAG_READ_ONLY|"
85 "NBD_FLAG_SEND_FUA|NBD_FLAG_SEND_CACHE|0x80008000)" RVAL_EBADF);
87 ioctl(-1, _IOC(_IOC_NONE, 0xab, 0xb, 0), NULL);
88 printf("ioctl(-1, _IOC(_IOC_NONE, 0xab, 0xb, 0), 0)" RVAL_EBADF);
90 puts("+++ exited with 0 +++");