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

Commit b7eac2d0 authored by Fernando Lugo's avatar Fernando Lugo
Browse files

fastboot: windows: fix Read function



Read function exits before reading all requested bytes. Fix that by
looping until the len requested is completed.

This will fix the issue execting get_staged command for a staged image
bigger than 1MB

Test: fastboot get_staged file.txt
Change-Id: Ic70ab48f3a8c8d78c225db638892501d4dc20b13
Signed-off-by: default avatarFernando Lugo <flugo@google.com>
parent c76078e4
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -195,25 +195,28 @@ ssize_t WindowsUsbTransport::Write(const void* data, size_t len) {
ssize_t WindowsUsbTransport::Read(void* data, size_t len) {
    unsigned long time_out = 0;
    unsigned long read = 0;
    size_t count = 0;
    int ret;

    DBG("usb_read %zu\n", len);
    if (nullptr != handle_) {
        while (1) {
            int xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;
        while (len > 0) {
            size_t xfer = (len > MAX_USBFS_BULK_SIZE) ? MAX_USBFS_BULK_SIZE : len;

            ret = AdbReadEndpointSync(handle_->adb_read_pipe, data, xfer, &read, time_out);
            errno = GetLastError();
            DBG("usb_read got: %ld, expected: %d, errno: %d\n", read, xfer, errno);
            if (ret) {
                return read;
            } else {
            if (ret == 0) {
                // assume ERROR_INVALID_HANDLE indicates we are disconnected
                if (errno == ERROR_INVALID_HANDLE)
                    usb_kick(handle_.get());
                break;
            }
            // else we timed out - try again
            count += read;
            len -= read;
            data = (char*)data + read;

            if (xfer != read || len == 0) return count;
        }
    } else {
        DBG("usb_read NULL handle\n");