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