コード例 #1
0
void create_default_settings(void) {
    FILE    *   ini ;

	if(ini = fopen_path(COTSETTINGS, "r")) {
		fclose(COTSETTINGS);
		remove(COTSETTINGS);
	}

    ini = fopen_path(COTSETTINGS, "w");
    fprintf(ini,
    ";\n"
    "; COT Settings INI\n"
    ";\n"
    "\n"
    "[Settings]\n"
    "Theme = hydro ;\n"
    "SDTheme = 0;\n"
    "ORSReboot = 0 ;\n"
    "ORSWipePrompt = 1 ;\n"
    "BackupPrompt = 1 ;\n"
    "SignatureCheckEnabled = 1 ;\n"
    "BackupFormat = 0 ;\n"
    "maxX = 0 ;\n"
    "maxY = 0 ;\n"
    "touchY = 0 ;\n"
    "Language = en ;\n"
    "\n");
    fclose(ini);
    // is the first_boot flag already set?
    if (first_boot == 0) {
		// if not, set it!
		first_boot = 1;
	}
}
コード例 #2
0
// clear the recovery command and prepare to boot a (hopefully working) system,
// copy our log file to cache as well (for the system to read), and
// record any intent we were asked to communicate back to the system.
// this function is idempotent: call it as many times as you like.
static void
finish_recovery(const char *send_intent) {
    // By this point, we're ready to return to the main system...
    if (send_intent != NULL) {
        FILE *fp = fopen_path(INTENT_FILE, "w");
        if (fp == NULL) {
            LOGE("Can't open %s\n", INTENT_FILE);
        } else {
            fputs(send_intent, fp);
            check_and_fclose(fp, INTENT_FILE);
        }
    }

    // Save the locale to cache, so if recovery is next started up
    // without a --locale argument (eg, directly from the bootloader)
    // it will use the last-known locale.
    if (locale != NULL) {
        LOGI("Saving locale \"%s\"\n", locale);
        FILE* fp = fopen_path(LOCALE_FILE, "w");
        fwrite(locale, 1, strlen(locale), fp);
        fflush(fp);
        fsync(fileno(fp));
        check_and_fclose(fp, LOCALE_FILE);
    }

    // Copy logs to cache so the system can find out what happened.
    copy_log_file(TEMPORARY_LOG_FILE, LOG_FILE, true);
    copy_log_file(TEMPORARY_LOG_FILE, LAST_LOG_FILE, false);
    copy_log_file(TEMPORARY_INSTALL_FILE, LAST_INSTALL_FILE, false);
    chmod(LOG_FILE, 0600);
    chown(LOG_FILE, 1000, 1000);   // system user
    chmod(LAST_LOG_FILE, 0640);
    chmod(LAST_INSTALL_FILE, 0644);

    // Reset to normal system boot so recovery won't cycle indefinitely.
    struct bootloader_message boot;
    memset(&boot, 0, sizeof(boot));
    set_bootloader_message(&boot);

    // Remove the command file, so recovery won't repeat indefinitely.
    if (ensure_path_mounted(COMMAND_FILE) != 0 ||
        (unlink(COMMAND_FILE) && errno != ENOENT)) {
        LOGW("Can't unlink %s\n", COMMAND_FILE);
    }

    ensure_path_unmounted(CACHE_ROOT);
    sync();  // For good measure.
}
コード例 #3
0
ファイル: install.cpp プロジェクト: JasonHJ/android-6.0.0_r1
int
install_package(const char* path, bool* wipe_cache, const char* install_file,
                bool needs_mount)
{
    modified_flash = true;

    FILE* install_log = fopen_path(install_file, "w");
    if (install_log) {
        fputs(path, install_log);
        fputc('\n', install_log);
    } else {
        LOGE("failed to open last_install: %s\n", strerror(errno));
    }
    int result;
    if (setup_install_mounts() != 0) {
        LOGE("failed to set up expected mounts for install; aborting\n");
        result = INSTALL_ERROR;
    } else {
        result = really_install_package(path, wipe_cache, needs_mount);
    }
    if (install_log) {
        fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log);
        fputc('\n', install_log);
        fclose(install_log);
    }
    return result;
}
コード例 #4
0
// clear the recovery command and prepare to boot a (hopefully working) system,
// copy our log file to cache as well (for the system to read), and
// record any intent we were asked to communicate back to the system.
// this function is idempotent: call it as many times as you like.
static void
finish_recovery(const char *send_intent) {
    // By this point, we're ready to return to the main system...
    if (send_intent != NULL) {
        FILE *fp = fopen_path(INTENT_FILE, "w");
        if (fp == NULL) {
            LOGE("Can't open %s\n", INTENT_FILE);
        } else {
            fputs(send_intent, fp);
            check_and_fclose(fp, INTENT_FILE);
        }
    }

    // Copy logs to cache so the system can find out what happened.
    copy_log_file(LOG_FILE, true);
    copy_log_file(LAST_LOG_FILE, false);
    chmod(LAST_LOG_FILE, 0640);

    // Reset to normal system boot so recovery won't cycle indefinitely.
    struct bootloader_message boot;
    memset(&boot, 0, sizeof(boot));
    set_bootloader_message(&boot);

    // Remove the command file, so recovery won't repeat indefinitely.
    if (ensure_path_mounted(COMMAND_FILE) != 0 ||
        (unlink(COMMAND_FILE) && errno != ENOENT)) {
        LOGW("Can't unlink %s\n", COMMAND_FILE);
    }

    sync();  // For good measure.
}
コード例 #5
0
ファイル: install.c プロジェクト: Shoxxy/PhilMeHd7aio
int
install_package(const char* path, int* wipe_cache, const char* install_file)
{
    FILE* install_log = fopen_path(install_file, "w");
    if (install_log) {
        fputs(path, install_log);
        fputc('\n', install_log);
    } else {
        LOGE("failed to open last_install: %s\n", strerror(errno));
    }
    int result;
    if (strstr(path, AROMA_FM_PATH) == NULL && setup_install_mounts() != 0) {
        // do not umount any partition when starting up aroma file manager from default location
        // in some devices, aroma have trouble mounting /system and /data if they are unmounted at this stage
        LOGE("failed to set up expected mounts for install; aborting\n");
        result = INSTALL_ERROR;
    } else {
        result = really_install_package(path, wipe_cache);
    }

#ifdef ENABLE_LOKI
    if (result == INSTALL_SUCCESS && loki_support_enabled() > 0) {
        ui_print("Checking if loki-fying is needed\n");
        result = loki_check();
    }
#endif

    if (install_log) {
        fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log);
        fputc('\n', install_log);
        fclose(install_log);
    }

    return result;
}
コード例 #6
0
int get_amss_location(const char* amss_path_name)
{
    FILE* fp;
    int i = 0;

    fp = fopen_path(amss_path_name, "r");

    if (fp == NULL)
    {
        LOGI("Failed to open %s\n",
             amss_path_name);
    }
    else
    {
        fclose(fp);
    }

    if (access(amss_path_name, F_OK) != 0) {
        LOGI("amss image does not exist %s\n", amss_path_name);
        return -1;
    }

    LOGI("amss image path name: %s\n", amss_path_name);

    return 0;
}
コード例 #7
0
void update_cot_settings(void) {
    FILE    *   ini ;
	ini = fopen_path(COTSETTINGS, "w");
	fprintf(ini, ";\n; COT Settings INI\n;\n\n[Settings]\nTheme = %s ;\nSDTheme = %i;\nORSReboot = %i ;\nORSWipePrompt = %i ;\nBackupPrompt = %i ;\nSignatureCheckEnabled = %i ;\nBackupFormat = %i ;\nmaxX = %i ;\nmaxY = %i ;\ntouchY = %i ;\nLanguage = %s ;\n\n", currenttheme, is_sd_theme, orsreboot, orswipeprompt, backupprompt, signature_check_enabled, backupfmt, maxX, maxY, touchY, language);
    fclose(ini);
    parse_settings();
}
コード例 #8
0
static int read_buildprop(char **ver)
{
    FILE* b_fp;
    char line[MAX_STRING_LEN];
    char *tmpStr, *saveptr;

    LOGI("read_buildprop.\n");

    b_fp = fopen_path(BUILD_PROP_FILE, "r");
    if(!b_fp)
        return -1;

    while(fgets(line, sizeof(line), b_fp))
    {
        tmpStr = strtok_r(line, "=", &saveptr);
        if(strcmp(tmpStr, BUILD_PROP_NAME) == 0)
        {
           tmpStr = strtok_r(NULL, "=", &saveptr);
           strlcpy(*ver, tmpStr, MAX_STRING_LEN);
           fclose(b_fp);
           return 0;
        }
    }
    fclose(b_fp);
    return -1;

}
コード例 #9
0
int get_amss_backup(const char* amss_path_name1, const char* amss_path_name2)
{
    FILE *fp_read, *fp_write;
    char *buffer;
    unsigned max_size = (256 * 1024);
    unsigned num_read = 0;
    int ret = 0;

    fp_read = fopen_path(amss_path_name1,"rb");
    if (fp_read == NULL) {
        LOGE("Failed to open %s\n",amss_path_name1);
        return -1;
    }

    fp_write = fopen_path(amss_path_name2,"wb+");
    if (fp_write == NULL) {
        LOGE("Failed to open %s\n",amss_path_name2);
        fclose(fp_read);
        return -1;
    }
    buffer = (char *) malloc(sizeof(char)*max_size);
    if (buffer == NULL) {
        LOGE("Failed to allocate buffer\n");
        fclose(fp_read);
        fclose(fp_write);
        return -1;
    }
    while (!feof(fp_read)) {
           if ((num_read = fread(buffer, 1, max_size, fp_read)) < 0) {
               LOGE("Failed to read from file :%s\n",amss_path_name1);
               ret = -1;
               goto fail;
           }
           if(fwrite(buffer, 1, num_read, fp_write) < 0) {
               LOGE("Failed to write to file :%s\n",amss_path_name2);
               ret = -1;
               goto fail;
           }
    }

fail:
    fclose(fp_read);
    fclose(fp_write);
    free(buffer);
    return ret;
}
コード例 #10
0
ファイル: recovery.c プロジェクト: xwliu/open-ivi.MX53
int update_radioCFG()
{
	char *cmd_buf[256];
	char *radioCFG_name = "/sdcard/tractor/radio_conf.xml";
	FILE *fp;
	fp = fopen_path(radioCFG_name,"rb");
	if(NULL == fp) {
		printf("no radio_conf\n\r");
		return INSTALL_ERROR;
	}
	umount("/dev/block/mmcblk0p6");
	if(mount("/dev/block/mmcblk0p6", "/firmware", "ext4",
		MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) {
		printf("mount firmware failure\n");
	}
	fp = fopen_path("/firmware/misc/","r");
	if(fp == NULL) {
		sprintf(buf_cmd, "/system/bin/busybox mkdir /firmware/misc/");
		system(buf_cmd);
		printf("%s\n\r",buf_cmd);
		sprintf(buf_cmd, "/system/bin/busybox mkdir /firmware/misc/radioplayer/");
		system(buf_cmd);
		printf("%s\n\r",buf_cmd);
	} else {
		fp = fopen_path("/firmware/misc/radioplayer/","r");
		if(fp == NULL) {
			sprintf(buf_cmd, "/system/bin/busybox mkdir /firmware/misc/radioplayer/");
			system(buf_cmd);
			printf("%s\n\r",buf_cmd);
		} else {
			sprintf(buf_cmd, "/system/bin/busybox rm -rf /firmware/misc/radioplayer/radio_conf.xml");
			system(buf_cmd);
			printf("%s\n\r",buf_cmd);
		}
	}
	copy_file("/sdcard/tractor/radio_conf.xml", "/firmware/misc/radioplayer/radio_conf.xml", 1 | 4 | 8 );
	return INSTALL_SUCCESS;
}
コード例 #11
0
ファイル: emflexsup.c プロジェクト: Rajesh-Veeranki/MACEK
int	yyincl(char *fn, int fil) {
	char		*s;

	DEBUG(CURDLEV+1,"Going to include (ptr=%d) %s \'%s\'.\n",include_stack_ptr,fil?"file":"string",fn);
	if (include_stack_ptr>=MAX_INCLUDE_DEPTH || include_stack_ptr<-MAX_INCLUDE_DEPTH) {
		PROGERROR("Includes are nested too deeply! %d",include_stack_ptr);
		exit(-1);
	}
	if (include_stack_ptr<0) {
		include_stack_ptr = -1;	 include_app = 0;
		inpfile = NULL;  include_stack_file[0] = NULL;
	}
			/* opens the given include file for reading */
	if (fil) {
		if (include_stack_ptr>0)	/* (tries also the subdir of the previous include) */
			s = fdir_extract(include_stack_fn[include_stack_ptr-1]);
		else  s = NULL;
		yyin = fopen_path(fn,"r",frame_path_read,s,frame_extension);
		//********* add stdin as an input "-" (interactive input) ........
		if (!yyin) {
			LERROR("Cannot open include file \'%s\'!",fn);
			return -1;
		}
		if (!FRNAME(curframe)) {
			frame_setname(curframe,s=fname_extract(fn));
			FREE(s);	/* (this s is a private copy of the string) */
		}
	}
	if (include_stack_ptr>=0) {	/* stores the current buffer, and opens a new buffer */
		include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
	}
	if (fil) {
		yy_switch_to_buffer(yy_create_buffer(yyin,YY_BUF_SIZE));
		if (include_stack_ptr+1>=0)  include_stack_file[include_stack_ptr+1] = yyin;
	} else {
		yy_scan_string(fn);
		if (include_stack_ptr+1>=0)  include_stack_file[include_stack_ptr+1] = NULL;
	}
	if (include_stack_ptr>=0) {	/* stores the whole current state on the stack */
		yy_push_state(INITIAL);
		include_stack_fn[include_stack_ptr] = inpfile;
		include_stack_ln[include_stack_ptr] = inpline;
	}
	inpfile = MSTRDUP(fn);	/* (freed in yywrap()) */
	inpline = 1;
	include_stack_ptr++;
	inpspecial = !fil;	/* whether special-lines should apply to this include - see SPECMATRIXLINE */
	return 0;
}
コード例 #12
0
void create_default_settings(void) {
    FILE    *   ini ;

	if(ini = fopen_path(COTSETTINGS, "r")) {
		fclose(COTSETTINGS);
		remove(COTSETTINGS);
	}

    ini = fopen_path(COTSETTINGS, "w");
    fprintf(ini,
    ";\n"
    "; COT Settings INI\n"
    ";\n"
    "\n"
    "[Settings]\n"
    "Theme = hydro ;\n"
    "ORSReboot = 0 ;\n"
    "ORSWipePrompt = 1 ;\n"
    "BackupPrompt = 1 ;\n"
    "SignatureCheckEnabled = 1 ;\n"
    "Language = en ;\n"
    "\n");
    fclose(ini);
}
コード例 #13
0
ファイル: read_pcm.c プロジェクト: fzahari/ParFit
/* ============================================================ */
void rdfile(int mode, int isub)
{
     if (mode == -1)
        fclose(pcminfile);
     else if (mode == 0)
     {
        pcminfile = fopen_path(Openbox.path,Openbox.fname, "r");
         
        if (pcminfile == NULL)
        {
                message_alert("Error Opening PCM file","Error");
                return;
        }
     } else
        rdpcm(mode,isub);
}
コード例 #14
0
static int get_deltaupdate_recoverycount(void)
{
    FILE* f;
    int len, num;
    char* buf;

    f = fopen_path(NUM_OF_RECOVERY, "r");
    if(f == NULL)
    {
       LOGI("Error opening recovery count file. Ignore.\n");
       return 0;
    }

    fseek(f, 0, SEEK_END);
    len = ftell(f);
    buf = malloc(len+1);
    if (buf == NULL) {
        LOGI("Failed to allocate buffer\n");
        return 0;
    }
    memset(buf,0x0,len+1);
    fseek(f, 0, SEEK_SET);
    fread(buf, sizeof(char), len, f);
    check_and_fclose(f,NUM_OF_RECOVERY);

    if ((buf = strstr((const char*)buf, "numRecovery")) == NULL)
    {
        LOGI("Recovery count string doesn't match.Ignore.\n");
    }
    else
    {
        buf += 11;
        if ((buf = strstr((const char*)buf, "=")) == NULL)
        {
            LOGI("Invalid recovery count value. Ignore.\n");
        }
        else
        {
            buf += 1;
            buf = (char*)skip_whitespaces((const char*)buf);
            num = atoi((const char*)buf);
            return num;
        }
    }
    return 0;
}
コード例 #15
0
ファイル: recovery.c プロジェクト: xwliu/open-ivi.MX53
int device_burn_data_if_exist(){
	char* copy = NULL;
	int result = 0;
	FILE *fp = fopen_path(RECOVERY_FILE, "r");
	if(fp == NULL){
		//LOGE("cant find the RECOVERY_FILE:%s\n", RECOVERY_FILE);
		return INSTALL_NOT_EXISTED;	   	
	}
	check_and_fclose(fp,RECOVERY_FILE);
//	printf("check auto Burning update.zip in data tractor..\n");
	//copy = copy_sideloaded_package(RECOVERY_FILE);
	//printf("\n burn [%s][%s] ...\n", RECOVERY_FILE, copy);			
	if (RECOVERY_FILE) {
		ui_set_burning_type(BURNING_TYPE_SYSTEM);
		ui_set_burning_status(BURNING_SEEKBAR_0);
		ui_set_burning_system();
		erase_volume("/data");
		erase_firmware_app();
		result = install_package(RECOVERY_FILE);
		copy_app_2_data();
		remove_logo_config_file();
#if 0
		if(result == INSTALL_SUCCESS){
			FILE* fp_done = fopen("/sdcard/tractor/skip","w");
			if(fp_done == NULL){
				LOGE("Error to disable auto burn\n");
				result = INSTALL_ERROR;
			}else{
				char buffer[16] = {0xFF};
				fwrite(buffer, 1, 16, fp_done);
				fclose(fp_done);
				printf("Burning Done! Disable auto recovery burn\n");
				result = INSTALL_SUCCESS;
			}
		}
#endif
	} else {
		result = INSTALL_ERROR;
	}
	while(system_update_end == 0) {
		//printf("waiting thread is end");
		usleep(50000);
	}
	return result;
}
コード例 #16
0
ファイル: install.cpp プロジェクト: Besik13/iq450_H2_mt6589
int
install_package(const char* path, int* wipe_cache, const char* install_file)
{
    FILE* install_log = fopen_path(install_file, "w");
    if (install_log) {
        fputs(path, install_log);
        fputc('\n', install_log);
    } else {
        LOGE("failed to open last_install: %s\n", strerror(errno));
    }
    int result = really_install_package(path, wipe_cache);
    if (install_log) {
        fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log);
        fputc('\n', install_log);
        fclose(install_log);
    }
    return result;
}
コード例 #17
0
static void
load_locale_from_cache() {
    FILE* fp = fopen_path(LOCALE_FILE, "r");
    char buffer[80];
    if (fp != NULL) {
        fgets(buffer, sizeof(buffer), fp);
        int j = 0;
        unsigned int i;
        for (i = 0; i < sizeof(buffer) && buffer[i]; ++i) {
            if (!isspace(buffer[i])) {
                buffer[j++] = buffer[i];
            }
        }
        buffer[j] = 0;
        locale = strdup(buffer);
        check_and_fclose(fp, LOCALE_FILE);
    }
}
コード例 #18
0
int
install_package(const char* path)
{
    FILE* install_log = fopen_path(LAST_INSTALL_FILE, "w");
    if (install_log) {
        fputs(path, install_log);
        fputc('\n', install_log);
    } else {
        LOGE("failed to open last_install: %s\n", strerror(errno));
    }
    int result = really_install_package(path);
    if (install_log) {
        fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log);
        fputc('\n', install_log);
        fclose(install_log);
        chmod(LAST_INSTALL_FILE, 0644);
    }
    return result;
}
コード例 #19
0
static void file_to_ui(const char* fn) {
    FILE *fp = fopen_path(fn, "re");
    if (fp == NULL) {
        ui->Print("  Unable to open %s: %s\n", fn, strerror(errno));
        return;
    }
    char line[1024];
    int ct = 0;
    redirect_stdio("/dev/null");
    while(fgets(line, sizeof(line), fp) != NULL) {
        ui->Print("%s", line);
        ct++;
        if (ct % 30 == 0) {
            // give the user time to glance at the entries
            ui->WaitKey();
        }
    }
    redirect_stdio(TEMPORARY_LOG_FILE);
    fclose(fp);
}
コード例 #20
0
static int get_deltaupdate_status(void)
{
    FILE* f;
    int len;
    char* buf;
    int i, num_index;

    LOGI("Checking delta update status...\n");

    f = fopen_path(DELTA_UPDATE_STATUS_FILE, "r");
    if(f == NULL)
    {
       LOGI("fopen error(%s)\n",DELTA_UPDATE_STATUS_FILE);
       return -1;
    }

    fseek(f, 0, SEEK_END);
    len = ftell(f);
    buf = malloc(len+1);
    if (buf == NULL) {
        LOGI("Failed to allocate buffer\n");
        return -1;
    }
    memset(buf,0x0,len+1);
    fseek(f, 0, SEEK_SET);
    fread(buf, sizeof(char), len, f);
    check_and_fclose(f,DELTA_UPDATE_STATUS_FILE);

    num_index = sizeof(DELTA_UPDATE_STATUS_DB)/sizeof(deltaupdate_config_st);

    for (i = 0; i < num_index; i++)
    {
        if (strstr((const char*)buf, DELTA_UPDATE_STATUS_DB[i].str)!=NULL)
        {
            return DELTA_UPDATE_STATUS_DB[i].idx;
        }
    }

    LOGI("NO UPDATE SET\n");
    return NO_DELTA_UPDATE;
}
コード例 #21
0
static void
copy_log_file(const char* source, const char* destination, int append) {
    FILE *log = fopen_path(destination, append ? "a" : "w");
    if (log == NULL) {
        LOGE("Can't open %s\n", destination);
    } else {
        FILE *tmplog = fopen(source, "r");
        if (tmplog != NULL) {
            if (append) {
                fseek(tmplog, tmplog_offset, SEEK_SET);  // Since last write
            }
            char buf[4096];
            while (fgets(buf, sizeof(buf), tmplog)) fputs(buf, log);
            if (append) {
                tmplog_offset = ftell(tmplog);
            }
            check_and_fclose(tmplog, source);
        }
        check_and_fclose(log, destination);
    }
}
コード例 #22
0
ファイル: recovery.c プロジェクト: xwliu/open-ivi.MX53
int update_overridekey()
{
	char *cmd_buf[256];
	char *overridekey_name = "/sdcard/tractor/overridekey.conf";
	FILE *fp;
	fp = fopen_path(overridekey_name,"rb");
	if(NULL == fp) {
		printf("no overridekey\n\r");
		return INSTALL_ERROR;
	}
	umount("/dev/block/mmcblk0p6");
	if(mount("/dev/block/mmcblk0p6", "/firmware", "ext4",
		MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) {
		printf("mount firmware failure\n");
	}
	sprintf(buf_cmd, "/system/bin/busybox rm -rf /firmware/overridekey.conf");
	system(buf_cmd);
	printf("%s\n\r",buf_cmd);
	copy_file("/sdcard/tractor/overridekey.conf", "/firmware/overridekey.conf", 1 | 4 | 8 );
	return INSTALL_SUCCESS;
}
コード例 #23
0
ファイル: recovery.c プロジェクト: xwliu/open-ivi.MX53
int update_tractorprop()
{
	char *cmd_buf[256];
	char *tractor_prop = "/sdcard/tractor/tractor.prop";
	FILE *fp;
	umount("/dev/block/mmcblk0p6");
	if(mount("/dev/block/mmcblk0p6", "/firmware", "ext4",
		MS_NOATIME | MS_NODEV | MS_NODIRATIME, "") < 0) {
		printf("mount firmware failure\n");
	}
	sprintf(buf_cmd, "/system/bin/busybox rm -rf /firmware/tractor.prop");
	system(buf_cmd);
	printf("%s\n\r",buf_cmd);   // Not like key and radio cfg, we will delete the prop file whatever the new file is exist or not...
	fp = fopen_path(tractor_prop,"rb");
	if(NULL == fp) {
		printf("no tractor prop exist\n\r");    // even we have no tractor.prop it is OK think the burn succ
		return INSTALL_SUCCESS;
	}
	copy_file("/sdcard/tractor/tractor.prop", "/firmware/tractor.prop", 1 | 4 | 8 );
	return INSTALL_SUCCESS;
}
コード例 #24
0
static int set_deltaupdate_status(int status, int error_code)
{
    FILE* f;
    char strbuf[64];

    LOGI("Setting delta update status...\n");

    f = fopen_path(DELTA_UPDATE_STATUS_FILE, "w");
    if(f == NULL)
    {
       LOGI("fopen error(%s)\n",DELTA_UPDATE_STATUS_FILE);
       return -1;
    }

    switch(status)
    {
        case START_DELTA_UPDATE:
        case DELTA_UPDATE_IN_PROGRESS:
        case DELTA_UPDATE_SUCCESSFUL:
        case DELTA_UPDATE_FAILED:
            if ((snprintf(strbuf, sizeof(strbuf), "%s %d", DELTA_UPDATE_STATUS_DB[status].str, error_code)) >= sizeof(strbuf)) {
               LOGI("Output Truncated while setting error code\n");
            }
            fwrite(strbuf, sizeof(char), strlen(strbuf), f);
            break;
        default:
            if ((snprintf(strbuf, sizeof(strbuf), "DELTA_NO_UPDATE %d", error_code)) >= sizeof(strbuf)) {
               LOGI("Output Truncated while setting error code\n");
            }
            fwrite(strbuf, sizeof(char), strlen(strbuf), f);
            break;
    }

    LOGI("Delta update status is set to (%s)\n",strbuf);
    check_and_fclose(f,DELTA_UPDATE_STATUS_FILE);
    return 0;
}
コード例 #25
0
void ScreenRecoveryUI::ShowFile(const char* filename) {
    FILE* fp = fopen_path(filename, "re");
    if (fp == nullptr) {
        Print("  Unable to open %s: %s\n", filename, strerror(errno));
        return;
    }

    char** old_text = text_;
    size_t old_text_col = text_col_;
    size_t old_text_row = text_row_;
    size_t old_text_top = text_top_;

    // Swap in the alternate screen and clear it.
    text_ = file_viewer_text_;
    ClearText();

    ShowFile(fp);
    fclose(fp);

    text_ = old_text;
    text_col_ = old_text_col;
    text_row_ = old_text_row;
    text_top_ = old_text_top;
}
コード例 #26
0
static void increment_deltaupdate_recoverycount(void)
{
    FILE* f;
    int num;
    char numbuf[8];
    char strbuf[32];

    num = get_deltaupdate_recoverycount();
    num += 1;
    snprintf(numbuf, sizeof(numbuf), "%d", num);

    memset(strbuf,0x0,sizeof(strbuf));
    strlcpy(strbuf,"numRecovery=",sizeof(strbuf));
    strlcat(strbuf,numbuf,sizeof(strbuf));

    f = fopen_path(NUM_OF_RECOVERY, "w");
    if(f == NULL)
    {
       LOGI("Error Creating file %s\n",NUM_OF_RECOVERY);
       return;
    }
    fwrite(strbuf, sizeof(char), strlen(strbuf), f);
    check_and_fclose(f, NUM_OF_RECOVERY);
}
コード例 #27
0
static int
erase_volume(const char *volume) {
    bool is_cache = (strcmp(volume, CACHE_ROOT) == 0);

    ui->SetBackground(RecoveryUI::ERASING);
    ui->SetProgressType(RecoveryUI::INDETERMINATE);

    saved_log_file* head = NULL;

    if (is_cache) {
        // If we're reformatting /cache, we load any
        // "/cache/recovery/last*" files into memory, so we can restore
        // them after the reformat.

        ensure_path_mounted(volume);

        DIR* d;
        struct dirent* de;
        d = opendir(CACHE_LOG_DIR);
        if (d) {
            char path[PATH_MAX];
            strcpy(path, CACHE_LOG_DIR);
            strcat(path, "/");
            int path_len = strlen(path);
            while ((de = readdir(d)) != NULL) {
                if (strncmp(de->d_name, "last", 4) == 0) {
                    saved_log_file* p = (saved_log_file*) malloc(sizeof(saved_log_file));
                    strcpy(path+path_len, de->d_name);
                    p->name = strdup(path);
                    if (stat(path, &(p->st)) == 0) {
                        // truncate files to 512kb
                        if (p->st.st_size > (1 << 19)) {
                            p->st.st_size = 1 << 19;
                        }
                        p->data = (unsigned char*) malloc(p->st.st_size);
                        FILE* f = fopen(path, "rb");
                        fread(p->data, 1, p->st.st_size, f);
                        fclose(f);
                        p->next = head;
                        head = p;
                    } else {
                        free(p);
                    }
                }
            }
            closedir(d);
        } else {
            if (errno != ENOENT) {
                printf("opendir failed: %s\n", strerror(errno));
            }
        }
    }

    ui->Print("Formatting %s...\n", volume);

    ensure_path_unmounted(volume);
    int result = format_volume(volume);

    if (is_cache) {
        while (head) {
            FILE* f = fopen_path(head->name, "wb");
            if (f) {
                fwrite(head->data, 1, head->st.st_size, f);
                fclose(f);
                chmod(head->name, head->st.st_mode);
                chown(head->name, head->st.st_uid, head->st.st_gid);
            }
            free(head->name);
            free(head->data);
            saved_log_file* temp = head->next;
            free(head);
            head = temp;
        }

        // Any part of the log we'd copied to cache is now gone.
        // Reset the pointer so we copy from the beginning of the temp
        // log.
        tmplog_offset = 0;
        copy_logs();
    }

    return result;
}
コード例 #28
0
// command line args come from, in decreasing precedence:
//   - the actual command line
//   - the bootloader control block (one per line, after "recovery")
//   - the contents of COMMAND_FILE (one per line)
static void
get_args(int *argc, char ***argv) {
    struct bootloader_message boot;
    memset(&boot, 0, sizeof(boot));
    get_bootloader_message(&boot);  // this may fail, leaving a zeroed structure
    stage = strndup(boot.stage, sizeof(boot.stage));

    if (boot.command[0] != 0 && boot.command[0] != 255) {
        LOGI("Boot command: %.*s\n", (int)sizeof(boot.command), boot.command);
    }

    if (boot.status[0] != 0 && boot.status[0] != 255) {
        LOGI("Boot status: %.*s\n", (int)sizeof(boot.status), boot.status);
    }

    // --- if arguments weren't supplied, look in the bootloader control block
    if (*argc <= 1) {
        boot.recovery[sizeof(boot.recovery) - 1] = '\0';  // Ensure termination
        const char *arg = strtok(boot.recovery, "\n");
        if (arg != NULL && !strcmp(arg, "recovery")) {
            *argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
            (*argv)[0] = strdup(arg);
            for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
                if ((arg = strtok(NULL, "\n")) == NULL) break;
                (*argv)[*argc] = strdup(arg);
            }
            LOGI("Got arguments from boot message\n");
        } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) {
            LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery);
        }
    }

    // --- if that doesn't work, try the command file
    if (*argc <= 1) {
        FILE *fp = fopen_path(COMMAND_FILE, "r");
        if (fp != NULL) {
            char *token;
            char *argv0 = (*argv)[0];
            *argv = (char **) malloc(sizeof(char *) * MAX_ARGS);
            (*argv)[0] = argv0;  // use the same program name

            char buf[MAX_ARG_LENGTH];
            for (*argc = 1; *argc < MAX_ARGS; ++*argc) {
                if (!fgets(buf, sizeof(buf), fp)) break;
                token = strtok(buf, "\r\n");
                if (token != NULL) {
                    (*argv)[*argc] = strdup(token);  // Strip newline.
                } else {
                    --*argc;
                }
            }

            check_and_fclose(fp, COMMAND_FILE);
            LOGI("Got arguments from %s\n", COMMAND_FILE);
        }
    }

    // --> write the arguments we have back into the bootloader control block
    // always boot into recovery after this (until finish_recovery() is called)
    strlcpy(boot.command, "boot-recovery", sizeof(boot.command));
    strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery));
    int i;
    for (i = 1; i < *argc; ++i) {
        strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery));
        strlcat(boot.recovery, "\n", sizeof(boot.recovery));
    }
    set_bootloader_message(&boot);
}
コード例 #29
0
static int deltaupdate_pkg_location(char* diff_pkg_path_name)
{
    static char line[MAX_STRING_LEN];
    struct stat status;
    FILE* fp;
    char* tmp_str, saveptr;
    bool found = false;
    int i = 0;

    while (i++ < 3)
    {
        LOGI("fopen_path %d %s\n", i, FOTA_PROP_FILE);
        sleep(1);
        fp = fopen_path(FOTA_PROP_FILE, "r");
        if (fp)
            break;
    }

    if (fp == NULL)
    {
        LOGI("Failed to open %s, use default pkg location:%s\n",
             FOTA_PROP_FILE, DEFAULT_PKG_LOCATION);
        strlcpy(diff_pkg_path_name, DEFAULT_PKG_LOCATION, PATH_MAX);
    }
    else
    {
        while(fgets(line, MAX_STRING_LEN, fp)!=NULL)
        {
            tmp_str = strtok_r(line, "=", &saveptr);
            if(strcmp(tmp_str, PKG_LOCATION_STRING_NAME) == 0)
            {
               tmp_str = strtok_r(NULL, "=\n", &saveptr);
               strlcpy(diff_pkg_path_name, tmp_str, PATH_MAX);
               diff_pkg_path_name = trim_whitespace(diff_pkg_path_name);
               LOGI("Package location: %s\r\n", diff_pkg_path_name);
               found = true;
               break;
            }
        }
        if (!found)
        {
            LOGI("Package location is not defined in %s. Use default location: %s\n",
            FOTA_PROP_FILE, DEFAULT_PKG_LOCATION );
            strlcpy(diff_pkg_path_name, DEFAULT_PKG_LOCATION, PATH_MAX);
        }
        fclose(fp);
    }

    if (ensure_path_mounted(diff_pkg_path_name) != 0) {
        LOGI("Cannot mount %s\n", diff_pkg_path_name);
        return -1;
    }

    strlcat(diff_pkg_path_name, "/", PATH_MAX);
    strlcat(diff_pkg_path_name, DIFF_PACKAGE_NAME, PATH_MAX);

    if (access(diff_pkg_path_name, F_OK) != 0) {
        LOGI("Delta package does not exist %s\n", diff_pkg_path_name);
        return -1;
    }

    LOGI("Delta package path name: %s\n", diff_pkg_path_name);

    return 0;
}
コード例 #30
0
static int update_fotapropver(char *ver)
{
    int size;
    FILE *b_fp;
    char *buff;
    char *newbuff;
    char *orgstr=NULL;
    char newstr[MAX_STRING_LEN];
    char line[MAX_STRING_LEN];

    LOGI("update_ver:%s\r\n",ver);

    b_fp = fopen_path(FOTA_PROP_FILE, "r");
    if(!b_fp)
       return -1;

    //Read Old Version
    while(fgets(line, sizeof(line), b_fp))
    {
        orgstr = strstr(line, VERSION_STRING_NAME);
        if(orgstr)
        {
           break;
        }
    }

    if(orgstr == NULL)
    {
       LOGI("No firmware property.\r\n");
       return -1;
    }

    //Build New Version
    snprintf(newstr, MAX_STRING_LEN, "%s=%s",VERSION_STRING_NAME, ver);

    //Read Org File
    fseek(b_fp, 0, SEEK_END);
    size = ftell(b_fp);
    buff = (char*)malloc(size+1);
    if (buff == NULL) {
        LOGI("Failed to allocate buffer\n");
        return -1;
    }
    memset(buff, 0x0, size);

    //Update Version
    fseek(b_fp, 0, SEEK_SET);
    fread(buff, sizeof(char), size, b_fp);
    fclose(b_fp);
    buff[size] = '\0';
    newbuff = delta_update_replace_str(buff, orgstr, newstr);

    if (newbuff) {
        b_fp = fopen_path(FOTA_PROP_FILE, "w+");
        fwrite(newbuff, sizeof(char), strlen(newbuff), b_fp);
        fclose(b_fp);
        return 0;
    }

    return -1;
}