Beispiel #1
0
static int do_saveenv(int argc, char *argv[])
{
	int ret, opt;
	unsigned envfs_flags = 0;
	char *filename = NULL, *dirname = NULL;

	printf("saving environment\n");
	while ((opt = getopt(argc, argv, "z")) > 0) {
		switch (opt) {
		case 'z':
			envfs_flags |= ENVFS_FLAGS_FORCE_BUILT_IN;
			break;
		}
	}

	/* destination and source are given? */
	if (argc - optind > 1)
		dirname = argv[optind + 1];

	/* destination only given? */
	if (argc - optind > 0)
		filename = argv[optind];

	ret = envfs_save(filename, dirname, envfs_flags);

	return ret;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	int opt;
	int save = 0, load = 0, pad = 0, fd;
	char *filename = NULL, *dirname = NULL;

	while((opt = getopt(argc, argv, "slp:")) != -1) {
		switch (opt) {
		case 's':
			save = 1;
			break;
		case 'l':
			load = 1;
			break;
		case 'p':
			pad = strtoul(optarg, NULL, 0);
			break;
		}
	}

	if (optind + 1 >= argc) {
		usage(argv[0]);
		exit(1);
	}

	dirname = argv[optind];
	filename = argv[optind + 1];

	if ((!load && !save) || (load && save) || !filename || !dirname) {
		usage(argv[0]);
		exit(1);
	}

	if (save) {
		fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644);
		if (fd < 0) {
			perror("open");
			exit(1);
		}
		close(fd);
	}

	if (save && pad) {
		if (truncate(filename, pad)) {
			perror("truncate");
			exit(1);
		}
	}

	if (load) {
		printf("loading env from file %s to %s\n", filename, dirname);
		envfs_load(filename, dirname);
	}
	if (save) {
		printf("saving contents of %s to file %s\n", dirname, filename);
		envfs_save(filename, dirname);
	}
	exit(0);
}
Beispiel #3
0
static int do_saveenv(int argc, char *argv[])
{
	int ret, fd;
	char *filename, *dirname;

	printf("saving environment\n");
	if (argc < 3)
		dirname = "/env";
	else
		dirname = argv[2];
	if (argc < 2)
		filename = default_environment_path_get();
	else
		filename = argv[1];

	fd = open(filename, O_WRONLY | O_CREAT);
	if (fd < 0) {
		printf("could not open %s: %s\n", filename, errno_str());
		return 1;
	}

	ret = protect(fd, ~0, 0, 0);

	/* ENOSYS is no error here, many devices do not need it */
	if (ret && errno != ENOSYS) {
		printf("could not unprotect %s: %s\n", filename, errno_str());
		close(fd);
		return 1;
	}

	ret = erase(fd, ~0, 0);

	/* ENOSYS is no error here, many devices do not need it */
	if (ret && errno != ENOSYS) {
		printf("could not erase %s: %s\n", filename, errno_str());
		close(fd);
		return 1;
	}

	close(fd);

	ret = envfs_save(filename, dirname);
	if (ret) {
		printf("saveenv failed\n");
		goto out;
	}

	fd = open(filename, O_WRONLY | O_CREAT);

	ret = protect(fd, ~0, 0, 1);

	/* ENOSYS is no error here, many devices do not need it */
	if (ret && errno != ENOSYS) {
		printf("could not protect %s: %s\n", filename, errno_str());
		close(fd);
		return 1;
	}

	ret = 0;
out:
	close(fd);
	return ret;
}