Apply Tizen coding rule 68/151868/2
authorSunmin Lee <sunm.lee@samsung.com>
Fri, 22 Sep 2017 04:52:01 +0000 (13:52 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Tue, 26 Sep 2017 02:21:28 +0000 (11:21 +0900)
Change-Id: Ic2e65905e90fa40b0dd6e637f66b46a6a41059b2
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
21 files changed:
bsdiff/ss_bsdiff.c
bsdiff/ss_bspatch.c
bsdiff/ss_bspatch_common.c
ss_engine/SS_ApplyPatch.c
ss_engine/SS_Common.c
ss_engine/SS_Common.h
ss_engine/SS_Engine_Errors.h
ss_engine/SS_Engine_Update.h
ss_engine/SS_FSUpdate.c
ss_engine/SS_FSUpdate.h
ss_engine/SS_ImageUpdate.h
ss_engine/SS_MultiProcessUpdate.h
ss_engine/SS_PatchDelta.c
ss_engine/SS_PatchDelta.h
ss_engine/SS_UPI.c
ss_engine/SS_UPI.h
ss_engine/fota_common.h
ss_engine/fota_log.c
ss_engine/fota_log.h
ss_engine/fota_tar.c
ss_engine/ua.h

index 7415c6b..68967ee 100755 (executable)
@@ -77,12 +77,11 @@ void get_time_stamp(void)
 #include <divsufsort.h>
 #endif
 
-#define MIN(x,y) (((x)<(y)) ? (x) : (y))
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
 
 #ifdef MULTI_THREADING
 
-struct data_thread
-{
+struct data_thread {
        unsigned num_threads;
        off_t size_thread;
 
@@ -113,7 +112,7 @@ int Function(int);
 
 #endif
 
-static off_t matchlen(u_char *old, off_t oldsize,u_char *new, off_t newsize)
+static off_t matchlen(u_char *old, off_t oldsize, u_char *new, off_t newsize)
 {
        off_t i;
        for (i = 0; (i < oldsize) && (i < newsize); i++)
@@ -128,11 +127,10 @@ static off_t search(saidx_t *I, u_char *old, off_t oldsize,
        off_t x, y;
        while (en - st >= 2) {
                x = st + (en - st) / 2;
-               if (memcmp(old + I[x], new, MIN(oldsize - I[x], newsize)) < 0) {
+               if (memcmp(old + I[x], new, MIN(oldsize - I[x], newsize)) < 0)
                        st = x;
-               } else {
+               else
                        en = x;
-               }
        }
 
        x = matchlen(old + I[st], oldsize - I[st], new, newsize);
@@ -286,7 +284,7 @@ int Function(int offset_oldscore)
 {
        unsigned int thread_num = 0;
        off_t end;
-       off_t scan=0;
+       off_t scan = 0;
        end = data.newsize;
        int t1 = 0, t2 = 0;
        get_time_stamp();  //total time capturing
@@ -561,7 +559,7 @@ int MY_CDECL main(int numArgs, const char *args[])
 {
        char rs[800] = { 0 };
        if (numArgs != 4)
-               errx(1,"ss_bsdiff Version 5.0\nUsage: ss_bsdiff oldfile newfile patchfile\n");
+               errx(1, "ss_bsdiff Version 5.0\nUsage: ss_bsdiff oldfile newfile patchfile\n");
 
        int ret = create_patch(numArgs, args, 8);
 #ifdef TIME_LIMIT_CHECK
index 468bb11..1915223 100755 (executable)
@@ -115,14 +115,13 @@ int main2(int numArgs, const char *args[], char *rs, int rs_size)
                LzmaDec_Free(&state, &g_Alloc);
                File_Close(&inStream.file);
                if (apply_patch(args[1], buf_res, &new_data, &new_size) != 0) {
-                       if (new_data){
+                       if (new_data)
                                free(new_data);
-                       }
                        return 1;
                }
                if (((fd = open(args[2], O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0) ||
                                (write(fd, new_data, new_size) != new_size) || (close(fd) == -1))
-                       err(1,"%s",args[2]);
+                       err(1, "%s", args[2]);
                if (res != SZ_OK) {
                        free(new_data);
                        free(buf_res);
@@ -147,7 +146,7 @@ int main(int numArgs, const char *args[])
 {
        char rs[800] = { 0 };
        if (numArgs != 4)
-               errx(1,"ss_bspatch Version 1.0\nUsage: ss_bspatch oldfile newfile patchfile\n");
+               errx(1, "ss_bspatch Version 1.0\nUsage: ss_bspatch oldfile newfile patchfile\n");
        int res = main2(numArgs, args, rs, sizeof(rs));
        fputs(rs, stdout);
        return res;
index ffb5a7e..e7bd45e 100755 (executable)
@@ -181,7 +181,7 @@ int apply_patch(const char *oldfile, unsigned char *patch_buffer, unsigned char
 
        /* Check for appropriate magic */
        if (memcmp(header, BSDIFF_HEADER, 8) != 0 && memcmp(header, SSDIFF_HEADER, 8) != 0) {
-               printf("%s().%d Patch buffer header corrupt\n", __FUNCTION__, __LINE__ );
+               printf("%s().%d Patch buffer header corrupt\n", __FUNCTION__, __LINE__);
                return 1;
        }
 
@@ -189,7 +189,7 @@ int apply_patch(const char *oldfile, unsigned char *patch_buffer, unsigned char
        newsize = offtin(header + 8);
 
        if ((newsize < 0)) {
-               printf("%s().%d Patch buffer corrupt\n", __FUNCTION__, __LINE__ );
+               printf("%s().%d Patch buffer corrupt\n", __FUNCTION__, __LINE__);
                return 1;
        }
 
@@ -238,15 +238,14 @@ int apply_patch(const char *oldfile, unsigned char *patch_buffer, unsigned char
                                        goto Cleanup;
                                }
                                if (newpos + match_size > newsize) {
-                                       printf("%s().%d Corrupt patch\n", __FUNCTION__, __LINE__ );
+                                       printf("%s().%d Corrupt patch\n", __FUNCTION__, __LINE__);
                                        result = 1;
                                        goto Cleanup;
                                }
                                memcpy((*dest_buf) + newpos, patch_buffer + patch_buffer_offset, match_size);
                                patch_buffer_offset += match_size;
-                               for (j = 0; j < match_size; j++) {
+                               for (j = 0; j < match_size; j++)
                                        (*dest_buf)[newpos + j] += old[j];
-                               }
                                newpos += match_size;
                                flag = false;
                        } else {
@@ -256,7 +255,7 @@ int apply_patch(const char *oldfile, unsigned char *patch_buffer, unsigned char
                                        goto Cleanup;
                                }
                                if (newpos + memory_usage > newsize) {
-                                       printf("%s().%d Corrupt patch\n", __FUNCTION__, __LINE__ );
+                                       printf("%s().%d Corrupt patch\n", __FUNCTION__, __LINE__);
                                        result = 1;
                                        goto Cleanup;
                                }
@@ -273,7 +272,7 @@ int apply_patch(const char *oldfile, unsigned char *patch_buffer, unsigned char
                ////////////////////////////////////////////////////////////////////////////////////////
                /* Sanity-check */
                if (newpos + ctrl[1] > newsize) {
-                       printf("%s().%d Corrupt patch\n", __FUNCTION__, __LINE__ );
+                       printf("%s().%d Corrupt patch\n", __FUNCTION__, __LINE__);
                        result = 1;
                        goto Cleanup;
                }
index 9516085..2057ac3 100755 (executable)
 
 int SS_ApplyBsdiff(char *oldfile, char *newfile, char *patch, SinkFn sink, void *token, sha1_ctx_t * ctx1)
 {
-
-    UInt64 unpackSize = 0;
-    CFileSeqInStream inStream;
-    ISeqOutStream outStream;
-    unsigned char *buf_res = NULL;
-    unsigned char *new_data = NULL;
-    char buf[256];
-    ssize_t new_size = 0;
-    int result = E_SS_FAILURE;
-
-    FileSeqInStream_CreateVTable(&inStream);
-    File_Construct(&inStream.file);
-    FileOutStream_CreateVTable((CFileOutStream *) & outStream);
-
-    if (InFile_Open(&inStream.file, patch) != 0)
-        return E_SS_FAILURE;
-
-    UInt64 i;
-    CLzmaDec state;
-    unsigned char header[LZMA_PROPS_SIZE + 8];
-
-    RINOK(SeqInStream_Read(&inStream.s, header, sizeof(header)));
-
-    unpackSize = 0;
-    for (i = 0; i < 8; i++)
-        unpackSize += (UInt64) header[LZMA_PROPS_SIZE + i] << (i * 8);
-
-    LzmaDec_Construct(&state);
-    RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
-
-    //decompress the patch file into buf_res
-    buf_res = (unsigned char *)SS_Malloc(unpackSize);
-    if (!buf_res) {
-        LOGE("Bad memory allocation\n");
-        goto Cleanup;
-    }
-    result = Decode2(&state, &outStream, &inStream.s, &unpackSize, buf_res);
-
-    LzmaDec_Free(&state, &g_Alloc);
-    File_Close(&inStream.file);
-
-    if (result != S_SS_SUCCESS) {
-        LOGE("Error decompression failed with code : [%d]\n", result);
-        goto Cleanup;
-    }
-    //apply patch using buffer decoded by Decode2
-    result = apply_patch(oldfile, buf_res, &new_data, &new_size);
-    if (result != S_SS_SUCCESS) {
-        goto Cleanup;
-    }
-
-    result = (sink(new_data, new_size, token) < new_size) ? E_SS_FAILURE : S_SS_SUCCESS;
-    if (result != S_SS_SUCCESS) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("short write of output: %d (%s)\n", errno, buf);
-        goto Cleanup;
-    }
-
-    if (ctx1) {
-        sha1_update(ctx1, new_data, new_size);
-    }
- Cleanup:
-    if (new_data)
-        SS_Free(new_data);
-    if (buf_res)
-        SS_Free(buf_res);
-    File_Close(&inStream.file);//wgid: 27007
-    return result;
+       UInt64 unpackSize = 0;
+       CFileSeqInStream inStream;
+       ISeqOutStream outStream;
+       unsigned char *buf_res = NULL;
+       unsigned char *new_data = NULL;
+       char buf[256];
+       ssize_t new_size = 0;
+       int result = E_SS_FAILURE;
+
+       FileSeqInStream_CreateVTable(&inStream);
+       File_Construct(&inStream.file);
+       FileOutStream_CreateVTable((CFileOutStream *) & outStream);
+
+       if (InFile_Open(&inStream.file, patch) != 0)
+               return E_SS_FAILURE;
+
+       UInt64 i;
+       CLzmaDec state;
+       unsigned char header[LZMA_PROPS_SIZE + 8];
+
+       RINOK(SeqInStream_Read(&inStream.s, header, sizeof(header)));
+
+       unpackSize = 0;
+       for (i = 0; i < 8; i++)
+               unpackSize += (UInt64) header[LZMA_PROPS_SIZE + i] << (i * 8);
+
+       LzmaDec_Construct(&state);
+       RINOK(LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc));
+
+       //decompress the patch file into buf_res
+       buf_res = (unsigned char *)SS_Malloc(unpackSize);
+       if (!buf_res) {
+               LOGE("Bad memory allocation\n");
+               goto Cleanup;
+       }
+       result = Decode2(&state, &outStream, &inStream.s, &unpackSize, buf_res);
+
+       LzmaDec_Free(&state, &g_Alloc);
+       File_Close(&inStream.file);
+
+       if (result != S_SS_SUCCESS) {
+               LOGE("Error decompression failed with code : [%d]\n", result);
+               goto Cleanup;
+       }
+       //apply patch using buffer decoded by Decode2
+       result = apply_patch(oldfile, buf_res, &new_data, &new_size);
+       if (result != S_SS_SUCCESS)
+               goto Cleanup;
+
+       result = (sink(new_data, new_size, token) < new_size) ? E_SS_FAILURE : S_SS_SUCCESS;
+       if (result != S_SS_SUCCESS) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("short write of output: %d (%s)\n", errno, buf);
+               goto Cleanup;
+       }
+
+       if (ctx1)
+               sha1_update(ctx1, new_data, new_size);
+Cleanup:
+       if (new_data)
+               SS_Free(new_data);
+       if (buf_res)
+               SS_Free(buf_res);
+       File_Close(&inStream.file);//wgid: 27007
+       return result;
 
 }
index 6a38d22..6722938 100755 (executable)
@@ -7,7 +7,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 
 void SS_Progress(void *pbUserData, SS_UINT32 uPercent)
 {
-    LOG("Progress before\n");
-    LOGL(LOG_SSENGINE, "Progress.. (%u %%)\n", uPercent);
-    LOG("Progress after:\n");
-    ((ua_data_t *) pbUserData)->ui_progress(pbUserData, uPercent);
+       LOG("Progress before\n");
+       LOGL(LOG_SSENGINE, "Progress.. (%u %%)\n", uPercent);
+       LOG("Progress after:\n");
+       ((ua_data_t *) pbUserData)->ui_progress(pbUserData, uPercent);
 }
 
 /* Prints a string like the C printf() function */
 SS_UINT32 SS_Trace(void *pUser, const char *aFormat, ...)
 {
 #if 0
-    LOGL(LOG_SSENGINE, aFormat);
+       LOGL(LOG_SSENGINE, aFormat);
 #else
-    char temp[4096];
-    va_list list;
+       char temp[4096];
+       va_list list;
 
-    va_start(list, aFormat);
-    vsnprintf(temp, sizeof(temp), aFormat, list);
-    va_end(list);
+       va_start(list, aFormat);
+       vsnprintf(temp, sizeof(temp), aFormat, list);
+       va_end(list);
 
-    LOGL(LOG_SSENGINE, "%s", temp);
+       LOGL(LOG_SSENGINE, "%s", temp);
 #endif
-    return S_SS_SUCCESS;
+       return S_SS_SUCCESS;
 }
 
 long SS_FSTrace(void *pbUserData, const unsigned short *aFormat, ...)
 {
-    va_list list;
+       va_list list;
 
-    va_start(list, aFormat);
-    vprintf((const char *)aFormat, list);
-    va_end(list);
+       va_start(list, aFormat);
+       vprintf((const char *)aFormat, list);
+       va_end(list);
 
-    return S_SS_SUCCESS;
+       return S_SS_SUCCESS;
 }
 
 long SS_ResetTimerA(void)
 {
-    //LOG("%s \n", __func__);
+       //LOG("%s \n", __func__);
 
-    return S_SS_SUCCESS;
+       return S_SS_SUCCESS;
 }
 
 long SS_GetDelta(void *pbUserData, unsigned char *pbBuffer, SS_UINT32 dwStartAddressOffset, SS_UINT32 dwSize)
 {
-    int ret = S_SS_SUCCESS;
-    int readCount = 0;
-    FILE *fp;
-    long itemOffset = 0;
-
-    ua_data_t *ua_data = (ua_data_t *) pbUserData;
-    ua_part_info_t *ua_partition = ua_data->parti_info;
-    ua_update_data_t *ua_update_data = ua_data->update_data;
-
-    LOGL(LOG_SSENGINE, "SS_GetDelta offset 0x%x(%u), size 0x%x(%u)\n",
-         dwStartAddressOffset, dwStartAddressOffset, dwSize, dwSize);
-
-    itemOffset = tar_get_item_offset(ua_update_data->ua_delta_path, ua_partition->ua_subject_name);
-    if (itemOffset < 0) {
-        return E_SS_OPENFILE_ONLYR;
-    }
-
-    fp = fopen(ua_update_data->ua_delta_path, "r");
-    if (!fp) {
-        LOGL(LOG_SSENGINE, "open file %s failed.\n", ua_update_data->ua_delta_path);
-        return E_SS_OPENFILE_ONLYR;
-    }
-
-    if (fseek(fp, itemOffset + dwStartAddressOffset, 0) == -1)
-        ret = E_SS_READ_ERROR;
-    else {
-        readCount = fread(pbBuffer, 1, dwSize, fp);
-        if (readCount != dwSize) {
-            LOGL(LOG_SSENGINE, "error in read size\n");
-            ret = E_SS_READ_ERROR;
-        }
-    }
-    fclose(fp);
-
-    return ret;
+       int ret = S_SS_SUCCESS;
+       int readCount = 0;
+       FILE *fp;
+       long itemOffset = 0;
+
+       ua_data_t *ua_data = (ua_data_t *) pbUserData;
+       ua_part_info_t *ua_partition = ua_data->parti_info;
+       ua_update_data_t *ua_update_data = ua_data->update_data;
+
+       LOGL(LOG_SSENGINE, "SS_GetDelta offset 0x%x(%u), size 0x%x(%u)\n",
+                dwStartAddressOffset, dwStartAddressOffset, dwSize, dwSize);
+
+       itemOffset = tar_get_item_offset(ua_update_data->ua_delta_path, ua_partition->ua_subject_name);
+       if (itemOffset < 0)
+               return E_SS_OPENFILE_ONLYR;
+
+       fp = fopen(ua_update_data->ua_delta_path, "r");
+       if (!fp) {
+               LOGL(LOG_SSENGINE, "open file %s failed.\n", ua_update_data->ua_delta_path);
+               return E_SS_OPENFILE_ONLYR;
+       }
+
+       if (fseek(fp, itemOffset + dwStartAddressOffset, 0) == -1)
+               ret = E_SS_READ_ERROR;
+       else {
+               readCount = fread(pbBuffer, 1, dwSize, fp);
+               if (readCount != dwSize) {
+                       LOGL(LOG_SSENGINE, "error in read size\n");
+                       ret = E_SS_READ_ERROR;
+               }
+       }
+       fclose(fp);
+
+       return ret;
 }
index 5d92020..d7175ba 100755 (executable)
@@ -7,7 +7,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 
 #define MAX_PATH 256
 
-#define NAND_BLOCK_BITS 18      // 0x40000
-#define NAND_PAGE_BITS 12       // 0x1000
+#define NAND_BLOCK_BITS 18       // 0x40000
+#define NAND_PAGE_BITS 12         // 0x1000
 
 #if defined(PART_W) || defined(PART_WB1) || defined(PART_W3G) || defined(PART_TINY) \
        || defined(PART_HIGGS) || defined(PART_KIRAN) || defined(PART_KIRANLTE) || defined(PART_ORBIS)
-#define UA_RAM_SIZE            64*1024*1024    // it sould be same <RamSize>0x4000000</RamSize> in xml.
+#define UA_RAM_SIZE            64*1024*1024    // it sould be same <RamSize>0x4000000</RamSize> in xml.
 #else
 #define UA_RAM_SIZE            512*1024*1024   // it sould be same <RamSize>0x20000000</RamSize> in xml.
 #endif
 
-#define FS_ID_MAX_LEN 4
-#define DP_HEADER_SIZE 36
-#define DP_START_OFFSET        0
-#define  BACKUPBUFFER_NUM                           4
+#define FS_ID_MAX_LEN          4
+#define DP_HEADER_SIZE         36
+#define DP_START_OFFSET                0
+#define  BACKUPBUFFER_NUM      4
 
 /*******[ Multiprocess API sample implementation ]******/
 #define _NOEXEC_
 #define HANDLE_RUN_PROC        "handle_run_process"
 
 struct status_header_page {
-    unsigned char preamble[5];  // state·Î »ç¿ëÇÒ ¼ö ÀÖÀ½, FOTA, SBLB, ZIMG, PLRM, MDEM, DONE, FAILµî
-    unsigned long format;       //ÃÖÁ¾ return °ª, ¾Æ·¡ °¢ image¿¡ ´ëÇÑ engineÀÇ return°ªÀ» DM error table·Î º¯°æµÈ °ª
-    unsigned long reserved;     // Not used
-    unsigned long flexStatus;   // Not used
-    unsigned long apfwStatus;   //zImage update¿¡ ´ëÇÑ engineÀÇ return °ª
-    unsigned long apffsStatus;  //platform update¿¡ ´ëÇÑengineÀÇreturn °ª
-    unsigned long apuaStatus;   //sbl update¿¡ ´ëÇÑengineÀÇreturn °ª
-    unsigned long bpfwStatus;   //modem update¿¡ ´ëÇÑengineÀÇreturn °ª
-    unsigned long bpuaStatus;
+       unsigned char preamble[5];  // state·Î »ç¿ëÇÒ ¼ö ÀÖÀ½, FOTA, SBLB, ZIMG, PLRM, MDEM, DONE, FAILµî
+       unsigned long format;      //ÃÖÁ¾ return °ª, ¾Æ·¡ °¢ image¿¡ ´ëÇÑ engineÀÇ return°ªÀ» DM error table·Î º¯°æµÈ °ª
+       unsigned long reserved;  // Not used
+       unsigned long flexStatus;   // Not used
+       unsigned long apfwStatus;   //zImage update¿¡ ´ëÇÑ engineÀÇ return °ª
+       unsigned long apffsStatus;  //platform update¿¡ ´ëÇÑengineÀÇreturn °ª
+       unsigned long apuaStatus;   //sbl update¿¡ ´ëÇÑengineÀÇreturn °ª
+       unsigned long bpfwStatus;   //modem update¿¡ ´ëÇÑengineÀÇreturn °ª
+       unsigned long bpuaStatus;
 };
 
 void SS_unicode_to_char(const char *src, char *dest, int size);
index f116c14..c9e2daa 100755 (executable)
 #ifndef __SS_Engine_ERRORS__
 #define __SS_Engine_ERRORS__
 
-#define  S_SS_SUCCESS                                                                  (0)     /*! Success Code */
-#define  E_SS_FAILURE                                                                  (1)     /*! Failure Code */
+#define  S_SS_SUCCESS                                                  (0)     /*! Success Code */
+#define  E_SS_FAILURE                                                  (1)     /*! Failure Code */
 
 /* INPUT Processing errors */
 
 /* invocation errors */
-#define E_SS_BAD_PARAMS                                                                (0xA00)          /**< error in a run parameter */
+#define E_SS_BAD_PARAMS                                                        (0xA00)          /**< error in a run parameter */
 #define E_SS_FSINVALIDNODEPARAMS                                       (0xA01) /* Failed to Parse the Params to verify NODE */
-#define E_SS_FSBADNODES                                                                (0xA02) /* Failed to verify NODE for FS */
-#define E_SS_FSBADDELTA                                                                (0xA03) /* Delta File does NOT contain required information on FS */
-#define E_SS_FSBADATTRIBUTES                                           (0xA04) /* Failed to parse attribute data */
-#define E_SS_FSFAILEDTOOPENPATCHINFO                                   (0xA05) /*Failed to open patch list file having details of PATCH info */
-#define E_SS_FSFAILEDTOPARSEDELTACNT                           (0xA06) /* Failed to parse the PATCH count information */
-#define E_SS_FSFAILEDTOPARSEDELTAINFO                          (0xA07) /* Failed to parse the Delta patch information */
+#define E_SS_FSBADNODES                                                        (0xA02) /* Failed to verify NODE for FS */
+#define E_SS_FSBADDELTA                                                        (0xA03) /* Delta File does NOT contain required information on FS */
+#define E_SS_FSBADATTRIBUTES                                           (0xA04) /* Failed to parse attribute data */
+#define E_SS_FSFAILEDTOOPENPATCHINFO                                   (0xA05) /*Failed to open patch list file having details of PATCH info */
+#define E_SS_FSFAILEDTOPARSEDELTACNT                                   (0xA06) /* Failed to parse the PATCH count information */
+#define E_SS_FSFAILEDTOPARSEDELTAINFO                                  (0xA07) /* Failed to parse the Delta patch information */
 
 /* update package errors */
-#define  E_SS_PKG_TOO_LONG                                                     (0xA08) /**< expected length error    */
-#define  E_SS_PKG_CORRUPTED                                                    (0xA09) /**< structural error         */
+#define  E_SS_PKG_TOO_LONG                                             (0xA08) /**< expected length error    */
+#define  E_SS_PKG_CORRUPTED                                            (0xA09) /**< structural error         */
 #define  E_SS_SOURCE_CORRUPTED                                         (0xA10) /**< signature error          */
 
 /*Delta Errors*/
 
-#define E_SS_FSBADPATCH                                                                (0xB00) /*File Patch Does NOT match the signature */
+#define E_SS_FSBADPATCH                                                        (0xB00) /*File Patch Does NOT match the signature */
 #define E_SS_FSSHA_MISMATCH                                            (0xB01) /*Could NOT produce expected Target SHA for file */
-#define E_SS_IMGBADDELTA                                                       (0xB02) /* Failed to parse attribute data */
-#define E_SS_IMGBADPATCH                                                       (0xB03) /*Image Patch Does NOT match the signature */
+#define E_SS_IMGBADDELTA                                               (0xB02) /* Failed to parse attribute data */
+#define E_SS_IMGBADPATCH                                               (0xB03) /*Image Patch Does NOT match the signature */
 #define E_SS_IMGSHA_MISMATCH                                           (0xB04) /*Could NOT produce expected Target SHA for Image */
 #define E_SS_SHAPRASE_FAILED                                           (0xB05) /*Could NOT Parse SHA */
 
 
 /* Resources errors */
 #define  E_SS_NOT_ENOUGH_RAM                                           (0xC00) /**< given RAM is not enough  */
-#define  E_SS_BAD_RAM                                                          (0xC01) /**< does not behave as RAM   */
-#define  E_SS_MALLOC_ERROR                                                     (0xC02) /**< memory allocation failure */
+#define  E_SS_BAD_RAM                                                  (0xC01) /**< does not behave as RAM   */
+#define  E_SS_MALLOC_ERROR                                             (0xC02) /**< memory allocation failure */
 
 /* Image update Error codes */
-#define  E_SS_WRITE_ERROR                                                      (0xC03) /**< flash writing failure    */
-#define  E_SS_ERASE_ERROR                                                      (0xC04) /**< flash erasing failure    */
-#define  E_SS_READ_ERROR                                                       (0xC05) /**< flash reading failure    */
+#define  E_SS_WRITE_ERROR                                              (0xC03) /**< flash writing failure    */
+#define  E_SS_ERASE_ERROR                                              (0xC04) /**< flash erasing failure    */
+#define  E_SS_READ_ERROR                                               (0xC05) /**< flash reading failure    */
 
 /*File System Error codes */
 #define  E_SS_OPENFILE_ONLYR                                           (0xC06)         /**< file does not exist      */
-#define  E_SS_OPENFILE_WRITE                                                   (0xC07)         /**< RO or no access rights   */
+#define  E_SS_OPENFILE_WRITE                                           (0xC07)         /**< RO or no access rights   */
 #define  E_SS_DELETEFILE_NOFILE                                                (0xC08) /**< file does not exist      */
-#define  E_SS_DELETEFILE                                                               (0xC09) /**< no access rights         */
-#define  E_SS_RESIZEFILE                                                               (0xC10) /**< cannot resize file       */
-#define  E_SS_READFILE_SIZE                                                    (0xC11) /**< cannot read specified size*/
+#define  E_SS_DELETEFILE                                               (0xC09) /**< no access rights         */
+#define  E_SS_RESIZEFILE                                               (0xC10) /**< cannot resize file       */
+#define  E_SS_READFILE_SIZE                                            (0xC11) /**< cannot read specified size*/
 #define  E_SS_CLOSEFILE_ERROR                                          (0xC12) /**< cannot close file handle */
-#define  E_SS_FAILED_CREATING_SYMBOLIC_LINK            (0xC13)         /**< Failed creating symbolic link */
-#define  E_SS_CANNOT_CREATE_DIRECTORY                          (0xC14)         /**< Failed creating directory */
+#define  E_SS_FAILED_CREATING_SYMBOLIC_LINK                            (0xC13)         /**< Failed creating symbolic link */
+#define  E_SS_CANNOT_CREATE_DIRECTORY                                  (0xC14)         /**< Failed creating directory */
 #define  E_SS_FSMEMORYERROR                                            (0xC15) /* Failed to allocate Memory */
 #define  E_SS_FILENAMELENERROR                                         (0xC16) /* Failed to serve filename length */
 
 /*Engine errors */
 
-#define E_SS_NOT_ENOUGH_RAM_FOR_OPERATION2             (0xD00) /**< There is not enough RAM to run with operation=2 (Dry update) */
+#define E_SS_NOT_ENOUGH_RAM_FOR_OPERATION2                             (0xD00) /**< There is not enough RAM to run with operation=2 (Dry update) */
 #define E_SS_DELTA_FILE_TOO_LONG                                       (0xD01) /**< Delta file too long - curropted */
 #define E_SS_ERROR_IN_DELETES_SIG                                      (0xD02) /**< Mismatch between deletes sig and delta deletes buffers signature */
 #define E_SS_DELTA_IS_CORRUPT                                          (0xD03) /**< Delta file is corrupt: signature mismatch between delta header signature and calculated signature */
-#define E_SS_SOURCE_FILE_SIG_MISMATCH                          (0xD04) /**< File signature does not match signature */
+#define E_SS_SOURCE_FILE_SIG_MISMATCH                                  (0xD04) /**< File signature does not match signature */
 #define E_SS_TARGET_SIG_MISMATCH                                       (0xD05) /**< Signature for the target buffer does not match the one stored in the delta file */
-#define E_SS_INVALID_BACKUP                                                    (0xD06) /**< Too many dirty buffers */
+#define E_SS_INVALID_BACKUP                                            (0xD06) /**< Too many dirty buffers */
 #define E_SS_UPI_VERSION_MISMATCH                                      (0xD07) /**< UPI version mismatch between UPI and delta */
-#define E_SS_PARTITION_NAME_NOT_FOUND                          (0xD08) /**< Partition name is different in delta and in UPI data */
-#define E_SS_NO_SPACE_LEFT                                                     (0xD09) /**< There is not enough flash to update or install the files */
-#define E_SS_INVALID_DP_HEADER                                         (0xD10)  /**< Deployment Package header is invalid */
-#define E_SS_INVALID_DP_WRONG_SIGNATURE                        (0xD11)  /**< Deployment Package signature is invalid */
-#define E_SS_FSFAILEDTOBACKUPPATCHINFO                         (0xD12) /* Failed to create backup file to write Delta patch info data */
-#define E_SS_FSUPDATEFAILED                                                    (0xD13) /*FS Failed during UPGRADE */
-#define E_SS_FSSRCBACKUPFAILED                                         (0xD14) /*Failed to backup FS */
-#define E_SS_FSSRCCURRUPTED                                                    (0xD15) /*Could NOT update FS as SRC seems to be corrupted */
+#define E_SS_PARTITION_NAME_NOT_FOUND                                  (0xD08) /**< Partition name is different in delta and in UPI data */
+#define E_SS_NO_SPACE_LEFT                                             (0xD09) /**< There is not enough flash to update or install the files */
+#define E_SS_INVALID_DP_HEADER                                         (0xD10)  /**< Deployment Package header is invalid */
+#define E_SS_INVALID_DP_WRONG_SIGNATURE                                        (0xD11)  /**< Deployment Package signature is invalid */
+#define E_SS_FSFAILEDTOBACKUPPATCHINFO                                 (0xD12) /* Failed to create backup file to write Delta patch info data */
+#define E_SS_FSUPDATEFAILED                                            (0xD13) /*FS Failed during UPGRADE */
+#define E_SS_FSSRCBACKUPFAILED                                         (0xD14) /*Failed to backup FS */
+#define E_SS_FSSRCCURRUPTED                                            (0xD15) /*Could NOT update FS as SRC seems to be corrupted */
 #define E_SS_IMGUPDATEFAILED                                           (0xD16) /*IMG Failed during UPGRADE */
-#define E_SS_IMGSRCBACKUPFAILED                                        (0xD17) /*Failed to backup IMG */
-#define E_SS_IMGRECOVERYWRITEFAILED                            (0xD18) /*Failed to write patched Recovery IMG */
+#define E_SS_IMGSRCBACKUPFAILED                                                (0xD17) /*Failed to backup IMG */
+#define E_SS_IMGRECOVERYWRITEFAILED                                    (0xD18) /*Failed to write patched Recovery IMG */
 #define E_SS_IMGSRCCURRUPTED                                           (0xD19) /*Could NOT update IMG as SRC seems to be corrupted */
 #define E_SS_IMGFLASHWRITEFAIL                                         (0xD20) /*Failed to write Patched IMG data to flash */
-#define E_SS_PATCHFILE_DEL_ERROR                                               (0xD21) /*Failed to Clear/Del Patched SRC file */
+#define E_SS_PATCHFILE_DEL_ERROR                                       (0xD21) /*Failed to Clear/Del Patched SRC file */
 
 #endif
index 72d6f8e..2f2ccc8 100755 (executable)
  * Partition type
  */
 typedef enum {
-    PT_FOTA,                    //!< Image
-    PT_FS                       //!< File system
+       PT_FOTA,                    //!< Image
+       PT_FS                       //!< File system
 } PartitionType;
 
 /**
  * In-place update
  */
 typedef enum {
-    UT_SELF_UPDATE = 0,         //!< Don't update in place
-    UT_NO_SELF_UPDATE,          //!< Update in place
-    UT_PRIVATE,                 //!< For internal usage
+       UT_SELF_UPDATE = 0,         //!< Don't update in place
+       UT_NO_SELF_UPDATE,          //!< Update in place
+       UT_PRIVATE,                 //!< For internal usage
 } UpdateType;
 
 typedef unsigned int SS_UINT32;
 
 typedef enum {
-    FT_REGULAR_FILE,
-    FT_SYMBOLIC_LINK,
-    FT_FOLDER,
-    FT_MISSING
+       FT_REGULAR_FILE,
+       FT_SYMBOLIC_LINK,
+       FT_FOLDER,
+       FT_MISSING
 } enumFileType;
 
 #ifdef __cplusplus
@@ -58,53 +58,53 @@ extern "C" {
 /**
  * Partition data
  */
-    typedef struct tagCustomerPartitionData {
+       typedef struct tagCustomerPartitionData {
 /**
  * Partition name. Maximum 256 characters. Must match exactly the name used in
  * the UPG.
  */
-        const char *partition_name;
+               const char *partition_name;
 
 /**
  * Partition flash address. Address must be sector aligned. Relevant only for
  * R/O partitions of any type; for R/W FS updates, set to 0.
  */
-        SS_UINT32 rom_start_address;
+               SS_UINT32 rom_start_address;
 
 /**
  * Mount point or drive letter containing the partition. Maximum size is 256
  * characters. Relevent only for R/W FS updates; otherwise set to 0.<p>
  */
-        const char *mount_point;
+               const char *mount_point;
 
 /**
  * Source path (input) partition if the update will not be done in place.
  * Maximum 25 characters. For Image updates, set to 0.
  */
-        const char *strSourcePath;
+               const char *strSourcePath;
 
 /**
  * Target path (output) partition if the update will not be done in place.
  * Maximum 25 characters. For Image updates, set to 0.
  */
-        const char *strTargetPath;
+               const char *strTargetPath;
 
 /**
  * Internal use; leave null.
  */
-        const void *priv;
+               const void *priv;
 
 /**
  * Partition type, a \ref PartitionType value.
  */
-        PartitionType partition_type;
+               PartitionType partition_type;
 
-    } CustomerPartitionData;
+       } CustomerPartitionData;
 
 /**
  * Device data
  */
-    typedef struct tag_Engine_DeviceData {
+       typedef struct tag_Engine_DeviceData {
 /**
  * UPI Mode. One of:
  * \li 0: scout and update. Verify that the update is applicable to the device
@@ -125,22 +125,22 @@ extern "C" {
  * (post-installation). This mode applies only to FS updates. Does not verify
  * attributes or empty folders.
  */
-        SS_UINT32 ui32Operation;
+               SS_UINT32 ui32Operation;
 
 /**
  * Pre-allocated RAM space.
  */
-        unsigned char *pRam;
+               unsigned char *pRam;
 
 /**
  * Size of pRam in bytes.
  */
-        SS_UINT32 ui32RamSize;
+               SS_UINT32 ui32RamSize;
 
 /**
  * Number of backup sectors listed in pBufferBlocks.
  */
-        SS_UINT32 ui32NumberOfBuffers;
+               SS_UINT32 ui32NumberOfBuffers;
 
 /**
  * List of backup buffer sector addresses. Addresses must be
@@ -148,18 +148,18 @@ extern "C" {
  * is used instead of pTempPath. Otherwise pBufferBlocks should be set to 0
  * and pTempPath (see below) will be used to allocate the backup as a file.
  */
-        SS_UINT32 *pBufferBlocks;
+               SS_UINT32 *pBufferBlocks;
 
 /**
  * Number of partitions listed in pFirstPartitionData.
  */
-        SS_UINT32 ui32NumberOfPartitions;
+               SS_UINT32 ui32NumberOfPartitions;
 
 /**
  * List of partition data structures, a list of \ref CustomerPartitionData
  * values.
  */
-        CustomerPartitionData *pFirstPartitionData;
+               CustomerPartitionData *pFirstPartitionData;
 
 /**
  * Path to temporary storage. If the update contains FS updates, pTempPath is
@@ -169,13 +169,13 @@ extern "C" {
  * The maximum file size will not exceed the sector size x number of backup
  * sectors.
  */
-        char *pTempPath;
+               char *pTempPath;
 
 /**
  * Whether or not there is a UPI self-update in the update, an
  * \ref UpdateType value.
  */
-        UpdateType enmUpdateType;
+               UpdateType enmUpdateType;
 
 /**
  * List of customer-defined installer types. For an Image only update, use a
@@ -183,12 +183,12 @@ extern "C" {
  *
  * For the list of installer types, see the SWM Center documentation.
  */
-        SS_UINT32 *pComponentInstallerTypes;
+               SS_UINT32 *pComponentInstallerTypes;
 
 /**
  * Number of installer types in pComponentInstallerTypes.
  */
-        SS_UINT32 ui32ComponentInstallerTypesNum;
+               SS_UINT32 ui32ComponentInstallerTypesNum;
 
 /**
  * Update flags, if any. Used by the SWM Center.<p>
@@ -196,23 +196,23 @@ extern "C" {
  * For non SWM Center update, set to 0xFFFFFFFF
  * For the list of update flags, see the SWM Center documentation.
  */
-        SS_UINT32 ui32ComponentUpdateFlags;
+               SS_UINT32 ui32ComponentUpdateFlags;
 
 /**
  * Update number within the DP.
  */
-        SS_UINT32 ui32OrdinalToUpdate;
+               SS_UINT32 ui32OrdinalToUpdate;
 
 /**
  * Deprecated.
  */
-        char *pDeltaPath;
+               char *pDeltaPath;
 
 /**
  * Additional data to pass to APIs, if any. Set to null if not used.
  */
-        void *pbUserData;
-    } Engine_DeviceData;
+               void *pbUserData;
+       } Engine_DeviceData;
 
 /**
  *******************************************************************************
@@ -224,7 +224,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_CheckDPStructure(void *pbUserData);
+       long SS_CheckDPStructure(void *pbUserData);
 
 /**
  *******************************************************************************
@@ -245,8 +245,8 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_GetNumberOfDeltas(void *pbUserData, SS_UINT32 * num_deltas, SS_UINT32 * installer_types,
-                              SS_UINT32 installer_types_num, SS_UINT32 component_flags);
+       long SS_GetNumberOfDeltas(void *pbUserData, SS_UINT32 * num_deltas, SS_UINT32 * installer_types,
+                       SS_UINT32 installer_types_num, SS_UINT32 component_flags);
 
 /**
  *******************************************************************************
@@ -269,8 +269,8 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_GetSignedDeltaOffset(void *pbUserData, SS_UINT32 delta_ordinal, SS_UINT32 * offset, SS_UINT32 * size,
-                                 SS_UINT32 * installer_types, SS_UINT32 installer_types_num, SS_UINT32 component_flags);
+       long SS_GetSignedDeltaOffset(void *pbUserData, SS_UINT32 delta_ordinal, SS_UINT32 * offset, SS_UINT32 * size,
+                       SS_UINT32 * installer_types, SS_UINT32 installer_types_num, SS_UINT32 component_flags);
 
 /**
  *******************************************************************************
@@ -293,9 +293,9 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_GetUnsignedDeltaOffset(void *pbUserData, SS_UINT32 delta_ordinal, SS_UINT32 * offset, SS_UINT32 * size,
-                                   SS_UINT32 * installer_types, SS_UINT32 installer_types_num,
-                                   SS_UINT32 component_flags);
+       long SS_GetUnsignedDeltaOffset(void *pbUserData, SS_UINT32 delta_ordinal, SS_UINT32 * offset, SS_UINT32 * size,
+                       SS_UINT32 * installer_types, SS_UINT32 installer_types_num,
+                       SS_UINT32 component_flags);
 
 /**
  *******************************************************************************
@@ -309,7 +309,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_GetRBDeltaOffset(void *pbUserData, SS_UINT32 signed_delta_offset, SS_UINT32 * delta_offset);
+       long SS_GetRBDeltaOffset(void *pbUserData, SS_UINT32 signed_delta_offset, SS_UINT32 * delta_offset);
 
 /**
  *******************************************************************************
@@ -327,7 +327,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_Engine_Update(Engine_DeviceData * pDeviceData);
+       long SS_Engine_Update(Engine_DeviceData * pDeviceData);
 
 /**
  *******************************************************************************
@@ -342,7 +342,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_Engine_GetDpRamUse(SS_UINT32 * ui32pRamUse, Engine_DeviceData * pDeviceData);
+       long SS_Engine_GetDpRamUse(SS_UINT32 * ui32pRamUse, Engine_DeviceData * pDeviceData);
 
 /**
  *******************************************************************************
@@ -369,9 +369,9 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_GetDPProtocolVersion(void *pbUserData, void *pbyRAM, SS_UINT32 dwRAMSize,
-                                 SS_UINT32 * installer_types, SS_UINT32 installer_types_num, SS_UINT32 component_flags,
-                                 SS_UINT32 * dpProtocolVersion);
+       long SS_GetDPProtocolVersion(void *pbUserData, void *pbyRAM, SS_UINT32 dwRAMSize,
+                       SS_UINT32 * installer_types, SS_UINT32 installer_types_num, SS_UINT32 component_flags,
+                       SS_UINT32 * dpProtocolVersion);
 
 /**
  *******************************************************************************
@@ -399,9 +399,9 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_GetDPScoutProtocolVersion(void *pbUserData, void *pbyRAM, SS_UINT32 dwRAMSize,
-                                      SS_UINT32 * installer_types, SS_UINT32 installer_types_num,
-                                      SS_UINT32 component_flags, SS_UINT32 * dpScoutProtocolVersion);
+       long SS_GetDPScoutProtocolVersion(void *pbUserData, void *pbyRAM, SS_UINT32 dwRAMSize,
+                       SS_UINT32 * installer_types, SS_UINT32 installer_types_num,
+                       SS_UINT32 component_flags, SS_UINT32 * dpScoutProtocolVersion);
 
 /**
  *******************************************************************************
@@ -414,7 +414,7 @@ extern "C" {
  * \return     S_SS_SUCCESS
  *******************************************************************************
  */
-    long SS_GetUPIVersion(unsigned char *pbVersion);
+       long SS_GetUPIVersion(unsigned char *pbVersion);
 
 /**
  *******************************************************************************
@@ -428,7 +428,7 @@ extern "C" {
  *                     this returns 50140.
  *******************************************************************************
  */
-    SS_UINT32 SS_GetUPIProtocolVersion(void);
+       SS_UINT32 SS_GetUPIProtocolVersion(void);
 
 /**
  *******************************************************************************
@@ -442,7 +442,7 @@ extern "C" {
  *                     5.0.14.33, this returns 50140.
  *******************************************************************************
  */
-    SS_UINT32 SS_GetUPIScoutProtocolVersion(void);
+       SS_UINT32 SS_GetUPIScoutProtocolVersion(void);
 
 /**
  *******************************************************************************
@@ -457,7 +457,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    SS_UINT32 SS_GetDeltaProtocolVersion(void *pbUserData, void *pbyRAM, SS_UINT32 dwRAMSize);
+       SS_UINT32 SS_GetDeltaProtocolVersion(void *pbUserData, void *pbyRAM, SS_UINT32 dwRAMSize);
 /**
  *******************************************************************************
  * Get scout protocol version of an update.<p>
@@ -471,7 +471,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    SS_UINT32 SS_GetDeltaScoutProtocolVersion(void *pbUserData, void *pbyRAM, SS_UINT32 dwRAMSize);     /* User data passed to all porting routines, pointer for the ram to use, size of the ram */
+       SS_UINT32 SS_GetDeltaScoutProtocolVersion(void *pbUserData, void *pbyRAM, SS_UINT32 dwRAMSize);     /* User data passed to all porting routines, pointer for the ram to use, size of the ram */
 
 /**
  *******************************************************************************
@@ -485,7 +485,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_ResetTimerA(void);
+       long SS_ResetTimerA(void);
 
 /**
  *******************************************************************************
@@ -502,7 +502,7 @@ extern "C" {
  * \return     None
  *******************************************************************************
  */
-    void SS_Progress(void *pbUserData, SS_UINT32 uPercent);
+       void SS_Progress(void *pbUserData, SS_UINT32 uPercent);
 
 /**
  *******************************************************************************
@@ -525,7 +525,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    SS_UINT32 SS_Trace(void *pbUserData, const char *aFormat, ...);
+       SS_UINT32 SS_Trace(void *pbUserData, const char *aFormat, ...);
 
 /**
  *******************************************************************************
@@ -543,7 +543,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_GetDelta(void *pbUserData, unsigned char *pbBuffer, SS_UINT32 dwStartAddressOffset, SS_UINT32 dwSize);
+       long SS_GetDelta(void *pbUserData, unsigned char *pbBuffer, SS_UINT32 dwStartAddressOffset, SS_UINT32 dwSize);
 
 #ifdef __cplusplus
 }
index f0dadd1..187d209 100755 (executable)
@@ -45,47 +45,45 @@ static int feature_support_capability;
  ************************************************************/
 void SS_create_dir(char *pathname, int mode)
 {
-    char *p;
-    int r;
-
-    /* Strip trailing '/' */
-    if (pathname[strlen(pathname) - 1] == '/')
-        pathname[strlen(pathname) - 1] = '\0';
-
-    /* Try creating the directory. */
-    r = mkdir(pathname, mode);
-
-    if (r != 0) {
-        /* On failure, try creating parent directory. */
-        p = strrchr(pathname, '/');
-        if (p != NULL) {
-            *p = '\0';
-            SS_create_dir(pathname, 0755);
-            *p = '/';
-            r = mkdir(pathname, mode);
-        }
-    }
-    if (r != 0) {
-        if (r != EEXIST && r != -1)
-            LOG("Could not create directory [%s] Error[%d]\n", pathname, r);
-    }
+       char *p;
+       int r;
+
+       /* Strip trailing '/' */
+       if (pathname[strlen(pathname) - 1] == '/')
+               pathname[strlen(pathname) - 1] = '\0';
+
+       /* Try creating the directory. */
+       r = mkdir(pathname, mode);
+
+       if (r != 0) {
+               /* On failure, try creating parent directory. */
+               p = strrchr(pathname, '/');
+               if (p != NULL) {
+                       *p = '\0';
+                       SS_create_dir(pathname, 0755);
+                       *p = '/';
+                       r = mkdir(pathname, mode);
+               }
+       }
+       if (r != 0) {
+               if (r != EEXIST && r != -1)
+                       LOG("Could not create directory [%s] Error[%d]\n", pathname, r);
+       }
 }
 
 
 void SS_unicode_to_char(const char *src, char *dest, int size)
 {
-       if (src == NULL) {
+       if (src == NULL)
                return;
-       }
 
        strncpy(dest, src, size);
 }
 
 void SS_char_to_unicode(const char *src, char *dest, int size)
 {
-       if (src == NULL) {
+       if (src == NULL)
                return;
-       }
 
        strncpy(dest, src, size);
 }
@@ -156,7 +154,7 @@ SS_CopyFile(void *pbUserData,
                writeCount = write(fd2, buf, readCount);
                if (writeCount != readCount) {
                        LOGE(" read %d, but write %d, abort.\n", readCount,
-                            writeCount);
+                                       writeCount);
                        ret = E_SS_WRITE_ERROR;
                        break;
                }
@@ -191,9 +189,9 @@ int SS_unlink_cbf(const char *fpath, const struct stat *sb, int typeflag, struct
 {
        int rv = remove(fpath);//returns zero on success and -1 on failure
 
-       if (rv){
+       if (rv) {
                perror(fpath);
-               LOGE("path : %s, remove value: %d, errno: %d\n",fpath, rv, errno);
+               LOGE("path : %s, remove value: %d, errno: %d\n", fpath, rv, errno);
        }
        return rv;
 }
@@ -230,14 +228,14 @@ long SS_CreateFolder(void *pbUserData, const char *strPath)
 
        SS_unicode_to_char((const char *)strPath, (char *)path, MAX_PATH - 1);
        mode = S_IRUSR /*Read by owner */  |
-           S_IWUSR /*Write by owner */  |
-           S_IXUSR /*Execute by owner */  |
-           S_IRGRP /*Read by group */  |
-           S_IWGRP /*Write by group */  |
-           S_IXGRP /*Execute by group */  |
-           S_IROTH /*Read by others */  |
-           S_IWOTH /*Write by others */  |
-           S_IXOTH /*Execute by others */ ;
+               S_IWUSR /*Write by owner */  |
+               S_IXUSR /*Execute by owner */  |
+               S_IRGRP /*Read by group */  |
+               S_IWGRP /*Write by group */  |
+               S_IXGRP /*Execute by group */  |
+               S_IROTH /*Read by others */  |
+               S_IWOTH /*Write by others */  |
+               S_IXOTH /*Execute by others */ ;
 
        LOGL(LOG_SSENGINE, "%s, mode:0x%x\n", path, mode);
 
@@ -245,8 +243,7 @@ long SS_CreateFolder(void *pbUserData, const char *strPath)
 
        if (ret == 0 || ((ret == -1) && (errno == EEXIST))) {
                return S_SS_SUCCESS;
-       } else if ((ret == -1) && (errno == ENOENT))    //maybe multi directory problem
-       {
+       } else if ((ret == -1) && (errno == ENOENT)) {  //maybe multi directory problem
                //do//Recursive Function
                //{
                ret = SS_recursive_folder_creater(path, mode);
@@ -297,7 +294,7 @@ SS_OpenFile(void *pbUserData,
        mode = SS_get_mode(wFlag);
        //LOGL(LOG_SSENGINE, "Path:%s  wFlag:%d  Mode:%d\n", path, wFlag, mode);
 
-       if(mode & O_CREAT) {
+       if (mode & O_CREAT) {
                //LOGL(LOG_SSENGINE, " open() S_IRWXU\n");
                *pwHandle = open(path, mode, S_IRWXU);
        } else {
@@ -391,14 +388,14 @@ long SS_CloseFile(void *pbUserData, long wHandle)
 
 long
 SS_WriteFile(void *pbUserData,
-            long wHandle,
-            SS_UINT32 dwPosition,
-            unsigned char *pbBuffer, SS_UINT32 dwSize)
+               long wHandle,
+               SS_UINT32 dwPosition,
+               unsigned char *pbBuffer, SS_UINT32 dwSize)
 {
        int ret = 0;
 
        LOGL(LOG_SSENGINE, "Handle:%ld , Pos:%u , Size: %u\n", wHandle,
-            dwPosition, dwSize);
+                       dwPosition, dwSize);
 
        ret = lseek(wHandle, dwPosition, SEEK_SET);
        if (ret < 0) {
@@ -427,9 +424,8 @@ long SS_MoveFile(void *pbUserData, const char *strFromPath,
        char path1[MAX_PATH] = { '\0' };
        char path2[MAX_PATH] = { '\0' };
 
-       if (!strFromPath || !strToPath) {
+       if (!strFromPath || !strToPath)
                return -1;      //should never happen
-       }
 
        SS_unicode_to_char(strFromPath, (char *)path1, MAX_PATH - 1);
        SS_unicode_to_char(strToPath, (char *)path2, MAX_PATH - 1);
@@ -444,17 +440,16 @@ long SS_MoveFile(void *pbUserData, const char *strFromPath,
        if (ret < 0) {
                LOGL(LOG_INFO, "rename fail with code [%d], try to create dir if errno is 2\n", errno);
                if (errno == 2) {
-                       char * file_name = strrchr(path2,'/');
+                       char * file_name = strrchr(path2, '/');
                        *file_name = '\0';
-                       SS_create_dir(path2,0755);
+                       SS_create_dir(path2, 0755);
                        *file_name = '/';
                        ret = rename(path1, path2);
                        if (ret < 0) {
-                               LOGE("Move failed, error code [%d]",errno);
+                               LOGE("Move failed, error code [%d]", errno);
                                return E_SS_WRITE_ERROR;
-                               }
-               }
-               else if (errno == 18){ //EXDEV 18  /* Cross-device link */
+                       }
+               } else if (errno == 18) { //EXDEV 18  /* Cross-device link */
                        //Moving file across partitions if mount point is different (Extremely rare)
                        ret = (int)SS_CopyFile(NULL, path1, path2);
                        if (ret != S_SS_SUCCESS) {
@@ -466,9 +461,8 @@ long SS_MoveFile(void *pbUserData, const char *strFromPath,
                                LOGE("failed to unlink [%s] code [%d]\n", path1, errno);
                                return E_SS_WRITE_ERROR;
                        }
-               }
-               else{
-                       LOGE("Move failed, error code [%d]",errno);
+               } else {
+                       LOGE("Move failed, error code [%d]", errno);
                        return E_SS_WRITE_ERROR;
                }
        }
@@ -595,7 +589,7 @@ SS_Link(void *pbUserData, char *pLinkName, char *pReferenceFileName)
 
        ret = symlink(refpath, sympath);
        if (ret != 0) {
-               LOGE(" symlink failed with return value: %d, errno: %d\n", ret,errno);
+               LOGE(" symlink failed with return value: %d, errno: %d\n", ret, errno);
 
                if (errno == EEXIST) {
                        ret = lstat(sympath, &sbuf);
@@ -603,21 +597,21 @@ SS_Link(void *pbUserData, char *pLinkName, char *pReferenceFileName)
                        if (ret >= 0) {
                                        if (S_ISREG(sbuf.st_mode)) {
                                        LOGL(LOG_SSENGINE, " stat->st_mode = regular file, To be deleted and create a LINK \n");
-                                       SS_DeleteFile(pbUserData,sympath);
+                                       SS_DeleteFile(pbUserData, sympath);
                                        SS_Link(pbUserData, pLinkName, pReferenceFileName);
                                        }
                                }
                        if (SS_VerifyLinkReference(pbUserData, pLinkName
                                , pReferenceFileName) == S_SS_SUCCESS) {
                                return S_SS_SUCCESS;
-                       }
-                       else
+                       } else {
                                return E_SS_FAILURE;
-               }
-               else if(errno == ENOENT )//to handle cases where new symlink points to a new symlink yet to be created
+                       }
+               } else if (errno == ENOENT) {//to handle cases where new symlink points to a new symlink yet to be created
                        return errno;
-               else
+               } else {
                        return E_SS_FAILURE;
+               }
        }
        //LOGL(LOG_SSENGINE, "symlink with return value: %d\n", ret);
 
@@ -829,12 +823,10 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                                        LOGL(LOG_SSENGINE, " stat->st_mode = symbolic link file\n");
 //        return S_RB_SUCCESS; // sybolic link should be set mode.
                                }
-                               if (S_ISREG(sbuf.st_mode)) {
+                               if (S_ISREG(sbuf.st_mode))
                                        LOGL(LOG_SSENGINE, " stat->st_mode = regular file\n");
-                               }
-                               if (S_ISDIR(sbuf.st_mode)) {
+                               if (S_ISDIR(sbuf.st_mode))
                                        LOGL(LOG_SSENGINE, " stat->st_mode = directory\n");
-                               }
                }
 
                LOGL(LOG_SSENGINE, "ui16pFilePath = %s\n", setFilePath);
@@ -875,7 +867,7 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                        char *cap_mark = "capability=0x";
                        int cap_mark_len = strlen(cap_mark);
                        psmack = strstr(smack_attr_pos, cap_mark);
-                       if(psmack) {
+                       if (psmack) {
                                int cap_hex_len;
                                int i;
                                char ch1, ch2;
@@ -891,16 +883,16 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                                cap_hex_len = strlen(tmpSmackAttribs);
                                cap_len = cap_hex_len/2;
                                memset(cap_raw, 0x00, sizeof(cap_raw));
-                               for (i=0; i<cap_len; i++) {
+                               for (i = 0; i < cap_len; i++) {
                                        ch1 = tmpSmackAttribs[i*2];
                                        ch2 = tmpSmackAttribs[i*2+1];
-                                       if ((ch1 >= '0')&&(ch1 <= '9'))         raw1 = ch1 - '0';
-                                       else if ((ch1 >= 'a')&&(ch1 <= 'f'))            raw1 = ch1 - 'a' + 10;
-                                       else if ((ch1 >= 'A')&&(ch1 <= 'F'))            raw1 = ch1 - 'A' + 10;
+                                       if ((ch1 >= '0') && (ch1 <= '9'))               raw1 = ch1 - '0';
+                                       else if ((ch1 >= 'a') && (ch1 <= 'f'))          raw1 = ch1 - 'a' + 10;
+                                       else if ((ch1 >= 'A') && (ch1 <= 'F'))          raw1 = ch1 - 'A' + 10;
                                        else raw1 = 0;
-                                       if ((ch2 >= '0')&&(ch2 <= '9'))         raw2 = ch2 - '0';
-                                       else if ((ch2 >= 'a')&&(ch2 <= 'f'))            raw2 = ch2 - 'a' + 10;
-                                       else if ((ch2 >= 'A')&&(ch2 <= 'F'))            raw2 = ch2 - 'A' + 10;
+                                       if ((ch2 >= '0') && (ch2 <= '9'))               raw2 = ch2 - '0';
+                                       else if ((ch2 >= 'a') && (ch2 <= 'f'))          raw2 = ch2 - 'a' + 10;
+                                       else if ((ch2 >= 'A') && (ch2 <= 'F'))          raw2 = ch2 - 'A' + 10;
                                        else raw2 = 0;
 
                                        cap_raw[i] = raw1*16 + raw2;
@@ -916,7 +908,7 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                        char *acl_mark = "acl_access=0x";
                        int acl_mark_len = strlen(acl_mark);
                        psmack = strstr(smack_attr_pos, acl_mark);
-                       if(psmack) {
+                       if (psmack) {
                                int acl_hex_len;
                                int i;
                                char ch1, ch2;
@@ -932,16 +924,16 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                                acl_hex_len = strlen(tmpSmackAttribs);
                                acl_len = acl_hex_len/2;
                                memset(acl_raw, 0x00, sizeof(acl_raw));
-                               for (i=0; i<acl_len; i++) {
+                               for (i = 0; i < acl_len; i++) {
                                        ch1 = tmpSmackAttribs[i*2];
                                        ch2 = tmpSmackAttribs[i*2+1];
-                                       if ((ch1 >= '0')&&(ch1 <= '9'))         raw1 = ch1 - '0';
-                                       else if ((ch1 >= 'a')&&(ch1 <= 'f'))            raw1 = ch1 - 'a' + 10;
-                                       else if ((ch1 >= 'A')&&(ch1 <= 'F'))            raw1 = ch1 - 'A' + 10;
+                                       if ((ch1 >= '0') && (ch1 <= '9'))               raw1 = ch1 - '0';
+                                       else if ((ch1 >= 'a') && (ch1 <= 'f'))          raw1 = ch1 - 'a' + 10;
+                                       else if ((ch1 >= 'A') && (ch1 <= 'F'))          raw1 = ch1 - 'A' + 10;
                                        else raw1 = 0;
-                                       if ((ch2 >= '0')&&(ch2 <= '9'))         raw2 = ch2 - '0';
-                                       else if ((ch2 >= 'a')&&(ch2 <= 'f'))            raw2 = ch2 - 'a' + 10;
-                                       else if ((ch2 >= 'A')&&(ch2 <= 'F'))            raw2 = ch2 - 'A' + 10;
+                                       if ((ch2 >= '0') && (ch2 <= '9'))               raw2 = ch2 - '0';
+                                       else if ((ch2 >= 'a') && (ch2 <= 'f'))          raw2 = ch2 - 'a' + 10;
+                                       else if ((ch2 >= 'A') && (ch2 <= 'F'))          raw2 = ch2 - 'A' + 10;
                                        else raw2 = 0;
 
                                        acl_raw[i] = raw1*16 + raw2;
@@ -961,14 +953,14 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                smack_lsetlabel(setFilePath, NULL, SMACK_LABEL_TRANSMUTE);
 
                psmack = strstr(smack_attr_pos, "access=\"");
-               if(psmack) {
+               if (psmack) {
                        memset(tmpSmackAttribs, 0x0, sizeof(tmpSmackAttribs));
                        memcpy(tmpSmackAttribs, psmack, strlen(psmack));
                        smack_value = strtok_r(tmpSmackAttribs, "\"", &saveptr);
                        if (smack_value) {
                                smack_value = strtok_r(NULL, "\"", &saveptr);
                                //LOGL(LOG_SSENGINE, "[SMACK_LABEL_ACCESS] smack_value=%s\n", smack_value);
-                               if(smack_value) {
+                               if (smack_value) {
                                        ret = smack_lsetlabel(setFilePath, smack_value, SMACK_LABEL_ACCESS);
                                        if (ret < 0)
                                                LOGL(LOG_SSENGINE, "smack_lsetlabel() failed\n");
@@ -976,14 +968,14 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                        }
                }
                psmack = strstr(smack_attr_pos, "execute=\"");
-               if(psmack) {
+               if (psmack) {
                        memset(tmpSmackAttribs, 0x0, sizeof(tmpSmackAttribs));
                        memcpy(tmpSmackAttribs, psmack, strlen(psmack));
                        smack_value = strtok_r(tmpSmackAttribs, "\"", &saveptr);
                        if (smack_value) {
                                smack_value = strtok_r(NULL, "\"", &saveptr);
                                //LOGL(LOG_SSENGINE, "[SMACK_LABEL_EXEC] smack_value=%s\n", smack_value);
-                               if(smack_value) {
+                               if (smack_value) {
                                        ret = smack_lsetlabel(setFilePath, smack_value, SMACK_LABEL_EXEC);
                                        if (ret < 0)
                                                LOGL(LOG_SSENGINE, "smack_lsetlabel() failed\n");
@@ -991,14 +983,14 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                        }
                }
                psmack = strstr(smack_attr_pos, "mmap=\"");
-               if(psmack) {
+               if (psmack) {
                        memset(tmpSmackAttribs, 0x0, sizeof(tmpSmackAttribs));
                        memcpy(tmpSmackAttribs, psmack, strlen(psmack));
                        smack_value = strtok_r(tmpSmackAttribs, "\"", &saveptr);
                        if (smack_value) {
                                smack_value = strtok_r(NULL, "\"", &saveptr);
                                //LOGL(LOG_SSENGINE, "[SMACK_LABEL_MMAP] smack_value=%s\n", smack_value);
-                               if(smack_value) {
+                               if (smack_value) {
                                        ret = smack_lsetlabel(setFilePath, smack_value, SMACK_LABEL_MMAP);
                                        if (ret < 0)
                                                LOGL(LOG_SSENGINE, "smack_lsetlabel() failed\n");
@@ -1006,19 +998,18 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
                        }
                }
                psmack = strstr(smack_attr_pos, "transmute=\"");
-               if(psmack) {
+               if (psmack) {
                        memset(tmpSmackAttribs, 0x0, sizeof(tmpSmackAttribs));
                        memcpy(tmpSmackAttribs, psmack, strlen(psmack));
                        smack_value = strtok_r(tmpSmackAttribs, "\"", &saveptr);
                        if (smack_value) {
                                smack_value = strtok_r(NULL, "\"", &saveptr);
                                //LOGL(LOG_SSENGINE, "[SMACK_LABEL_TRANSMUTE] smack_value=%s\n", smack_value);
-                               if(smack_value) {
-                                       if (strcasecmp(smack_value, "TRUE")==0) {
+                               if (smack_value) {
+                                       if (strcasecmp(smack_value, "TRUE") == 0)
                                                ret = smack_lsetlabel(setFilePath, "1", SMACK_LABEL_TRANSMUTE);
-                                       } else {
+                                       else
                                                ret = smack_lsetlabel(setFilePath, "0", SMACK_LABEL_TRANSMUTE);
-                                       }
                                        if (ret < 0)
                                                LOGL(LOG_SSENGINE, "smack_lsetlabel() failed\n");
                                }
@@ -1105,20 +1096,18 @@ SS_GetAvailableFreeSpace(void *pbUserData, const char *partition_name,
 
        //LOGL(LOG_SSENGINE, "path=%s\n", path);
        result = statfs(path, &vfs);
-       if (result < 0 )
-       {
+       if (result < 0) {
                LOGE("failed to fstatfs, err : %d errno: %d\n", result, errno);
                return -1;
        }
 
        *available_flash_size = vfs.f_bsize * vfs.f_bavail;
-       if(*available_flash_size == 0)
-               {
+       if (*available_flash_size == 0) {
                *available_flash_size = 0x80000; //Same as Legecy RB
-       LOGE("available_flash_size=%u(vfs.f_bsize=%d vfs.f_bavail=%d\n",
-               (unsigned int)*available_flash_size, (int)vfs.f_bsize, (int)vfs.f_bavail);
-                       return 0; // Same as Legecy RB
-               }
+               LOGE("available_flash_size=%u(vfs.f_bsize=%d vfs.f_bavail=%d\n",
+                               (unsigned int)*available_flash_size, (int)vfs.f_bsize, (int)vfs.f_bavail);
+               return 0; // Same as Legecy RB
+       }
        return 0;
 }
 
@@ -1135,9 +1124,9 @@ void *SS_Malloc(SS_UINT32 size)
                memset(p, 0, size);
 #ifdef HEAP_PROFILING
        cur_mem += size;
-       if(cur_mem > max_mem ){
+       if (cur_mem > max_mem) {
                max_mem = cur_mem;
-               LOGL(LOG_SSENGINE,"New chunk [%d] assigned making heap [%d]\n",size,cur_mem);
+               LOGL(LOG_SSENGINE, "New chunk [%d] assigned making heap [%d]\n", size, cur_mem);
        }
 #endif
 
@@ -1148,9 +1137,9 @@ void SS_Free(void *pMemBlock)
 {
 #ifdef HEAP_PROFILING
        cur_mem -= malloc_usable_size(pMemBlock);
-       LOGL(LOG_SSENGINE,"Old chunk [%d] removed making heap [%d]\n",malloc_usable_size(pMemBlock),cur_mem);
+       LOGL(LOG_SSENGINE, "Old chunk [%d] removed making heap [%d]\n", malloc_usable_size(pMemBlock), cur_mem);
 #endif
-       if(pMemBlock)
+       if (pMemBlock)
                free(pMemBlock);
 }
 
@@ -1178,13 +1167,12 @@ void* SS_WaitForProcess(const void *handle, SS_UINT32* process_exit_code)
        if (pid < 0)
                return NULL;
 
-       if (!WIFEXITED(*process_exit_code))
-       {
+       if (!WIFEXITED(*process_exit_code)) {
                *process_exit_code = (char)WTERMSIG(*process_exit_code);
                LOG("Wait Error\n");
-       }
-       else
+       } else {
                *process_exit_code = (char)WEXITSTATUS(*process_exit_code);
+       }
 
        return (void*)pid;
 }
@@ -1209,8 +1197,7 @@ void* SS_RunProcess(void *pbUserData, int argc, char* argv[])
        }
 
        // This is the child
-       if (child_pid == 0)
-       {
+       if (child_pid == 0) {
                #ifdef _NOEXEC_
                #ifdef _TIZEN_SSENGINE//bota
                SS_HandleProcessRequest(pbUserData, argc, argv);
@@ -1223,8 +1210,7 @@ void* SS_RunProcess(void *pbUserData, int argc, char* argv[])
                int i;
 
                params = (char **)SS_Malloc((argc+EXTRA_ARGS) *sizeof(char*));
-               if (!params)
-               {
+               if (!params) {
                        LOG("params allocation failed\n");
                        return NULL;
                }
@@ -1233,16 +1219,14 @@ void* SS_RunProcess(void *pbUserData, int argc, char* argv[])
                params[1] = strdup("handle_run_process");
                params[2] = strdup(((sample_userdata*)user)->delta_path);
 
-               for (i=0; i < argc; i++)
+               for (i = 0; i < argc; i++)
                        params[i+EXTRA_ARGS] = strdup(argv[i]);
 
                // no need to free allocated memory - execv takes care of it
                execv(params[0], (char**)params);
                _exit(-1); // if we're here, execv has failed
                #endif
-       }
-       else
-       {
+       } else {
                return (void *)child_pid;
        }
 }
index 3bc4e88..49eda03 100755 (executable)
@@ -36,11 +36,11 @@ extern "C" {
 /*!
  * File access modes
  */
-    typedef enum tag_RW_TYPE {
-        ONLY_R,                 //!< Read-only
-        ONLY_W,                 //!< Write-only
-        BOTH_RW                 //!< Read-write
-    } E_RW_TYPE;
+       typedef enum tag_RW_TYPE {
+               ONLY_R,                 //!< Read-only
+               ONLY_W,                 //!< Write-only
+               BOTH_RW                 //!< Read-write
+       } E_RW_TYPE;
 
 /*!
  *******************************************************************************
@@ -59,7 +59,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_CopyFile(void *pbUserData, const char *strFromPath, const char *strToPath);
+       long SS_CopyFile(void *pbUserData, const char *strFromPath, const char *strToPath);
 
 /*!
  *******************************************************************************
@@ -74,7 +74,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_MoveFile(void *pbUserData, const char *strFromPath, const char *strToPath);
+       long SS_MoveFile(void *pbUserData, const char *strFromPath, const char *strToPath);
 
 /*!
  *******************************************************************************
@@ -91,7 +91,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_DeleteFile(void *pbUserData, const char *strPath);
+       long SS_DeleteFile(void *pbUserData, const char *strPath);
 
 /*!
  *******************************************************************************
@@ -107,7 +107,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_DeleteFolder(void *pbUserData, const char *strPath);
+       long SS_DeleteFolder(void *pbUserData, const char *strPath);
 
 /*!
  *******************************************************************************
@@ -125,7 +125,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_CreateFolder(void *pbUserData, const char *strPath);
+       long SS_CreateFolder(void *pbUserData, const char *strPath);
 
 /*!
  *******************************************************************************
@@ -146,7 +146,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_OpenFile(void *pbUserData, const char *strPath, E_RW_TYPE wFlag, long *pwHandle);
+       long SS_OpenFile(void *pbUserData, const char *strPath, E_RW_TYPE wFlag, long *pwHandle);
 
 /*!
  *******************************************************************************
@@ -161,7 +161,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_ResizeFile(void *pbUserData, long wHandle, SS_UINT32 dwSize);
+       long SS_ResizeFile(void *pbUserData, long wHandle, SS_UINT32 dwSize);
 
 /*!
  *******************************************************************************
@@ -175,7 +175,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_CloseFile(void *pbUserData, long wHandle);
+       long SS_CloseFile(void *pbUserData, long wHandle);
 
 /*!
  *******************************************************************************
@@ -195,7 +195,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_WriteFile(void *pbUserData, long wHandle, SS_UINT32 dwPosition, unsigned char *pbBuffer, SS_UINT32 dwSize);
+       long SS_WriteFile(void *pbUserData, long wHandle, SS_UINT32 dwPosition, unsigned char *pbBuffer, SS_UINT32 dwSize);
 
 /*!
  *******************************************************************************
@@ -210,7 +210,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_SyncFile(void *pbUserData, long wHandle);
+       long SS_SyncFile(void *pbUserData, long wHandle);
 
 /*!
  *******************************************************************************
@@ -229,7 +229,7 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_ReadFile(void *pbUserData, long wHandle, SS_UINT32 dwPosition, unsigned char *pbBuffer, SS_UINT32 dwSize);
+       long SS_ReadFile(void *pbUserData, long wHandle, SS_UINT32 dwPosition, unsigned char *pbBuffer, SS_UINT32 dwSize);
 
 /*!
  *******************************************************************************
@@ -242,7 +242,7 @@ extern "C" {
  * \return     File size, -1 if file not found, or &lt; -1 on error
  *******************************************************************************
  */
-    long SS_GetFileSize(void *pbUserData, long wHandle);
+       long SS_GetFileSize(void *pbUserData, long wHandle);
 
 /*!
  *******************************************************************************
@@ -257,7 +257,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_GetAvailableFreeSpace(void *pbUserData, const char *path, SS_UINT32 * available_flash_size);
+       long SS_GetAvailableFreeSpace(void *pbUserData, const char *path, SS_UINT32 * available_flash_size);
 
 /*!
  *******************************************************************************
@@ -275,7 +275,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_Unlink(void *pbUserData, char *pLinkName);
+       long SS_Unlink(void *pbUserData, char *pLinkName);
 
 /*!
  *******************************************************************************
@@ -297,7 +297,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_Link(void *pbUserData, char *pLinkName, char *pReferenceFileName);
+       long SS_Link(void *pbUserData, char *pLinkName, char *pReferenceFileName);
 
 /*!
  *******************************************************************************
@@ -320,8 +320,8 @@ extern "C" {
  *******************************************************************************
  */
 
-    long SS_SetFileAttributes(const char *ui16pFilePath,
-                              const SS_UINT32 ui32AttribSize, const unsigned char *ui8pAttribs);
+       long SS_SetFileAttributes(const char *ui16pFilePath,
+                       const SS_UINT32 ui32AttribSize, const unsigned char *ui8pAttribs);
 
 /*!
  *******************************************************************************
@@ -340,8 +340,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    SS_UINT32 SS_Trace(void *pbUserData, const char *aFormat, ...
-        );
+       SS_UINT32 SS_Trace(void *pbUserData, const char *aFormat, ...);
 
 /**
  *******************************************************************************
@@ -352,16 +351,16 @@ extern "C" {
  * \return     A pointer to the memory block on success, NULL on failure
  *******************************************************************************
  */
-    void *SS_Malloc(SS_UINT32 size);
+       void *SS_Malloc(SS_UINT32 size);
 
 /**
  *******************************************************************************
  * Free a memory block.
  *
- * \param      pMemBlock       Pointer to the memory block
+ * \param      pMemBlock       Pointer to the memory block
  *******************************************************************************
  */
-    void SS_Free(void *pMemBlock);
+       void SS_Free(void *pMemBlock);
 
 /**
  *******************************************************************************
@@ -370,7 +369,7 @@ extern "C" {
  * \return     The value of feature_support_capability
  *******************************************************************************
  */
-    int SS_get_feature_support_capability(void);
+       int SS_get_feature_support_capability(void);
 
 /**
  *******************************************************************************
@@ -379,7 +378,7 @@ extern "C" {
  * \param      val     The value to set feature_support_capability
  *******************************************************************************
  */
-    void SS_set_feature_support_capability(int val);
+       void SS_set_feature_support_capability(int val);
 
 #ifdef __cplusplus
 }
index 2923b71..2b9b773 100755 (executable)
@@ -45,7 +45,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_ReadBackupBlock(void *pbUserData, unsigned char *pbBuffer, SS_UINT32 dwBlockAddress, SS_UINT32 dwSize);
+       long SS_ReadBackupBlock(void *pbUserData, unsigned char *pbBuffer, SS_UINT32 dwBlockAddress, SS_UINT32 dwSize);
 
 /**
  *******************************************************************************
@@ -65,7 +65,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_EraseBackupBlock(void *pbUserData, SS_UINT32 dwStartAddress);
+       long SS_EraseBackupBlock(void *pbUserData, SS_UINT32 dwStartAddress);
 
 /**
  *******************************************************************************
@@ -82,7 +82,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_WriteBackupBlock(void *pbUserData, SS_UINT32 dwBlockStartAddress, unsigned char *pbBuffer);
+       long SS_WriteBackupBlock(void *pbUserData, SS_UINT32 dwBlockStartAddress, unsigned char *pbBuffer);
 
 /**
  *******************************************************************************
@@ -106,8 +106,8 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_WriteBackupPartOfBlock(void *pbUserData,
-                                   SS_UINT32 dwStartAddress, SS_UINT32 dwSize, unsigned char *pbBuffer);
+       long SS_WriteBackupPartOfBlock(void *pbUserData,
+                       SS_UINT32 dwStartAddress, SS_UINT32 dwSize, unsigned char *pbBuffer);
 
 /**
  *******************************************************************************
@@ -124,7 +124,7 @@ extern "C" {
  *                     or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_WriteBlock(void *pbUserData, SS_UINT32 dwBlockAddress, unsigned char *pbBuffer);
+       long SS_WriteBlock(void *pbUserData, SS_UINT32 dwBlockAddress, unsigned char *pbBuffer);
 
 /**
  *******************************************************************************
@@ -142,9 +142,9 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_ReadImage(void *pbUserData, unsigned char *pbBuffer,        /* pointer to user buffer */
-                      SS_UINT32 dwStartAddress, /* memory address to read from */
-                      SS_UINT32 dwSize);        /* number of bytes to copy */
+       long SS_ReadImage(void *pbUserData, unsigned char *pbBuffer,        /* pointer to user buffer */
+                       SS_UINT32 dwStartAddress, /* memory address to read from */
+                       SS_UINT32 dwSize);        /* number of bytes to copy */
 
 /**
  *******************************************************************************
@@ -166,7 +166,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
  *******************************************************************************
  */
-    long SS_ReadImageNewKey(void *pbUserData, unsigned char *pbBuffer, SS_UINT32 dwStartAddress, SS_UINT32 dwSize);
+       long SS_ReadImageNewKey(void *pbUserData, unsigned char *pbBuffer, SS_UINT32 dwStartAddress, SS_UINT32 dwSize);
 
 /**
  *******************************************************************************
@@ -178,7 +178,7 @@ extern "C" {
  * \return     Sector size, in bytes
  *******************************************************************************
  */
-    long SS_GetBlockSize(void *pbUserData);
+       long SS_GetBlockSize(void *pbUserData);
 
 #ifdef __cplusplus
 }
index 73a0d75..e0cfa12 100755 (executable)
  * To use the UPI with multi-process support you should implement the following
  * Porting Layer functions:
  *             SS_Malloc
- *             SS_Free
- *             SS_WaitForProcess
- *             SS_RunProcess
- *             SS_GetMaxNumProcess
- *             SS_GetMaxProcRamSize
+ *             SS_Free
+ *             SS_WaitForProcess
+ *             SS_RunProcess
+ *             SS_GetMaxNumProcess
+ *             SS_GetMaxProcRamSize
  *
  * The function SS_RunProcess must run a sub-process (optionally the same
  * executable running the main process) that is also integrated with the UPI.
@@ -58,9 +58,9 @@
  *             for SS_Trace, these preparations must be done before calling
  *             SS_HandleProcessRequests.
  * \li  To distinguish between processes when running in Multi-Process Update mode,
- *             it is recommended that you add the Process ID (i.e. getpid()) to the log
- *             output in SS_Trace. Alternatively, create a log file for each sub-process
- *             named log_file.[pid]
+ *             it is recommended that you add the Process ID (i.e. getpid()) to the log
+ *             output in SS_Trace. Alternatively, create a log file for each sub-process
+ *             named log_file.[pid]
  * \li If your implementation uses the optional opaque data structure ('user'
  *             in the functions below), you may also have to pass it to sub-processes.
  *             You must implement this functionality.
@@ -85,16 +85,16 @@ extern "C" {
  * \return     A pointer to the memory block on success, NULL on failure
  *******************************************************************************
  */
-    void *SS_Malloc(SS_UINT32 size);
+       void *SS_Malloc(SS_UINT32 size);
 
 /**
  *******************************************************************************
  * Free a memory block.
  *
- * \param      pMemBlock       Pointer to the memory block
+ * \param      pMemBlock       Pointer to the memory block
  *******************************************************************************
  */
-    void SS_Free(void *pMemBlock);
+       void SS_Free(void *pMemBlock);
 
 /**
  *******************************************************************************
@@ -107,7 +107,7 @@ extern "C" {
  * \return     Handle of the completed process or NULL on error
  *******************************************************************************
  */
-    void *SS_WaitForProcess(const void *handle, SS_UINT32 * process_exit_code);
+       void *SS_WaitForProcess(const void *handle, SS_UINT32 * process_exit_code);
 
 /**
  *******************************************************************************
@@ -124,7 +124,7 @@ extern "C" {
  * \return     Handle to the new process or NULL on error
  *******************************************************************************
  */
-    void *SS_RunProcess(void *user, int argc, char *argv[]);
+       void *SS_RunProcess(void *user, int argc, char *argv[]);
 
 /**
  *******************************************************************************
@@ -137,7 +137,7 @@ extern "C" {
  *                     allowed
  *******************************************************************************
  */
-    SS_UINT32 SS_GetMaxNumProcess(void *user);
+       SS_UINT32 SS_GetMaxNumProcess(void *user);
 /**
  *******************************************************************************
  * Get the maximum available memory for processes to use.
@@ -148,7 +148,7 @@ extern "C" {
  * \return     The memory amount available for processes or 0 if there is no available memory
  *******************************************************************************
  */
-    unsigned long SS_GetMaxProcRamSize(void *user);
+       unsigned long SS_GetMaxProcRamSize(void *user);
 
 /**
  *******************************************************************************
@@ -166,7 +166,7 @@ extern "C" {
  * \return     S_SS_SUCCESS on success or an error code
  *******************************************************************************
  */
-    long SS_HandleProcessRequest(void *user, int argc, char *argv[]);
+       long SS_HandleProcessRequest(void *user, int argc, char *argv[]);
 
 #ifdef __cplusplus
 }
index 49180a4..3395881 100755 (executable)
@@ -7,7 +7,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 extern void *SS_Malloc(unsigned int size);
 
 typedef struct {
-    unsigned char *buffer;
-    ssize_t size;
-    ssize_t pos;
+       unsigned char *buffer;
+       ssize_t size;
+       ssize_t pos;
 } MemorySinkInfo;
 
 ssize_t ss_memorySink(unsigned char *data, ssize_t len, void *token)
 {
-    MemorySinkInfo *msi = (MemorySinkInfo *) token;
-    if (msi->size - msi->pos < len) {
-        return -1;
-    }
-    memcpy(msi->buffer + msi->pos, data, len);
-    msi->pos += len;
-    return len;
+       MemorySinkInfo *msi = (MemorySinkInfo *) token;
+       if (msi->size - msi->pos < len)
+               return -1;
+       memcpy(msi->buffer + msi->pos, data, len);
+       msi->pos += len;
+       return len;
 }
 
 ssize_t ss_fileSink(unsigned char *data, ssize_t len, void *token)
 {
-    int ss_fd = *(int *)token;
-    char buf[256];
-    ssize_t done = 0;
-    ssize_t wrote;
-    while (done < (ssize_t) len) {
-        wrote = write(ss_fd, data + done, len - done);
-        if (wrote <= 0) {
-            if (errno == EINTR || errno == EAGAIN)
-                continue;       // try again
-           strerror_r(errno, buf, sizeof(buf));
-            LOGE("error writing %d bytes: %s\n", (int)(len - done), buf);
-            return done;
-        }
-        done += wrote;
-    }
-    return done;
+       int ss_fd = *(int *)token;
+       char buf[256];
+       ssize_t done = 0;
+       ssize_t wrote;
+       while (done < (ssize_t) len) {
+               wrote = write(ss_fd, data + done, len - done);
+               if (wrote <= 0) {
+                       if (errno == EINTR || errno == EAGAIN)
+                               continue;          // try again
+               strerror_r(errno, buf, sizeof(buf));
+                       LOGE("error writing %d bytes: %s\n", (int)(len - done), buf);
+                       return done;
+               }
+               done += wrote;
+       }
+       return done;
 }
 
 // Take a string 'str' of 40 hex digits and parse it into the 20
@@ -77,142 +76,140 @@ ssize_t ss_fileSink(unsigned char *data, ssize_t len, void *token)
 // error.
 int ParseSha1(const char *str, uint8_t * digest)
 {
-    int i;
-    const char *ps = str;
-    uint8_t *pd = digest;
-    for (i = 0; i < SHA_DIGEST_SIZE * 2; ++i, ++ps) {
-        int digit;
-        if (*ps >= '0' && *ps <= '9') {
-            digit = *ps - '0';
-        } else if (*ps >= 'a' && *ps <= 'f') {
-            digit = *ps - 'a' + 10;
-        } else if (*ps >= 'A' && *ps <= 'F') {
-            digit = *ps - 'A' + 10;
-        } else {
-            return -1;
-        }
-        if (i % 2 == 0) {
-            *pd = digit << 4;
-        } else {
-            *pd |= digit;
-            ++pd;
-        }
-    }
-    if (*ps != '\0')
-        return -1;
-    return 0;
+       int i;
+       const char *ps = str;
+       uint8_t *pd = digest;
+       for (i = 0; i < SHA_DIGEST_SIZE * 2; ++i, ++ps) {
+               int digit;
+               if (*ps >= '0' && *ps <= '9')
+                       digit = *ps - '0';
+               else if (*ps >= 'a' && *ps <= 'f')
+                       digit = *ps - 'a' + 10;
+               else if (*ps >= 'A' && *ps <= 'F')
+                       digit = *ps - 'A' + 10;
+               else
+                       return -1;
+               if (i % 2 == 0) {
+                       *pd = digit << 4;
+               } else {
+                       *pd |= digit;
+                       ++pd;
+               }
+       }
+       if (*ps != '\0')
+               return -1;
+       return 0;
 }
 
 //Function to find the start of gzipped part in compressed kernel
 int getOffset(char *zimage_path)
 {
-    char gzip_header[] = { 31, -117, 8 };       //header value for gzip which needs to be checked
-    char buf[4] = { 0, };
-    int offset = 0;//wgid:14074
-
-    FILE *f = fopen(zimage_path, "r");
-    if(!f){
-        LOGE("Fopen failed for path %s\n", zimage_path);
-        SS_SetUpgradeState(E_SS_OPENFILE_ONLYR);
-        return -1;
-    }
-    fseek(f, 0, SEEK_SET);
-    while (fread(buf, 1, 3, f) > 0) {
-        if (gzip_header[0] == buf[0] && gzip_header[1] == buf[1] && gzip_header[2] == buf[2]) {
-            LOGL(LOG_SSENGINE, "match for %d %d %d found at %d\n", buf[0], buf[1], buf[2], ftell(f) - 3);
-            break;
-        } else {
-            fseek(f, -2, SEEK_CUR);
-        }
-    }
-    offset = ftell(f) - 3;
-    fclose(f);
-    return offset;
+       char gzip_header[] = { 31, -117, 8 };      //header value for gzip which needs to be checked
+       char buf[4] = { 0, };
+       int offset = 0;//wgid:14074
+
+       FILE *f = fopen(zimage_path, "r");
+       if (!f) {
+               LOGE("Fopen failed for path %s\n", zimage_path);
+               SS_SetUpgradeState(E_SS_OPENFILE_ONLYR);
+               return -1;
+       }
+       fseek(f, 0, SEEK_SET);
+       while (fread(buf, 1, 3, f) > 0) {
+               if (gzip_header[0] == buf[0] && gzip_header[1] == buf[1] && gzip_header[2] == buf[2]) {
+                       LOGL(LOG_SSENGINE, "match for %d %d %d found at %d\n", buf[0], buf[1], buf[2], ftell(f) - 3);
+                       break;
+               } else {
+                       fseek(f, -2, SEEK_CUR);
+               }
+       }
+       offset = ftell(f) - 3;
+       fclose(f);
+       return offset;
 }
 
 int SS_LoadPartition(const char *filename, FileInfo * file)
 {
-    size_t read = 0;
-    FILE *dev = NULL;
-    int i;
-    char buf[256];
-
-    dev = fopen(filename, "rb");
-    if (dev == NULL) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("failed to open partition \"%s\": %s\n", filename, buf);
-        return -1;
-    }
-
-    sha1_ctx_t sha_ctx;
-    sha1_init(&sha_ctx);
-
-    file->data = SS_Malloc(file->size);
-    if (file->data) {
-        read = fread(file->data, 1, file->size, dev);
-        LOGL(LOG_SSENGINE, "Partition size read %d\n", read);
-        sha1_update(&sha_ctx, file->data, read);
-        file->size = read;
-    }
-
-    const uint8_t sha_final[SHA_DIGEST_SIZE] = { 0, };
-    sha1_final(&sha_ctx, (uint32_t *) & sha_final);
-    for (i = 0; i < SHA_DIGEST_SIZE; ++i) {
-        file->sha1[i] = sha_final[i];
-    }
-    //LOGL(LOG_SSENGINE, "Final SHA of Source (%s)\n", sha_final);
-
-    file->st.st_mode = 0644;
-    file->st.st_uid = 0;
-    file->st.st_gid = 0;
-    fclose(dev);
-    return 0;
+       size_t read = 0;
+       FILE *dev = NULL;
+       int i;
+       char buf[256];
+
+       dev = fopen(filename, "rb");
+       if (dev == NULL) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("failed to open partition \"%s\": %s\n", filename, buf);
+               return -1;
+       }
+
+       sha1_ctx_t sha_ctx;
+       sha1_init(&sha_ctx);
+
+       file->data = SS_Malloc(file->size);
+       if (file->data) {
+               read = fread(file->data, 1, file->size, dev);
+               LOGL(LOG_SSENGINE, "Partition size read %d\n", read);
+               sha1_update(&sha_ctx, file->data, read);
+               file->size = read;
+       }
+
+       const uint8_t sha_final[SHA_DIGEST_SIZE] = { 0, };
+       sha1_final(&sha_ctx, (uint32_t *) & sha_final);
+       for (i = 0; i < SHA_DIGEST_SIZE; ++i)
+               file->sha1[i] = sha_final[i];
+       //LOGL(LOG_SSENGINE, "Final SHA of Source (%s)\n", sha_final);
+
+       file->st.st_mode = 0644;
+       file->st.st_uid = 0;
+       file->st.st_gid = 0;
+       fclose(dev);
+       return 0;
 }
 
 //extern int write_data_to_blkdev(char* dev_name, int blk_start, int blk_cnt, char* data);
 
 int SS_LoadFile(const char *filename, FileInfo * file)
 {
-    char buf[256];
-
-    file->data = NULL;
-    //LOGL(LOG_SSENGINE,"SS_LoadFile --- [File name %s]\n",filename);
-
-    if (stat(filename, &file->st) != 0) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("failed to stat \"%s\": %s\n", filename, buf);
-        return -1;
-    }
-
-    file->size = file->st.st_size;
-    file->data = SS_Malloc(file->size);
-    if (!file->data) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("failed to allocate memory for \"%s\": %s\n", filename, buf);
-        return -1;
-    }
-
-    FILE *f = fopen(filename, "rb");
-    if (f == NULL) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("failed to open \"%s\": %s\n", filename, buf);
-        SS_Free(file->data);
-        file->data = NULL;
-        return -1;
-    }
-
-    ssize_t bytes_read = fread(file->data, 1, file->size, f);
-    if (bytes_read != file->size) {
-        LOGE("short read of \"%s\" (%ld bytes of %ld)\n", filename, (long)bytes_read, (long)file->size);
-        SS_Free(file->data);
-        file->data = NULL;
-        fclose(f);
-        return -1;
-    }
-    fclose(f);
-    //LOGL(LOG_SSENGINE,"SS_LoadFile --- [bytes_read %d]\n",bytes_read);
-    sha1(file->data, file->size, (uint32_t *) file->sha1);
-    return 0;
+       char buf[256];
+
+       file->data = NULL;
+       //LOGL(LOG_SSENGINE,"SS_LoadFile --- [File name %s]\n",filename);
+
+       if (stat(filename, &file->st) != 0) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("failed to stat \"%s\": %s\n", filename, buf);
+               return -1;
+       }
+
+       file->size = file->st.st_size;
+       file->data = SS_Malloc(file->size);
+       if (!file->data) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("failed to allocate memory for \"%s\": %s\n", filename, buf);
+               return -1;
+       }
+
+       FILE *f = fopen(filename, "rb");
+       if (f == NULL) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("failed to open \"%s\": %s\n", filename, buf);
+               SS_Free(file->data);
+               file->data = NULL;
+               return -1;
+       }
+
+       ssize_t bytes_read = fread(file->data, 1, file->size, f);
+       if (bytes_read != file->size) {
+               LOGE("short read of \"%s\" (%ld bytes of %ld)\n", filename, (long)bytes_read, (long)file->size);
+               SS_Free(file->data);
+               file->data = NULL;
+               fclose(f);
+               return -1;
+       }
+       fclose(f);
+       //LOGL(LOG_SSENGINE,"SS_LoadFile --- [bytes_read %d]\n",bytes_read);
+       sha1(file->data, file->size, (uint32_t *) file->sha1);
+       return 0;
 }
 
 extern int gvalid_session;
@@ -220,317 +217,314 @@ extern void create_dir(char *pathname, int mode);
 #ifdef SUPPORT_CONTAINER
 //unzip source archive , apply patch from extracted delta folder and repack the source archive
 int SS_UpdateArchive(ua_dataSS_t * ua_dataSS, const char *source_filename, const char *target_filename,
-                     const char *source_sha1_str, const char *target_sha1_str)
+                                        const char *source_sha1_str, const char *target_sha1_str)
 {
-    FILE *fp;
-    char *line = NULL, *token = NULL, *source_file = NULL, *new_file = NULL, *dir_to_create = NULL, *patch_file = NULL;
-    char patch_path_full[MAX_FILE_PATH] = { 0, };       //absolute path for patches
-    char source_path_full[MAX_FILE_PATH] = { 0, };      //absolute path for uncompressed source files
-    char target_path_full[MAX_FILE_PATH] = { 0, };
-    char patchlist[MAX_FILE_PATH] = { 0, };
-    char cmd[2 * MAX_FILE_PATH] = { 0, };
-    size_t len = 0, read = 0;
-    int result = S_SS_SUCCESS;
-    uint8_t target_sha1[SHA_DIGEST_SIZE];
-    uint8_t source_sha1[SHA_DIGEST_SIZE] = { 0, };
-    FileInfo source_data = { 0, };
-    int backupsrc = -1;
-    SinkFn sink = NULL;
-    void *tok = NULL;
-    int output = -1;
-    char *outname = NULL;
-
-    if (ParseSha1(target_sha1_str, target_sha1) != 0) {
-        LOGE("failed to parse tgt-sha1 \"%s\"\n", target_sha1_str);
-        return E_SS_FAILURE;
-    }
-
-    if (0 == gvalid_session) {
-        if (ParseSha1(source_sha1_str, source_sha1) != 0) {
-            LOGE("failed to parse tgt-sha1 \"%s\"\n", source_sha1_str);
-            return E_SS_FAILURE;
-        }
-        if (SS_LoadFile(source_filename, &source_data) == 0) {
-            if (memcmp(source_data.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Can be applied\n");
-                if (source_data.data)
-                    SS_Free(source_data.data);
-            } else if (memcmp(source_data.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Already applied\n");
-                if (source_data.data)
-                    SS_Free(source_data.data);
-                return S_SS_SUCCESS;
-            } else {
-                //Check for backup file SHA
-                SS_Free(source_data.data);
-                source_data.data = NULL;
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Source was currupted, Try loading from backup source\n");
-                if (SS_LoadFile(SS_BACKUP_SOURCE, &source_data) == 0) {
-                    if (memcmp(source_data.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                        if (SS_CopyFile(NULL, SS_BACKUP_SOURCE, source_filename) != 0) {
-                            LOGE("copy of backup to \"%s\" failed: %s\n", source_filename, strerror(errno));
-                            SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                            if (source_data.data)
-                                SS_Free(source_data.data);
-                            return E_SS_FAILURE;
-                        }
-                        LOGL(LOG_SSENGINE,
-                             "SS_UpdateDeltaFS - Patch Can be applied from using backup file as source\n");
-                    } else {
-                        SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
-                        if (source_data.data)
-                            SS_Free(source_data.data);
-                        return E_SS_FAILURE;
-                    }
-                } else {
-                    SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
-                    if (source_data.data)
-                        SS_Free(source_data.data);
-                    return E_SS_FAILURE;
-                }
-            }
-        } else {
-            LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Source was deleted, Try loading from backup source\n");
-            if (SS_LoadFile(SS_BACKUP_SOURCE, &source_data) == 0) {
-                if (memcmp(source_data.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                    if (SS_CopyFile(NULL, SS_BACKUP_SOURCE, source_filename) != 0) {
-                        LOGE("copy of backup to \"%s\" failed: %s\n", source_filename, strerror(errno));
-                        SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                        if (source_data.data)
-                            SS_Free(source_data.data);
-                        return E_SS_FAILURE;
-                    }
-                    LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Can be applied from using backup file as source\n");
-                } else {
-                    SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
-                    if (source_data.data)
-                        SS_Free(source_data.data);
-                    return E_SS_FAILURE;
-                }
-            } else {
-                SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
-                if (source_data.data)
-                    SS_Free(source_data.data);
-                return E_SS_FAILURE;
-            }
-        }
-    }
+       FILE *fp;
+       char *line = NULL, *token = NULL, *source_file = NULL, *new_file = NULL, *dir_to_create = NULL, *patch_file = NULL;
+       char patch_path_full[MAX_FILE_PATH] = { 0, };      //absolute path for patches
+       char source_path_full[MAX_FILE_PATH] = { 0, };    //absolute path for uncompressed source files
+       char target_path_full[MAX_FILE_PATH] = { 0, };
+       char patchlist[MAX_FILE_PATH] = { 0, };
+       char cmd[2 * MAX_FILE_PATH] = { 0, };
+       size_t len = 0, read = 0;
+       int result = S_SS_SUCCESS;
+       uint8_t target_sha1[SHA_DIGEST_SIZE];
+       uint8_t source_sha1[SHA_DIGEST_SIZE] = { 0, };
+       FileInfo source_data = { 0, };
+       int backupsrc = -1;
+       SinkFn sink = NULL;
+       void *tok = NULL;
+       int output = -1;
+       char *outname = NULL;
+
+       if (ParseSha1(target_sha1_str, target_sha1) != 0) {
+               LOGE("failed to parse tgt-sha1 \"%s\"\n", target_sha1_str);
+               return E_SS_FAILURE;
+       }
+
+       if (0 == gvalid_session) {
+               if (ParseSha1(source_sha1_str, source_sha1) != 0) {
+                       LOGE("failed to parse tgt-sha1 \"%s\"\n", source_sha1_str);
+                       return E_SS_FAILURE;
+               }
+               if (SS_LoadFile(source_filename, &source_data) == 0) {
+                       if (memcmp(source_data.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Can be applied\n");
+                               if (source_data.data)
+                                       SS_Free(source_data.data);
+                       } else if (memcmp(source_data.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Already applied\n");
+                               if (source_data.data)
+                                       SS_Free(source_data.data);
+                               return S_SS_SUCCESS;
+                       } else {
+                               //Check for backup file SHA
+                               SS_Free(source_data.data);
+                               source_data.data = NULL;
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Source was currupted, Try loading from backup source\n");
+                               if (SS_LoadFile(SS_BACKUP_SOURCE, &source_data) == 0) {
+                                       if (memcmp(source_data.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                                               if (SS_CopyFile(NULL, SS_BACKUP_SOURCE, source_filename) != 0) {
+                                                       LOGE("copy of backup to \"%s\" failed: %s\n", source_filename, strerror(errno));
+                                                       SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                                       if (source_data.data)
+                                                               SS_Free(source_data.data);
+                                                       return E_SS_FAILURE;
+                                               }
+                                               LOGL(LOG_SSENGINE,
+                                                        "SS_UpdateDeltaFS - Patch Can be applied from using backup file as source\n");
+                                       } else {
+                                               SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
+                                               if (source_data.data)
+                                                       SS_Free(source_data.data);
+                                               return E_SS_FAILURE;
+                                       }
+                               } else {
+                                       SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
+                                       if (source_data.data)
+                                               SS_Free(source_data.data);
+                                       return E_SS_FAILURE;
+                               }
+                       }
+               } else {
+                       LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Source was deleted, Try loading from backup source\n");
+                       if (SS_LoadFile(SS_BACKUP_SOURCE, &source_data) == 0) {
+                               if (memcmp(source_data.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                                       if (SS_CopyFile(NULL, SS_BACKUP_SOURCE, source_filename) != 0) {
+                                               LOGE("copy of backup to \"%s\" failed: %s\n", source_filename, strerror(errno));
+                                               SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                               if (source_data.data)
+                                                       SS_Free(source_data.data);
+                                               return E_SS_FAILURE;
+                                       }
+                                       LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Can be applied from using backup file as source\n");
+                               } else {
+                                       SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
+                                       if (source_data.data)
+                                               SS_Free(source_data.data);
+                                       return E_SS_FAILURE;
+                               }
+                       } else {
+                               SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
+                               if (source_data.data)
+                                       SS_Free(source_data.data);
+                               return E_SS_FAILURE;
+                       }
+               }
+       }
 #ifndef ENHANCED_BSDIFF
-    backupsrc = SS_BackupSource(source_filename);
-    if (backupsrc != 0) {
-        LOGE("failed to Backup source File:[%s] \n", source_filename);
-        SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
-        return E_SS_FAILURE;
-    }
+       backupsrc = SS_BackupSource(source_filename);
+       if (backupsrc != 0) {
+               LOGE("failed to Backup source File:[%s] \n", source_filename);
+               SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
+               return E_SS_FAILURE;
+       }
 #endif
-    //create workspace for processing container upgrade
-    SS_CreateFolder(NULL, SS_ARCHIVE_WORK_FOLDER);
-    SS_CreateFolder(NULL, SS_ARCHIVE_UNPACK_FOLDER);
-
-    //unpack the source container to the unpack workspace
-    snprintf(cmd, sizeof(cmd) - 1, "%s -qo %s -d %s", SS_UNZIP_COMMAND, source_filename, SS_ARCHIVE_UNPACK_FOLDER);
-    result = _system_cmd_wait(cmd);
-    if (result != S_SS_SUCCESS) {
-        LOGE("zip extraction for [%s] failed, code [%d]\n", cmd, result);
-        return E_SS_FAILURE;
-    }
-    //extract unpack scipt from delta.tar to process containers later
-    if (tar_get_item_size(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT) > 0)
-        if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT, SS_KERN_UNPK_SCRIPT_PATH) >
-            0)
-            LOGL(LOG_SSENGINE, "Extracted %s successfully\n", SS_KERNEL_UNPACK_SCRIPT);
-        else {
-            LOGE("Error in fn tar_extract_file for item %s", SS_KERNEL_UNPACK_SCRIPT);
-            SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
-            result = E_SS_FAILURE;
-        }
-    //move new tpk extracted in the delta folder to the work folder
-    new_file = strrchr(target_filename, '/');
-    snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_DELTA_FOLDER, new_file + 1);
-    snprintf(target_path_full, sizeof(target_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, new_file + 1);
-
-    result = rename(source_path_full, target_path_full);
-    if (result != 0) {
-        LOGE("fatal error in moving %s to %s\n", source_path_full, target_path_full);
-        return E_SS_FAILURE;
-    }
-    snprintf(cmd, sizeof(cmd) - 1, "%s -qo %s -d %s", SS_UNZIP_COMMAND, target_path_full, SS_ARCHIVE_WORK_FOLDER);
-    result = _system_cmd_wait(cmd);
-    if (result != S_SS_SUCCESS) {
-        LOGE("zip extraction for [%s] failed, code [%d]\n", cmd, result);
-        return E_SS_FAILURE;
-    } else
-        LOGL(LOG_SSENGINE, "Thin zip extracted successfully\n");
-    // open the patch list and start iterating through the changes and the same files
-    snprintf(patchlist, MAX_FILE_PATH, "%s/%s", SS_ARCHIVE_DELTA_FOLDER, SS_CONTAINER_INFO_FILE);
-    fp = fopen(patchlist, "r");
-    if (!fp) {
-        LOGE("file open error [%s]\n", patchlist);
-        return E_SS_FAILURE;
-    }
-
-    while ((read = getline(&line, &len, fp)) != -1) {
-
-        switch (line[0]) {      // '-' == Delete File, 's' == same File, 'c' == Changed File
-        case 's':              //for same files case, just extract from old tpk to the work folder, update new tpk in the end
-            token = strtok(line, SS_SEPARATOR_TOKEN);
-
-            source_file = strtok(NULL, SS_NEWLINE_TOKEN);
-
-            snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_UNPACK_FOLDER, source_file);
-            snprintf(target_path_full, sizeof(target_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, source_file);
-            LOGL(LOG_SSENGINE, "copy %s\n", source_file);
-            result = SS_MoveFile(NULL, source_path_full, target_path_full);
-            if (result != S_SS_SUCCESS) {
-                LOGE("fatal error [%d]\n", errno);
-                goto Cleanup;
-            }
-            break;
-        case 'c':
-            token = strtok(line, SS_SEPARATOR_TOKEN);
-
-            source_file = strtok(NULL, SS_SEPARATOR_TOKEN);
-            patch_file = strtok(NULL, SS_NEWLINE_TOKEN);
-
-            snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_UNPACK_FOLDER, source_file);
-            snprintf(target_path_full, sizeof(target_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, source_file);
-            LOGL(LOG_SSENGINE, "copy %s\n", source_file);
-            result = SS_MoveFile(NULL, source_path_full, target_path_full);
-            if (result != S_SS_SUCCESS) {
-                LOGE("fatal error [%d]\n", errno);
-            }
-
-            snprintf(patch_path_full, sizeof(patch_path_full) - 1, "%s/%s", SS_ARCHIVE_DELTA_FOLDER, patch_file);
-            snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, source_file);
-
-            {
-                // We write the decoded output to "<tgt-file>.patch".
-                //allocate some extra space to allow for concatinating ".patch" with the name
-                outname = (char *)SS_Malloc(strlen(source_path_full) + 10);
-                if (outname == NULL)
-                    goto Cleanup;
-                strcpy(outname, source_path_full);
-                strcat(outname, ".patch");
-
-                output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
-                if (output < 0) {
-                    LOGE("failed to open output file %s: %s\n", outname, strerror(errno));
-                    SS_Free(outname);
-                    goto Cleanup;
-                }
-                sink = ss_fileSink;
-                tok = &output;
-            }
-            result = SS_ApplyBsdiff((char *)source_path_full, outname, patch_path_full, sink, tok, NULL);
-            LOGL(LOG_SSENGINE, "GenerateTarget Output is %d and result is %d\n", output, result);
-            if (output >= 0) {
-                fsync(output);
-                close(output);
-            }
-
-            if (result != 0) {
-                LOGE("applying patch failed %s\n", source_path_full);
-                if (outname != NULL) {
-                    unlink(outname);
-                }
-                goto Cleanup;
-            }
-            result = rename(outname, source_path_full);
-            if (result != 0) {
-                LOGE("fatal error %s\n", source_path_full);
-                goto Cleanup;
-            } else {
-                LOGL(LOG_SSENGINE, "Successfully applied patch for [%s]\n", source_path_full);
-            }
-            break;
-        default:
-            break;
-        }
-    }
-
-    new_file = strrchr(target_filename, '/');
-    snprintf(cmd, sizeof(cmd) - 1, "%s -p %s %s /opt/data/fota", SS_KERN_UNPK_SCRIPT_PATH, SS_ARCHIVE_WORK_FOLDER,
-             new_file + 1);
-    int ret = _system_cmd_wait(cmd);
-    LOGL(LOG_SSENGINE, "ret for %s is %d\n", cmd, ret);
-
-    //Apply diff between intermediate new tpk and the new tpk which contains central dir changes only
-    snprintf(patch_path_full, sizeof(patch_path_full) - 1, "%s/New_%s.delta", SS_ARCHIVE_DELTA_FOLDER, new_file + 1);
-    snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, new_file + 1);
-
-    {
-        // We write the decoded output to "<tgt-file>.patch".
-        //allocate some extra space to allow for concatinating ".patch" with the name
-        outname = (char *)SS_Malloc(strlen(source_path_full) + 10);
-        if (outname == NULL)
-            return E_SS_FAILURE;
-        strcpy(outname, source_path_full);
-        strcat(outname, ".patch");
-
-        output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
-        if (output < 0) {
-            LOGE("failed to open output file %s: %s\n", outname, strerror(errno));
-            SS_Free(outname);
-            goto Cleanup;
-        }
-        sink = ss_fileSink;
-        tok = &output;
-    }
-    result = SS_ApplyBsdiff((char *)source_path_full, outname, patch_path_full, sink, tok, NULL);
-    LOGL(LOG_SSENGINE, "GenerateTarget Output is %d and result is %d\n", output, result);
-    if (output >= 0) {
-        fsync(output);
-        close(output);
-    }
-
-    if (result != 0) {
-        LOGE("applying patch failed %s\n", source_path_full);
-        if (outname != NULL) {
-            unlink(outname);
-        }
-        goto Cleanup;
-    }
-
-    if (SS_LoadFile(outname, &source_data) == 0)
-        result = memcmp(source_data.sha1, target_sha1, SHA_DIGEST_SIZE);
-    if (result != S_SS_SUCCESS) {
-        LOGE("patch did not produce expected sha1 \n");
-        SS_SetUpgradeState(E_SS_IMGSHA_MISMATCH);
-        goto Cleanup;
-    }
-
-    result = rename(outname, source_path_full);
-    if (result != 0) {
-        LOGE("fatal error %s\n", source_path_full);
-        goto Cleanup;
-    }
-    //Delete old file and copy patched archive, cant use rename as partitions  may be different
-    unlink(source_filename);
-    if (result != 0) {
-        LOGE("failed to unlink [%s] code [%d]\n", source_filename, errno);
-        goto Cleanup;
-    }
-    result = (int)SS_CopyFile(NULL, source_path_full, target_filename);
-    if (result != S_SS_SUCCESS) {
-        LOGE("failed to copy file [%s] result [%d]\n", source_path_full, result);
-        goto Cleanup;
-    }
+       //create workspace for processing container upgrade
+       SS_CreateFolder(NULL, SS_ARCHIVE_WORK_FOLDER);
+       SS_CreateFolder(NULL, SS_ARCHIVE_UNPACK_FOLDER);
+
+       //unpack the source container to the unpack workspace
+       snprintf(cmd, sizeof(cmd) - 1, "%s -qo %s -d %s", SS_UNZIP_COMMAND, source_filename, SS_ARCHIVE_UNPACK_FOLDER);
+       result = _system_cmd_wait(cmd);
+       if (result != S_SS_SUCCESS) {
+               LOGE("zip extraction for [%s] failed, code [%d]\n", cmd, result);
+               return E_SS_FAILURE;
+       }
+       //extract unpack scipt from delta.tar to process containers later
+       if (tar_get_item_size(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT) > 0)
+               if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT, SS_KERN_UNPK_SCRIPT_PATH) >
+                       0)
+                       LOGL(LOG_SSENGINE, "Extracted %s successfully\n", SS_KERNEL_UNPACK_SCRIPT);
+               else {
+                       LOGE("Error in fn tar_extract_file for item %s", SS_KERNEL_UNPACK_SCRIPT);
+                       SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
+                       result = E_SS_FAILURE;
+               }
+       //move new tpk extracted in the delta folder to the work folder
+       new_file = strrchr(target_filename, '/');
+       snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_DELTA_FOLDER, new_file + 1);
+       snprintf(target_path_full, sizeof(target_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, new_file + 1);
+
+       result = rename(source_path_full, target_path_full);
+       if (result != 0) {
+               LOGE("fatal error in moving %s to %s\n", source_path_full, target_path_full);
+               return E_SS_FAILURE;
+       }
+       snprintf(cmd, sizeof(cmd) - 1, "%s -qo %s -d %s", SS_UNZIP_COMMAND, target_path_full, SS_ARCHIVE_WORK_FOLDER);
+       result = _system_cmd_wait(cmd);
+       if (result != S_SS_SUCCESS) {
+               LOGE("zip extraction for [%s] failed, code [%d]\n", cmd, result);
+               return E_SS_FAILURE;
+       } else
+               LOGL(LOG_SSENGINE, "Thin zip extracted successfully\n");
+       // open the patch list and start iterating through the changes and the same files
+       snprintf(patchlist, MAX_FILE_PATH, "%s/%s", SS_ARCHIVE_DELTA_FOLDER, SS_CONTAINER_INFO_FILE);
+       fp = fopen(patchlist, "r");
+       if (!fp) {
+               LOGE("file open error [%s]\n", patchlist);
+               return E_SS_FAILURE;
+       }
+
+       while ((read = getline(&line, &len, fp)) != -1) {
+
+               switch (line[0]) {        // '-' == Delete File, 's' == same File, 'c' == Changed File
+               case 's':                         //for same files case, just extract from old tpk to the work folder, update new tpk in the end
+                       token = strtok(line, SS_SEPARATOR_TOKEN);
+
+                       source_file = strtok(NULL, SS_NEWLINE_TOKEN);
+
+                       snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_UNPACK_FOLDER, source_file);
+                       snprintf(target_path_full, sizeof(target_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, source_file);
+                       LOGL(LOG_SSENGINE, "copy %s\n", source_file);
+                       result = SS_MoveFile(NULL, source_path_full, target_path_full);
+                       if (result != S_SS_SUCCESS) {
+                               LOGE("fatal error [%d]\n", errno);
+                               goto Cleanup;
+                       }
+                       break;
+               case 'c':
+                       token = strtok(line, SS_SEPARATOR_TOKEN);
+
+                       source_file = strtok(NULL, SS_SEPARATOR_TOKEN);
+                       patch_file = strtok(NULL, SS_NEWLINE_TOKEN);
+
+                       snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_UNPACK_FOLDER, source_file);
+                       snprintf(target_path_full, sizeof(target_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, source_file);
+                       LOGL(LOG_SSENGINE, "copy %s\n", source_file);
+                       result = SS_MoveFile(NULL, source_path_full, target_path_full);
+                       if (result != S_SS_SUCCESS)
+                               LOGE("fatal error [%d]\n", errno);
+
+                       snprintf(patch_path_full, sizeof(patch_path_full) - 1, "%s/%s", SS_ARCHIVE_DELTA_FOLDER, patch_file);
+                       snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, source_file);
+
+                       {
+                               // We write the decoded output to "<tgt-file>.patch".
+                               //allocate some extra space to allow for concatinating ".patch" with the name
+                               outname = (char *)SS_Malloc(strlen(source_path_full) + 10);
+                               if (outname == NULL)
+                                       goto Cleanup;
+                               strcpy(outname, source_path_full);
+                               strcat(outname, ".patch");
+
+                               output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
+                               if (output < 0) {
+                                       LOGE("failed to open output file %s: %s\n", outname, strerror(errno));
+                                       SS_Free(outname);
+                                       goto Cleanup;
+                               }
+                               sink = ss_fileSink;
+                               tok = &output;
+                       }
+                       result = SS_ApplyBsdiff((char *)source_path_full, outname, patch_path_full, sink, tok, NULL);
+                       LOGL(LOG_SSENGINE, "GenerateTarget Output is %d and result is %d\n", output, result);
+                       if (output >= 0) {
+                               fsync(output);
+                               close(output);
+                       }
+
+                       if (result != 0) {
+                               LOGE("applying patch failed %s\n", source_path_full);
+                               if (outname != NULL)
+                                       unlink(outname);
+                               goto Cleanup;
+                       }
+                       result = rename(outname, source_path_full);
+                       if (result != 0) {
+                               LOGE("fatal error %s\n", source_path_full);
+                               goto Cleanup;
+                       } else {
+                               LOGL(LOG_SSENGINE, "Successfully applied patch for [%s]\n", source_path_full);
+                       }
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       new_file = strrchr(target_filename, '/');
+       snprintf(cmd, sizeof(cmd) - 1, "%s -p %s %s /opt/data/fota", SS_KERN_UNPK_SCRIPT_PATH, SS_ARCHIVE_WORK_FOLDER,
+                        new_file + 1);
+       int ret = _system_cmd_wait(cmd);
+       LOGL(LOG_SSENGINE, "ret for %s is %d\n", cmd, ret);
+
+       //Apply diff between intermediate new tpk and the new tpk which contains central dir changes only
+       snprintf(patch_path_full, sizeof(patch_path_full) - 1, "%s/New_%s.delta", SS_ARCHIVE_DELTA_FOLDER, new_file + 1);
+       snprintf(source_path_full, sizeof(source_path_full) - 1, "%s/%s", SS_ARCHIVE_WORK_FOLDER, new_file + 1);
+
+       {
+               // We write the decoded output to "<tgt-file>.patch".
+               //allocate some extra space to allow for concatinating ".patch" with the name
+               outname = (char *)SS_Malloc(strlen(source_path_full) + 10);
+               if (outname == NULL)
+                       return E_SS_FAILURE;
+               strcpy(outname, source_path_full);
+               strcat(outname, ".patch");
+
+               output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
+               if (output < 0) {
+                       LOGE("failed to open output file %s: %s\n", outname, strerror(errno));
+                       SS_Free(outname);
+                       goto Cleanup;
+               }
+               sink = ss_fileSink;
+               tok = &output;
+       }
+       result = SS_ApplyBsdiff((char *)source_path_full, outname, patch_path_full, sink, tok, NULL);
+       LOGL(LOG_SSENGINE, "GenerateTarget Output is %d and result is %d\n", output, result);
+       if (output >= 0) {
+               fsync(output);
+               close(output);
+       }
+
+       if (result != 0) {
+               LOGE("applying patch failed %s\n", source_path_full);
+               if (outname != NULL)
+                       unlink(outname);
+               goto Cleanup;
+       }
+
+       if (SS_LoadFile(outname, &source_data) == 0)
+               result = memcmp(source_data.sha1, target_sha1, SHA_DIGEST_SIZE);
+       if (result != S_SS_SUCCESS) {
+               LOGE("patch did not produce expected sha1 \n");
+               SS_SetUpgradeState(E_SS_IMGSHA_MISMATCH);
+               goto Cleanup;
+       }
+
+       result = rename(outname, source_path_full);
+       if (result != 0) {
+               LOGE("fatal error %s\n", source_path_full);
+               goto Cleanup;
+       }
+       //Delete old file and copy patched archive, cant use rename as partitions  may be different
+       unlink(source_filename);
+       if (result != 0) {
+               LOGE("failed to unlink [%s] code [%d]\n", source_filename, errno);
+               goto Cleanup;
+       }
+       result = (int)SS_CopyFile(NULL, source_path_full, target_filename);
+       if (result != S_SS_SUCCESS) {
+               LOGE("failed to copy file [%s] result [%d]\n", source_path_full, result);
+               goto Cleanup;
+       }
 
  Cleanup:
-    fclose(fp);
-    if (line)
-        SS_Free(line);
-    if (outname)
-        SS_Free(outname);
-    SS_DeleteFile(NULL, SS_KERN_UNPK_SCRIPT_PATH);
-    SS_DeleteFile(NULL, SS_FIND_CMD_TARGET);
-    SS_DeleteFolder(NULL, SS_CONTAINER_WORKSPACE);
-    return result;
+       fclose(fp);
+       if (line)
+               SS_Free(line);
+       if (outname)
+               SS_Free(outname);
+       SS_DeleteFile(NULL, SS_KERN_UNPK_SCRIPT_PATH);
+       SS_DeleteFile(NULL, SS_FIND_CMD_TARGET);
+       SS_DeleteFolder(NULL, SS_CONTAINER_WORKSPACE);
+       return result;
 }
 #endif
 /*!
  *********************************************************************************
- *                     SS_UpdateDeltaFS
+ *                                      SS_UpdateDeltaFS
  *********************************************************************************
  *
  * @brief
@@ -546,238 +540,235 @@ int SS_UpdateArchive(ua_dataSS_t * ua_dataSS, const char *source_filename, const
  */
 
 int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
-                     const char *source_sha1_str, const char *target_sha1_str, int patch_data_size)
+                                        const char *source_sha1_str, const char *target_sha1_str, int patch_data_size)
 {
-    uint8_t target_sha1[SHA_DIGEST_SIZE];
-    sha1_ctx_t ctx1;
-    int output;
-    int retry = 1;
-    int use_backup = 0;
-    char *outname = NULL;
-    int backupsrc = -1;
-    int result = 0;
-    char buf[256];
-    FileInfo source_file;
-    uint8_t source_sha1[SHA_DIGEST_SIZE] = { 0, };
-
-    if (ParseSha1(target_sha1_str, target_sha1) != 0) {
-        LOGE("failed to parse tgt-sha1 \"%s\"\n", target_sha1_str);
-        return E_SS_FAILURE;
-    }
-
-    /*
-       if battery removed in between update gvalid_session becomes 0
-       need to check file integrity in that case
-     */
-    if (0 == gvalid_session) {
-        if (ParseSha1(source_sha1_str, source_sha1) != 0) {
-            LOGE("failed to parse tgt-sha1 \"%s\"\n", source_sha1_str);
-            return E_SS_FAILURE;
-        }
-        if (SS_LoadFile(source_filename, &source_file) == 0) {
-            if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Can be applied\n");
-                if (source_file.data)
-                    SS_Free(source_file.data);
-            } else if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Already applied\n");
-                if (source_file.data)
-                    SS_Free(source_file.data);
-                return S_SS_SUCCESS;
-            } else {
-                //Check for backup file SHA
-                SS_Free(source_file.data);
-                source_file.data = NULL;
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Source was currupted, Try loading from backup source\n");
-                if (SS_LoadFile(SS_BACKUP_SOURCE, &source_file) == 0) {
-                    if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                        if (SS_CopyFile(NULL, SS_BACKUP_SOURCE, source_filename) != S_SS_SUCCESS) {
-                            strerror_r(errno, buf, sizeof(buf));
-                            LOGE("copy of backup to \"%s\" failed: %s\n", source_filename, buf);
-                            SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                            if (source_file.data)
-                                SS_Free(source_file.data);
-                            return E_SS_FAILURE;
-                        }
-                        LOGL(LOG_SSENGINE,
-                             "SS_UpdateDeltaFS - Patch Can be applied from using backup file as source\n");
-                    } else {
-                        SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
-                        if (source_file.data)
-                            SS_Free(source_file.data);
-                        return E_SS_FAILURE;
-                    }
-                } else {
-                    SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
-                    if (source_file.data)
-                        SS_Free(source_file.data);
-                    return E_SS_FAILURE;
-                }
-            }
-        } else {
-            LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Source was deleted, Try loading from backup source\n");
-            if (SS_LoadFile(SS_BACKUP_SOURCE, &source_file) == 0) {
-                if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                    use_backup = 1;
-                    LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Can be applied from using backup file as source\n");
-                } else {
-                    SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
-                    if (source_file.data)
-                        SS_Free(source_file.data);
-                    return E_SS_FAILURE;
-                }
-            } else {
-                SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
-                if (source_file.data)
-                    SS_Free(source_file.data);
-                return E_SS_FAILURE;
-            }
-        }
-    }
-    //Now proceed wit patch application since patch can be applied
-    do {
-        int enough_space = 0;
-        size_t free_space;
-        char *tok;
-
-        if (retry > 0) {
-            if (use_backup) {
-                tok = strrchr(source_filename, '/');
-                *tok = '\0';
-            }
-            SS_GetAvailableFreeSpace(NULL, source_filename, &free_space);
-            enough_space = (free_space > (256 << 10)) &&        // 256k (two-block) minimum
-                (free_space > (patch_data_size * 3 / 2));       // 50% margin of error
-            if (use_backup)
-                *tok = '/';
-        }
-
-        if (!use_backup) {
+       uint8_t target_sha1[SHA_DIGEST_SIZE];
+       sha1_ctx_t ctx1;
+       int output;
+       int retry = 1;
+       int use_backup = 0;
+       char *outname = NULL;
+       int backupsrc = -1;
+       int result = 0;
+       char buf[256];
+       FileInfo source_file;
+       uint8_t source_sha1[SHA_DIGEST_SIZE] = { 0, };
+
+       if (ParseSha1(target_sha1_str, target_sha1) != 0) {
+               LOGE("failed to parse tgt-sha1 \"%s\"\n", target_sha1_str);
+               return E_SS_FAILURE;
+       }
+
+       /*
+          if battery removed in between update gvalid_session becomes 0
+          need to check file integrity in that case
+        */
+       if (0 == gvalid_session) {
+               if (ParseSha1(source_sha1_str, source_sha1) != 0) {
+                       LOGE("failed to parse tgt-sha1 \"%s\"\n", source_sha1_str);
+                       return E_SS_FAILURE;
+               }
+               if (SS_LoadFile(source_filename, &source_file) == 0) {
+                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Can be applied\n");
+                               if (source_file.data)
+                                       SS_Free(source_file.data);
+                       } else if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Already applied\n");
+                               if (source_file.data)
+                                       SS_Free(source_file.data);
+                               return S_SS_SUCCESS;
+                       } else {
+                               //Check for backup file SHA
+                               SS_Free(source_file.data);
+                               source_file.data = NULL;
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Source was currupted, Try loading from backup source\n");
+                               if (SS_LoadFile(SS_BACKUP_SOURCE, &source_file) == 0) {
+                                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                                               if (SS_CopyFile(NULL, SS_BACKUP_SOURCE, source_filename) != S_SS_SUCCESS) {
+                                                       strerror_r(errno, buf, sizeof(buf));
+                                                       LOGE("copy of backup to \"%s\" failed: %s\n", source_filename, buf);
+                                                       SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                                       if (source_file.data)
+                                                               SS_Free(source_file.data);
+                                                       return E_SS_FAILURE;
+                                               }
+                                               LOGL(LOG_SSENGINE,
+                                                        "SS_UpdateDeltaFS - Patch Can be applied from using backup file as source\n");
+                                       } else {
+                                               SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
+                                               if (source_file.data)
+                                                       SS_Free(source_file.data);
+                                               return E_SS_FAILURE;
+                                       }
+                               } else {
+                                       SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
+                                       if (source_file.data)
+                                               SS_Free(source_file.data);
+                                       return E_SS_FAILURE;
+                               }
+                       }
+               } else {
+                       LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Source was deleted, Try loading from backup source\n");
+                       if (SS_LoadFile(SS_BACKUP_SOURCE, &source_file) == 0) {
+                               if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                                       use_backup = 1;
+                                       LOGL(LOG_SSENGINE, "SS_UpdateDeltaFS - Patch Can be applied from using backup file as source\n");
+                               } else {
+                                       SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
+                                       if (source_file.data)
+                                               SS_Free(source_file.data);
+                                       return E_SS_FAILURE;
+                               }
+                       } else {
+                               SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);
+                               if (source_file.data)
+                                       SS_Free(source_file.data);
+                               return E_SS_FAILURE;
+                       }
+               }
+       }
+       //Now proceed wit patch application since patch can be applied
+       do {
+               int enough_space = 0;
+               size_t free_space;
+               char *tok;
+
+               if (retry > 0) {
+                       if (use_backup) {
+                               tok = strrchr(source_filename, '/');
+                               *tok = '\0';
+                       }
+                       SS_GetAvailableFreeSpace(NULL, source_filename, &free_space);
+                       enough_space = (free_space > (256 << 10)) &&            // 256k (two-block) minimum
+                               (free_space > (patch_data_size * 3 / 2));          // 50% margin of error
+                       if (use_backup)
+                               *tok = '/';
+               }
+
+               if (!use_backup) {
 #ifndef ENHANCED_BSDIFF
-            backupsrc = SS_BackupSource(source_filename);
-            if (backupsrc != 0) {
-                LOGE("failed to Backup source File:[%s] \n", source_filename);
-                SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
-                return E_SS_FAILURE;
-            }
+                       backupsrc = SS_BackupSource(source_filename);
+                       if (backupsrc != 0) {
+                               LOGE("failed to Backup source File:[%s] \n", source_filename);
+                               SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
+                               return E_SS_FAILURE;
+                       }
 #endif
-        }
-        if (!enough_space) {
-            LOGL(LOG_SSENGINE, "For %s: free space %ld bytes; enough %d\n", source_filename, (long)free_space,
-                 enough_space);
-            retry = 0;
-            use_backup = 1;
-            unlink(source_filename);
-        }
-        //LOGL(LOG_SSENGINE, "For %s: target %ld bytes; free space %ld bytes; enough %d\n",
-        // source_filename, (long)patch_data_size, (long)free_space, enough_space);
-        //LOGL(LOG_SSENGINE,"Generate Target Space availabitiy [%d]\n", enough_space);
-
-        SinkFn sink = NULL;
-        void *token = NULL;
-        output = -1;
-        outname = NULL;
-
-        {
-            // We write the decoded output to "<tgt-file>.patch".
-            //allocate some extra space to allow for concatinating ".patch" with the name
-            outname = (char *)SS_Malloc(strlen(target_filename) + 10);
-            if (outname == NULL)
-                return -1;
-           snprintf(outname, strlen(target_filename) + 10,
-                           "%s.patch", target_filename);
-
-            output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
-            if (output < 0) {
-                if (errno == 2) {
-                    char *dir_path = strrchr(outname, '/');
-                    *dir_path = '\0';
-                    // need to create directory as the target may be different from source
-                    LOGL(LOG_SSENGINE, "need to create directory [%s]\n", outname);
-                    create_dir(outname, 0755);
-                    *dir_path = '/';
-                    output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
-                    if (output < 0) {
-                        strerror_r(errno, buf, sizeof(buf));
-                        LOGE("failed to open output file %s: %s\n", outname, buf);
-                        SS_Free(outname);
-                        return E_SS_FAILURE;
-                    }
-                }
-            }
-            sink = ss_fileSink;
-            token = &output;
-        }
-        sha1_init(&ctx1);
-        if (use_backup)
-            result = SS_ApplyBsdiff(SS_BACKUP_SOURCE, outname, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
-        else
-            result = SS_ApplyBsdiff((char *)source_filename, outname, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
-        if (output >= 0) {
-            fsync(output);
-            close(output);
-        }
-
-        if (result != 0) {
-            if (retry == 0) {
-                LOGE("applying patch failed result : [%d]\n", result);
-                SS_Free(outname);//wgid: 20739
-                SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                return E_SS_FAILURE;
-            } else {
-                LOGE("applying patch failed; retrying\n");
-                SS_Free(outname);//wgid: 20739
-            }
-        } else {
-            // succeeded; no need to retry
-            break;
-        }
-    } while (retry-- > 0);
-    const uint8_t current_target_sha1[SHA_DIGEST_SIZE] = { 0, };
-    sha1_final(&ctx1, (uint32_t *) & current_target_sha1);
-    if (memcmp(current_target_sha1, target_sha1, SHA_DIGEST_SIZE) != 0) {
-        LOGE("patch did not produce expected sha1\n");
-        SS_SetUpgradeState(E_SS_FSSHA_MISMATCH);
-        if (outname != NULL) {
-            SS_Free(outname);
-        }
-        return E_SS_FAILURE;
-    }
-    // Finally, rename the .patch file to replace the target file.
+               }
+               if (!enough_space) {
+                       LOGL(LOG_SSENGINE, "For %s: free space %ld bytes; enough %d\n", source_filename, (long)free_space,
+                                enough_space);
+                       retry = 0;
+                       use_backup = 1;
+                       unlink(source_filename);
+               }
+               //LOGL(LOG_SSENGINE, "For %s: target %ld bytes; free space %ld bytes; enough %d\n",
+               // source_filename, (long)patch_data_size, (long)free_space, enough_space);
+               //LOGL(LOG_SSENGINE,"Generate Target Space availabitiy [%d]\n", enough_space);
+
+               SinkFn sink = NULL;
+               void *token = NULL;
+               output = -1;
+               outname = NULL;
+
+               {
+                       // We write the decoded output to "<tgt-file>.patch".
+                       //allocate some extra space to allow for concatinating ".patch" with the name
+                       outname = (char *)SS_Malloc(strlen(target_filename) + 10);
+                       if (outname == NULL)
+                               return -1;
+               snprintf(outname, strlen(target_filename) + 10,
+                               "%s.patch", target_filename);
+
+                       output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
+                       if (output < 0) {
+                               if (errno == 2) {
+                                       char *dir_path = strrchr(outname, '/');
+                                       *dir_path = '\0';
+                                       // need to create directory as the target may be different from source
+                                       LOGL(LOG_SSENGINE, "need to create directory [%s]\n", outname);
+                                       create_dir(outname, 0755);
+                                       *dir_path = '/';
+                                       output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
+                                       if (output < 0) {
+                                               strerror_r(errno, buf, sizeof(buf));
+                                               LOGE("failed to open output file %s: %s\n", outname, buf);
+                                               SS_Free(outname);
+                                               return E_SS_FAILURE;
+                                       }
+                               }
+                       }
+                       sink = ss_fileSink;
+                       token = &output;
+               }
+               sha1_init(&ctx1);
+               if (use_backup)
+                       result = SS_ApplyBsdiff(SS_BACKUP_SOURCE, outname, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
+               else
+                       result = SS_ApplyBsdiff((char *)source_filename, outname, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
+               if (output >= 0) {
+                       fsync(output);
+                       close(output);
+               }
+
+               if (result != 0) {
+                       if (retry == 0) {
+                               LOGE("applying patch failed result : [%d]\n", result);
+                               SS_Free(outname);//wgid: 20739
+                               SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                               return E_SS_FAILURE;
+                       } else {
+                               LOGE("applying patch failed; retrying\n");
+                               SS_Free(outname);//wgid: 20739
+                       }
+               } else {
+                       // succeeded; no need to retry
+                       break;
+               }
+       } while (retry-- > 0);
+       const uint8_t current_target_sha1[SHA_DIGEST_SIZE] = { 0, };
+       sha1_final(&ctx1, (uint32_t *) & current_target_sha1);
+       if (memcmp(current_target_sha1, target_sha1, SHA_DIGEST_SIZE) != 0) {
+               LOGE("patch did not produce expected sha1\n");
+               SS_SetUpgradeState(E_SS_FSSHA_MISMATCH);
+               if (outname != NULL)
+                       SS_Free(outname);
+               return E_SS_FAILURE;
+       }
+       // Finally, rename the .patch file to replace the target file.
 #ifdef ENHANCED_BSDIFF
-    if (SS_rename1(outname, target_filename) != 0) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("rename of .patch to \"%s\" failed: %s\n", target_filename, buf);
-        SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-        if (outname != NULL) {
-            SS_Free(outname);
-        }
-        return E_SS_FAILURE;
-    }
+       if (SS_rename1(outname, target_filename) != 0) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("rename of .patch to \"%s\" failed: %s\n", target_filename, buf);
+               SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+               if (outname != NULL)
+                       SS_Free(outname);
+               return E_SS_FAILURE;
+       }
 #else
-    if (rename(outname, target_filename) != 0) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("rename of .patch to \"%s\" failed: %s\n", target_filename, buf);
-        SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-        if (outname != NULL) {
-            SS_Free(outname);
-        }
-        return E_SS_FAILURE;
-    }
-    //remove source file if target is not same
-    if (strcmp(source_filename, target_filename) != 0)
-        unlink(source_filename);
-    SS_BackupSourceClear();
+       if (rename(outname, target_filename) != 0) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("rename of .patch to \"%s\" failed: %s\n", target_filename, buf);
+               SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+               if (outname != NULL)
+                       SS_Free(outname);
+               return E_SS_FAILURE;
+       }
+       //remove source file if target is not same
+       if (strcmp(source_filename, target_filename) != 0)
+               unlink(source_filename);
+       SS_BackupSourceClear();
 #endif
-    SS_PatchSourceClear();
-    SS_Free(outname);
+       SS_PatchSourceClear();
+       SS_Free(outname);
 
-    return result;
+       return result;
 }
 
 /*!
  *********************************************************************************
- *                     SS_UpdateDeltaKernel
+ *                                      SS_UpdateDeltaKernel
  *********************************************************************************
  *
  * @brief
@@ -794,302 +785,301 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
 
 int SS_UpdateDeltaKernel(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *, int, int, char *))
 {
-    uint8_t target_sha1[SHA_DIGEST_SIZE];
-    uint8_t source_sha1[SHA_DIGEST_SIZE];
-    FileInfo source_file;
-    int result = S_SS_SUCCESS;
-    int blk_cnt, read_count = 0;
-    int blk_start = 0;
-    int backupsrc = -1;
-    int use_backup_img = -1;
-    FILE *fp = NULL, *wp = NULL, *kp = NULL;
-    int i = 0, j = 0, file_len = 0;
-    char *magic = NULL, *file_name = NULL, *tok_buf = NULL, *buf = NULL, a = '0';
-    char *saveptr;
-    char err_buf[256];
-    char cmd[1024] = { 0, };
-    char source_filename[MAX_FILE_PATH] = { 0, };
-    char part_filename[MAX_FILE_PATH] = { 0, };
-    int file_num = 0;
-    SinkFn sink = NULL;
-    void *tok = NULL;
-    int output = -1;
-    char *outname = NULL;
-    //Kernel Parts are created on unpacking kernel which is then used to apply delta
-    char *kernel_parts[] = { "decompression_code",
-        "piggy.gz",
-        "padding_piggy",
-        "piggy_trailer"
-    };
-
-    if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-        LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-        return E_SS_FAILURE;
-    }
-
-    source_file.size = ua_dataSS->update_cfg->soure_img_size;
-    source_file.data = NULL;
-    if (0 == gvalid_session) {
-
-        if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
-            LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
-            return E_SS_FAILURE;
-        }
-
-        if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) == 0) {
-            if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Can be applied\n");
-
-            } else if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Already applied\n");
-                SS_Free(source_file.data);
-                return S_SS_SUCCESS;
-            } else {
-                SS_Free(source_file.data);
-                source_file.data = NULL;
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Source was currupted, Try loading from backup source\n");
-                if (SS_LoadPartition(SS_BACKUP_SOURCE, &source_file) == 0) {
-                    if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                        use_backup_img = 1;
-
-                        LOGL(LOG_SSENGINE,
-                             "SS_UpdateDeltaIMG - Patch Can be applied from using backup file as source\n");
-                    } else {
-                        SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
-                        SS_Free(source_file.data);
-                        return E_SS_FAILURE;
-                    }
-                }
-            }
-        }
-    } else {                    //in case of kernel delta need to copy kernel data  from blk to buffer
-        if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) != 0) {
-            SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
-            LOGE("Fatal Error : Kernel block is corrupted\n");
-            return E_SS_FAILURE;
-        }
-    }
-    if (use_backup_img == -1) {
-        backupsrc = SS_BackupSource(ua_dataSS->parti_info->ua_blk_name);
-        if (backupsrc != 0) {
-            LOGE("failed to Backup source File:[%s] \n", ua_dataSS->parti_info->ua_blk_name);
-            SS_SetUpgradeState(E_SS_IMGSRCBACKUPFAILED);
-            return E_SS_FAILURE;
-        }
-    }
-    //Cleanup workspace and copy helper executables to it before proceeding
-    SS_DeleteFolder(NULL, SS_KERNEL_WORKSPACE);
-    create_dir(SS_KERNEL_WORKSPACE, 0755);
-    SS_CopyFile(NULL, SS_GZIP_SOURCE, SS_GZIP_TARGET);
-    SS_CopyFile(NULL, SS_STAT_SOURCE, SS_STAT_TARGET);
-    SS_CopyFile(NULL, SS_DD_SOURCE, SS_DD_TARGET);
-
-    if (tar_get_item_size(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT) > 0)
-        if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT, SS_KERN_UNPK_SCRIPT_PATH) >
-            0)
-            LOGL(LOG_SSENGINE, "Extracted %s successfully\n", SS_KERNEL_UNPACK_SCRIPT);
-        else {
-            LOGE("Error in fn tar_extract_file for item %s", SS_KERNEL_UNPACK_SCRIPT);
-            SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
-            result = E_SS_FAILURE;
-            goto Cleanup;
-    } else {
-        LOGE("Error size is not positive for item %s", SS_KERNEL_UNPACK_SCRIPT);
-        SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
-        result = E_SS_FAILURE;
-        goto Cleanup;
-    }
-    //Now write the kernel data to the workplace and start applying patch
-    snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_NAME);
-    fp = fopen(source_filename, "w");
-    if (!fp) {
-        LOGE("file open error [%s] code [%d]\n", source_filename, errno);
-        SS_Free(source_file.data);
-        result = E_SS_FAILURE;
-        goto Cleanup;
-    }
-    //write source kernel data to workspace
-    read_count = fwrite(source_file.data, 1, source_file.size, fp);
-    if (read_count != source_file.size) {
-        LOGE("file write error read_count = %d for [%s]\n", read_count, source_filename);
-        SS_Free(source_file.data);
-        result = E_SS_FAILURE;
-        goto Cleanup;
-    }
-    SS_Free(source_file.data);
-    fclose(fp);
-    fp = NULL;//wgid: 59313
-
-    //Unpack source kernel
-    int offset = getOffset(source_filename);
-    if(offset < 0){
-        LOGE("Failed to get offset\n");
-        result = E_SS_FAILURE;
-        goto Cleanup;
-    }
-    snprintf(cmd, sizeof(cmd) - 1, "%s -u %s %s %d", SS_KERN_UNPK_SCRIPT_PATH, SS_KERNEL_WORKSPACE, SS_KERNEL_NAME,
-             offset);
-    int ret = _system_cmd_wait(cmd);
-    LOGL(LOG_SSENGINE, "ret for %s is %d\n", cmd, ret);
-
-    //open delta file, extract kernel delta parts and apply patch to previously unpacked kernel
-    fp = fopen(SS_PATCHFILE_SOURCE, "r");
-    if (fp == NULL) {
-        LOGE("Failed to open kernel delta patch\n");
-        result = E_SS_FAILURE;
-        goto Cleanup;
-    }
-    //read kernel delta header for  delta names and size
-    buf = SS_Malloc(SS_KERNEL_DELTA_HEADER);
-    if(!buf){//wgid: 13099
-        LOGE("Failed to allocate memory\n");
-        result = E_SS_MALLOC_ERROR;
-        goto Cleanup;
-    }
-    ssize_t bytes_read = fread(buf, 1, SS_KERNEL_DELTA_HEADER, fp);
-    if (bytes_read != SS_KERNEL_DELTA_HEADER)
-        LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)SS_KERNEL_DELTA_HEADER);
-    magic = strtok_r(buf, ":", &saveptr);
-    LOGL(LOG_SSENGINE, "magic: %s\n", magic);
-    tok_buf = strtok_r(NULL, ":", &saveptr);
-    if (tok_buf)
-        file_num = atoi(tok_buf);
-
-    //adjust offset to start of data section before proceeding
-    fseek(fp, SS_KERNEL_DELTA_HEADER, SEEK_SET);
-
-    while (file_num-- > 0) {
-        file_name = strtok_r(NULL, ":", &saveptr);
+       uint8_t target_sha1[SHA_DIGEST_SIZE];
+       uint8_t source_sha1[SHA_DIGEST_SIZE];
+       FileInfo source_file;
+       int result = S_SS_SUCCESS;
+       int blk_cnt, read_count = 0;
+       int blk_start = 0;
+       int backupsrc = -1;
+       int use_backup_img = -1;
+       FILE *fp = NULL, *wp = NULL, *kp = NULL;
+       int i = 0, j = 0, file_len = 0;
+       char *magic = NULL, *file_name = NULL, *tok_buf = NULL, *buf = NULL, a = '0';
+       char *saveptr;
+       char err_buf[256];
+       char cmd[1024] = { 0, };
+       char source_filename[MAX_FILE_PATH] = { 0, };
+       char part_filename[MAX_FILE_PATH] = { 0, };
+       int file_num = 0;
+       SinkFn sink = NULL;
+       void *tok = NULL;
+       int output = -1;
+       char *outname = NULL;
+       //Kernel Parts are created on unpacking kernel which is then used to apply delta
+       char *kernel_parts[] = { "decompression_code",
+               "piggy.gz",
+               "padding_piggy",
+               "piggy_trailer"
+       };
+
+       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
+               LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
+               return E_SS_FAILURE;
+       }
+
+       source_file.size = ua_dataSS->update_cfg->soure_img_size;
+       source_file.data = NULL;
+       if (0 == gvalid_session) {
+
+               if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
+                       LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
+                       return E_SS_FAILURE;
+               }
+
+               if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) == 0) {
+                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Can be applied\n");
+
+                       } else if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Already applied\n");
+                               SS_Free(source_file.data);
+                               return S_SS_SUCCESS;
+                       } else {
+                               SS_Free(source_file.data);
+                               source_file.data = NULL;
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Source was currupted, Try loading from backup source\n");
+                               if (SS_LoadPartition(SS_BACKUP_SOURCE, &source_file) == 0) {
+                                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                                               use_backup_img = 1;
+
+                                               LOGL(LOG_SSENGINE,
+                                                        "SS_UpdateDeltaIMG - Patch Can be applied from using backup file as source\n");
+                                       } else {
+                                               SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
+                                               SS_Free(source_file.data);
+                                               return E_SS_FAILURE;
+                                       }
+                               }
+                       }
+               }
+       } else {                                        //in case of kernel delta need to copy kernel data  from blk to buffer
+               if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) != 0) {
+                       SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
+                       LOGE("Fatal Error : Kernel block is corrupted\n");
+                       return E_SS_FAILURE;
+               }
+       }
+       if (use_backup_img == -1) {
+               backupsrc = SS_BackupSource(ua_dataSS->parti_info->ua_blk_name);
+               if (backupsrc != 0) {
+                       LOGE("failed to Backup source File:[%s] \n", ua_dataSS->parti_info->ua_blk_name);
+                       SS_SetUpgradeState(E_SS_IMGSRCBACKUPFAILED);
+                       return E_SS_FAILURE;
+               }
+       }
+       //Cleanup workspace and copy helper executables to it before proceeding
+       SS_DeleteFolder(NULL, SS_KERNEL_WORKSPACE);
+       create_dir(SS_KERNEL_WORKSPACE, 0755);
+       SS_CopyFile(NULL, SS_GZIP_SOURCE, SS_GZIP_TARGET);
+       SS_CopyFile(NULL, SS_STAT_SOURCE, SS_STAT_TARGET);
+       SS_CopyFile(NULL, SS_DD_SOURCE, SS_DD_TARGET);
+
+       if (tar_get_item_size(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT) > 0)
+               if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT, SS_KERN_UNPK_SCRIPT_PATH) >
+                       0)
+                       LOGL(LOG_SSENGINE, "Extracted %s successfully\n", SS_KERNEL_UNPACK_SCRIPT);
+               else {
+                       LOGE("Error in fn tar_extract_file for item %s", SS_KERNEL_UNPACK_SCRIPT);
+                       SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
+                       result = E_SS_FAILURE;
+                       goto Cleanup;
+       } else {
+               LOGE("Error size is not positive for item %s", SS_KERNEL_UNPACK_SCRIPT);
+               SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
+               result = E_SS_FAILURE;
+               goto Cleanup;
+       }
+       //Now write the kernel data to the workplace and start applying patch
+       snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_NAME);
+       fp = fopen(source_filename, "w");
+       if (!fp) {
+               LOGE("file open error [%s] code [%d]\n", source_filename, errno);
+               SS_Free(source_file.data);
+               result = E_SS_FAILURE;
+               goto Cleanup;
+       }
+       //write source kernel data to workspace
+       read_count = fwrite(source_file.data, 1, source_file.size, fp);
+       if (read_count != source_file.size) {
+               LOGE("file write error read_count = %d for [%s]\n", read_count, source_filename);
+               SS_Free(source_file.data);
+               result = E_SS_FAILURE;
+               goto Cleanup;
+       }
+       SS_Free(source_file.data);
+       fclose(fp);
+       fp = NULL;//wgid: 59313
+
+       //Unpack source kernel
+       int offset = getOffset(source_filename);
+       if (offset < 0) {
+               LOGE("Failed to get offset\n");
+               result = E_SS_FAILURE;
+               goto Cleanup;
+       }
+       snprintf(cmd, sizeof(cmd) - 1, "%s -u %s %s %d", SS_KERN_UNPK_SCRIPT_PATH, SS_KERNEL_WORKSPACE, SS_KERNEL_NAME,
+                        offset);
+       int ret = _system_cmd_wait(cmd);
+       LOGL(LOG_SSENGINE, "ret for %s is %d\n", cmd, ret);
+
+       //open delta file, extract kernel delta parts and apply patch to previously unpacked kernel
+       fp = fopen(SS_PATCHFILE_SOURCE, "r");
+       if (fp == NULL) {
+               LOGE("Failed to open kernel delta patch\n");
+               result = E_SS_FAILURE;
+               goto Cleanup;
+       }
+       //read kernel delta header for  delta names and size
+       buf = SS_Malloc(SS_KERNEL_DELTA_HEADER);
+       if (!buf) {//wgid: 13099
+               LOGE("Failed to allocate memory\n");
+               result = E_SS_MALLOC_ERROR;
+               goto Cleanup;
+       }
+       ssize_t bytes_read = fread(buf, 1, SS_KERNEL_DELTA_HEADER, fp);
+       if (bytes_read != SS_KERNEL_DELTA_HEADER)
+               LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)SS_KERNEL_DELTA_HEADER);
+       magic = strtok_r(buf, ":", &saveptr);
+       LOGL(LOG_SSENGINE, "magic: %s\n", magic);
        tok_buf = strtok_r(NULL, ":", &saveptr);
        if (tok_buf)
-           file_len = atoi(tok_buf);
-        j = file_len;
-        snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s_unpacked/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_NAME,
-                 file_name);
-        snprintf(part_filename, sizeof(part_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, file_name);
-        wp = fopen(part_filename, "w");
-        while (j-- > 0) {
-            a = fgetc(fp);
-            fputc(a, wp);
-        }
-        fclose(wp);
-
-        //apply bspatch to the unpacked kernel parts
-
-        {
-            // We write the decoded output to "<tgt-file>.patch".
-            //allocate some extra space to allow for concatinating ".patch" with the name
-            outname = (char *)SS_Malloc(strlen(source_filename) + 10);
-            if (outname == NULL) {
-                SS_SetUpgradeState(E_SS_MALLOC_ERROR);
-                result = E_SS_FAILURE;
-                goto Cleanup;
-            }
-           snprintf(outname, strlen(source_filename) + 10, "%s.patch",
-                           source_filename);
-
-            output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
-            if (output < 0) {
-                strerror_r(errno, err_buf, sizeof(err_buf));
-                LOGE("failed to open output file %s: %s\n", outname, err_buf);
-                result = E_SS_FAILURE;
-                goto Cleanup;
-            }
-            sink = ss_fileSink;
-            tok = &output;
-        }
-        result = SS_ApplyBsdiff(source_filename, outname, part_filename, sink, tok, NULL);
-        LOGL(LOG_SSENGINE, "GenerateTarget Output is %d and result is %d\n", output, result);
-        if (output >= 0) {
-            fsync(output);
-            close(output);
-        }
-
-        if (result != S_SS_SUCCESS) {
-            LOGE("applying patch failed %s\n", source_filename);
-            if (outname != NULL) {
-                unlink(outname);
-            }
-            goto Cleanup;
-        }
-        result = rename(outname, source_filename);
-        if (result != S_SS_SUCCESS) {
-            LOGE("fatal error %s\n", source_filename);
-            goto Cleanup;
-        }
-        if (file_name && strcmp(file_name, "piggy") == 0) {
-            snprintf(cmd, sizeof(cmd) - 1,
-                     "%s/gzip -n -9 -c %s/%s/%s > %s/%s/%s.gz",
-                     SS_KERNEL_WORKSPACE, SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR, file_name,
-                     SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR, file_name);
-            result = _system_cmd_wait(cmd);
-            LOGL(LOG_SSENGINE, "ret for %s = %d\n", cmd, result);
-            unlink(source_filename);
-        }
-        unlink(part_filename);
-    }
-    //open new kernel file and append kernel parts to it in
-    snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_TARGET_NAME);
-    kp = fopen(source_filename, "w");
-    for (i = 0; i < 4; i++) {
-        snprintf(part_filename, sizeof(part_filename) - 1, "%s/%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR,
-                 kernel_parts[i]);
-        wp = fopen(part_filename, "r");
-        fseek(wp, SEEK_SET, SEEK_END);
-        j = ftell(wp);
-        fseek(wp, SEEK_SET, SEEK_SET);
-        while (j-- > 0) {
-            a = fgetc(wp);
-            if(a != EOF)
-                fputc(a, kp);
-            else
-                break;
-        }
-        fclose(wp);
-        unlink(part_filename);
-    }
-    fclose(fp);
-    fp = NULL;
-    fclose(kp);
-
-    if (SS_LoadFile(source_filename, &source_file) == 0)
-        result = memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE);
-    if (result != S_SS_SUCCESS) {
-        LOGE("patch did not produce expected sha1 \n");
-        SS_SetUpgradeState(E_SS_IMGSHA_MISMATCH);
-        goto Cleanup;
-    }
-    //Considering EMMC partition by deafult
-
-    blk_cnt = ((ua_dataSS->update_cfg->target_img_size - 1) / SECTOR_SIZE) + 1;
-    result = write_to_blkdev((char *)ua_dataSS->parti_info->ua_blk_name, blk_start, blk_cnt, (char *)source_file.data);
-    if (result != S_SS_SUCCESS) {
-        LOGE("write of patched data to %s failed\n", ua_dataSS->parti_info->ua_blk_name);       // All returns should go to CLEAN UP.
-        SS_SetUpgradeState(E_SS_IMGFLASHWRITEFAIL);
-        goto Cleanup;
-    }
+               file_num = atoi(tok_buf);
+
+       //adjust offset to start of data section before proceeding
+       fseek(fp, SS_KERNEL_DELTA_HEADER, SEEK_SET);
+
+       while (file_num-- > 0) {
+               file_name = strtok_r(NULL, ":", &saveptr);
+               tok_buf = strtok_r(NULL, ":", &saveptr);
+               if (tok_buf)
+                       file_len = atoi(tok_buf);
+               j = file_len;
+               snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s_unpacked/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_NAME,
+                                file_name);
+               snprintf(part_filename, sizeof(part_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, file_name);
+               wp = fopen(part_filename, "w");
+               while (j-- > 0) {
+                       a = fgetc(fp);
+                       fputc(a, wp);
+               }
+               fclose(wp);
+
+               //apply bspatch to the unpacked kernel parts
+
+               {
+                       // We write the decoded output to "<tgt-file>.patch".
+                       //allocate some extra space to allow for concatinating ".patch" with the name
+                       outname = (char *)SS_Malloc(strlen(source_filename) + 10);
+                       if (outname == NULL) {
+                               SS_SetUpgradeState(E_SS_MALLOC_ERROR);
+                               result = E_SS_FAILURE;
+                               goto Cleanup;
+                       }
+               snprintf(outname, strlen(source_filename) + 10, "%s.patch",
+                               source_filename);
+
+                       output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
+                       if (output < 0) {
+                               strerror_r(errno, err_buf, sizeof(err_buf));
+                               LOGE("failed to open output file %s: %s\n", outname, err_buf);
+                               result = E_SS_FAILURE;
+                               goto Cleanup;
+                       }
+                       sink = ss_fileSink;
+                       tok = &output;
+               }
+               result = SS_ApplyBsdiff(source_filename, outname, part_filename, sink, tok, NULL);
+               LOGL(LOG_SSENGINE, "GenerateTarget Output is %d and result is %d\n", output, result);
+               if (output >= 0) {
+                       fsync(output);
+                       close(output);
+               }
+
+               if (result != S_SS_SUCCESS) {
+                       LOGE("applying patch failed %s\n", source_filename);
+                       if (outname != NULL)
+                               unlink(outname);
+                       goto Cleanup;
+               }
+               result = rename(outname, source_filename);
+               if (result != S_SS_SUCCESS) {
+                       LOGE("fatal error %s\n", source_filename);
+                       goto Cleanup;
+               }
+               if (file_name && strcmp(file_name, "piggy") == 0) {
+                       snprintf(cmd, sizeof(cmd) - 1,
+                                        "%s/gzip -n -9 -c %s/%s/%s > %s/%s/%s.gz",
+                                        SS_KERNEL_WORKSPACE, SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR, file_name,
+                                        SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR, file_name);
+                       result = _system_cmd_wait(cmd);
+                       LOGL(LOG_SSENGINE, "ret for %s = %d\n", cmd, result);
+                       unlink(source_filename);
+               }
+               unlink(part_filename);
+       }
+       //open new kernel file and append kernel parts to it in
+       snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_TARGET_NAME);
+       kp = fopen(source_filename, "w");
+       for (i = 0; i < 4; i++) {
+               snprintf(part_filename, sizeof(part_filename) - 1, "%s/%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR,
+                                kernel_parts[i]);
+               wp = fopen(part_filename, "r");
+               fseek(wp, SEEK_SET, SEEK_END);
+               j = ftell(wp);
+               fseek(wp, SEEK_SET, SEEK_SET);
+               while (j-- > 0) {
+                       a = fgetc(wp);
+                       if (a != EOF)
+                               fputc(a, kp);
+                       else
+                               break;
+               }
+               fclose(wp);
+               unlink(part_filename);
+       }
+       fclose(fp);
+       fp = NULL;
+       fclose(kp);
+
+       if (SS_LoadFile(source_filename, &source_file) == 0)
+               result = memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE);
+       if (result != S_SS_SUCCESS) {
+               LOGE("patch did not produce expected sha1 \n");
+               SS_SetUpgradeState(E_SS_IMGSHA_MISMATCH);
+               goto Cleanup;
+       }
+       //Considering EMMC partition by deafult
+
+       blk_cnt = ((ua_dataSS->update_cfg->target_img_size - 1) / SECTOR_SIZE) + 1;
+       result = write_to_blkdev((char *)ua_dataSS->parti_info->ua_blk_name, blk_start, blk_cnt, (char *)source_file.data);
+       if (result != S_SS_SUCCESS) {
+               LOGE("write of patched data to %s failed\n", ua_dataSS->parti_info->ua_blk_name);          // All returns should go to CLEAN UP.
+               SS_SetUpgradeState(E_SS_IMGFLASHWRITEFAIL);
+               goto Cleanup;
+       }
 
  Cleanup:
-    SS_BackupSourceClear();
-    SS_PatchSourceClear();
-    SS_DeleteFile(NULL, SS_KERN_UNPK_SCRIPT_PATH);
-    SS_DeleteFolder(NULL, SS_KERNEL_WORKSPACE);
-    SS_Free(buf);
-    SS_Free(outname);//wgid: 20740
-    if (result == S_SS_SUCCESS)
-        LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaKernel  SUCCESS *****************\n");
-    else{
-        LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaKernel  FAILED *****************\n");
-        if(fp)
-            fclose(fp);//wgid:14711
-    }
-    return result;
+       SS_BackupSourceClear();
+       SS_PatchSourceClear();
+       SS_DeleteFile(NULL, SS_KERN_UNPK_SCRIPT_PATH);
+       SS_DeleteFolder(NULL, SS_KERNEL_WORKSPACE);
+       SS_Free(buf);
+       SS_Free(outname);//wgid: 20740
+       if (result == S_SS_SUCCESS)
+               LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaKernel  SUCCESS *****************\n");
+       else{
+               LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaKernel  FAILED *****************\n");
+               if (fp)
+                       fclose(fp);//wgid:14711
+       }
+       return result;
 
 }
 
 /*!
  *********************************************************************************
- *                     SS_UpdateDeltaIMG
+ *                                      SS_UpdateDeltaIMG
  *********************************************************************************
  *
  * @brief
@@ -1106,146 +1096,145 @@ int SS_UpdateDeltaKernel(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *
 
 int SS_UpdateDeltaIMG(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *, int, int, char *))
 {
-    uint8_t target_sha1[SHA_DIGEST_SIZE];
-    uint8_t source_sha1[SHA_DIGEST_SIZE];
-    const uint8_t current_target_sha1[SHA_DIGEST_SIZE];
-    FileInfo source_file;
-    sha1_ctx_t ctx1;
-    MemorySinkInfo msi;
-    int result = S_SS_SUCCESS;
-    int blk_cnt;
-    int blk_start = 0;
-    int backupsrc = -1;
-    int use_backup_img = -1;
-    int fd = -1;
-    char buf[256];
-    if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-        LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-        return E_SS_FAILURE;
-    }
-
-    source_file.size = ua_dataSS->update_cfg->soure_img_size;
-    source_file.data = NULL;
-    if (0 == gvalid_session) {
-
-        if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
-            LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
-            return E_SS_FAILURE;
-        }
-
-        if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) == 0) {
-            if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Can be applied\n");
-                SS_Free(source_file.data);
-            } else if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Already applied\n");
-                SS_Free(source_file.data);
-                return S_SS_SUCCESS;
-            } else {
-                SS_Free(source_file.data);
-                source_file.data = NULL;
-                LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Source was currupted, Try loading from backup source\n");
-                if (SS_LoadPartition(SS_BACKUP_SOURCE, &source_file) == 0) {
-                    if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                        use_backup_img = 1;
-                        SS_Free(source_file.data);
-                        LOGL(LOG_SSENGINE,
-                             "SS_UpdateDeltaIMG - Patch Can be applied from using backup file as source\n");
-                    } else {
-                        SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
-                        SS_Free(source_file.data);
-                        return E_SS_FAILURE;
-                    }
-                }
-            }
-        }
-    }
-    if (use_backup_img == -1) {
-        backupsrc = SS_BackupSource(ua_dataSS->parti_info->ua_blk_name);
-        if (backupsrc != 0) {
-            LOGE("failed to Backup source File:[%s] \n", ua_dataSS->parti_info->ua_blk_name);
-            SS_SetUpgradeState(E_SS_IMGSRCBACKUPFAILED);
-            return E_SS_FAILURE;
-        }
-    }
-    SinkFn sink = NULL;
-    void *token = NULL;
-
-    blk_cnt = ((ua_dataSS->update_cfg->target_img_size - 1) / SECTOR_SIZE) + 1;
-
-    msi.buffer = SS_Malloc(blk_cnt * SECTOR_SIZE);
-    if (msi.buffer == NULL) {
-        LOGE("failed to alloc %ld bytes for output\n", (long)ua_dataSS->update_cfg->target_img_size);
-        SS_SetUpgradeState(E_SS_MALLOC_ERROR);
-        return E_SS_FAILURE;
-    }
-    msi.pos = 0;
-    msi.size = ua_dataSS->update_cfg->target_img_size;
-    sink = ss_memorySink;
-    token = &msi;
-
-    sha1_init(&ctx1);
-    //if souce was corrupted, use backup to apply diff
-    if (use_backup_img == -1)
-        result =
-            SS_ApplyBsdiff((char *)ua_dataSS->parti_info->ua_blk_name, NULL, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
-    else
-        result = SS_ApplyBsdiff(SS_BACKUP_SOURCE, NULL, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
-    if (result != S_SS_SUCCESS) {
-        LOGE("failed to SS_ApplyBsdiff\n");
-        SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
-        goto Cleanup;
-    }
-
-    sha1_final(&ctx1, (uint32_t *) & current_target_sha1);
-    result = memcmp(current_target_sha1, target_sha1, SHA_DIGEST_SIZE);
-    if (result != S_SS_SUCCESS) {
-        LOGE("patch did not produce expected sha1 \n");
-        SS_SetUpgradeState(E_SS_IMGSHA_MISMATCH);
-        goto Cleanup;
-    }
-    //Considering EMMC partition by deafult
-
-    if (ua_dataSS->update_cfg->update_type == DELTA_IMG) {
-        blk_cnt = ((ua_dataSS->update_cfg->target_img_size - 1) / SECTOR_SIZE) + 1;
-        result = write_to_blkdev((char *)ua_dataSS->parti_info->ua_blk_name, blk_start, blk_cnt, (char *)msi.buffer);
-        if (result != S_SS_SUCCESS) {
-            LOGE("write of patched data to %s failed\n", ua_dataSS->parti_info->ua_blk_name);   // All returns should go to CLEAN UP.
-            SS_SetUpgradeState(E_SS_IMGFLASHWRITEFAIL);
-            goto Cleanup;
-        }
-    } else if (ua_dataSS->update_cfg->update_type == EXTRA && ua_dataSS->update_data->ua_temp_path) {
-        fd = open(ua_dataSS->update_data->ua_temp_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
-        if (fd < 0) {
-            strerror_r(errno, buf, sizeof(buf));
-            LOGE("failed to open %s for write: %s\n", ua_dataSS->update_data->ua_temp_path, buf);
-            SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
-            result = E_SS_FAILURE;
-            goto Cleanup;
-        }
-        result = SS_WriteFile(NULL, fd, 0, msi.buffer, msi.size);
-        if (result != S_SS_SUCCESS) {
-            LOGE("failed to write\n");
-            SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
-            goto Cleanup;
-        }
-        fsync(fd);
-    }
-    else {
-        SS_SetUpgradeState(E_SS_IMGUPDATEFAILED);
-        result = E_SS_FAILURE;
-        LOGE("failed to apply patch - Invalid Update type params \n");
-    }
-
- Cleanup:
-    SS_BackupSourceClear();
-    SS_PatchSourceClear();
-    if (msi.buffer)
-        SS_Free(msi.buffer);
-    if (fd >= 0)
-        close(fd);
-    if (result == S_SS_SUCCESS)
-        LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaIMG  SUCCESS *****************\n");
-    return result;
+       uint8_t target_sha1[SHA_DIGEST_SIZE];
+       uint8_t source_sha1[SHA_DIGEST_SIZE];
+       const uint8_t current_target_sha1[SHA_DIGEST_SIZE];
+       FileInfo source_file;
+       sha1_ctx_t ctx1;
+       MemorySinkInfo msi;
+       int result = S_SS_SUCCESS;
+       int blk_cnt;
+       int blk_start = 0;
+       int backupsrc = -1;
+       int use_backup_img = -1;
+       int fd = -1;
+       char buf[256];
+       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
+               LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
+               return E_SS_FAILURE;
+       }
+
+       source_file.size = ua_dataSS->update_cfg->soure_img_size;
+       source_file.data = NULL;
+       if (0 == gvalid_session) {
+
+               if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
+                       LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
+                       return E_SS_FAILURE;
+               }
+
+               if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) == 0) {
+                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Can be applied\n");
+                               SS_Free(source_file.data);
+                       } else if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Already applied\n");
+                               SS_Free(source_file.data);
+                               return S_SS_SUCCESS;
+                       } else {
+                               SS_Free(source_file.data);
+                               source_file.data = NULL;
+                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Source was currupted, Try loading from backup source\n");
+                               if (SS_LoadPartition(SS_BACKUP_SOURCE, &source_file) == 0) {
+                                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                                               use_backup_img = 1;
+                                               SS_Free(source_file.data);
+                                               LOGL(LOG_SSENGINE,
+                                                        "SS_UpdateDeltaIMG - Patch Can be applied from using backup file as source\n");
+                                       } else {
+                                               SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
+                                               SS_Free(source_file.data);
+                                               return E_SS_FAILURE;
+                                       }
+                               }
+                       }
+               }
+       }
+       if (use_backup_img == -1) {
+               backupsrc = SS_BackupSource(ua_dataSS->parti_info->ua_blk_name);
+               if (backupsrc != 0) {
+                       LOGE("failed to Backup source File:[%s] \n", ua_dataSS->parti_info->ua_blk_name);
+                       SS_SetUpgradeState(E_SS_IMGSRCBACKUPFAILED);
+                       return E_SS_FAILURE;
+               }
+       }
+       SinkFn sink = NULL;
+       void *token = NULL;
+
+       blk_cnt = ((ua_dataSS->update_cfg->target_img_size - 1) / SECTOR_SIZE) + 1;
+
+       msi.buffer = SS_Malloc(blk_cnt * SECTOR_SIZE);
+       if (msi.buffer == NULL) {
+               LOGE("failed to alloc %ld bytes for output\n", (long)ua_dataSS->update_cfg->target_img_size);
+               SS_SetUpgradeState(E_SS_MALLOC_ERROR);
+               return E_SS_FAILURE;
+       }
+       msi.pos = 0;
+       msi.size = ua_dataSS->update_cfg->target_img_size;
+       sink = ss_memorySink;
+       token = &msi;
+
+       sha1_init(&ctx1);
+       //if souce was corrupted, use backup to apply diff
+       if (use_backup_img == -1)
+               result =
+                       SS_ApplyBsdiff((char *)ua_dataSS->parti_info->ua_blk_name, NULL, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
+       else
+               result = SS_ApplyBsdiff(SS_BACKUP_SOURCE, NULL, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
+       if (result != S_SS_SUCCESS) {
+               LOGE("failed to SS_ApplyBsdiff\n");
+               SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
+               goto Cleanup;
+       }
+
+       sha1_final(&ctx1, (uint32_t *) & current_target_sha1);
+       result = memcmp(current_target_sha1, target_sha1, SHA_DIGEST_SIZE);
+       if (result != S_SS_SUCCESS) {
+               LOGE("patch did not produce expected sha1 \n");
+               SS_SetUpgradeState(E_SS_IMGSHA_MISMATCH);
+               goto Cleanup;
+       }
+       //Considering EMMC partition by deafult
+
+       if (ua_dataSS->update_cfg->update_type == DELTA_IMG) {
+               blk_cnt = ((ua_dataSS->update_cfg->target_img_size - 1) / SECTOR_SIZE) + 1;
+               result = write_to_blkdev((char *)ua_dataSS->parti_info->ua_blk_name, blk_start, blk_cnt, (char *)msi.buffer);
+               if (result != S_SS_SUCCESS) {
+                       LOGE("write of patched data to %s failed\n", ua_dataSS->parti_info->ua_blk_name);   // All returns should go to CLEAN UP.
+                       SS_SetUpgradeState(E_SS_IMGFLASHWRITEFAIL);
+                       goto Cleanup;
+               }
+       } else if (ua_dataSS->update_cfg->update_type == EXTRA && ua_dataSS->update_data->ua_temp_path) {
+               fd = open(ua_dataSS->update_data->ua_temp_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
+               if (fd < 0) {
+                       strerror_r(errno, buf, sizeof(buf));
+                       LOGE("failed to open %s for write: %s\n", ua_dataSS->update_data->ua_temp_path, buf);
+                       SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
+                       result = E_SS_FAILURE;
+                       goto Cleanup;
+               }
+               result = SS_WriteFile(NULL, fd, 0, msi.buffer, msi.size);
+               if (result != S_SS_SUCCESS) {
+                       LOGE("failed to write\n");
+                       SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
+                       goto Cleanup;
+               }
+               fsync(fd);
+       } else {
+               SS_SetUpgradeState(E_SS_IMGUPDATEFAILED);
+               result = E_SS_FAILURE;
+               LOGE("failed to apply patch - Invalid Update type params \n");
+       }
+
+Cleanup:
+       SS_BackupSourceClear();
+       SS_PatchSourceClear();
+       if (msi.buffer)
+               SS_Free(msi.buffer);
+       if (fd >= 0)
+               close(fd);
+       if (result == S_SS_SUCCESS)
+               LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaIMG  SUCCESS *****************\n");
+       return result;
 
 }
index db54078..fd3bb66 100755 (executable)
 #define SS_UPDATE_IMG 1
 //#define SHA_DIGEST_SIZE 20
 typedef struct {
-    int type;
-    ssize_t size;
-    char *data;
+       int type;
+       ssize_t size;
+       char *data;
 } Value;
 typedef struct _Patch {
-    uint8_t sha1[SHA_DIGEST_SIZE];
-    const char *patch_filename;
+       uint8_t sha1[SHA_DIGEST_SIZE];
+       const char *patch_filename;
 } Patch;
 
 typedef struct _FileInfo {
-    unsigned char sha1[20];     //SHA_DIGEST_SIZE 20
-    unsigned char *data;
-    int size;
-    struct stat st;
+       unsigned char sha1[20];     //SHA_DIGEST_SIZE 20
+       unsigned char *data;
+       int size;
+       struct stat st;
 } FileInfo;
 
 typedef ssize_t(*SinkFn) (unsigned char *, ssize_t, void *);
@@ -53,11 +53,11 @@ int ParseSha1(const char *str, uint8_t * digest);
 
 void ShowBSDiffLicense();
 int ApplyBSDiffPatch(const unsigned char *old_data, ssize_t old_size,
-                     const Value * patch, ssize_t patch_offset, SinkFn sink, void *token, sha1_ctx_t * ctx1);
+               const Value * patch, ssize_t patch_offset, SinkFn sink, void *token, sha1_ctx_t * ctx1);
 int ApplyBSDiffPatchMem(const unsigned char *old_data, ssize_t old_size,
-                        const Value * patch, ssize_t patch_offset, unsigned char **new_data, ssize_t * new_size);
+               const Value * patch, ssize_t patch_offset, unsigned char **new_data, ssize_t * new_size);
 //int ApplyOptimizedBSDiffPatch(const unsigned char* old_data,void* token,
-//                                                                 const Value* patch, SinkFn sink,sha1_ctx_t* ctx1);
+//                              const Value* patch, SinkFn sink,sha1_ctx_t* ctx1);
 
 int SS_LoadPartition(const char *filename, FileInfo * file);
 int SS_LoadFile(const char *filename, FileInfo * file);
@@ -68,7 +68,7 @@ extern int SS_ApplyBsdiff(char *oldfile, char *newfile, char *patch, SinkFn sink
 extern int SS_BackupSourceClear();
 extern int SS_PatchSourceClear();
 extern long SS_WriteFile(void *pbUserData,
-                         long wHandle, SS_UINT32 dwPosition, unsigned char *pbBuffer, SS_UINT32 dwSize);
+               long wHandle, SS_UINT32 dwPosition, unsigned char *pbBuffer, SS_UINT32 dwSize);
 extern void SS_Free(void * pMemBlock);
 extern long SS_CopyFile(void * pbUserData, const char * strFromPath, const char * strToPath);
 extern long SS_DeleteFolder(void * pbUserData, const char * strPath);
index be6bbcd..aef89db 100755 (executable)
@@ -7,7 +7,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -42,7 +42,7 @@ Function Prototypes Mandatory
 
 int gtotalFSCnt = 0;
 int FS_UpgradeState = E_SS_FAILURE;
-int gvalid_session = 0;         //used as fail-safe in case device is turmed off or battery removed during update
+int gvalid_session = 0;                 //used as fail-safe in case device is turmed off or battery removed during update
 fs_list *fs_headptr_main = NULL;
 fs_list *headptr_list[UA_PARTI_MAX];
 tar_Data_t *tar_cfg_data = NULL;
@@ -60,38 +60,38 @@ tar_Data_t *tar_cfg_data = NULL;
 int mem_profiling_start = 0;
 int SS_Do_Memory_Profiling()
 {
-    int ret = -1;
-    pid_t pid;
-    char memory_usage_script[1024] = "#!/bin/bash\nlog_file=$1\npid=$2\nmaxmem=0\nwhile [[ -d \"/proc/${pid}\" ]]; do\n\
-   mem=`cat /proc/${pid}/smaps | grep Pss | grep -v Swap|awk '{print $2}'|awk '{s+=$1} END {print s}'`\n\
-        if [[ ${mem} -gt ${maxmem} ]]; then\n          maxmem=${mem}\n\
-               echo -e \"Memory usage till now is: ${maxmem} KB.\" >> $log_file\n      fi\n    sleep 0.01\ndone\n\
-   echo -e \"Max was : ${maxmem} KB.\" >> $log_file\n";
-    char cmd[1024] = { 0, };
-
-    //Open a file and write the script contents in it
-    FILE *fp = fopen(SS_MEMORY_PROFILING_SCRIPT, "w+");
-    fwrite(memory_usage_script, strlen(memory_usage_script), 1, fp);
-    fclose(fp);
-    //make the file executable      -       Octal 495 is 757 decimal
-    if (chmod(SS_MEMORY_PROFILING_SCRIPT, 495) < 0) {
-        LOGE("Error in chmod(%s, 495) - %d (%s)\n", SS_MEMORY_PROFILING_SCRIPT, errno, strerror(errno));
-        return E_SS_FAILURE;
-    }
-    //calling mem_use.sh
-    //Usage : <location of script> <location of log file to be created> <pid of the calling process>
-    pid = getpid();
-    snprintf(cmd, sizeof(cmd) - 1, "%s %s %d", SS_MEMORY_PROFILING_SCRIPT, SS_MEMORY_USAGE_LOG, pid);
-    ret = _system_cmd_nowait(cmd);
-    sleep(1);
-    LOG("ret for memory profiling cmd is %d\n", ret);
-    if (ret == 0) {
-        mem_profiling_start = 1;
-        return S_SS_SUCCESS;
-    } else {
-        LOGE("Could not start Memory Profiling\n");
-        return E_SS_FAILURE;
-    }
+       int ret = -1;
+       pid_t pid;
+       char memory_usage_script[1024] = "#!/bin/bash\nlog_file=$1\npid=$2\nmaxmem=0\nwhile [[ -d \"/proc/${pid}\" ]]; do\n\
+                                         mem=`cat /proc/${pid}/smaps | grep Pss | grep -v Swap|awk '{print $2}'|awk '{s+=$1} END {print s}'`\n\
+                                         if [[ ${mem} -gt ${maxmem} ]]; then\nmaxmem=${mem}\n\
+                                                 echo -e \"Memory usage till now is: ${maxmem} KB.\" >> $log_file\n    fi\n    sleep 0.01\ndone\n\
+                                                         echo -e \"Max was : ${maxmem} KB.\" >> $log_file\n";
+       char cmd[1024] = { 0, };
+
+       //Open a file and write the script contents in it
+       FILE *fp = fopen(SS_MEMORY_PROFILING_SCRIPT, "w+");
+       fwrite(memory_usage_script, strlen(memory_usage_script), 1, fp);
+       fclose(fp);
+       //make the file executable        -        Octal 495 is 757 decimal
+       if (chmod(SS_MEMORY_PROFILING_SCRIPT, 495) < 0) {
+               LOGE("Error in chmod(%s, 495) - %d (%s)\n", SS_MEMORY_PROFILING_SCRIPT, errno, strerror(errno));
+               return E_SS_FAILURE;
+       }
+       //calling mem_use.sh
+       //Usage : <location of script> <location of log file to be created> <pid of the calling process>
+       pid = getpid();
+       snprintf(cmd, sizeof(cmd) - 1, "%s %s %d", SS_MEMORY_PROFILING_SCRIPT, SS_MEMORY_USAGE_LOG, pid);
+       ret = _system_cmd_nowait(cmd);
+       sleep(1);
+       LOG("ret for memory profiling cmd is %d\n", ret);
+       if (ret == 0) {
+               mem_profiling_start = 1;
+               return S_SS_SUCCESS;
+       } else {
+               LOGE("Could not start Memory Profiling\n");
+               return E_SS_FAILURE;
+       }
 }
 #endif
 
@@ -104,264 +104,261 @@ double SS_FSBuildNodes_time = 0.0;
 
 static void get_time_stamp1(void)
 {
-    struct timeval tv;
-    int sec, msec;
+       struct timeval tv;
+       int sec, msec;
 
-    gettimeofday(&tv, NULL);
-    sec = (int)tv.tv_sec;
-    msec = (int)(tv.tv_usec / 1000);
-    snprintf(ts1, 256, "%06d.%03d", sec % 100000, msec);
+       gettimeofday(&tv, NULL);
+       sec = (int)tv.tv_sec;
+       msec = (int)(tv.tv_usec / 1000);
+       snprintf(ts1, 256, "%06d.%03d", sec % 100000, msec);
 }
 
 static double get_time_stamp2(void)
 {
-    struct timeval tv;
+       struct timeval tv;
 
-    gettimeofday(&tv, NULL);
-    ts2 = (double)tv.tv_sec + (double)(tv.tv_usec / 1000000.0);
-    return ts2;
+       gettimeofday(&tv, NULL);
+       ts2 = (double)tv.tv_sec + (double)(tv.tv_usec / 1000000.0);
+       return ts2;
 }
 #endif
 
 //Check SS function if available
 int file_exist(char *filename, int type)
 {
-    struct stat buf;
-    int ret = 0;
-
-    ret = lstat(filename, &buf);
-    if (ret < 0) {
-        ret = stat(filename, &buf);
-    }
-    return (ret >= 0) ? (1) : (0);
+       struct stat buf;
+       int ret = 0;
+
+       ret = lstat(filename, &buf);
+       if (ret < 0)
+               ret = stat(filename, &buf);
+       return (ret >= 0) ? (1) : (0);
 }
 
 long SS_GetUPIVersion(unsigned char *ver_str)
 {
-    if (ver_str) {
-        strncpy((char *)ver_str, SS_TOTA_VERSION, MAX_PATH);
+       if (ver_str) {
+               strncpy((char *)ver_str, SS_TOTA_VERSION, MAX_PATH);
 #ifdef MEM_PROFILING
-        if (!mem_profiling_start)
-            if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
-                LOGE("Unable to start Memory_Profiling");
+               if (!mem_profiling_start)
+                       if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
+                               LOGE("Unable to start Memory_Profiling");
 #endif
-        return S_SS_SUCCESS;//wgid: 2456
-    } else
-        return E_SS_FAILURE;
+               return S_SS_SUCCESS;//wgid: 2456
+       } else
+               return E_SS_FAILURE;
 }
 
 int SS_CalculateFileSha(char *filename, int filesize, FileInfo * file)
 {
 
-    FILE *fp = NULL;
-    int ulResult = S_SS_SUCCESS;
-    int chunk = 20*1024*1024;
-    char buf[256];
-
-    fp = fopen(filename, "rb");
-    if (fp == NULL) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("failed to open \"%s\": %s\n", filename, buf);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    file->data = SS_Malloc(chunk);
-    if (!file->data) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("failed to allocate memory for \"%s\": %s\n", filename, buf);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    ssize_t bytes_read = 0;
-    sha1_ctx_t sha_ctx;
-    sha1_init(&sha_ctx);
-
-    while( filesize > 0){
-        if(filesize < chunk){
-            bytes_read = fread(file->data, 1, filesize, fp);
-            if (bytes_read != filesize) {
-                LOGE("short read of \"%s\" (%ld bytes of %ld)\n", filename, (long)bytes_read, (long)file->size);
-                ulResult = E_SS_FAILURE;
-                goto Cleanup;
-            }
-            sha1_update(&sha_ctx, file->data, filesize);
-            break;
-        }
-        else {
-            bytes_read = fread(file->data, 1, chunk, fp);
-            if (bytes_read != chunk) {
-                LOGE("short read of \"%s\" (%ld bytes of %ld)\n", filename, (long)bytes_read, (long)file->size);
-                ulResult = E_SS_FAILURE;
-                goto Cleanup;
-            }
-            sha1_update(&sha_ctx, file->data, chunk);
-            filesize -= chunk;
-        }
-    }
-
-    sha1_final(&sha_ctx, (uint32_t *) &file->sha1);
+       FILE *fp = NULL;
+       int ulResult = S_SS_SUCCESS;
+       int chunk = 20*1024*1024;
+       char buf[256];
+
+       fp = fopen(filename, "rb");
+       if (fp == NULL) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("failed to open \"%s\": %s\n", filename, buf);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       file->data = SS_Malloc(chunk);
+       if (!file->data) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("failed to allocate memory for \"%s\": %s\n", filename, buf);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       ssize_t bytes_read = 0;
+       sha1_ctx_t sha_ctx;
+       sha1_init(&sha_ctx);
+
+       while (filesize > 0) {
+               if (filesize < chunk) {
+                       bytes_read = fread(file->data, 1, filesize, fp);
+                       if (bytes_read != filesize) {
+                               LOGE("short read of \"%s\" (%ld bytes of %ld)\n", filename, (long)bytes_read, (long)file->size);
+                               ulResult = E_SS_FAILURE;
+                               goto Cleanup;
+                       }
+                       sha1_update(&sha_ctx, file->data, filesize);
+                       break;
+               } else {
+                       bytes_read = fread(file->data, 1, chunk, fp);
+                       if (bytes_read != chunk) {
+                               LOGE("short read of \"%s\" (%ld bytes of %ld)\n", filename, (long)bytes_read, (long)file->size);
+                               ulResult = E_SS_FAILURE;
+                               goto Cleanup;
+                       }
+                       sha1_update(&sha_ctx, file->data, chunk);
+                       filesize -= chunk;
+               }
+       }
+
+       sha1_final(&sha_ctx, (uint32_t *) &file->sha1);
 
 Cleanup:
-    if(fp)
-        fclose(fp);
-    if(file->data)
-        SS_Free(file->data);
-    return ulResult;
+       if (fp)
+               fclose(fp);
+       if (file->data)
+               SS_Free(file->data);
+       return ulResult;
 }
 
 int SS_verify_DELTA_image(char *filename)
 {
 
-    FileInfo file;
-    FILE *fp = NULL;
-    char line[SS_TOKEN_MAXLINE_LEN] = { '\0' };
-    char * delta_size = NULL;
-    char *signature = NULL;
-    char * sha1trg = NULL;
-    char *saveptr;
-    uint8_t target_sha1[SHA_DIGEST_SIZE] = { 0, };
-    char cmd[512] = { 0, };
-    char buf[256];
-    int udelta_size = 0;
-    int ulResult = S_SS_SUCCESS;
-
-    if (stat(filename, &file.st) != 0) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("failed to stat \"%s\": %s\n", filename, buf);
-        return -1;
-    }
-
-    snprintf(cmd, sizeof(cmd) - 1, "grep -o -P '%s' --binary-files=text system/%s > %s",
-                SS_IMAGE_MAGIC_KEY,filename, SS_IMAGE_MAGIC_KEY_VAL);
-
-    ulResult = _system_cmd_wait(cmd);
-    if (ulResult != S_SS_SUCCESS) {
-        LOGE("Grep extraction for [%s] failed, code [%d]\n", cmd, ulResult);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    fp = fopen(SS_IMAGE_MAGIC_KEY_VAL, "r");
-    if (!fp) {
-        LOGE("Grep extraction for [%s] failed, code [%d]\n", cmd, ulResult);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL){
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-    fclose(fp);
-    fp = NULL;
-
-    signature = strtok_r(line, SS_TOEKN_COLON, &saveptr);
-    delta_size = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-    sha1trg = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-
-    if (signature && sha1trg && delta_size) {
-        udelta_size = atoi(delta_size);
+       FileInfo file;
+       FILE *fp = NULL;
+       char line[SS_TOKEN_MAXLINE_LEN] = { '\0' };
+       char * delta_size = NULL;
+       char *signature = NULL;
+       char * sha1trg = NULL;
+       char *saveptr;
+       uint8_t target_sha1[SHA_DIGEST_SIZE] = { 0, };
+       char cmd[512] = { 0, };
+       char buf[256];
+       int udelta_size = 0;
+       int ulResult = S_SS_SUCCESS;
+
+       if (stat(filename, &file.st) != 0) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("failed to stat \"%s\": %s\n", filename, buf);
+               return -1;
+       }
+
+       snprintf(cmd, sizeof(cmd) - 1, "grep -o -P '%s' --binary-files=text system/%s > %s",
+                               SS_IMAGE_MAGIC_KEY, filename, SS_IMAGE_MAGIC_KEY_VAL);
+
+       ulResult = _system_cmd_wait(cmd);
+       if (ulResult != S_SS_SUCCESS) {
+               LOGE("Grep extraction for [%s] failed, code [%d]\n", cmd, ulResult);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       fp = fopen(SS_IMAGE_MAGIC_KEY_VAL, "r");
+       if (!fp) {
+               LOGE("Grep extraction for [%s] failed, code [%d]\n", cmd, ulResult);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+       fclose(fp);
+       fp = NULL;
+
+       signature = strtok_r(line, SS_TOEKN_COLON, &saveptr);
+       delta_size = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+       sha1trg = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+
+       if (signature && sha1trg && delta_size) {
+               udelta_size = atoi(delta_size);
        if (udelta_size < 0)
-                LOGE("Invalid udelta_size %d (%s)\n", udelta_size, delta_size);
-        LOGL(LOG_SSENGINE, "delta_size %d sha1trg %s\n", udelta_size, sha1trg);
-    }
-    else {
-        LOGE("Could not parse signature [%s]\n", line);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    if (ParseSha1(sha1trg, target_sha1) != 0) {
-        LOGE("failed to parse tgt-sha1 \"%s\"\n", sha1trg);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    ulResult = SS_CalculateFileSha(filename, udelta_size, &file);
-    if (ulResult != S_SS_SUCCESS)
-        goto Cleanup;
-
-    if(memcmp(file.sha1, target_sha1, SHA_DIGEST_SIZE) != 0){
-        LOGE("SHA mismatch -[%s] actual [%x] target [%x]\n", filename, file.sha1, target_sha1);
-        SS_SetUpgradeState(E_SS_FSBADDELTA);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-    else
-        LOGL(LOG_SSENGINE, "DELTA verified %s \n", sha1trg);
+                               LOGE("Invalid udelta_size %d (%s)\n", udelta_size, delta_size);
+               LOGL(LOG_SSENGINE, "delta_size %d sha1trg %s\n", udelta_size, sha1trg);
+       } else {
+               LOGE("Could not parse signature [%s]\n", line);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       if (ParseSha1(sha1trg, target_sha1) != 0) {
+               LOGE("failed to parse tgt-sha1 \"%s\"\n", sha1trg);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       ulResult = SS_CalculateFileSha(filename, udelta_size, &file);
+       if (ulResult != S_SS_SUCCESS)
+               goto Cleanup;
+
+       if (memcmp(file.sha1, target_sha1, SHA_DIGEST_SIZE) != 0) {
+               LOGE("SHA mismatch -[%s] actual [%x] target [%x]\n", filename, file.sha1, target_sha1);
+               SS_SetUpgradeState(E_SS_FSBADDELTA);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       } else {
+               LOGL(LOG_SSENGINE, "DELTA verified %s \n", sha1trg);
+       }
 
 Cleanup:
-    if(fp)
-        fclose(fp);
-    if(file_exist(SS_IMAGE_MAGIC_KEY_VAL, 0))
-        SS_DeleteFile(NULL, SS_IMAGE_MAGIC_KEY_VAL);
-    return ulResult;
+       if (fp)
+               fclose(fp);
+       if (file_exist(SS_IMAGE_MAGIC_KEY_VAL, 0))
+               SS_DeleteFile(NULL, SS_IMAGE_MAGIC_KEY_VAL);
+       return ulResult;
 }
 
 
 int SS_GetProgressResolution(int ultotalFSCnt)
 {
-    if (ultotalFSCnt < DISPLAYRESOLUTION_SIZE)
-        return 1;
-    else
-        return (ultotalFSCnt / DISPLAYRESOLUTION_SIZE);
+       if (ultotalFSCnt < DISPLAYRESOLUTION_SIZE)
+               return 1;
+       else
+               return (ultotalFSCnt / DISPLAYRESOLUTION_SIZE);
 }
 
 void SS_SetUpgradeState(int Val)
 {
-    LOGE("FAILED to upgrade Cause:[0x%x]\n", Val);
-    FS_UpgradeState = Val;
-    return;
+       LOGE("FAILED to upgrade Cause:[0x%x]\n", Val);
+       FS_UpgradeState = Val;
+       return;
 }
 
 int SS_GetUpgradeState()
 {
-    return FS_UpgradeState;
+       return FS_UpgradeState;
 }
 
 int SS_rename(const char *old_file_name, const char *new_file_name)
 {
-    if (link(old_file_name, new_file_name) < 0) {
-        if (errno == EEXIST) {
-            if (unlink(new_file_name) < 0 || link(old_file_name, new_file_name) < 0)
-                return -1;
-        } else
-            return -1;
-    }
-    if (unlink(old_file_name) < 0) {
-        if (unlink(new_file_name) == 0)
-            return -1;
-    }
-    return 0;
+       if (link(old_file_name, new_file_name) < 0) {
+               if (errno == EEXIST) {
+                       if (unlink(new_file_name) < 0 || link(old_file_name, new_file_name) < 0)
+                               return -1;
+               } else
+                       return -1;
+       }
+       if (unlink(old_file_name) < 0) {
+               if (unlink(new_file_name) == 0)
+                       return -1;
+       }
+       return 0;
 }
 
 int SS_rename1(const char *old_file_name, const char *new_file_name)
 {
 
-    int result = E_SS_FAILURE;
-    char *temp_name = NULL;
-    temp_name = (char *)SS_Malloc(strlen(new_file_name) + 10);
-    if (temp_name == NULL)
-        return E_SS_FAILURE;
-    snprintf(temp_name, strlen(new_file_name) + 10, "%s.temp", new_file_name);
-    result = rename(new_file_name, temp_name);
-    if (result != 0)
-        goto Cleanup;
-    result = rename(old_file_name, new_file_name);
-    if (result != 0)
-        goto Cleanup;
-    result = unlink(temp_name);
+       int result = E_SS_FAILURE;
+       char *temp_name = NULL;
+       temp_name = (char *)SS_Malloc(strlen(new_file_name) + 10);
+       if (temp_name == NULL)
+               return E_SS_FAILURE;
+       snprintf(temp_name, strlen(new_file_name) + 10, "%s.temp", new_file_name);
+       result = rename(new_file_name, temp_name);
+       if (result != 0)
+               goto Cleanup;
+       result = rename(old_file_name, new_file_name);
+       if (result != 0)
+               goto Cleanup;
+       result = unlink(temp_name);
  Cleanup:
-    if (temp_name)
-        SS_Free(temp_name);
-    return result;
+       if (temp_name)
+               SS_Free(temp_name);
+       return result;
 }
 
 /*!
  *********************************************************************************
- *                     SS_FSVerifyNode
+ *                                      SS_FSVerifyNode
  *********************************************************************************
  *
  * @brief
@@ -377,71 +374,72 @@ int SS_rename1(const char *old_file_name, const char *new_file_name)
  *********************************************************************************
  */
 int SS_FSVerifyNode(const char *ubDeltaPath, const char *path, const char *patchname, const char *sha1src, int type,
-                    char *patchpath_name, int *data_size, int *data_offset)
+                                       char *patchpath_name, int *data_size, int *data_offset)
 {
-    char patch[MAX_FILE_PATH] = { 0 };
-    FileInfo source_file;
-    uint8_t source_sha1[SHA_DIGEST_SIZE];
-
-    if (gvalid_session) {
-        if ((type == DIFFS || type == DELETES || type == MOVES) && !file_exist((char *)path, type)) {
-            LOGE("failed to verifyNodes [does not exist], Path : [%s] Type[%d]\n", path, type);
-            SS_SetUpgradeState(E_SS_FSBADNODES);
-            return E_SS_FAILURE;
-        }
-        snprintf(patch, MAX_FILE_PATH, "%s%s%s", patchpath_name, "/", patchname);
-        if ((type == DIFFS /*||type == NEWFILES */ ))   // allowing size 0 also for folders
-        {
-            if (tar_get_item_size_from_struct(&tar_cfg_data, patchname, data_size, data_offset) != S_SS_SUCCESS) {
-                LOGE("failed to get item size from struct, Patch : [%s]\n", patchname);
-                SS_SetUpgradeState(E_SS_FSBADNODES);
-                return E_SS_FAILURE;
-            }
-            if (*data_size < 0) {
-                LOGE("failed to verifyNodes [delta absent], Patch : [%s] Type[%d]\n", patch, type);
-                SS_SetUpgradeState(E_SS_FSBADNODES);
-                return E_SS_FAILURE;
-            }
-        }
-        //For other types (NEWs, SYMs, Folders), SHA check not required
-        if ((type == DIFFS || type == MOVES /* ||type == DELETES */ ) && (strcmp(sha1src, SS_NULLENTRY) != 0)) {
-            if (ParseSha1(sha1src, source_sha1) != 0) {
-                LOGE("Failed to parse Src-sha1 \"%s\"\n", sha1src);
-                return E_SS_FAILURE;
-            }
-            if (SS_LoadFile(path, &source_file) == 0) {
-                if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) != 0) {
-                    SS_Free(source_file.data);
-                    LOGE("SS_FSVerifyNode - SHA mismatch with SRC  - PATH [%s]\n", path);
-                    SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);    // Define other error
-                    return E_SS_FAILURE;
-                }
-            }
-            SS_Free(source_file.data);
-        }
-    } else {
-        LOGL(LOG_SSENGINE, "FS partition Already verified - Filling only size and offset \n");
-        snprintf(patch, MAX_FILE_PATH, "%s%s%s", patchpath_name, "/", patchname);
-        if ((type == DIFFS /*||type == NEWFILES */ ))   // allowing size 0 also for folders
-        {
-            if (tar_get_item_size_from_struct(&tar_cfg_data, patchname, data_size, data_offset) != S_SS_SUCCESS) {
-                LOGE("failed to get item size from struct, Patch : [%s] \n", patchname);
-                SS_SetUpgradeState(E_SS_FSBADNODES);
-                return E_SS_FAILURE;
-            }
-            if (*data_size < 0) {
-                LOGE("failed to verifyNodes [delta absent], Patch : [%s] Type[%d]\n", patch, type);
-                SS_SetUpgradeState(E_SS_FSBADNODES);
-                return E_SS_FAILURE;
-            }
-        }
-    }
-    return S_SS_SUCCESS;
+       char patch[MAX_FILE_PATH] = { 0 };
+       FileInfo source_file;
+       uint8_t source_sha1[SHA_DIGEST_SIZE];
+
+       if (gvalid_session) {
+               if ((type == DIFFS || type == DELETES || type == MOVES) && !file_exist((char *)path, type)) {
+                       LOGE("failed to verifyNodes [does not exist], Path : [%s] Type[%d]\n", path, type);
+                       SS_SetUpgradeState(E_SS_FSBADNODES);
+                       return E_SS_FAILURE;
+               }
+               snprintf(patch, MAX_FILE_PATH, "%s%s%s", patchpath_name, "/", patchname);
+               if ((type == DIFFS/*||type == NEWFILES */)) {   // allowing size 0 also for folders
+                       if (tar_get_item_size_from_struct(&tar_cfg_data, patchname, data_size, data_offset)
+                                       != S_SS_SUCCESS) {
+                               LOGE("failed to get item size from struct, Patch : [%s]\n", patchname);
+                               SS_SetUpgradeState(E_SS_FSBADNODES);
+                               return E_SS_FAILURE;
+                       }
+                       if (*data_size < 0) {
+                               LOGE("failed to verifyNodes [delta absent], Patch : [%s] Type[%d]\n", patch, type);
+                               SS_SetUpgradeState(E_SS_FSBADNODES);
+                               return E_SS_FAILURE;
+                       }
+               }
+               //For other types (NEWs, SYMs, Folders), SHA check not required
+               if ((type == DIFFS || type == MOVES/* ||type == DELETES */) &&
+                               (strcmp(sha1src, SS_NULLENTRY) != 0)) {
+                       if (ParseSha1(sha1src, source_sha1) != 0) {
+                               LOGE("Failed to parse Src-sha1 \"%s\"\n", sha1src);
+                               return E_SS_FAILURE;
+                       }
+                       if (SS_LoadFile(path, &source_file) == 0) {
+                               if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) != 0) {
+                                       SS_Free(source_file.data);
+                                       LOGE("SS_FSVerifyNode - SHA mismatch with SRC  - PATH [%s]\n", path);
+                                       SS_SetUpgradeState(E_SS_FSSRCCURRUPTED);        // Define other error
+                                       return E_SS_FAILURE;
+                               }
+                       }
+                       SS_Free(source_file.data);
+               }
+       } else {
+               LOGL(LOG_SSENGINE, "FS partition Already verified - Filling only size and offset \n");
+               snprintf(patch, MAX_FILE_PATH, "%s%s%s", patchpath_name, "/", patchname);
+               if ((type == DIFFS/* ||type == NEWFILES */)) {   // allowing size 0 also for folders
+                       if (tar_get_item_size_from_struct(&tar_cfg_data, patchname, data_size, data_offset)
+                                       != S_SS_SUCCESS) {
+                               LOGE("failed to get item size from struct, Patch : [%s] \n", patchname);
+                               SS_SetUpgradeState(E_SS_FSBADNODES);
+                               return E_SS_FAILURE;
+                       }
+                       if (*data_size < 0) {
+                               LOGE("failed to verifyNodes [delta absent], Patch : [%s] Type[%d]\n", patch, type);
+                               SS_SetUpgradeState(E_SS_FSBADNODES);
+                               return E_SS_FAILURE;
+                       }
+               }
+       }
+       return S_SS_SUCCESS;
 }
 
 /*!
  *********************************************************************************
- *                     SS_AppendNode
+ *                                      SS_AppendNode
  *********************************************************************************
  *
  * @brief
@@ -456,84 +454,81 @@ int SS_FSVerifyNode(const char *ubDeltaPath, const char *path, const char *patch
  *********************************************************************************
  */
 int SS_AppendNode(const char *ubDeltaPath, fs_params ** headparam, fs_params ** tailparam, const char *old_path,
-                  const char *new_path, const char *patchname, const char *sha1src, const char *sha1trg, int type,
-                  char *patchpath_name)
+                                 const char *new_path, const char *patchname, const char *sha1src, const char *sha1trg, int type,
+                                 char *patchpath_name)
 {
-    fs_params *newnode = NULL;
-    int data_size = 0;
-    int data_offset = 0;
-
-    if (!ubDeltaPath || !old_path || !new_path || !patchname || !sha1src || !sha1trg || !patchpath_name) {
-        LOGE("Bad Nodes, NULL params passed for Appending Nodes \n");
-        SS_SetUpgradeState(E_SS_FSINVALIDNODEPARAMS);
-        return E_SS_FAILURE;
-    }
-    if ((E_SS_FAILURE ==
-         SS_FSVerifyNode(ubDeltaPath, old_path, patchname, sha1src, type, patchpath_name, &data_size, &data_offset))) {
-        LOGE("Bad Nodes, Failed to pass verification - [Delta Path - %s][OldPath - %s] [NewPath - %s] \n", ubDeltaPath,
-             old_path, new_path);
-        return E_SS_FAILURE;
-    }
-    newnode = (fs_params *) SS_Malloc(sizeof(fs_params));
-    if (!newnode)
-        return E_SS_FAILURE;
-    strncpy(newnode->file_old_path, old_path, SS_MAX_NAMELENSUPPORTED);//wgid: 29483
-    strncpy(newnode->file_new_path, new_path, SS_MAX_NAMELENSUPPORTED);//wgid: 29482
-    strncpy(newnode->patch_name, patchname, SS_MAX_NAMELENSUPPORTED);//wgid: 28033
-    strncpy(newnode->sha1src, sha1src, sizeof(newnode->sha1src) -1);//wgid: 25282
-    strncpy(newnode->sha1trg, sha1trg, sizeof(newnode->sha1trg) - 1);//wgid: 25283
-    newnode->type = type;
-    newnode->data_size = data_size;
-    newnode->data_offset = data_offset;
-    newnode->nextnode = NULL;
-
-    //LOG("%s %s %d %s %s \n",newnode->file_path,newnode->patch_name,newnode->type, newnode->sha1src, newnode->sha1trg);
-
-    if (*headparam == NULL) {
-        *headparam = newnode;
-        *tailparam = newnode;
-    } else {
-        (*tailparam)->nextnode = newnode;
-        (*tailparam) = (*tailparam)->nextnode;
-    }
-    return S_SS_SUCCESS;
+       fs_params *newnode = NULL;
+       int data_size = 0;
+       int data_offset = 0;
+
+       if (!ubDeltaPath || !old_path || !new_path || !patchname || !sha1src || !sha1trg || !patchpath_name) {
+               LOGE("Bad Nodes, NULL params passed for Appending Nodes \n");
+               SS_SetUpgradeState(E_SS_FSINVALIDNODEPARAMS);
+               return E_SS_FAILURE;
+       }
+       if ((E_SS_FAILURE ==
+                SS_FSVerifyNode(ubDeltaPath, old_path, patchname, sha1src, type, patchpath_name, &data_size, &data_offset))) {
+               LOGE("Bad Nodes, Failed to pass verification - [Delta Path - %s][OldPath - %s] [NewPath - %s] \n", ubDeltaPath,
+                        old_path, new_path);
+               return E_SS_FAILURE;
+       }
+       newnode = (fs_params *) SS_Malloc(sizeof(fs_params));
+       if (!newnode)
+               return E_SS_FAILURE;
+       strncpy(newnode->file_old_path, old_path, SS_MAX_NAMELENSUPPORTED);//wgid: 29483
+       strncpy(newnode->file_new_path, new_path, SS_MAX_NAMELENSUPPORTED);//wgid: 29482
+       strncpy(newnode->patch_name, patchname, SS_MAX_NAMELENSUPPORTED);//wgid: 28033
+       strncpy(newnode->sha1src, sha1src, sizeof(newnode->sha1src) -1);//wgid: 25282
+       strncpy(newnode->sha1trg, sha1trg, sizeof(newnode->sha1trg) - 1);//wgid: 25283
+       newnode->type = type;
+       newnode->data_size = data_size;
+       newnode->data_offset = data_offset;
+       newnode->nextnode = NULL;
+
+       //LOG("%s %s %d %s %s \n",newnode->file_path,newnode->patch_name,newnode->type, newnode->sha1src, newnode->sha1trg);
+
+       if (*headparam == NULL) {
+               *headparam = newnode;
+               *tailparam = newnode;
+       } else {
+               (*tailparam)->nextnode = newnode;
+               (*tailparam) = (*tailparam)->nextnode;
+       }
+       return S_SS_SUCCESS;
 
 }
 
 void SS_UpdateUIProgress(ua_dataSS_t * ua_dataSS, int ulTotalFsCnt, int ulDone)
 {
-
-    static int ss_count = 1;
-    int res_val = SS_GetProgressResolution(ulTotalFsCnt);
-    if (!ua_dataSS) {
-        LOGE("Error ua_dataSS\n");
-        return;
-    }
+       static int ss_count = 1;
+       int res_val = SS_GetProgressResolution(ulTotalFsCnt);
+       if (!ua_dataSS) {
+               LOGE("Error ua_dataSS\n");
+               return;
+       }
 //LOG("\nvalues are ss_count[%d] total_file_cnt[%d]",ss_count,ulTotalFsCnt);
-    if (ulDone == 1) {
-        if (ua_dataSS->ui_progress)
-            ua_dataSS->ui_progress(ua_dataSS, 100);
-        ss_count = 1;
-    } else if (ss_count < ulTotalFsCnt) {
-
-        if (ss_count % res_val == 0 /* && ss_iterator <= 2 */ ) //Max 50 times display
-        {
-            double data = (double)ss_count / (double)ulTotalFsCnt;
-            if (ua_dataSS->ui_progress)
-                ua_dataSS->ui_progress(ua_dataSS, data * 100);
-        }
-        ss_count++;
-    } else {
-        if (ua_dataSS->ui_progress)
-            ua_dataSS->ui_progress(ua_dataSS, 100);
-        ss_count = 1;
-    }
+       if (ulDone == 1) {
+               if (ua_dataSS->ui_progress)
+                       ua_dataSS->ui_progress(ua_dataSS, 100);
+               ss_count = 1;
+       } else if (ss_count < ulTotalFsCnt) {
+               if (ss_count % res_val == 0) { //Max 50 times display
+                       double data = (double)ss_count / (double)ulTotalFsCnt;
+                       if (ua_dataSS->ui_progress)
+                               ua_dataSS->ui_progress(ua_dataSS, data * 100);
+               }
+               ss_count++;
+       } else {
+               if (ua_dataSS->ui_progress)
+                       ua_dataSS->ui_progress(ua_dataSS, 100);
+               ss_count = 1;
+       }
 
 }
 
 /*!
  *********************************************************************************
- *                     SS_FSClearNodes
+ *                                      SS_FSClearNodes
  *********************************************************************************
  *
  * @brief
@@ -548,66 +543,66 @@ void SS_UpdateUIProgress(ua_dataSS_t * ua_dataSS, int ulTotalFsCnt, int ulDone)
  */
 void SS_FSClearNodes(int idx)
 {
-    fs_params *local_temp = NULL;
-    fs_params *local_next = NULL;
-    LOGL(LOG_SSENGINE, "Free Nodes idx=%d \n", idx);
-    if (headptr_list[idx]) {
-        if (headptr_list[idx]->del_ref) {
-            local_temp = headptr_list[idx]->del_ref;
-            while (local_temp) {
-                local_next = local_temp->nextnode;
-                SS_Free(local_temp);
-                local_temp = local_next;
-            }
-        }
-        if (headptr_list[idx]->dif_ref) {
-            local_temp = headptr_list[idx]->dif_ref;
-            while (local_temp) {
-                local_next = local_temp->nextnode;
-                SS_Free(local_temp);
-                local_temp = local_next;
-            }
-        }
-        if (headptr_list[idx]->move_ref) {
-            local_temp = headptr_list[idx]->move_ref;
-            while (local_temp) {
-                local_next = local_temp->nextnode;
-                SS_Free(local_temp);
-                local_temp = local_next;
-            }
-        }
-        if (headptr_list[idx]->new_ref) {
-            local_temp = headptr_list[idx]->new_ref;
-            while (local_temp) {
-                local_next = local_temp->nextnode;
-                SS_Free(local_temp);
-                local_temp = local_next;
-            }
-        }
-        if (headptr_list[idx]->sym_difref) {
-            local_temp = headptr_list[idx]->sym_difref;
-            while (local_temp) {
-                local_next = local_temp->nextnode;
-                SS_Free(local_temp);
-                local_temp = local_next;
-            }
-        }
-        if (headptr_list[idx]->sym_newref) {
-            local_temp = headptr_list[idx]->sym_newref;
-            while (local_temp) {
-                local_next = local_temp->nextnode;
-                SS_Free(local_temp);
-                local_temp = local_next;
-            }
-        }
-        SS_Free(headptr_list[idx]);
-        headptr_list[idx] = NULL;
-    }
+       fs_params *local_temp = NULL;
+       fs_params *local_next = NULL;
+       LOGL(LOG_SSENGINE, "Free Nodes idx=%d \n", idx);
+       if (headptr_list[idx]) {
+               if (headptr_list[idx]->del_ref) {
+                       local_temp = headptr_list[idx]->del_ref;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               if (headptr_list[idx]->dif_ref) {
+                       local_temp = headptr_list[idx]->dif_ref;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               if (headptr_list[idx]->move_ref) {
+                       local_temp = headptr_list[idx]->move_ref;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               if (headptr_list[idx]->new_ref) {
+                       local_temp = headptr_list[idx]->new_ref;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               if (headptr_list[idx]->sym_difref) {
+                       local_temp = headptr_list[idx]->sym_difref;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               if (headptr_list[idx]->sym_newref) {
+                       local_temp = headptr_list[idx]->sym_newref;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               SS_Free(headptr_list[idx]);
+               headptr_list[idx] = NULL;
+       }
 }
 
 /*!
  *********************************************************************************
- *                     SS_FSGetDeltaCount
+ *                                      SS_FSGetDeltaCount
  *********************************************************************************
  *
  * @brief
@@ -624,160 +619,160 @@ void SS_FSClearNodes(int idx)
 
 struct details *SS_FSGetDeltaCount(char *ubDeltaPath, char *ubDeltaInfoFile)
 {
-    int size = 0, bckupsize = 0, ret = 1;
-    char *token = NULL;
-    char *FileData = NULL;
-    int data_size = -1;
-    char *line = NULL;
-    char *saveptr;
-    char buf[256];
-    struct details *refer_copy = NULL;
-    FILE *filename_bkup = NULL;
-
-    if (!(ubDeltaPath && ubDeltaInfoFile)) {
-        LOGE("failed to Parse DELTA count information: \n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return NULL;
-    }
-    refer_copy = (struct details *)SS_Malloc(sizeof(struct details));
-
-    if (refer_copy == NULL) {
-        LOGE("failed to allocate memory\n");
-        return NULL;
-    }
-
-    LOGL(LOG_SSENGINE, "Delta File Info =%s\n", ubDeltaInfoFile);
-
-    size = tar_get_item_size(ubDeltaPath, ubDeltaInfoFile);
-    if (size < 0) {
-        LOGE("failed to Access DELTA info file DPath:[%s] File: [%s]\n", ubDeltaPath, ubDeltaInfoFile);
-        SS_SetUpgradeState(E_SS_FSBADDELTA);
-        ret = 0;
-        goto cleanup;
-    }
-
-    FileData = SS_Malloc(size + 1);
-    if (FileData == NULL) {
-        LOGE("Failed to Allocate Memory\n");
-        SS_SetUpgradeState(E_SS_MALLOC_ERROR);
-        ret = 0;
-        goto cleanup;
-    }
-
-    data_size = tar_get_cfg_data(ubDeltaPath, ubDeltaInfoFile, FileData, size);
-    if (data_size <= 0) {       // == 0 is NOT okay??
-        LOGE("Failed to read cfg data from Delta\n");
-        SS_SetUpgradeState(E_SS_FSBADDELTA);
-        ret = 0;
-        goto cleanup;
-    }
-    filename_bkup = fopen(SS_PATCHLIST_BKUPLOC, "wb+");
-    if (filename_bkup == NULL) {
-        strerror_r(errno, buf, sizeof(buf));
-        LOGE("Failed to create BACKUP file Error:[%s]\n", buf);
-        SS_SetUpgradeState(E_SS_FSFAILEDTOBACKUPPATCHINFO);
-        ret = 0;
-        goto cleanup;
-    }
-
-    bckupsize = fwrite(FileData, 1, data_size, filename_bkup);  //RECHECK SIZE 1
-    if (bckupsize <= 0) {
-        SS_SetUpgradeState(E_SS_FSFAILEDTOBACKUPPATCHINFO);
-        ret = 0;
-        goto cleanup;
-    }
-    LOGL(LOG_SSENGINE, " Size [%d] DataSize [%d] BakUpSize [%d]\n", size, data_size, bckupsize);
-
-    line = strstr(FileData, SS_FSCOUNT_MAGIC_KEY);
-    if (line) {
-        LOGL(LOG_SSENGINE, "SS_FSGetDeltaCount() last line %s \n", line);
-
-        token = strtok_r(&line[SS_FSCOUNT_MAGIG_KEYLEN], SS_TOKEN_SPACE, &saveptr);
-        if (token)
-            refer_copy->diffs = atoi(token);
-        else {
-            SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
-            ret = 0;
-            goto cleanup;
-        }
-        token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
-        if (token)
-            refer_copy->moves = atoi(token);
-        else {
-            SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
-            ret = 0;
-            goto cleanup;
-        }
-
-        token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
-        if (token)
-            refer_copy->news = atoi(token);
-        else {
-            SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
-            ret = 0;
-            goto cleanup;
-        }
-
-        token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
-        if (token)
-            refer_copy->deletes = atoi(token);
-        else {
-            SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
-            ret = 0;
-            goto cleanup;
-        }
-
-        token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
-        if (token)
-            refer_copy->symdiffs = atoi(token);
-        else {
-            SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
-            ret = 0;
-            goto cleanup;
-        }
-
-        token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
-        if (token)
-            refer_copy->symnews = atoi(token);
-        else {
-            SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
-            ret = 0;
-            goto cleanup;
-        }
-
-        gtotalFSCnt =
-            refer_copy->diffs + refer_copy->moves + refer_copy->news + refer_copy->deletes + refer_copy->symdiffs +
-            refer_copy->symnews;
-        LOG("SS_FSGetDeltaCount() total no of file %d\n", gtotalFSCnt);
-
-    } else {
-        SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
-        LOG("SS_FSGetDeltaCount() Failed to read last line\n");
-    }
-    if (gtotalFSCnt < 0) {
-        ret = 0;
-        goto cleanup;
-    }
+       int size = 0, bckupsize = 0, ret = 1;
+       char *token = NULL;
+       char *FileData = NULL;
+       int data_size = -1;
+       char *line = NULL;
+       char *saveptr;
+       char buf[256];
+       struct details *refer_copy = NULL;
+       FILE *filename_bkup = NULL;
+
+       if (!(ubDeltaPath && ubDeltaInfoFile)) {
+               LOGE("failed to Parse DELTA count information: \n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return NULL;
+       }
+       refer_copy = (struct details *)SS_Malloc(sizeof(struct details));
+
+       if (refer_copy == NULL) {
+               LOGE("failed to allocate memory\n");
+               return NULL;
+       }
+
+       LOGL(LOG_SSENGINE, "Delta File Info =%s\n", ubDeltaInfoFile);
+
+       size = tar_get_item_size(ubDeltaPath, ubDeltaInfoFile);
+       if (size < 0) {
+               LOGE("failed to Access DELTA info file DPath:[%s] File: [%s]\n", ubDeltaPath, ubDeltaInfoFile);
+               SS_SetUpgradeState(E_SS_FSBADDELTA);
+               ret = 0;
+               goto cleanup;
+       }
+
+       FileData = SS_Malloc(size + 1);
+       if (FileData == NULL) {
+               LOGE("Failed to Allocate Memory\n");
+               SS_SetUpgradeState(E_SS_MALLOC_ERROR);
+               ret = 0;
+               goto cleanup;
+       }
+
+       data_size = tar_get_cfg_data(ubDeltaPath, ubDeltaInfoFile, FileData, size);
+       if (data_size <= 0) {      // == 0 is NOT okay??
+               LOGE("Failed to read cfg data from Delta\n");
+               SS_SetUpgradeState(E_SS_FSBADDELTA);
+               ret = 0;
+               goto cleanup;
+       }
+       filename_bkup = fopen(SS_PATCHLIST_BKUPLOC, "wb+");
+       if (filename_bkup == NULL) {
+               strerror_r(errno, buf, sizeof(buf));
+               LOGE("Failed to create BACKUP file Error:[%s]\n", buf);
+               SS_SetUpgradeState(E_SS_FSFAILEDTOBACKUPPATCHINFO);
+               ret = 0;
+               goto cleanup;
+       }
+
+       bckupsize = fwrite(FileData, 1, data_size, filename_bkup);  //RECHECK SIZE 1
+       if (bckupsize <= 0) {
+               SS_SetUpgradeState(E_SS_FSFAILEDTOBACKUPPATCHINFO);
+               ret = 0;
+               goto cleanup;
+       }
+       LOGL(LOG_SSENGINE, " Size [%d] DataSize [%d] BakUpSize [%d]\n", size, data_size, bckupsize);
+
+       line = strstr(FileData, SS_FSCOUNT_MAGIC_KEY);
+       if (line) {
+               LOGL(LOG_SSENGINE, "SS_FSGetDeltaCount() last line %s \n", line);
+
+               token = strtok_r(&line[SS_FSCOUNT_MAGIG_KEYLEN], SS_TOKEN_SPACE, &saveptr);
+               if (token)
+                       refer_copy->diffs = atoi(token);
+               else {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+                       ret = 0;
+                       goto cleanup;
+               }
+               token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
+               if (token)
+                       refer_copy->moves = atoi(token);
+               else {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+                       ret = 0;
+                       goto cleanup;
+               }
+
+               token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
+               if (token)
+                       refer_copy->news = atoi(token);
+               else {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+                       ret = 0;
+                       goto cleanup;
+               }
+
+               token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
+               if (token)
+                       refer_copy->deletes = atoi(token);
+               else {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+                       ret = 0;
+                       goto cleanup;
+               }
+
+               token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
+               if (token)
+                       refer_copy->symdiffs = atoi(token);
+               else {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+                       ret = 0;
+                       goto cleanup;
+               }
+
+               token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
+               if (token)
+                       refer_copy->symnews = atoi(token);
+               else {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+                       ret = 0;
+                       goto cleanup;
+               }
+
+               gtotalFSCnt =
+                       refer_copy->diffs + refer_copy->moves + refer_copy->news + refer_copy->deletes + refer_copy->symdiffs +
+                       refer_copy->symnews;
+               LOG("SS_FSGetDeltaCount() total no of file %d\n", gtotalFSCnt);
+
+       } else {
+               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+               LOG("SS_FSGetDeltaCount() Failed to read last line\n");
+       }
+       if (gtotalFSCnt < 0) {
+               ret = 0;
+               goto cleanup;
+       }
 
  cleanup:
-    if (ret) {
-        SS_Free(FileData);
-        if (filename_bkup)
-            fclose(filename_bkup);
-        return refer_copy;
-    } else {
-        SS_Free(FileData);
-        SS_Free(refer_copy);
-        if (filename_bkup)
-            fclose(filename_bkup);
-        return NULL;
-    }
+       if (ret) {
+               SS_Free(FileData);
+               if (filename_bkup)
+                       fclose(filename_bkup);
+               return refer_copy;
+       } else {
+               SS_Free(FileData);
+               SS_Free(refer_copy);
+               if (filename_bkup)
+                       fclose(filename_bkup);
+               return NULL;
+       }
 
 }
 
 /*!
  *********************************************************************************
- *                     SS_FSBuildNodes
+ *                                      SS_FSBuildNodes
  *********************************************************************************
  *
  * @brief
@@ -794,66 +789,66 @@ struct details *SS_FSGetDeltaCount(char *ubDeltaPath, char *ubDeltaInfoFile)
  */
 fs_list *SS_FSBuildNodes(ua_dataSS_t * ua_dataSS)
 {
-    FILE *fp = NULL;
-    char line[SS_TOKEN_MAXLINE_LEN] = { '\0' };
-    char string_na[] = "NA";
-    char *patch_name = NULL;
-    char *source_name = NULL;
-    char *target_name = NULL;
-    char *sha1src = NULL;
-    char *sha1trg = NULL;
-    char *change_type = NULL;
-    char *file_type = NULL;
-    char *saveptr;
-    uint32_t ulPatchCount = 0, del_type = DELETES;
-    fs_params *fs_diffhead = NULL;
-    fs_params *fs_difftail = NULL;
-    fs_params *fs_movehead = NULL;
-    fs_params *fs_movetail = NULL;
-    fs_params *fs_newhead = NULL;
-    fs_params *fs_delhead = NULL;
-    fs_params *fs_deltail = NULL;
-    fs_params *fs_symlinkdiffhead = NULL;
-    fs_params *fs_symlinkdifftail = NULL;
-    fs_params *fs_symlinknewhead = NULL;
-    fs_params *fs_symlinknewtail = NULL;
-
-    struct details *local = NULL;
-    fs_list *fs_head_node = NULL;
-    int i = 0, retval = 0;
-    if (!ua_dataSS) {
-        LOGE("Bad structure ua_dataSS\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return NULL;
-    }
-    LOGL(LOG_SSENGINE, " Build Nodes Entry \n");
-    if (tar_cfg_data == NULL)
-        tar_cfg_data = tar_build_cfg_table(ua_dataSS->update_data->ua_delta_path);
-    if (!tar_cfg_data) {
-        LOGE(" tar_build_cfg_table  Failed \n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return NULL;
-    }
-    local = SS_FSGetDeltaCount(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_patch_info);
-    if (local == NULL) {
-        LOGE(" Build Nodes Failed \n");
-        if (tar_cfg_data)
-            tar_free_cfg_table(&tar_cfg_data);
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return NULL;
-    }
-
-    fp = fopen(SS_PATCHLIST_BKUPLOC, "r");
-    if (!fp) {
-        SS_SetUpgradeState(E_SS_FSFAILEDTOOPENPATCHINFO);
-        if (tar_cfg_data)
-            tar_free_cfg_table(&tar_cfg_data);
-        SS_Free(local);
-        return NULL;
-    }
-
-    ulPatchCount = local->diffs + local->deletes + local->news + local->moves + local->symdiffs + local->symnews;
-    LOG("Total FS count [%d].\n", ulPatchCount);
+       FILE *fp = NULL;
+       char line[SS_TOKEN_MAXLINE_LEN] = { '\0' };
+       char string_na[] = "NA";
+       char *patch_name = NULL;
+       char *source_name = NULL;
+       char *target_name = NULL;
+       char *sha1src = NULL;
+       char *sha1trg = NULL;
+       char *change_type = NULL;
+       char *file_type = NULL;
+       char *saveptr;
+       uint32_t ulPatchCount = 0, del_type = DELETES;
+       fs_params *fs_diffhead = NULL;
+       fs_params *fs_difftail = NULL;
+       fs_params *fs_movehead = NULL;
+       fs_params *fs_movetail = NULL;
+       fs_params *fs_newhead = NULL;
+       fs_params *fs_delhead = NULL;
+       fs_params *fs_deltail = NULL;
+       fs_params *fs_symlinkdiffhead = NULL;
+       fs_params *fs_symlinkdifftail = NULL;
+       fs_params *fs_symlinknewhead = NULL;
+       fs_params *fs_symlinknewtail = NULL;
+
+       struct details *local = NULL;
+       fs_list *fs_head_node = NULL;
+       int i = 0, retval = 0;
+       if (!ua_dataSS) {
+               LOGE("Bad structure ua_dataSS\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return NULL;
+       }
+       LOGL(LOG_SSENGINE, " Build Nodes Entry \n");
+       if (tar_cfg_data == NULL)
+               tar_cfg_data = tar_build_cfg_table(ua_dataSS->update_data->ua_delta_path);
+       if (!tar_cfg_data) {
+               LOGE(" tar_build_cfg_table  Failed \n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return NULL;
+       }
+       local = SS_FSGetDeltaCount(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_patch_info);
+       if (local == NULL) {
+               LOGE(" Build Nodes Failed \n");
+               if (tar_cfg_data)
+                       tar_free_cfg_table(&tar_cfg_data);
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return NULL;
+       }
+
+       fp = fopen(SS_PATCHLIST_BKUPLOC, "r");
+       if (!fp) {
+               SS_SetUpgradeState(E_SS_FSFAILEDTOOPENPATCHINFO);
+               if (tar_cfg_data)
+                       tar_free_cfg_table(&tar_cfg_data);
+               SS_Free(local);
+               return NULL;
+       }
+
+       ulPatchCount = local->diffs + local->deletes + local->news + local->moves + local->symdiffs + local->symnews;
+       LOG("Total FS count [%d].\n", ulPatchCount);
 /*
 ************************************************************************
 Parsing logic implemented for patchlist
@@ -872,335 +867,334 @@ SYM:DIFF:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:system/u
 SYM:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
 ***********************************************************************
 */
-    if (local && ((local->diffs) > 0 || (local->moves > 0))) {
-        LOGL(LOG_SSENGINE, "%ss [%d] %ss [%d]\n", SS_STRING_DIFF, local->diffs, SS_STRING_MOVE, local->moves);
-        for (i = 0; i < (local->diffs + local->moves); i++) {
-            if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
-                SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                break;
-            }
-            //LOGL(LOG_SSENGINE, "DIFF LINE:[%d] [%s] \n",i+1,line);
-
-            change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
-            file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-
-            if (change_type && strcmp(change_type, SS_STRING_MOVE) == 0) {     // && strcmp(file_type,"TPK") == 0){
-                source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                sha1src = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
-                //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_MOVE, i);
-
-                if (!source_name || !target_name || !sha1src) {
-                    SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                    //LOGE("Failed to extract Patch Info Type:DELETES \n");
-                    LOGE("Failed to parse DIFFS - LINE:[%d] [%s] \n", i + 1, line);
-                    goto CleanUp;
-                }
-                retval =
-                    SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_movehead, &fs_movetail, source_name,
-                                  target_name, string_na, sha1src, string_na, MOVES,
-                                  ua_dataSS->update_delta->ua_patch_path);
-                if (retval == E_SS_FAILURE)     // ONLY test purpose, should enable this
-                    goto CleanUp;
-                SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-            } else if (change_type && strcmp(change_type, SS_STRING_DIFF) == 0) {      // && strcmp(file_type,"TPK") == 0){
-                source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                sha1src = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                sha1trg = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
-                //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_DIFF, i);
-
-                if (patch_name && (strlen(patch_name) <= SS_MAX_NAMELENSUPPORTED)) {
-                    retval =
-                        SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_diffhead, &fs_difftail,
-                                      source_name, target_name, patch_name, sha1src, sha1trg, DIFFS,
-                                      ua_dataSS->update_delta->ua_patch_path);
-                    if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
-                        goto CleanUp;
-                } else {
-                    SS_SetUpgradeState(E_SS_FILENAMELENERROR);
-                    LOGE("File Name length Limitation Error File:[%s]\n", patch_name);
-                    goto CleanUp;
-                }
-                SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-            } else {
-                SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                LOGE("Patch Name format Error File\n");
-                goto CleanUp;
-            }
-        }
-    }
-    if (local && (local->news) > 0) {   //check if new files archive is present in the delta
-        char new_patch_path[MAX_FILE_PATH] = { 0, };
-        snprintf(new_patch_path, MAX_FILE_PATH, "%s%s", ua_dataSS->parti_info->ua_subject_name, SS_COMPRESSED_FILE);
-        if (tar_get_item_size(ua_dataSS->update_data->ua_delta_path, new_patch_path) <= 0) {
-            SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-            LOGE("New files not present in Patch\n");
-            goto CleanUp;
-        }
-    }
-    if (local && (local->deletes) > 0) {        //this is to group to delete list
-        LOGL(LOG_SSENGINE, "%ss [%d]\n", SS_STRING_DEL, local->deletes);
-        for (i = 0; i < (local->deletes); i++) {
-            if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
-                SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                break;
-            }
-
-            change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
-            file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-
-            if (file_type && strcmp(file_type, SS_STRING_REG) == 0) {
-                source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                sha1src = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
-                del_type = DELETES;
-            } else if (file_type && strcmp(file_type, SS_STRING_SYM) == 0) {
-                source_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
-                sha1src = string_na;
-                del_type = DELETES;
-            } else if (file_type && strcmp(file_type, SS_STRING_END) == 0) {
-                source_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
-                sha1src = string_na;
-                del_type = DELETE_END;
-            }
-            else {
-                LOGE("Failed to parse DELETES - LINE:[%d] [%s] \n", i + 1, line);
-                goto CleanUp;
-            }
-
-            if (!source_name || !sha1src) {
-                SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                //LOGE("Failed to extract Patch Info Type:DELETES \n");
-                LOGE("Failed to parse DELETES - LINE:[%d] [%s] \n", i + 1, line);
-                goto CleanUp;
-            }
-            //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_DEL, i);
-            retval =
-                SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_delhead, &fs_deltail, source_name,
-                              string_na, string_na, sha1src, string_na, del_type,
-                              ua_dataSS->update_delta->ua_patch_path);
-            if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
-                goto CleanUp;
-            SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-
-        }
-    }                           //For symlink files
-
-    if (local && (local->symdiffs) > 0) {
-        LOGL(LOG_SSENGINE, "%s %ss [%d]\n", SS_STRING_SYM, SS_STRING_DIFF, local->symdiffs);
-        for (i = 0; i < (local->symdiffs); i++) {       //get the count from below function
-            if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
-                SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                break;
-            }
-            //LOGL(LOG_SSENGINE, "SYMDIFF LINE:[%d] [%s] \n",i+1,line);
-
-            change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
-            file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-
-            if ((change_type && file_type) &&
-                    strcmp(change_type, SS_STRING_SYM) == 0 && strcmp(file_type, SS_STRING_DIFF) == 0) {    // && strcmp(file_type,"TPK") == 0){
-                source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
-                //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_DIFF, i);
-
-                if (!source_name || !target_name || !patch_name) {
-                    SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                    //LOGE("Failed to extract Patch Info Type:DELETES \n");
-                    LOGE("Failed to parse SymDiffs - LINE:[%d] [%s] \n", i + 1, line);
-                    goto CleanUp;
-                }
-                retval =
-                    SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_symlinkdiffhead, &fs_symlinkdifftail,
-                                  source_name, target_name, patch_name, string_na, string_na, SYMDIFFS,
-                                  ua_dataSS->update_delta->ua_patch_path);
-                if (retval == E_SS_FAILURE)     // ONLY test purpose, should enable this
-                    goto CleanUp;
-                SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-            }
-        }
-    }
-    if (local && (local->symnews) > 0) {
-        LOGL(LOG_SSENGINE, "%s %ss [%d]n", SS_STRING_SYM, SS_STRING_NEW, local->symnews);
-        for (i = 0; i < (local->symnews); i++) {
-            if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
-                SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                break;
-            }
-            //LOGL(LOG_SSENGINE, "SYMNEWS LINE:[%d] [%s] \n",i+1,line);
-
-            change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
-            file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-
-            if ((change_type && file_type) &&
-                    (strcmp(change_type, SS_STRING_SYM) == 0 && strcmp(file_type, SS_STRING_NEW) == 0)) {
-                source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-                patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
-                //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_NEW, i);
-
-                if (!source_name || !patch_name) {
-                    SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
-                    //LOGE("Failed to extract Patch Info Type:DELETES \n");
-                    LOGE("Failed to parse SymNews - LINE:[%d] [%s] \n", i + 1, line);
-                    goto CleanUp;
-                }
-                retval =
-                    SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_symlinknewhead, &fs_symlinknewtail,
-                                  source_name, string_na, patch_name, string_na, string_na, SYMNEWFILES,
-                                  ua_dataSS->update_delta->ua_patch_path);
-                if (retval == E_SS_FAILURE)     // ONLY test purpose, should enable this
-                    goto CleanUp;
-                SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-            }
-        }
-    }
-
-    fs_head_node = (fs_list *) SS_Malloc(sizeof(fs_list));
-    if (!fs_head_node) {
-        SS_SetUpgradeState(E_SS_MALLOC_ERROR);
-        goto CleanUp;
-    }
-    fs_head_node->dif_ref = fs_diffhead;
-    fs_head_node->move_ref = fs_movehead;
-    fs_head_node->new_ref = fs_newhead;
-    fs_head_node->del_ref = fs_delhead;
-    fs_head_node->sym_difref = fs_symlinkdiffhead;
-    fs_head_node->sym_newref = fs_symlinknewhead;
-    fs_head_node->ulPatchCount = ulPatchCount;
-
-    SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 1);
+       if (local && ((local->diffs) > 0 || (local->moves > 0))) {
+               LOGL(LOG_SSENGINE, "%ss [%d] %ss [%d]\n", SS_STRING_DIFF, local->diffs, SS_STRING_MOVE, local->moves);
+               for (i = 0; i < (local->diffs + local->moves); i++) {
+                       if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
+                               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                               break;
+                       }
+                       //LOGL(LOG_SSENGINE, "DIFF LINE:[%d] [%s] \n",i+1,line);
+
+                       change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
+                       file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+
+                       if (change_type && strcmp(change_type, SS_STRING_MOVE) == 0) {   // && strcmp(file_type,"TPK") == 0){
+                               source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               sha1src = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_MOVE, i);
+
+                               if (!source_name || !target_name || !sha1src) {
+                                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                                       //LOGE("Failed to extract Patch Info Type:DELETES \n");
+                                       LOGE("Failed to parse DIFFS - LINE:[%d] [%s] \n", i + 1, line);
+                                       goto CleanUp;
+                               }
+                               retval =
+                                       SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_movehead, &fs_movetail, source_name,
+                                                                 target_name, string_na, sha1src, string_na, MOVES,
+                                                                 ua_dataSS->update_delta->ua_patch_path);
+                               if (retval == E_SS_FAILURE)      // ONLY test purpose, should enable this
+                                       goto CleanUp;
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                       } else if (change_type && strcmp(change_type, SS_STRING_DIFF) == 0) {     // && strcmp(file_type,"TPK") == 0){
+                               source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               sha1src = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               sha1trg = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_DIFF, i);
+
+                               if (patch_name && (strlen(patch_name) <= SS_MAX_NAMELENSUPPORTED)) {
+                                       retval =
+                                               SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_diffhead, &fs_difftail,
+                                                                         source_name, target_name, patch_name, sha1src, sha1trg, DIFFS,
+                                                                         ua_dataSS->update_delta->ua_patch_path);
+                                       if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
+                                               goto CleanUp;
+                               } else {
+                                       SS_SetUpgradeState(E_SS_FILENAMELENERROR);
+                                       LOGE("File Name length Limitation Error File:[%s]\n", patch_name);
+                                       goto CleanUp;
+                               }
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                       } else {
+                               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                               LOGE("Patch Name format Error File\n");
+                               goto CleanUp;
+                       }
+               }
+       }
+       if (local && (local->news) > 0) {   //check if new files archive is present in the delta
+               char new_patch_path[MAX_FILE_PATH] = { 0, };
+               snprintf(new_patch_path, MAX_FILE_PATH, "%s%s", ua_dataSS->parti_info->ua_subject_name, SS_COMPRESSED_FILE);
+               if (tar_get_item_size(ua_dataSS->update_data->ua_delta_path, new_patch_path) <= 0) {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                       LOGE("New files not present in Patch\n");
+                       goto CleanUp;
+               }
+       }
+       if (local && (local->deletes) > 0) {            //this is to group to delete list
+               LOGL(LOG_SSENGINE, "%ss [%d]\n", SS_STRING_DEL, local->deletes);
+               for (i = 0; i < (local->deletes); i++) {
+                       if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
+                               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                               break;
+                       }
+
+                       change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
+                       file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+
+                       if (file_type && strcmp(file_type, SS_STRING_REG) == 0) {
+                               source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               sha1src = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               del_type = DELETES;
+                       } else if (file_type && strcmp(file_type, SS_STRING_SYM) == 0) {
+                               source_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               sha1src = string_na;
+                               del_type = DELETES;
+                       } else if (file_type && strcmp(file_type, SS_STRING_END) == 0) {
+                               source_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               sha1src = string_na;
+                               del_type = DELETE_END;
+                       } else {
+                               LOGE("Failed to parse DELETES - LINE:[%d] [%s] \n", i + 1, line);
+                               goto CleanUp;
+                       }
+
+                       if (!source_name || !sha1src) {
+                               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                               //LOGE("Failed to extract Patch Info Type:DELETES \n");
+                               LOGE("Failed to parse DELETES - LINE:[%d] [%s] \n", i + 1, line);
+                               goto CleanUp;
+                       }
+                       //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_DEL, i);
+                       retval =
+                               SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_delhead, &fs_deltail, source_name,
+                                                         string_na, string_na, sha1src, string_na, del_type,
+                                                         ua_dataSS->update_delta->ua_patch_path);
+                       if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
+                               goto CleanUp;
+                       SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+
+               }
+       }                                                  //For symlink files
+
+       if (local && (local->symdiffs) > 0) {
+               LOGL(LOG_SSENGINE, "%s %ss [%d]\n", SS_STRING_SYM, SS_STRING_DIFF, local->symdiffs);
+               for (i = 0; i < (local->symdiffs); i++) {          //get the count from below function
+                       if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
+                               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                               break;
+                       }
+                       //LOGL(LOG_SSENGINE, "SYMDIFF LINE:[%d] [%s] \n",i+1,line);
+
+                       change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
+                       file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+
+                       if ((change_type && file_type) &&
+                                       strcmp(change_type, SS_STRING_SYM) == 0 && strcmp(file_type, SS_STRING_DIFF) == 0) {    // && strcmp(file_type,"TPK") == 0){
+                               source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_DIFF, i);
+
+                               if (!source_name || !target_name || !patch_name) {
+                                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                                       //LOGE("Failed to extract Patch Info Type:DELETES \n");
+                                       LOGE("Failed to parse SymDiffs - LINE:[%d] [%s] \n", i + 1, line);
+                                       goto CleanUp;
+                               }
+                               retval =
+                                       SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_symlinkdiffhead, &fs_symlinkdifftail,
+                                                                 source_name, target_name, patch_name, string_na, string_na, SYMDIFFS,
+                                                                 ua_dataSS->update_delta->ua_patch_path);
+                               if (retval == E_SS_FAILURE)      // ONLY test purpose, should enable this
+                                       goto CleanUp;
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                       }
+               }
+       }
+       if (local && (local->symnews) > 0) {
+               LOGL(LOG_SSENGINE, "%s %ss [%d]n", SS_STRING_SYM, SS_STRING_NEW, local->symnews);
+               for (i = 0; i < (local->symnews); i++) {
+                       if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
+                               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                               break;
+                       }
+                       //LOGL(LOG_SSENGINE, "SYMNEWS LINE:[%d] [%s] \n",i+1,line);
+
+                       change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
+                       file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+
+                       if ((change_type && file_type) &&
+                                       (strcmp(change_type, SS_STRING_SYM) == 0 && strcmp(file_type, SS_STRING_NEW) == 0)) {
+                               source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_NEW, i);
+
+                               if (!source_name || !patch_name) {
+                                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                                       //LOGE("Failed to extract Patch Info Type:DELETES \n");
+                                       LOGE("Failed to parse SymNews - LINE:[%d] [%s] \n", i + 1, line);
+                                       goto CleanUp;
+                               }
+                               retval =
+                                       SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_symlinknewhead, &fs_symlinknewtail,
+                                                                 source_name, string_na, patch_name, string_na, string_na, SYMNEWFILES,
+                                                                 ua_dataSS->update_delta->ua_patch_path);
+                               if (retval == E_SS_FAILURE)      // ONLY test purpose, should enable this
+                                       goto CleanUp;
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                       }
+               }
+       }
+
+       fs_head_node = (fs_list *) SS_Malloc(sizeof(fs_list));
+       if (!fs_head_node) {
+               SS_SetUpgradeState(E_SS_MALLOC_ERROR);
+               goto CleanUp;
+       }
+       fs_head_node->dif_ref = fs_diffhead;
+       fs_head_node->move_ref = fs_movehead;
+       fs_head_node->new_ref = fs_newhead;
+       fs_head_node->del_ref = fs_delhead;
+       fs_head_node->sym_difref = fs_symlinkdiffhead;
+       fs_head_node->sym_newref = fs_symlinknewhead;
+       fs_head_node->ulPatchCount = ulPatchCount;
+
+       SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 1);
 
  CleanUp:
-    fclose(fp);
-    SS_Free(local);
-    unlink(SS_PATCHLIST_BKUPLOC);
-    if (retval == E_SS_FAILURE)
-        if (tar_cfg_data)
-            tar_free_cfg_table(&tar_cfg_data);
-    return fs_head_node;
+       fclose(fp);
+       SS_Free(local);
+       unlink(SS_PATCHLIST_BKUPLOC);
+       if (retval == E_SS_FAILURE)
+               if (tar_cfg_data)
+                       tar_free_cfg_table(&tar_cfg_data);
+       return fs_head_node;
 }
 
 void SS_GetPartition_LocDetails(ua_dataSS_t * ua_dataSS, int part_idx)
 {
-    LOGL(LOG_SSENGINE, "PART NAME: [%s] \n", ua_dataSS->parti_info->ua_parti_name);
-    snprintf(ua_dataSS->update_delta->ua_patch_path, MAX_FILE_PATH, "%s", ua_dataSS->parti_info->ua_subject_name);
-    snprintf(ua_dataSS->update_delta->ua_patch_info, MAX_FILE_PATH, "%s%s%s", ua_dataSS->parti_info->ua_subject_name,
-             ua_dataSS->parti_info->ua_parti_name, SS_PATCHLISTFORMAT);
-    snprintf(ua_dataSS->update_delta->ua_attrib_path, MAX_FILE_PATH, "%s%s%s", ua_dataSS->parti_info->ua_subject_name,
-             ua_dataSS->parti_info->ua_parti_name, SS_PATCH_ATTR_FORMAT);
-    LOGL(LOG_SSENGINE, "PatchPath[%s] PatchInfo [%s] Attributes [%s]\n", ua_dataSS->update_delta->ua_patch_path,
-         ua_dataSS->update_delta->ua_patch_info, ua_dataSS->update_delta->ua_attrib_path);
-
-    return;
+       LOGL(LOG_SSENGINE, "PART NAME: [%s] \n", ua_dataSS->parti_info->ua_parti_name);
+       snprintf(ua_dataSS->update_delta->ua_patch_path, MAX_FILE_PATH, "%s", ua_dataSS->parti_info->ua_subject_name);
+       snprintf(ua_dataSS->update_delta->ua_patch_info, MAX_FILE_PATH, "%s%s%s", ua_dataSS->parti_info->ua_subject_name,
+                        ua_dataSS->parti_info->ua_parti_name, SS_PATCHLISTFORMAT);
+       snprintf(ua_dataSS->update_delta->ua_attrib_path, MAX_FILE_PATH, "%s%s%s", ua_dataSS->parti_info->ua_subject_name,
+                        ua_dataSS->parti_info->ua_parti_name, SS_PATCH_ATTR_FORMAT);
+       LOGL(LOG_SSENGINE, "PatchPath[%s] PatchInfo [%s] Attributes [%s]\n", ua_dataSS->update_delta->ua_patch_path,
+                ua_dataSS->update_delta->ua_patch_info, ua_dataSS->update_delta->ua_attrib_path);
+
+       return;
 }
 
 //Support functions//Change Struct format details (Can include total file count also???)/*!
 /*
 ******************************************************************************** *
 SS_FSSetAttributes
-    *********************************************************************************
-    * *@brief
-    * This is used to set the file attributes at the end of application of patches in FS
-    *
-    * *@param
-    *
-    *@return returns S_SS_SUCCESS
-    * E_SS_FAILURE in case of error
-    *
-    *********************************************************************************
+       *********************************************************************************
+       * *@brief
+       * This is used to set the file attributes at the end of application of patches in FS
+       *
+       * *@param
+       *
+       *@return returns S_SS_SUCCESS
+       * E_SS_FAILURE in case of error
+       *
+       *********************************************************************************
  */
 int SS_FSSetAttributes(ua_dataSS_t * ua_dataSS)
 {
-    char *pline = NULL;
-    char *psaveptr = NULL;
-    char *pfilePath = NULL;
-    char *pfiletype = NULL;
-    char *attributSize = NULL;
-    char *pattribs = NULL;
-    int ulAttribSize = 0;
-    int result = S_SS_SUCCESS;
-
-    if (!(ua_dataSS && ua_dataSS->update_delta && ua_dataSS->update_data->ua_delta_path)) {
-        LOGE("Bad params for SS_FSSetAttributes\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return E_SS_FAILURE;
-    }
-    LOGL(LOG_SSENGINE, "ATTRIB PATH: [%s] \n", ua_dataSS->update_delta->ua_attrib_path);
-
-    int item_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_attrib_path);
-
-    if (item_size <= 0) {
-        LOGL(LOG_SSENGINE, "No Attributes to SET\n");
-        return S_SS_SUCCESS;    // Delta with ONLY deletes
-    }
-    char *item_data = SS_Malloc(item_size + 1);
-    if (item_data == NULL) {
-        SS_SetUpgradeState(E_SS_MALLOC_ERROR);
-        return E_SS_FAILURE;
-    }
-    int read_data =
-        tar_get_cfg_data(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_attrib_path, item_data,
-                         item_size);
-    if (read_data <= 0) {
-        SS_SetUpgradeState(E_SS_FSBADDELTA);
-        if (item_data != NULL)
-            SS_Free(item_data);
-        return E_SS_FAILURE;
-    }
-    pline = strtok_r(item_data, "\n", &psaveptr);
-    if (pline == NULL) {
-        LOGL(LOG_SSENGINE, "No Attributes to SET as no lines in file\n");
-        if (item_data != NULL)
-            SS_Free(item_data);
-        return E_SS_FAILURE;
-    }
-
-    while (pline) {
-        char *saveptr_pline;
-        pfilePath = strtok_r(pline, "\"", &saveptr_pline);
-
-        if (pfilePath && strcmp(pfilePath, SS_FWSLASH) == 0) {
-            LOGE("\n skip root: it is RO");
-            pline = strtok_r(NULL, SS_TOKEN_NEWLINE, &psaveptr);
-            continue;
-        }
-
-        pfiletype = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr_pline);
-        attributSize = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr_pline);
-        pattribs = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr_pline);
-        LOG("\nSS_FSSetAttributes [%s][%s][%s]", pfiletype, attributSize, pattribs);
-        if (pattribs && pfilePath && pfiletype) {
-            ulAttribSize = strlen(pattribs);
-            //LOG("\nSS_SetFileAttributes [%s][%s][%d][%s]",pfilePath,pfiletype,ulAttribSize, pattribs );
-            //LOG("SS_SetFileAttributes [%s]\n", pfilePath);
-
-            result = SS_SetFileAttributes(pfilePath, ulAttribSize, (const unsigned char *)pattribs);
-            if (result != S_SS_SUCCESS) {
-                LOGE("\n Failed to set Attributes %s", pfilePath);
-                SS_SetUpgradeState(E_SS_FSBADATTRIBUTES);
-                if (item_data)
-                    SS_Free(item_data);
-                return E_SS_FAILURE;
-            }
-        } else {
-            LOGE("\n Failed to Parse Attributes - LINE %s", pline);
-            SS_SetUpgradeState(E_SS_FSBADATTRIBUTES);
-            if (item_data)
-                SS_Free(item_data);
-            return E_SS_FAILURE;
-        }
-        pline = strtok_r(NULL, SS_TOKEN_NEWLINE, &psaveptr);
-    }
-    SS_Free(item_data);
-
-    return S_SS_SUCCESS;
+       char *pline = NULL;
+       char *psaveptr = NULL;
+       char *pfilePath = NULL;
+       char *pfiletype = NULL;
+       char *attributSize = NULL;
+       char *pattribs = NULL;
+       int ulAttribSize = 0;
+       int result = S_SS_SUCCESS;
+
+       if (!(ua_dataSS && ua_dataSS->update_delta && ua_dataSS->update_data->ua_delta_path)) {
+               LOGE("Bad params for SS_FSSetAttributes\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return E_SS_FAILURE;
+       }
+       LOGL(LOG_SSENGINE, "ATTRIB PATH: [%s] \n", ua_dataSS->update_delta->ua_attrib_path);
+
+       int item_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_attrib_path);
+
+       if (item_size <= 0) {
+               LOGL(LOG_SSENGINE, "No Attributes to SET\n");
+               return S_SS_SUCCESS;    // Delta with ONLY deletes
+       }
+       char *item_data = SS_Malloc(item_size + 1);
+       if (item_data == NULL) {
+               SS_SetUpgradeState(E_SS_MALLOC_ERROR);
+               return E_SS_FAILURE;
+       }
+       int read_data =
+               tar_get_cfg_data(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_attrib_path, item_data,
+                                                item_size);
+       if (read_data <= 0) {
+               SS_SetUpgradeState(E_SS_FSBADDELTA);
+               if (item_data != NULL)
+                       SS_Free(item_data);
+               return E_SS_FAILURE;
+       }
+       pline = strtok_r(item_data, "\n", &psaveptr);
+       if (pline == NULL) {
+               LOGL(LOG_SSENGINE, "No Attributes to SET as no lines in file\n");
+               if (item_data != NULL)
+                       SS_Free(item_data);
+               return E_SS_FAILURE;
+       }
+
+       while (pline) {
+               char *saveptr_pline;
+               pfilePath = strtok_r(pline, "\"", &saveptr_pline);
+
+               if (pfilePath && strcmp(pfilePath, SS_FWSLASH) == 0) {
+                       LOGE("\n skip root: it is RO");
+                       pline = strtok_r(NULL, SS_TOKEN_NEWLINE, &psaveptr);
+                       continue;
+               }
+
+               pfiletype = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr_pline);
+               attributSize = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr_pline);
+               pattribs = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr_pline);
+               LOG("\nSS_FSSetAttributes [%s][%s][%s]", pfiletype, attributSize, pattribs);
+               if (pattribs && pfilePath && pfiletype) {
+                       ulAttribSize = strlen(pattribs);
+                       //LOG("\nSS_SetFileAttributes [%s][%s][%d][%s]",pfilePath,pfiletype,ulAttribSize, pattribs );
+                       //LOG("SS_SetFileAttributes [%s]\n", pfilePath);
+
+                       result = SS_SetFileAttributes(pfilePath, ulAttribSize, (const unsigned char *)pattribs);
+                       if (result != S_SS_SUCCESS) {
+                               LOGE("\n Failed to set Attributes %s", pfilePath);
+                               SS_SetUpgradeState(E_SS_FSBADATTRIBUTES);
+                               if (item_data)
+                                       SS_Free(item_data);
+                               return E_SS_FAILURE;
+                       }
+               } else {
+                       LOGE("\n Failed to Parse Attributes - LINE %s", pline);
+                       SS_SetUpgradeState(E_SS_FSBADATTRIBUTES);
+                       if (item_data)
+                               SS_Free(item_data);
+                       return E_SS_FAILURE;
+               }
+               pline = strtok_r(NULL, SS_TOKEN_NEWLINE, &psaveptr);
+       }
+       SS_Free(item_data);
+
+       return S_SS_SUCCESS;
 }
 
 /*!
  *********************************************************************************
- *                     SS_FSUpdateFile
+ *                                      SS_FSUpdateFile
  *********************************************************************************
  *
  * @brief
@@ -1215,307 +1209,304 @@ int SS_FSSetAttributes(ua_dataSS_t * ua_dataSS)
  *********************************************************************************
  */
 int SS_FSUpdateFile(int ubFileType, ua_dataSS_t * ua_dataSS, int ulPatchCount, fs_params * pFsNode,
-                    const char *patch_path)
+                                       const char *patch_path)
 {
-    int ulFileIndex = 1;
-    char ubPatch[SS_MAX_FILE_PATH] = {
-        0
-    };
-    int ulReadCnt = 0;
-    int ulResult = S_SS_SUCCESS;
-
-    if (!patch_path) {
-        LOGE("Bad patch_path name\n");
-        return E_SS_FAILURE;
-    }
-    switch (ubFileType) {
-    case DIFFS:
-        {
-            tar_open(ua_dataSS->update_data->ua_delta_path);
+       int ulFileIndex = 1;
+       char ubPatch[SS_MAX_FILE_PATH] = {
+               0
+       };
+       int ulReadCnt = 0;
+       int ulResult = S_SS_SUCCESS;
+
+       if (!patch_path) {
+               LOGE("Bad patch_path name\n");
+               return E_SS_FAILURE;
+       }
+       switch (ubFileType) {
+       case DIFFS:
+               {
+                       tar_open(ua_dataSS->update_data->ua_delta_path);
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t1 = atoi(ts1);
+                       get_time_stamp1();  //total time capturing
+                       t1 = atoi(ts1);
 #endif
-            while (pFsNode) {
-                LOGL(LOG_SSENGINE, "DIFFS update Index: [%d] \n", ulFileIndex++);
-                snprintf(ubPatch, SS_MAX_FILE_PATH, "%s%s", patch_path, pFsNode->patch_name);
-                //LOGL(LOG_SSENGINE, "DIFF list --- [File Name %s]\n [Patch Name %s]",pFsNode->file_path, ubPatch);
-                if (pFsNode->data_size > 0) {
-                    ulReadCnt =
-                        fast_tar_extract_file(ua_dataSS->update_data->ua_delta_path, ubPatch, SS_PATCHFILE_SOURCE,
-                                              pFsNode->data_size, pFsNode->data_offset);
-                    if (ulReadCnt < 0) {
-                        ulResult = E_SS_FAILURE;
-                        tar_close();
-                        SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                        LOGE("Delta Read Failed\n");
-                        break;
-                    }
-                    //LOGL(LOG_SSENGINE,"Updating [Item - %s]and size is[%d] Read Count[%d]\n",ubPatch, pFsNode->data_size, ulReadCnt);
-
-                    if (ulReadCnt > 0)
-                        ulResult =
-                            SS_UpdateDeltaFS(pFsNode->file_old_path, pFsNode->file_new_path, pFsNode->sha1src,
-                                             pFsNode->sha1trg, pFsNode->data_size);
-                    if (ulResult != S_SS_SUCCESS) {
-                        LOGE("FS update Failed Result : [%d], [Item - %s]and size is[%d] Read Count[%d]\n", ulResult,
-                             ubPatch, pFsNode->data_size, ulReadCnt);
-                        tar_close();
-                        SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                        break;
-                    }
-                    SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-                    pFsNode = pFsNode->nextnode;
-                }
+                       while (pFsNode) {
+                               LOGL(LOG_SSENGINE, "DIFFS update Index: [%d] \n", ulFileIndex++);
+                               snprintf(ubPatch, SS_MAX_FILE_PATH, "%s%s", patch_path, pFsNode->patch_name);
+                               //LOGL(LOG_SSENGINE, "DIFF list --- [File Name %s]\n [Patch Name %s]",pFsNode->file_path, ubPatch);
+                               if (pFsNode->data_size > 0) {
+                                       ulReadCnt =
+                                               fast_tar_extract_file(ua_dataSS->update_data->ua_delta_path, ubPatch, SS_PATCHFILE_SOURCE,
+                                                                                         pFsNode->data_size, pFsNode->data_offset);
+                                       if (ulReadCnt < 0) {
+                                               ulResult = E_SS_FAILURE;
+                                               tar_close();
+                                               SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                               LOGE("Delta Read Failed\n");
+                                               break;
+                                       }
+                                       //LOGL(LOG_SSENGINE,"Updating [Item - %s]and size is[%d] Read Count[%d]\n",ubPatch, pFsNode->data_size, ulReadCnt);
+
+                                       if (ulReadCnt > 0)
+                                               ulResult =
+                                                       SS_UpdateDeltaFS(pFsNode->file_old_path, pFsNode->file_new_path, pFsNode->sha1src,
+                                                                                        pFsNode->sha1trg, pFsNode->data_size);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("FS update Failed Result : [%d], [Item - %s]and size is[%d] Read Count[%d]\n", ulResult,
+                                                        ubPatch, pFsNode->data_size, ulReadCnt);
+                                               tar_close();
+                                               SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                               break;
+                                       }
+                                       SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                                       pFsNode = pFsNode->nextnode;
+                               }
 #ifdef SUPPORT_CONTAINER
-                else if (pFsNode->data_size == 0) {     //need to add logic to identify archive update
-                    ulResult = tar_extract_folder(ua_dataSS->update_data->ua_delta_path, ubPatch,
-                                                  SS_ARCHIVE_DELTA_FOLDER);
-                    if (ulResult != S_SS_SUCCESS) {
-                        LOGE("extraction failed for [%s] result [%d]\n", ubPatch, ulResult);
-                        SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
-                        break;
-                    }
-                    //Copy exe's for zip , unzip and find operations    - code to be removed after ramdisk upgrade
-                    ulResult = (int)SS_CopyFile(NULL, SS_ZIP_SOURCE, SS_ZIP_TARGET);
-                    if (ulResult != S_SS_SUCCESS) {
-                        LOGE("failed to copy unzip [%d]\n", ulResult);
-                        SS_SetUpgradeState(E_SS_WRITE_ERROR);
-                        break;
-                    }
-                    ulResult = (int)SS_CopyFile(NULL, SS_UNZIP_SOURCE, SS_UNZIP_TARGET);
-                    if (ulResult != S_SS_SUCCESS) {
-                        LOGE("failed to copy unzip [%d]\n", ulResult);
-                        SS_SetUpgradeState(E_SS_WRITE_ERROR);
-                        break;
-                    }
-                    ulResult = (int)SS_CopyFile(NULL, SS_FIND_CMD_SOURCE, SS_FIND_CMD_TARGET);
-                    if (ulResult != S_SS_SUCCESS) {
-                        LOGE("failed to copy find [%d]\n", ulResult);
-                        SS_SetUpgradeState(E_SS_WRITE_ERROR);
-                        break;
-                    }
-                    ulResult =
-                        SS_UpdateArchive(ua_dataSS, pFsNode->file_old_path, pFsNode->file_new_path, pFsNode->sha1src,
-                                         pFsNode->sha1trg);
-                    if (ulResult != S_SS_SUCCESS) {
-                        LOGE("FS update Failed, Unable to extact archive\n");
-                        break;
-                    }
-
-                    SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-                    pFsNode = pFsNode->nextnode;
-                }
+                               else if (pFsNode->data_size == 0) {      //need to add logic to identify archive update
+                                       ulResult = tar_extract_folder(ua_dataSS->update_data->ua_delta_path, ubPatch,
+                                                                                                 SS_ARCHIVE_DELTA_FOLDER);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("extraction failed for [%s] result [%d]\n", ubPatch, ulResult);
+                                               SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
+                                               break;
+                                       }
+                                       //Copy exe's for zip , unzip and find operations        - code to be removed after ramdisk upgrade
+                                       ulResult = (int)SS_CopyFile(NULL, SS_ZIP_SOURCE, SS_ZIP_TARGET);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("failed to copy unzip [%d]\n", ulResult);
+                                               SS_SetUpgradeState(E_SS_WRITE_ERROR);
+                                               break;
+                                       }
+                                       ulResult = (int)SS_CopyFile(NULL, SS_UNZIP_SOURCE, SS_UNZIP_TARGET);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("failed to copy unzip [%d]\n", ulResult);
+                                               SS_SetUpgradeState(E_SS_WRITE_ERROR);
+                                               break;
+                                       }
+                                       ulResult = (int)SS_CopyFile(NULL, SS_FIND_CMD_SOURCE, SS_FIND_CMD_TARGET);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("failed to copy find [%d]\n", ulResult);
+                                               SS_SetUpgradeState(E_SS_WRITE_ERROR);
+                                               break;
+                                       }
+                                       ulResult =
+                                               SS_UpdateArchive(ua_dataSS, pFsNode->file_old_path, pFsNode->file_new_path, pFsNode->sha1src,
+                                                                                pFsNode->sha1trg);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("FS update Failed, Unable to extact archive\n");
+                                               break;
+                                       }
+
+                                       SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                                       pFsNode = pFsNode->nextnode;
+                               }
 #endif
-                else {
-                    ulResult = E_SS_FAILURE;
-                    tar_close();
-                    LOGE("size is invalid\n");
-                    SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                    break;
-                }
-            }
+                               else {
+                                       ulResult = E_SS_FAILURE;
+                                       tar_close();
+                                       LOGE("size is invalid\n");
+                                       SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                       break;
+                               }
+                       }
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t2 = atoi(ts1);
-            LOG("Shirsh time for DIFFS - [%d] \n", (t2 - t1));
+                       get_time_stamp1();  //total time capturing
+                       t2 = atoi(ts1);
+                       LOG("Shirsh time for DIFFS - [%d] \n", (t2 - t1));
 #endif
 #ifdef SUPPORT_CONTAINER
-            SS_DeleteFile(NULL, SS_ZIP_TARGET);
-            SS_DeleteFile(NULL, SS_UNZIP_TARGET);
+                       SS_DeleteFile(NULL, SS_ZIP_TARGET);
+                       SS_DeleteFile(NULL, SS_UNZIP_TARGET);
 #endif
-            tar_close();
-        }
-        break;
-    case MOVES:
-        {
+                       tar_close();
+               }
+               break;
+       case MOVES:
+               {
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t1 = atoi(ts1);
+                       get_time_stamp1();  //total time capturing
+                       t1 = atoi(ts1);
 #endif
-            while (pFsNode) {
-                LOGL(LOG_SSENGINE, "MOVES update Index: [%d] \n", ulFileIndex++);
-                ulResult = SS_MoveFile(NULL, pFsNode->file_old_path, pFsNode->file_new_path);
-                if (ulResult != S_SS_SUCCESS) {
-                    LOGE("Move Failed for [%s] to [%s]\n", pFsNode->file_old_path, pFsNode->file_new_path);
-                    SS_SetUpgradeState(ulResult);
-                    break;
-                }
-                SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-                pFsNode = pFsNode->nextnode;
-            }
+                       while (pFsNode) {
+                               LOGL(LOG_SSENGINE, "MOVES update Index: [%d] \n", ulFileIndex++);
+                               ulResult = SS_MoveFile(NULL, pFsNode->file_old_path, pFsNode->file_new_path);
+                               if (ulResult != S_SS_SUCCESS) {
+                                       LOGE("Move Failed for [%s] to [%s]\n", pFsNode->file_old_path, pFsNode->file_new_path);
+                                       SS_SetUpgradeState(ulResult);
+                                       break;
+                               }
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                               pFsNode = pFsNode->nextnode;
+                       }
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t2 = atoi(ts1);
-            LOG("Shirsh time for DELETES - [%d] \n", (t2 - t1));
+                       get_time_stamp1();  //total time capturing
+                       t2 = atoi(ts1);
+                       LOG("Shirsh time for DELETES - [%d] \n", (t2 - t1));
 #endif
-        }
-        break;
-    case DELETES:
-        {
-            int ulFiletype = 0;
+               }
+               break;
+       case DELETES:
+               {
+                       int ulFiletype = 0;
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t1 = atoi(ts1);
+                       get_time_stamp1();  //total time capturing
+                       t1 = atoi(ts1);
 #endif
-            while (pFsNode) {
-                if (pFsNode->type == DELETES) {
-                    LOGL(LOG_SSENGINE, "DELETES update Index: [%d] \n", ulFileIndex++);
-                    SS_GetFileType(NULL, pFsNode->file_old_path, (enumFileType *) & ulFiletype);
-                    if (ulFiletype == 2)        //FT_FOLDER
-                        ulResult = SS_DeleteFolder(NULL, pFsNode->file_old_path);
-                    else
-                        ulResult = SS_DeleteFile(NULL, pFsNode->file_old_path);
-                    if (ulResult != S_SS_SUCCESS) {
-                        LOGE("Delete Failed\n");
-                        SS_SetUpgradeState(ulResult);
-                        break;
-                    }
-                }
-                SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-                pFsNode = pFsNode->nextnode;
-            }
+                       while (pFsNode) {
+                               if (pFsNode->type == DELETES) {
+                                       LOGL(LOG_SSENGINE, "DELETES update Index: [%d] \n", ulFileIndex++);
+                                       SS_GetFileType(NULL, pFsNode->file_old_path, (enumFileType *) & ulFiletype);
+                                       if (ulFiletype == 2)            //FT_FOLDER
+                                               ulResult = SS_DeleteFolder(NULL, pFsNode->file_old_path);
+                                       else
+                                               ulResult = SS_DeleteFile(NULL, pFsNode->file_old_path);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("Delete Failed\n");
+                                               SS_SetUpgradeState(ulResult);
+                                               break;
+                                       }
+                               }
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                               pFsNode = pFsNode->nextnode;
+                       }
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t2 = atoi(ts1);
-            LOG("Shirsh time for DELETES - [%d] \n", (t2 - t1));
+                       get_time_stamp1();  //total time capturing
+                       t2 = atoi(ts1);
+                       LOG("Shirsh time for DELETES - [%d] \n", (t2 - t1));
 #endif
-        }
-        break;
-    case DELETE_END:
-        {
-            int ulFiletype = 0;
+               }
+               break;
+       case DELETE_END:
+               {
+                       int ulFiletype = 0;
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t1 = atoi(ts1);
+                       get_time_stamp1();  //total time capturing
+                       t1 = atoi(ts1);
 #endif
-            while (pFsNode) {
-                if (pFsNode->type == DELETE_END) {
-                    LOGL(LOG_SSENGINE, "DELETES update Index: [%d] \n", ulFileIndex++);
-                    SS_GetFileType(NULL, pFsNode->file_old_path, (enumFileType *) & ulFiletype);
-                    if (ulFiletype == 2)        //FT_FOLDER
-                        ulResult = SS_DeleteFolder(NULL, pFsNode->file_old_path);
-                    else
-                        ulResult = SS_DeleteFile(NULL, pFsNode->file_old_path);
-                    if (ulResult != S_SS_SUCCESS) {
-                        LOGE("Delete Failed\n");
-                        SS_SetUpgradeState(ulResult);
-                        break;
-                    }
-                }
-                pFsNode = pFsNode->nextnode;
-            }
+                       while (pFsNode) {
+                               if (pFsNode->type == DELETE_END) {
+                                       LOGL(LOG_SSENGINE, "DELETES update Index: [%d] \n", ulFileIndex++);
+                                       SS_GetFileType(NULL, pFsNode->file_old_path, (enumFileType *) & ulFiletype);
+                                       if (ulFiletype == 2)            //FT_FOLDER
+                                               ulResult = SS_DeleteFolder(NULL, pFsNode->file_old_path);
+                                       else
+                                               ulResult = SS_DeleteFile(NULL, pFsNode->file_old_path);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("Delete Failed\n");
+                                               SS_SetUpgradeState(ulResult);
+                                               break;
+                                       }
+                               }
+                               pFsNode = pFsNode->nextnode;
+                       }
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t2 = atoi(ts1);
-            LOG("Shirsh time for DELETES - [%d] \n", (t2 - t1));
+                       get_time_stamp1();  //total time capturing
+                       t2 = atoi(ts1);
+                       LOG("Shirsh time for DELETES - [%d] \n", (t2 - t1));
 #endif
-        }
-        break;
+               }
+               break;
 
-    case NEWFILES:
-        {
+       case NEWFILES:
+               {
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t1 = atoi(ts1);
+                       get_time_stamp1();  //total time capturing
+                       t1 = atoi(ts1);
 #endif
-            LOGL(LOG_SSENGINE, "Starting New file upgrade for   [%s]\n", patch_path);
-            if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, (char *)patch_path, SS_NEW_COMPRESSED_FILE) >=
-                0)
-                if (_7zdecompress(SS_NEW_COMPRESSED_FILE) == 0)
-                    LOGL(LOG_SSENGINE, "7zip extracted  successfully %s\n", ua_dataSS->parti_info->ua_parti_name);
-                else
-                    LOGL(LOG_SSENGINE, "7zip extraction error for %s\n", ua_dataSS->parti_info->ua_parti_name);
-            else
-                LOGL(LOG_SSENGINE, "tar extraction error for %s\n", ua_dataSS->parti_info->ua_parti_name);
-            SS_DeleteFile(NULL, SS_NEW_COMPRESSED_FILE);
+                       LOGL(LOG_SSENGINE, "Starting New file upgrade for   [%s]\n", patch_path);
+                       if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, (char *)patch_path, SS_NEW_COMPRESSED_FILE) >=
+                               0)
+                               if (_7zdecompress(SS_NEW_COMPRESSED_FILE) == 0)
+                                       LOGL(LOG_SSENGINE, "7zip extracted  successfully %s\n", ua_dataSS->parti_info->ua_parti_name);
+                               else
+                                       LOGL(LOG_SSENGINE, "7zip extraction error for %s\n", ua_dataSS->parti_info->ua_parti_name);
+                       else
+                               LOGL(LOG_SSENGINE, "tar extraction error for %s\n", ua_dataSS->parti_info->ua_parti_name);
+                       SS_DeleteFile(NULL, SS_NEW_COMPRESSED_FILE);
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t2 = atoi(ts1);
-            LOG("Shirsh time for NEWFILES - [%d] \n", (t2 - t1));
+                       get_time_stamp1();  //total time capturing
+                       t2 = atoi(ts1);
+                       LOG("Shirsh time for NEWFILES - [%d] \n", (t2 - t1));
 #endif
-        }
-        break;
-    case SYMDIFFS:
-        {
+               }
+               break;
+       case SYMDIFFS:
+               {
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t1 = atoi(ts1);
+                       get_time_stamp1();  //total time capturing
+                       t1 = atoi(ts1);
 #endif
-            while (pFsNode) {
-                LOGL(LOG_SSENGINE, "SYMDIFFS update Index: [%d] \n", ulFileIndex++);
-                //LOG("Sym Diff file paths: [Linkname - %s] [reference file name- %s][]\n", pFsNode->file_path,pFsNode->patch_name);
-                ulResult = SS_Unlink(NULL, pFsNode->file_old_path);
-                if (ulResult == S_SS_SUCCESS)
-                    ulResult = SS_Link(NULL, pFsNode->file_new_path, pFsNode->patch_name);
-                else {
-                    LOGE("Unlink Failed\n");
-                    SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                    break;
-                }
-                SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-                pFsNode = pFsNode->nextnode;
-            }
+                       while (pFsNode) {
+                               LOGL(LOG_SSENGINE, "SYMDIFFS update Index: [%d] \n", ulFileIndex++);
+                               //LOG("Sym Diff file paths: [Linkname - %s] [reference file name- %s][]\n", pFsNode->file_path,pFsNode->patch_name);
+                               ulResult = SS_Unlink(NULL, pFsNode->file_old_path);
+                               if (ulResult == S_SS_SUCCESS)
+                                       ulResult = SS_Link(NULL, pFsNode->file_new_path, pFsNode->patch_name);
+                               else {
+                                       LOGE("Unlink Failed\n");
+                                       SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                       break;
+                               }
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                               pFsNode = pFsNode->nextnode;
+                       }
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t2 = atoi(ts1);
-            LOG("Shirsh time for SYMDIFFS - [%d] \n", (t2 - t1));
+                       get_time_stamp1();  //total time capturing
+                       t2 = atoi(ts1);
+                       LOG("Shirsh time for SYMDIFFS - [%d] \n", (t2 - t1));
 #endif
-        }
-        break;
-    case SYMNEWFILES:
-        {
-            fs_params *head_node;
-            int retry_count = 0, do_retry = 0;
+               }
+               break;
+       case SYMNEWFILES:
+               {
+                       fs_params *head_node;
+                       int retry_count = 0, do_retry = 0;
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t1 = atoi(ts1);
+                       get_time_stamp1();  //total time capturing
+                       t1 = atoi(ts1);
 #endif
  SYMLINK_CREATE:
-            head_node = pFsNode;
-            while (head_node) {
-                LOGL(LOG_SSENGINE, "SYMNEWS update Index: [%d] \n", ulFileIndex++);
-                snprintf(ubPatch, SS_MAX_FILE_PATH, "%s%s%s", patch_path, "/", head_node->patch_name);
-                LOGL(LOG_SSENGINE, "Sym New file paths: [Linkname - %s] [reference file name- %s][]\n",
-                     head_node->file_old_path, head_node->patch_name);
-                ulResult = SS_Link(NULL, head_node->file_old_path, head_node->patch_name);
-                if (ulResult == E_SS_FAILURE) {
-                    LOGE("Link Failed\n");
-                    SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                    break;
-                } else if (ulResult == ENOENT)  //to handle cases where new symlink points to a new symlink yet to be created
-                {
-                    do_retry = 1;       //we will retry the failed symlinks with error 2 (no file or dir) again after this cycle
-                    //SS_UpdateUIProgress(ua_dataSS,ulPatchCount);
-                    head_node = head_node->nextnode;
-                    continue;
-
-                }
-                SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
-                head_node = head_node->nextnode;
-            }
-            if (do_retry && (retry_count < 4)) {
-                retry_count++;
-                ulFileIndex = 0;
-                do_retry = 0;
-                goto SYMLINK_CREATE;
-            } else if (do_retry && (retry_count >= 4))  //retry to be done maximum 4 times
-            {
-                LOGE("Link Failed after %d retrys\n", retry_count);
-                //SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
-                break;
-            }
+                       head_node = pFsNode;
+                       while (head_node) {
+                               LOGL(LOG_SSENGINE, "SYMNEWS update Index: [%d] \n", ulFileIndex++);
+                               snprintf(ubPatch, SS_MAX_FILE_PATH, "%s%s%s", patch_path, "/", head_node->patch_name);
+                               LOGL(LOG_SSENGINE, "Sym New file paths: [Linkname - %s] [reference file name- %s][]\n",
+                                        head_node->file_old_path, head_node->patch_name);
+                               ulResult = SS_Link(NULL, head_node->file_old_path, head_node->patch_name);
+                               if (ulResult == E_SS_FAILURE) {
+                                       LOGE("Link Failed\n");
+                                       SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                       break;
+                               } else if (ulResult == ENOENT) {  //to handle cases where new symlink points to a new symlink yet to be created
+                                       do_retry = 1;      //we will retry the failed symlinks with error 2 (no file or dir) again after this cycle
+                                       //SS_UpdateUIProgress(ua_dataSS,ulPatchCount);
+                                       head_node = head_node->nextnode;
+                                       continue;
+                               }
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                               head_node = head_node->nextnode;
+                       }
+                       if (do_retry && (retry_count < 4)) {
+                               retry_count++;
+                               ulFileIndex = 0;
+                               do_retry = 0;
+                               goto SYMLINK_CREATE;
+                       } else if (do_retry && (retry_count >= 4)) {  //retry to be done maximum 4 times
+                               LOGE("Link Failed after %d retrys\n", retry_count);
+                               //SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                               break;
+                       }
 #ifdef TIME_PROFILING
-            get_time_stamp1();  //total time capturing
-            t2 = atoi(ts1);
-            LOG("Shirsh time for SYMNEWS - [%d] \n", (t2 - t1));
+                       get_time_stamp1();  //total time capturing
+                       t2 = atoi(ts1);
+                       LOG("Shirsh time for SYMNEWS - [%d] \n", (t2 - t1));
 #endif
-        }
-        break;
-    default:
-        break;
-    }
-    return ulResult;
+               }
+               break;
+       default:
+               break;
+       }
+       return ulResult;
 }
 
 #ifdef MEM_PROFILING
@@ -1524,7 +1515,7 @@ extern int cur_mem;
 #endif
 /*!
  *********************************************************************************
- *                     SS_FSUpdatemain
+ *                                      SS_FSUpdatemain
  *********************************************************************************
  *
  * @brief
@@ -1541,112 +1532,112 @@ extern int cur_mem;
 
 int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
 {
-    int ulResult = S_SS_SUCCESS;
-    fs_list *head_ptr_node = NULL;
-    char new_patch_path[SS_MAX_FILE_PATH] = {
-        0
-    };
-
-    if (!ua_dataSS)
-        return E_SS_BAD_PARAMS; // Set error ??
-    head_ptr_node = headptr_list[part_idx];
-
-    if (!head_ptr_node) {       //in case of power failure, try rebilding nodes again
-        SS_FSVerifyPartition(ua_dataSS, part_idx);
-        head_ptr_node = headptr_list[part_idx];
-    }
-
-    if (!head_ptr_node)
-        return E_SS_FSBADNODES;
-
-    SS_GetPartition_LocDetails(ua_dataSS, part_idx);
-
-    LOGL(LOG_SSENGINE, "FS Update Entry PartIndex: [%d]\n", part_idx);
-
-    if (head_ptr_node->del_ref == NULL) {
-        LOGL(LOG_SSENGINE, "No DEL header\n");
-    } else if (ulResult == S_SS_SUCCESS) {
-        ulResult =
-            SS_FSUpdateFile(DELETES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->del_ref,
-                            ua_dataSS->update_delta->ua_patch_path);
-    }
-
-    if (head_ptr_node->dif_ref == NULL) {
-        LOGL(LOG_SSENGINE, "No DIFF header\n");
-    } else if (ulResult == S_SS_SUCCESS) {
-        ulResult =
-            SS_FSUpdateFile(DIFFS, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->dif_ref,
-                            ua_dataSS->update_delta->ua_patch_path);
-    }
-
-    if (head_ptr_node->move_ref == NULL) {
-        LOGL(LOG_SSENGINE, "No MOVE header\n");
-    } else if (ulResult == S_SS_SUCCESS) {
-        ulResult =
-            SS_FSUpdateFile(MOVES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->move_ref,
-                            ua_dataSS->update_delta->ua_patch_path);
-    }
-
-    if (head_ptr_node->del_ref == NULL) {
-        LOGL(LOG_SSENGINE, "No DEL header\n");
-    } else if (ulResult == S_SS_SUCCESS) {
-        ulResult =
-            SS_FSUpdateFile(DELETE_END, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->del_ref,
-                            ua_dataSS->update_delta->ua_patch_path);
-    }
-
-     if (ulResult == S_SS_SUCCESS) {
-         //new file extraction start
-        snprintf(new_patch_path, SS_MAX_FILE_PATH, "%s%s", ua_dataSS->parti_info->ua_subject_name, SS_COMPRESSED_FILE);     // subject name wil have fw slash as part of cfg file
-        LOGL(LOG_SSENGINE, "File path created to extract new files : [%s]\n", new_patch_path);
-        ulResult =
-            SS_FSUpdateFile(NEWFILES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->new_ref, new_patch_path);
-        //new file extraction end
-    }
-
-    if (head_ptr_node->sym_difref == NULL) {
-        LOGL(LOG_SSENGINE, "No SYMDIFF header\n");
-    } else if (ulResult == S_SS_SUCCESS) {
-        ulResult =
-            SS_FSUpdateFile(SYMDIFFS, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->sym_difref,
-                            ua_dataSS->update_delta->ua_patch_path);
-    }
-
-    if (head_ptr_node->sym_newref == NULL) {
-        LOGL(LOG_SSENGINE, "No SYMNEW header\n");
-    } else if (ulResult == S_SS_SUCCESS) {
-        ulResult =
-            SS_FSUpdateFile(SYMNEWFILES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->sym_newref,
-                            ua_dataSS->update_delta->ua_patch_path);
-    }
-
-    if (ulResult == S_SS_SUCCESS)
-        ulResult = SS_FSSetAttributes(ua_dataSS);
-    sync();
-    sleep(1);
-    SS_FSClearNodes(part_idx);
-
-    if (ulResult == S_SS_SUCCESS)
-        SS_UpdateUIProgress(ua_dataSS, 0, 1);  //fix WGID : 51963, When all updates are done to FS , patchcount is not needed, passing 1 to 3rd arg is enough
-
-    LOGL(LOG_SSENGINE, "FS update Complete PartIndex: [%d]\n", part_idx);
+       int ulResult = S_SS_SUCCESS;
+       fs_list *head_ptr_node = NULL;
+       char new_patch_path[SS_MAX_FILE_PATH] = {
+               0
+       };
+
+       if (!ua_dataSS)
+               return E_SS_BAD_PARAMS; // Set error ??
+       head_ptr_node = headptr_list[part_idx];
+
+       if (!head_ptr_node) {      //in case of power failure, try rebilding nodes again
+               SS_FSVerifyPartition(ua_dataSS, part_idx);
+               head_ptr_node = headptr_list[part_idx];
+       }
+
+       if (!head_ptr_node)
+               return E_SS_FSBADNODES;
+
+       SS_GetPartition_LocDetails(ua_dataSS, part_idx);
+
+       LOGL(LOG_SSENGINE, "FS Update Entry PartIndex: [%d]\n", part_idx);
+
+       if (head_ptr_node->del_ref == NULL) {
+               LOGL(LOG_SSENGINE, "No DEL header\n");
+       } else if (ulResult == S_SS_SUCCESS) {
+               ulResult =
+                       SS_FSUpdateFile(DELETES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->del_ref,
+                                                       ua_dataSS->update_delta->ua_patch_path);
+       }
+
+       if (head_ptr_node->dif_ref == NULL) {
+               LOGL(LOG_SSENGINE, "No DIFF header\n");
+       } else if (ulResult == S_SS_SUCCESS) {
+               ulResult =
+                       SS_FSUpdateFile(DIFFS, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->dif_ref,
+                                                       ua_dataSS->update_delta->ua_patch_path);
+       }
+
+       if (head_ptr_node->move_ref == NULL) {
+               LOGL(LOG_SSENGINE, "No MOVE header\n");
+       } else if (ulResult == S_SS_SUCCESS) {
+               ulResult =
+                       SS_FSUpdateFile(MOVES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->move_ref,
+                                                       ua_dataSS->update_delta->ua_patch_path);
+       }
+
+       if (head_ptr_node->del_ref == NULL) {
+               LOGL(LOG_SSENGINE, "No DEL header\n");
+       } else if (ulResult == S_SS_SUCCESS) {
+               ulResult =
+                       SS_FSUpdateFile(DELETE_END, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->del_ref,
+                                                       ua_dataSS->update_delta->ua_patch_path);
+       }
+
+        if (ulResult == S_SS_SUCCESS) {
+                //new file extraction start
+               snprintf(new_patch_path, SS_MAX_FILE_PATH, "%s%s", ua_dataSS->parti_info->ua_subject_name, SS_COMPRESSED_FILE);  // subject name wil have fw slash as part of cfg file
+               LOGL(LOG_SSENGINE, "File path created to extract new files : [%s]\n", new_patch_path);
+               ulResult =
+                       SS_FSUpdateFile(NEWFILES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->new_ref, new_patch_path);
+               //new file extraction end
+       }
+
+       if (head_ptr_node->sym_difref == NULL) {
+               LOGL(LOG_SSENGINE, "No SYMDIFF header\n");
+       } else if (ulResult == S_SS_SUCCESS) {
+               ulResult =
+                       SS_FSUpdateFile(SYMDIFFS, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->sym_difref,
+                                                       ua_dataSS->update_delta->ua_patch_path);
+       }
+
+       if (head_ptr_node->sym_newref == NULL) {
+               LOGL(LOG_SSENGINE, "No SYMNEW header\n");
+       } else if (ulResult == S_SS_SUCCESS) {
+               ulResult =
+                       SS_FSUpdateFile(SYMNEWFILES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->sym_newref,
+                                                       ua_dataSS->update_delta->ua_patch_path);
+       }
+
+       if (ulResult == S_SS_SUCCESS)
+               ulResult = SS_FSSetAttributes(ua_dataSS);
+       sync();
+       sleep(1);
+       SS_FSClearNodes(part_idx);
+
+       if (ulResult == S_SS_SUCCESS)
+               SS_UpdateUIProgress(ua_dataSS, 0, 1);   //fix WGID : 51963, When all updates are done to FS , patchcount is not needed, passing 1 to 3rd arg is enough
+
+       LOGL(LOG_SSENGINE, "FS update Complete PartIndex: [%d]\n", part_idx);
 #ifdef  MEM_PROFILING
-    LOGL(LOG_SSENGINE, "Stats are : Cur Max : [%d] Global Max : [%d]\n", cur_mem, max_mem);
+       LOGL(LOG_SSENGINE, "Stats are : Cur Max : [%d] Global Max : [%d]\n", cur_mem, max_mem);
 #endif
-    if (ulResult == S_SS_SUCCESS)
-        return ulResult;
-    else
-        return SS_GetUpgradeState();
+       if (ulResult == S_SS_SUCCESS)
+               return ulResult;
+       else
+               return SS_GetUpgradeState();
 }
 
 /*!
  *********************************************************************************
- *                     SS_FSUpdatemain
+ *                                      SS_FSUpdatemain
  *********************************************************************************
  *
  * @brief
  *     This is the API exposed from the engine to update FS.
- *     FS entry function for updating FS partition. Should be invoked only after verification of the partition
+ *     FS entry function for updating FS partition. Should be invoked only after verification of the partition
  *
  *
  *     @param                          Requires common data structure having all details & Partition Index.
@@ -1661,257 +1652,253 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
 size_t SS_FSAvailiableFreeSpace(char *block_name)
 {
 
-    struct mntent *ent;
-    FILE *aFile;
-    struct statfs sb;
-    aFile = setmntent("/proc/mounts", "r");
-    if (aFile == NULL) {
-        LOGE("setmntent error");
-        return E_SS_FAILURE;
-    }
-    while (NULL != (ent = getmntent(aFile))) {
-        if (strcmp(ent->mnt_fsname, block_name) == 0) {
-            if (statfs(ent->mnt_dir, &sb) == 0) {
-                LOGL(LOG_SSENGINE, "Total free space = %d, blocks free = %d\n", sb.f_bsize * sb.f_bavail, sb.f_bfree);
-            }
-        }
-    }
-    endmntent(aFile);
-    return sb.f_bsize * sb.f_bavail;
+       struct mntent *ent;
+       FILE *aFile;
+       struct statfs sb;
+       aFile = setmntent("/proc/mounts", "r");
+       if (aFile == NULL) {
+               LOGE("setmntent error");
+               return E_SS_FAILURE;
+       }
+       while (NULL != (ent = getmntent(aFile))) {
+               if (strcmp(ent->mnt_fsname, block_name) == 0) {
+                       if (statfs(ent->mnt_dir, &sb) == 0)
+                               LOGL(LOG_SSENGINE, "Total free space = %d, blocks free = %d\n", sb.f_bsize * sb.f_bavail, sb.f_bfree);
+               }
+       }
+       endmntent(aFile);
+       return sb.f_bsize * sb.f_bavail;
 }
 
 int SS_FSVerifyPartition(ua_dataSS_t * ua_dataSS, int part_idx)
 {
-    int ulResult = S_SS_SUCCESS;
-    size_t free_space = 0;
-    if (!ua_dataSS) {
-        LOGE("Wrong Param for fs verification\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return E_SS_FAILURE;
-    }
-
-    LOGL(LOG_SSENGINE, "FS max free mem reqired : [%d]\n", ua_dataSS->update_cfg->soure_img_size);
-    free_space = SS_FSAvailiableFreeSpace(ua_dataSS->parti_info->ua_blk_name);
-    if (free_space != E_SS_FAILURE) {
-        //Source img size is max single file size for a file system under upgrade, which is updated in CFG file by UPG
-        if ((free_space) < (ua_dataSS->update_cfg->soure_img_size + ua_dataSS->update_cfg->soure_img_size / 10)) {
-            LOGE("Not enough free space [%d] for max size [%d]\n", free_space,
-                 (ua_dataSS->update_cfg->soure_img_size + ua_dataSS->update_cfg->soure_img_size / 10));
-            //SS_SetUpgradeState(E_SS_FSMEMORYERROR);
-            //return E_SS_FAILURE;
-        } else
-            LOGL(LOG_SSENGINE, "Enough space for Partition [%s]\n", ua_dataSS->parti_info->ua_parti_name);
-    }
-
-    SS_GetAvailableFreeSpace(NULL, SS_COMMON_WORKSPACE, &free_space);
-    //Checking for 2 times the file size free space , as delta can be worst case size of file.
-    if ((free_space) < (2 * ua_dataSS->update_cfg->soure_img_size)) {
-        LOGE("Not enough free space [%d] for max size [%d]\n", free_space, (2 * ua_dataSS->update_cfg->soure_img_size));
-        SS_SetUpgradeState(E_SS_FSMEMORYERROR);
-        return E_SS_FAILURE;
-    }
+       int ulResult = S_SS_SUCCESS;
+       size_t free_space = 0;
+       if (!ua_dataSS) {
+               LOGE("Wrong Param for fs verification\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return E_SS_FAILURE;
+       }
+
+       LOGL(LOG_SSENGINE, "FS max free mem reqired : [%d]\n", ua_dataSS->update_cfg->soure_img_size);
+       free_space = SS_FSAvailiableFreeSpace(ua_dataSS->parti_info->ua_blk_name);
+       if (free_space != E_SS_FAILURE) {
+               //Source img size is max single file size for a file system under upgrade, which is updated in CFG file by UPG
+               if ((free_space) < (ua_dataSS->update_cfg->soure_img_size + ua_dataSS->update_cfg->soure_img_size / 10)) {
+                       LOGE("Not enough free space [%d] for max size [%d]\n", free_space,
+                                (ua_dataSS->update_cfg->soure_img_size + ua_dataSS->update_cfg->soure_img_size / 10));
+                       //SS_SetUpgradeState(E_SS_FSMEMORYERROR);
+                       //return E_SS_FAILURE;
+               } else
+                       LOGL(LOG_SSENGINE, "Enough space for Partition [%s]\n", ua_dataSS->parti_info->ua_parti_name);
+       }
+
+       SS_GetAvailableFreeSpace(NULL, SS_COMMON_WORKSPACE, &free_space);
+       //Checking for 2 times the file size free space , as delta can be worst case size of file.
+       if ((free_space) < (2 * ua_dataSS->update_cfg->soure_img_size)) {
+               LOGE("Not enough free space [%d] for max size [%d]\n", free_space, (2 * ua_dataSS->update_cfg->soure_img_size));
+               SS_SetUpgradeState(E_SS_FSMEMORYERROR);
+               return E_SS_FAILURE;
+       }
 #ifdef MEM_PROFILING
-    if (!mem_profiling_start)
-        if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
-            return E_SS_FAILURE;
+       if (!mem_profiling_start)
+               if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
+                       return E_SS_FAILURE;
 #endif
-    SS_GetPartition_LocDetails(ua_dataSS, part_idx);
-    LOGL(LOG_SSENGINE, "FS Verification Start PartIndex:[%d]\n", part_idx);
-    if (ua_dataSS->ua_operation == UI_OP_SCOUT)
-        gvalid_session = TRUE;  // (shd b true if called during verification)
-    headptr_list[part_idx] = SS_FSBuildNodes(ua_dataSS);
+       SS_GetPartition_LocDetails(ua_dataSS, part_idx);
+       LOGL(LOG_SSENGINE, "FS Verification Start PartIndex:[%d]\n", part_idx);
+       if (ua_dataSS->ua_operation == UI_OP_SCOUT)
+               gvalid_session = TRUE;  // (shd b true if called during verification)
+       headptr_list[part_idx] = SS_FSBuildNodes(ua_dataSS);
 #ifdef TIME_PROFILING
-    LOGL(LOG_SSENGINE, "fast_tar_get_item_size_time :[%lf]\n", fast_tar_get_item_size_time);
-    LOGL(LOG_SSENGINE, "SS_LoadFile_time :[%lf]\n", SS_LoadFile_time);
-    LOGL(LOG_SSENGINE, "SS_FSBuildNodes_time :[%lf]\n", SS_FSBuildNodes_time);
+       LOGL(LOG_SSENGINE, "fast_tar_get_item_size_time :[%lf]\n", fast_tar_get_item_size_time);
+       LOGL(LOG_SSENGINE, "SS_LoadFile_time :[%lf]\n", SS_LoadFile_time);
+       LOGL(LOG_SSENGINE, "SS_FSBuildNodes_time :[%lf]\n", SS_FSBuildNodes_time);
 #endif
-    if (!headptr_list[part_idx]) {
-        LOGE("FS Verification Failed PartIndex: [%d]\n", part_idx);
-        SS_FSClearNodes(part_idx);
-        ulResult = E_SS_FAILURE;
-    }
-
-    if (ulResult == S_SS_SUCCESS)
-        return ulResult;
-    else
-        return SS_GetUpgradeState();
+       if (!headptr_list[part_idx]) {
+               LOGE("FS Verification Failed PartIndex: [%d]\n", part_idx);
+               SS_FSClearNodes(part_idx);
+               ulResult = E_SS_FAILURE;
+       }
+
+       if (ulResult == S_SS_SUCCESS)
+               return ulResult;
+       else
+               return SS_GetUpgradeState();
 }
 
 //Should check if space is available????
 int SS_BackupSource(const char *source_filename)
 {
-    int ret = E_SS_FAILURE;
-
-    if (source_filename) {
-        ret = (int)SS_CopyFile(NULL, source_filename, SS_BACKUP_SOURCE);
-        if (ret != S_SS_SUCCESS) {
-            LOGE("failed to back up source file  Error [%d]\n", ret);
-            SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
-        }
-    }
-    return ret;
+       int ret = E_SS_FAILURE;
+
+       if (source_filename) {
+               ret = (int)SS_CopyFile(NULL, source_filename, SS_BACKUP_SOURCE);
+               if (ret != S_SS_SUCCESS) {
+                       LOGE("failed to back up source file  Error [%d]\n", ret);
+                       SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
+               }
+       }
+       return ret;
 }
 
 int SS_BackupSourceClear(void)
 {
-    int ret = E_SS_FAILURE;
-    ret = (int)SS_DeleteFile(NULL, SS_BACKUP_SOURCE);
-    if (ret != S_SS_SUCCESS) {
-        LOGE("failed to delete BACKUP file\n");
-        SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
-    }
-    return ret;
+       int ret = E_SS_FAILURE;
+       ret = (int)SS_DeleteFile(NULL, SS_BACKUP_SOURCE);
+       if (ret != S_SS_SUCCESS) {
+               LOGE("failed to delete BACKUP file\n");
+               SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
+       }
+       return ret;
 }
 
 int SS_PatchSourceClear(void)
 {
-    int ret = E_SS_FAILURE;
-    ret = (int)SS_DeleteFile(NULL, SS_PATCHFILE_SOURCE);
-    if (ret != S_SS_SUCCESS) {
-        LOGE("failed to delete PATCHFILE file\n");
-        SS_SetUpgradeState(E_SS_PATCHFILE_DEL_ERROR);
-    }
-    return ret;
+       int ret = E_SS_FAILURE;
+       ret = (int)SS_DeleteFile(NULL, SS_PATCHFILE_SOURCE);
+       if (ret != S_SS_SUCCESS) {
+               LOGE("failed to delete PATCHFILE file\n");
+               SS_SetUpgradeState(E_SS_PATCHFILE_DEL_ERROR);
+       }
+       return ret;
 }
 int SS_IMGVerifyFullImage(ua_dataSS_t * ua_dataSS)
 {
-    int read_cnt = 0, patch_size = 0;
-    FileInfo source_file;
-    uint8_t target_sha1[SHA_DIGEST_SIZE];
-    int ulResult = S_SS_SUCCESS;
-
-     if (!(ua_dataSS && ua_dataSS->update_cfg && ua_dataSS->parti_info && ua_dataSS->parti_info->ua_blk_name
-            && !(ua_dataSS->update_cfg->skip_verify == 1))) {
-        LOGE("Bad structure or members\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return E_SS_FAILURE;
-    }
-
-    LOGL(LOG_SSENGINE, "FULL IMG Verification Entry BlkName:[%s]\n", ua_dataSS->parti_info->ua_blk_name);
-
-    if (ua_dataSS->update_data && ua_dataSS->parti_info && ua_dataSS->update_data->ua_delta_path
-        && ua_dataSS->parti_info->ua_subject_name)
-        patch_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name);
-    else {
-        LOGE("Bad structure members in ua_dataSS\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    if (ua_dataSS->update_cfg && ua_dataSS->update_cfg->soure_img_size && ua_dataSS->update_cfg->target_sha1)
-        LOGL(LOG_SSENGINE, "\nParams -image size [%d] sha1 [%s]\n",
-             ua_dataSS->update_cfg->soure_img_size, ua_dataSS->update_cfg->target_sha1);
-    else {
-        LOGE("Bad structure member update_cfg in ua_dataSS\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-        LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-        SS_SetUpgradeState(E_SS_IMGBADDELTA);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-
-    if ((patch_size) > 0)
-        read_cnt =
-            tar_extract_file(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name,
-                             SS_PATCHFILE_SOURCE);
-
-    if (read_cnt <= 0) {
-        LOGL(LOG_SSENGINE, "Failed to read delta\n");
-        SS_SetUpgradeState(E_SS_IMGBADDELTA);
-        ulResult = E_SS_FAILURE;
-        goto Cleanup;
-    }
-     if (SS_LoadFile(SS_PATCHFILE_SOURCE, &source_file) == 0) {
-            if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
-                LOGL(LOG_SSENGINE, "Patch Can be applied\n");
-                SS_Free(source_file.data);
-                ulResult = S_SS_SUCCESS;
-            }
-            else{
-                LOGL(LOG_SSENGINE, "Patch Cannot be applied\n");
-                SS_Free(source_file.data);
-                SS_SetUpgradeState(E_SS_IMGBADDELTA);
-                ulResult = E_SS_FAILURE;
-                goto Cleanup;
-            }
-    }
-    else{
-            LOGL(LOG_SSENGINE, "Failed to LoadFile\n");
-            SS_SetUpgradeState(E_SS_IMGBADDELTA);
-            ulResult = E_SS_FAILURE;
-    }
+       int read_cnt = 0, patch_size = 0;
+       FileInfo source_file;
+       uint8_t target_sha1[SHA_DIGEST_SIZE];
+       int ulResult = S_SS_SUCCESS;
+
+       if (!(ua_dataSS && ua_dataSS->update_cfg && ua_dataSS->parti_info &&
+                               ua_dataSS->parti_info->ua_blk_name &&
+                               !(ua_dataSS->update_cfg->skip_verify == 1))) {
+               LOGE("Bad structure or members\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return E_SS_FAILURE;
+       }
+
+       LOGL(LOG_SSENGINE, "FULL IMG Verification Entry BlkName:[%s]\n", ua_dataSS->parti_info->ua_blk_name);
+
+       if (ua_dataSS->update_data && ua_dataSS->parti_info && ua_dataSS->update_data->ua_delta_path
+               && ua_dataSS->parti_info->ua_subject_name) {
+               patch_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name);
+       } else {
+               LOGE("Bad structure members in ua_dataSS\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       if (ua_dataSS->update_cfg && ua_dataSS->update_cfg->soure_img_size && ua_dataSS->update_cfg->target_sha1) {
+               LOGL(LOG_SSENGINE, "\nParams -image size [%d] sha1 [%s]\n",
+                        ua_dataSS->update_cfg->soure_img_size, ua_dataSS->update_cfg->target_sha1);
+       } else {
+               LOGE("Bad structure member update_cfg in ua_dataSS\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
+               LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
+               SS_SetUpgradeState(E_SS_IMGBADDELTA);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+
+       if ((patch_size) > 0)
+               read_cnt = tar_extract_file(ua_dataSS->update_data->ua_delta_path,
+                               ua_dataSS->parti_info->ua_subject_name, SS_PATCHFILE_SOURCE);
+
+       if (read_cnt <= 0) {
+               LOGL(LOG_SSENGINE, "Failed to read delta\n");
+               SS_SetUpgradeState(E_SS_IMGBADDELTA);
+               ulResult = E_SS_FAILURE;
+               goto Cleanup;
+       }
+       if (SS_LoadFile(SS_PATCHFILE_SOURCE, &source_file) == 0) {
+               if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
+                       LOGL(LOG_SSENGINE, "Patch Can be applied\n");
+                       SS_Free(source_file.data);
+                       ulResult = S_SS_SUCCESS;
+               } else{
+                       LOGL(LOG_SSENGINE, "Patch Cannot be applied\n");
+                       SS_Free(source_file.data);
+                       SS_SetUpgradeState(E_SS_IMGBADDELTA);
+                       ulResult = E_SS_FAILURE;
+                       goto Cleanup;
+               }
+       } else {
+               LOGL(LOG_SSENGINE, "Failed to LoadFile\n");
+               SS_SetUpgradeState(E_SS_IMGBADDELTA);
+               ulResult = E_SS_FAILURE;
+       }
 
 Cleanup:
-    if(file_exist(SS_PATCHFILE_SOURCE, 0))
-            SS_DeleteFile(NULL, SS_PATCHFILE_SOURCE);
-    return ulResult;
+       if (file_exist(SS_PATCHFILE_SOURCE, 0))
+               SS_DeleteFile(NULL, SS_PATCHFILE_SOURCE);
+       return ulResult;
 }
 
 int SS_IMGVerfiyPartition(ua_dataSS_t * ua_dataSS)
 {
-    FileInfo source_file;
-    int ulResult = S_SS_SUCCESS;
-    uint8_t source_sha1[SHA_DIGEST_SIZE];
-    uint8_t target_sha1[SHA_DIGEST_SIZE];
-    size_t free_space = 0;
-
-    if (!(ua_dataSS && ua_dataSS->update_cfg && ua_dataSS->parti_info && ua_dataSS->parti_info->ua_blk_name)) {
-        LOGE("Bad structure or members\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return E_SS_FAILURE;
-    }
-
-    //We verify twice the image size for BACKUP source, not on Partition. As Patch will be created on RAM
-    SS_GetAvailableFreeSpace(NULL, SS_COMMON_WORKSPACE, &free_space);
-    if ((free_space) < (2 * ua_dataSS->update_cfg->target_img_size)) {
-        LOGE("Not enough free space [%d] for twice max size [%d]\n", free_space,
-             (2 * ua_dataSS->update_cfg->target_img_size));
-        SS_SetUpgradeState(E_SS_FSMEMORYERROR);
-        return E_SS_FAILURE;
-    }
-
-    if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
-        LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
-        SS_SetUpgradeState(E_SS_SHAPRASE_FAILED);
-        return E_SS_FAILURE;
-    }
-    // corner case, Parsing sha can fail if update.cfg is wrong/manually edited
-    if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-        LOGE("failed to parse Target-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-        SS_SetUpgradeState(E_SS_SHAPRASE_FAILED);
-        return E_SS_FAILURE;
-    }
-
-    source_file.size = ua_dataSS->update_cfg->soure_img_size;
-    source_file.data = NULL;
-    if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) == 0) {
-        if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-            LOGL(LOG_SSENGINE, "SS_IMGVerfiyPartition - SHA matches with source [%s] \n",
-                 ua_dataSS->parti_info->ua_blk_name);
-        } else                  // Need not compare with Target sha as once upgraded, it should NOT verify same partition again.
-        {
-            SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
-            ulResult = E_SS_FAILURE;
-        }
-    }
-    SS_Free(source_file.data);
-    if (ulResult == S_SS_SUCCESS) {
-        if (ua_dataSS->ui_progress)
-            ua_dataSS->ui_progress(ua_dataSS, 100);
-        return ulResult;
-    } else
-        return SS_GetUpgradeState();
+       FileInfo source_file;
+       int ulResult = S_SS_SUCCESS;
+       uint8_t source_sha1[SHA_DIGEST_SIZE];
+       uint8_t target_sha1[SHA_DIGEST_SIZE];
+       size_t free_space = 0;
+
+       if (!(ua_dataSS && ua_dataSS->update_cfg && ua_dataSS->parti_info && ua_dataSS->parti_info->ua_blk_name)) {
+               LOGE("Bad structure or members\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return E_SS_FAILURE;
+       }
+
+       //We verify twice the image size for BACKUP source, not on Partition. As Patch will be created on RAM
+       SS_GetAvailableFreeSpace(NULL, SS_COMMON_WORKSPACE, &free_space);
+       if ((free_space) < (2 * ua_dataSS->update_cfg->target_img_size)) {
+               LOGE("Not enough free space [%d] for twice max size [%d]\n", free_space,
+                        (2 * ua_dataSS->update_cfg->target_img_size));
+               SS_SetUpgradeState(E_SS_FSMEMORYERROR);
+               return E_SS_FAILURE;
+       }
+
+       if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
+               LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
+               SS_SetUpgradeState(E_SS_SHAPRASE_FAILED);
+               return E_SS_FAILURE;
+       }
+       // corner case, Parsing sha can fail if update.cfg is wrong/manually edited
+       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
+               LOGE("failed to parse Target-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
+               SS_SetUpgradeState(E_SS_SHAPRASE_FAILED);
+               return E_SS_FAILURE;
+       }
+
+       source_file.size = ua_dataSS->update_cfg->soure_img_size;
+       source_file.data = NULL;
+       if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) == 0) {
+               if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
+                       LOGL(LOG_SSENGINE, "SS_IMGVerfiyPartition - SHA matches with source [%s] \n",
+                                ua_dataSS->parti_info->ua_blk_name);
+               } else {                          // Need not compare with Target sha as once upgraded, it should NOT verify same partition again.
+                       SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
+                       ulResult = E_SS_FAILURE;
+               }
+       }
+       SS_Free(source_file.data);
+       if (ulResult == S_SS_SUCCESS) {
+               if (ua_dataSS->ui_progress)
+                       ua_dataSS->ui_progress(ua_dataSS, 100);
+               return ulResult;
+       } else
+               return SS_GetUpgradeState();
 }
 
 /*!
  *********************************************************************************
- *                     SS_IMGUpdatemain
+ *                                      SS_IMGUpdatemain
  *********************************************************************************
  *
  * @brief
@@ -1928,78 +1915,77 @@ int SS_IMGVerfiyPartition(ua_dataSS_t * ua_dataSS)
 
 int SS_IMGUpdatemain(ua_dataSS_t * ua_dataSS, int update_type)  //SS_FSUpdatePartition
 {
-    int read_cnt = 0, patch_size;
-    int ulResult = S_SS_SUCCESS;
-
-    //sprintf(Blk_name, "%s%s%s","EMMC",":", ua_dataSS->parti_info->ua_blk_name);
-    //LOGL(LOG_SSENGINE, "IMG Upgrade Entry BlkName:[%s]\n",Blk_name);
-    if (!ua_dataSS) {
-        LOGE("Bad structure ua_dataSS\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return E_SS_FAILURE;
-    }
-    LOGL(LOG_SSENGINE, "IMG Upgrade Entry BlkName:[%s]\n", ua_dataSS->parti_info->ua_blk_name);
-
-    if (ua_dataSS->update_data && ua_dataSS->parti_info && ua_dataSS->update_data->ua_delta_path
-        && ua_dataSS->parti_info->ua_subject_name)
-        patch_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name);
-    else {
-        LOGE("Bad structure members in ua_dataSS\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return E_SS_FAILURE;
-    }
-    if (ua_dataSS->update_cfg && ua_dataSS->update_cfg->soure_img_size && ua_dataSS->update_cfg->target_sha1)
-        LOGL(LOG_SSENGINE, "\n SS_IMGUpdatemain Params -source size [%d] sha1 [%s]",
-             ua_dataSS->update_cfg->soure_img_size, ua_dataSS->update_cfg->target_sha1);
-    else {
-        LOGE("Bad structure member update_cfg in ua_dataSS\n");
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return E_SS_FAILURE;
-    }
-
-    if ((patch_size) > 0)
-        read_cnt =
-            tar_extract_file(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name,
-                             SS_PATCHFILE_SOURCE);
-
-    if (read_cnt <= 0) {
-        ulResult = E_SS_FAILURE;
-        SS_SetUpgradeState(E_SS_IMGBADDELTA);
-        return E_SS_FAILURE;    //ulResult;
-    }
-    if (ua_dataSS->ui_progress)
-        ua_dataSS->ui_progress(ua_dataSS, 40);
-
-    if (update_type == FULL_IMG && ua_dataSS->update_data->ua_temp_path)
-        ulResult = SS_MoveFile(ua_dataSS, SS_PATCHFILE_SOURCE, ua_dataSS->update_data->ua_temp_path);
-    else if ((ua_dataSS->update_cfg->update_type == DELTA_IMG && ua_dataSS->write_data_to_blkdev)
-                    || ua_dataSS->update_cfg->update_type == EXTRA) {
-
-        FILE *fp = NULL;
-        char buf[14] = { 0, };  //to store zImage-delta magic keyword
-        ssize_t bytes_read;
-        fp = fopen(SS_PATCHFILE_SOURCE, "r");
-        bytes_read = fread(buf, 1, 13, fp);        //error check not required as any delta corruption will be caught in SS_UpdateDeltaIMG
-        if (bytes_read != 13)
-            LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)13);
-        fclose(fp);
-
-        if (strcmp(buf, SS_KERNEL_MAGIC) == 0)
-            ulResult = SS_UpdateDeltaKernel(ua_dataSS, ua_dataSS->write_data_to_blkdev);
-        else
-            ulResult = SS_UpdateDeltaIMG(ua_dataSS, ua_dataSS->write_data_to_blkdev);
-    }
-    else {
-        LOGE("Update type is INVALID - Exit \n");
-        ulResult = E_SS_FAILURE;
-        SS_SetUpgradeState(E_SS_BAD_PARAMS);
-        return E_SS_FAILURE;
-    }
-
-    if (ulResult == S_SS_SUCCESS) {
-        if (ua_dataSS->ui_progress)
-            ua_dataSS->ui_progress(ua_dataSS, 100);
-        return ulResult;
-    } else
-        return SS_GetUpgradeState();
+       int read_cnt = 0, patch_size;
+       int ulResult = S_SS_SUCCESS;
+
+       //sprintf(Blk_name, "%s%s%s","EMMC",":", ua_dataSS->parti_info->ua_blk_name);
+       //LOGL(LOG_SSENGINE, "IMG Upgrade Entry BlkName:[%s]\n",Blk_name);
+       if (!ua_dataSS) {
+               LOGE("Bad structure ua_dataSS\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return E_SS_FAILURE;
+       }
+       LOGL(LOG_SSENGINE, "IMG Upgrade Entry BlkName:[%s]\n", ua_dataSS->parti_info->ua_blk_name);
+
+       if (ua_dataSS->update_data && ua_dataSS->parti_info && ua_dataSS->update_data->ua_delta_path
+               && ua_dataSS->parti_info->ua_subject_name)
+               patch_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name);
+       else {
+               LOGE("Bad structure members in ua_dataSS\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return E_SS_FAILURE;
+       }
+       if (ua_dataSS->update_cfg && ua_dataSS->update_cfg->soure_img_size && ua_dataSS->update_cfg->target_sha1)
+               LOGL(LOG_SSENGINE, "\n SS_IMGUpdatemain Params -source size [%d] sha1 [%s]",
+                        ua_dataSS->update_cfg->soure_img_size, ua_dataSS->update_cfg->target_sha1);
+       else {
+               LOGE("Bad structure member update_cfg in ua_dataSS\n");
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return E_SS_FAILURE;
+       }
+
+       if ((patch_size) > 0)
+               read_cnt =
+                       tar_extract_file(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name,
+                                                        SS_PATCHFILE_SOURCE);
+
+       if (read_cnt <= 0) {
+               ulResult = E_SS_FAILURE;
+               SS_SetUpgradeState(E_SS_IMGBADDELTA);
+               return E_SS_FAILURE;    //ulResult;
+       }
+       if (ua_dataSS->ui_progress)
+               ua_dataSS->ui_progress(ua_dataSS, 40);
+
+       if (update_type == FULL_IMG && ua_dataSS->update_data->ua_temp_path)
+               ulResult = SS_MoveFile(ua_dataSS, SS_PATCHFILE_SOURCE, ua_dataSS->update_data->ua_temp_path);
+       else if ((ua_dataSS->update_cfg->update_type == DELTA_IMG && ua_dataSS->write_data_to_blkdev)
+                                       || ua_dataSS->update_cfg->update_type == EXTRA) {
+
+               FILE *fp = NULL;
+               char buf[14] = { 0, };  //to store zImage-delta magic keyword
+               ssize_t bytes_read;
+               fp = fopen(SS_PATCHFILE_SOURCE, "r");
+               bytes_read = fread(buf, 1, 13, fp);             //error check not required as any delta corruption will be caught in SS_UpdateDeltaIMG
+               if (bytes_read != 13)
+                       LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)13);
+               fclose(fp);
+
+               if (strcmp(buf, SS_KERNEL_MAGIC) == 0)
+                       ulResult = SS_UpdateDeltaKernel(ua_dataSS, ua_dataSS->write_data_to_blkdev);
+               else
+                       ulResult = SS_UpdateDeltaIMG(ua_dataSS, ua_dataSS->write_data_to_blkdev);
+       } else {
+               LOGE("Update type is INVALID - Exit \n");
+               ulResult = E_SS_FAILURE;
+               SS_SetUpgradeState(E_SS_BAD_PARAMS);
+               return E_SS_FAILURE;
+       }
+
+       if (ulResult == S_SS_SUCCESS) {
+               if (ua_dataSS->ui_progress)
+                       ua_dataSS->ui_progress(ua_dataSS, 100);
+               return ulResult;
+       } else
+               return SS_GetUpgradeState();
 }
index 8d3fabd..8a4e351 100755 (executable)
@@ -7,7 +7,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 #define DISPLAYRESOLUTION_SIZE 50
 
 struct details {
-    int diffs;
-    int moves;
-    int news;
-    int deletes;
-    int symdiffs;
-    int symnews;
+       int diffs;
+       int moves;
+       int news;
+       int deletes;
+       int symdiffs;
+       int symnews;
 };
 
 enum DEL_TYPE { DIFFS, MOVES, NEWFILES, DELETES, SYMDIFFS, SYMNEWFILES, DELETE_END };
-struct fs_params {              // Use Macros
-    char file_old_path[512];
-    char file_new_path[512];
-    char patch_name[256];
-    char sha1src[64];
-    char sha1trg[64];
-    int data_size;
-    int data_offset;
-    int type;                   //0 is for diff and 1 is for verbatim
-    struct fs_params *nextnode;
+struct fs_params {                       // Use Macros
+       char file_old_path[512];
+       char file_new_path[512];
+       char patch_name[256];
+       char sha1src[64];
+       char sha1trg[64];
+       int data_size;
+       int data_offset;
+       int type;                                  //0 is for diff and 1 is for verbatim
+       struct fs_params *nextnode;
 };
 typedef struct fs_params fs_params;
 
 struct fs_list {
-    fs_params *dif_ref;
-    fs_params *move_ref;
-    fs_params *new_ref;
-    fs_params *del_ref;
-    fs_params *sym_difref;
-    fs_params *sym_newref;
-    int ulPatchCount;
+       fs_params *dif_ref;
+       fs_params *move_ref;
+       fs_params *new_ref;
+       fs_params *del_ref;
+       fs_params *sym_difref;
+       fs_params *sym_newref;
+       int ulPatchCount;
 };
 typedef struct fs_list fs_list;
 struct details *get_fs_details(char *filename);
 
 int SS_AppendNode(const char *ubDeltaPath, fs_params ** headparam, fs_params ** tailparam, const char *old_path,
-                  const char *new_path, const char *patchname, const char *sha1src, const char *sha1trg, int type,
-                  char *patchpath_name);
+                                 const char *new_path, const char *patchname, const char *sha1src, const char *sha1trg, int type,
+                                 char *patchpath_name);
 extern int SS_IMGUpdatemain(ua_dataSS_t * ua_dataSS, int update_type);
 extern int SS_IMGVerfiyPartition(ua_dataSS_t * ua_dataSS);
 extern int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx);
@@ -77,10 +77,10 @@ extern int tar_open(char *tar);
 extern int fast_tar_extract_file(char *tar, char *item, char *pathname, int size, int offset);
 extern int tar_close();
 extern int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
-                            const char *source_sha1_str, const char *target_sha1_str, int patch_data_size);
+                                                       const char *source_sha1_str, const char *target_sha1_str, int patch_data_size);
 extern int tar_extract_file(char *tar, char *item, char *pathname);
 extern int _7zdecompress(char *path);
 extern void tar_free_cfg_table(tar_Data_t ** delta_tar);
 extern long SS_GetFileType(void *pbUserData, char *pLinkName, enumFileType * fileType);
 
-#endif                          //_SS_UPI_H_
+#endif                                           //_SS_UPI_H_
index 91af6fa..6dbe909 100755 (executable)
@@ -58,92 +58,92 @@ typedef unsigned long long u64;
 
 #define UNUSED(x) (void)(x)
 
-#define SS_TOTA_VERSION        "1.0.18"
-#define BSDIFF "BSDIFF40"
-#define IMGDIFF "IMGDIFF2"
-#define SECTOR_SIZE             512
+#define SS_TOTA_VERSION                        "1.0.18"
+#define BSDIFF                         "BSDIFF40"
+#define IMGDIFF                                "IMGDIFF2"
+#define SECTOR_SIZE                    512
 #define SS_KERNEL_DELTA_HEADER         128
 
 #define SS_COMMON_WORKSPACE                    "/system/opt/usr/data/fota"
 #define SS_KERNEL_UNPACK_SCRIPT                "unpack.sh"
 #define SS_KERN_UNPK_SCRIPT_PATH       SS_COMMON_WORKSPACE "/" SS_KERNEL_UNPACK_SCRIPT
-#define SS_BACKUP_SOURCE                                       SS_COMMON_WORKSPACE "/saved.file"       //How to make sure there is SPACE
-#define SS_PATCHFILE_SOURCE                            SS_COMMON_WORKSPACE "/patchfile.file"   //define in common place
-#define SS_PATCHLIST_BKUPLOC                   SS_COMMON_WORKSPACE "/patchlist.txt"
-#define SS_NEW_COMPRESSED_FILE                 SS_COMMON_WORKSPACE "/system.7z"
-#define SS_KERNEL_WORKSPACE                            SS_COMMON_WORKSPACE "/kernel-work"
-#define SS_GZIP_TARGET                                                         SS_KERNEL_WORKSPACE "/gzip"
-#define SS_STAT_TARGET                                                 SS_KERNEL_WORKSPACE "/stat"
-#define SS_DD_TARGET                                                           SS_KERNEL_WORKSPACE "/dd"
-
-#define SS_GZIP_SOURCE                                                 "system/bin/gzip"
-#define SS_STAT_SOURCE                                                 "system/usr/bin/stat"
-#define SS_DD_SOURCE                                                           "system/bin/dd"
-
-#define SS_KERNEL_MAGIC                                                "UnpackdzImage"
-#define SS_KERNEL_NAME                                                 "zImage"
-#define SS_KERNEL_TARGET_NAME                  "dzImage_final"
-#define SS_KERNEL_UNPACK_DIR                   SS_KERNEL_NAME "_unpacked"
-#define SS_PATCHLISTFOLDER                             "/p"
-#define SS_NEWPATCHFOLDER                                      "/n"
-#define SS_PATCHLISTFORMAT                             ".txt"
-#define SS_PATCH_ATTR_FORMAT                   "_attr.txt"
-#define SS_FSCOUNT_MAGIC_KEY                   "PaTcHCoUnT:"
-#define SS_FSCOUNT_MAGIG_KEYLEN                (11)    //length of  SS_FSCOUNT_MAGIC_KEY
-#define SS_IMAGE_MAGIC_KEY                      "TiZSiG@tOtA_00_:.{0,64}"
-#define SS_IMAGE_MAGIC_KEY_VAL                         SS_COMMON_WORKSPACE "/delta_sha.txt"
-
-#define SS_TOKEN_SPACE                                                         " "
-#define SS_TOKEN_NEWLINE                                       "\n"
-#define SS_TOEKN_COLON                                                 ":"
-#define SS_CHAR_FWSLASH                                                '/'
-#define SS_FWSLASH                                                                     "/"
-#define SS_NULLENTRY                                                           "0"
-#define SS_MAX_NAMELENSUPPORTED                (200)   //(Tar supports 256, But extra space is used for PartitionName, .delta, /p, so restricting filename max to 200)
-#define SS_MAX_FILE_PATH                                               (512)
-#define SS_TOKEN_MAXLINE_LEN                   (1024)
-#define SS_COMPRESSED_FILE                                     "system.7z"
-
-#define SS_STRING_DIFF                                                 "DIFF"
-#define SS_STRING_MOVE                                                 "MOVE"
-#define SS_STRING_DEL                                                          "DEL"
-#define SS_STRING_SYM                                                  "SYM"
-#define SS_STRING_NEW                                                  "NEW"
-#define SS_STRING_REG                                                          "REG"
-#define SS_STRING_TPK                                                          "TPK"
-#define SS_STRING_ZIP                                                          "ZIP"
-#define SS_STRING_END                                                  "END"
+#define SS_BACKUP_SOURCE               SS_COMMON_WORKSPACE "/saved.file"       //How to make sure there is SPACE
+#define SS_PATCHFILE_SOURCE            SS_COMMON_WORKSPACE "/patchfile.file"   //define in common place
+#define SS_PATCHLIST_BKUPLOC           SS_COMMON_WORKSPACE "/patchlist.txt"
+#define SS_NEW_COMPRESSED_FILE         SS_COMMON_WORKSPACE "/system.7z"
+#define SS_KERNEL_WORKSPACE            SS_COMMON_WORKSPACE "/kernel-work"
+#define SS_GZIP_TARGET                 SS_KERNEL_WORKSPACE "/gzip"
+#define SS_STAT_TARGET                 SS_KERNEL_WORKSPACE "/stat"
+#define SS_DD_TARGET                   SS_KERNEL_WORKSPACE "/dd"
+
+#define SS_GZIP_SOURCE                 "system/bin/gzip"
+#define SS_STAT_SOURCE                 "system/usr/bin/stat"
+#define SS_DD_SOURCE                   "system/bin/dd"
+
+#define SS_KERNEL_MAGIC                        "UnpackdzImage"
+#define SS_KERNEL_NAME                 "zImage"
+#define SS_KERNEL_TARGET_NAME          "dzImage_final"
+#define SS_KERNEL_UNPACK_DIR           SS_KERNEL_NAME "_unpacked"
+#define SS_PATCHLISTFOLDER             "/p"
+#define SS_NEWPATCHFOLDER              "/n"
+#define SS_PATCHLISTFORMAT             ".txt"
+#define SS_PATCH_ATTR_FORMAT           "_attr.txt"
+#define SS_FSCOUNT_MAGIC_KEY           "PaTcHCoUnT:"
+#define SS_FSCOUNT_MAGIG_KEYLEN                (11)    //length of  SS_FSCOUNT_MAGIC_KEY
+#define SS_IMAGE_MAGIC_KEY             "TiZSiG@tOtA_00_:.{0,64}"
+#define SS_IMAGE_MAGIC_KEY_VAL         SS_COMMON_WORKSPACE "/delta_sha.txt"
+
+#define SS_TOKEN_SPACE                 " "
+#define SS_TOKEN_NEWLINE               "\n"
+#define SS_TOEKN_COLON                 ":"
+#define SS_CHAR_FWSLASH                        '/'
+#define SS_FWSLASH                     "/"
+#define SS_NULLENTRY                   "0"
+#define SS_MAX_NAMELENSUPPORTED                (200)   //(Tar supports 256, But extra space is used for PartitionName, .delta, /p, so restricting filename max to 200)
+#define SS_MAX_FILE_PATH               (512)
+#define SS_TOKEN_MAXLINE_LEN           (1024)
+#define SS_COMPRESSED_FILE             "system.7z"
+
+#define SS_STRING_DIFF                 "DIFF"
+#define SS_STRING_MOVE                 "MOVE"
+#define SS_STRING_DEL                  "DEL"
+#define SS_STRING_SYM                  "SYM"
+#define SS_STRING_NEW                  "NEW"
+#define SS_STRING_REG                  "REG"
+#define SS_STRING_TPK                  "TPK"
+#define SS_STRING_ZIP                  "ZIP"
+#define SS_STRING_END                  "END"
 
 #ifdef SUPPORT_CONTAINER
-#define SS_ZIP_SOURCE                                                          "system/usr/bin/zip"
-#define SS_ZIP_TARGET                                                          "system/opt/data/fota/zip"
-#define SS_UNZIP_SOURCE                                                "system/usr/bin/unzip"
-#define SS_UNZIP_TARGET                                                "system/opt/data/fota/unzip"
-#define SS_FIND_CMD_SOURCE                             "system/usr/bin/find"
-#define SS_FIND_CMD_TARGET                             "system/opt/data/fota/find"
-#define SS_ZIP_COMMAND                                                 "/opt/data/fota/zip"
-#define SS_UNZIP_COMMAND                                       "/opt/data/fota/unzip"
-#define SS_FIND_COMMAND                                                "/opt/data/fota/find"
-#define SS_SEPARATOR_TOKEN                             "|"
-#define SS_NEWLINE_TOKEN                                               "\n"
-#define SS_FW_SLASH_TOKEN                                      '/'
-#define SS_CONTAINER_INFO_FILE                 "PATCH.txt"
+#define SS_ZIP_SOURCE                  "system/usr/bin/zip"
+#define SS_ZIP_TARGET                  "system/opt/data/fota/zip"
+#define SS_UNZIP_SOURCE                        "system/usr/bin/unzip"
+#define SS_UNZIP_TARGET                        "system/opt/data/fota/unzip"
+#define SS_FIND_CMD_SOURCE             "system/usr/bin/find"
+#define SS_FIND_CMD_TARGET             "system/opt/data/fota/find"
+#define SS_ZIP_COMMAND                 "/opt/data/fota/zip"
+#define SS_UNZIP_COMMAND               "/opt/data/fota/unzip"
+#define SS_FIND_COMMAND                        "/opt/data/fota/find"
+#define SS_SEPARATOR_TOKEN             "|"
+#define SS_NEWLINE_TOKEN               "\n"
+#define SS_FW_SLASH_TOKEN              '/'
+#define SS_CONTAINER_INFO_FILE         "PATCH.txt"
 #define SS_CONTAINER_WORKSPACE         SS_COMMON_WORKSPACE "/archive"
-#define SS_ARCHIVE_WORK_FOLDER         SS_CONTAINER_WORKSPACE "/tpk"
-#define SS_ARCHIVE_DELTA_FOLDER                SS_CONTAINER_WORKSPACE "/delta"
-#define SS_ARCHIVE_UNPACK_FOLDER        SS_CONTAINER_WORKSPACE "/unpack"
+#define SS_ARCHIVE_WORK_FOLDER         SS_CONTAINER_WORKSPACE "/tpk"
+#define SS_ARCHIVE_DELTA_FOLDER                SS_CONTAINER_WORKSPACE "/delta"
+#define SS_ARCHIVE_UNPACK_FOLDER       SS_CONTAINER_WORKSPACE "/unpack"
 #endif
 
 #ifdef MEM_PROFILING
-#define SS_MEMORY_USAGE_LOG                                    SS_COMMON_WORKSPACE "/log_memory"
+#define SS_MEMORY_USAGE_LOG            SS_COMMON_WORKSPACE "/log_memory"
 #define SS_MEMORY_PROFILING_SCRIPT     SS_COMMON_WORKSPACE "/mem_use.sh"
 #endif
 
 struct tar_Data {
-    int itemSize;
-    int itemOffset;
-    int itemName[256];
-    struct tar_Data *nextnode;
+       int itemSize;
+       int itemOffset;
+       int itemName[256];
+       struct tar_Data *nextnode;
 };
 typedef struct tar_Data tar_Data_t;
 
index 5fa3220..348dba0 100755 (executable)
@@ -43,15 +43,13 @@ static long __check_existence(const char *file_path)
        struct stat statbuf;
        char filename[MAX_FILE_PATH];
 
-       if (strncpy(filename, file_path, strlen(file_path) + 1) == NULL) {
-               return 0;
-       }
+       if (strncpy(filename, file_path, strlen(file_path) + 1) == NULL)
+               return 0;
        if (stat(filename, &statbuf)) {
-               if (ENOENT == errno) {
-                       return 0;
-               }
+               if (ENOENT == errno)
+                       return 0;
        }
-       return statbuf.st_size;
+       return statbuf.st_size;
 }
 
 /*-----------------------------------------------------------------------------
@@ -65,14 +63,12 @@ static int __read_from_file(const char *path, char *buf, size_t size)
        if (!path)
                return -1;
 
-       if (size == 0) {
+       if (size == 0)
                return 0;
-       }
 
        fd = open(path, O_RDONLY, 0);
-       if (fd == -1) {
+       if (fd == -1)
                return -1;
-       }
 
        count = read(fd, buf, size);
        if (count > 0) {
@@ -100,13 +96,11 @@ static int get_opt_logfile_size(void)
        */
        char buf[256];
 
-       if (__check_existence(LOG_SIZE_OPT_PATH) == 0) {
+       if (__check_existence(LOG_SIZE_OPT_PATH) == 0)
                return -1;
-       }
 
-       if (__read_from_file(LOG_SIZE_OPT_PATH, buf, sizeof(buf)) < 0) {
+       if (__read_from_file(LOG_SIZE_OPT_PATH, buf, sizeof(buf)) < 0)
                return -1;
-       }
 
        return atoi(buf);
 }
@@ -118,9 +112,8 @@ void set_max_logfile_size(void)
 {
        int size = get_opt_logfile_size();
 
-       if (size <= 0) {
+       if (size <= 0)
                size = DEF_MAX_LOG_SIZE;
-       }
 
        max_logfile_size = size;
 }
@@ -188,11 +181,10 @@ void truncate_log_file(char *log_path, int size_kb)
 
        if (size_kb == 0) {
                log_fp = fopen(log_path, "w");
-               if (log_fp == NULL) {
+               if (log_fp == NULL)
                        perror("file open error\n");
-               } else {
+               else
                        fclose(log_fp);
-               }
        }
 
        sync();
index 6c9aca5..231af30 100755 (executable)
@@ -33,37 +33,37 @@ extern void set_max_logfile_size(void);
 
 #define LOG_INFO       (1<<8)
 #define LOG_ENGINE     (1<<7)
-#define LOG_FUNCS      (1<<6)
+#define LOG_FUNCS      (1<<6)
 #define LOG_GUI                (1<<5)
-#define LOG_DEBUG      (1<<4)
-#define LOG_FILE       (1<<3)
-#define LOG_FLASH      (1<<2)
-#define LOG_SSENGINE  LOG_ENGINE
+#define LOG_DEBUG      (1<<4)
+#define LOG_FILE       (1<<3)
+#define LOG_FLASH      (1<<2)
+#define LOG_SSENGINE   LOG_ENGINE
 
 //#define DEBUG_STDOUT
 #define DEBUG_FILE
 
 #ifdef DEBUG_STDOUT
 #define LOGE(s, args...) printf("UA/ERROR(%s)  " s, __func__, ##args)   // Error log
-#define LOGL(mask, s, args...) do{if((mask) & __log_level__) printf("UA/(%s): " s,__func__, ##args);}while(0)
+#define LOGL(mask, s, args...) do { if ((mask) & __log_level__) printf("UA/(%s): " s, __func__, ##args); } while (0)
 #define LOG(s, args...) LOGL(LOG_DEBUG, s, ##args)
 
 #elif defined(DEBUG_FILE)
 #define LOGE(s, args...) (void)log_printf(__log_out_file__, "UA/ERROR(%s)  " s, __func__, ##args)
-#define LOGL(mask, s, args...) do{if((mask) & __log_level__) (void)log_printf(__log_out_file__, "UA/(%s): " s ,__func__, ##args);}while(0)
+#define LOGL(mask, s, args...) do { if ((mask) & __log_level__) (void)log_printf(__log_out_file__, "UA/(%s): " s , __func__, ##args); } while (0)
 #define LOG(s, args...) LOGL(LOG_DEBUG, s, ##args)
 
 #elif defined(DEBUG_STDOUT_FILE)        // debug printf
 #define LOGE(s, args...) do {\
                                                printf("UA/ERROR(%s)  " s, __func__, ##args);\
                                                (void)log_printf(__log_out_file__, "UA/ERROR(%s)  " s, __func__, ##args);\
-                                       }while(0)
-#define LOGL(mask, s, args...) do{ \
-                                               if((mask) & __log_level__){\
-                                                       printf("UA/(%s): " s ,__func__, ##args);\
-                                                   (void)log_printf(__log_out_file__, "UA/(%s): " s,__func__, ##args);\
-                                               }\
-                                       }while(0)
+                                       } while (0)
+#define LOGL(mask, s, args...) do { \
+                                               if ((mask) & __log_level__) {\
+                                                       printf("UA/(%s): " s , __func__, ##args);\
+                                                       (void)log_printf(__log_out_file__, "UA/(%s): " s, __func__, ##args);\
+                                               } \
+                                       } while (0)
 #define LOG(s, args...) LOGL(LOG_DEBUG, s, ##args)
 
 #else
index 5e10a88..9c63c82 100755 (executable)
@@ -7,7 +7,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 
 /* tar Header Block, from POSIX 1003.1-1990. for reference */
 #if 0
-        /* POSIX header.  */
-
-struct posix_header {           /* byte offset */
-    char name[100];             /*   0 */
-    char mode[8];               /* 100 */
-    char uid[8];                /* 108 */
-    char gid[8];                /* 116 */
-    char size[12];              /* 124 */
-    char mtime[12];             /* 136 */
-    char chksum[8];             /* 148 */
-    char typeflag;              /* 156 */
-    char linkname[100];         /* 157 */
-    char magic[6];              /* 257 */
-    char version[2];            /* 263 */
-    char uname[32];             /* 265 */
-    char gname[32];             /* 297 */
-    char devmajor[8];           /* 329 */
-    char devminor[8];           /* 337 */
-    char prefix[155];           /* 345 */
-    /* 500 */
+               /* POSIX header.  */
+
+struct posix_header {             /* byte offset */
+       char name[100];                  /*   0 */
+       char mode[8];                      /* 100 */
+       char uid[8];                            /* 108 */
+       char gid[8];                            /* 116 */
+       char size[12];                    /* 124 */
+       char mtime[12];                  /* 136 */
+       char chksum[8];                  /* 148 */
+       char typeflag;                    /* 156 */
+       char linkname[100];              /* 157 */
+       char magic[6];                    /* 257 */
+       char version[2];                        /* 263 */
+       char uname[32];                  /* 265 */
+       char gname[32];                  /* 297 */
+       char devmajor[8];                  /* 329 */
+       char devminor[8];                  /* 337 */
+       char prefix[155];                  /* 345 */
+       /* 500 */
 };
 #endif
 
@@ -64,7 +64,7 @@ struct posix_header {           /* byte offset */
 #define        TAR_LONG_NAME_SIZE              256
 #define        TAR_ITEM_TYPE_FLAG_POS  156
 
-            /*** The byte that indicates whether the prefix is present or not */
+/*** The byte that indicates whether the prefix is present or not */
 #define PREFIX_INDICATOR_BYTE 345
 #define PREFIX_LEN 155
 
@@ -72,118 +72,118 @@ struct posix_header {           /* byte offset */
 
 /* Values used in typeflag field.  */
 
-#define REGTYPE  '0'            /* regular file */
-#define AREGTYPE '\0'           /* regular file */
-#define LNKTYPE  '1'            /* link */
-#define SYMTYPE  '2'            /* reserved */
-#define CHRTYPE  '3'            /* character special */
-#define BLKTYPE  '4'            /* block special */
-#define DIRTYPE  '5'            /* directory */
-#define FIFOTYPE '6'            /* FIFO special */
-#define CONTTYPE '7'            /* reserved, for compatibility with gnu tar,
-                                   treat as regular file, where it represents
-                                   a regular file, but saved contiguously on disk */
+#define REGTYPE  '0'                   /* regular file */
+#define AREGTYPE '\0'             /* regular file */
+#define LNKTYPE  '1'                   /* link */
+#define SYMTYPE  '2'                   /* reserved */
+#define CHRTYPE  '3'                   /* character special */
+#define BLKTYPE  '4'                   /* block special */
+#define DIRTYPE  '5'                   /* directory */
+#define FIFOTYPE '6'                   /* FIFO special */
+#define CONTTYPE '7'                   /* reserved, for compatibility with gnu tar,
+                                                                  treat as regular file, where it represents
+                                                                  a regular file, but saved contiguously on disk */
 
 /* GNU tar extensions */
 
-#define GNUTYPE_DUMPDIR  'D'    /* file names from dumped directory */
-#define GNUTYPE_LONGLINK 'K'    /* long link name */
-#define GNUTYPE_LONGNAME 'L'    /* long file name */
-#define GNUTYPE_MULTIVOL 'M'    /* continuation of file from another volume */
-#define GNUTYPE_NAMES    'N'    /* file name that does not fit into main hdr */
-#define GNUTYPE_SPARSE   'S'    /* sparse file */
-#define GNUTYPE_VOLHDR   'V'    /* tape/volume header */
+#define GNUTYPE_DUMPDIR  'D'   /* file names from dumped directory */
+#define GNUTYPE_LONGLINK 'K'   /* long link name */
+#define GNUTYPE_LONGNAME 'L'   /* long file name */
+#define GNUTYPE_MULTIVOL 'M'   /* continuation of file from another volume */
+#define GNUTYPE_NAMES  'N'     /* file name that does not fit into main hdr */
+#define GNUTYPE_SPARSE   'S'   /* sparse file */
+#define GNUTYPE_VOLHDR   'V'   /* tape/volume header */
 
 extern void *SS_Malloc(SS_UINT32 size);
 
-int gTarFd = -1;                // Currenlty this logic supports only one tar file
+int gTarFd = -1;                               // Currenlty this logic supports only one tar file
 
 /* Parse an octal number, ignoring leading and trailing nonsense. */
 static int parseoct(const char *p, size_t n)
 {
-    int i = 0;
-
-    while (*p < '0' || *p > '7') {
-        ++p;
-        --n;
-    }
-    while (*p >= '0' && *p <= '7' && n > 0) {
-        i *= 8;
-        i += *p - '0';
-        ++p;
-        --n;
-    }
-    return (i);
+       int i = 0;
+
+       while (*p < '0' || *p > '7') {
+               ++p;
+               --n;
+       }
+       while (*p >= '0' && *p <= '7' && n > 0) {
+               i *= 8;
+               i += *p - '0';
+               ++p;
+               --n;
+       }
+       return (i);
 }
 
 /* Verify the tar checksum. */
 static int verify_checksum(const char *p)
 {
-    int n, u = 0;
-    for (n = 0; n < 512; ++n) {
-        if (n < 148 || n > 155)
-            /* Standard tar checksum adds unsigned bytes. */
-            u += ((unsigned char *)p)[n];
-        else
-            u += 0x20;
-
-    }
-    return (u == parseoct(p + 148, 8));
+       int n, u = 0;
+       for (n = 0; n < 512; ++n) {
+               if (n < 148 || n > 155)
+                       /* Standard tar checksum adds unsigned bytes. */
+                       u += ((unsigned char *)p)[n];
+               else
+                       u += 0x20;
+
+       }
+       return (u == parseoct(p + 148, 8));
 }
 
 static int is_end_of_archive(const char *p)
 {
-    int n;
-    for (n = 511; n >= 0; --n)
-        if (p[n] != '\0')
-            return (0);
-    return (1);
+       int n;
+       for (n = 511; n >= 0; --n)
+               if (p[n] != '\0')
+                       return (0);
+       return (1);
 }
 
 void create_dir(char *pathname, int mode)
 {
-    char *p;
-    int r;
-
-    /* Strip trailing '/' */
-    if (pathname[strlen(pathname) - 1] == '/')
-        pathname[strlen(pathname) - 1] = '\0';
-
-    /* Try creating the directory. */
-    r = mkdir(pathname, mode);
-
-    if (r != 0) {
-        /* On failure, try creating parent directory. */
-        p = strrchr(pathname, '/');
-        if (p != NULL) {
-            *p = '\0';
-            create_dir(pathname, 0755);
-            *p = '/';
-            r = mkdir(pathname, mode);
-        }
-    }
-    if (r != 0) {
-        if (r != EEXIST && r != -1)
-            LOG("Could not create directory [%s] Error[%d]\n", pathname, r);
-    }
+       char *p;
+       int r;
+
+       /* Strip trailing '/' */
+       if (pathname[strlen(pathname) - 1] == '/')
+               pathname[strlen(pathname) - 1] = '\0';
+
+       /* Try creating the directory. */
+       r = mkdir(pathname, mode);
+
+       if (r != 0) {
+               /* On failure, try creating parent directory. */
+               p = strrchr(pathname, '/');
+               if (p != NULL) {
+                       *p = '\0';
+                       create_dir(pathname, 0755);
+                       *p = '/';
+                       r = mkdir(pathname, mode);
+               }
+       }
+       if (r != 0) {
+               if (r != EEXIST && r != -1)
+                       LOG("Could not create directory [%s] Error[%d]\n", pathname, r);
+       }
 }
 
 /* Create a file, including parent directory as necessary. */
 static FILE *create_file(char *pathname, int mode)
 {
-    FILE *f;
-    f = fopen(pathname, "w+");
-    if (f == NULL) {
-        /* Try creating parent dir and then creating file. */
-        char *p = strrchr(pathname, '/');
-        if (p != NULL) {
-            *p = '\0';
-            create_dir(pathname, 0755);
-            *p = '/';
-            f = fopen(pathname, "w+");
-        }
-    }
-    return (f);
+       FILE *f;
+       f = fopen(pathname, "w+");
+       if (f == NULL) {
+               /* Try creating parent dir and then creating file. */
+               char *p = strrchr(pathname, '/');
+               if (p != NULL) {
+                       *p = '\0';
+                       create_dir(pathname, 0755);
+                       *p = '/';
+                       f = fopen(pathname, "w+");
+               }
+       }
+       return (f);
 }
 
 /*-----------------------------------------------------------------------------
@@ -191,79 +191,79 @@ static FILE *create_file(char *pathname, int mode)
  ----------------------------------------------------------------------------*/
 int tar_get_item_offset(char *tar, char *item)
 {
-    int ret = -1;
-    int fd = -1;
-    char header[TAR_BLOCK_SIZE] = { 0, };
-    char name[TAR_ITEM_NAME_SIZE + 1] = { 0, };
-    char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
-    int size_dec = 0;
-    int blknum = 0;
-    off_t pos = 0;
-    off_t tar_len = 0;
-    ssize_t rdcnt = 0;
-
-    //check if gTarFd was opened by tar_open during SS_FSUpdateFile then use it
-    if (gTarFd > 0)
-        fd = gTarFd;
-    if (fd < 0) {
-        fd = open(tar, O_RDONLY);
-        if (fd < 0) {
-            LOGE("can't open file(%s).\n", tar);
-            return -1;
-        }
-    }
-
-    tar_len = lseek(fd, 0, SEEK_END);
-    if (tar_len < 0) {
-        LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
-        goto Cleanup;
-    }
-    pos = lseek(fd, 0, SEEK_SET);
-    if (pos < 0) {
-        LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
-        goto Cleanup;
-    }
-    while (pos < tar_len) {
-        /* read file header */
-        rdcnt = read(fd, header, sizeof(header));
-        if (rdcnt <= 0) {
-            LOG("read failed. (rdcnt=%d)\n", rdcnt);
-            break;
-        }
-
-        /* get file name and file size */
-        memcpy(name, header, sizeof(name) - 1);
-        memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
-        size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
-        if (size_dec > MAX_ITEM_SIZE) {
-            LOG("size too big. (size_dec=0x%08X)\n", size_dec);
-            break;
-        }
-
-        /* check if the file is what we are looking for */
-        if (strncmp(name, item, TAR_ITEM_NAME_SIZE) == 0) {
-            ret = (int)lseek(fd, 0, SEEK_CUR);
-            break;
-        }
-
-        /* move file pointer to next file header */
-        blknum = size_dec / TAR_BLOCK_SIZE;
-        if (size_dec % TAR_BLOCK_SIZE)
-            blknum++;
-
-        pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
-        if (pos < 0) {
-            LOGE("can't read next block (%s).\n", tar);
-            close(fd);
-            return -1;
-        }
-    }
+       int ret = -1;
+       int fd = -1;
+       char header[TAR_BLOCK_SIZE] = { 0, };
+       char name[TAR_ITEM_NAME_SIZE + 1] = { 0, };
+       char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
+       int size_dec = 0;
+       int blknum = 0;
+       off_t pos = 0;
+       off_t tar_len = 0;
+       ssize_t rdcnt = 0;
+
+       //check if gTarFd was opened by tar_open during SS_FSUpdateFile then use it
+       if (gTarFd > 0)
+               fd = gTarFd;
+       if (fd < 0) {
+               fd = open(tar, O_RDONLY);
+               if (fd < 0) {
+                       LOGE("can't open file(%s).\n", tar);
+                       return -1;
+               }
+       }
+
+       tar_len = lseek(fd, 0, SEEK_END);
+       if (tar_len < 0) {
+               LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
+               goto Cleanup;
+       }
+       pos = lseek(fd, 0, SEEK_SET);
+       if (pos < 0) {
+               LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
+               goto Cleanup;
+       }
+       while (pos < tar_len) {
+               /* read file header */
+               rdcnt = read(fd, header, sizeof(header));
+               if (rdcnt <= 0) {
+                       LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                       break;
+               }
+
+               /* get file name and file size */
+               memcpy(name, header, sizeof(name) - 1);
+               memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
+               size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
+               if (size_dec > MAX_ITEM_SIZE) {
+                       LOG("size too big. (size_dec=0x%08X)\n", size_dec);
+                       break;
+               }
+
+               /* check if the file is what we are looking for */
+               if (strncmp(name, item, TAR_ITEM_NAME_SIZE) == 0) {
+                       ret = (int)lseek(fd, 0, SEEK_CUR);
+                       break;
+               }
+
+               /* move file pointer to next file header */
+               blknum = size_dec / TAR_BLOCK_SIZE;
+               if (size_dec % TAR_BLOCK_SIZE)
+                       blknum++;
+
+               pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
+               if (pos < 0) {
+                       LOGE("can't read next block (%s).\n", tar);
+                       close(fd);
+                       return -1;
+               }
+       }
 
  Cleanup:
-    if (gTarFd < 0)
-        close(fd);
+       if (gTarFd < 0)
+               close(fd);
 
-    return ret;
+       return ret;
 }
 
 /*-----------------------------------------------------------------------------
@@ -271,93 +271,93 @@ int tar_get_item_offset(char *tar, char *item)
  ----------------------------------------------------------------------------*/
 int tar_get_item_size(char *tar, char *item)
 {
-    int ret = -1;
-    int fd = -1;
-    char header[TAR_BLOCK_SIZE] = { 0, };
-    char uExtendedName[MAX_FILE_PATH] = { 0, };
-    char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
-    unsigned long size_dec = 0;
-    int blknum = 0;
-    off_t pos = 0;
-    off_t tar_len = 0;
-    ssize_t rdcnt = 0;
-    LOGL(LOG_SSENGINE, "Tar file Looking for (%s)\n", item);
-    fd = open(tar, O_RDONLY);
-    if (fd < 0) {
-        LOG("can't open file(%s).\n", tar);
-        return -1;
-    }
-
-    tar_len = lseek(fd, 0, SEEK_END);
-    if (tar_len < 0) {
-        LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
-        goto Cleanup;
-    }
-    pos = lseek(fd, 0, SEEK_SET);
-    if (pos < 0) {
-        LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
-        goto Cleanup;
-    }
-
-    while (pos < tar_len) {
-        /* read file header */
-        rdcnt = read(fd, header, sizeof(header));
-        if (rdcnt <= 0) {
-            LOG("read failed. (rdcnt=%d)\n", rdcnt);
-            break;
-        }
-
-        /* get file name and file size */
-        if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) {
-            //rdcnt = read(fd, header, sizeof(header));
-            memset(uExtendedName, 0, sizeof(uExtendedName));
-            rdcnt = read(fd, uExtendedName, sizeof(uExtendedName));
-            if (rdcnt <= 0) {
-                LOG("read failed. (rdcnt=%d)\n", rdcnt);
-                break;
-            }
-            rdcnt = read(fd, header, sizeof(header));
-            if (rdcnt <= 0) {
-                LOG("read failed. (rdcnt=%d)\n", rdcnt);
-                break;
-            }
-        } else {
-            memset(uExtendedName, 0, sizeof(uExtendedName));
-            memcpy(uExtendedName, header, TAR_ITEM_NAME_SIZE);
-        }
-        //memcpy(name, header, sizeof(name));
-        memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
-        size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
-        if (size_dec > MAX_ITEM_SIZE) {
-            LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
-            break;
-        }
-
-        /* check if the file is what we are looking for */
-        if (strcmp(uExtendedName, item) == 0) {
-            ret = (int)size_dec;
-            if ((ret == 0) && (header[TAR_ITEM_TYPE_FLAG_POS] == DIRTYPE))
-                ret = tar_get_folder_size(tar, item);
-            break;
-        }
-        /* move file pointer to next file header */
-        //LOGL(LOG_SSENGINE,"Item in Tar (%s)\n", uExtendedName);
-        blknum = size_dec / TAR_BLOCK_SIZE;
-        if (size_dec % TAR_BLOCK_SIZE)
-            blknum++;
-
-        pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
-        if (pos < 0) {
-            LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
-            close(fd);
-            return -1;
-        }
-    }
+       int ret = -1;
+       int fd = -1;
+       char header[TAR_BLOCK_SIZE] = { 0, };
+       char uExtendedName[MAX_FILE_PATH] = { 0, };
+       char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
+       unsigned long size_dec = 0;
+       int blknum = 0;
+       off_t pos = 0;
+       off_t tar_len = 0;
+       ssize_t rdcnt = 0;
+       LOGL(LOG_SSENGINE, "Tar file Looking for (%s)\n", item);
+       fd = open(tar, O_RDONLY);
+       if (fd < 0) {
+               LOG("can't open file(%s).\n", tar);
+               return -1;
+       }
+
+       tar_len = lseek(fd, 0, SEEK_END);
+       if (tar_len < 0) {
+               LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
+               goto Cleanup;
+       }
+       pos = lseek(fd, 0, SEEK_SET);
+       if (pos < 0) {
+               LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
+               goto Cleanup;
+       }
+
+       while (pos < tar_len) {
+               /* read file header */
+               rdcnt = read(fd, header, sizeof(header));
+               if (rdcnt <= 0) {
+                       LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                       break;
+               }
+
+               /* get file name and file size */
+               if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) {
+                       //rdcnt = read(fd, header, sizeof(header));
+                       memset(uExtendedName, 0, sizeof(uExtendedName));
+                       rdcnt = read(fd, uExtendedName, sizeof(uExtendedName));
+                       if (rdcnt <= 0) {
+                               LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                               break;
+                       }
+                       rdcnt = read(fd, header, sizeof(header));
+                       if (rdcnt <= 0) {
+                               LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                               break;
+                       }
+               } else {
+                       memset(uExtendedName, 0, sizeof(uExtendedName));
+                       memcpy(uExtendedName, header, TAR_ITEM_NAME_SIZE);
+               }
+               //memcpy(name, header, sizeof(name));
+               memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
+               size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
+               if (size_dec > MAX_ITEM_SIZE) {
+                       LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
+                       break;
+               }
+
+               /* check if the file is what we are looking for */
+               if (strcmp(uExtendedName, item) == 0) {
+                       ret = (int)size_dec;
+                       if ((ret == 0) && (header[TAR_ITEM_TYPE_FLAG_POS] == DIRTYPE))
+                               ret = tar_get_folder_size(tar, item);
+                       break;
+               }
+               /* move file pointer to next file header */
+               //LOGL(LOG_SSENGINE,"Item in Tar (%s)\n", uExtendedName);
+               blknum = size_dec / TAR_BLOCK_SIZE;
+               if (size_dec % TAR_BLOCK_SIZE)
+                       blknum++;
+
+               pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
+               if (pos < 0) {
+                       LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
+                       close(fd);
+                       return -1;
+               }
+       }
 
  Cleanup:
-    close(fd);
+       close(fd);
 
-    return ret;
+       return ret;
 }
 
 /*-----------------------------------------------------------------------------
@@ -366,76 +366,76 @@ int tar_get_item_size(char *tar, char *item)
 
 char tar_get_item_type(char *tar, char *item)
 {
-    char ret = '0';
-    int fd = -1;
-    char header[TAR_BLOCK_SIZE] = { 0, };
-    char name[TAR_ITEM_NAME_SIZE + 1] = { 0, };
-    char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
-    unsigned long size_dec = 0;
-    int blknum = 0;
-    off_t pos = 0;
-    off_t tar_len = 0;
-    ssize_t rdcnt = 0;
-    //LOG("Tar file Looking for (%s)\n", item);
-    fd = open(tar, O_RDONLY);
-    if (fd < 0) {
-        LOG("can't open file(%s).\n", tar);
-        return -1;
-    }
-
-    tar_len = lseek(fd, 0, SEEK_END);
-    if (tar_len < 0) {
-        LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
-        goto Cleanup;
-    }
-    pos = lseek(fd, 0, SEEK_SET);
-    if (pos < 0) {
-        LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
-        goto Cleanup;
-    }
-
-    while (pos < tar_len) {
-        /* read file header */
-        rdcnt = read(fd, header, sizeof(header));
-        if (rdcnt <= 0) {
-            LOG("read failed. (rdcnt=%d)\n", rdcnt);
-            ret = -1;
-            break;
-        }
-
-        /* get file name and file size */
-        memcpy(name, header, sizeof(name) - 1);
-        memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
-        size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
-        if (size_dec > MAX_ITEM_SIZE) {
-            LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
-            ret = -1;
-            break;
-        }
-
-        /* check if the file is what we are looking for */
-        if (strncmp(name, item, TAR_ITEM_NAME_SIZE) == 0) {
-            ret = header[TAR_ITEM_TYPE_FLAG_POS];
-            break;
-        }
-
-        /* move file pointer to next file header */
-        blknum = size_dec / TAR_BLOCK_SIZE;
-        if (size_dec % TAR_BLOCK_SIZE)
-            blknum++;
-
-        pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
-        if (pos < 0) {
-            LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
-            close(fd);
-            return -1;
-        }
-    }
+       char ret = '0';
+       int fd = -1;
+       char header[TAR_BLOCK_SIZE] = { 0, };
+       char name[TAR_ITEM_NAME_SIZE + 1] = { 0, };
+       char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
+       unsigned long size_dec = 0;
+       int blknum = 0;
+       off_t pos = 0;
+       off_t tar_len = 0;
+       ssize_t rdcnt = 0;
+       //LOG("Tar file Looking for (%s)\n", item);
+       fd = open(tar, O_RDONLY);
+       if (fd < 0) {
+               LOG("can't open file(%s).\n", tar);
+               return -1;
+       }
+
+       tar_len = lseek(fd, 0, SEEK_END);
+       if (tar_len < 0) {
+               LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
+               goto Cleanup;
+       }
+       pos = lseek(fd, 0, SEEK_SET);
+       if (pos < 0) {
+               LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
+               goto Cleanup;
+       }
+
+       while (pos < tar_len) {
+               /* read file header */
+               rdcnt = read(fd, header, sizeof(header));
+               if (rdcnt <= 0) {
+                       LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                       ret = -1;
+                       break;
+               }
+
+               /* get file name and file size */
+               memcpy(name, header, sizeof(name) - 1);
+               memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
+               size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
+               if (size_dec > MAX_ITEM_SIZE) {
+                       LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
+                       ret = -1;
+                       break;
+               }
+
+               /* check if the file is what we are looking for */
+               if (strncmp(name, item, TAR_ITEM_NAME_SIZE) == 0) {
+                       ret = header[TAR_ITEM_TYPE_FLAG_POS];
+                       break;
+               }
+
+               /* move file pointer to next file header */
+               blknum = size_dec / TAR_BLOCK_SIZE;
+               if (size_dec % TAR_BLOCK_SIZE)
+                       blknum++;
+
+               pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
+               if (pos < 0) {
+                       LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
+                       close(fd);
+                       return -1;
+               }
+       }
 
  Cleanup:
-    close(fd);
+       close(fd);
 
-    return ret;
+       return ret;
 }
 
 /*-----------------------------------------------------------------------------
@@ -443,681 +443,677 @@ char tar_get_item_type(char *tar, char *item)
  ----------------------------------------------------------------------------*/
 int tar_get_cfg_data(char *tar, char *item, char *buf, int buflen)
 {
-    int fd = -1;
-    int data_size = -1;
-    int data_offset = -1;
-    off_t pos = 0;
-    ssize_t rdcnt = 0;
-
-    data_size = tar_get_item_size(tar, item);
-    if (data_size <= 0) {
-        return -1;
-    }
-
-    if (data_size > buflen) {
-        data_size = buflen;
-    }
-
-    data_offset = tar_get_item_offset(tar, item);
-    if (data_offset < 0) {
-        return -1;
-    }
-
-    fd = open(tar, O_RDONLY);
-    if (fd < 0) {
-        LOG("can't open file(%s).\n", tar);
-        return -1;
-    }
-
-    pos = lseek(fd, data_offset, SEEK_SET);
-    if (pos < 0) {
-        LOG("lseek fail (%s offset %d).\n", tar, data_offset);
-        close(fd);
-        return -1;
-    }
-
-    rdcnt = read(fd, buf, data_size);
-    if (rdcnt != (ssize_t) data_size) {
-        LOG("read fail(%s from %s).\n", item, tar);
-        close(fd);
-        return -1;
-    }
-
-    close(fd);
-
-    return rdcnt;
+       int fd = -1;
+       int data_size = -1;
+       int data_offset = -1;
+       off_t pos = 0;
+       ssize_t rdcnt = 0;
+
+       data_size = tar_get_item_size(tar, item);
+       if (data_size <= 0)
+               return -1;
+
+       if (data_size > buflen)
+               data_size = buflen;
+
+       data_offset = tar_get_item_offset(tar, item);
+       if (data_offset < 0)
+               return -1;
+
+       fd = open(tar, O_RDONLY);
+       if (fd < 0) {
+               LOG("can't open file(%s).\n", tar);
+               return -1;
+       }
+
+       pos = lseek(fd, data_offset, SEEK_SET);
+       if (pos < 0) {
+               LOG("lseek fail (%s offset %d).\n", tar, data_offset);
+               close(fd);
+               return -1;
+       }
+
+       rdcnt = read(fd, buf, data_size);
+       if (rdcnt != (ssize_t) data_size) {
+               LOG("read fail(%s from %s).\n", item, tar);
+               close(fd);
+               return -1;
+       }
+
+       close(fd);
+
+       return rdcnt;
 }
 
 tar_Data_t *tar_build_cfg_table(char *tar)
 {
 
-    int fd = -1;
-    int ret = 0;
-    char header[TAR_BLOCK_SIZE] = { 0, };
-    char uExtendedName[MAX_FILE_PATH] = { 0, };
-    char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
-    unsigned long size_dec = 0;
-    int blknum = 0;
-    off_t pos = 0;
-    off_t tar_len = 0;
-    ssize_t rdcnt = 0;
-
-    int itemSize;
-    int itemOffset;
-    tar_Data_t *headparam = NULL, *tailparam = NULL, *newnode = NULL;
-    tar_Data_t *local_temp = NULL;
-    tar_Data_t *local_next = NULL;
-    if (!tar) {
-        LOGE("Bad param tar\n");
-        return NULL;
-    }
-    //check if gTarFd was opened by tar_open during SS_FSUpdateFile then use it
-    if (gTarFd > 0)
-        fd = gTarFd;
-    if (fd < 0) {
-        fd = open(tar, O_RDONLY);
-        if (fd < 0) {
-            LOG("can't open file(%s).\n", tar);
-            return NULL;
-        }
-    }
-    tar_len = lseek(fd, 0, SEEK_END);
-    if (tar_len < 0) {
-        LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
-        goto Cleanup;
-    }
-    pos = lseek(fd, 0, SEEK_SET);
-    if (pos < 0) {
-        LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
-        goto Cleanup;
-    }
-    while (pos < tar_len) {
-        /* read file header */
-        rdcnt = read(fd, header, sizeof(header));
-        if (rdcnt <= 0) {
-            LOG("read failed. (rdcnt=%d)\n", rdcnt);
-            ret = -1;
-            break;
-        }
-        /* get file name and file size */
-        //memcpy(name, header, sizeof(name));
-        if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) {
-            //rdcnt = read(fd, header, sizeof(header));
-            memset(uExtendedName, 0, sizeof(uExtendedName));
-            rdcnt = read(fd, uExtendedName, sizeof(uExtendedName));
-            if (rdcnt <= 0) {
-                LOG("read failed. (rdcnt=%d)\n", rdcnt);
-                ret = -1;
-                break;
-            }
-            rdcnt = read(fd, header, sizeof(header));
-            if (rdcnt <= 0) {
-                LOG("read failed. (rdcnt=%d)\n", rdcnt);
-                ret = -1;
-                break;
-            }
-        } else {
-            memset(uExtendedName, 0, sizeof(uExtendedName));
-            memcpy(uExtendedName, header, TAR_ITEM_NAME_SIZE);
-        }
-        memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
-        size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
-        if (size_dec > MAX_ITEM_SIZE) {
-            LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
-            ret = -1;
-            break;
-        }
-        //fix WGID : 51254 , size_dec comparison is not required
-        if ((strstr(uExtendedName, "/diff") != NULL)) //add only delta files from rootfs and csc, hardcoding shd b removed..
-        {
-
-            /* check if the file is what we are looking for */
-            //strncpy(itemName, name,100);
-            itemSize = (int)size_dec;
-            itemOffset = (int)lseek(fd, 0, SEEK_CUR);
-            newnode = (tar_Data_t *) SS_Malloc(sizeof(tar_Data_t));
-            if (!newnode) {
-                ret = -1;
-                break;
-            }
-            strncpy((char *)newnode->itemName, uExtendedName, sizeof(newnode->itemName));
-            newnode->itemOffset = itemOffset;
-            newnode->itemSize = itemSize;
-            newnode->nextnode = NULL;
-            if (headparam == NULL) {
-                headparam = newnode;
-                tailparam = newnode;
-            } else {
-                (tailparam)->nextnode = newnode;
-                (tailparam) = (tailparam)->nextnode;
-            }
-        }
-
-        /* move file pointer to next file header */
-        blknum = size_dec / TAR_BLOCK_SIZE;
-        if (size_dec % TAR_BLOCK_SIZE)
-            blknum++;
-
-        pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
-        if (pos < 0) {
-            LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
-            ret = -1;
-            break;
-        }
-    }
+       int fd = -1;
+       int ret = 0;
+       char header[TAR_BLOCK_SIZE] = { 0, };
+       char uExtendedName[MAX_FILE_PATH] = { 0, };
+       char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
+       unsigned long size_dec = 0;
+       int blknum = 0;
+       off_t pos = 0;
+       off_t tar_len = 0;
+       ssize_t rdcnt = 0;
+
+       int itemSize;
+       int itemOffset;
+       tar_Data_t *headparam = NULL, *tailparam = NULL, *newnode = NULL;
+       tar_Data_t *local_temp = NULL;
+       tar_Data_t *local_next = NULL;
+       if (!tar) {
+               LOGE("Bad param tar\n");
+               return NULL;
+       }
+       //check if gTarFd was opened by tar_open during SS_FSUpdateFile then use it
+       if (gTarFd > 0)
+               fd = gTarFd;
+       if (fd < 0) {
+               fd = open(tar, O_RDONLY);
+               if (fd < 0) {
+                       LOG("can't open file(%s).\n", tar);
+                       return NULL;
+               }
+       }
+       tar_len = lseek(fd, 0, SEEK_END);
+       if (tar_len < 0) {
+               LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
+               goto Cleanup;
+       }
+       pos = lseek(fd, 0, SEEK_SET);
+       if (pos < 0) {
+               LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
+               goto Cleanup;
+       }
+       while (pos < tar_len) {
+               /* read file header */
+               rdcnt = read(fd, header, sizeof(header));
+               if (rdcnt <= 0) {
+                       LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                       ret = -1;
+                       break;
+               }
+               /* get file name and file size */
+               //memcpy(name, header, sizeof(name));
+               if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) {
+                       //rdcnt = read(fd, header, sizeof(header));
+                       memset(uExtendedName, 0, sizeof(uExtendedName));
+                       rdcnt = read(fd, uExtendedName, sizeof(uExtendedName));
+                       if (rdcnt <= 0) {
+                               LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                               ret = -1;
+                               break;
+                       }
+                       rdcnt = read(fd, header, sizeof(header));
+                       if (rdcnt <= 0) {
+                               LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                               ret = -1;
+                               break;
+                       }
+               } else {
+                       memset(uExtendedName, 0, sizeof(uExtendedName));
+                       memcpy(uExtendedName, header, TAR_ITEM_NAME_SIZE);
+               }
+               memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
+               size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
+               if (size_dec > MAX_ITEM_SIZE) {
+                       LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
+                       ret = -1;
+                       break;
+               }
+               //fix WGID : 51254 , size_dec comparison is not required
+               if ((strstr(uExtendedName, "/diff") != NULL)) { //add only delta files from rootfs and csc, hardcoding shd b removed..
+
+                       /* check if the file is what we are looking for */
+                       //strncpy(itemName, name,100);
+                       itemSize = (int)size_dec;
+                       itemOffset = (int)lseek(fd, 0, SEEK_CUR);
+                       newnode = (tar_Data_t *) SS_Malloc(sizeof(tar_Data_t));
+                       if (!newnode) {
+                               ret = -1;
+                               break;
+                       }
+                       strncpy((char *)newnode->itemName, uExtendedName, sizeof(newnode->itemName));
+                       newnode->itemOffset = itemOffset;
+                       newnode->itemSize = itemSize;
+                       newnode->nextnode = NULL;
+                       if (headparam == NULL) {
+                               headparam = newnode;
+                               tailparam = newnode;
+                       } else {
+                               (tailparam)->nextnode = newnode;
+                               (tailparam) = (tailparam)->nextnode;
+                       }
+               }
+
+               /* move file pointer to next file header */
+               blknum = size_dec / TAR_BLOCK_SIZE;
+               if (size_dec % TAR_BLOCK_SIZE)
+                       blknum++;
+
+               pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
+               if (pos < 0) {
+                       LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
+                       ret = -1;
+                       break;
+               }
+       }
  Cleanup:
-    //if gTarFd was opened by tar_open during SS_FSUpdateFile we do not close it
-    if (gTarFd < 0)
-        close(fd);
-    if (ret != -1)
-        return headparam;
-    else {
-        if (newnode)
-            SS_Free(newnode);
-        if (headparam) {
-            local_temp = headparam;
-            while (local_temp) {
-                local_next = local_temp->nextnode;
-                SS_Free(local_temp);
-                local_temp = local_next;
-            }
-        }
-        return NULL;
-    }
+       //if gTarFd was opened by tar_open during SS_FSUpdateFile we do not close it
+       if (gTarFd < 0)
+               close(fd);
+       if (ret != -1)
+               return headparam;
+       else {
+               if (newnode)
+                       SS_Free(newnode);
+               if (headparam) {
+                       local_temp = headparam;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               return NULL;
+       }
 }
 
 void tar_free_cfg_table(tar_Data_t ** delta_tar)
 {
-    tar_Data_t *local_temp = NULL;
-    tar_Data_t *local_next = NULL;
-    LOGL(LOG_SSENGINE, "Free TAR CFG TABLE\n");
-    if (*delta_tar) {
-        local_temp = *delta_tar;
-        while (local_temp) {
-            local_next = local_temp->nextnode;
-            //LOGL(LOG_SSENGINE,"freeing [%s]\n",local_temp->itemName);
-            SS_Free(local_temp);
-            local_temp = local_next;
-        }
-    }
+       tar_Data_t *local_temp = NULL;
+       tar_Data_t *local_next = NULL;
+       LOGL(LOG_SSENGINE, "Free TAR CFG TABLE\n");
+       if (*delta_tar) {
+               local_temp = *delta_tar;
+               while (local_temp) {
+                       local_next = local_temp->nextnode;
+                       //LOGL(LOG_SSENGINE,"freeing [%s]\n",local_temp->itemName);
+                       SS_Free(local_temp);
+                       local_temp = local_next;
+               }
+       }
 }
 
 void deleteNode(tar_Data_t * head, tar_Data_t * n)
 {
-    tar_Data_t *prev = head;
-    if (head == n) {
-        if (head->nextnode == NULL) {
-            LOG("There is only one node. The list can't be made empty ");
-            return;
-        }
-        strncpy((char *)head->itemName, (const char *)head->nextnode->itemName, TAR_ITEM_NAME_SIZE);    //head->itemName = head->nextnode->itemName;
-        head->itemSize = head->nextnode->itemSize;
-        head->itemOffset = head->nextnode->itemOffset;
-        n = head->nextnode;
-        head->nextnode = head->nextnode->nextnode;
-        SS_Free(n);
-        return;
-    }
-    while (prev->nextnode != NULL && prev->nextnode != n)
-        prev = prev->nextnode;
-    if (prev->nextnode == NULL) {
-        LOG("\n Given node is not present in Linked List");
-        return;
-    }
-    prev->nextnode = prev->nextnode->nextnode;
-    SS_Free(n);
-    return;
+       tar_Data_t *prev = head;
+       if (head == n) {
+               if (head->nextnode == NULL) {
+                       LOG("There is only one node. The list can't be made empty ");
+                       return;
+               }
+               strncpy((char *)head->itemName, (const char *)head->nextnode->itemName, TAR_ITEM_NAME_SIZE);    //head->itemName = head->nextnode->itemName;
+               head->itemSize = head->nextnode->itemSize;
+               head->itemOffset = head->nextnode->itemOffset;
+               n = head->nextnode;
+               head->nextnode = head->nextnode->nextnode;
+               SS_Free(n);
+               return;
+       }
+       while (prev->nextnode != NULL && prev->nextnode != n)
+               prev = prev->nextnode;
+       if (prev->nextnode == NULL) {
+               LOG("\n Given node is not present in Linked List");
+               return;
+       }
+       prev->nextnode = prev->nextnode->nextnode;
+       SS_Free(n);
+       return;
 }
 
 int tar_get_item_size_from_struct(tar_Data_t ** delta_tar, const char *patchname, int *data_size, int *data_offset)
 {
-    tar_Data_t *head = *delta_tar;
-    tar_Data_t *base = *delta_tar;
-    if (head == NULL)
-        return 1;
-    else {
-        //LOG("fast_tar_get_item_size- looking for [%s] [%s]\n",patchname,head->itemName);
-        while (1) {
-            if (strstr((const char *)head->itemName, patchname) != 0) {
-                //LOG("fast_tar_get_item_size found [%s]  in [%s]\n",patchname, head->itemName);
-                *data_size = head->itemSize;
-                *data_offset = head->itemOffset;
-                deleteNode(base, head);
-                return 0;
-
-            } else if (head->nextnode != NULL) {
-                head = head->nextnode;
-                //LOG("fast_tar_get_item_size current node [%s] \n",head->itemName);
-            } else {
-                LOGE("fast_tar_get_item_size FAILED TO GET [%s]  in [%s]\n", patchname, (char *)head->itemName);
-                break;
-            }
-        }
-        return 1;
-    }
+       tar_Data_t *head = *delta_tar;
+       tar_Data_t *base = *delta_tar;
+       if (head == NULL)
+               return 1;
+       else {
+               //LOG("fast_tar_get_item_size- looking for [%s] [%s]\n",patchname,head->itemName);
+               while (1) {
+                       if (strstr((const char *)head->itemName, patchname) != 0) {
+                               //LOG("fast_tar_get_item_size found [%s]  in [%s]\n",patchname, head->itemName);
+                               *data_size = head->itemSize;
+                               *data_offset = head->itemOffset;
+                               deleteNode(base, head);
+                               return 0;
+
+                       } else if (head->nextnode != NULL) {
+                               head = head->nextnode;
+                               //LOG("fast_tar_get_item_size current node [%s] \n",head->itemName);
+                       } else {
+                               LOGE("fast_tar_get_item_size FAILED TO GET [%s]  in [%s]\n", patchname, (char *)head->itemName);
+                               break;
+                       }
+               }
+               return 1;
+       }
 }
 
 tar_Data_t *tar_cfg_clear_nodes(tar_Data_t * head)
 {
-    tar_Data_t *local_temp = NULL;
-    while (head) {
-        LOGL(LOG_SSENGINE, "tar_cfg_delete_node [%s]", (char *)head->itemName);
-        local_temp = head->nextnode;
-        SS_Free(head);
-        head = local_temp;
-    }
-    return 0;
+       tar_Data_t *local_temp = NULL;
+       while (head) {
+               LOGL(LOG_SSENGINE, "tar_cfg_delete_node [%s]", (char *)head->itemName);
+               local_temp = head->nextnode;
+               SS_Free(head);
+               head = local_temp;
+       }
+       return 0;
 }
 
 int tar_open(char *tar)
 {
-    if (gTarFd)
-        close(gTarFd);
-    gTarFd = open(tar, O_RDONLY);
-    if (gTarFd < 0) {
-        LOG("can't open TAR file(%s).\n", tar);
-        return -1;
-    }
-    return 0;
+       if (gTarFd)
+               close(gTarFd);
+       gTarFd = open(tar, O_RDONLY);
+       if (gTarFd < 0) {
+               LOG("can't open TAR file(%s).\n", tar);
+               return -1;
+       }
+       return 0;
 }
 
 int tar_close()
 {
-    if (gTarFd)
-        close(gTarFd);
-    gTarFd = -1;
-    return 0;
+       if (gTarFd)
+               close(gTarFd);
+       gTarFd = -1;
+       return 0;
 }
 
 int tar_get_folder_size(char *tar, char *item)
 {
-    int ret = -1;
-    int fd = -1;
-    char header[TAR_BLOCK_SIZE] = { 0, };
-    char name[TAR_LONG_NAME_SIZE + 1] = { 0, };
-    char *lastfolder = NULL;
-    int folderpathlen = 0;
-    char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
-    unsigned long size_dec = 0;
-    int blknum = 0;
-    off_t pos = 0;
-    off_t tar_len = 0;
-    ssize_t rdcnt = 0;
-    LOG("Tar folder Looking for (%s)\n", item);
-    fd = open(tar, O_RDONLY);
-    if (fd < 0) {
-        LOG("can't open file(%s).\n", tar);
-        return -1;
-    }
-
-    tar_len = lseek(fd, 0, SEEK_END);
-    if (tar_len < 0) {
-        LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
-        goto Cleanup;
-    }
-    pos = lseek(fd, 0, SEEK_SET);
-    if (pos < 0) {
-        LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
-        goto Cleanup;
-    }
-
-    while (pos < tar_len) {
-        /* read file header */
-        rdcnt = read(fd, header, sizeof(header));
-        if (rdcnt <= 0) {
-            LOG("read failed. (rdcnt=%d)\n", rdcnt);
-            ret = -1;
-            break;
-        }
-
-        /* get file name and file size */
-        memcpy(name, header, sizeof(name) - 1);
-        memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
-        size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
-        if (size_dec > MAX_ITEM_SIZE) {
-            LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
-            ret = -1;
-            break;
-        }
-
-        /* check if the file is what we are looking for */
-        //Get until folder name
-
-        lastfolder = strrchr(name, '/');
-        if (lastfolder)
-            folderpathlen = strlen(name) - strlen(lastfolder);
-
-        if (strncmp(name, item, folderpathlen) == 0) {
-            ret += (int)size_dec;
-            //LOG("Tar Files under folder [%s]\n", name);
-            //break;
-        }
-
-        /* move file pointer to next file header */
-        blknum = size_dec / TAR_BLOCK_SIZE;
-        if (size_dec % TAR_BLOCK_SIZE)
-            blknum++;
-
-        pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
-        if (pos < 0) {
-            LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
-            close(fd);
-            return -1;
-        }
-    }
+       int ret = -1;
+       int fd = -1;
+       char header[TAR_BLOCK_SIZE] = { 0, };
+       char name[TAR_LONG_NAME_SIZE + 1] = { 0, };
+       char *lastfolder = NULL;
+       int folderpathlen = 0;
+       char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
+       unsigned long size_dec = 0;
+       int blknum = 0;
+       off_t pos = 0;
+       off_t tar_len = 0;
+       ssize_t rdcnt = 0;
+       LOG("Tar folder Looking for (%s)\n", item);
+       fd = open(tar, O_RDONLY);
+       if (fd < 0) {
+               LOG("can't open file(%s).\n", tar);
+               return -1;
+       }
+
+       tar_len = lseek(fd, 0, SEEK_END);
+       if (tar_len < 0) {
+               LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
+               goto Cleanup;
+       }
+       pos = lseek(fd, 0, SEEK_SET);
+       if (pos < 0) {
+               LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
+               goto Cleanup;
+       }
+
+       while (pos < tar_len) {
+               /* read file header */
+               rdcnt = read(fd, header, sizeof(header));
+               if (rdcnt <= 0) {
+                       LOG("read failed. (rdcnt=%d)\n", rdcnt);
+                       ret = -1;
+                       break;
+               }
+
+               /* get file name and file size */
+               memcpy(name, header, sizeof(name) - 1);
+               memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
+               size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
+               if (size_dec > MAX_ITEM_SIZE) {
+                       LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
+                       ret = -1;
+                       break;
+               }
+
+               /* check if the file is what we are looking for */
+               //Get until folder name
+
+               lastfolder = strrchr(name, '/');
+               if (lastfolder)
+                       folderpathlen = strlen(name) - strlen(lastfolder);
+
+               if (strncmp(name, item, folderpathlen) == 0) {
+                       ret += (int)size_dec;
+                       //LOG("Tar Files under folder [%s]\n", name);
+                       //break;
+               }
+
+               /* move file pointer to next file header */
+               blknum = size_dec / TAR_BLOCK_SIZE;
+               if (size_dec % TAR_BLOCK_SIZE)
+                       blknum++;
+
+               pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
+               if (pos < 0) {
+                       LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
+                       close(fd);
+                       return -1;
+               }
+       }
 
  Cleanup:
-    close(fd);
-    LOG("ret=%d\n", ret);
+       close(fd);
+       LOG("ret=%d\n", ret);
 
-    return ret;                 //Should return +1?? or Ignore??
+       return ret;                              //Should return +1?? or Ignore??
 }
 
 /*Extract Specific Folder from tar, Taken from Untar.c */
 int tar_extract_folder(char *tar, char *item, char *path)
 {
-    char buff[MAX_FILE_PATH];
-    FILE *f = NULL;
-    size_t bytes_read;
-    int filesize;
-    int data_offset = -1;
-    int fd = -1;
-    char name[512] = { 0, };
-    int folderpathlen = 0;
-    char dirPath[512] = { 0 };
-    int getheader = 1;          // Asuming initial header is TAR header
-    char fullname[512] = { 0 };
-    int ret;
-    LOG("Extracting Folder from %s %s to %s\n", tar, item, path);
-
-    data_offset = tar_get_item_offset(tar, item);
-    if (data_offset < 0) {
-        LOGE("data offset for [%s] is [%d]\n", item, data_offset);
-        return -1;
-    }
-
-    fd = open(tar, O_RDONLY);
-    if (fd < 0) {
-        LOGE("can't open file(%s).\n", tar);
-        return -1;
-    }
-
-    folderpathlen = strlen(item);
-
-    for (;;) {
-        bytes_read = read(fd, buff, sizeof(buff));
-        if (bytes_read < 512) {
-            LOGE("Short read on %s: expected 512, got %d\n", tar, bytes_read);
-            close(fd);
-            return -1;
-        }
-        if (is_end_of_archive(buff)) {
-            close(fd);
-            LOG("End of %s\n", tar);    //Can stop at end of folder.
-            return S_SS_SUCCESS;
-        }
-        if (!verify_checksum(buff)) {
-            close(fd);
-            LOGE("Checksum failure\n");
-            return -1;
-        }
-        filesize = parseoct(buff + 124, 12);
-        if (getheader == 2) {
-            getheader = 1;
-            //LOG(" Working on LONG FILE NAME CASE [%s]\n", fullname);
-        } else {
-            memset(fullname, 0, sizeof(fullname));
-            strncpy(fullname, buff, 100);
-            //LOG(" Working on Normal FILE NAME CASE [%s]\n", fullname);
-        }
-
-        switch (buff[156]) {
-        case '1':
-            LOG(" Ignoring hardlink %s\n", fullname);
-            break;
-        case '2':
-
-            //LOG(" Creating symlink %s\n", buff);
-            if (strncmp(fullname, item, folderpathlen) == 0) {
-                //LOG("Printing Buffer \n");
-                //for(i=157; buff[i] !='\0' ;i++)
-                //{
-                //LOG("%c", buff[i])    ;
-                //}
-                //LOG("\nEnd buffer\n");
-                memset(name, 0, sizeof(name));
-                strncpy(name, buff + 157, 100); //157, target link name will be present
-                memset(dirPath, 0, sizeof(dirPath));
-                snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
-                LOG(" Creating Symlink [%s][%s]\n", name, dirPath);
-                ret = symlink(name, dirPath); // use ss_link
-                if (ret < 0)
-                    LOG("Error with symlink: %d\n", errno);
-            }
-            break;
-        case '3':
-            LOG(" Ignoring character device %s\n", fullname);
-            break;
-        case '4':
-            LOG(" Ignoring block device %s\n", fullname);
-            break;
-        case '5':
-            //break;//delete
-            //LOG(" Dir [%s] Item [%s] Length [%d]\n", fullname, item, folderpathlen);
-            if (strncmp(fullname, item, folderpathlen) == 0) {
-                //LOG(" Extracting dir %s\n", fullname);
-                memset(dirPath, 0, sizeof(dirPath));
-                snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
-                create_dir(dirPath, parseoct(fullname + 100, 8));
-            }
-
-            filesize = 0;
-            break;
-        case '6':
-            LOG(" Ignoring FIFO %s\n", fullname);
-            break;
-        case GNUTYPE_LONGLINK:
-        case GNUTYPE_LONGNAME:
-            {
-                getheader = 2;
-                memset(fullname, 0, sizeof(fullname));
-                bytes_read = read(fd, fullname, sizeof(fullname));
-                if (bytes_read < 512) {
-                    LOGE("Short read on %s: expected 512, got %d\n", tar, bytes_read);
-                    close(fd);
-                    return -1;
-                }
-                filesize = 0;
-                //LOG("Entered LONG FILE NAME CASE  new NAME is [%s]\n", fullname);
-                break;
-            }
-
-        default:
-            //break;
-            //LOG(" File [%s] Item [%s] Length [%d]\n", fullname, item, folderpathlen);
-            if (strncmp(fullname, item, folderpathlen) == 0) {
-                if (buff[PREFIX_INDICATOR_BYTE] != 0) {
-                    memset(name, 0, sizeof(name));
-                    memset(dirPath, 0, sizeof(dirPath));
-                    strncpy(name, buff, 100);
-                   snprintf(name + strlen(name), sizeof(name) - strlen(name),
-                                   "%s", buff + PREFIX_INDICATOR_BYTE);
-                    snprintf(dirPath, sizeof(dirPath), "%s/%s", path, name + folderpathlen);
-                    LOG(" File Name is longer than 100 bytes -Remaining Str [%s]\n Full Str[%s]", dirPath);
-                } else {
-                    //LOG(" Extracting file %s\n", fullname);
-                    memset(dirPath, 0, sizeof(dirPath));
-                    snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
-                    f = create_file(dirPath, parseoct(fullname + 100, 8));
-                }
-            }
-
-            break;
-        }
-
-        while (filesize > 0) {
-            bytes_read = read(fd, buff, sizeof(buff));
-            if (bytes_read < 512) {
-                LOGE("Short read on %s: Expected 512, got %d\n", tar, bytes_read);
-                close(fd);
-                if(f){
-                    fclose(f);//wgid: 16892
-                    f = NULL;
-                }
-                return -1;
-            }
-            if (filesize < 512)
-                bytes_read = filesize;
-            if (f != NULL) {
-                if (fwrite(buff, 1, bytes_read, f)
-                    != bytes_read) {
-                    LOG("Failed write\n");
-                    fclose(f);
-                    f = NULL;
-                    close(fd);//wgid: 59268
-                    return -1;//wgid: 16892
-                }
-            }
-            filesize -= bytes_read;
-        }
-        if (f != NULL) {
-            fclose(f);
-            f = NULL;
-        }
-
-    }
-    close(fd);
-    return S_SS_SUCCESS;
+       char buff[MAX_FILE_PATH];
+       FILE *f = NULL;
+       size_t bytes_read;
+       int filesize;
+       int data_offset = -1;
+       int fd = -1;
+       char name[512] = { 0, };
+       int folderpathlen = 0;
+       char dirPath[512] = { 0 };
+       int getheader = 1;                // Asuming initial header is TAR header
+       char fullname[512] = { 0 };
+       int ret;
+       LOG("Extracting Folder from %s %s to %s\n", tar, item, path);
+
+       data_offset = tar_get_item_offset(tar, item);
+       if (data_offset < 0) {
+               LOGE("data offset for [%s] is [%d]\n", item, data_offset);
+               return -1;
+       }
+
+       fd = open(tar, O_RDONLY);
+       if (fd < 0) {
+               LOGE("can't open file(%s).\n", tar);
+               return -1;
+       }
+
+       folderpathlen = strlen(item);
+
+       for (;;) {
+               bytes_read = read(fd, buff, sizeof(buff));
+               if (bytes_read < 512) {
+                       LOGE("Short read on %s: expected 512, got %d\n", tar, bytes_read);
+                       close(fd);
+                       return -1;
+               }
+               if (is_end_of_archive(buff)) {
+                       close(fd);
+                       LOG("End of %s\n", tar);        //Can stop at end of folder.
+                       return S_SS_SUCCESS;
+               }
+               if (!verify_checksum(buff)) {
+                       close(fd);
+                       LOGE("Checksum failure\n");
+                       return -1;
+               }
+               filesize = parseoct(buff + 124, 12);
+               if (getheader == 2) {
+                       getheader = 1;
+                       //LOG(" Working on LONG FILE NAME CASE [%s]\n", fullname);
+               } else {
+                       memset(fullname, 0, sizeof(fullname));
+                       strncpy(fullname, buff, 100);
+                       //LOG(" Working on Normal FILE NAME CASE [%s]\n", fullname);
+               }
+
+               switch (buff[156]) {
+               case '1':
+                       LOG(" Ignoring hardlink %s\n", fullname);
+                       break;
+               case '2':
+
+                       //LOG(" Creating symlink %s\n", buff);
+                       if (strncmp(fullname, item, folderpathlen) == 0) {
+                               //LOG("Printing Buffer \n");
+                               //for(i=157; buff[i] !='\0' ;i++)
+                               //{
+                               //LOG("%c", buff[i])    ;
+                               //}
+                               //LOG("\nEnd buffer\n");
+                               memset(name, 0, sizeof(name));
+                               strncpy(name, buff + 157, 100); //157, target link name will be present
+                               memset(dirPath, 0, sizeof(dirPath));
+                               snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
+                               LOG(" Creating Symlink [%s][%s]\n", name, dirPath);
+                               ret = symlink(name, dirPath); // use ss_link
+                               if (ret < 0)
+                                       LOG("Error with symlink: %d\n", errno);
+                       }
+                       break;
+               case '3':
+                       LOG(" Ignoring character device %s\n", fullname);
+                       break;
+               case '4':
+                       LOG(" Ignoring block device %s\n", fullname);
+                       break;
+               case '5':
+                       //break;//delete
+                       //LOG(" Dir [%s] Item [%s] Length [%d]\n", fullname, item, folderpathlen);
+                       if (strncmp(fullname, item, folderpathlen) == 0) {
+                               //LOG(" Extracting dir %s\n", fullname);
+                               memset(dirPath, 0, sizeof(dirPath));
+                               snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
+                               create_dir(dirPath, parseoct(fullname + 100, 8));
+                       }
+
+                       filesize = 0;
+                       break;
+               case '6':
+                       LOG(" Ignoring FIFO %s\n", fullname);
+                       break;
+               case GNUTYPE_LONGLINK:
+               case GNUTYPE_LONGNAME:
+                       {
+                               getheader = 2;
+                               memset(fullname, 0, sizeof(fullname));
+                               bytes_read = read(fd, fullname, sizeof(fullname));
+                               if (bytes_read < 512) {
+                                       LOGE("Short read on %s: expected 512, got %d\n", tar, bytes_read);
+                                       close(fd);
+                                       return -1;
+                               }
+                               filesize = 0;
+                               //LOG("Entered LONG FILE NAME CASE  new NAME is [%s]\n", fullname);
+                               break;
+                       }
+
+               default:
+                       //break;
+                       //LOG(" File [%s] Item [%s] Length [%d]\n", fullname, item, folderpathlen);
+                       if (strncmp(fullname, item, folderpathlen) == 0) {
+                               if (buff[PREFIX_INDICATOR_BYTE] != 0) {
+                                       memset(name, 0, sizeof(name));
+                                       memset(dirPath, 0, sizeof(dirPath));
+                                       strncpy(name, buff, 100);
+                       snprintf(name + strlen(name), sizeof(name) - strlen(name),
+                                       "%s", buff + PREFIX_INDICATOR_BYTE);
+                                       snprintf(dirPath, sizeof(dirPath), "%s/%s", path, name + folderpathlen);
+                                       LOG(" File Name is longer than 100 bytes -Remaining Str [%s]\n Full Str[%s]", dirPath);
+                               } else {
+                                       //LOG(" Extracting file %s\n", fullname);
+                                       memset(dirPath, 0, sizeof(dirPath));
+                                       snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
+                                       f = create_file(dirPath, parseoct(fullname + 100, 8));
+                               }
+                       }
+
+                       break;
+               }
+
+               while (filesize > 0) {
+                       bytes_read = read(fd, buff, sizeof(buff));
+                       if (bytes_read < 512) {
+                               LOGE("Short read on %s: Expected 512, got %d\n", tar, bytes_read);
+                               close(fd);
+                               if (f) {
+                                       fclose(f);//wgid: 16892
+                                       f = NULL;
+                               }
+                               return -1;
+                       }
+                       if (filesize < 512)
+                               bytes_read = filesize;
+                       if (f != NULL) {
+                               if (fwrite(buff, 1, bytes_read, f)
+                                       != bytes_read) {
+                                       LOG("Failed write\n");
+                                       fclose(f);
+                                       f = NULL;
+                                       close(fd);//wgid: 59268
+                                       return -1;//wgid: 16892
+                               }
+                       }
+                       filesize -= bytes_read;
+               }
+               if (f != NULL) {
+                       fclose(f);
+                       f = NULL;
+               }
+
+       }
+       close(fd);
+       return S_SS_SUCCESS;
 }
 
 int fast_tar_extract_file(char *tar, char *item, char *pathname, int size, int offset)
 {
-    int fd = -1;
-    int data_size = size;
-    int data_offset = offset;
-    off_t pos = 0;
-    ssize_t rdcnt = 0;
-    ssize_t writeCount = 0;
-    char *buf = NULL;
-    char err_buf[256];
-    int fd2;
-
-    if (gTarFd > 0)
-        fd = gTarFd;
-    if (fd < 0) {
-        fd = open(tar, O_RDONLY);
-        if (fd < 0) {
-            LOG("can't open file(%s).\n", tar);
-            return -1;
-        }
-    }
-    pos = lseek(fd, data_offset, SEEK_SET);
-    if (pos < 0) {
-        LOG("lseek fail (%s offset %d).\n", tar, data_offset);
-        close(fd);
-        return -1;
-    }
-    buf = SS_Malloc(data_size + 1);
-    if (buf == NULL) {
-        close(fd);
-        LOGE("Failed to Allocate Memory\n");
-        return -1;
-    }
-    rdcnt = read(fd, buf, data_size);
-    if (rdcnt != (ssize_t) data_size) {
-        LOG(" rdcnt read fail(%s from %s).\n", item, tar);
-        SS_Free(buf);
-        close(fd);
-        return -1;
-    }
-    fd2 = open(pathname, O_CREAT | O_WRONLY, 0777);     // Directory where file is required should be created already.
-    if (fd2 < 0) {
-        LOG("can't open file(%s).\n", pathname);
-        SS_Free(buf);
-        close(fd);
-        return -1;
-    }
-    writeCount = write(fd2, buf, rdcnt);
-    if (writeCount != rdcnt) {
-        LOG("writeCount write fail(%s from %s).\n", item, tar);
-        strerror_r(errno, err_buf, sizeof(err_buf));
-        LOG("Oh  dear, something went wrong with read()! %s\n", err_buf);
-        close(fd);
-        close(fd2);
-        SS_Free(buf);
-        return -1;
-    }
-    SS_Free(buf);
-    if (gTarFd < 0)
-        close(fd);
-    fsync(fd2);
-    close(fd2);
-    return rdcnt;               // or jus return success?
+       int fd = -1;
+       int data_size = size;
+       int data_offset = offset;
+       off_t pos = 0;
+       ssize_t rdcnt = 0;
+       ssize_t writeCount = 0;
+       char *buf = NULL;
+       char err_buf[256];
+       int fd2;
+
+       if (gTarFd > 0)
+               fd = gTarFd;
+       if (fd < 0) {
+               fd = open(tar, O_RDONLY);
+               if (fd < 0) {
+                       LOG("can't open file(%s).\n", tar);
+                       return -1;
+               }
+       }
+       pos = lseek(fd, data_offset, SEEK_SET);
+       if (pos < 0) {
+               LOG("lseek fail (%s offset %d).\n", tar, data_offset);
+               close(fd);
+               return -1;
+       }
+       buf = SS_Malloc(data_size + 1);
+       if (buf == NULL) {
+               close(fd);
+               LOGE("Failed to Allocate Memory\n");
+               return -1;
+       }
+       rdcnt = read(fd, buf, data_size);
+       if (rdcnt != (ssize_t) data_size) {
+               LOG(" rdcnt read fail(%s from %s).\n", item, tar);
+               SS_Free(buf);
+               close(fd);
+               return -1;
+       }
+       fd2 = open(pathname, O_CREAT | O_WRONLY, 0777);  // Directory where file is required should be created already.
+       if (fd2 < 0) {
+               LOG("can't open file(%s).\n", pathname);
+               SS_Free(buf);
+               close(fd);
+               return -1;
+       }
+       writeCount = write(fd2, buf, rdcnt);
+       if (writeCount != rdcnt) {
+               LOG("writeCount write fail(%s from %s).\n", item, tar);
+               strerror_r(errno, err_buf, sizeof(err_buf));
+               LOG("Oh  dear, something went wrong with read()! %s\n", err_buf);
+               close(fd);
+               close(fd2);
+               SS_Free(buf);
+               return -1;
+       }
+       SS_Free(buf);
+       if (gTarFd < 0)
+               close(fd);
+       fsync(fd2);
+       close(fd2);
+       return rdcnt;                      // or jus return success?
 }
 
 int tar_extract_file(char *tar, char *item, char *pathname)
 {
-    int fd = -1;
-    int data_size = -1;
-    int data_offset = -1;
-    off_t pos = 0;
-    ssize_t rdcnt = 0;
-    ssize_t writeCount = 0;
-    char *buf = NULL;
-    char err_buf[256];
-    int fd2;
-    data_size = tar_get_item_size(tar, item);
-    data_offset = tar_get_item_offset(tar, item);
-
-    if (data_size <= 0 || data_offset < 0) {
-        LOGE("Error Not a file , size is [%d], offset [%d] for item [%s]\n", data_size, data_offset, item);
-        return -1;
-    } else
-        LOGL(LOG_SSENGINE, "extracting file [%s] size [%d]\n", item, data_size);
-    fd = open(tar, O_RDONLY);
-    if (fd < 0) {
-        LOG("can't open file(%s).\n", tar);
-        return -1;
-    }
-    pos = lseek(fd, data_offset, SEEK_SET);
-    if (pos < 0) {
-        LOG("lseek fail (%s offset %d).\n", tar, data_offset);
-        close(fd);
-        return -1;
-    }
-    buf = SS_Malloc(data_size + 1);
-    if (buf == NULL) {
-        close(fd);
-        LOGE("Failed to Allocate Memory\n");
-        return -1;
-    }
-    rdcnt = read(fd, buf, data_size);
-    if (rdcnt != (ssize_t) data_size) {
-        LOG(" rdcnt read fail(%s from %s).\n", item, tar);
-        SS_Free(buf);
-        close(fd);
-        return -1;
-    }
-    fd2 = open(pathname, O_CREAT | O_WRONLY, 0777);     // Directory where file is required should be created already.
-    if (fd2 < 0) {
-        LOG("can't open file(%s).\n", pathname);
-        SS_Free(buf);
-        close(fd);
-        return -1;
-    }
-    writeCount = write(fd2, buf, rdcnt);
-    if (writeCount != rdcnt) {
-        LOG("writeCount write fail(%s from %s).\n", item, tar);
-        strerror_r(errno, err_buf, sizeof(err_buf));
-        LOG("Oh  dear, something went wrong with read()! %s\n", err_buf);
-        close(fd);
-        close(fd2);
-        SS_Free(buf);
-        return -1;
-    }
-    SS_Free(buf);
-    close(fd);
-    fsync(fd2);
-    close(fd2);
-    return rdcnt;               // or jus return success?
+       int fd = -1;
+       int data_size = -1;
+       int data_offset = -1;
+       off_t pos = 0;
+       ssize_t rdcnt = 0;
+       ssize_t writeCount = 0;
+       char *buf = NULL;
+       char err_buf[256];
+       int fd2;
+       data_size = tar_get_item_size(tar, item);
+       data_offset = tar_get_item_offset(tar, item);
+
+       if (data_size <= 0 || data_offset < 0) {
+               LOGE("Error Not a file , size is [%d], offset [%d] for item [%s]\n", data_size, data_offset, item);
+               return -1;
+       } else
+               LOGL(LOG_SSENGINE, "extracting file [%s] size [%d]\n", item, data_size);
+       fd = open(tar, O_RDONLY);
+       if (fd < 0) {
+               LOG("can't open file(%s).\n", tar);
+               return -1;
+       }
+       pos = lseek(fd, data_offset, SEEK_SET);
+       if (pos < 0) {
+               LOG("lseek fail (%s offset %d).\n", tar, data_offset);
+               close(fd);
+               return -1;
+       }
+       buf = SS_Malloc(data_size + 1);
+       if (buf == NULL) {
+               close(fd);
+               LOGE("Failed to Allocate Memory\n");
+               return -1;
+       }
+       rdcnt = read(fd, buf, data_size);
+       if (rdcnt != (ssize_t) data_size) {
+               LOG(" rdcnt read fail(%s from %s).\n", item, tar);
+               SS_Free(buf);
+               close(fd);
+               return -1;
+       }
+       fd2 = open(pathname, O_CREAT | O_WRONLY, 0777);  // Directory where file is required should be created already.
+       if (fd2 < 0) {
+               LOG("can't open file(%s).\n", pathname);
+               SS_Free(buf);
+               close(fd);
+               return -1;
+       }
+       writeCount = write(fd2, buf, rdcnt);
+       if (writeCount != rdcnt) {
+               LOG("writeCount write fail(%s from %s).\n", item, tar);
+               strerror_r(errno, err_buf, sizeof(err_buf));
+               LOG("Oh  dear, something went wrong with read()! %s\n", err_buf);
+               close(fd);
+               close(fd2);
+               SS_Free(buf);
+               return -1;
+       }
+       SS_Free(buf);
+       close(fd);
+       fsync(fd2);
+       close(fd2);
+       return rdcnt;                      // or jus return success?
 }
index 7d1e73c..55eae02 100755 (executable)
@@ -21,8 +21,8 @@
 
 #include <stdio.h>
 
-#define MAX_FILE_PATH           512
-#define MAX_PART_NAME           32
+#define MAX_FILE_PATH          512
+#define MAX_PART_NAME          32
 
 /*
  * FOTA Adaptaion header
 
 #define ERROR -1                // 0XFFFFFFFF
 
-#define INVALID    0
-#define VALID      1
+#define INVALID 0
+#define VALID 1
 #define TRUE 1
 #define FALSE 0
 #define OK 0
 #define SUCCESS 0
 #define FAIL 1
 #define RESTORING 2
-#define UA_PARTI_MAX                                   20      //currently supporting max 20 partitions
+#define UA_PARTI_MAX                   20      //currently supporting max 20 partitions
 #define DEFAULT_DELTA_NAME             "delta.tar"
 #define UPDATTE_CFG_FILE               "update.cfg"
 
 
 
 typedef enum {
-    FULL_IMG,
-    DELTA_IMG,
-    DELTA_FS,
-    EXTRA
+       FULL_IMG,
+       DELTA_IMG,
+       DELTA_FS,
+       EXTRA
 } UA_DATA_FORMAT;
 
 typedef enum {
-    UA_MODE_SCOUT_UPDATE,
-    UA_MODE_SCOUT,
-    UA_MODE_VERIFYTARGET,
-    UA_MODE_UPDATE,
-    UA_MODE_SUPPLYIMFOM = 200
+       UA_MODE_SCOUT_UPDATE,
+       UA_MODE_SCOUT,
+       UA_MODE_VERIFYTARGET,
+       UA_MODE_UPDATE,
+       UA_MODE_SUPPLYIMFOM = 200
 } UA_OPERATION_MODE;
 
 typedef struct _ua_update_data_t {
-    unsigned int exist_check;
-    unsigned int verify_check;
-    unsigned int update_check;
-    unsigned int weight;        // the sum of weight should be 100
-    unsigned int weight_offset; // start offset
-    unsigned int data_size;     // byte
-    char *ua_delta_path;        // it will be allocated to copy delta file path, need to free memory
-    char *ua_temp_path;         // it will be allocated to copy delta file path, need to free memory
+       unsigned int exist_check;
+       unsigned int verify_check;
+       unsigned int update_check;
+       unsigned int weight;        // the sum of weight should be 100
+       unsigned int weight_offset; // start offset
+       unsigned int data_size;     // byte
+       char *ua_delta_path;        // it will be allocated to copy delta file path, need to free memory
+       char *ua_temp_path;         // it will be allocated to copy delta file path, need to free memory
 } ua_update_data_t;
 
 typedef struct _ua_update_cfg_t {
-    unsigned int update_type;
-    unsigned int part_idx;
-    int skip_verify;
-    int skip_update;
-    int soure_img_size;         //TOTA
-    int target_img_size;
-    char *soure_sha1;
-    char *target_sha1;
+       unsigned int update_type;
+       unsigned int part_idx;
+       int skip_verify;
+       int skip_update;
+       int soure_img_size;         //TOTA
+       int target_img_size;
+       char *soure_sha1;
+       char *target_sha1;
 } ua_update_cfg_t;
 
 typedef struct _ua_part_info_t {
-    char *ua_parti_name;
-    char *ua_subject_name;
-    char *ua_blk_name;
-    int ua_blk_offset;
+       char *ua_parti_name;
+       char *ua_subject_name;
+       char *ua_blk_name;
+       int ua_blk_offset;
 } ua_part_info_t;
 
 // User data structure
 typedef struct _ua_data_t {     // partition operations
-    ua_part_info_t *parti_info;
-    ua_update_cfg_t *update_cfg;
-    ua_update_data_t *update_data;
-    unsigned long ua_operation;
-
-    int (*ua_op_read_block) (void *, unsigned char *, unsigned long, unsigned long);
-    int (*ua_op_write_block) (void *, unsigned char *, unsigned long);
-    void (*ui_progress) (void *, unsigned long);
+       ua_part_info_t *parti_info;
+       ua_update_cfg_t *update_cfg;
+       ua_update_data_t *update_data;
+       unsigned long ua_operation;
+
+       int (*ua_op_read_block) (void *, unsigned char *, unsigned long, unsigned long);
+       int (*ua_op_write_block) (void *, unsigned char *, unsigned long);
+       void (*ui_progress) (void *, unsigned long);
 } ua_data_t;
 
 typedef struct _ua_delta_info_t {
-    char ua_patch_path[MAX_FILE_PATH];
-    char ua_patch_info[MAX_FILE_PATH];
-    char ua_delta_path[MAX_FILE_PATH];
-    char ua_attrib_path[MAX_FILE_PATH];
+       char ua_patch_path[MAX_FILE_PATH];
+       char ua_patch_info[MAX_FILE_PATH];
+       char ua_delta_path[MAX_FILE_PATH];
+       char ua_attrib_path[MAX_FILE_PATH];
 } ua_delta_info_t;
 
 typedef struct _ua_dataSS_t {   // partition operations
-    ua_part_info_t *parti_info;
-    ua_update_cfg_t *update_cfg;
-    ua_update_data_t *update_data;
-    ua_delta_info_t *update_delta;
-    unsigned long ua_operation;
-    void (*ui_progress) (void *, unsigned long);
-    int (*write_data_to_blkdev) (char *, int, int, char *);
+       ua_part_info_t *parti_info;
+       ua_update_cfg_t *update_cfg;
+       ua_update_data_t *update_data;
+       ua_delta_info_t *update_delta;
+       unsigned long ua_operation;
+       void (*ui_progress) (void *, unsigned long);
+       int (*write_data_to_blkdev) (char *, int, int, char *);
 } ua_dataSS_t;
 
 #endif