gadget: f_thor: update to support more than 4GB file as thor 5.0 89/177589/5
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 2 May 2018 04:26:05 +0000 (13:26 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 10 May 2018 07:29:47 +0000 (07:29 +0000)
During file download, it only uses 32bit variable for file size and
it limits maximum file size less than 4GB. Update to support more
than 4GB file with using two 32bit variables for file size as thor
protocol 5.0.

Change-Id: Ifc572b6939db1693455e168e2e8fb871edac62a2
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
drivers/usb/gadget/f_thor.c
drivers/usb/gadget/f_thor.h

index a279758..3925d08 100644 (file)
@@ -54,7 +54,7 @@ DEFINE_CACHE_ALIGN_BUFFER(unsigned char, thor_rx_data_buf,
 /*         THOR protocol - transmission handling             */
 /* ********************************************************** */
 DEFINE_CACHE_ALIGN_BUFFER(char, f_name, F_NAME_BUF_SIZE + 1);
-static size_t thor_file_size;
+static unsigned long long int thor_file_size;
 #ifdef CONFIG_TIZEN
 static unsigned long long int total_file_size;
 static unsigned long long int downloaded_file_size;
@@ -155,7 +155,8 @@ static int download_head(unsigned long long total,
                                   size_t *left,
                                   int *cnt)
 {
-       size_t rcv_cnt = 0, left_to_rcv, ret_rcv;
+       unsigned long long int rcv_cnt = 0;
+       size_t left_to_rcv, ret_rcv;
        struct dfu_entity *dfu_entity = dfu_get_entity(alt_setting_num);
        void *transfer_buffer = dfu_get_buf(dfu_entity);
        void *buf = transfer_buffer;
@@ -175,7 +176,7 @@ static int download_head(unsigned long long total,
                if (ret < 0)
                        return ret;
                rcv_cnt += ret_rcv;
-               debug("%d: RCV data count: %zu cnt: %d\n", usb_pkt_cnt,
+               debug("%d: RCV data count: %llu cnt: %d\n", usb_pkt_cnt,
                      rcv_cnt, *cnt);
 
                if ((rcv_cnt % THOR_STORE_UNIT_SIZE) == 0) {
@@ -193,7 +194,7 @@ static int download_head(unsigned long long total,
        }
 
        /* Calculate the amount of data to arrive from PC (in bytes) */
-       left_to_rcv = total - rcv_cnt;
+       left_to_rcv = (size_t)(total - rcv_cnt);
 
        /*
         * Calculate number of data already received. but not yet stored
@@ -212,7 +213,7 @@ static int download_head(unsigned long long total,
                send_data_rsp(0, ++usb_pkt_cnt);
        }
 
-       debug("%s: %zu total: %llu cnt: %d\n", __func__, rcv_cnt, total, *cnt);
+       debug("%s: %llu total: %llu cnt: %d\n", __func__, rcv_cnt, total, *cnt);
 
        return 0;
 }
@@ -280,12 +281,14 @@ static int process_rqt_download(const struct rqt_box *rqt)
 
        switch (rqt->rqt_data) {
        case RQT_DL_INIT:
-               thor_file_size = (uint32_t)rqt->int_data[0];
+               thor_file_size = (unsigned long long int) rqt->int_data[0] +
+                                (((unsigned long long int)rqt->int_data[1])
+                                 << 32);
 #ifdef CONFIG_TIZEN
                total_file_size = thor_file_size;
                downloaded_file_size = 0;
 #endif
-               debug("INIT: total %zu bytes\n", thor_file_size);
+               debug("INIT: total %llu bytes\n", thor_file_size);
                break;
        case RQT_DL_FILE_INFO:
                file_type = rqt->int_data[0];
@@ -296,11 +299,13 @@ static int process_rqt_download(const struct rqt_box *rqt)
                        break;
                }
 
-               thor_file_size = (uint32_t)rqt->int_data[1];
+               thor_file_size = (unsigned long long int)rqt->int_data[1] +
+                                (((unsigned long long int)rqt->int_data[2])
+                                 << 32);
                memcpy(f_name, rqt->str_data[0], F_NAME_BUF_SIZE);
                f_name[F_NAME_BUF_SIZE] = '\0';
 
-               debug("INFO: name(%s, %d), size(%zu), type(%d)\n",
+               debug("INFO: name(%s, %d), size(%llu), type(%d)\n",
                      f_name, 0, thor_file_size, file_type);
 
                rsp->int_data[0] = THOR_PACKET_SIZE;
index 8341285..7820788 100644 (file)
@@ -35,7 +35,7 @@ struct usb_cdc_attribute_vendor_descriptor {
        __u8 DAUValue;
 } __packed;
 
-#define VER_PROTOCOL_MAJOR     4
+#define VER_PROTOCOL_MAJOR     5
 #define VER_PROTOCOL_MINOR     0
 
 enum rqt {