Skip to contentSkip to conversation

Misc usb-mtp fixes

PATCH In review Bandan Das 2 participants 5 messages Sep 7, 2018 – Sep 13, 2018

lore
Share & tools
lore

Bandan Das

author
#0 lore raw

v2 cover Misc usb-mtp fixes

v2:
Same as v1 but with another minor cleanup
patch. The write buffer breakup is still WIP.

A documentation fix and changes to return the
right error code on write failures.

Bandan (2):
usb-mtp: fix error conditions for write operation
doc: replace x-root with rootdir for usb-mtp

Bandan Das (1):
usb-mtp: reset ObjectInfo dataset size on cleanup

 hw/usb/dev-mtp.c          | 9 ++++++---
 qemu-doc.texi             | 2 +-
 scripts/device-crash-test | 2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)
Signature · 1 line
2.14.4
author
#1 lore raw

PATCH v2 1/3 usb-mtp: fix error conditions for write operation

From: Bandan <[email protected]>

Return STORE_FULL if we can't write all the bytes but return incomplete transfer if data received is less then what was specified in the metadata. Also, use d->offset as the file size which is valid for all file sizes.

---
 hw/usb/dev-mtp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/usb/dev-mtp.c +4 -3
index 3fdc4b0da1..15edf3bb82 100644
@@ -1665,13 +1665,14 @@ static void usb_mtp_write_data(MTPState *s)
             goto success;
         }
 
-        rc = write_retry(d->fd, d->data, s->dataset.size);
-        if (!rc) {
+        rc = write_retry(d->fd, d->data, d->offset);
+        if (rc != d->offset) {
             usb_mtp_queue_result(s, RES_STORE_FULL, d->trans,
                                  0, 0, 0, 0);
             goto done;
             }
-        if (rc != s->dataset.size) {
+        /* Only for < 4G file sizes */
+        if (s->dataset.size != 0xFFFFFFFF && rc != s->dataset.size) {
             usb_mtp_queue_result(s, RES_INCOMPLETE_TRANSFER, d->trans,
                                  0, 0, 0, 0);
             goto done;
Signature · 1 line
2.14.4
author
#2 lore raw

PATCH v2 2/3 doc: replace x-root with rootdir for usb-mtp

In reply to Bandan Das

From: Bandan <[email protected]>

---
 qemu-doc.texi             | 2 +-
 scripts/device-crash-test | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
qemu-doc.texi +1 -1
index f74542a0e9..cc7d81181c 100644
@@ -943,7 +943,7 @@ for details
 Bulk-only transport storage device, see
 @url{https://git.qemu.org/?p=qemu.git;a=blob_plain;f=docs/usb-storage.txt,usb-storage.txt}
 for details here, too
-@item usb-mtp,x-root=@var{dir}
+@item usb-mtp,rootdir=@var{dir}
 Media transfer protocol device, using @var{dir} as root of the file tree
 that is presented to the guest.
 @item usb-host,hostbus=@var{bus},hostaddr=@var{addr}
scripts/device-crash-test +1 -1
index e6c233e9bf..7045594bd4 100755
@@ -125,7 +125,7 @@ ERROR_WHITELIST = [
     {'device':'tpm-tis', 'expected':True},                 # tpm_tis: backend driver with id (null) could not be found
     {'device':'unimplemented-device', 'expected':True},    # property 'size' not specified or zero
     {'device':'usb-braille', 'expected':True},             # Property chardev is required
-    {'device':'usb-mtp', 'expected':True},                 # x-root property must be configured
+    {'device':'usb-mtp', 'expected':True},                 # rootdir property must be configured
     {'device':'usb-redir', 'expected':True},               # Parameter 'chardev' is missing
     {'device':'usb-serial', 'expected':True},              # Property chardev is required
     {'device':'usb-storage', 'expected':True},             # drive property not set
Signature · 1 line
2.14.4
author
#3 lore raw

PATCH v2 3/3 usb-mtp: reset ObjectInfo dataset size on cleanup

In reply to Bandan Das

Stale values in this field may result in qemu
expecting more data on the next operation

---
 hw/usb/dev-mtp.c | 2 ++
 1 file changed, 2 insertions(+)
hw/usb/dev-mtp.c +2 -0
index 15edf3bb82..00a3691bae 100644
@@ -1568,6 +1568,7 @@ static void usb_mtp_handle_control(USBDevice *dev, USBPacket *p,
             if (s->write_pending) {
                 g_free(s->dataset.filename);
                 s->write_pending = false;
+                s->dataset.size = 0;
             }
             usb_mtp_data_free(s->data_out);
             s->data_out = NULL;
@@ -1693,6 +1694,7 @@ done:
     }
 free:
     g_free(s->dataset.filename);
+    s->dataset.size = 0;
     g_free(path);
     s->write_pending = false;
 }
Signature · 1 line
2.14.4
#4 lore raw
In reply to Bandan Das
Quoted 6 lines · Bandan Das

v2:
Same as v1 but with another minor cleanup
patch. The write buffer breakup is still WIP.

A documentation fix and changes to return the
right error code on write failures.

Added to usb queue.

thanks,
Gerd