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.
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 @@
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 @@
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 @@
DIR *busdir, *devdir;
struct dirent *de;
int fd;
+ int writable = 1;
busdir = opendir(base);
if(busdir == 0) return 0;
@@ -220,12 +223,18 @@
// 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 @@
{
return find_usb_device("/dev/bus/usb", callback);
}
-
-