Beispiel #1
0
static int fill_opts(void)
{
    static char _device[PATH_MAX];
    static char _mount_point[PATH_MAX];

    if (device && mount_point)
        return 0;

    if (disk_descriptor) {
        int ret;
        struct ploop_disk_images_data *di;

        ret = read_dd(&di, disk_descriptor);
        if (ret)
            return ret;

        ret = ploop_get_dev(di, _device, sizeof(_device));
        ploop_free_diskdescriptor(di);
        if (ret < 0)
            return SYSEXIT_PARAM;

        if (ret == 1) {
            fprintf(stderr, "The image is not mounted\n");
            return SYSEXIT_PARAM;
        }

        device = _device;
    }

    if (!device && mount_point) {
        if (ploop_get_dev_by_mnt(mount_point, _device, sizeof(_device))) {
            fprintf(stderr, "Unable to find ploop device by %s\n", mount_point);
            return SYSEXIT_PARAM;
        }
        device = _device;
        return 0;
    }

    if (!mount_point && device) {
        if (ploop_get_mnt_by_dev(device, _mount_point, sizeof(_mount_point))) {
            fprintf(stderr, "Unable to find mount point for %s\n", device);
            return SYSEXIT_PARAM;
        }
        mount_point = _mount_point;
        return 0;
    }

    fprintf(stderr, "Error: one of -d, -m or DiskDescriptor.xml argument is required\n");
    return 1;
}
Beispiel #2
0
static int plooptool_info(int argc, char **argv)
{
	int ret, i;
	int spec = 0;
	int device = 0;
	struct ploop_info info = {};

	while ((i = getopt(argc, argv, "sd")) != EOF) {
		switch (i) {
		case 's':
			spec = 1;
			break;
		case 'd':
			device = 1;
			break;
		default:
			usage_info();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 1 || !is_xml_fname(argv[0])) {
		usage_info();
		return SYSEXIT_PARAM;
	}

	if (spec || device) {
		struct ploop_disk_images_data *di;

		ret = ploop_open_dd(&di, argv[0]);
		if (ret)
			return ret;

		if (spec) {
			struct ploop_spec spec = {};

			ret = ploop_get_spec(di, &spec);
			if (ret)
				goto exit;

			printf("size:\t\t%llu\nblocksize:\t%d\nfmt_version:\t%d\n",
					(unsigned long long)spec.size,
					spec.blocksize,
					spec.fmt_version);
		}

		if (device) {
			char dev[PATH_MAX] = {};

			if (ploop_get_dev(di, dev, sizeof(dev)) == -1) {
				ret = SYSEXIT_SYS;
				goto exit;
			}

			printf("device:\t\t%s\n", dev);
		}

exit:
		ploop_close_dd(di);
	} else {
		ret = ploop_get_info_by_descr(argv[0], &info);
		if (ret == 0)
			print_info(&info);
	}

	return ret;
}