4 * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 Function Prototypes Mandatory
35 #include <sys/statfs.h>
38 #include "SS_Common.h"
39 #include "fota_common.h"
41 #include "SS_PatchDelta.h"
42 #include "SS_Engine_Errors.h"
43 #include "SS_FSUpdate.h"
46 int FS_UpgradeState = E_SS_FAILURE;
47 int gvalid_session = 0; //used as fail-safe in case device is turmed off or battery removed during update
48 fs_list *headptr_list;
49 tar_Data_t *tar_cfg_data = NULL;
54 Create script file , set it executable, execute script in child process
55 Only works if valid delta.tar is present for upgrade
57 If MEM_PROFILING is activated,
58 we can see the result of memory profiling after delta upgrade
59 in file defined by macro - SS_MEMORY_PROFILING_SCRIPT
61 int mem_profiling_start = 0;
62 int SS_Do_Memory_Profiling()
66 char memory_usage_script[1024] = "#!/bin/bash\nlog_file=$1\npid=$2\nmaxmem=0\nwhile [[ -d \"/proc/${pid}\" ]]; do\n\
67 mem=`cat /proc/${pid}/smaps | grep Pss | grep -v Swap|awk '{print $2}'|awk '{s+=$1} END {print s}'`\n\
68 if [[ ${mem} -gt ${maxmem} ]]; then\nmaxmem=${mem}\n\
69 echo -e \"Memory usage till now is: ${maxmem} KB.\" >> $log_file\n fi\n sleep 0.01\ndone\n\
70 echo -e \"Max was : ${maxmem} KB.\" >> $log_file\n";
71 char cmd[1024] = { 0, };
73 //Open a file and write the script contents in it
74 FILE *fp = fopen(SS_MEMORY_PROFILING_SCRIPT, "w+");
75 fwrite(memory_usage_script, strlen(memory_usage_script), 1, fp);
77 //make the file executable - Octal 495 is 757 decimal
78 if (chmod(SS_MEMORY_PROFILING_SCRIPT, 495) < 0) {
79 LOGE("Error in chmod(%s, 495) - %d (%s)\n", SS_MEMORY_PROFILING_SCRIPT, errno, strerror(errno));
83 //Usage : <location of script> <location of log file to be created> <pid of the calling process>
85 snprintf(cmd, sizeof(cmd) - 1, "%s %s %d", SS_MEMORY_PROFILING_SCRIPT, SS_MEMORY_USAGE_LOG, pid);
86 ret = _system_cmd_nowait(cmd);
88 LOG("ret for memory profiling cmd is %d\n", ret);
90 mem_profiling_start = 1;
93 LOGE("Could not start Memory Profiling\n");
103 double fast_tar_get_item_size_time = 0.0;
104 double SS_LoadFile_time = 0.0;
105 double SS_FSBuildNodes_time = 0.0;
107 static void get_time_stamp1(void)
112 gettimeofday(&tv, NULL);
113 sec = (int)tv.tv_sec;
114 msec = (int)(tv.tv_usec / 1000);
115 snprintf(ts1, 256, "%06d.%03d", sec % 100000, msec);
119 //Check SS function if available
120 int file_exist(char *filename)
125 ret = lstat(filename, &buf);
127 ret = stat(filename, &buf);
129 return (ret >= 0) ? (1) : (0);
132 #ifdef POWER_FAIL_TEST
134 static int SS_Get_power_fail_flag(void)
142 if (file_exist(SS_POWER_FAIL_TEST_FLAG) == 0) {
143 LOGE("No exist file!!\n");
147 fd = open(SS_POWER_FAIL_TEST_FLAG, O_RDWR, S_IRWXU);
149 LOGE("Could not open status file!!\n");
153 result = SS_ReadFile(fd, 0, buf, sizeof(buf));
155 LOGE("SS_ReadFile failed!!\n");
161 result = SS_CloseFile(fd);
163 LOGE("SS_CloseFile failed!!\n");
168 static void SS_Set_power_fail_flag(int del_type)
173 LOG("del_type:[%d]\n", del_type);
175 fd = open(SS_POWER_FAIL_TEST_FLAG, O_RDWR | O_CREAT, S_IRWXU);
177 LOGE("Could not open status file!!\n");
181 sprintf(num_str, "%d", del_type);
182 result = SS_WriteFile(fd, 0, num_str, strlen(num_str));
184 LOGE("SS_WriteFile failed!!\n");
186 result = SS_CloseFile(fd);
188 LOGE("SS_CloseFile failed!!\n");
194 int SS_Do_Power_fail_test(int del_type)
197 char cmd[1024] = { 0, };
199 SS_Set_power_fail_flag(del_type);
201 snprintf(cmd, sizeof(cmd) - 1, "%s", "/usr/sbin/reboot fota");
202 ret = _system_cmd_nowait(cmd);
204 LOG("ret for SS_Do_Power_fail_test cmd is %d\n", ret);
208 LOGE("Could not start Memory Profiling\n");
214 int SS_GetProgressResolution(int ultotalFSCnt)
216 if (ultotalFSCnt < DISPLAYRESOLUTION_SIZE)
219 return (ultotalFSCnt / DISPLAYRESOLUTION_SIZE);
222 void SS_SetUpgradeState(int Val)
224 LOGE("FAILED to upgrade Cause:[0x%x]\n", Val);
225 FS_UpgradeState = Val;
229 int SS_GetUpgradeState()
231 return FS_UpgradeState;
234 int SS_Get_last_update_status(int* last_update_status, int* del_type, char* status_path)
237 unsigned char buf[257];
239 char *saveptr = NULL;
242 if (file_exist(status_path) == 0) {
243 LOG("No exist file!! - File_path:[%s]\n", status_path);
247 fd = open(status_path, O_RDWR, S_IRWXU);
249 LOGE("Could not open status file!!, File_path:[%s]\n", status_path);
253 result = SS_ReadFile(fd, 0, buf, sizeof(buf)-1);
255 LOGE("SS_ReadFile failed!!\n");
256 result = SS_CloseFile(fd);
258 LOGE("SS_CloseFile failed!!\n");
262 ptr = strtok_r((char *)buf, " ", &saveptr);
265 *last_update_status = atoi(ptr);
266 ptr = strtok_r(NULL, " ", &saveptr);
270 *del_type = atoi(ptr);
273 result = SS_CloseFile(fd);
275 LOGE("SS_CloseFile failed!!\n");
280 void SS_Set_last_update_status(int last_update_status, int del_type, char *status_path)
285 LOG("last_update_status:[%d], del_type:[%d]\n", last_update_status, del_type);
287 fd = open(status_path, O_RDWR | O_CREAT, S_IRWXU);
289 LOGE("Could not open status file!!, File_path:[%s]\n", status_path);
293 snprintf(num_str, sizeof(num_str), "%d %d", last_update_status, del_type);
294 result = SS_WriteFile(fd, 0, (unsigned char *)num_str, strlen(num_str));
296 LOGE("SS_WriteFile failed!!\n");
298 result = SS_CloseFile(fd);
300 LOGE("SS_CloseFile failed!!\n");
306 int SS_rename1(const char *old_file_name, const char *new_file_name)
308 int result = E_SS_FAILURE;
309 char *temp_name = NULL;
310 temp_name = (char *)SS_Malloc(strlen(new_file_name) + 10);
311 if (temp_name == NULL)
313 snprintf(temp_name, strlen(new_file_name) + 10, "%s.temp", new_file_name);
314 result = rename(new_file_name, temp_name);
317 result = rename(old_file_name, new_file_name);
320 result = unlink(temp_name);
328 *********************************************************************************
330 *********************************************************************************
333 * This is to verify nodes being added to global control structure for diff and delete cases.
334 * gvalid_session global is used to check if nodes are already verified.
339 * @return returns S_SS_SUCCESS and
340 * returns E_SS_FAILURE in case any error occurs
342 *********************************************************************************
344 int SS_FSVerifyNode(const char *path, const char *patchname, const char *sha1src, int type,
345 char *patchpath_name, int *data_size, int *data_offset)
347 char patch[MAX_FILE_PATH] = { 0 };
348 FileInfo source_file;
349 uint8_t source_sha1[SHA_DIGEST_SIZE];
351 if (gvalid_session) {
352 if ((type == DIFFS || type == DELETES || type == MOVES) && !file_exist((char *)path)) {
353 LOGE("failed to verifyNodes [does not exist], Path : [%s] Type[%d]\n", path, type);
354 SS_SetUpgradeState(E_SS_FSBADNODES);
357 snprintf(patch, MAX_FILE_PATH, "%s%s%s", patchpath_name, "/", patchname);
358 if ((type == DIFFS/*||type == NEWFILES */)) { // allowing size 0 also for folders
359 if (tar_get_item_size_from_struct(&tar_cfg_data, patchname, data_size, data_offset)
361 LOGE("failed to get item size from struct, Patch : [%s]\n", patchname);
362 SS_SetUpgradeState(E_SS_FSBADNODES);
365 if (*data_size < 0) {
366 LOGE("failed to verifyNodes [delta absent], Patch : [%s] Type[%d]\n", patch, type);
367 SS_SetUpgradeState(E_SS_FSBADNODES);
371 //For other types (NEWs, SYMs, Folders), SHA check not required
372 if ((type == DIFFS || type == MOVES/* ||type == DELETES */) &&
373 (strcmp(sha1src, SS_NULLENTRY) != 0)) {
374 if (ParseSha1(sha1src, source_sha1) != 0) {
375 LOGE("Failed to parse Src-sha1 \"%s\"\n", sha1src);
378 if (SS_LoadFile(path, &source_file) == 0) {
379 if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) != 0) {
380 SS_Free(source_file.data);
381 unsigned char actualShaBuffer[41] = { 0, };
382 hex_digest(source_file.sha1, actualShaBuffer, SHA_DIGEST_SIZE);
383 LOGE("SS_FSVerifyNode - SHA mismatch with SRC - PATH [%s] Expected [%s] Actual [%s]\n",
384 path, sha1src, actualShaBuffer);
385 SS_SetUpgradeState(E_SS_FSSRCCURRUPTED); // Define other error
389 SS_Free(source_file.data);
392 LOGL(LOG_SSENGINE, "FS partition Already verified - Filling only size and offset \n");
393 snprintf(patch, MAX_FILE_PATH, "%s%s%s", patchpath_name, "/", patchname);
394 if ((type == DIFFS/* ||type == NEWFILES */)) { // allowing size 0 also for folders
395 if (tar_get_item_size_from_struct(&tar_cfg_data, patchname, data_size, data_offset)
397 LOGE("failed to get item size from struct, Patch : [%s] \n", patchname);
398 SS_SetUpgradeState(E_SS_FSBADNODES);
401 if (*data_size < 0) {
402 LOGE("failed to verifyNodes [delta absent], Patch : [%s] Type[%d]\n", patch, type);
403 SS_SetUpgradeState(E_SS_FSBADNODES);
412 *********************************************************************************
414 *********************************************************************************
417 * This is to append node to the global control structure for delta files.
422 * @return returns S_SS_SUCCESS and
423 * returns E_SS_FAILURE in case any error occurs
425 *********************************************************************************
427 int SS_AppendNode(const char *ubDeltaPath, fs_params ** headparam, fs_params ** tailparam, const char *old_path,
428 const char *new_path, const char *patchname, const char *sha1src, const char *sha1trg, int type,
429 char *patchpath_name)
431 fs_params *newnode = NULL;
435 if (!ubDeltaPath || !old_path || !new_path || !patchname || !sha1src || !sha1trg || !patchpath_name) {
436 LOGE("Bad Nodes, NULL params passed for Appending Nodes \n");
437 SS_SetUpgradeState(E_SS_FSINVALIDNODEPARAMS);
441 SS_FSVerifyNode(old_path, patchname, sha1src, type, patchpath_name, &data_size, &data_offset))) {
442 LOGE("Bad Nodes, Failed to pass verification - [Delta Path - %s][OldPath - %s] [NewPath - %s] \n", ubDeltaPath,
446 newnode = (fs_params *) SS_Malloc(sizeof(fs_params));
449 strncpy(newnode->file_old_path, old_path, SS_MAX_NAMELENSUPPORTED);//wgid: 29483
450 strncpy(newnode->file_new_path, new_path, SS_MAX_NAMELENSUPPORTED);//wgid: 29482
451 strncpy(newnode->patch_name, patchname, SS_MAX_NAMELENSUPPORTED);//wgid: 28033
452 strncpy(newnode->sha1src, sha1src, sizeof(newnode->sha1src) -1);//wgid: 25282
453 strncpy(newnode->sha1trg, sha1trg, sizeof(newnode->sha1trg) - 1);//wgid: 25283
454 newnode->type = type;
455 newnode->data_size = data_size;
456 newnode->data_offset = data_offset;
457 newnode->nextnode = NULL;
459 //LOG("%s %s %d %s %s \n",newnode->file_path,newnode->patch_name,newnode->type, newnode->sha1src, newnode->sha1trg);
461 if (*headparam == NULL) {
462 *headparam = newnode;
463 *tailparam = newnode;
465 (*tailparam)->nextnode = newnode;
466 (*tailparam) = (*tailparam)->nextnode;
472 void SS_UpdateUIProgress(ua_dataSS_t * ua_dataSS, int ulTotalFsCnt, int ulDone)
474 static int ss_count = 1;
475 int res_val = SS_GetProgressResolution(ulTotalFsCnt);
477 LOGE("Error ua_dataSS\n");
480 //LOG("\nvalues are ss_count[%d] total_file_cnt[%d]",ss_count,ulTotalFsCnt);
482 if (ua_dataSS->ui_progress)
483 ua_dataSS->ui_progress(ua_dataSS, 100);
485 } else if (ss_count < ulTotalFsCnt) {
486 if (ss_count % res_val == 0) { //Max 50 times display
487 double data = (double)ss_count / (double)ulTotalFsCnt;
488 if (ua_dataSS->ui_progress)
489 ua_dataSS->ui_progress(ua_dataSS, data * 100);
493 if (ua_dataSS->ui_progress)
494 ua_dataSS->ui_progress(ua_dataSS, 100);
501 *********************************************************************************
503 *********************************************************************************
506 * This is to clear the global control structure for delta files.
513 *********************************************************************************
515 void SS_FSClearNodes()
517 fs_params *local_temp = NULL;
518 fs_params *local_next = NULL;
519 LOGL(LOG_SSENGINE, "Free Nodes\n");
521 if (headptr_list->del_ref) {
522 local_temp = headptr_list->del_ref;
524 local_next = local_temp->nextnode;
526 local_temp = local_next;
529 if (headptr_list->dif_ref) {
530 local_temp = headptr_list->dif_ref;
532 local_next = local_temp->nextnode;
534 local_temp = local_next;
537 if (headptr_list->move_ref) {
538 local_temp = headptr_list->move_ref;
540 local_next = local_temp->nextnode;
542 local_temp = local_next;
545 if (headptr_list->new_ref) {
546 local_temp = headptr_list->new_ref;
548 local_next = local_temp->nextnode;
550 local_temp = local_next;
553 if (headptr_list->sym_difref) {
554 local_temp = headptr_list->sym_difref;
556 local_next = local_temp->nextnode;
558 local_temp = local_next;
561 if (headptr_list->sym_newref) {
562 local_temp = headptr_list->sym_newref;
564 local_next = local_temp->nextnode;
566 local_temp = local_next;
569 if (headptr_list->hard_newref) {
570 local_temp = headptr_list->hard_newref;
572 local_next = local_temp->nextnode;
574 local_temp = local_next;
577 if (headptr_list->hard_difref) {
578 local_temp = headptr_list->hard_difref;
580 local_next = local_temp->nextnode;
582 local_temp = local_next;
585 SS_Free(headptr_list);
591 *********************************************************************************
593 *********************************************************************************
596 * This is to get the delta count for diffs , deletes etc.
601 * @return returns structure with delta count info
602 * NULL in case of error
604 *********************************************************************************
607 struct details *SS_FSGetDeltaCount(char *ubDeltaPath, char *ubDeltaInfoFile, char *patchlist_backup_patch)
609 int size = 0, bckupsize = 0, ret = 1;
611 char *FileData = NULL;
614 char *saveptr = NULL;
616 struct details *refer_copy = NULL;
617 FILE *filename_bkup = NULL;
619 if (!(ubDeltaPath && ubDeltaInfoFile)) {
620 LOGE("failed to Parse DELTA count information: \n");
621 SS_SetUpgradeState(E_SS_BAD_PARAMS);
624 refer_copy = (struct details *)SS_Malloc(sizeof(struct details));
626 if (refer_copy == NULL) {
627 LOGE("failed to allocate memory\n");
631 LOGL(LOG_SSENGINE, "Delta File Info =%s\n", ubDeltaInfoFile);
633 size = tar_get_item_size(ubDeltaPath, ubDeltaInfoFile);
635 LOGE("failed to Access DELTA info file DPath:[%s] File: [%s]\n", ubDeltaPath, ubDeltaInfoFile);
636 SS_SetUpgradeState(E_SS_FSBADDELTA);
641 FileData = SS_Malloc(size + 1);
642 if (FileData == NULL) {
643 LOGE("Failed to Allocate Memory\n");
644 SS_SetUpgradeState(E_SS_MALLOC_ERROR);
649 memset(FileData, 0, size + 1);
650 data_size = tar_get_cfg_data(ubDeltaPath, ubDeltaInfoFile, FileData, size);
651 if (data_size <= 0) { // == 0 is NOT okay??
652 LOGE("Failed to read cfg data from Delta\n");
653 SS_SetUpgradeState(E_SS_FSBADDELTA);
657 filename_bkup = fopen(patchlist_backup_patch, "wb+");
658 if (filename_bkup == NULL) {
659 strerror_r(errno, buf, sizeof(buf));
660 LOGE("Failed to create BACKUP file Error:[%s]\n", buf);
661 SS_SetUpgradeState(E_SS_FSFAILEDTOBACKUPPATCHINFO);
666 bckupsize = fwrite(FileData, 1, data_size, filename_bkup); //RECHECK SIZE 1
667 if (bckupsize <= 0) {
668 SS_SetUpgradeState(E_SS_FSFAILEDTOBACKUPPATCHINFO);
672 LOGL(LOG_SSENGINE, " Size [%d] DataSize [%d] BakUpSize [%d]\n", size, data_size, bckupsize);
674 line = strstr(FileData, SS_FSCOUNT_MAGIC_KEY);
676 LOGL(LOG_SSENGINE, "SS_FSGetDeltaCount() last line %s \n", line);
678 token = strtok_r(&line[SS_FSCOUNT_MAGIG_KEYLEN], SS_TOKEN_SPACE, &saveptr);
680 refer_copy->diffs = atoi(token);
682 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
686 token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
688 refer_copy->moves = atoi(token);
690 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
695 token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
697 refer_copy->news = atoi(token);
699 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
704 token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
706 refer_copy->deletes = atoi(token);
708 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
713 token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
715 refer_copy->symdiffs = atoi(token);
717 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
722 token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
724 refer_copy->symnews = atoi(token);
726 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
731 token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
733 refer_copy->harddiffs = atoi(token);
735 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
740 token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
742 refer_copy->hardnews = atoi(token);
744 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
750 refer_copy->diffs + refer_copy->moves + refer_copy->news + refer_copy->deletes + refer_copy->symdiffs +
751 refer_copy->symnews + refer_copy->harddiffs + refer_copy->hardnews;
752 LOG("SS_FSGetDeltaCount() total no of file %d\n", gtotalFSCnt);
755 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
756 LOG("SS_FSGetDeltaCount() Failed to read last line\n");
758 if (gtotalFSCnt < 0) {
767 fclose(filename_bkup);
773 fclose(filename_bkup);
780 *********************************************************************************
782 *********************************************************************************
785 * This is used to build the gobal control structure for diffs, deletes etc.
786 * For all the entries in config file (which has info) the information is parsed to the global control struct
791 * @return returns fs_list structure filled with details of all the files to be diff-ed ,deleted etc.
792 * NULL in case of error
794 *********************************************************************************
796 fs_list *SS_FSBuildNodes(ua_dataSS_t * ua_dataSS)
799 char line[SS_TOKEN_MAXLINE_LEN] = { '\0' };
800 char patchlist_backup_patch[MAX_FILE_PATH];
801 snprintf(patchlist_backup_patch, MAX_FILE_PATH, "%s/%s",ua_dataSS->update_data->ua_delta_folder, SS_PATCHLIST_BKUPLOC);
802 char string_na[] = "NA";
803 char *patch_name = NULL;
804 char *source_name = NULL;
805 char *target_name = NULL;
806 char *sha1src = NULL;
807 char *sha1trg = NULL;
808 char *change_type = NULL;
809 char *file_type = NULL;
810 char *saveptr = NULL;
811 uint32_t ulPatchCount = 0, del_type = DELETES;
812 fs_params *fs_diffhead = NULL;
813 fs_params *fs_difftail = NULL;
814 fs_params *fs_movehead = NULL;
815 fs_params *fs_movetail = NULL;
816 fs_params *fs_newhead = NULL;
817 fs_params *fs_delhead = NULL;
818 fs_params *fs_deltail = NULL;
819 fs_params *fs_symlinkdiffhead = NULL;
820 fs_params *fs_symlinkdifftail = NULL;
821 fs_params *fs_symlinknewhead = NULL;
822 fs_params *fs_symlinknewtail = NULL;
823 fs_params *fs_hardlinkdiffhead = NULL;
824 fs_params *fs_hardlinkdifftail = NULL;
825 fs_params *fs_hardlinknewhead = NULL;
826 fs_params *fs_hardlinkdnewtail = NULL;
828 struct details *local = NULL;
829 fs_list *fs_head_node = NULL;
830 int i = 0, retval = 0;
832 LOGE("Bad structure ua_dataSS\n");
833 SS_SetUpgradeState(E_SS_BAD_PARAMS);
836 LOGL(LOG_SSENGINE, " Build Nodes Entry \n");
837 if (tar_cfg_data == NULL)
838 tar_cfg_data = tar_build_cfg_table(ua_dataSS->update_data->ua_delta_path);
840 LOGE(" tar_build_cfg_table Failed \n");
841 SS_SetUpgradeState(E_SS_BAD_PARAMS);
844 local = SS_FSGetDeltaCount(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_patch_info, patchlist_backup_patch);
846 LOGE(" Build Nodes Failed \n");
848 tar_free_cfg_table(&tar_cfg_data);
849 SS_SetUpgradeState(E_SS_BAD_PARAMS);
853 fp = fopen(patchlist_backup_patch, "r");
855 SS_SetUpgradeState(E_SS_FSFAILEDTOOPENPATCHINFO);
857 tar_free_cfg_table(&tar_cfg_data);
862 ulPatchCount = local->diffs + local->deletes + local->news + local->moves + local->symdiffs +
863 local->symnews + local->harddiffs + local->hardnews;
864 LOG("Total FS count [%d].\n", ulPatchCount);
866 ************************************************************************
867 Parsing logic implemented for patchlist
868 ************************************************************************
869 Sample entries in patchlist as below :
870 <CHANGE-TYPE>:<FILE-TYPE>:<OTHER-DETAILS...>
871 ************************************************************************
872 DIFF:REG:system/bin/vi:system/bin/vi:2f2f3dc6d3ee06af0080ac7975f22941660f2480:78b2d44af32d854c70f1cb7431a60c2682a320cc:diff1_vi.delta
873 DIFF:TPK:system/usr/packages/removable/com.samsung.calculator.tpk:system/usr/packages/removable/com.samsung.calculator.tpk:
874 96fc1bcde30d501ba65ef0038e05da46d255a7b3:fa1d5d9daa4097ac302b69244297f508577c3a01:diff1598_com.samsung.calculator.tpk.delta/
875 MOVE:REG:system/etc/smack/accesses.d/heremaps-engine-devel:system/usr/apps/com.samsung.contacts/res/temp:da39a3ee5e6b4b0d3255bfef95601890afd80709
876 DEL:REG:system/usr/ug/res/images/ug-phone/contacts/favorites_icon_remove.PNG:38ad8be378506d19b1c769d46be262cf100f6c59
877 DEL:SYM:system/usr/apps/com.samsung.message-lite/lib/libmsg-common.so
878 DEL:HARD:system/usr/apps/com.samsung.message-lite/lib/libmsg-common.so
879 SYM:DIFF:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:
880 libplugin-na-mobex.so.0.3.57
881 SYM:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
882 HARD:DIFF:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:
883 libplugin-na-mobex.so.0.3.57
884 HARD:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
885 ***********************************************************************
887 if (local && ((local->diffs) > 0 || (local->moves > 0))) {
888 LOGL(LOG_SSENGINE, "%ss [%d] %ss [%d]\n", SS_STRING_DIFF, local->diffs, SS_STRING_MOVE, local->moves);
889 for (i = 0; i < (local->diffs + local->moves); i++) {
890 if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
891 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
894 //LOGL(LOG_SSENGINE, "DIFF LINE:[%d] [%s] \n",i+1,line);
896 change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
897 file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
899 LOGE("Unexpected null in strtok_r");
903 if (change_type && strcmp(change_type, SS_STRING_MOVE) == 0) { // && strcmp(file_type,"TPK") == 0){
904 source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
905 target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
906 sha1src = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
907 //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_MOVE, i);
909 if (!source_name || !target_name || !sha1src) {
910 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
911 //LOGE("Failed to extract Patch Info Type:DELETES \n");
912 LOGE("Failed to parse DIFFS - LINE:[%d] [%s] \n", i + 1, line);
916 SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_movehead, &fs_movetail, source_name,
917 target_name, string_na, sha1src, string_na, MOVES,
918 ua_dataSS->update_delta->ua_patch_path);
919 if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
922 if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
923 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
925 } else if (change_type && strcmp(change_type, SS_STRING_DIFF) == 0) { // && strcmp(file_type,"TPK") == 0){
926 source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
927 target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
928 sha1src = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
929 sha1trg = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
930 patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
931 //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_DIFF, i);
933 if (patch_name && (strlen(patch_name) <= SS_MAX_NAMELENSUPPORTED)) {
935 SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_diffhead, &fs_difftail,
936 source_name, target_name, patch_name, sha1src, sha1trg, DIFFS,
937 ua_dataSS->update_delta->ua_patch_path);
938 if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
941 SS_SetUpgradeState(E_SS_FILENAMELENERROR);
942 LOGE("File Name length Limitation Error File:[%s]\n", patch_name);
946 if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
947 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
950 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
951 LOGE("Patch Name format Error File\n");
956 if (local && (local->news) > 0) { //check if new files archive is present in the delta
957 char new_patch_path[MAX_FILE_PATH] = { 0, };
958 snprintf(new_patch_path, MAX_FILE_PATH, "%s%s", ua_dataSS->parti_info->ua_subject_name, SS_COMPRESSED_FILE);
959 if (tar_get_item_size(ua_dataSS->update_data->ua_delta_path, new_patch_path) <= 0) {
960 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
961 LOGE("New files not present in Patch\n");
965 if (local && (local->deletes) > 0) { //this is to group to delete list
966 LOGL(LOG_SSENGINE, "%ss [%d]\n", SS_STRING_DEL, local->deletes);
967 for (i = 0; i < (local->deletes); i++) {
968 if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
969 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
973 change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
975 LOGE("Unexpected null in strtok_r");
978 file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
980 if (file_type && strcmp(file_type, SS_STRING_REG) == 0) {
981 source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
982 sha1src = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
984 } else if (file_type && ((strcmp(file_type, SS_STRING_SYM) == 0) || (strcmp(file_type, SS_STRING_HARD) == 0))) {
985 source_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
988 } else if (file_type && strcmp(file_type, SS_STRING_END) == 0) {
989 source_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
991 del_type = DELETE_END;
993 LOGE("Failed to parse DELETES - LINE:[%d] [%s] \n", i + 1, line);
997 if (!source_name || !sha1src) {
998 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
999 //LOGE("Failed to extract Patch Info Type:DELETES \n");
1000 LOGE("Failed to parse DELETES - LINE:[%d] [%s] \n", i + 1, line);
1003 //LOGL(LOG_SSENGINE, "%s Index [%d]\n", SS_STRING_DEL, i);
1005 SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_delhead, &fs_deltail, source_name,
1006 string_na, string_na, sha1src, string_na, del_type,
1007 ua_dataSS->update_delta->ua_patch_path);
1008 if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
1010 if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
1011 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1015 } //For symlink files
1017 if (local && (local->symdiffs) > 0) {
1018 LOGL(LOG_SSENGINE, "%s %ss [%d]\n", SS_STRING_SYM, SS_STRING_DIFF, local->symdiffs);
1019 for (i = 0; i < (local->symdiffs); i++) { //get the count from below function
1020 if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
1021 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
1024 //LOGL(LOG_SSENGINE, "SYMDIFF LINE:[%d] [%s] \n",i+1,line);
1026 change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
1027 file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1029 if ((change_type && file_type) &&
1030 strcmp(change_type, SS_STRING_SYM) == 0 && strcmp(file_type, SS_STRING_DIFF) == 0) { // && strcmp(file_type,"TPK") == 0){
1031 source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1032 target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1033 patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
1034 //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_DIFF, i);
1036 if (!source_name || !target_name || !patch_name) {
1037 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
1038 //LOGE("Failed to extract Patch Info Type:DELETES \n");
1039 LOGE("Failed to parse SymDiffs - LINE:[%d] [%s] \n", i + 1, line);
1043 SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_symlinkdiffhead, &fs_symlinkdifftail,
1044 source_name, target_name, patch_name, string_na, string_na, SYMDIFFS,
1045 ua_dataSS->update_delta->ua_patch_path);
1046 if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
1048 if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
1049 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1054 if (local && (local->symnews) > 0) {
1055 LOGL(LOG_SSENGINE, "%s %ss [%d]n", SS_STRING_SYM, SS_STRING_NEW, local->symnews);
1056 for (i = 0; i < (local->symnews); i++) {
1057 if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
1058 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
1061 //LOGL(LOG_SSENGINE, "SYMNEWS LINE:[%d] [%s] \n",i+1,line);
1063 change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
1064 file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1066 if ((change_type && file_type) &&
1067 (strcmp(change_type, SS_STRING_SYM) == 0 && strcmp(file_type, SS_STRING_NEW) == 0)) {
1068 source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1069 patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
1070 //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_NEW, i);
1072 if (!source_name || !patch_name) {
1073 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
1074 //LOGE("Failed to extract Patch Info Type:DELETES \n");
1075 LOGE("Failed to parse SymNews - LINE:[%d] [%s] \n", i + 1, line);
1079 SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_symlinknewhead, &fs_symlinknewtail,
1080 source_name, string_na, patch_name, string_na, string_na, SYMNEWFILES,
1081 ua_dataSS->update_delta->ua_patch_path);
1082 if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
1084 if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
1085 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1090 if (local && (local->hardnews) > 0) {
1091 LOGL(LOG_SSENGINE, "%s %ss [%d]\n", SS_STRING_HARD, SS_STRING_NEW, local->hardnews);
1092 for (i = 0; i < (local->hardnews); i++) {
1093 if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
1094 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
1097 //LOGL(LOG_SSENGINE, "HARDNEWS LINE:[%d] [%s] \n",i+1,line);
1099 change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
1100 file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1102 if ((change_type && file_type) &&
1103 (strcmp(change_type, SS_STRING_HARD) == 0 && strcmp(file_type, SS_STRING_NEW) == 0)) {
1104 source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1105 patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
1106 //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_NEW, i);
1108 if (!source_name || !patch_name) {
1109 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
1110 //LOGE("Failed to extract Patch Info Type:DELETES \n");
1111 LOGE("Failed to parse HardNews - LINE:[%d] [%s] \n", i + 1, line);
1115 SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_hardlinknewhead, &fs_hardlinkdnewtail,
1116 source_name, string_na, patch_name, string_na, string_na, HARDNEWFILES,
1117 ua_dataSS->update_delta->ua_patch_path);
1118 if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
1120 if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
1121 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1127 if (local && (local->harddiffs) > 0) {
1128 LOGL(LOG_SSENGINE, "%s %ss [%d]\n", SS_STRING_HARD, SS_STRING_DIFF, local->harddiffs);
1129 for (i = 0; i < (local->harddiffs); i++) { //get the count from below function
1130 if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
1131 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
1134 //LOGL(LOG_SSENGINE, "HARDIFFS LINE:[%d] [%s] \n",i+1,line);
1136 change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
1137 file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1139 if ((change_type && file_type) &&
1140 strcmp(change_type, SS_STRING_HARD) == 0 && strcmp(file_type, SS_STRING_DIFF) == 0) { // && strcmp(file_type,"TPK") == 0){
1141 source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1142 target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
1143 patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
1144 //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_DIFF, i);
1146 if (!source_name || !target_name || !patch_name) {
1147 SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
1148 //LOGE("Failed to extract Patch Info Type:DELETES \n");
1149 LOGE("Failed to parse HardDiffs - LINE:[%d] [%s] \n", i + 1, line);
1153 SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_hardlinkdiffhead, &fs_hardlinkdifftail,
1154 source_name, target_name, patch_name, string_na, string_na, HARDDIFFS,
1155 ua_dataSS->update_delta->ua_patch_path);
1156 if (retval == E_SS_FAILURE) // ONLY test purpose, should enable this
1158 if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
1159 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1165 fs_head_node = (fs_list *) SS_Malloc(sizeof(fs_list));
1166 if (!fs_head_node) {
1167 SS_SetUpgradeState(E_SS_MALLOC_ERROR);
1170 fs_head_node->dif_ref = fs_diffhead;
1171 fs_head_node->move_ref = fs_movehead;
1172 fs_head_node->new_ref = fs_newhead;
1173 fs_head_node->del_ref = fs_delhead;
1174 fs_head_node->sym_difref = fs_symlinkdiffhead;
1175 fs_head_node->sym_newref = fs_symlinknewhead;
1176 fs_head_node->hard_difref = fs_hardlinkdiffhead;
1177 fs_head_node->hard_newref = fs_hardlinknewhead;
1178 fs_head_node->ulPatchCount = ulPatchCount;
1180 if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
1181 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 1);
1187 unlink(patchlist_backup_patch);
1188 if (retval == E_SS_FAILURE)
1190 tar_free_cfg_table(&tar_cfg_data);
1191 return fs_head_node;
1194 void SS_GetPartition_LocDetails(ua_dataSS_t * ua_dataSS)
1196 LOGL(LOG_SSENGINE, "PART NAME: [%s] \n", ua_dataSS->parti_info->ua_parti_name);
1197 snprintf(ua_dataSS->update_delta->ua_patch_path, MAX_FILE_PATH, "%s", ua_dataSS->parti_info->ua_subject_name);
1198 snprintf(ua_dataSS->update_delta->ua_patch_info, MAX_FILE_PATH, "%s%s%s", ua_dataSS->parti_info->ua_subject_name,
1199 ua_dataSS->parti_info->ua_parti_name, SS_PATCHLISTFORMAT);
1200 snprintf(ua_dataSS->update_delta->ua_attrib_path, MAX_FILE_PATH, "%s%s%s", ua_dataSS->parti_info->ua_subject_name,
1201 ua_dataSS->parti_info->ua_parti_name, SS_PATCH_ATTR_FORMAT);
1202 LOGL(LOG_SSENGINE, "PatchPath[%s] PatchInfo [%s] Attributes [%s]\n", ua_dataSS->update_delta->ua_patch_path,
1203 ua_dataSS->update_delta->ua_patch_info, ua_dataSS->update_delta->ua_attrib_path);
1208 //Support functions//Change Struct format details (Can include total file count also???)/*!
1210 ******************************************************************************** *
1212 *********************************************************************************
1214 * This is used to set the file attributes at the end of application of patches in FS
1218 *@return returns S_SS_SUCCESS
1219 * E_SS_FAILURE in case of error
1221 *********************************************************************************
1223 int SS_FSSetAttributes(ua_dataSS_t * ua_dataSS)
1226 char *psaveptr = NULL;
1227 char *pfilePath = NULL;
1228 char *pfiletype = NULL;
1229 char *attributSize = NULL;
1230 char *pattribs = NULL;
1231 int ulAttribSize = 0;
1232 int result = S_SS_SUCCESS;
1235 if (!(ua_dataSS && ua_dataSS->update_delta && ua_dataSS->update_data->ua_delta_path)) {
1236 LOGE("Bad params for SS_FSSetAttributes\n");
1237 SS_SetUpgradeState(E_SS_BAD_PARAMS);
1238 return E_SS_FAILURE;
1240 LOGL(LOG_SSENGINE, "ATTRIB PATH: [%s] \n", ua_dataSS->update_delta->ua_attrib_path);
1242 int item_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_attrib_path);
1244 if (item_size <= 0) {
1245 LOGL(LOG_SSENGINE, "No Attributes to SET\n");
1246 return S_SS_SUCCESS; // Delta with ONLY deletes
1248 char *item_data = SS_Malloc(item_size + 1);
1249 if (item_data == NULL) {
1250 LOGE("SS_Malloc failed!! - item_data\n");
1251 SS_SetUpgradeState(E_SS_MALLOC_ERROR);
1252 return E_SS_FAILURE;
1255 tar_get_cfg_data(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_attrib_path, item_data,
1257 if (read_data <= 0) {
1258 LOGE("read_data failed!!\n");
1259 SS_SetUpgradeState(E_SS_FSBADDELTA);
1260 if (item_data != NULL) {
1264 return E_SS_FAILURE;
1266 item_data[read_data] = '\0';
1268 pline = strtok_r(item_data, "\n", &psaveptr);
1269 if (pline == NULL) {
1270 LOGL(LOG_SSENGINE, "No Attributes to SET as no lines in file\n");
1271 if (item_data != NULL) {
1275 return E_SS_FAILURE;
1279 char *saveptr_pline = NULL;
1280 pfilePath = strtok_r(pline, "\"", &saveptr_pline);
1282 if (pfilePath && strcmp(pfilePath, SS_FWSLASH) == 0) {
1283 LOGE("skip root: it is RO\n");
1284 pline = strtok_r(NULL, SS_TOKEN_NEWLINE, &psaveptr);
1288 pfiletype = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr_pline);
1289 attributSize = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr_pline);
1290 pattribs = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr_pline);
1291 //LOG("\nSS_FSSetAttributes [%s][%s][%s]", pfiletype, attributSize, pattribs);
1292 if (pattribs && pfilePath && pfiletype && attributSize) {
1293 ulAttribSize = strlen(pattribs);
1294 //LOG("\nSS_SetFileAttributes [%s][%s][%d][%s]",pfilePath,pfiletype,ulAttribSize, pattribs );
1295 //LOG("SS_SetFileAttributes [%s]\n", pfilePath);
1297 result = SS_SetFileAttributes(pfilePath, ulAttribSize, (const unsigned char *)pattribs);
1298 if (result != S_SS_SUCCESS) {
1299 LOGE("Failed to set Attributes %s\n", pfilePath);
1300 SS_SetUpgradeState(E_SS_FSBADATTRIBUTES);
1308 LOGE("Failed to Parse Attributes - LINE %s\n", pline);
1309 SS_SetUpgradeState(E_SS_FSBADATTRIBUTES);
1316 pline = strtok_r(NULL, SS_TOKEN_NEWLINE, &psaveptr);
1319 if (item_data != NULL) {
1325 result = E_SS_FAILURE;
1327 result = S_SS_SUCCESS;
1333 *********************************************************************************
1335 *********************************************************************************
1338 * This is used to update individual files on case basis
1343 * @return returns S_SS_SUCCESS
1344 * E_SS_FAILURE in case of error
1346 *********************************************************************************
1348 int SS_FSUpdateFile(int ubFileType, ua_dataSS_t * ua_dataSS, int ulPatchCount, fs_params * pFsNode,
1349 const char *patch_path)
1351 int ulFileIndex = 1;
1352 char ubPatch[SS_MAX_FILE_PATH] = { 0, };
1354 int ulResult = S_SS_SUCCESS;
1355 FileInfo source_file;
1356 FileInfo target_file;
1357 uint8_t target_sha1[SHA_DIGEST_SIZE] = { 0, };
1358 char new_compressed_path[MAX_FILE_PATH], patchfile_source_path[MAX_FILE_PATH];
1359 snprintf(new_compressed_path, MAX_FILE_PATH, "%s/%s", ua_dataSS->update_data->ua_delta_folder, SS_NEW_COMPRESSED_FILE);
1360 snprintf(patchfile_source_path, MAX_FILE_PATH, "%s/%s", ua_dataSS->update_data->ua_delta_folder, SS_PATCHFILE_SOURCE);
1363 LOGE("Bad patch_path name\n");
1364 return E_SS_FAILURE;
1366 switch (ubFileType) {
1369 LOGL(LOG_SSENGINE, "DIFFS mode start\n");
1370 #ifdef TIME_PROFILING
1371 get_time_stamp1(); //total time capturing
1373 LOGL(LOG_SSENGINE, "DIFFS mode start time = [%lf]\n",
1376 tar_open(ua_dataSS->update_data->ua_delta_path);
1378 //LOGL(LOG_SSENGINE, "DIFFS update Index: [%d] \n", ulFileIndex++);
1379 snprintf(ubPatch, SS_MAX_FILE_PATH, "%s%s", patch_path, pFsNode->patch_name);
1380 //LOGL(LOG_SSENGINE, "DIFF list --- [File Name %s]\n [Patch Name %s]",pFsNode->file_path, ubPatch);
1381 if (pFsNode->data_size > 0) {
1383 fast_tar_extract_file(ua_dataSS->update_data->ua_delta_path, ubPatch, patchfile_source_path,
1384 pFsNode->data_size, pFsNode->data_offset);
1385 if (ulReadCnt < 0) {
1386 ulResult = E_SS_FAILURE;
1388 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1389 LOGE("Delta Read Failed\n");
1392 //LOGL(LOG_SSENGINE,"Updating [Item - %s]and size is[%d] Read Count[%d]\n",ubPatch, pFsNode->data_size, ulReadCnt);
1396 SS_UpdateDeltaFS(pFsNode->file_old_path, pFsNode->file_new_path, pFsNode->sha1src,
1397 pFsNode->sha1trg, pFsNode->data_size, ua_dataSS->update_data->ua_delta_folder);
1398 if (ulResult != S_SS_SUCCESS) {
1399 LOGE("FS update Failed Result : [%d], [Item - %s]and size is[%d] Read Count[%d], index = [%d]\n", ulResult,
1400 ubPatch, pFsNode->data_size, ulReadCnt, ulFileIndex);
1402 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1405 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1406 pFsNode = pFsNode->nextnode;
1409 ulResult = E_SS_FAILURE;
1411 LOGE("size is invalid, index = [%d]\n",
1413 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1418 LOGL(LOG_SSENGINE, "DIFFS : Total index = [%d]\n",
1420 #ifdef TIME_PROFILING
1421 get_time_stamp1(); //total time capturing
1424 "DIFFS mode end time = [%lf], diff = [%lf]\n", t2,
1428 LOGL(LOG_SSENGINE, "DIFFS mode end\n");
1433 LOGL(LOG_SSENGINE, "MOVES mode start\n");
1435 #ifdef TIME_PROFILING
1436 get_time_stamp1(); //total time capturing
1438 LOGL(LOG_SSENGINE, "MOVES mode start time = [%lf]\n",
1442 //LOGL(LOG_SSENGINE, "MOVES update Index: [%d] \n", ulFileIndex++);
1444 if (SS_LoadFile(pFsNode->file_old_path, &source_file) == 0) {
1445 LOGL(LOG_SSENGINE, "Patch Can be applied\n");
1446 if (source_file.data)
1447 SS_Free(source_file.data);
1448 } else if (SS_LoadFile(pFsNode->file_new_path, &target_file) == 0) {
1449 LOGL(LOG_SSENGINE, "source deleted!!, file_old_path: [%s]\n", pFsNode->file_old_path);
1450 if (ParseSha1(pFsNode->sha1src, target_sha1) != 0) {
1451 LOGE("failed to parse sha1 \"%s\"\n", pFsNode->sha1src);
1452 ulResult = E_SS_FAILURE;
1453 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1454 if (target_file.data)
1455 SS_Free(target_file.data);
1458 if (memcmp(target_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
1459 LOGL(LOG_SSENGINE, "Patch already applied\n");
1461 if (target_file.data)
1462 SS_Free(target_file.data);
1464 LOGL(LOG_SSENGINE, "target_sha1 diff!!: [%s]\n", target_sha1);
1465 ulResult = E_SS_FAILURE;
1466 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1467 if (target_file.data)
1468 SS_Free(target_file.data);
1472 LOGE("No exist files. - file_old_path: [%s] file_new_path: [%s]\n", pFsNode->file_old_path, pFsNode->file_new_path);
1473 ulResult = E_SS_FAILURE;
1474 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1478 if (skip_flag == 0) {
1479 ulResult = SS_MoveFile(pFsNode->file_old_path, pFsNode->file_new_path);
1480 if (ulResult != S_SS_SUCCESS) {
1481 LOGE("Move Failed for [%s] to [%s], result = [%d], index = [%d]\n", pFsNode->file_old_path, pFsNode->file_new_path, ulResult, ulFileIndex);
1482 SS_SetUpgradeState(ulResult);
1486 if (SS_LoadFile(pFsNode->file_new_path, &target_file) == 0) {
1487 if (ParseSha1(pFsNode->sha1src, target_sha1) != 0) {
1488 LOGE("failed to parse sha1 \"%s\"\n", pFsNode->sha1src);
1489 ulResult = E_SS_FAILURE;
1490 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1491 if (target_file.data)
1492 SS_Free(target_file.data);
1495 if (memcmp(target_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
1496 LOGL(LOG_SSENGINE, "Patch success!!\n");
1497 if (target_file.data)
1498 SS_Free(target_file.data);
1500 LOGL(LOG_SSENGINE, "target_sha1 diff!!: [%s]\n", target_sha1);
1501 ulResult = E_SS_FAILURE;
1502 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1503 if (target_file.data)
1504 SS_Free(target_file.data);
1510 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1511 pFsNode = pFsNode->nextnode;
1514 LOGL(LOG_SSENGINE, "MOVES : Total index = [%d]\n",
1516 #ifdef TIME_PROFILING
1517 get_time_stamp1(); //total time capturing
1520 "MOVES mode end time = [%lf], diff = [%lf]\n", t2,
1523 LOGL(LOG_SSENGINE, "MOVES mode end\n");
1528 LOGL(LOG_SSENGINE, "DELETES mode start\n");
1531 #ifdef TIME_PROFILING
1532 get_time_stamp1(); //total time capturing
1534 LOGL(LOG_SSENGINE, "DELETES mode start time = [%lf]\n",
1538 if (pFsNode->type == DELETES) {
1539 //LOGL(LOG_SSENGINE, "DELETES update Index: [%d] \n", ulFileIndex++);
1540 SS_GetFileType(pFsNode->file_old_path, (enumFileType *) & ulFiletype);
1541 if (ulFiletype == 2) //FT_FOLDER
1542 ulResult = SS_DeleteFolder(pFsNode->file_old_path);
1544 ulResult = SS_DeleteFile(pFsNode->file_old_path);
1545 if (ulResult != S_SS_SUCCESS) {
1546 LOGE("Delete Failed, result = [%d], index = [%d]\n", ulResult, ulFileIndex);
1547 SS_SetUpgradeState(ulResult);
1552 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1553 pFsNode = pFsNode->nextnode;
1555 LOGL(LOG_SSENGINE, "DELETES : Total index = [%d]\n",
1557 #ifdef TIME_PROFILING
1558 get_time_stamp1(); //total time capturing
1561 "DELETES mode end time = [%lf], diff = [%lf]\n",
1564 LOGL(LOG_SSENGINE, "DELETES mode end\n");
1569 LOGL(LOG_SSENGINE, "DELETE_END mode start\n");
1572 #ifdef TIME_PROFILING
1573 get_time_stamp1(); //total time capturing
1576 "DELETE_END mode start time = [%lf]\n", t1);
1579 if (pFsNode->type == DELETE_END) {
1580 LOGL(LOG_SSENGINE, "DELETE_END update Index: [%d] \n", ulFileIndex++);
1581 SS_GetFileType(pFsNode->file_old_path, (enumFileType *) & ulFiletype);
1582 if (ulFiletype == 2) //FT_FOLDER
1583 ulResult = SS_DeleteFolder(pFsNode->file_old_path);
1585 ulResult = SS_DeleteFile(pFsNode->file_old_path);
1586 if (ulResult != S_SS_SUCCESS) {
1587 LOGE("Delete Failed, result = [%d], index = [%d]\n", ulResult, ulFileIndex);
1588 SS_SetUpgradeState(ulResult);
1593 pFsNode = pFsNode->nextnode;
1595 LOGL(LOG_SSENGINE, "DELETE_END : Total index = [%d]\n",
1597 #ifdef TIME_PROFILING
1598 get_time_stamp1(); //total time capturing
1601 "DELETE_END mode start time = [%lf], diff = [%lf]\n",
1604 LOGL(LOG_SSENGINE, "DELETE_END mode end\n");
1610 LOGL(LOG_SSENGINE, "NEWFILES mode start\n");
1612 #ifdef TIME_PROFILING
1613 get_time_stamp1(); //total time capturing
1615 LOGL(LOG_SSENGINE, "NEWFILES mode start time = [%lf]\n",
1618 LOGL(LOG_SSENGINE, "Starting New file upgrade for [%s]\n", patch_path);
1619 if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, (char *)patch_path, new_compressed_path) >=
1621 if (_7zdecompress(new_compressed_path) == 0)
1622 LOGL(LOG_SSENGINE, "7zip extracted successfully %s\n", ua_dataSS->parti_info->ua_parti_name);
1624 LOGL(LOG_SSENGINE, "7zip extraction error for %s\n", ua_dataSS->parti_info->ua_parti_name);
1626 LOGL(LOG_SSENGINE, "tar extraction error for %s\n", ua_dataSS->parti_info->ua_parti_name);
1627 SS_DeleteFile(new_compressed_path);
1628 #ifdef TIME_PROFILING
1629 get_time_stamp1(); //total time capturing
1632 "NEWFILES mode end time = [%lf], diff = [%lf]\n",
1635 LOGL(LOG_SSENGINE, "NEWFILES mode end\n");
1640 LOGL(LOG_SSENGINE, "SYMDIFFS mode start\n");
1642 #ifdef TIME_PROFILING
1643 get_time_stamp1(); //total time capturing
1645 LOGL(LOG_SSENGINE, "SYMDIFFS mode start time = [%lf]\n",
1649 //LOGL(LOG_SSENGINE, "SYMDIFFS update Index: [%d] \n", ulFileIndex++);
1650 //LOG("Sym Diff file paths: [Linkname - %s] [reference file name- %s][]\n", pFsNode->file_path,pFsNode->patch_name);
1651 ulResult = SS_Unlink(pFsNode->file_old_path);
1652 if (ulResult == S_SS_SUCCESS) {
1653 ulResult = SS_Link(NULL, pFsNode->file_new_path, pFsNode->patch_name);
1654 if (ulResult != S_SS_SUCCESS) {
1655 LOGE("SS_Link Failed, Linkname:[%s], reference file name, index = [%d]:[%s]\n",
1656 pFsNode->file_new_path, ulFileIndex, pFsNode->patch_name);
1659 LOGE("Unlink Failed, result = [%d], index = [%d]\n", ulResult, ulFileIndex);
1660 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1663 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1664 pFsNode = pFsNode->nextnode;
1667 LOGL(LOG_SSENGINE, "SYMDIFFS : Total index = [%d]\n",
1669 #ifdef TIME_PROFILING
1670 get_time_stamp1(); //total time capturing
1673 "SYMDIFFS mode end time = [%lf], diff = [%lf]\n",
1676 LOGL(LOG_SSENGINE, "SYMDIFFS mode end\n");
1681 LOGL(LOG_SSENGINE, "SYMNEWFILES mode start\n");
1683 fs_params *head_node;
1684 int retry_count = 0, do_retry = 0;
1685 #ifdef TIME_PROFILING
1686 get_time_stamp1(); //total time capturing
1689 "SYMNEWFILES mode start time = [%lf]\n", t1);
1692 head_node = pFsNode;
1694 //LOGL(LOG_SSENGINE, "SYMNEWS update Index: [%d] \n", ulFileIndex++);
1695 snprintf(ubPatch, SS_MAX_FILE_PATH, "%s%s%s", patch_path, "/", head_node->patch_name);
1696 LOGL(LOG_SSENGINE, "Sym New file paths: [Linkname - %s] [reference file name- %s][]\n",
1697 head_node->file_old_path, head_node->patch_name);
1698 ulResult = SS_Link(NULL, head_node->file_old_path, head_node->patch_name);
1699 if (ulResult == E_SS_FAILURE) {
1700 LOGE("Link Failed, result = [%d], index = [%d]\n", ulResult, ulFileIndex);
1701 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1703 } else if (ulResult == ENOENT) { //to handle cases where new symlink points to a new symlink yet to be created
1704 do_retry = 1; //we will retry the failed symlinks with error 2 (no file or dir) again after this cycle
1705 //SS_UpdateUIProgress(ua_dataSS,ulPatchCount);
1706 head_node = head_node->nextnode;
1709 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1710 head_node = head_node->nextnode;
1713 LOGL(LOG_SSENGINE, "SYMNEWFILES : Total index = [%d]\n",
1715 if (do_retry && (retry_count < 4)) {
1719 goto SYMLINK_CREATE;
1720 } else if (do_retry && (retry_count >= 4)) { //retry to be done maximum 4 times
1721 LOGE("Link Failed after %d retrys\n", retry_count);
1722 //SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1725 #ifdef TIME_PROFILING
1726 get_time_stamp1(); //total time capturing
1729 "SYMNEWFILES mode end time = [%lf], diff = [%lf]\n",
1732 LOGL(LOG_SSENGINE, "SYMNEWFILES mode end\n");
1737 LOGL(LOG_SSENGINE, "HARDDIFFS mode start\n");
1739 #ifdef TIME_PROFILING
1740 get_time_stamp1(); //total time capturing
1742 LOGL(LOG_SSENGINE, "HARDDIFFS mode start time = [%lf]\n",
1746 //LOGL(LOG_SSENGINE, "SYMDIFFS update Index: [%d] \n", ulFileIndex++);
1747 //LOG("Sym Diff file paths: [Linkname - %s] [reference file name- %s][]\n", pFsNode->file_path,pFsNode->patch_name);
1748 ulResult = SS_DeleteFile(pFsNode->file_old_path);
1749 if (ulResult == S_SS_SUCCESS) {
1750 ulResult = SS_HardLink(pFsNode->file_new_path, pFsNode->patch_name);
1751 if (ulResult != S_SS_SUCCESS) {
1752 LOGE("SS_HardLink Failed, Linkname:[%s], reference file name, index = [%d]:[%s]\n",
1753 pFsNode->file_new_path, ulFileIndex, pFsNode->patch_name);
1756 LOGE("Removing old hardlink Failed, result = [%d], index = [%d]\n", ulResult, ulFileIndex);
1757 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1760 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1761 pFsNode = pFsNode->nextnode;
1764 LOGL(LOG_SSENGINE, "HARDDIFFS : Total index = [%d]\n",
1766 #ifdef TIME_PROFILING
1767 get_time_stamp1(); //total time capturing
1770 "HARDDIFFS mode end time = [%lf], diff = [%lf]\n",
1773 LOGL(LOG_SSENGINE, "HARDDIFFS mode end\n");
1778 LOGL(LOG_SSENGINE, "HARDNEWFILES mode start\n");
1780 #ifdef TIME_PROFILING
1781 get_time_stamp1(); //total time capturing
1784 "HARDNEWFILES mode start time = [%lf]\n", t1);
1786 fs_params *head_node = pFsNode;
1788 //LOGL(LOG_SSENGINE, "SYMNEWS update Index: [%d] \n", ulFileIndex++);
1789 LOGL(LOG_SSENGINE, "Hardlink New file paths: [Linkname - %s] [reference file name- %s][]\n",
1790 head_node->file_old_path, head_node->patch_name);
1791 ulResult = SS_HardLink(head_node->file_old_path, head_node->patch_name);
1792 if (ulResult == E_SS_FAILURE) {
1793 LOGE("Link Failed, result = [%d], index = [%d]\n", ulResult, ulFileIndex);
1794 SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
1797 SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
1798 head_node = head_node->nextnode;
1801 LOGL(LOG_SSENGINE, "HARDNEWFILES : Total index = [%d]\n",
1804 #ifdef TIME_PROFILING
1805 get_time_stamp1(); //total time capturing
1808 "HARDNEWFILES mode end time = [%lf], diff = [%lf]\n",
1811 LOGL(LOG_SSENGINE, "HARDNEWFILES mode end\n");
1821 #ifdef MEM_PROFILING
1826 *********************************************************************************
1828 *********************************************************************************
1831 * This is the API exposed from the engine to update FS.
1836 * @return returns S_SS_SUCCESS
1837 * E_SS_FAILURE in case of error
1839 *********************************************************************************
1842 int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS)
1844 int ulResult = S_SS_SUCCESS;
1845 int last_update_status = 0;
1847 fs_list *head_ptr_node = NULL;
1848 char new_patch_path[SS_MAX_FILE_PATH] = {
1851 char status_path[MAX_FILE_PATH];
1852 snprintf(status_path, MAX_FILE_PATH, "%s/%s",ua_dataSS->update_data->ua_delta_folder, SS_UPDATE_STATUS_PATH);
1855 return E_SS_BAD_PARAMS; // Set error ??
1856 head_ptr_node = headptr_list;
1858 if (!head_ptr_node) { //in case of power failure, try rebilding nodes again
1859 SS_FSVerifyPartition(ua_dataSS);
1860 head_ptr_node = headptr_list;
1864 return E_SS_FSBADNODES;
1866 SS_GetPartition_LocDetails(ua_dataSS);
1868 LOGL(LOG_SSENGINE, "FS Update Entry\n");
1870 #ifdef POWER_FAIL_TEST
1871 int fail_test_flag = 0;
1872 fail_test_flag = SS_Get_power_fail_flag();
1873 LOGL(LOG_SSENGINE, "fail_test_flag: [%d]\n", fail_test_flag);
1876 if(SS_Get_last_update_status(&last_update_status, &del_type, status_path) == -1)
1877 LOGE("SS_Get_last_update_status failed!!\n");
1879 LOGL(LOG_SSENGINE, "last_update_status: [%d], del_type: [%d]\n", last_update_status, del_type);
1881 // for now, we don't want to read last del_type as the logic doesn't work
1884 if (head_ptr_node->del_ref == NULL) {
1885 LOGL(LOG_SSENGINE, "No DEL header\n");
1886 } else if (ulResult == S_SS_SUCCESS) {
1887 if (del_type < DELETES) {
1888 ulResult = SS_FSUpdateFile(DELETES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->del_ref,
1889 ua_dataSS->update_delta->ua_patch_path);
1890 if (ulResult == S_SS_SUCCESS) {
1891 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - DELETES success!!\n");
1893 #ifdef POWER_FAIL_TEST
1894 if (fail_test_flag < DELETES) {
1895 if (SS_Do_Power_fail_test(DELETES) == E_SS_FAILURE) {
1896 LOGE("SS_Do_Power_fail_test failed!!\n");
1900 SS_Set_last_update_status(0, DELETES, status_path);
1903 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - DELETES already applied!!\n");
1907 if (head_ptr_node->dif_ref == NULL) {
1908 LOGL(LOG_SSENGINE, "No DIFF header\n");
1909 } else if (ulResult == S_SS_SUCCESS) {
1911 SS_FSUpdateFile(DIFFS, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->dif_ref,
1912 ua_dataSS->update_delta->ua_patch_path);
1913 if (ulResult == S_SS_SUCCESS) {
1914 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - DIFFS success!!\n");
1915 #ifdef POWER_FAIL_TEST
1916 if (fail_test_flag < DIFFS) {
1917 if (SS_Do_Power_fail_test(DIFFS) == E_SS_FAILURE) {
1918 LOGE("SS_Do_Power_fail_test failed!!\n");
1925 if (head_ptr_node->move_ref == NULL) {
1926 LOGL(LOG_SSENGINE, "No MOVE header\n");
1927 } else if (ulResult == S_SS_SUCCESS) {
1928 if (del_type < MOVES) {
1930 SS_FSUpdateFile(MOVES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->move_ref,
1931 ua_dataSS->update_delta->ua_patch_path);
1932 if (ulResult == S_SS_SUCCESS) {
1933 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - MOVES success!!\n");
1934 #ifdef POWER_FAIL_TEST
1935 if (fail_test_flag < MOVES) {
1936 if (SS_Do_Power_fail_test(MOVES) == E_SS_FAILURE) {
1937 LOGE("SS_Do_Power_fail_test failed!!\n");
1941 SS_Set_last_update_status(0, MOVES, status_path);
1944 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - MOVES already applied!!\n");
1948 if (head_ptr_node->del_ref == NULL) {
1949 LOGL(LOG_SSENGINE, "No DEL header\n");
1950 } else if (ulResult == S_SS_SUCCESS) {
1951 if (del_type < DELETE_END) {
1952 ulResult = SS_FSUpdateFile(DELETE_END, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->del_ref,
1953 ua_dataSS->update_delta->ua_patch_path);
1954 if (ulResult == S_SS_SUCCESS) {
1955 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - DELETE_END success!!\n");
1956 #ifdef POWER_FAIL_TEST
1957 if (fail_test_flag < DELETE_END) {
1958 if (SS_Do_Power_fail_test(DELETE_END) == E_SS_FAILURE) {
1959 LOGE("SS_Do_Power_fail_test failed!!\n");
1963 SS_Set_last_update_status(0, DELETE_END, status_path);
1966 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - DELETE_END already applied!!\n");
1970 if (ulResult == S_SS_SUCCESS) {
1971 //new file extraction start
1972 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
1973 LOGL(LOG_SSENGINE, "File path created to extract new files : [%s]\n", new_patch_path);
1975 SS_FSUpdateFile(NEWFILES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->new_ref, new_patch_path);
1976 //new file extraction end
1977 if (ulResult == S_SS_SUCCESS) {
1978 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - NEWFILES success!!\n");
1982 if (head_ptr_node->sym_difref == NULL) {
1983 LOGL(LOG_SSENGINE, "No SYMDIFF header\n");
1984 } else if (ulResult == S_SS_SUCCESS) {
1986 SS_FSUpdateFile(SYMDIFFS, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->sym_difref,
1987 ua_dataSS->update_delta->ua_patch_path);
1988 if (ulResult == S_SS_SUCCESS) {
1989 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - SYMDIFFS success!!\n");
1990 #ifdef POWER_FAIL_TEST
1991 if (fail_test_flag < SYMDIFFS) {
1992 if (SS_Do_Power_fail_test(SYMDIFFS) == E_SS_FAILURE) {
1993 LOGE("SS_Do_Power_fail_test failed!!\n");
2000 if (head_ptr_node->sym_newref == NULL) {
2001 LOGL(LOG_SSENGINE, "No SYMNEW header\n");
2002 } else if (ulResult == S_SS_SUCCESS) {
2004 SS_FSUpdateFile(SYMNEWFILES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->sym_newref,
2005 ua_dataSS->update_delta->ua_patch_path);
2006 if (ulResult == S_SS_SUCCESS) {
2007 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - SYMNEWFILES success!!\n");
2008 #ifdef POWER_FAIL_TEST
2009 if (fail_test_flag < SYMNEWFILES) {
2010 if (SS_Do_Power_fail_test(SYMNEWFILES) == E_SS_FAILURE) {
2011 LOGE("SS_Do_Power_fail_test failed!!\n");
2018 if (head_ptr_node->hard_newref == NULL) {
2019 LOGL(LOG_SSENGINE, "No HARDNEW header\n");
2020 } else if (ulResult == S_SS_SUCCESS) {
2022 SS_FSUpdateFile(HARDNEWFILES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->hard_newref,
2023 ua_dataSS->update_delta->ua_patch_path);
2024 if (ulResult == S_SS_SUCCESS) {
2025 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - HARDNEWFILES success!!\n");
2026 #ifdef POWER_FAIL_TEST
2027 if (fail_test_flag < HARDNEWFILES) {
2028 if (SS_Do_Power_fail_test(HARDNEWFILES) == E_SS_FAILURE) {
2029 LOGE("SS_Do_Power_fail_test failed!!\n");
2036 if (head_ptr_node->hard_difref == NULL) {
2037 LOGL(LOG_SSENGINE, "No HARDDIFF header\n");
2038 } else if (ulResult == S_SS_SUCCESS) {
2040 SS_FSUpdateFile(HARDDIFFS, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->hard_difref,
2041 ua_dataSS->update_delta->ua_patch_path);
2042 if (ulResult == S_SS_SUCCESS) {
2043 LOGL(LOG_SSENGINE, "SS_FSUpdateFile - HARDDIFFs success!!\n");
2044 #ifdef POWER_FAIL_TEST
2045 if (fail_test_flag < HARDDIFFS) {
2046 if (SS_Do_Power_fail_test(HARDDIFFS) == E_SS_FAILURE) {
2047 LOGE("SS_Do_Power_fail_test failed!!\n");
2054 if (ulResult == S_SS_SUCCESS) {
2055 ulResult = SS_FSSetAttributes(ua_dataSS);
2057 SS_FSSetAttributes(ua_dataSS); // To prevent boot failures by smack.
2064 if (ulResult == S_SS_SUCCESS) {
2065 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
2066 SS_Set_last_update_status(0, DEL_TYPE_MAX, status_path);
2069 LOGL(LOG_SSENGINE, "FS update Complete\n");
2070 #ifdef MEM_PROFILING
2071 LOGL(LOG_SSENGINE, "Stats are : Cur Max : [%d] Global Max : [%d]\n", cur_mem, max_mem);
2073 #ifdef POWER_FAIL_TEST
2074 unlink(SS_POWER_FAIL_TEST_FLAG);
2076 if (ulResult == S_SS_SUCCESS)
2079 return SS_GetUpgradeState();
2083 *********************************************************************************
2085 *********************************************************************************
2088 * This is the API exposed from the engine to update FS.
2089 * FS entry function for updating FS partition. Should be invoked only after verification of the partition
2092 * @param Requires common data structure having all details & Partition Index.
2093 * (Used for getting right NODES information that built during verification)
2094 * (Configuration, Delta info, Partition Info, UI link , Kind of operation.(Verify or Updates))
2096 * @return returns S_SS_SUCCESS
2097 * E_SS_FAILURE in case of error
2099 *********************************************************************************
2101 size_t SS_FSAvailiableFreeSpace(char *block_name)
2107 aFile = setmntent("/proc/mounts", "r");
2108 if (aFile == NULL) {
2109 LOGE("setmntent error\n");
2110 return E_SS_FAILURE;
2112 while (NULL != (ent = getmntent(aFile))) {
2113 if (strcmp(ent->mnt_fsname, block_name) == 0) {
2114 if (statfs(ent->mnt_dir, &sb) == 0)
2115 LOGL(LOG_SSENGINE, "Total free space = %" PRIu64 ", blocks free = %" PRIu64 "\n", sb.f_bsize * sb.f_bavail, sb.f_bfree);
2119 return ((long long)sb.f_bsize * (long long)sb.f_bavail >= (long long)SIZE_4GB) ? SIZE_4GB : sb.f_bsize * sb.f_bavail ;
2122 int SS_FSVerifyPartition(ua_dataSS_t * ua_dataSS)
2124 int ulResult = S_SS_SUCCESS;
2126 LOGE("Wrong Param for fs verification\n");
2127 SS_SetUpgradeState(E_SS_BAD_PARAMS);
2128 return E_SS_FAILURE;
2131 #ifdef MEM_PROFILING
2132 if (!mem_profiling_start)
2133 if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
2134 return E_SS_FAILURE;
2136 SS_GetPartition_LocDetails(ua_dataSS);
2137 LOGL(LOG_SSENGINE, "FS Verification Start\n");
2138 if (ua_dataSS->ua_operation == UI_OP_SCOUT)
2139 gvalid_session = 1; // (shd b true if called during verification)
2140 headptr_list = SS_FSBuildNodes(ua_dataSS);
2141 #ifdef TIME_PROFILING
2142 LOGL(LOG_SSENGINE, "fast_tar_get_item_size_time :[%lf]\n", fast_tar_get_item_size_time);
2143 LOGL(LOG_SSENGINE, "SS_LoadFile_time :[%lf]\n", SS_LoadFile_time);
2144 LOGL(LOG_SSENGINE, "SS_FSBuildNodes_time :[%lf]\n", SS_FSBuildNodes_time);
2146 if (!headptr_list) {
2147 LOGE("FS Verification Failed\n");
2149 ulResult = E_SS_FAILURE;
2152 if (ulResult == S_SS_SUCCESS)
2155 return SS_GetUpgradeState();
2158 //Should check if space is available????
2159 int SS_BackupSource(const char *source_filename, char *backup_path)
2161 int ret = E_SS_FAILURE;
2163 if (source_filename) {
2164 ret = (int)SS_CopyFile(source_filename, backup_path);
2165 if (ret != S_SS_SUCCESS) {
2166 LOGE("failed to back up source file Error [%d]\n", ret);
2167 SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
2173 int SS_BackupSourceClear(char *backup_path)
2175 int ret = E_SS_FAILURE;
2176 ret = (int)SS_DeleteFile(backup_path);
2177 if (ret != S_SS_SUCCESS) {
2178 LOGE("failed to delete BACKUP file\n");
2179 SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
2184 int SS_PatchSourceClear(char *patch_path)
2186 int ret = E_SS_FAILURE;
2187 ret = (int)SS_DeleteFile(patch_path);
2188 if (ret != S_SS_SUCCESS) {
2189 LOGE("failed to delete PATCHFILE file\n");
2190 SS_SetUpgradeState(E_SS_PATCHFILE_DEL_ERROR);
2195 long SS_GetUPIVersion(unsigned char *ver_str)
2198 strncpy((char *)ver_str, SS_TOTA_VERSION, MAX_PATH);
2199 #ifdef MEM_PROFILING
2200 if (!mem_profiling_start)
2201 if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
2202 LOGE("Unable to start Memory_Profiling\n");
2204 return S_SS_SUCCESS;//wgid: 2456
2206 return E_SS_FAILURE;