1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <stdio.h>
28#include <unistd.h>
29#include <stdlib.h>
30#include <errno.h>
31#include <string.h>
32#include <fcntl.h>
33#include <sys/ioctl.h>
34#include <sys/stat.h>
35#include <linux/media.h>
36
37int main(int argc, char **argv)
38{
39 int opt;
40 char media_device[256];
41 int count = 0;
42 struct media_device_info mdi;
43 int ret;
44 int fd;
45
46 if (argc < 2) {
47 printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
48 exit(-1);
49 }
50
51
52 while ((opt = getopt(argc, argv, "d:")) != -1) {
53 switch (opt) {
54 case 'd':
55 strncpy(media_device, optarg, sizeof(media_device) - 1);
56 media_device[sizeof(media_device)-1] = '\0';
57 break;
58 default:
59 printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);
60 exit(-1);
61 }
62 }
63
64 if (getuid() != 0) {
65 printf("Please run the test as root - Exiting.\n");
66 exit(-1);
67 }
68
69
70 fd = open(media_device, O_RDWR);
71 if (fd == -1) {
72 printf("Media Device open errno %s\n", strerror(errno));
73 exit(-1);
74 }
75
76 ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);
77 if (ret < 0)
78 printf("Media Device Info errno %s\n", strerror(errno));
79 else
80 printf("Media device model %s driver %s\n",
81 mdi.model, mdi.driver);
82}
83