• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
3  * Copyright (c) 2016-2018 The strace developers.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "tests.h"
30 #include <errno.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <sys/ioctl.h>
34 #include <linux/types.h>
35 #include <linux/videodev2.h>
36 
37 #define cc0(arg) ((unsigned int) (unsigned char) (arg))
38 #define cc1(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 8))
39 #define cc2(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 16))
40 #define cc3(arg) ((unsigned int) (unsigned char) ((unsigned int) (arg) >> 24))
41 #define fourcc(a0, a1, a2, a3) \
42 	((unsigned int)(a0) | \
43 	 ((unsigned int)(a1) << 8) | \
44 	 ((unsigned int)(a2) << 16) | \
45 	 ((unsigned int)(a3) << 24))
46 
47 static const unsigned int magic = 0xdeadbeef;
48 static const unsigned int pf_magic = fourcc('S', '5', '0', '8');
49 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
50 static const unsigned int sf_magic = fourcc('R', 'U', '1', '2');
51 #endif
52 
53 static void
init_v4l2_format(struct v4l2_format * const f,const unsigned int buf_type)54 init_v4l2_format(struct v4l2_format *const f,
55 		 const unsigned int buf_type)
56 {
57 	memset(f, -1, sizeof(*f));
58 	f->type = buf_type;
59 	switch (buf_type) {
60 	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
61 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
62 		f->fmt.pix.width = 0x657b8160;
63 		f->fmt.pix.height = 0x951c0047;
64 		if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
65 			f->fmt.pix.pixelformat = magic;
66 		else
67 			f->fmt.pix.pixelformat = pf_magic;
68 		f->fmt.pix.field = V4L2_FIELD_NONE;
69 		f->fmt.pix.bytesperline = 0xdf20d185;
70 		f->fmt.pix.sizeimage = 0x0cf7be41;
71 		f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
72 		break;
73 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
74 	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
75 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: {
76 		unsigned int i;
77 
78 		f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
79 		f->fmt.pix_mp.width = 0x1f3b774b;
80 		f->fmt.pix_mp.height = 0xab96a8d6;
81 		if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
82 			f->fmt.pix_mp.pixelformat = magic;
83 		else
84 			f->fmt.pix_mp.pixelformat = pf_magic;
85 		f->fmt.pix_mp.field = V4L2_FIELD_NONE;
86 		f->fmt.pix_mp.colorspace = V4L2_COLORSPACE_JPEG;
87 		struct v4l2_plane_pix_format *cur_pix =
88 		       f->fmt.pix_mp.plane_fmt;
89 		for (i = 0;
90 		     i < ARRAY_SIZE(f->fmt.pix_mp.plane_fmt);
91 		     i++) {
92 			cur_pix[i].sizeimage = 0x1e3c531c | i;
93 			cur_pix[i].bytesperline = 0xa983d721 | i;
94 		}
95 		break;
96 	}
97 #endif
98 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
99 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
100 #endif
101 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
102 		f->fmt.win.w.left = 0xe8373662;
103 		f->fmt.win.w.top = 0x0336d283;
104 		f->fmt.win.w.width = 0x9235fe72;
105 		f->fmt.win.w.height = 0xbbd886c8;
106 		f->fmt.win.field = V4L2_FIELD_ANY;
107 		f->fmt.win.chromakey = 0xdb1f991f;
108 		f->fmt.win.clipcount = 2;
109 		f->fmt.win.clips =
110 			tail_alloc(sizeof(*f->fmt.win.clips) *
111 			f->fmt.win.clipcount);
112 		f->fmt.win.clips[0].c.left = 0x3313d36e;
113 		f->fmt.win.clips[0].c.top = 0xcdffe510;
114 		f->fmt.win.clips[0].c.width = 0x2064f3a8;
115 		f->fmt.win.clips[0].c.height = 0xd06d314a;
116 		f->fmt.win.clips[1].c.left = 0xd8c8a83f;
117 		f->fmt.win.clips[1].c.top = 0x336e87ba;
118 		f->fmt.win.clips[1].c.width = 0x9e3a6fb3;
119 		f->fmt.win.clips[1].c.height = 0x05617b76;
120 
121 		f->fmt.win.bitmap = (void *) -2UL;
122 #ifdef HAVE_STRUCT_V4L2_WINDOW_GLOBAL_ALPHA
123 		f->fmt.win.global_alpha = 0xce;
124 #endif
125 		break;
126 	case V4L2_BUF_TYPE_VBI_CAPTURE:
127 	case V4L2_BUF_TYPE_VBI_OUTPUT:
128 		f->fmt.vbi.sampling_rate = 0x3d9b5b79;
129 		f->fmt.vbi.offset = 0x055b3a09;
130 		f->fmt.vbi.samples_per_line = 0xf176d436;
131 		if (buf_type == V4L2_BUF_TYPE_VBI_CAPTURE)
132 			f->fmt.vbi.sample_format = magic;
133 		else
134 			f->fmt.vbi.sample_format = pf_magic;
135 		f->fmt.vbi.start[0] = 0x9858e2eb;
136 		f->fmt.vbi.start[1] = 0x8a4dc8c1;
137 		f->fmt.vbi.count[0] = 0x4bcf36a3;
138 		f->fmt.vbi.count[1] = 0x97dff65f;
139 		f->fmt.vbi.flags = V4L2_VBI_INTERLACED;
140 		break;
141 #if HAVE_DECL_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
142 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
143 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: {
144 		unsigned int i;
145 
146 		f->fmt.sliced.service_set = V4L2_SLICED_VPS;
147 		f->fmt.sliced.io_size = 0xd897925a;
148 		for (i = 0;
149 		     i < ARRAY_SIZE(f->fmt.sliced.service_lines[0]);
150 		     i++) {
151 			f->fmt.sliced.service_lines[0][i] = 0xc38e | i;
152 			f->fmt.sliced.service_lines[1][i] = 0x3abb | i;
153 		}
154 		break;
155 	}
156 #endif
157 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
158 	case V4L2_BUF_TYPE_SDR_OUTPUT:
159 		f->fmt.sdr.pixelformat = sf_magic;
160 # ifdef HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE
161 		f->fmt.sdr.buffersize = 0x25afabfb;
162 # endif
163 		break;
164 #endif
165 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_CAPTURE
166 	case V4L2_BUF_TYPE_SDR_CAPTURE:
167 		f->fmt.sdr.pixelformat = magic;
168 # ifdef HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE
169 		f->fmt.sdr.buffersize = 0x25afabfb;
170 # endif
171 		break;
172 #endif
173 	}
174 }
175 
176 static void
dprint_ioctl_v4l2(struct v4l2_format * const f,const char * request,const unsigned int buf_type,const char * buf_type_string)177 dprint_ioctl_v4l2(struct v4l2_format *const f,
178 		  const char *request, const unsigned int buf_type,
179 		  const char *buf_type_string)
180 {
181 	int saved_errno;
182 
183 	switch (buf_type) {
184 	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
185 	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
186 		saved_errno = errno;
187 		printf("ioctl(-1, %s, {type=%s"
188 		       ", fmt.pix={width=%u, height=%u, pixelformat=",
189 		       request,
190 		       buf_type_string,
191 		       f->fmt.pix.width, f->fmt.pix.height);
192 
193 		if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
194 			printf("v4l2_fourcc('\\x%x', '\\x%x', '\\x%x', '\\x%x')",
195 			       cc0(magic), cc1(magic), cc2(magic), cc3(magic));
196 		else
197 			printf("v4l2_fourcc('%c', '%c', '%c', '%c') "
198 			       "/* V4L2_PIX_FMT_SPCA508 */",
199 			       cc0(pf_magic), cc1(pf_magic), cc2(pf_magic),
200 			       cc3(pf_magic));
201 
202 		errno = saved_errno;
203 		printf(", field=V4L2_FIELD_NONE, bytesperline=%u, sizeimage=%u"
204 		       ", colorspace=V4L2_COLORSPACE_JPEG}}) = -1 EBADF (%m)\n",
205 		       f->fmt.pix.bytesperline,
206 		       f->fmt.pix.sizeimage);
207 		break;
208 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
209 	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
210 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: {
211 		unsigned int i;
212 
213 		saved_errno = errno;
214 		printf("ioctl(-1, %s"
215 		       ", {type=%s"
216 		       ", fmt.pix_mp={width=%u, height=%u, pixelformat=",
217 		       request,
218 		       buf_type_string,
219 		       f->fmt.pix_mp.width, f->fmt.pix_mp.height);
220 
221 		if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
222 			printf("v4l2_fourcc('\\x%x', '\\x%x', '\\x%x', '\\x%x')",
223 			       cc0(magic), cc1(magic), cc2(magic), cc3(magic));
224 		else
225 			printf("v4l2_fourcc('%c', '%c', '%c', '%c') "
226 			       "/* V4L2_PIX_FMT_SPCA508 */",
227 			       cc0(pf_magic), cc1(pf_magic), cc2(pf_magic),
228 			       cc3(pf_magic));
229 
230 		printf(", field=V4L2_FIELD_NONE, colorspace="
231 		       "V4L2_COLORSPACE_JPEG, plane_fmt=[");
232 		for (i = 0;
233 		     i < ARRAY_SIZE(f->fmt.pix_mp.plane_fmt);
234 		     ++i) {
235 			if (i)
236 				printf(", ");
237 			printf("{sizeimage=%u, bytesperline=%u}",
238 			f->fmt.pix_mp.plane_fmt[i].sizeimage,
239 			f->fmt.pix_mp.plane_fmt[i].bytesperline);
240 		}
241 		errno = saved_errno;
242 		printf("], num_planes=%u}}) = -1 EBADF (%m)\n",
243 		f->fmt.pix_mp.num_planes);
244 		break;
245 	}
246 #endif
247 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
248 	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
249 #endif
250 	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
251 		printf("ioctl(-1, %s, {type=%s"
252 		       ", fmt.win={left=%d, top=%d, width=%u, height=%u"
253 		       ", field=V4L2_FIELD_ANY, chromakey=%#x, clips="
254 		       "[{left=%d, top=%d, width=%u, height=%u}, "
255 		       "{left=%d, top=%d, width=%u, height=%u}]"
256 		       ", clipcount=%u, bitmap=%p"
257 #ifdef HAVE_STRUCT_V4L2_WINDOW_GLOBAL_ALPHA
258 		       ", global_alpha=%#x"
259 #endif
260 		       "}}) = -1 EBADF (%m)\n",
261 		       request,
262 		       buf_type_string,
263 		       f->fmt.win.w.left, f->fmt.win.w.top,
264 		       f->fmt.win.w.width, f->fmt.win.w.height,
265 		       f->fmt.win.chromakey,
266 		       f->fmt.win.clips[0].c.left,
267 		       f->fmt.win.clips[0].c.top,
268 		       f->fmt.win.clips[0].c.width,
269 		       f->fmt.win.clips[0].c.height,
270 		       f->fmt.win.clips[1].c.left,
271 		       f->fmt.win.clips[1].c.top,
272 		       f->fmt.win.clips[1].c.width,
273 		       f->fmt.win.clips[1].c.height,
274 		       f->fmt.win.clipcount, f->fmt.win.bitmap
275 #ifdef HAVE_STRUCT_V4L2_WINDOW_GLOBAL_ALPHA
276 		       , f->fmt.win.global_alpha
277 #endif
278 		       );
279 		break;
280 	case V4L2_BUF_TYPE_VBI_CAPTURE:
281 	case V4L2_BUF_TYPE_VBI_OUTPUT:
282 		saved_errno = errno;
283 		printf("ioctl(-1, %s, {type=%s"
284 		       ", fmt.vbi={sampling_rate=%u, offset=%u"
285 		       ", samples_per_line=%u, sample_format=",
286 		       request,
287 		       buf_type_string,
288 		       f->fmt.vbi.sampling_rate, f->fmt.vbi.offset,
289 		       f->fmt.vbi.samples_per_line);
290 
291 		if (buf_type == V4L2_BUF_TYPE_VBI_CAPTURE)
292 			printf("v4l2_fourcc('\\x%x', '\\x%x', '\\x%x', '\\x%x')",
293 			       cc0(magic), cc1(magic), cc2(magic), cc3(magic));
294 		else
295 			printf("v4l2_fourcc('%c', '%c', '%c', '%c') "
296 			       "/* V4L2_PIX_FMT_SPCA508 */",
297 			       cc0(pf_magic), cc1(pf_magic), cc2(pf_magic),
298 			       cc3(pf_magic));
299 
300 		errno = saved_errno;
301 		printf(", start=[%u, %u], count=[%u, %u]"
302 		       ", flags=V4L2_VBI_INTERLACED}})"
303 		       " = -1 EBADF (%m)\n",
304 		       f->fmt.vbi.start[0], f->fmt.vbi.start[1],
305 		       f->fmt.vbi.count[0], f->fmt.vbi.count[1]);
306 		break;
307 #if HAVE_DECL_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
308 	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
309 	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: {
310 		unsigned int i, j;
311 
312 		printf("ioctl(-1, %s, {type=%s"
313 		       ", fmt.sliced={service_set=V4L2_SLICED_VPS"
314 		       ", io_size=%u, service_lines=[",
315 		       request,
316 		       buf_type_string,
317 		       f->fmt.sliced.io_size);
318 		for (i = 0;
319 		     i < ARRAY_SIZE(f->fmt.sliced.service_lines);
320 		     i++) {
321 			if (i > 0)
322 				printf(", ");
323 			printf("[");
324 			for (j = 0;
325 			     j < ARRAY_SIZE(f->fmt.sliced.service_lines[0]);
326 			     j++) {
327 				if (j > 0)
328 					printf(", ");
329 				printf("%#x",
330 				       f->fmt.sliced.service_lines[i][j]);
331 			}
332 			printf("]");
333 		}
334 		printf("]}}) = -1 EBADF (%m)\n");
335 		break;
336 	}
337 #endif
338 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
339 	case V4L2_BUF_TYPE_SDR_OUTPUT:
340 #endif
341 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_CAPTURE
342 	case V4L2_BUF_TYPE_SDR_CAPTURE:
343 		saved_errno = errno;
344 		printf("ioctl(-1, %s, {type=%s"
345 		       ", fmt.sdr={pixelformat=",
346 		       request,
347 		       buf_type_string);
348 
349 		if (buf_type == V4L2_BUF_TYPE_SDR_CAPTURE)
350 			printf("v4l2_fourcc('\\x%x', '\\x%x', '\\x%x', '\\x%x')",
351 			       cc0(magic), cc1(magic), cc2(magic), cc3(magic));
352 # if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
353 		else
354 			printf("v4l2_fourcc('%c', '%c', '%c', '%c') "
355 			       "/* V4L2_SDR_FMT_RU12LE */",
356 			       cc0(sf_magic), cc1(sf_magic), cc2(sf_magic),
357 			       cc3(sf_magic));
358 # endif
359 
360 		errno = saved_errno;
361 		printf(
362 #ifdef HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE
363 		       ", buffersize=%u"
364 #endif
365 		       "}}) = -1 EBADF (%m)\n"
366 #ifdef HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE
367 		       , f->fmt.sdr.buffersize
368 #endif
369 		       );
370 		break;
371 #endif
372 	}
373 }
374 #define print_ioctl_v4l2(v4l2_format, request, buf_type)	\
375 	dprint_ioctl_v4l2((v4l2_format), (request), (buf_type), #buf_type)
376 
377 int
main(void)378 main(void)
379 {
380 	const unsigned int size = get_page_size();
381 	void *const page = tail_alloc(size);
382 	void *const page_end = page + size;
383 	fill_memory(page, size);
384 
385 	unsigned char cc[sizeof(int)] = { 'A', '\'', '\\', '\xfa' };
386 
387 	/* VIDIOC_QUERYCAP */
388 	ioctl(-1, VIDIOC_QUERYCAP, 0);
389 	printf("ioctl(-1, VIDIOC_QUERYCAP, NULL) = -1 EBADF (%m)\n");
390 
391 	ioctl(-1, VIDIOC_QUERYCAP, page);
392 	printf("ioctl(-1, VIDIOC_QUERYCAP, %p) = -1 EBADF (%m)\n", page);
393 
394 	/* VIDIOC_ENUM_FMT */
395 	ioctl(-1, VIDIOC_ENUM_FMT, 0);
396 	printf("ioctl(-1, VIDIOC_ENUM_FMT, NULL) = -1 EBADF (%m)\n");
397 
398 	TAIL_ALLOC_OBJECT_CONST_PTR(struct v4l2_fmtdesc, p_fmtdesc);
399 	p_fmtdesc->index = magic;
400 	p_fmtdesc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
401 	ioctl(-1, VIDIOC_ENUM_FMT, p_fmtdesc);
402 	printf("ioctl(-1, VIDIOC_ENUM_FMT, {index=%u"
403 	       ", type=V4L2_BUF_TYPE_VIDEO_CAPTURE}) = -1 EBADF (%m)\n",
404 	       p_fmtdesc->index);
405 
406 	/* VIDIOC_G_FMT */
407 	ioctl(-1, VIDIOC_G_FMT, 0);
408 	printf("ioctl(-1, VIDIOC_G_FMT, NULL) = -1 EBADF (%m)\n");
409 
410 	TAIL_ALLOC_OBJECT_CONST_PTR(struct v4l2_format, p_format);
411 
412 	p_format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
413 	ioctl(-1, VIDIOC_G_FMT, p_format);
414 	printf("ioctl(-1, VIDIOC_G_FMT"
415 	       ", {type=V4L2_BUF_TYPE_VIDEO_CAPTURE}) = -1 EBADF (%m)\n");
416 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
417 	p_format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
418 	ioctl(-1, VIDIOC_G_FMT, p_format);
419 	printf("ioctl(-1, VIDIOC_G_FMT"
420 	       ", {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE}) ="
421 	       " -1 EBADF (%m)\n");
422 #endif
423 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
424 	p_format->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY;
425 	ioctl(-1, VIDIOC_G_FMT, p_format);
426 	printf("ioctl(-1, VIDIOC_G_FMT"
427 	       ", {type=V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY}) ="
428 	       " -1 EBADF (%m)\n");
429 #endif
430 	p_format->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
431 	ioctl(-1, VIDIOC_G_FMT, p_format);
432 	printf("ioctl(-1, VIDIOC_G_FMT"
433 	       ", {type=V4L2_BUF_TYPE_VIDEO_OVERLAY}) ="
434 	       " -1 EBADF (%m)\n");
435 
436 	p_format->type = V4L2_BUF_TYPE_VBI_CAPTURE;
437 	ioctl(-1, VIDIOC_G_FMT, p_format);
438 	printf("ioctl(-1, VIDIOC_G_FMT"
439 	       ", {type=V4L2_BUF_TYPE_VBI_CAPTURE}) = -1 EBADF (%m)\n");
440 #if HAVE_DECL_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
441 	p_format->type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
442 	ioctl(-1, VIDIOC_G_FMT, p_format);
443 	printf("ioctl(-1, VIDIOC_G_FMT"
444 	       ", {type=V4L2_BUF_TYPE_SLICED_VBI_CAPTURE}) = -1 EBADF (%m)\n");
445 #endif
446 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_CAPTURE
447 	p_format->type = V4L2_BUF_TYPE_SDR_CAPTURE;
448 	ioctl(-1, VIDIOC_G_FMT, p_format);
449 	printf("ioctl(-1, VIDIOC_G_FMT"
450 	       ", {type=V4L2_BUF_TYPE_SDR_CAPTURE}) = -1 EBADF (%m)\n");
451 #endif
452 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
453 	p_format->type = V4L2_BUF_TYPE_SDR_OUTPUT;
454 	ioctl(-1, VIDIOC_G_FMT, p_format);
455 	printf("ioctl(-1, VIDIOC_G_FMT"
456 	       ", {type=V4L2_BUF_TYPE_SDR_OUTPUT}) = -1 EBADF (%m)\n");
457 #endif
458 	/* VIDIOC_S_FMT */
459 	ioctl(-1, VIDIOC_S_FMT, 0);
460 	printf("ioctl(-1, VIDIOC_S_FMT, NULL) = -1 EBADF (%m)\n");
461 
462 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VIDEO_OUTPUT);
463 	ioctl(-1, VIDIOC_S_FMT, p_format);
464 	print_ioctl_v4l2(p_format, "VIDIOC_S_FMT", V4L2_BUF_TYPE_VIDEO_OUTPUT);
465 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
466 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
467 	ioctl(-1, VIDIOC_S_FMT, p_format);
468 	print_ioctl_v4l2(p_format, "VIDIOC_S_FMT",
469 			 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
470 #endif
471 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
472 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY);
473 	ioctl(-1, VIDIOC_S_FMT, p_format);
474 	print_ioctl_v4l2(p_format, "VIDIOC_S_FMT",
475 			 V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY);
476 #endif
477 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VIDEO_OVERLAY);
478 	ioctl(-1, VIDIOC_S_FMT, p_format);
479 	print_ioctl_v4l2(p_format, "VIDIOC_S_FMT",
480 			 V4L2_BUF_TYPE_VIDEO_OVERLAY);
481 
482 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VBI_CAPTURE);
483 	ioctl(-1, VIDIOC_S_FMT, p_format);
484 	print_ioctl_v4l2(p_format, "VIDIOC_S_FMT", V4L2_BUF_TYPE_VBI_CAPTURE);
485 #if HAVE_DECL_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
486 	init_v4l2_format(p_format, V4L2_BUF_TYPE_SLICED_VBI_CAPTURE);
487 	ioctl(-1, VIDIOC_S_FMT, p_format);
488 	print_ioctl_v4l2(p_format, "VIDIOC_S_FMT",
489 			 V4L2_BUF_TYPE_SLICED_VBI_CAPTURE);
490 #endif
491 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_CAPTURE
492 	init_v4l2_format(p_format, V4L2_BUF_TYPE_SDR_CAPTURE);
493 	ioctl(-1, VIDIOC_S_FMT, p_format);
494 	print_ioctl_v4l2(p_format, "VIDIOC_S_FMT", V4L2_BUF_TYPE_SDR_CAPTURE);
495 #endif
496 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
497 	init_v4l2_format(p_format, V4L2_BUF_TYPE_SDR_OUTPUT);
498 	ioctl(-1, VIDIOC_S_FMT, p_format);
499 	print_ioctl_v4l2(p_format, "VIDIOC_S_FMT", V4L2_BUF_TYPE_SDR_OUTPUT);
500 #endif
501 	/* VIDIOC_TRY_FMT */
502 	ioctl(-1, VIDIOC_TRY_FMT, 0);
503 	printf("ioctl(-1, VIDIOC_TRY_FMT, NULL) = -1 EBADF (%m)\n");
504 
505 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VIDEO_OUTPUT);
506 	ioctl(-1, VIDIOC_TRY_FMT, p_format);
507 	print_ioctl_v4l2(p_format, "VIDIOC_TRY_FMT",
508 			 V4L2_BUF_TYPE_VIDEO_OUTPUT);
509 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
510 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
511 	ioctl(-1, VIDIOC_TRY_FMT, p_format);
512 	print_ioctl_v4l2(p_format, "VIDIOC_TRY_FMT",
513 			 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
514 #endif
515 #if HAVE_DECL_V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
516 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY);
517 	ioctl(-1, VIDIOC_TRY_FMT, p_format);
518 	print_ioctl_v4l2(p_format, "VIDIOC_TRY_FMT",
519 			 V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY);
520 #endif
521 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VIDEO_OVERLAY);
522 	ioctl(-1, VIDIOC_TRY_FMT, p_format);
523 	print_ioctl_v4l2(p_format, "VIDIOC_TRY_FMT",
524 			 V4L2_BUF_TYPE_VIDEO_OVERLAY);
525 
526 	init_v4l2_format(p_format, V4L2_BUF_TYPE_VBI_CAPTURE);
527 	ioctl(-1, VIDIOC_TRY_FMT, p_format);
528 	print_ioctl_v4l2(p_format, "VIDIOC_TRY_FMT", V4L2_BUF_TYPE_VBI_CAPTURE);
529 #if HAVE_DECL_V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
530 	init_v4l2_format(p_format, V4L2_BUF_TYPE_SLICED_VBI_CAPTURE);
531 	ioctl(-1, VIDIOC_TRY_FMT, p_format);
532 	print_ioctl_v4l2(p_format, "VIDIOC_TRY_FMT",
533 			 V4L2_BUF_TYPE_SLICED_VBI_CAPTURE);
534 #endif
535 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_CAPTURE
536 	init_v4l2_format(p_format, V4L2_BUF_TYPE_SDR_CAPTURE);
537 	ioctl(-1, VIDIOC_TRY_FMT, p_format);
538 	print_ioctl_v4l2(p_format, "VIDIOC_TRY_FMT", V4L2_BUF_TYPE_SDR_CAPTURE);
539 #endif
540 #if HAVE_DECL_V4L2_BUF_TYPE_SDR_OUTPUT
541 	init_v4l2_format(p_format, V4L2_BUF_TYPE_SDR_OUTPUT);
542 	ioctl(-1, VIDIOC_TRY_FMT, p_format);
543 	print_ioctl_v4l2(p_format, "VIDIOC_TRY_FMT", V4L2_BUF_TYPE_SDR_OUTPUT);
544 #endif
545 	struct v4l2_format *const p_v4l2_format =
546 		page_end - sizeof(*p_v4l2_format);
547 	ioctl(-1, VIDIOC_TRY_FMT, p_v4l2_format);
548 	printf("ioctl(-1, VIDIOC_TRY_FMT, {type=%#x /* V4L2_BUF_TYPE_??? */})"
549 	       " = -1 EBADF (%m)\n", p_v4l2_format->type);
550 
551 	/* VIDIOC_REQBUFS */
552 	ioctl(-1, VIDIOC_REQBUFS, 0);
553 	printf("ioctl(-1, VIDIOC_REQBUFS, NULL) = -1 EBADF (%m)\n");
554 
555 	struct v4l2_requestbuffers *const p_v4l2_requestbuffers =
556 		page_end - sizeof(*p_v4l2_requestbuffers);
557 	ioctl(-1, VIDIOC_REQBUFS, p_v4l2_requestbuffers);
558 	printf("ioctl(-1, VIDIOC_REQBUFS, {type=%#x /* V4L2_BUF_TYPE_??? */, "
559 	       "memory=%#x /* V4L2_MEMORY_??? */, count=%u})"
560 	       " = -1 EBADF (%m)\n",
561 	       p_v4l2_requestbuffers->type,
562 	       p_v4l2_requestbuffers->memory,
563 	       p_v4l2_requestbuffers->count);
564 
565 	/* VIDIOC_QUERYBUF */
566 	ioctl(-1, VIDIOC_QUERYBUF, 0);
567 	printf("ioctl(-1, VIDIOC_QUERYBUF, NULL) = -1 EBADF (%m)\n");
568 
569 	struct v4l2_buffer *const p_v4l2_buffer =
570 		page_end - sizeof(*p_v4l2_buffer);
571 	ioctl(-1, VIDIOC_QUERYBUF, p_v4l2_buffer);
572 	printf("ioctl(-1, VIDIOC_QUERYBUF, {type=%#x /* V4L2_BUF_TYPE_??? */"
573 	       ", index=%u}) = -1 EBADF (%m)\n",
574 	       p_v4l2_buffer->type, p_v4l2_buffer->index);
575 
576 	/* VIDIOC_QBUF */
577 	ioctl(-1, VIDIOC_QBUF, 0);
578 	printf("ioctl(-1, VIDIOC_QBUF, NULL) = -1 EBADF (%m)\n");
579 
580 	ioctl(-1, VIDIOC_QBUF, p_v4l2_buffer);
581 	printf("ioctl(-1, VIDIOC_QBUF, {type=%#x /* V4L2_BUF_TYPE_??? */"
582 	       ", index=%u}) = -1 EBADF (%m)\n",
583 	       p_v4l2_buffer->type, p_v4l2_buffer->index);
584 
585 	/* VIDIOC_DQBUF */
586 	ioctl(-1, VIDIOC_DQBUF, 0);
587 	printf("ioctl(-1, VIDIOC_DQBUF, NULL) = -1 EBADF (%m)\n");
588 
589 	ioctl(-1, VIDIOC_DQBUF, p_v4l2_buffer);
590 	printf("ioctl(-1, VIDIOC_DQBUF, {type=%#x"
591 	       " /* V4L2_BUF_TYPE_??? */}) = -1 EBADF (%m)\n",
592 	       p_v4l2_buffer->type);
593 
594 	/* VIDIOC_G_FBUF */
595 	ioctl(-1, VIDIOC_G_FBUF, 0);
596 	printf("ioctl(-1, VIDIOC_G_FBUF, NULL) = -1 EBADF (%m)\n");
597 
598 	ioctl(-1, VIDIOC_G_FBUF, page);
599 	printf("ioctl(-1, VIDIOC_G_FBUF, %p) = -1 EBADF (%m)\n", page);
600 
601 	/* VIDIOC_S_FBUF */
602 	ioctl(-1, VIDIOC_S_FBUF, 0);
603 	printf("ioctl(-1, VIDIOC_S_FBUF, NULL) = -1 EBADF (%m)\n");
604 
605 	struct v4l2_framebuffer *const p_v4l2_framebuffer =
606 		page_end - sizeof(*p_v4l2_framebuffer);
607 	ioctl(-1, VIDIOC_S_FBUF, p_v4l2_framebuffer);
608 	printf("ioctl(-1, VIDIOC_S_FBUF, {capability=%#x"
609 	       ", flags=%#x, base=%p}) = -1 EBADF (%m)\n",
610 	       p_v4l2_framebuffer->capability,
611 	       p_v4l2_framebuffer->flags,
612 	       p_v4l2_framebuffer->base);
613 
614 	/* VIDIOC_STREAMON */
615 	ioctl(-1, VIDIOC_STREAMON, 0);
616 	printf("ioctl(-1, VIDIOC_STREAMON, NULL) = -1 EBADF (%m)\n");
617 
618 	int *const p_int = page_end - sizeof(int);
619 	ioctl(-1, VIDIOC_STREAMON, p_int);
620 	printf("ioctl(-1, VIDIOC_STREAMON, [%#x /* V4L2_BUF_TYPE_??? */])"
621 	       " = -1 EBADF (%m)\n", *p_int);
622 
623 	/* VIDIOC_STREAMOFF */
624 	ioctl(-1, VIDIOC_STREAMOFF, 0);
625 	printf("ioctl(-1, VIDIOC_STREAMOFF, NULL) = -1 EBADF (%m)\n");
626 
627 	ioctl(-1, VIDIOC_STREAMOFF, p_int);
628 	printf("ioctl(-1, VIDIOC_STREAMOFF, [%#x /* V4L2_BUF_TYPE_??? */])"
629 	       " = -1 EBADF (%m)\n", *p_int);
630 
631 	/* VIDIOC_G_PARM */
632 	ioctl(-1, VIDIOC_G_PARM, 0);
633 	printf("ioctl(-1, VIDIOC_G_PARM, NULL) = -1 EBADF (%m)\n");
634 
635 	struct v4l2_streamparm *const p_v4l2_streamparm =
636 		page_end - sizeof(*p_v4l2_streamparm);
637 	ioctl(-1, VIDIOC_G_PARM, p_v4l2_streamparm);
638 	printf("ioctl(-1, VIDIOC_G_PARM, {type=%#x /* V4L2_BUF_TYPE_??? */})"
639 	       " = -1 EBADF (%m)\n", p_v4l2_streamparm->type);
640 
641 	/* VIDIOC_S_PARM */
642 	ioctl(-1, VIDIOC_S_PARM, 0);
643 	printf("ioctl(-1, VIDIOC_S_PARM, NULL) = -1 EBADF (%m)\n");
644 
645 	ioctl(-1, VIDIOC_S_PARM, p_v4l2_streamparm);
646 	printf("ioctl(-1, VIDIOC_S_PARM, {type=%#x /* V4L2_BUF_TYPE_??? */})"
647 	       " = -1 EBADF (%m)\n", p_v4l2_streamparm->type);
648 
649 	TAIL_ALLOC_OBJECT_CONST_PTR(struct v4l2_streamparm, p_streamparm);
650 	p_streamparm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
651 	p_streamparm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
652 	p_streamparm->parm.capture.capturemode = V4L2_MODE_HIGHQUALITY;
653 	p_streamparm->parm.capture.timeperframe.numerator = 0xdeadbeef;
654 	p_streamparm->parm.capture.timeperframe.denominator = 0xbadc0ded;
655 	ioctl(-1, VIDIOC_S_PARM, p_streamparm);
656 	printf("ioctl(-1, VIDIOC_S_PARM, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE"
657 	       ", parm.capture={capability=V4L2_CAP_TIMEPERFRAME"
658 	       ", capturemode=V4L2_MODE_HIGHQUALITY, timeperframe=%u/%u"
659 	       ", extendedmode=%u, readbuffers=%u}}) = -1 EBADF (%m)\n",
660 	       p_streamparm->parm.capture.timeperframe.numerator,
661 	       p_streamparm->parm.capture.timeperframe.denominator, -1U, -1U);
662 
663 	p_streamparm->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
664 	p_streamparm->parm.output.outputmode = 0;
665 	ioctl(-1, VIDIOC_S_PARM, p_streamparm);
666 	printf("ioctl(-1, VIDIOC_S_PARM, {type=V4L2_BUF_TYPE_VIDEO_OUTPUT"
667 	       ", parm.output={capability=V4L2_CAP_TIMEPERFRAME"
668 	       ", outputmode=0, timeperframe=%u/%u"
669 	       ", extendedmode=%u, writebuffers=%u}}) = -1 EBADF (%m)\n",
670 	       p_streamparm->parm.output.timeperframe.numerator,
671 	       p_streamparm->parm.output.timeperframe.denominator, -1U, -1U);
672 
673 	/* VIDIOC_G_STD */
674 	ioctl(-1, VIDIOC_G_STD, 0);
675 	printf("ioctl(-1, VIDIOC_G_STD, NULL) = -1 EBADF (%m)\n");
676 
677 	ioctl(-1, VIDIOC_G_STD, page);
678 	printf("ioctl(-1, VIDIOC_G_STD, %p) = -1 EBADF (%m)\n", page);
679 
680 	/* VIDIOC_S_STD */
681 	ioctl(-1, VIDIOC_S_STD, 0);
682 	printf("ioctl(-1, VIDIOC_S_STD, NULL) = -1 EBADF (%m)\n");
683 
684 	long long *const p_longlong = page_end - sizeof(*p_longlong);
685 	ioctl(-1, VIDIOC_S_STD, p_longlong);
686 	printf("ioctl(-1, VIDIOC_S_STD, [%#llx]) = -1 EBADF (%m)\n",
687 	       *p_longlong);
688 
689 	/* VIDIOC_ENUMSTD */
690 	ioctl(-1, VIDIOC_ENUMSTD, 0);
691 	printf("ioctl(-1, VIDIOC_ENUMSTD, NULL) = -1 EBADF (%m)\n");
692 
693 	struct v4l2_standard *const p_v4l2_standard =
694 		page_end - sizeof(*p_v4l2_standard);
695 	ioctl(-1, VIDIOC_ENUMSTD, p_v4l2_standard);
696 	printf("ioctl(-1, VIDIOC_ENUMSTD, {index=%u}) = -1 EBADF (%m)\n",
697 	       p_v4l2_standard->index);
698 
699 	/* VIDIOC_ENUMINPUT */
700 	ioctl(-1, VIDIOC_ENUMINPUT, 0);
701 	printf("ioctl(-1, VIDIOC_ENUMINPUT, NULL) = -1 EBADF (%m)\n");
702 
703 	struct v4l2_input *const p_v4l2_input =
704 		page_end - sizeof(*p_v4l2_input);
705 	ioctl(-1, VIDIOC_ENUMINPUT, p_v4l2_input);
706 	printf("ioctl(-1, VIDIOC_ENUMINPUT, {index=%u}) = -1 EBADF (%m)\n",
707 	       p_v4l2_input->index);
708 
709 	/* VIDIOC_G_CTRL */
710 	ioctl(-1, VIDIOC_G_CTRL, 0);
711 	printf("ioctl(-1, VIDIOC_G_CTRL, NULL) = -1 EBADF (%m)\n");
712 
713 	struct v4l2_control *const p_v4l2_control =
714 		page_end - sizeof(*p_v4l2_control);
715 	ioctl(-1, VIDIOC_G_CTRL, p_v4l2_control);
716 	printf("ioctl(-1, VIDIOC_G_CTRL, {id=%#x /* V4L2_CID_??? */})"
717 	       " = -1 EBADF (%m)\n", p_v4l2_control->id);
718 
719 	/* VIDIOC_S_CTRL */
720 	ioctl(-1, VIDIOC_S_CTRL, 0);
721 	printf("ioctl(-1, VIDIOC_S_CTRL, NULL) = -1 EBADF (%m)\n");
722 
723 	ioctl(-1, VIDIOC_S_CTRL, p_v4l2_control);
724 	printf("ioctl(-1, VIDIOC_S_CTRL, {id=%#x /* V4L2_CID_??? */"
725 	       ", value=%d}) = -1 EBADF (%m)\n",
726 	       p_v4l2_control->id, p_v4l2_control->value);
727 
728 	/* VIDIOC_G_TUNER */
729 	ioctl(-1, VIDIOC_G_TUNER, 0);
730 	printf("ioctl(-1, VIDIOC_G_TUNER, NULL) = -1 EBADF (%m)\n");
731 
732 	struct v4l2_tuner *const p_v4l2_tuner =
733 		page_end - sizeof(*p_v4l2_tuner);
734 	ioctl(-1, VIDIOC_G_TUNER, p_v4l2_tuner);
735 	printf("ioctl(-1, VIDIOC_G_TUNER, {index=%u})"
736 	       " = -1 EBADF (%m)\n", p_v4l2_tuner->index);
737 
738 	/* VIDIOC_S_TUNER */
739 	ioctl(-1, VIDIOC_S_TUNER, 0);
740 	printf("ioctl(-1, VIDIOC_S_TUNER, NULL) = -1 EBADF (%m)\n");
741 
742 	TAIL_ALLOC_OBJECT_CONST_PTR(struct v4l2_tuner, p_tuner);
743 	p_tuner->index = 0x4fb6df39;
744 	strcpy((char *) p_tuner->name, "cum tacent clamant");
745 	p_tuner->type = V4L2_TUNER_RADIO;
746 	p_tuner->capability = V4L2_TUNER_CAP_LOW;
747 	p_tuner->rangelow = 0xa673bc29;
748 	p_tuner->rangehigh = 0xbaf16d12;
749 	p_tuner->rxsubchans = V4L2_TUNER_SUB_MONO;
750 	p_tuner->audmode = V4L2_TUNER_MODE_MONO;
751 	p_tuner->signal = 0x10bf92c8;
752 	p_tuner->afc = 0x3bf7e18b;
753 	ioctl(-1, VIDIOC_S_TUNER, p_tuner);
754 	printf("ioctl(-1, VIDIOC_S_TUNER, {index=%u"
755 	       ", name=\"cum tacent clamant\""
756 	       ", type=V4L2_TUNER_RADIO, capability=V4L2_TUNER_CAP_LOW"
757 	       ", rangelow=%u, rangehigh=%u"
758 	       ", rxsubchans=V4L2_TUNER_SUB_MONO"
759 	       ", audmode=V4L2_TUNER_MODE_MONO, signal=%d, afc=%d"
760 	       "}) = -1 EBADF (%m)\n",
761 	       p_tuner->index, p_tuner->rangelow,
762 	       p_tuner->rangehigh, p_tuner->signal, p_tuner->afc);
763 
764 	/* VIDIOC_QUERYCTRL */
765 	ioctl(-1, VIDIOC_QUERYCTRL, 0);
766 	printf("ioctl(-1, VIDIOC_QUERYCTRL, NULL) = -1 EBADF (%m)\n");
767 
768 	struct v4l2_queryctrl *const p_v4l2_queryctrl =
769 		page_end - sizeof(*p_v4l2_queryctrl);
770 	ioctl(-1, VIDIOC_QUERYCTRL, p_v4l2_queryctrl);
771 # ifdef V4L2_CTRL_FLAG_NEXT_CTRL
772 	printf("ioctl(-1, VIDIOC_QUERYCTRL, {id=V4L2_CTRL_FLAG_NEXT_CTRL"
773 	       "|%#x /* V4L2_CID_??? */}) = -1 EBADF (%m)\n",
774 	       p_v4l2_queryctrl->id & ~V4L2_CTRL_FLAG_NEXT_CTRL);
775 # else
776 	printf("ioctl(-1, VIDIOC_QUERYCTRL, {id=%#x /* V4L2_CID_??? */})"
777 	       " = -1 EBADF (%m)\n", p_v4l2_queryctrl->id);
778 # endif
779 
780 	TAIL_ALLOC_OBJECT_CONST_PTR(struct v4l2_queryctrl, p_queryctrl);
781 	p_queryctrl->id = V4L2_CID_SATURATION;
782 	ioctl(-1, VIDIOC_QUERYCTRL, p_queryctrl);
783 	printf("ioctl(-1, VIDIOC_QUERYCTRL, {id=V4L2_CID_SATURATION})"
784 	       " = -1 EBADF (%m)\n");
785 
786 	/* VIDIOC_G_INPUT */
787 	ioctl(-1, VIDIOC_G_INPUT, 0);
788 	printf("ioctl(-1, VIDIOC_G_INPUT, NULL) = -1 EBADF (%m)\n");
789 
790 	ioctl(-1, VIDIOC_G_INPUT, page);
791 	printf("ioctl(-1, VIDIOC_G_INPUT, %p) = -1 EBADF (%m)\n", page);
792 
793 	/* VIDIOC_S_INPUT */
794 	ioctl(-1, VIDIOC_S_INPUT, 0);
795 	printf("ioctl(-1, VIDIOC_S_INPUT, NULL) = -1 EBADF (%m)\n");
796 
797 	ioctl(-1, VIDIOC_S_INPUT, p_int);
798 	printf("ioctl(-1, VIDIOC_S_INPUT, [%u]) = -1 EBADF (%m)\n", *p_int);
799 
800 	/* VIDIOC_CROPCAP */
801 	ioctl(-1, VIDIOC_CROPCAP, 0);
802 	printf("ioctl(-1, VIDIOC_CROPCAP, NULL) = -1 EBADF (%m)\n");
803 
804 	struct v4l2_cropcap *const p_v4l2_cropcap =
805 		page_end - sizeof(*p_v4l2_cropcap);
806 	ioctl(-1, VIDIOC_CROPCAP, p_v4l2_cropcap);
807 	printf("ioctl(-1, VIDIOC_CROPCAP, {type=%#x /* V4L2_BUF_TYPE_??? */})"
808 	       " = -1 EBADF (%m)\n", p_v4l2_cropcap->type);
809 
810 	/* VIDIOC_G_CROP */
811 	ioctl(-1, VIDIOC_G_CROP, 0);
812 	printf("ioctl(-1, VIDIOC_G_CROP, NULL) = -1 EBADF (%m)\n");
813 
814 	struct v4l2_crop *const p_v4l2_crop =
815 		page_end - sizeof(*p_v4l2_crop);
816 	ioctl(-1, VIDIOC_G_CROP, p_v4l2_crop);
817 	printf("ioctl(-1, VIDIOC_G_CROP, {type=%#x /* V4L2_BUF_TYPE_??? */})"
818 	       " = -1 EBADF (%m)\n", p_v4l2_crop->type);
819 
820 	/* VIDIOC_S_CROP */
821 	ioctl(-1, VIDIOC_S_CROP, 0);
822 	printf("ioctl(-1, VIDIOC_S_CROP, NULL) = -1 EBADF (%m)\n");
823 
824 	ioctl(-1, VIDIOC_S_CROP, p_v4l2_crop);
825 	printf("ioctl(-1, VIDIOC_S_CROP, {type=%#x /* V4L2_BUF_TYPE_??? */"
826 	       ", c={left=%d, top=%d, width=%u, height=%u}}) = -1 EBADF (%m)\n",
827 	       p_v4l2_crop->type,
828 	       p_v4l2_crop->c.left,
829 	       p_v4l2_crop->c.top,
830 	       p_v4l2_crop->c.width,
831 	       p_v4l2_crop->c.height);
832 
833 #ifdef VIDIOC_S_EXT_CTRLS
834 	/* VIDIOC_S_EXT_CTRLS */
835 	ioctl(-1, VIDIOC_S_EXT_CTRLS, 0);
836 	printf("ioctl(-1, VIDIOC_S_EXT_CTRLS, NULL) = -1 EBADF (%m)\n");
837 
838 	TAIL_ALLOC_OBJECT_CONST_PTR(struct v4l2_ext_controls, p_ext_controls);
839 	p_ext_controls->ctrl_class = V4L2_CTRL_CLASS_USER;
840 	p_ext_controls->count = 0;
841 	p_ext_controls->controls = (void *) -2UL;
842 	ioctl(-1, VIDIOC_S_EXT_CTRLS, p_ext_controls);
843 	printf("ioctl(-1, VIDIOC_S_EXT_CTRLS, {ctrl_class=V4L2_CTRL_CLASS_USER"
844 	       ", count=%u}) = -1 EBADF (%m)\n", p_ext_controls->count);
845 
846 	p_ext_controls->ctrl_class = 0x00a30000;
847 	p_ext_controls->count = magic;
848 	ioctl(-1, VIDIOC_S_EXT_CTRLS, p_ext_controls);
849 	printf("ioctl(-1, VIDIOC_S_EXT_CTRLS, {ctrl_class=V4L2_CTRL_CLASS_DETECT"
850 	       ", count=%u, controls=%p}) = -1 EBADF (%m)\n",
851 	       p_ext_controls->count, p_ext_controls->controls);
852 
853 	p_ext_controls->ctrl_class = 0x00a40000;
854 	p_ext_controls->count = magic;
855 	ioctl(-1, VIDIOC_S_EXT_CTRLS, p_ext_controls);
856 	printf("ioctl(-1, VIDIOC_S_EXT_CTRLS"
857 	       ", {ctrl_class=0xa40000 /* V4L2_CTRL_CLASS_??? */"
858 	       ", count=%u, controls=%p}) = -1 EBADF (%m)\n",
859 	       p_ext_controls->count, p_ext_controls->controls);
860 
861 	p_ext_controls->ctrl_class = V4L2_CTRL_CLASS_MPEG;
862 	p_ext_controls->count = magic;
863 	ioctl(-1, VIDIOC_S_EXT_CTRLS, p_ext_controls);
864 	printf("ioctl(-1, VIDIOC_S_EXT_CTRLS, {ctrl_class=V4L2_CTRL_CLASS_MPEG"
865 	       ", count=%u, controls=%p}) = -1 EBADF (%m)\n",
866 	       p_ext_controls->count, p_ext_controls->controls);
867 
868 # if HAVE_DECL_V4L2_CTRL_TYPE_STRING
869 	p_ext_controls->count = 2;
870 	p_ext_controls->controls =
871 		tail_alloc(sizeof(*p_ext_controls->controls) * p_ext_controls->count);
872 	p_ext_controls->controls[0].id = V4L2_CID_BRIGHTNESS;
873 	p_ext_controls->controls[0].size = 0;
874 	p_ext_controls->controls[0].value64 = 0xfacefeeddeadbeefULL;
875 	p_ext_controls->controls[1].id = V4L2_CID_CONTRAST;
876 	p_ext_controls->controls[1].size = 2;
877 	p_ext_controls->controls[1].string =
878 		tail_alloc(p_ext_controls->controls[1].size);
879 
880 	ioctl(-1, VIDIOC_S_EXT_CTRLS, p_ext_controls);
881 	printf("ioctl(-1, VIDIOC_S_EXT_CTRLS"
882 	       ", {ctrl_class=V4L2_CTRL_CLASS_MPEG, count=%u, controls="
883 	       "[{id=V4L2_CID_BRIGHTNESS, size=0, value=%d, value64=%lld}"
884 	       ", {id=V4L2_CID_CONTRAST, size=2, string=\"\\377\\377\"}"
885 	       "] => controls="
886 	       "[{id=V4L2_CID_BRIGHTNESS, size=0, value=%d, value64=%lld}"
887 	       ", {id=V4L2_CID_CONTRAST, size=2, string=\"\\377\\377\"}"
888 	       "], error_idx=%u}) = -1 EBADF (%m)\n",
889 	       p_ext_controls->count,
890 	       p_ext_controls->controls[0].value,
891 	       (long long) p_ext_controls->controls[0].value64,
892 	       p_ext_controls->controls[0].value,
893 	       (long long) p_ext_controls->controls[0].value64,
894 	       p_ext_controls->error_idx);
895 
896 	++p_ext_controls->count;
897 	ioctl(-1, VIDIOC_S_EXT_CTRLS, p_ext_controls);
898 	printf("ioctl(-1, VIDIOC_S_EXT_CTRLS"
899 	       ", {ctrl_class=V4L2_CTRL_CLASS_MPEG, count=%u, controls="
900 	       "[{id=V4L2_CID_BRIGHTNESS, size=0, value=%d, value64=%lld}"
901 	       ", {id=V4L2_CID_CONTRAST, size=2, string=\"\\377\\377\"}"
902 	       ", ... /* %p */]}) = -1 EBADF (%m)\n",
903 	       p_ext_controls->count,
904 	       p_ext_controls->controls[0].value,
905 	       (long long) p_ext_controls->controls[0].value64,
906 	       p_ext_controls->controls + 2);
907 # endif /* HAVE_DECL_V4L2_CTRL_TYPE_STRING */
908 
909 	/* VIDIOC_TRY_EXT_CTRLS */
910 	ioctl(-1, VIDIOC_TRY_EXT_CTRLS, 0);
911 	printf("ioctl(-1, VIDIOC_TRY_EXT_CTRLS, NULL) = -1 EBADF (%m)\n");
912 
913 	p_ext_controls->ctrl_class = V4L2_CTRL_CLASS_USER;
914 	p_ext_controls->count = magic;
915 	p_ext_controls->controls = (void *) -2UL;
916 	ioctl(-1, VIDIOC_TRY_EXT_CTRLS, p_ext_controls);
917 	printf("ioctl(-1, VIDIOC_TRY_EXT_CTRLS"
918 	       ", {ctrl_class=V4L2_CTRL_CLASS_USER, count=%u, controls=%p})"
919 	       " = -1 EBADF (%m)\n",
920 	       p_ext_controls->count, p_ext_controls->controls);
921 
922 	/* VIDIOC_G_EXT_CTRLS */
923 	ioctl(-1, VIDIOC_G_EXT_CTRLS, 0);
924 	printf("ioctl(-1, VIDIOC_G_EXT_CTRLS, NULL) = -1 EBADF (%m)\n");
925 
926 	ioctl(-1, VIDIOC_G_EXT_CTRLS, p_ext_controls);
927 	printf("ioctl(-1, VIDIOC_G_EXT_CTRLS"
928 	       ", {ctrl_class=V4L2_CTRL_CLASS_USER, count=%u, controls=%p"
929 	       ", error_idx=%u}) = -1 EBADF (%m)\n",
930 	       p_ext_controls->count, p_ext_controls->controls,
931 	       p_ext_controls->error_idx);
932 #endif /* VIDIOC_S_EXT_CTRLS */
933 
934 #ifdef VIDIOC_ENUM_FRAMESIZES
935 	ioctl(-1, VIDIOC_ENUM_FRAMESIZES, 0);
936 	printf("ioctl(-1, VIDIOC_ENUM_FRAMESIZES, NULL) = -1 EBADF (%m)\n");
937 
938 	TAIL_ALLOC_OBJECT_CONST_PTR(struct v4l2_frmsizeenum, p_frmsizeenum);
939 	p_frmsizeenum->index = magic;
940 	p_frmsizeenum->pixel_format = fourcc(cc[0], cc[1], cc[2], cc[3]);
941 
942 	ioctl(-1, VIDIOC_ENUM_FRAMESIZES, p_frmsizeenum);
943 	printf("ioctl(-1, VIDIOC_ENUM_FRAMESIZES, {index=%u"
944 	       ", pixel_format=v4l2_fourcc('%c', '\\%c', '\\%c', '\\x%x')})"
945 	       " = -1 EBADF (%m)\n", p_frmsizeenum->index,
946 	       cc[0], cc[1], cc[2], cc[3]);
947 #endif /* VIDIOC_ENUM_FRAMESIZES */
948 
949 #ifdef VIDIOC_ENUM_FRAMEINTERVALS
950 	ioctl(-1, VIDIOC_ENUM_FRAMEINTERVALS, 0);
951 	printf("ioctl(-1, VIDIOC_ENUM_FRAMEINTERVALS, NULL) = -1 EBADF (%m)\n");
952 
953 	struct v4l2_frmivalenum *const p_v4l2_frmivalenum =
954 		page_end - sizeof(*p_v4l2_frmivalenum);
955 	ioctl(-1, VIDIOC_ENUM_FRAMEINTERVALS, p_v4l2_frmivalenum);
956 	printf("ioctl(-1, VIDIOC_ENUM_FRAMEINTERVALS, {index=%u"
957 	       ", pixel_format=v4l2_fourcc('\\x%x', '\\x%x', '\\x%x', '\\x%x')"
958 	       ", width=%u, height=%u}) = -1 EBADF (%m)\n",
959 	       p_v4l2_frmivalenum->index,
960 	       cc0(p_v4l2_frmivalenum->pixel_format),
961 	       cc1(p_v4l2_frmivalenum->pixel_format),
962 	       cc2(p_v4l2_frmivalenum->pixel_format),
963 	       cc3(p_v4l2_frmivalenum->pixel_format),
964 	       p_v4l2_frmivalenum->width,
965 	       p_v4l2_frmivalenum->height);
966 #endif /* VIDIOC_ENUM_FRAMEINTERVALS */
967 
968 #ifdef VIDIOC_CREATE_BUFS
969 	ioctl(-1, VIDIOC_CREATE_BUFS, 0);
970 	printf("ioctl(-1, VIDIOC_CREATE_BUFS, NULL) = -1 EBADF (%m)\n");
971 
972 	struct v4l2_create_buffers *const p_v4l2_create_buffers =
973 		page_end - sizeof(*p_v4l2_create_buffers);
974 	ioctl(-1, VIDIOC_CREATE_BUFS, p_v4l2_create_buffers);
975 	printf("ioctl(-1, VIDIOC_CREATE_BUFS, {count=%u, memory=%#x"
976 	       " /* V4L2_MEMORY_??? */, format={type=%#x"
977 	       " /* V4L2_BUF_TYPE_??? */}}) = -1 EBADF (%m)\n",
978 	       p_v4l2_create_buffers->count,
979 	       p_v4l2_create_buffers->memory,
980 	       p_v4l2_create_buffers->format.type);
981 #endif /* VIDIOC_CREATE_BUFS */
982 
983 	puts("+++ exited with 0 +++");
984 	return 0;
985 }
986