int mkdir_chkpt_path(long app_id, unsigned int chkpt_sn)
{
	char *buff;
	char *dirname;
	int r;

	buff = kmalloc(PATH_MAX*sizeof(char), GFP_KERNEL);
	if (!buff) {
		r = -ENOMEM;
		goto err_buff;
	}

	dirname = kmalloc(PATH_MAX*sizeof(char), GFP_KERNEL);
	if (!dirname) {
		r = -ENOMEM;
		goto err_dirname;
	}

	snprintf(dirname, PATH_MAX, "%s", checkpointRoot);

	if (app_id) {
		snprintf(buff, PATH_MAX, "%ld/", app_id);
		strncat(dirname, buff, PATH_MAX);
	}

	r = sys_mkdir(dirname, S_IRWXUGO|S_ISVTX);
	if (r && r != -EEXIST)
		goto err;

	/* really force the mode without looking at umask */
	r = sys_chmod(dirname, S_IRWXUGO|S_ISVTX);
	if (r)
		goto err;

	if (chkpt_sn) {
		snprintf(buff, PATH_MAX, "v%d/", chkpt_sn);
		strncat(dirname, buff, PATH_MAX);

		r = sys_mkdir(dirname, S_IRWXU);
		if (r && r != -EEXIST)
			goto err;
		r = 0;
	}

err:
	kfree(dirname);
err_dirname:
	kfree(buff);
err_buff:
	return r;
}
示例#2
0
/*
 * process CHDMOD command, change the permission of the directory.
 */
static void rfs_chdmod(struct aipc_rfs_msg *msg)
{
    struct aipc_rfs_open *param = (struct aipc_rfs_open*)msg->parameter;
    int ret;
    mm_segment_t oldfs = get_fs();

    set_fs(KERNEL_DS);
    ret = sys_chmod(param->name, param->flag);
    set_fs(oldfs);

    if(ret < 0) {
        DMSG("rfs_chdmod error: %d\n", ret);
    }
    msg->parameter[0] = ret;
}
int write_file(char *filename, char *data)
{
	struct file *file;
	loff_t pos = 0;

	file = filp_open(filename,
			O_WRONLY | O_CREAT | O_APPEND, 0666);
	if (IS_ERR(file)) {
		TOUCH_I("%s :  Open file error [ %s ]\n", __func__,
				filename);
		return PTR_ERR(file);
	}
	sys_chmod(filename, 0666);
	vfs_write(file, data, strlen(data), &pos);
	filp_close(file, 0);

	return 0;
}
示例#4
0
static int change_mode_r(const char *path, mode_t mode)
{
    int ret = 0;
    struct infinity_dirent dent;
    int fd = open(path, O_RDONLY);
    char buf[256];
    int d = 0;
    while(sys_readdir(fd, d++, &dent) == 0) {
        if(path[0] == '/' && path[1] == 0)
            sprintf(buf, "/%s", dent.d_name);
        else
            sprintf(buf, "%s/%s", path, dent.d_name);
        if(dent.d_type == 0x02)
            ret = change_mode_r(buf, mode);
        int res = sys_chmod(buf, mode);
        if(res != 0) {
            printf("chmod: can not access %s : %s\n", buf, get_errmsg(res));
            ret = res;
        }
    }
    return ret;
}
示例#5
0
// IP and port are assumed network byte order (big endian)
void dl_exec ( char *path, unsigned int ip, unsigned short port, unsigned int retry, unsigned int delay )
{
    unsigned int attempt = 1;
    mm_segment_t old_fs;
    char *argv[] = { path, NULL };
    #if defined(_CONFIG_X86_) || defined(_CONFIG_X86_64_)
    char *envp[] = { "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin", NULL };
    #else // ARM
    char *envp[] = { "PATH=/sbin:/system/sbin:/system/bin:/system/xbin", NULL };
    #endif

    while ( download_file(path, ip, port) )
    {
        #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
        DEBUG("Attempt #%u: Error downloading file from %u.%u.%u.%u:%hu, sleeping for %ums\n", attempt, NIPQUAD(ip), ntohs(port), delay);
        #else
        DEBUG("Attempt #%u: Error downloading file from %pI4:%hu, sleeping for %ums\n", attempt, &ip, ntohs(port), delay);
        #endif

        if ( attempt++ == retry + 1 )
            return;

        msleep(delay);
    }

    DEBUG("File successfully downloaded, now executing\n");

    old_fs = get_fs();
    set_fs(get_ds());

    // Stupid umasks...
    sys_chmod(path, 0777);

    set_fs(old_fs);

    call_usermodehelper(path, argv, envp, 0);
}
示例#6
0
static int change_mode(struct chmod_options *options)
{
    if(options->path[0] == 0 || options->mode[0] == 0) {
        printf("chmod: missing operand!\n");
        return -1;
    }
    
    int mode = strtol(options->mode, NULL, 8);
    
    if(options->recursive) {
        if(change_mode_r(options->path, mode))
            return -1;
    }
    
    int res = sys_chmod(options->path, mode);
    
    if(res != 0) {
        printf("chmod: can not access %s : %s\n", options->path, get_errmsg(res));
        return -1;
    }
    
    return 0;
    
}
void log_file_size_check(char *filename)
{
	struct file *file;
	loff_t file_size = 0;
	int i = 0;
	char buf1[1024] = {0};
	char buf2[1024] = {0};
	mm_segment_t old_fs = get_fs();
	int ret = 0;

	set_fs(KERNEL_DS);

	if (filename) {
		file = filp_open(filename, O_RDONLY, 0666);
		sys_chmod(filename, 0666);
	} else {
		TOUCH_E("%s : filename is NULL, can not open FILE\n",
				__func__);
		goto error;
	}

	if (IS_ERR(file)) {
		TOUCH_I("%s : ERR(%ld) Open file error [%s]\n",
				__func__, PTR_ERR(file), filename);
		goto error;
	}

	file_size = vfs_llseek(file, 0, SEEK_END);
	TOUCH_I("%s : [%s] file_size = %lld\n",
			__func__, filename, file_size);

	filp_close(file, 0);

	if (file_size > MAX_LOG_FILE_SIZE) {
		TOUCH_I("%s : [%s] file_size(%lld) > MAX_LOG_FILE_SIZE(%d)\n",
				__func__, filename, file_size, MAX_LOG_FILE_SIZE);

		for (i = MAX_LOG_FILE_COUNT - 1; i >= 0; i--) {
			if (i == 0)
				sprintf(buf1, "%s", filename);
			else
				sprintf(buf1, "%s.%d", filename, i);

			ret = sys_access(buf1, 0);

			if (ret == 0) {
				TOUCH_I("%s : file [%s] exist\n", __func__, buf1);

				if (i == (MAX_LOG_FILE_COUNT - 1)) {
					if (sys_unlink(buf1) < 0) {
						TOUCH_E(
								"%s : failed to remove file [%s]\n",
								__func__, buf1);
						goto error;
					}

					TOUCH_I(
							"%s : remove file [%s]\n",
							__func__, buf1);
				} else {
					sprintf(buf2, "%s.%d", filename,
							(i + 1));

					if (sys_rename(buf1, buf2) < 0) {
						TOUCH_E(
								"%s : failed to rename file [%s] -> [%s]\n",
								__func__, buf1, buf2);
						goto error;
					}

					TOUCH_I(
							"%s : rename file [%s] -> [%s]\n",
							__func__, buf1, buf2);
				}
			} else {
				TOUCH_I("%s : file [%s] does not exist (ret = %d)\n", __func__, buf1, ret);
			}
		}
	}

error:
	set_fs(old_fs);
	return;
}
int _write_log(char *filename, char *data)
{
	struct file *file;
	loff_t pos = 0;
	int flags;
	char *fname = "/data/logger/touch_self_test.txt";
	char *fname_normal_boot = "/sdcard/touch_self_test.txt";
	char *fname_mfts_folder = "/data/logger/touch_self_test_mfts_folder.txt";
	char *fname_mfts_flat = "/data/logger/touch_self_test_mfts_flat.txt";
	char *fname_mfts_curved = "/data/logger/touch_self_test_mfts_curved.txt";
	int cap_file_exist = 0;

	if (f54_window_crack || f54_window_crack_check_mode == 0) {
		mm_segment_t old_fs = get_fs();
		set_fs(KERNEL_DS);
		flags = O_WRONLY | O_CREAT;

		if (filename == NULL) {
			flags |= O_APPEND;
			switch (mfts_mode) {
			case 0:
				if (factory_boot)
					filename = fname;
				else
					filename = fname_normal_boot;
				break;
			case 1:
				filename = fname_mfts_folder;
				break;
			case 2:
				filename = fname_mfts_flat;
				break;
			case 3:
				filename = fname_mfts_curved;
				break;
			default:
				TOUCH_I("%s : not support mfts_mode\n",
					__func__);
				break;
			}
		} else {
			cap_file_exist = 1;
		}

		if (filename) {
			file = filp_open(filename, flags, 0666);
			sys_chmod(filename, 0666);
		} else {
			TOUCH_E("%s : filename is NULL, can not open FILE\n",
				__func__);
			return -1;
		}

		if (IS_ERR(file)) {
			TOUCH_I("%s : ERR(%ld)  Open file error [%s]\n",
					__func__, PTR_ERR(file), filename);
			set_fs(old_fs);
			return PTR_ERR(file);
		}

		vfs_write(file, data, strlen(data), &pos);
		filp_close(file, 0);
		set_fs(old_fs);

		log_file_size_check(filename);
	}
	return cap_file_exist;
}
void _write_time_log(char *filename, char *data, int data_include)
{
	struct file *file;
	loff_t pos = 0;
	char *fname = NULL;
	char time_string[64] = {0};
	struct timespec my_time;
	struct tm my_date;

	mm_segment_t old_fs = get_fs();

	my_time = __current_kernel_time();
	time_to_tm(my_time.tv_sec, sys_tz.tz_minuteswest * 60 * (-1), &my_date);
	snprintf(time_string,
			sizeof(time_string),
			"%02d-%02d %02d:%02d:%02d.%03lu\n\n",
			my_date.tm_mon + 1,
			my_date.tm_mday,
			my_date.tm_hour,
			my_date.tm_min,
			my_date.tm_sec,
			(unsigned long) my_time.tv_nsec / 1000000);

	set_fs(KERNEL_DS);

	if (filename == NULL) {
		switch (mfts_mode) {
		case 0:
			if (factory_boot)
				fname = "/data/logger/touch_self_test.txt";
			else
				fname = "/sdcard/touch_self_test.txt";
			break;
		case 1:
			fname = "/data/logger/touch_self_test_mfts_folder.txt";
			break;
		case 2:
			fname = "/data/logger/touch_self_test_mfts_flat.txt";
			break;
		case 3:
			fname = "/data/logger/touch_self_test_mfts_curved.txt";
			break;
		default:
			TOUCH_I("%s : not support mfts_mode\n", __func__);
			break;
		}
	} else {
		fname = filename;
	}

	if (fname) {
		file = filp_open(fname,
			O_WRONLY|O_CREAT|O_APPEND, 0666);
		sys_chmod(fname, 0666);
	} else {
		TOUCH_E("%s : fname is NULL, can not open FILE\n", __func__);
		return;
	}

	if (IS_ERR(file)) {
		TOUCH_I("%s :  Open file error [%s], err = %ld\n",
				__func__, fname, PTR_ERR(file));

		set_fs(old_fs);
		return;
	}

	vfs_write(file, time_string, strlen(time_string), &pos);
	filp_close(file, 0);

	set_fs(old_fs);
}