Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 16b78db9 authored by Jerry Zhang's avatar Jerry Zhang
Browse files

adb: Have device usb_handle return io size

Previously, read and write would return 0
on success. Now it will return the number
of bytes read/write. This is more consistent
with other usb handles and is needed in order
to handle partial packets (for fastbootd).

Update usb_write in other usb handles
to return amount written.

Change transport_usb accordingly.

Test: adb works
Bug: 78793464
Change-Id: If07ff05fbc8120343f20661475d34f4e5ff805de
parent b156c60a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -589,7 +589,7 @@ int usb_write(usb_handle* h, const void* d, int len) {

    int rc = perform_usb_transfer(h, info, std::move(lock));
    LOG(DEBUG) << "usb_write(" << len << ") = " << rc;
    return rc;
    return info->transfer->actual_length;
}

int usb_read(usb_handle* h, void* d, int len) {
+2 −2
Original line number Diff line number Diff line
@@ -418,11 +418,11 @@ int usb_write(usb_handle *h, const void *_data, int len)
    if (h->zero_mask && !(len & h->zero_mask)) {
        // If we need 0-markers and our transfer is an even multiple of the packet size,
        // then send a zero marker.
        return usb_bulk_write(h, _data, 0);
        return usb_bulk_write(h, _data, 0) == 0 ? n : -1;
    }

    D("-- usb_write --");
    return 0;
    return n;
}

int usb_read(usb_handle *h, void *_data, int len)
+2 −2
Original line number Diff line number Diff line
@@ -497,8 +497,8 @@ int usb_write(usb_handle *handle, const void *buf, int len)
        }
    }

    if (0 == result)
        return 0;
    if (!result)
        return len;

    LOG(ERROR) << "usb_write failed with status: " << std::hex << result;
    return -1;
+1 −1
Original line number Diff line number Diff line
@@ -365,7 +365,7 @@ int usb_write(usb_handle* handle, const void* data, int len) {
        }
    }

    return 0;
    return written;

fail:
    // Any failure should cause us to kick the device instead of leaving it a
+7 −3
Original line number Diff line number Diff line
@@ -368,6 +368,7 @@ static int usb_ffs_write(usb_handle* h, const void* data, int len) {
    D("about to write (fd=%d, len=%d)", h->bulk_in, len);

    const char* buf = static_cast<const char*>(data);
    int orig_len = len;
    while (len > 0) {
        int write_len = std::min(USB_FFS_BULK_SIZE, len);
        int n = adb_write(h->bulk_in, buf, write_len);
@@ -380,13 +381,14 @@ static int usb_ffs_write(usb_handle* h, const void* data, int len) {
    }

    D("[ done fd=%d ]", h->bulk_in);
    return 0;
    return orig_len;
}

static int usb_ffs_read(usb_handle* h, void* data, int len) {
    D("about to read (fd=%d, len=%d)", h->bulk_out, len);

    char* buf = static_cast<char*>(data);
    int orig_len = len;
    while (len > 0) {
        int read_len = std::min(USB_FFS_BULK_SIZE, len);
        int n = adb_read(h->bulk_out, buf, read_len);
@@ -399,7 +401,7 @@ static int usb_ffs_read(usb_handle* h, void* data, int len) {
    }

    D("[ done fd=%d ]", h->bulk_out);
    return 0;
    return orig_len;
}

static int usb_ffs_do_aio(usb_handle* h, const void* data, int len, bool read) {
@@ -447,6 +449,7 @@ static int usb_ffs_do_aio(usb_handle* h, const void* data, int len, bool read) {
        if (num_bufs == 1 && aiob->events[0].res == -EINTR) {
            continue;
        }
        int ret = 0;
        for (int i = 0; i < num_bufs; i++) {
            if (aiob->events[i].res < 0) {
                errno = -aiob->events[i].res;
@@ -454,8 +457,9 @@ static int usb_ffs_do_aio(usb_handle* h, const void* data, int len, bool read) {
                            << " total bufs " << num_bufs;
                return -1;
            }
            ret += aiob->events[i].res;
        }
        return 0;
        return ret;
    }
}

Loading