Esempio n. 1
0
static int plooptool_convert(int argc, char **argv)
{
	int i, ret;
	struct ploop_disk_images_data *di;
	int mode = -1;
	int version = -1;

	while ((i = getopt(argc, argv, "f:v:")) != EOF) {
		switch (i) {
		case 'f':
			mode = parse_format_opt(optarg);
			break;
		case 'v':
			version = parse_version_opt(optarg);
			if (version < 0) {
				 usage_convert();
				 return SYSEXIT_PARAM;
			}
			break;
		default:
			usage_convert();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc == 0 ||
		(mode == -1 && version == -1) ||
		(mode != -1 && version != -1))
	{
		usage_convert();
		return SYSEXIT_PARAM;
	}

	ret = ploop_open_dd(&di, argv[0]);
	if (ret)
		return ret;
	if (mode != -1)
		ret = ploop_convert_image(di, mode, 0);
	else if (version != -1)
		ret = ploop_change_fmt_version(di, version, 0);

	ploop_close_dd(di);

	return ret;
}
Esempio n. 2
0
int
exec_convert(__unused int argc, __unused char **argv)
{
	int ch;
	bool revert = false;
	bool dry_run = false;
	const char *pkg_add_dbdir = "/var/db/pkg";

	while ((ch = getopt(argc, argv, "d:nr")) != -1) {
		switch (ch) {
		case 'd':
			pkg_add_dbdir = optarg;
			break;
		case 'n':
			dry_run = true;
			break;
		case 'r':
			revert = true;
			break;
		default:
			usage_convert();
			return (EX_USAGE);
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 1) {
		usage_convert();
		return (EX_USAGE);
	}

	printf("Converting packages %s %s\n", revert ? "to" : "from", pkg_add_dbdir);

	if (revert)
		return (convert_to_old(pkg_add_dbdir, dry_run));
	else
		return (convert_from_old(pkg_add_dbdir, dry_run));
}
Esempio n. 3
0
int
exec_convert(__unused int argc, __unused char **argv)
{
	int		 ch;
	bool		 dry_run = false;
	const char	*pkg_add_dbdir = "/var/db/pkg";

	struct option longopts[] = {
		{ "pkg-dbdir",	required_argument,	NULL,	'd' },
		{ "dry-run",	no_argument,		NULL,	'n' },
		{ NULL,		0,			NULL,	0   },
	};

	while ((ch = getopt_long(argc, argv, "+d:n", longopts, NULL)) != -1) {
		switch (ch) {
		case 'd':
			pkg_add_dbdir = optarg;
			break;
		case 'n':
			dry_run = true;
			break;
		default:
			usage_convert();
			return (EX_USAGE);
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 1) {
		usage_convert();
		return (EX_USAGE);
	}

	printf("Converting packages from %s\n", pkg_add_dbdir);

	return (convert_from_old(pkg_add_dbdir, dry_run));
}