示例#1
0
文件: dump.c 项目: djwong/e2fsprogs
static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
			const char *name, const char *dumproot)
{
	char *fullname;

	/* There are more efficient ways to do this, but this method
	 * requires only minimal debugging. */
	fullname = malloc(strlen(dumproot) + strlen(name) + 2);
	if (!fullname) {
		com_err("rdump", errno, "while allocating memory");
		return;
	}
	sprintf(fullname, "%s/%s", dumproot, name);

	if (LINUX_S_ISLNK(inode->i_mode))
		rdump_symlink(ino, inode, fullname);
	else if (LINUX_S_ISREG(inode->i_mode)) {
		int fd;
		fd = open(fullname, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, S_IRWXU);
		if (fd == -1) {
			com_err("rdump", errno, "while opening %s", fullname);
			goto errout;
		}
		dump_file("rdump", ino, fd, 1, fullname);
		if (close(fd) != 0) {
			com_err("rdump", errno, "while closing %s", fullname);
			goto errout;
		}
	}
	else if (LINUX_S_ISDIR(inode->i_mode) && strcmp(name, ".") && strcmp(name, "..")) {
		errcode_t retval;

		/* Create the directory with 0700 permissions, because we
		 * expect to have to create entries it.  Then fix its perms
		 * once we've done the traversal. */
		if (name[0] && mkdir(fullname, S_IRWXU) == -1) {
			com_err("rdump", errno, "while making directory %s", fullname);
			goto errout;
		}

		retval = ext2fs_dir_iterate(current_fs, ino, 0, 0,
					    rdump_dirent, (void *) fullname);
		if (retval)
			com_err("rdump", retval, "while dumping %s", fullname);

		fix_perms("rdump", inode, -1, fullname);
	}
	/* else do nothing (don't dump device files, sockets, fifos, etc.) */

errout:
	free(fullname);
}
示例#2
0
文件: dump.c 项目: Einheri/wl500g
static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
		      int preserve, char *outname)
{
	errcode_t retval;
	struct ext2_inode	inode;
	char		*buf = 0;
	ext2_file_t	e2_file;
	int		nbytes;
	unsigned int	got, blocksize = current_fs->blocksize;

	if (debugfs_read_inode(ino, &inode, cmdname))
		return;

	retval = ext2fs_file_open(current_fs, ino, 0, &e2_file);
	if (retval) {
		com_err(cmdname, retval, "while opening ext2 file");
		return;
	}
	retval = ext2fs_get_mem(blocksize, &buf);
	if (retval) {
		com_err(cmdname, retval, "while allocating memory");
		return;
	}
	while (1) {
		retval = ext2fs_file_read(e2_file, buf, blocksize, &got);
		if (retval)
			com_err(cmdname, retval, "while reading ext2 file");
		if (got == 0)
			break;
		nbytes = write(fd, buf, got);
		if ((unsigned) nbytes != got)
			com_err(cmdname, errno, "while writing file");
	}
	if (buf)
		ext2fs_free_mem(&buf);
	retval = ext2fs_file_close(e2_file);
	if (retval) {
		com_err(cmdname, retval, "while closing ext2 file");
		return;
	}

	if (preserve)
		fix_perms("dump_file", &inode, fd, outname);
	else if (fd != 1)
		close(fd);

	return;
}
示例#3
0
void*
job_or_resv_recov_fs(char *filename, int objtype)
{
	int		 fds;
	job		*pj;
	void		*pobj = NULL;
#ifndef PBS_MOM
	resc_resv	*presv;
#endif
	void		*p_fixed = NULL;
	int		fixed_size;
	char		*prefix = NULL;
	char		*path = NULL;
	char		*err_msg;
	char		*ptcs;		/*text control string for err msg*/
	char		*pobjID = NULL;
	char		*pn;		/*name of the file "root" (prefix)*/
	attribute	*wattr = NULL;
	attribute_def	*p_attr_def = NULL;
	int		final_attr;
	int		attr_unkn;
	char		namebuf[MAXPATHLEN];
	char		err_buf[80];

	if (objtype == RESC_RESV_OBJECT) {

#ifndef PBS_MOM		/*MOM doesn't know about resource reservations*/
		presv = resc_resv_alloc();   /* allocate & init resc_rescv struct */
		if (presv == (resc_resv *)0) {
			return ((void *)0);
		}
		pobj = (void *)presv;
		path = path_resvs;
		err_msg = "error opening reservation file";
		ptcs = "reservation Id %s does not match file name for %s";
		pobjID = presv->ri_qs.ri_resvID;
		p_fixed = (void *)&presv->ri_qs;
		fixed_size = sizeof(struct resvfix);
		prefix = presv->ri_qs.ri_fileprefix;
		p_attr_def = resv_attr_def;
		wattr = presv->ri_wattr;
		attr_unkn = RESV_ATR_UNKN;
		final_attr = RESV_ATR_LAST;
#else	/* PBS_MOM only: This will never come here for MOM!!! */
		return ((void *)0);
#endif

	} else {

		pj = job_alloc();           /* allocate & initialize job struct */
		if (pj == (job *)0) {
			return ((void *)0);
		}
		pobj = (void *)pj;
		path = path_jobs;
		err_msg = "error opening job file";
		ptcs = "Job Id %s does not match file name for %s";
		pobjID = pj->ji_qs.ji_jobid;
		p_fixed = (void *)&pj->ji_qs;
		fixed_size = sizeof(struct jobfix);
		if (*pj->ji_qs.ji_fileprefix != '\0')
			prefix = pj->ji_qs.ji_fileprefix;
		else
			prefix = pj->ji_qs.ji_jobid;
		p_attr_def = job_attr_def;
		wattr = pj->ji_wattr;
		attr_unkn = JOB_ATR_UNKN;
		final_attr = JOB_ATR_LAST;
	}

	(void)strcpy(namebuf, path);	/* job (reservation) directory path */
	(void)strcat(namebuf, filename);
#ifdef WIN32
	fix_perms(namebuf);
#endif
	fds = open(namebuf, O_RDONLY, 0);
	if (fds < 0) {
		sprintf(log_buffer, "%s on %s", err_msg, namebuf);
		log_err(errno, "job_or_resv_recov", log_buffer);
		free((char *)pobj);
		return ((void *)0);
	}
#ifdef WIN32
	setmode(fds, O_BINARY);
#endif

	/* read in job or resc_resv quick save sub-structure */

	if (read(fds, (char *)p_fixed, fixed_size) != fixed_size) {
		(void)sprintf(err_buf, "problem reading %s", namebuf);
		log_err(errno, "job_or_resv_recov", err_buf);
		free((char *)pobj);
		(void)close(fds);
		return ((void *)0);
	}
	/* Does file name match the internal name? */
	/* This detects ghost files */

#ifdef WIN32
	pn = strrchr(namebuf, (int)'/');
	if (pn == NULL)
		pn = strrchr(namebuf, (int)'\\');
	if (pn == NULL) {
		sprintf(log_buffer, "bad path %s", namebuf);
		log_err(errno, "job_or_resv_recov", log_buffer);
		free((char *)pj);
		(void)close(fds);
		return ((job *)0);
	}
	pn++;
#else
	pn = strrchr(namebuf, (int)'/') + 1;
#endif

	if (strncmp(pn, prefix, strlen(prefix)) != 0) {
		/* mismatch, discard job (reservation) */

		(void)sprintf(log_buffer, ptcs, pobjID, namebuf);
		log_err(-1, "job_or_resv_recov", log_buffer);
		free((char *)pobj);
		(void)close(fds);
		return ((void *)0);
	}

	/* read in working attributes */

	if (recov_attr_fs(fds, pobj, p_attr_def, wattr,
		final_attr, attr_unkn) != 0) {

		log_err(errno, "job_or_resv_recov", "error from recov_attr");
		if (objtype == RESC_RESV_OBJECT) {

#ifndef PBS_MOM		/*MOM doesn't know about resource reservations*/
			resv_free((resc_resv *)pobj);
#endif
		} else {
			job_free((job *)pobj);
		}

		(void)close(fds);
		return ((void *)0);
	}

	(void)close(fds);

#if defined(PBS_MOM) && defined(WIN32)
	/* get a handle to the job (may not exist) */
	pj->ji_hJob = OpenJobObject(JOB_OBJECT_ALL_ACCESS, FALSE,
		pj->ji_qs.ji_jobid);
#endif

	/* all done recovering the job (reservation) */

	return (pobj);
}
示例#4
0
job *
job_recov_fs(char *filename, int recov_subjob)
{
	int		 fds;
	char		 basen[MAXPATHLEN+1];
	job		*pj;
	char		*pn;
	char		*psuffix;


	pj = job_alloc();	/* allocate & initialize job structure space */
	if (pj == (job *)0) {
		return ((job *)0);
	}

	(void)strcpy(pbs_recov_filename, path_jobs);	/* job directory path */
	(void)strcat(pbs_recov_filename, filename);
#ifdef WIN32
	fix_perms(pbs_recov_filename);
#endif

	/* change file name in case recovery fails so we don't try same file */

	(void)strcpy(basen, pbs_recov_filename);
	psuffix = basen + strlen(basen) - strlen(JOB_BAD_SUFFIX);
	(void)strcpy(psuffix, JOB_BAD_SUFFIX);
#ifdef WIN32
	if (MoveFileEx(pbs_recov_filename, basen,
		MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) == 0) {
		errno = GetLastError();
		sprintf(log_buffer, "MoveFileEx(%s, %s) failed!",
			pbs_recov_filename, basen);
		log_err(errno, "nodes", log_buffer);

	}
	secure_file(basen, "Administrators",
		READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
#else
	if (rename(pbs_recov_filename, basen) == -1) {
		sprintf(log_buffer, "error renaming job file %s",
			pbs_recov_filename);
		log_err(errno, "job_recov", log_buffer);
		free((char *)pj);
		return ((job *)0);
	}
#endif

	fds = open(basen, O_RDONLY, 0);
	if (fds < 0) {
		sprintf(log_buffer, "error opening of job file %s",
			pbs_recov_filename);
		log_err(errno, "job_recov", log_buffer);
		free((char *)pj);
		return ((job *)0);
	}
#ifdef WIN32
	setmode(fds, O_BINARY);
#endif

	/* read in job fixed sub-structure */

	errno = -1;
	if (read(fds, (char *)&pj->ji_qs, fixedsize) != (int)fixedsize) {
		sprintf(log_buffer, "error reading fixed portion of %s",
			pbs_recov_filename);
		log_err(errno, "job_recov", log_buffer);
		free((char *)pj);
		(void)close(fds);
		return ((job *)0);
	}
	/* Does file name match the internal name? */
	/* This detects ghost files */

#ifdef WIN32
	pn = strrchr(pbs_recov_filename, (int)'/');
	if (pn == NULL)
		pn = strrchr(pbs_recov_filename, (int)'\\');
	if (pn == NULL) {
		sprintf(log_buffer, "bad path %s", pbs_recov_filename);
		log_err(errno, "job_recov", log_buffer);
		free((char *)pj);
		(void)close(fds);
		return ((job *)0);
	}
	pn++;
#else
	pn = strrchr(pbs_recov_filename, (int)'/') + 1;
#endif

	if (strncmp(pn, pj->ji_qs.ji_jobid, strlen(pn)-3) != 0) {
		/* mismatch, discard job */

		(void)sprintf(log_buffer,
			"Job Id %s does not match file name for %s",
			pj->ji_qs.ji_jobid,
			pbs_recov_filename);
		log_err(-1, "job_recov", log_buffer);
		free((char *)pj);
		(void)close(fds);
		return ((job *)0);
	}

	/* unless directed, don't recover Array Sub jobs */

	if ((pj->ji_qs.ji_svrflags & JOB_SVFLG_SubJob) &&
		(recov_subjob == NO_RECOV_SUBJOB)) {
		free((char *)pj);
		(void)close(fds);
		return ((job *)0);
	}

	/* read in extended save area depending on VERSION */

	errno = -1;
	DBPRT(("Job save version %d\n", pj->ji_qs.ji_jsversion))
	if (pj->ji_qs.ji_jsversion < JSVERSION_514) {
		/* If really old version, it wasn't there, abort out */
		sprintf(log_buffer,
			"Job structure version cannot be recovered for job %s",
			pbs_recov_filename);
		log_err(errno, "job_recov", log_buffer);
		free((char *)pj);
		(void)close(fds);
		return ((job *)0);
	} else if (pj->ji_qs.ji_jsversion < JSVERSION_80) {
		/* If older version, read and copy extended area     */
		if (recov_514_extend(fds, pj) != 0) {
			sprintf(log_buffer,
				"error reading extended portion"
				" of %s for prior version",
				pbs_recov_filename);
			log_err(errno, "job_recov", log_buffer);
			free((char *)pj);
			(void)close(fds);
			return ((job *)0);
		}
	} else {
		/* If current version, JSVERSION_80, read into place */
		if (read(fds, (char *)&pj->ji_extended,
			sizeof(union jobextend)) !=
			sizeof(union jobextend)) {
			sprintf(log_buffer,
				"error reading extended portion of %s",
				pbs_recov_filename);
			log_err(errno, "job_recov", log_buffer);
			free((char *)pj);
			(void)close(fds);
			return ((job *)0);
		}
	}
#ifndef PBS_MOM
	if (pj->ji_qs.ji_svrflags & JOB_SVFLG_ArrayJob) {
		size_t xs;

		if (read(fds, (char *)&xs, sizeof(xs)) != sizeof(xs)) {
			sprintf(log_buffer,
				"error reading array section of %s",
				pbs_recov_filename);
			log_err(errno, "job_recov", log_buffer);
			free((char *)pj);
			(void)close(fds);
			return ((job *)0);
		}
		if ((pj->ji_ajtrk = (struct ajtrkhd *)malloc(xs)) == NULL) {
			free((char *)pj);
			(void)close(fds);
			return ((job *)0);
		}
		read(fds, (char *)pj->ji_ajtrk + sizeof(xs), xs - sizeof(xs));
		pj->ji_ajtrk->tkm_size = xs;
	}
#endif	/* not PBS_MOM */

	/* read in working attributes */

	if (recov_attr_fs(fds, pj, job_attr_def, pj->ji_wattr, (int)JOB_ATR_LAST,
		(int)JOB_ATR_UNKN) != 0) {
		sprintf(log_buffer, "error reading attributes portion of %s",
			pbs_recov_filename);
		log_err(errno, "job_recov", log_buffer);
		job_free(pj);
		(void)close(fds);
		return ((job *)0);
	}
	(void)close(fds);

#if defined(PBS_MOM) && defined(WIN32)
	/* get a handle to the job (may not exist) */
	pj->ji_hJob = OpenJobObject(JOB_OBJECT_ALL_ACCESS, FALSE,
		pj->ji_qs.ji_jobid);
#endif

	/* all done recovering the job, change file name back to .JB */

#ifdef WIN32
	if (MoveFileEx(basen, pbs_recov_filename,
		MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) == 0) {
		errno = GetLastError();
		sprintf(log_buffer, "MoveFileEx(%s, %s) failed!",
			basen, pbs_recov_filename);
		log_err(errno, "nodes", log_buffer);

	}
	secure_file(pbs_recov_filename, "Administrators",
		READS_MASK|WRITES_MASK|STANDARD_RIGHTS_REQUIRED);
#else
	(void)rename(basen, pbs_recov_filename);
#endif

	return (pj);
}
示例#5
0
文件: action.cpp 项目: Borkata/linux
int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
{
	static string zip_queue[10];
	static int zip_queue_index;
	int simulate;

	std::string arg = gui_parse_text(action.mArg);

	std::string function = gui_parse_text(action.mFunction);

	DataManager::GetValue(TW_SIMULATE_ACTIONS, simulate);

    if (function == "reboot")
    {
        //curtainClose(); this sometimes causes a crash

        sync();

        if (arg == "recovery")
            tw_reboot(rb_recovery);
        else if (arg == "poweroff")
            tw_reboot(rb_poweroff);
        else if (arg == "bootloader")
            tw_reboot(rb_bootloader);
        else if (arg == "download")
	    tw_reboot(rb_download);
        else
            tw_reboot(rb_system);

        // This should never occur
        return -1;
    }
    if (function == "home")
    {
        PageManager::SelectPackage("TWRP");
        gui_changePage("main");
        return 0;
    }

    if (function == "key")
    {
        PageManager::NotifyKey(getKeyByName(arg));
        return 0;
    }

    if (function == "page") {
		std::string page_name = gui_parse_text(arg);
        return gui_changePage(page_name);
	}

    if (function == "reload") {
		int check = 0, ret_val = 0;
		std::string theme_path;

		operation_start("Reload Theme");
		theme_path = DataManager::GetSettingsStoragePath();
		if (ensure_path_mounted(theme_path.c_str()) < 0) {
			LOGE("Unable to mount %s during reload function startup.\n", theme_path.c_str());
			check = 1;
		}

		theme_path += "/TWRP/theme/ui.zip";
		if (check != 0 || PageManager::ReloadPackage("TWRP", theme_path) != 0)
		{
			// Loading the custom theme failed - try loading the stock theme
			LOGI("Attempting to reload stock theme...\n");
			if (PageManager::ReloadPackage("TWRP", "/res/ui.xml"))
			{
				LOGE("Failed to load base packages.\n");
				ret_val = 1;
			}
		}
        operation_end(ret_val, simulate);
	}

    if (function == "readBackup")
    {
		set_restore_files();
        return 0;
    }

    if (function == "set")
    {
        if (arg.find('=') != string::npos)
        {
            string varName = arg.substr(0, arg.find('='));
            string value = arg.substr(arg.find('=') + 1, string::npos);

            DataManager::GetValue(value, value);
            DataManager::SetValue(varName, value);
        }
        else
            DataManager::SetValue(arg, "1");
        return 0;
    }
    if (function == "clear")
    {
        DataManager::SetValue(arg, "0");
        return 0;
    }

    if (function == "mount")
    {
        if (arg == "usb")
        {
            DataManager::SetValue(TW_ACTION_BUSY, 1);
			if (!simulate)
				usb_storage_enable();
			else
				ui_print("Simulating actions...\n");
        }
        else if (!simulate)
        {
            string cmd;
			if (arg == "EXTERNAL")
				cmd = "mount " + DataManager::GetStrValue(TW_EXTERNAL_MOUNT);
			else if (arg == "INTERNAL")
				cmd = "mount " + DataManager::GetStrValue(TW_INTERNAL_MOUNT);
			else
				cmd = "mount " + arg;
            __system(cmd.c_str());
			if (arg == "/data" && DataManager::GetIntValue(TW_HAS_DATADATA) == 1)
				__system("mount /datadata");
        } else
			ui_print("Simulating actions...\n");
        return 0;
    }

    if (function == "umount" || function == "unmount")
    {
        if (arg == "usb")
        {
            if (!simulate)
				usb_storage_disable();
			else
				ui_print("Simulating actions...\n");
			DataManager::SetValue(TW_ACTION_BUSY, 0);
        }
        else if (!simulate)
        {
            string cmd;
			if (arg == "EXTERNAL")
				cmd = "umount " + DataManager::GetStrValue(TW_EXTERNAL_MOUNT);
			else if (arg == "INTERNAL")
				cmd = "umount " + DataManager::GetStrValue(TW_INTERNAL_MOUNT);
			else if (DataManager::GetIntValue(TW_DONT_UNMOUNT_SYSTEM) == 1 && (arg == "system" || arg == "/system"))
				return 0;
			else
				cmd = "umount " + arg;
            __system(cmd.c_str());
			if (arg == "/data" && DataManager::GetIntValue(TW_HAS_DATADATA) == 1)
				__system("umount /datadata");
        } else
			ui_print("Simulating actions...\n");
        return 0;
    }
	
	if (function == "restoredefaultsettings")
	{
		operation_start("Restore Defaults");
		if (simulate) // Simulated so that people don't accidently wipe out the "simulation is on" setting
			ui_print("Simulating actions...\n");
		else {
			DataManager::ResetDefaults();
			mount_current_storage();
		}
		operation_end(0, simulate);
	}
	
	if (function == "copylog")
	{
		operation_start("Copy Log");
		if (!simulate)
		{
			char command[255];

			mount_current_storage();
			sprintf(command, "cp /tmp/recovery.log %s", DataManager::GetCurrentStoragePath().c_str());
			__system(command);
			sync();
			ui_print("Copied recovery log to %s.\n", DataManager::GetCurrentStoragePath().c_str());
		} else
			simulate_progress_bar();
		operation_end(0, simulate);
		return 0;
	}
	
	if (function == "compute" || function == "addsubtract")
	{
		if (arg.find("+") != string::npos)
        {
            string varName = arg.substr(0, arg.find('+'));
            string string_to_add = arg.substr(arg.find('+') + 1, string::npos);
			int amount_to_add = atoi(string_to_add.c_str());
			int value;

			DataManager::GetValue(varName, value);
            DataManager::SetValue(varName, value + amount_to_add);
			return 0;
        }
		if (arg.find("-") != string::npos)
        {
            string varName = arg.substr(0, arg.find('-'));
            string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos);
			int amount_to_subtract = atoi(string_to_subtract.c_str());
			int value;

			DataManager::GetValue(varName, value);
			value -= amount_to_subtract;
			if (value <= 0)
				value = 0;
            DataManager::SetValue(varName, value);
			return 0;
        }
	}
	
	if (function == "setguitimezone")
	{
		string SelectedZone;
		DataManager::GetValue(TW_TIME_ZONE_GUISEL, SelectedZone); // read the selected time zone into SelectedZone
		string Zone = SelectedZone.substr(0, SelectedZone.find(';')); // parse to get time zone
		string DSTZone = SelectedZone.substr(SelectedZone.find(';') + 1, string::npos); // parse to get DST component
		
		int dst;
		DataManager::GetValue(TW_TIME_ZONE_GUIDST, dst); // check wether user chose to use DST
		
		string offset;
		DataManager::GetValue(TW_TIME_ZONE_GUIOFFSET, offset); // pull in offset
		
		string NewTimeZone = Zone;
		if (offset != "0")
			NewTimeZone += ":" + offset;
		
		if (dst != 0)
			NewTimeZone += DSTZone;
		
		DataManager::SetValue(TW_TIME_ZONE_VAR, NewTimeZone);
		update_tz_environment_variables();
		return 0;
	}

	if (function == "togglestorage") {
		if (arg == "internal") {
			DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 0);
			DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)((sdcint.sze - sdcint.used) / 1048576LLU));
		} else if (arg == "external") {
			DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 1);
			DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)((sdcext.sze - sdcext.used) / 1048576LLU));
		}
		if (mount_current_storage() == 0) {
			if (arg == "internal") {
				// Save the current zip location to the external variable
				DataManager::SetValue(TW_ZIP_EXTERNAL_VAR, DataManager::GetStrValue(TW_ZIP_LOCATION_VAR));
				// Change the current zip location to the internal variable
				DataManager::SetValue(TW_ZIP_LOCATION_VAR, DataManager::GetStrValue(TW_ZIP_INTERNAL_VAR));
			} else if (arg == "external") {
				// Save the current zip location to the internal variable
				DataManager::SetValue(TW_ZIP_INTERNAL_VAR, DataManager::GetStrValue(TW_ZIP_LOCATION_VAR));
				// Change the current zip location to the external variable
				DataManager::SetValue(TW_ZIP_LOCATION_VAR, DataManager::GetStrValue(TW_ZIP_EXTERNAL_VAR));
			}
		} else {
			// We weren't able to toggle for some reason, restore original setting
			if (arg == "internal") {
				DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 1);
				DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)((sdcext.sze - sdcext.used) / 1048576LLU));
			} else if (arg == "external") {
				DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 0);
				DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)((sdcint.sze - sdcint.used) / 1048576LLU));
			}
		}
		return 0;
	}
	
	if (function == "overlay")
        return gui_changeOverlay(arg);

	if (function == "queuezip")
    {
        if (zip_queue_index >= 10) {
			ui_print("Maximum zip queue reached!\n");
			return 0;
		}
		DataManager::GetValue("tw_filename", zip_queue[zip_queue_index]);
		if (strlen(zip_queue[zip_queue_index].c_str()) > 0) {
			zip_queue_index++;
			DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
		}
		return 0;
	}

	if (function == "cancelzip")
    {
        if (zip_queue_index <= 0) {
			ui_print("Minimum zip queue reached!\n");
			return 0;
		} else {
			zip_queue_index--;
			DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
		}
		return 0;
	}

	if (function == "queueclear")
	{
		zip_queue_index = 0;
		DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
		return 0;
	}

	if (function == "sleep")
	{
		usleep(atoi(arg.c_str()));
		return 0;
	}

    if (isThreaded)
    {
        if (function == "flash")
        {
			int i, ret_val = 0;

			for (i=0; i<zip_queue_index; i++) {
				operation_start("Flashing");
		        DataManager::SetValue("tw_filename", zip_queue[i]);
		        DataManager::SetValue(TW_ZIP_INDEX, (i + 1));

				ret_val = flash_zip(zip_queue[i], arg, simulate);
				if (ret_val != 0) {
					ui_print("Error flashing zip '%s'\n", zip_queue[i].c_str());
					i = 10; // Error flashing zip - exit queue
					ret_val = 1;
				}
			}
			zip_queue_index = 0;
			DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);

			if (DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) {
				operation_start("ReinjectTWRP");
				ui_print("Injecting TWRP into boot image...\n");
				if (simulate) {
					simulate_progress_bar();
				} else {
					__system("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
					ui_print("TWRP injection complete.\n");
				}
			}
			operation_end(ret_val, simulate);
            return 0;
        }
        if (function == "wipe")
        {
            operation_start("Format");
            DataManager::SetValue("tw_partition", arg);

			if (simulate) {
				simulate_progress_bar();
			} else {
				if (arg == "data")
					wipe_data(0);
				else if (arg == "battery")
					wipe_battery_stats();
				else if (arg == "rotate")
					wipe_rotate_data();
				else if (arg == "dalvik")
					wipe_dalvik_cache();
				else
					erase_volume(arg.c_str());
				
				if (arg == "/sdcard") {
					ensure_path_mounted(SDCARD_ROOT);
					mkdir("/sdcard/TWRP", 0777);
					DataManager::Flush();
				}
			}
			update_system_details();
            operation_end(0, simulate);
            return 0;
        }
		if (function == "refreshsizes")
		{
			operation_start("Refreshing Sizes");
			if (simulate) {
				simulate_progress_bar();
			} else
				update_system_details();
			operation_end(0, simulate);
		}
        if (function == "nandroid")
        {
            operation_start("Nandroid");

			if (simulate) {
				DataManager::SetValue("tw_partition", "Simulation");
				simulate_progress_bar();
			} else {
				if (arg == "backup")
					nandroid_back_exe();
				else if (arg == "restore")
					nandroid_rest_exe();
				else {
					operation_end(1, simulate);
					return -1;
				}
			}
            operation_end(0, simulate);
			return 0;
        }
		if (function == "fixpermissions")
		{
			operation_start("Fix Permissions");
            LOGI("fix permissions started!\n");
			if (simulate) {
				simulate_progress_bar();
			} else
				fix_perms();

			LOGI("fix permissions DONE!\n");
			operation_end(0, simulate);
			return 0;
		}
        if (function == "dd")
        {
            operation_start("imaging");

			if (simulate) {
				simulate_progress_bar();
			} else {
				char cmd[512];
				sprintf(cmd, "dd %s", arg.c_str());
				__system(cmd);
			}
            operation_end(0, simulate);
            return 0;
        }
		if (function == "partitionsd")
		{
			operation_start("Partition SD Card");

			if (simulate) {
				simulate_progress_bar();
			} else {
				int allow_partition;
				DataManager::GetValue(TW_ALLOW_PARTITION_SDCARD, allow_partition);
				if (allow_partition == 0) {
					ui_print("This device does not have a real SD Card!\nAborting!\n");
				} else {
					// Below seen in Koush's recovery
					char sddevice[256];
					Volume *vol = volume_for_path("/sdcard");
					strcpy(sddevice, vol->device);
					// Just need block not whole partition
					sddevice[strlen("/dev/block/mmcblkX")] = NULL;

					char es[64];
					std::string ext_format;
					int ext, swap;
					DataManager::GetValue("tw_sdext_size", ext);
					DataManager::GetValue("tw_swap_size", swap);
					DataManager::GetValue("tw_sdpart_file_system", ext_format);
					sprintf(es, "/sbin/sdparted -es %dM -ss %dM -efs %s -s > /cache/part.log",ext,swap,ext_format.c_str());
					LOGI("\nrunning script: %s\n", es);
					run_script("\nContinue partitioning?",
						   "\nPartitioning sdcard : ",
						   es,
						   "\nunable to execute parted!\n(%s)\n",
						   "\nOops... something went wrong!\nPlease check the recovery log!\n",
						   "\nPartitioning complete!\n\n",
						   "\nPartitioning aborted!\n\n", 0);
					
					// recreate TWRP folder and rewrite settings - these will be gone after sdcard is partitioned
					ensure_path_mounted(SDCARD_ROOT);
					mkdir("/sdcard/TWRP", 0777);
					DataManager::Flush();
					DataManager::SetValue(TW_ZIP_EXTERNAL_VAR, "/sdcard");
					if (DataManager::GetIntValue(TW_USE_EXTERNAL_STORAGE) == 1)
						DataManager::SetValue(TW_ZIP_LOCATION_VAR, "/sdcard");

					update_system_details();
				}
			}
			operation_end(0, simulate);
			return 0;
		}
		if (function == "installhtcdumlock")
		{
			operation_start("Install HTC Dumlock");
			if (simulate) {
				simulate_progress_bar();
			} else
				install_htc_dumlock();

			operation_end(0, simulate);
			return 0;
		}
		if (function == "htcdumlockrestoreboot")
		{
			operation_start("HTC Dumlock Restore Boot");
			if (simulate) {
				simulate_progress_bar();
			} else
				htc_dumlock_restore_original_boot();

			operation_end(0, simulate);
			return 0;
		}
		if (function == "htcdumlockreflashrecovery")
		{
			operation_start("HTC Dumlock Reflash Recovery");
			if (simulate) {
				simulate_progress_bar();
			} else
				htc_dumlock_reflash_recovery_to_boot();

			operation_end(0, simulate);
			return 0;
		}
		if (function == "cmd")
		{
			int op_status = 0;

			operation_start("Command");
			ui_print("Running command: '%s'\n", arg.c_str());
			if (simulate) {
				simulate_progress_bar();
			} else {
				op_status = __system(arg.c_str());
				if (op_status != 0)
					op_status = 1;
			}

			operation_end(op_status, simulate);
			return 0;
		}
		if (function == "reinjecttwrp")
		{
			int op_status = 0;

			operation_start("ReinjectTWRP");
			ui_print("Injecting TWRP into boot image...\n");
			if (simulate) {
				simulate_progress_bar();
			} else {
				__system("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
				ui_print("TWRP injection complete.\n");
			}

			operation_end(op_status, simulate);
			return 0;
		}
    }
    else
    {
        pthread_t t;
        pthread_create(&t, NULL, thread_start, this);
        return 0;
    }
    return -1;
}
示例#6
0
pbs_queue *
que_recov_fs(char   *filename)
{
	int	   fds;
	int	   i;
	pbs_queue *pq;


	pq = que_alloc(filename);  /* allocate & init queue structure space */
	if (pq == (pbs_queue *)0) {
		log_err(-1, "que_recov", "que_alloc failed");
		return ((pbs_queue *)0);
	}

	(void)strcpy(pbs_recov_filename, path_queues);
	(void)strcat(pbs_recov_filename, filename);

#ifdef WIN32
	fix_perms(pbs_recov_filename);
#endif

	fds = open(pbs_recov_filename, O_RDONLY, 0);
	if (fds < 0) {
		sprintf(log_buffer, "error opening %s", pbs_recov_filename);
		log_err(errno, "que_recov", log_buffer);
		free((char *)pq);
		return ((pbs_queue *)0);
	}

#ifdef WIN32
	setmode(fds, O_BINARY);
#endif

	/* read in queue save sub-structure */

	errno = -1;
	if (read(fds, (char *)&pq->qu_qs, sizeof(struct queuefix)) !=
		sizeof(struct queuefix)) {
		sprintf(log_buffer, "error reading %s", pbs_recov_filename);
		log_err(errno, "que_recov", log_buffer);
		free((char *)pq);
		(void)close(fds);
		return ((pbs_queue *)0);
	}

	/* read in queue attributes */

	if (recov_attr_fs(fds, pq, que_attr_def, pq->qu_attr,
		(int)QA_ATR_LAST, 0) != 0) {
		log_err(-1, "que_recov", "recov_attr[common] failed");
		que_free(pq);
		(void)close(fds);
		return ((pbs_queue *)0);
	}

	/*
	 * now reload the access control lists, these attributes were
	 * saved separately
	 */

	for (i=0; i < (int)QA_ATR_LAST; i++) {
		if (pq->qu_attr[i].at_type == ATR_TYPE_ACL) {
			recov_acl(&pq->qu_attr[i], &que_attr_def[i],
				que_attr_def[i].at_name, pq->qu_qs.qu_name);
		}
	}

	/* all done recovering the queue */

	(void)close(fds);
	return (pq);
}