diff options
author | Linus Walleij <triad@df.lth.se> | 2010-12-05 14:00:34 +0000 |
---|---|---|
committer | Linus Walleij <triad@df.lth.se> | 2010-12-05 14:00:34 +0000 |
commit | 549f49a7966b55adde29133d8b97ab9a10a9ab25 (patch) | |
tree | e7e25696c888c32e4fdf0bafa0f5fdceef388347 /util/mtp-probe.c | |
parent | 4f4082b6fac5d3ac61b1cc626759615b9b2813cc (diff) | |
download | libmtp-549f49a7966b55adde29133d8b97ab9a10a9ab25.tar.gz |
Improbe the hotplug capability
Diffstat (limited to 'util/mtp-probe.c')
-rw-r--r-- | util/mtp-probe.c | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/util/mtp-probe.c b/util/mtp-probe.c index 7de15f8..a05820e 100644 --- a/util/mtp-probe.c +++ b/util/mtp-probe.c @@ -4,12 +4,20 @@ * userspace to determine if they are MTP devices, used for * udev rules. * - * Invoke the program on a sysfs device entry to check it - * for MTP signatures, e.g. - * mtp-probe /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-8 + * Invoke the program from udev to check it for MTP signatures, + * e.g. + * ATTR{bDeviceClass}=="ff", + * PROGRAM="<path>/mtp-probe /sys$env{DEVPATH} $attr{busnum} $attr{devnum}", + * RESULT=="1", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1", + * SYMLINK+="libmtp-%k", MODE="666" * - * Exits with status code 0 if the device is an MTP device, - * else exits with 1. + * Is you issue this before testing your /var/log/messages + * will be more verbose: + * + * udevadm control --log-priority=debug + * + * Exits with status code 1 if the device is an MTP device, + * else exits with 0. * * Copyright (C) 2010 Linus Walleij <triad@df.lth.se> * @@ -28,21 +36,44 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ -#include <libmtp.h> +#ifndef __linux__ +#error "This program should only be compiled for Linux!" +#endif + #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <syslog.h> +#include <libmtp.h> int main (int argc, char **argv) { char *fname; + int busno; + int devno; + int ret; - if (argc < 2) { - printf("No device file to check\n"); - exit(1); + if (argc < 4) { + syslog(LOG_INFO, "need device path, busnumber, device number as argument\n"); + printf("0"); + exit(0); } + fname = argv[1]; - printf("Checking: \"%s\"...\n", fname); - exit (1); + busno = atoi(argv[2]); + devno = atoi(argv[3]); + + syslog(LOG_INFO, "checking bus %d, device %d: \"%s\"\n", busno, devno, fname); + + ret = LIBMTP_Check_Specific_Device(busno, devno); + if (ret) { + syslog(LOG_INFO, "bus: %d, device: %d was an MTP device\n", busno, devno); + printf("1"); + } else { + syslog(LOG_INFO, "bus: %d, device: %d was not an MTP device\n", busno, devno); + printf("0"); + } + + exit(0); } |