Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: util/mtp-hotplug.c

Issue 2345493002: Uprev libmtp to 1.1.12 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libmtp@master
Patch Set: Re-upload cl Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « util/Makefile.in ('k') | util/mtp-probe.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * \file mtp-hotplug.c 2 * \file mtp-hotplug.c
3 * Program to create hotplug scripts. 3 * Program to create hotplug scripts.
4 * 4 *
5 * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se> 5 * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se>
6 * Copyright (C) 2006-2008 Marcus Meissner <marcus@jet.franken.de> 6 * Copyright (C) 2006-2008 Marcus Meissner <marcus@jet.franken.de>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 11 matching lines...) Expand all
22 */ 22 */
23 #include <libmtp.h> 23 #include <libmtp.h>
24 #include <unistd.h> 24 #include <unistd.h>
25 #include <stdlib.h> 25 #include <stdlib.h>
26 #include <stdio.h> 26 #include <stdio.h>
27 #include <string.h> 27 #include <string.h>
28 28
29 static void usage(void) 29 static void usage(void)
30 { 30 {
31 fprintf(stderr, "usage: hotplug [-u -H -i -a\"ACTION\"] -p\"DIR\" -g\"GROUP\" -m\"MODE\"\n"); 31 fprintf(stderr, "usage: hotplug [-u -H -i -a\"ACTION\"] -p\"DIR\" -g\"GROUP\" -m\"MODE\"\n");
32 fprintf(stderr, " -w: use hwdb syntax\n");
32 fprintf(stderr, " -u: use udev syntax\n"); 33 fprintf(stderr, " -u: use udev syntax\n");
33 fprintf(stderr, " -o: use old udev syntax\n"); 34 fprintf(stderr, " -o: use old udev syntax\n");
34 fprintf(stderr, " -H: use hal syntax\n"); 35 fprintf(stderr, " -H: use hal syntax\n");
35 fprintf(stderr, " -i: use usb.ids simple list syntax\n"); 36 fprintf(stderr, " -i: use usb.ids simple list syntax\n");
36 fprintf(stderr, " -a\"ACTION\": perform udev action ACTION on attachment \n"); 37 fprintf(stderr, " -a\"ACTION\": perform udev action ACTION on attachment \n");
37 fprintf(stderr, " -p\"DIR\": directory where mtp-probe will be installed \n"); 38 fprintf(stderr, " -p\"DIR\": directory where mtp-probe will be installed \n");
38 fprintf(stderr, " -g\"GROUP\": file group for device nodes\n"); 39 fprintf(stderr, " -g\"GROUP\": file group for device nodes\n");
39 fprintf(stderr, " -m\"MODE\": file mode for device nodes\n"); 40 fprintf(stderr, " -m\"MODE\": file mode for device nodes\n");
40 exit(1); 41 exit(1);
41 } 42 }
42 43
43 enum style { 44 enum style {
44 style_usbmap, 45 style_usbmap,
45 style_udev, 46 style_udev,
46 style_udev_old, 47 style_udev_old,
47 style_hal, 48 style_hal,
48 style_usbids 49 style_usbids,
50 style_hwdb
49 }; 51 };
50 52
51 int main (int argc, char **argv) 53 int main (int argc, char **argv)
52 { 54 {
53 LIBMTP_device_entry_t *entries; 55 LIBMTP_device_entry_t *entries;
54 int numentries; 56 int numentries;
55 int i; 57 int i;
56 int ret; 58 int ret;
57 enum style style = style_usbmap; 59 enum style style = style_usbmap;
58 int opt; 60 int opt;
59 extern int optind; 61 extern int optind;
60 extern char *optarg; 62 extern char *optarg;
61 char *udev_action = NULL; 63 char *udev_action = NULL;
62 /* 64 /*
63 * You could tag on MODE="0666" here to enfore writeable 65 * You could tag on MODE="0666" here to enfore writeable
64 * device nodes, use the command line argument for that. 66 * device nodes, use the command line argument for that.
65 * Current udev default rules will make any device tagged 67 * Current udev default rules will make any device tagged
66 * with ENV{ID_MEDIA_PLAYER}=1 writable for the console 68 * with ENV{ID_MEDIA_PLAYER}=1 writable for the console
67 * user. 69 * user.
68 */ 70 */
69 char default_udev_action[] = "SYMLINK+=\"libmtp-%k\", ENV{ID_MTP_DEVICE}=\"1\" , ENV{ID_MEDIA_PLAYER}=\"1\""; 71 char default_udev_action[] = "SYMLINK+=\"libmtp-%k\", ENV{ID_MTP_DEVICE}=\"1\" , ENV{ID_MEDIA_PLAYER}=\"1\"";
70 char *action; // To hold the action actually used. 72 char *action; // To hold the action actually used.
71 uint16_t last_vendor = 0x0000U; 73 uint16_t last_vendor = 0x0000U;
72 char mtp_probe_dir[256]; 74 char mtp_probe_dir[256];
73 char *udev_group= NULL; 75 char *udev_group= NULL;
74 char *udev_mode = NULL; 76 char *udev_mode = NULL;
75 77
76 while ( (opt = getopt(argc, argv, "uoiHa:p:g:m:")) != -1 ) { 78 while ( (opt = getopt(argc, argv, "wuoiHa:p:g:m:")) != -1 ) {
77 switch (opt) { 79 switch (opt) {
78 case 'a': 80 case 'a':
79 udev_action = strdup(optarg); 81 udev_action = strdup(optarg);
80 break; 82 break;
81 case 'u': 83 case 'u':
82 style = style_udev; 84 style = style_udev;
83 break; 85 break;
84 case 'o': 86 case 'o':
85 style = style_udev_old; 87 style = style_udev_old;
86 break; 88 break;
87 case 'H': 89 case 'H':
88 style = style_hal; 90 style = style_hal;
89 break; 91 break;
90 case 'i': 92 case 'i':
91 style = style_usbids; 93 style = style_usbids;
92 break; 94 break;
95 case 'w':
96 style = style_hwdb;
97 break;
93 case 'p': 98 case 'p':
94 strncpy(mtp_probe_dir,optarg,sizeof(mtp_probe_dir)); 99 strncpy(mtp_probe_dir,optarg,sizeof(mtp_probe_dir));
95 mtp_probe_dir[sizeof(mtp_probe_dir)-1] = '\0'; 100 mtp_probe_dir[sizeof(mtp_probe_dir)-1] = '\0';
96 if (strlen(mtp_probe_dir) <= 1) { 101 if (strlen(mtp_probe_dir) <= 1) {
97 printf("Supply some sane mtp-probe dir\n"); 102 printf("Supply some sane mtp-probe dir\n");
98 exit(1); 103 exit(1);
99 } 104 }
100 /* Make sure the dir ends with '/' */ 105 /* Make sure the dir ends with '/' */
101 if (mtp_probe_dir[strlen(mtp_probe_dir)-1] != '/') { 106 if (mtp_probe_dir[strlen(mtp_probe_dir)-1] != '/') {
102 int index = strlen(mtp_probe_dir); 107 int index = strlen(mtp_probe_dir);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 printf("ATTR{idVendor}==\"085c\", GOTO=\"libmtp_rules_end\"\n"); 152 printf("ATTR{idVendor}==\"085c\", GOTO=\"libmtp_rules_end\"\n");
148 printf("ATTR{idVendor}==\"0971\", GOTO=\"libmtp_rules_end\"\n"); 153 printf("ATTR{idVendor}==\"0971\", GOTO=\"libmtp_rules_end\"\n");
149 printf("# Canon scanners that look like MTP devices (PID 0x22nn)\n"); 154 printf("# Canon scanners that look like MTP devices (PID 0x22nn)\n");
150 printf("ATTR{idVendor}==\"04a9\", ATTR{idProduct}==\"22*\", GOTO=\"libmtp_ rules_end\"\n"); 155 printf("ATTR{idVendor}==\"04a9\", ATTR{idProduct}==\"22*\", GOTO=\"libmtp_ rules_end\"\n");
151 printf("# Canon digital camera (EOS 3D) that looks like MTP device (PID 0x 3113)\n"); 156 printf("# Canon digital camera (EOS 3D) that looks like MTP device (PID 0x 3113)\n");
152 printf("ATTR{idVendor}==\"04a9\", ATTR{idProduct}==\"3113\", GOTO=\"libmtp _rules_end\"\n"); 157 printf("ATTR{idVendor}==\"04a9\", ATTR{idProduct}==\"3113\", GOTO=\"libmtp _rules_end\"\n");
153 printf("# Sensitive Atheros devices that look like MTP devices\n"); 158 printf("# Sensitive Atheros devices that look like MTP devices\n");
154 printf("ATTR{idVendor}==\"0cf3\", GOTO=\"libmtp_rules_end\"\n"); 159 printf("ATTR{idVendor}==\"0cf3\", GOTO=\"libmtp_rules_end\"\n");
155 printf("# Sensitive Atmel JTAG programmers\n"); 160 printf("# Sensitive Atmel JTAG programmers\n");
156 printf("ATTR{idVendor}==\"03eb\", GOTO=\"libmtp_rules_end\"\n"); 161 printf("ATTR{idVendor}==\"03eb\", GOTO=\"libmtp_rules_end\"\n");
162 printf("# Sensitive Philips device\n");
163 printf("ATTR{idVendor}==\"0471\", ATTR{idProduct}==\"083f\", GOTO=\"libmtp _rules_end\"\n");
157 break; 164 break;
158 case style_udev_old: 165 case style_udev_old:
159 printf("# UDEV-style hotplug map for libmtp\n"); 166 printf("# UDEV-style hotplug map for libmtp\n");
160 printf("# Put this file in /etc/udev/rules.d\n\n"); 167 printf("# Put this file in /etc/udev/rules.d\n\n");
161 printf("ACTION!=\"add\", GOTO=\"libmtp_rules_end\"\n"); 168 printf("ACTION!=\"add\", GOTO=\"libmtp_rules_end\"\n");
162 printf("ENV{MAJOR}!=\"?*\", GOTO=\"libmtp_rules_end\"\n"); 169 printf("ENV{MAJOR}!=\"?*\", GOTO=\"libmtp_rules_end\"\n");
163 printf("SUBSYSTEM==\"usb_device\", GOTO=\"libmtp_usb_device_rules\"\n" 170 printf("SUBSYSTEM==\"usb_device\", GOTO=\"libmtp_usb_device_rules\"\n"
164 "GOTO=\"libmtp_rules_end\"\n\n" 171 "GOTO=\"libmtp_rules_end\"\n\n"
165 "LABEL=\"libmtp_usb_device_rules\"\n\n"); 172 "LABEL=\"libmtp_usb_device_rules\"\n\n");
166 break; 173 break;
167 case style_usbmap: 174 case style_usbmap:
168 printf("# This usermap will call the script \"libmtp.sh\" whenever a known MTP device is attached.\n\n"); 175 printf("# This usermap will call the script \"libmtp.sh\" whenever a known MTP device is attached.\n\n");
169 break; 176 break;
170 case style_hal: 177 case style_hal:
171 printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <!-- -*- SGML -*- -->\n"); 178 printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <!-- -*- SGML -*- -->\n");
172 printf("<!-- This file was generated by %s - - fdi -->\n", argv[0]); 179 printf("<!-- This file was generated by %s - - fdi -->\n", argv[0]);
173 printf("<deviceinfo version=\"0.2\">\n"); 180 printf("<deviceinfo version=\"0.2\">\n");
174 printf(" <device>\n"); 181 printf(" <device>\n");
175 printf(" <match key=\"info.subsystem\" string=\"usb\">\n"); 182 printf(" <match key=\"info.subsystem\" string=\"usb\">\n");
176 break; 183 break;
177 case style_usbids: 184 case style_usbids:
178 printf("# usb.ids style device list from libmtp\n"); 185 printf("# usb.ids style device list from libmtp\n");
179 printf("# Compare: http://www.linux-usb.org/usb.ids\n"); 186 printf("# Compare: http://www.linux-usb.org/usb.ids\n");
180 break; 187 break;
188 case style_hwdb:
189 printf("# hardware database file for libmtp supported devices\n");
190 break;
181 } 191 }
182 192
183 for (i = 0; i < numentries; i++) { 193 for (i = 0; i < numentries; i++) {
184 LIBMTP_device_entry_t * entry = &entries[i]; 194 LIBMTP_device_entry_t * entry = &entries[i];
185 195
186 switch (style) { 196 switch (style) {
187 case style_udev: 197 case style_udev:
188 case style_udev_old: 198 case style_udev_old:
189 printf("# %s %s\n", entry->vendor, entry->product); 199 printf("# %s %s\n", entry->vendor, entry->product);
190 printf("ATTR{idVendor}==\"%04x\", ATTR{idProduct}==\"%04x\", %s", entry- >vendor_id, entry->product_id, action); 200 printf("ATTR{idVendor}==\"%04x\", ATTR{idProduct}==\"%04x\", %s", entry- >vendor_id, entry->product_id, action);
191 if (udev_group != NULL) printf(", GROUP=\"%s\"", udev_group); 201 if (udev_group != NULL) printf(", GROUP=\"%s\"", udev_group);
192 if (udev_mode != NULL) printf(", MODE=\"%s\"", udev_mode); 202 if (udev_mode != NULL) printf(", MODE=\"%s\"", udev_mode);
193 printf("\n"); 203 printf("\n");
194 break; 204 break;
195 case style_usbmap: 205 case style_usbmap:
196 printf("# %s %s\n", entry->vendor, entry->product); 206 printf("# %s %s\n", entry->vendor, entry->product);
197 printf("libmtp.sh 0x0003 0x%04x 0x%04x 0x0000 0x0000 0x00 0 x00 0x00 0x00 0x00 0x00 0x00000000\n", entry->vendor_id, entry->p roduct_id); 207 printf("libmtp.sh 0x0003 0x%04x 0x%04x 0x0000 0x0000 0x00 0 x00 0x00 0x00 0x00 0x00 0x00000000\n", entry->vendor_id, entry->p roduct_id);
198 break; 208 break;
199 case style_hal: 209 case style_hal:
200 printf(" <!-- %s %s -->\n", entry->vendor, entry->product); 210 printf(" <!-- %s %s -->\n", entry->vendor, entry->product);
201 printf(" <match key=\"usb.vendor_id\" int=\"0x%04x\">\n", entry-> vendor_id); 211 printf(" <match key=\"usb.vendor_id\" int=\"0x%04x\">\n", entry-> vendor_id);
202 printf(" <match key=\"usb.product_id\" int=\"0x%04x\">\n", entr y->product_id); 212 printf(" <match key=\"usb.product_id\" int=\"0x%04x\">\n", entr y->product_id);
203 /* FIXME: If hal >=0.5.10 can be depended upon, the matches below with contains_not can instead use addset */ 213 /* FIXME: If hal >=0.5.10 can be depended upon, the matches below with contains_not can instead use addset */
204 printf(" <match key=\"info.capabilities\" contains_not=\"port able_audio_player\">\n"); 214 printf(" <match key=\"info.capabilities\" contains_not=\"port able_audio_player\">\n");
205 printf(" <append key=\"info.capabilities\" type=\"strlist\" >portable_audio_player</append>\n"); 215 printf(" <append key=\"info.capabilities\" type=\"strlist\" >portable_audio_player</append>\n");
206 printf(" </match>\n"); 216 printf(" </match>\n");
207 printf(" <merge key=\"info.vendor\" type=\"string\">%s</merge >\n", entry->vendor); 217 printf(" <merge key=\"info.vendor\" type=\"string\">%s</merge >\n", entry->vendor);
208 printf(" <merge key=\"info.product\" type=\"string\">%s</merg e>\n", entry->product); 218 printf(" <merge key=\"info.product\" type=\"string\">%s</merg e>\n", entry->product);
209 printf(" <merge key=\"info.category\" type=\"string\">portabl e_audio_player</merge>\n"); 219 printf(" <merge key=\"info.category\" type=\"string\">portabl e_audio_player</merge>\n");
(...skipping 14 matching lines...) Expand all
224 entry->vendor_id == 0x066f || // TrekStor 234 entry->vendor_id == 0x066f || // TrekStor
225 entry->vendor_id == 0x1703) { // NormSoft, Inc. 235 entry->vendor_id == 0x1703) { // NormSoft, Inc.
226 printf(" <match key=\"portable_audio_player.output_formats\ " contains_not=\"application/ogg\">\n"); 236 printf(" <match key=\"portable_audio_player.output_formats\ " contains_not=\"application/ogg\">\n");
227 printf(" <append key=\"portable_audio_player.output_forma ts\" type=\"strlist\">application/ogg</append>\n"); 237 printf(" <append key=\"portable_audio_player.output_forma ts\" type=\"strlist\">application/ogg</append>\n");
228 printf(" </match>\n"); 238 printf(" </match>\n");
229 } 239 }
230 printf(" <merge key=\"portable_audio_player.libmtp.protocol\" type=\"string\">mtp</merge>\n"); 240 printf(" <merge key=\"portable_audio_player.libmtp.protocol\" type=\"string\">mtp</merge>\n");
231 printf(" </match>\n"); 241 printf(" </match>\n");
232 printf(" </match>\n"); 242 printf(" </match>\n");
233 break; 243 break;
234 case style_usbids: 244 case style_usbids:
235 if (last_vendor != entry->vendor_id) { 245 if (last_vendor != entry->vendor_id) {
236 printf("%04x\n", entry->vendor_id); 246 printf("%04x\n", entry->vendor_id);
237 } 247 }
238 printf("\t%04x %s %s\n", entry->product_id, entry->vendor, entry->pro duct); 248 printf("\t%04x %s %s\n", entry->product_id, entry->vendor, entry->pro duct);
239 break; 249 break;
250 case style_hwdb:
251 printf("# %s %s\n", entry->vendor, entry->product);
252 printf("usb:v%04xp%04x*\n", entry->vendor_id, entry->product_id);
253 printf(" ID_MEDIA_PLAYER=1\n");
254 printf(" ID_MTP_DEVICE=1\n");
255 printf("\n");
256 break;
240 } 257 }
241 last_vendor = entry->vendor_id; 258 last_vendor = entry->vendor_id;
242 } 259 }
243 } else { 260 } else {
244 printf("Error.\n"); 261 printf("Error.\n");
245 exit(1); 262 exit(1);
246 } 263 }
247 264
248 // Then the footer. 265 // Then the footer.
249 switch (style) { 266 switch (style) {
250 case style_usbmap: 267 case style_usbmap:
268 case style_hwdb:
251 break; 269 break;
252 case style_udev: 270 case style_udev:
253 case style_udev_old: 271 case style_udev_old:
254 /* 272 /*
255 * This is code that invokes the mtp-probe program on 273 * This is code that invokes the mtp-probe program on
256 * every USB device that is either PTP or vendor specific 274 * every USB device that is either PTP or vendor specific
257 */ 275 */
258 printf("\n# Autoprobe vendor-specific, communication and PTP devices\n"); 276 printf("\n# Autoprobe vendor-specific, communication and PTP devices\n");
259 printf("ENV{ID_MTP_DEVICE}!=\"1\", ENV{MTP_NO_PROBE}!=\"1\", ENV{COLOR_MEASU REMENT_DEVICE}!=\"1\", ENV{libsane_matched}!=\"yes\", ATTR{bDeviceClass}==\"00|0 2|06|ef|ff\", PROGRAM=\"%smtp-probe /sys$env{DEVPATH} $attr{busnum} $attr{devnum }\", RESULT==\"1\", %s", mtp_probe_dir, action); 277 printf("ENV{ID_MTP_DEVICE}!=\"1\", ENV{MTP_NO_PROBE}!=\"1\", ENV{COLOR_MEASU REMENT_DEVICE}!=\"1\", ENV{libsane_matched}!=\"yes\", ATTR{bDeviceClass}==\"00|0 2|06|ef|ff\", PROGRAM=\"%smtp-probe /sys$env{DEVPATH} $attr{busnum} $attr{devnum }\", RESULT==\"1\", %s", mtp_probe_dir, action);
260 if (udev_group != NULL) printf(", GROUP=\"%s\"", udev_group); 278 if (udev_group != NULL) printf(", GROUP=\"%s\"", udev_group);
261 if (udev_mode != NULL) printf(", MODE=\"%s\"", udev_mode); 279 if (udev_mode != NULL) printf(", MODE=\"%s\"", udev_mode);
262 printf("\n"); 280 printf("\n");
263 printf("\nLABEL=\"libmtp_rules_end\"\n"); 281 printf("\nLABEL=\"libmtp_rules_end\"\n");
264 break; 282 break;
265 case style_hal: 283 case style_hal:
266 printf(" </match>\n"); 284 printf(" </match>\n");
267 printf(" </device>\n"); 285 printf(" </device>\n");
268 printf("</deviceinfo>\n"); 286 printf("</deviceinfo>\n");
269 break; 287 break;
270 case style_usbids: 288 case style_usbids:
271 printf("\n"); 289 printf("\n");
272 } 290 }
273 291
274 exit (0); 292 exit (0);
275 } 293 }
OLDNEW
« no previous file with comments | « util/Makefile.in ('k') | util/mtp-probe.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698