diff options
author | Elliott Hughes <enh@google.com> | 2009-10-06 18:07:49 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2009-10-06 18:07:49 -0700 |
commit | b4add9b74525210478bac702d27fdaf9cf7ab18f (patch) | |
tree | c25ecbe4025f917ffa2d40b2c8890555424a2eaf /fastboot/usb_linux.c | |
parent | 04b7f9d42e751c7b96b872075d0fca4f3249254a (diff) | |
download | system_core-b4add9b74525210478bac702d27fdaf9cf7ab18f.zip system_core-b4add9b74525210478bac702d27fdaf9cf7ab18f.tar.gz system_core-b4add9b74525210478bac702d27fdaf9cf7ab18f.tar.bz2 |
Make fastboot say "no permissions" for non-writable devices.
Without this patch, "adb devices" will say "no permissions" when it sees
a device it can't write to, but "fastboot devices" will silently ignore it.
This is confusing to n00bs, especially since it doesn't seem to be widely
known that a device's USB id might be different in the bootloader (meaning
two udev rules are needed). It can also be confusing if you're sshed in,
when you can't access the device because you won't be in the "plugdev"
group, but "fastboot devices" won't make this clear.
I'm not sure about the Mac OS and Windows changes. AIUI, devices are always
writable on those platforms, but I don't use either, so I can't test this.
This patch shouldn't alter the behavior on either of those platforms.
Diffstat (limited to 'fastboot/usb_linux.c')
-rw-r--r-- | fastboot/usb_linux.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.c index 3b40ba7..088c23a 100644 --- a/fastboot/usb_linux.c +++ b/fastboot/usb_linux.c @@ -89,7 +89,8 @@ static int check(void *_desc, int len, unsigned type, int size) return 0; } -static int filter_usb_device(int fd, char *ptr, int len, ifc_match_func callback, +static int filter_usb_device(int fd, char *ptr, int len, int writable, + ifc_match_func callback, int *ept_in_id, int *ept_out_id, int *ifc_id) { struct usb_device_descriptor *dev; @@ -119,7 +120,8 @@ static int filter_usb_device(int fd, char *ptr, int len, ifc_match_func callback info.dev_class = dev->bDeviceClass; info.dev_subclass = dev->bDeviceSubClass; info.dev_protocol = dev->bDeviceProtocol; - + info.writable = writable; + // read device serial number (if there is one) info.serial_number[0] = 0; if (dev->iSerialNumber) { @@ -201,6 +203,7 @@ static usb_handle *find_usb_device(const char *base, ifc_match_func callback) DIR *busdir, *devdir; struct dirent *de; int fd; + int writable = 1; busdir = opendir(base); if(busdir == 0) return 0; @@ -220,12 +223,18 @@ static usb_handle *find_usb_device(const char *base, ifc_match_func callback) // DBG("[ scanning %s ]\n", devname); if((fd = open(devname, O_RDWR)) < 0) { - continue; + // Check if we have read-only access, so we can give a helpful + // diagnostic like "adb devices" does. + writable = 0; + if((fd = open(devname, O_RDONLY)) < 0) { + continue; + } } n = read(fd, desc, sizeof(desc)); - if(filter_usb_device(fd, desc, n, callback, &in, &out, &ifc) == 0){ + if(filter_usb_device(fd, desc, n, writable, callback, + &in, &out, &ifc) == 0) { usb = calloc(1, sizeof(usb_handle)); strcpy(usb->fname, devname); usb->ep_in = in; @@ -375,5 +384,3 @@ usb_handle *usb_open(ifc_match_func callback) { return find_usb_device("/dev/bus/usb", callback); } - - |