···11+/*22+ * media_device_open.c - Media Controller Device Open Test33+ *44+ * Copyright (c) 2016 Shuah Khan <shuahkh@osg.samsung.com>55+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.66+ *77+ * This file is released under the GPLv2.88+ */99+1010+/*1111+ * This file adds a test for Media Controller API.1212+ * This test should be run as root and should not be1313+ * included in the Kselftest run. This test should be1414+ * run when hardware and driver that makes use Media1515+ * Controller API are present in the system.1616+ *1717+ * This test opens user specified Media Device and calls1818+ * MEDIA_IOC_DEVICE_INFO ioctl, closes the file, and exits.1919+ *2020+ * Usage:2121+ * sudo ./media_device_open -d /dev/mediaX2222+ *2323+ * Run this test is a loop and run bind/unbind on the driver.2424+*/2525+2626+#include <stdio.h>2727+#include <unistd.h>2828+#include <stdlib.h>2929+#include <errno.h>3030+#include <string.h>3131+#include <fcntl.h>3232+#include <sys/ioctl.h>3333+#include <sys/stat.h>3434+#include <linux/media.h>3535+3636+int main(int argc, char **argv)3737+{3838+ int opt;3939+ char media_device[256];4040+ int count = 0;4141+ struct media_device_info mdi;4242+ int ret;4343+ int fd;4444+4545+ if (argc < 2) {4646+ printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);4747+ exit(-1);4848+ }4949+5050+ /* Process arguments */5151+ while ((opt = getopt(argc, argv, "d:")) != -1) {5252+ switch (opt) {5353+ case 'd':5454+ strncpy(media_device, optarg, sizeof(media_device) - 1);5555+ media_device[sizeof(media_device)-1] = '\0';5656+ break;5757+ default:5858+ printf("Usage: %s [-d </dev/mediaX>]\n", argv[0]);5959+ exit(-1);6060+ }6161+ }6262+6363+ if (getuid() != 0) {6464+ printf("Please run the test as root - Exiting.\n");6565+ exit(-1);6666+ }6767+6868+ /* Open Media device and keep it open */6969+ fd = open(media_device, O_RDWR);7070+ if (fd == -1) {7171+ printf("Media Device open errno %s\n", strerror(errno));7272+ exit(-1);7373+ }7474+7575+ ret = ioctl(fd, MEDIA_IOC_DEVICE_INFO, &mdi);7676+ if (ret < 0)7777+ printf("Media Device Info errno %s\n", strerror(errno));7878+ else7979+ printf("Media device model %s driver %s\n",8080+ mdi.model, mdi.driver);8181+}