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.
This commit is contained in:
Elliott Hughes 2009-10-06 18:07:49 -07:00
parent 04b7f9d42e
commit b4add9b745
5 changed files with 20 additions and 8 deletions

View File

@ -165,6 +165,9 @@ int list_devices_callback(usb_ifc_info *info)
{
if (match_fastboot(info) == 0) {
char* serial = info->serial_number;
if (!info->writable) {
serial = "no permissions"; // like "adb devices"
}
if (!serial[0]) {
serial = "????????????";
}

View File

@ -50,6 +50,8 @@ struct usb_ifc_info
unsigned char has_bulk_in;
unsigned char has_bulk_out;
unsigned char writable;
char serial_number[256];
};

View File

@ -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);
}

View File

@ -351,6 +351,7 @@ static int try_device(io_service_t device, usb_handle *handle) {
// device has no serial number
handle->info.serial_number[0] = 0;
}
handle->info.writable = 1;
if (try_interfaces(dev, handle)) {
goto error;
@ -416,8 +417,6 @@ static int init_usb(ifc_match_func callback, usb_handle **handle) {
break;
}
usb_ifc_info info;
if (try_device(device, &h) != 0) {
IOObjectRelease(device);
ret = -1;

View File

@ -301,6 +301,7 @@ int recognized_device(usb_handle* handle, ifc_match_func callback) {
info.ifc_class = interf_desc.bInterfaceClass;
info.ifc_subclass = interf_desc.bInterfaceSubClass;
info.ifc_protocol = interf_desc.bInterfaceProtocol;
info.writable = 1;
// read serial number (if there is one)
unsigned long serial_number_len = sizeof(info.serial_number);