2 * This file is part of ioctl_mtd strace test.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
5 * Copyright (c) 2016-2017 The strace developers.
8 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifdef HAVE_STRUCT_MTD_WRITE_REQ
16 # include <inttypes.h>
19 # include <sys/ioctl.h>
20 # include <linux/ioctl.h>
21 # include <linux/version.h>
22 # include <mtd/mtd-abi.h>
24 static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL;
26 # define TEST_NULL_ARG(cmd) \
29 if (_IOC_DIR(cmd) == _IOC_WRITE) \
30 printf("ioctl(-1, MIXER_WRITE(%u) or %s, NULL)" \
31 " = -1 EBADF (%m)\n", \
32 (unsigned int) _IOC_NR(cmd), #cmd); \
33 else if (_IOC_DIR(cmd) == _IOC_READ) \
34 printf("ioctl(-1, MIXER_READ(%u) or %s, NULL)" \
35 " = -1 EBADF (%m)\n", \
36 (unsigned int) _IOC_NR(cmd), #cmd); \
38 printf("ioctl(-1, %s, NULL) = -1 EBADF (%m)\n", #cmd); \
41 # define TEST_erase_info_user(cmd, eiu) \
43 ioctl(-1, cmd, eiu); \
44 printf("ioctl(-1, MIXER_%s(%u) or %s, {start=%#x, length=%#x})" \
45 " = -1 EBADF (%m)\n", \
46 (_IOC_DIR(cmd) == _IOC_READ) ? "READ" : "WRITE", \
47 (unsigned int) _IOC_NR(cmd), #cmd, \
48 eiu->start, eiu->length); \
54 TEST_NULL_ARG(ECCGETLAYOUT);
55 TEST_NULL_ARG(ECCGETSTATS);
56 TEST_NULL_ARG(MEMERASE);
57 TEST_NULL_ARG(MEMERASE64);
58 TEST_NULL_ARG(MEMGETBADBLOCK);
59 TEST_NULL_ARG(MEMGETINFO);
60 TEST_NULL_ARG(MEMGETOOBSEL);
61 TEST_NULL_ARG(MEMGETREGIONCOUNT);
62 TEST_NULL_ARG(MEMISLOCKED);
63 TEST_NULL_ARG(MEMLOCK);
64 TEST_NULL_ARG(MEMREADOOB);
65 TEST_NULL_ARG(MEMREADOOB64);
66 TEST_NULL_ARG(MEMSETBADBLOCK);
67 TEST_NULL_ARG(MEMUNLOCK);
68 TEST_NULL_ARG(MEMWRITE);
69 TEST_NULL_ARG(MEMWRITEOOB);
70 TEST_NULL_ARG(MEMWRITEOOB64);
71 TEST_NULL_ARG(OTPGETREGIONCOUNT);
72 TEST_NULL_ARG(OTPGETREGIONINFO);
73 TEST_NULL_ARG(OTPLOCK);
74 TEST_NULL_ARG(OTPSELECT);
76 ioctl(-1, MTDFILEMODE, MTD_FILE_MODE_NORMAL);
77 printf("ioctl(-1, MTDFILEMODE, MTD_FILE_MODE_NORMAL) = -1 EBADF (%m)\n");
79 TAIL_ALLOC_OBJECT_CONST_PTR(int, opt);
81 ioctl(-1, OTPSELECT, opt);
82 printf("ioctl(-1, MIXER_READ(%u) or OTPSELECT, [MTD_OTP_OFF])"
83 " = -1 EBADF (%m)\n", (unsigned int) _IOC_NR(OTPSELECT));
85 TAIL_ALLOC_OBJECT_CONST_PTR(uint64_t, v64);
86 fill_memory(v64, sizeof(*v64));
88 ioctl(-1, MEMGETBADBLOCK, v64);
89 printf("ioctl(-1, MIXER_WRITE(%u) or MEMGETBADBLOCK, [%" PRIu64 "])"
91 (unsigned int) _IOC_NR(MEMGETBADBLOCK), *v64);
93 ioctl(-1, MEMSETBADBLOCK, v64);
94 printf("ioctl(-1, MIXER_WRITE(%u) or MEMSETBADBLOCK, [%" PRIu64 "])"
96 (unsigned int) _IOC_NR(MEMSETBADBLOCK), *v64);
98 TAIL_ALLOC_OBJECT_CONST_PTR(struct region_info_user, riu);
99 fill_memory(riu, sizeof(*riu));
100 ioctl(-1, MEMGETREGIONINFO, riu);
101 printf("ioctl(-1, %s, {regionindex=%#x}) = -1 EBADF (%m)\n",
104 " or MTRRIOC_GET_PAGE_ENTRY"
108 TAIL_ALLOC_OBJECT_CONST_PTR(struct erase_info_user, eiu);
109 fill_memory(eiu, sizeof(*eiu));
111 TEST_erase_info_user(MEMERASE, eiu);
112 TEST_erase_info_user(MEMLOCK, eiu);
113 TEST_erase_info_user(MEMUNLOCK, eiu);
114 TEST_erase_info_user(MEMISLOCKED, eiu);
116 TAIL_ALLOC_OBJECT_CONST_PTR(struct erase_info_user64, eiu64);
117 fill_memory(eiu64, sizeof(*eiu64));
118 ioctl(-1, MEMERASE64, eiu64);
119 printf("ioctl(-1, MIXER_WRITE(%u) or %s, {start=%#llx, length=%#llx})"
120 " = -1 EBADF (%m)\n",
121 (unsigned int) _IOC_NR(MEMERASE64), "MEMERASE64",
122 (unsigned long long) eiu64->start,
123 (unsigned long long) eiu64->length);
125 TAIL_ALLOC_OBJECT_CONST_PTR(struct mtd_oob_buf, oob);
126 fill_memory(oob, sizeof(*oob));
128 ioctl(-1, MEMWRITEOOB, oob);
129 printf("ioctl(-1, MEMWRITEOOB, {start=%#x, length=%#x, ptr=%p})"
130 " = -1 EBADF (%m)\n", oob->start, oob->length, oob->ptr);
132 ioctl(-1, MEMREADOOB, oob);
133 printf("ioctl(-1, MEMREADOOB, {start=%#x, length=%#x, ptr=%p})"
134 " = -1 EBADF (%m)\n", oob->start, oob->length, oob->ptr);
136 TAIL_ALLOC_OBJECT_CONST_PTR(struct mtd_oob_buf64, oob64);
137 fill_memory(oob64, sizeof(*oob64));
139 ioctl(-1, MEMWRITEOOB64, oob64);
140 printf("ioctl(-1, MEMWRITEOOB64"
141 ", {start=%#llx, length=%#x, usr_ptr=%#llx}) = -1 EBADF (%m)\n",
142 (unsigned long long) oob64->start, oob64->length,
143 (unsigned long long) oob64->usr_ptr);
145 ioctl(-1, MEMREADOOB64, oob64);
146 printf("ioctl(-1, MEMREADOOB64"
147 ", {start=%#llx, length=%#x, usr_ptr=%#llx}) = -1 EBADF (%m)\n",
148 (unsigned long long) oob64->start, oob64->length,
149 (unsigned long long) oob64->usr_ptr);
152 TAIL_ALLOC_OBJECT_CONST_PTR(struct otp_info, oi);
153 fill_memory(oi, sizeof(*oi));
154 ioctl(-1, OTPLOCK, oi);
155 printf("ioctl(-1, MIXER_READ(%u) or OTPLOCK"
156 ", {start=%#x, length=%#x, locked=%u}) = -1 EBADF (%m)\n",
157 (unsigned int) _IOC_NR(OTPLOCK), oi->start, oi->length, oi->locked);
159 TAIL_ALLOC_OBJECT_CONST_PTR(struct mtd_write_req, wr);
160 fill_memory(wr, sizeof(*wr));
161 wr->mode = MTD_OPS_PLACE_OOB;
162 ioctl(-1, MEMWRITE, wr);
163 printf("ioctl(-1, MEMWRITE, {start=%#llx, len=%#llx, ooblen=%#llx"
164 ", usr_data=%#llx, usr_oob=%#llx, mode=MTD_OPS_PLACE_OOB})"
165 " = -1 EBADF (%m)\n",
166 (unsigned long long) wr->start,
167 (unsigned long long) wr->len,
168 (unsigned long long) wr->ooblen,
169 (unsigned long long) wr->usr_data,
170 (unsigned long long) wr->usr_oob);
172 ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, 0x4d, 0xfe, 0xff), lmagic);
173 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n",
174 "_IOC(_IOC_READ|_IOC_WRITE, 0x4d, 0xfe, 0xff)", lmagic);
176 puts("+++ exited with 0 +++");
182 SKIP_MAIN_UNDEFINED("HAVE_STRUCT_MTD_WRITE_REQ")