Esempio n. 1
0
void
add_defaults(int fd)
{
	entry = 0;
	size = 524288;
	if (parse_uuid("EFI System", &type) != 0) {
		fprintf(stderr, "Unable to lookup uuid 'EFI System'\n");
		exit(1);
	}
	add(fd);

	entry = 1;
	size = 0;
	if (parse_uuid("DragonFly Label64", &type) != 0) {
		fprintf(stderr, "Unable to lookup uuid 'DragonFly Label64'\n");
		exit(1);
	}
	add(fd);
}
Esempio n. 2
0
static int plooptool_snapshot(int argc, char **argv)
{
	int i, ret;
	char *device = NULL;
	int syncfs = 0;
	struct ploop_snapshot_param param = {};

	while ((i = getopt(argc, argv, "Fd:u:")) != EOF) {
		switch (i) {
		case 'd':
			device = optarg;
			break;
		case 'F':
			syncfs = 1;
			break;
		case 'u':
			param.guid = parse_uuid(optarg);
			if (!param.guid)
				return SYSEXIT_PARAM;
			break;
		default:
			usage_snapshot();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 1) {
		usage_snapshot();
		return SYSEXIT_PARAM;
	}

	if (is_xml_fname(argv[0])) {
		struct ploop_disk_images_data *di;
		ret = ploop_open_dd(&di, argv[0]);
		if (ret)
			return ret;

		ret = ploop_create_snapshot(di, &param);

		ploop_close_dd(di);
	} else {
		if (!device) {
			usage_snapshot();
			return SYSEXIT_PARAM;
		}
		ret = create_snapshot(device, argv[0], syncfs);
	}

	return ret;
}
Esempio n. 3
0
/* HAL callback for new device */
static void hal_new_device( LibHalContext *ctx, const char *udi )
{
    DBusError error;
    char *parent = NULL;
    char *mount_point = NULL;
    char *device = NULL;
    char *type = NULL;
    char *uuid_str = NULL;
    GUID guid, *guid_ptr = NULL;
    enum device_type drive_type;

    p_dbus_error_init( &error );

    if (!(device = p_libhal_device_get_property_string( ctx, udi, "block.device", &error )))
        goto done;

    if (!(mount_point = p_libhal_device_get_property_string( ctx, udi, "volume.mount_point", &error )))
        goto done;

    if (!(parent = p_libhal_device_get_property_string( ctx, udi, "info.parent", &error )))
        goto done;

    if (!(uuid_str = p_libhal_device_get_property_string( ctx, udi, "volume.uuid", &error )))
        p_dbus_error_free( &error );  /* ignore error */
    else
        guid_ptr = parse_uuid( &guid, uuid_str );

    if (!(type = p_libhal_device_get_property_string( ctx, parent, "storage.drive_type", &error )))
        p_dbus_error_free( &error );  /* ignore error */

    if (type && !strcmp( type, "cdrom" )) drive_type = DEVICE_CDROM;
    else if (type && !strcmp( type, "floppy" )) drive_type = DEVICE_FLOPPY;
    else drive_type = DEVICE_UNKNOWN;

    if (p_libhal_device_get_property_bool( ctx, parent, "storage.removable", &error ))
    {
        add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr );
        /* add property watch for mount point */
        p_libhal_device_add_property_watch( ctx, udi, &error );
    }
    else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr );

done:
    if (type) p_libhal_free_string( type );
    if (parent) p_libhal_free_string( parent );
    if (device) p_libhal_free_string( device );
    if (uuid_str) p_libhal_free_string( uuid_str );
    if (mount_point) p_libhal_free_string( mount_point );
    p_dbus_error_free( &error );
}
Esempio n. 4
0
static int plooptool_snapshot_merge(int argc, char ** argv)
{
	int i, ret;
	struct ploop_merge_param param = {};

	while ((i = getopt(argc, argv, "u:A")) != EOF) {
		switch (i) {
		case 'u':
			param.guid = parse_uuid(optarg);
			if (!param.guid)
				return SYSEXIT_PARAM;
			break;
		case 'A':
			param.merge_all = 1;
			break;
		default:
			usage_snapshot_merge();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if (param.guid != NULL && param.merge_all != 0) {
		fprintf(stderr, "Options -u and -A can't be used together\n");
		usage_snapshot_merge();
		return SYSEXIT_PARAM;
	}

	if (argc == 1 && is_xml_fname(argv[0])) {
		struct ploop_disk_images_data *di;
		ret = ploop_open_dd(&di, argv[0]);
		if (ret)
			return ret;

		ret = ploop_merge_snapshot(di, &param);

		ploop_close_dd(di);
	} else {
		usage_snapshot_merge();
		return SYSEXIT_PARAM;
	}

	return ret;
}
Esempio n. 5
0
static int plooptool_tsnapshot(int argc, char **argv)
{
	int i, ret;
	struct ploop_disk_images_data *di;
	struct ploop_tsnapshot_param param = {};

	while ((i = getopt(argc, argv, "u:c:m:")) != EOF) {
		switch (i) {
		case 'u':
			param.guid = parse_uuid(optarg);
			if (!param.guid)
				return SYSEXIT_PARAM;
			break;
		case 'c':
			param.component_name = optarg;
			break;
		case 'm':
			param.target = optarg;
			break;
		default:
			usage_snapshot();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 1 || !is_xml_fname(argv[0]) ||
			param.guid == NULL ||
			param.component_name == NULL) {
		usage_tsnapshot();
		return SYSEXIT_PARAM;
	}

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

	ret = ploop_create_temporary_snapshot(di, &param, NULL);

	ploop_close_dd(di);

	return ret;
}
Esempio n. 6
0
static int plooptool_snapshot_switch(int argc, char **argv)
{
	int i, ret;
	char *uuid = NULL;
	int flags = 0;
	struct ploop_disk_images_data *di = NULL;

	while ((i = getopt(argc, argv, "u:D")) != EOF) {
		switch (i) {
		case 'u':
			uuid = parse_uuid(optarg);
			if (!uuid)
				return SYSEXIT_PARAM;
			break;
		case 'D':
			/* for test purposes */
			flags = PLOOP_SNAP_SKIP_TOPDELTA_DESTROY;
			break;
		default:
			usage_snapshot_switch();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if ((argc != 1 && !is_xml_fname(argv[0])) || uuid == NULL) {
		usage_snapshot_switch();
		return SYSEXIT_PARAM;
	}

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

	ret = ploop_switch_snapshot(di, uuid, flags);

	ploop_close_dd(di);

	return ret;
}
Esempio n. 7
0
static int plooptool_snapshot_delete(int argc, char **argv)
{
	int i, ret;
	char *uuid = NULL;
	struct ploop_disk_images_data *di = NULL;

	while ((i = getopt(argc, argv, "u:")) != EOF) {
		switch (i) {
		case 'u':
			uuid = parse_uuid(optarg);
			if (!uuid)
				return SYSEXIT_PARAM;
			break;
		default:
			usage_snapshot_delete();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

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

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

	ret = ploop_delete_snapshot(di, uuid);

	ploop_close_dd(di);

	return ret;
}
Esempio n. 8
0
/* UDisks callback for new device */
static void udisks_new_device( const char *udi )
{
    static const char *dev_name = "org.freedesktop.UDisks.Device";
    DBusMessage *request, *reply;
    DBusMessageIter iter, variant;
    DBusError error;
    const char *device = NULL;
    const char *mount_point = NULL;
    const char *type = NULL;
    GUID guid, *guid_ptr = NULL;
    int removable = FALSE;
    enum device_type drive_type = DEVICE_UNKNOWN;

    request = p_dbus_message_new_method_call( "org.freedesktop.UDisks", udi,
                                              "org.freedesktop.DBus.Properties", "GetAll" );
    if (!request) return;

    p_dbus_message_iter_init_append( request, &iter );
    p_dbus_message_iter_append_basic( &iter, DBUS_TYPE_STRING, &dev_name );

    p_dbus_error_init( &error );
    reply = p_dbus_connection_send_with_reply_and_block( connection, request, -1, &error );
    p_dbus_message_unref( request );
    if (!reply)
    {
        WARN( "failed: %s\n", error.message );
        p_dbus_error_free( &error );
        return;
    }
    p_dbus_error_free( &error );

    p_dbus_message_iter_init( reply, &iter );
    if (p_dbus_message_iter_get_arg_type( &iter ) == DBUS_TYPE_ARRAY)
    {
        const char *name;

        p_dbus_message_iter_recurse( &iter, &iter );
        while ((name = udisks_next_dict_entry( &iter, &variant )))
        {
            if (!strcmp( name, "DeviceFile" ))
                p_dbus_message_iter_get_basic( &variant, &device );
            else if (!strcmp( name, "DeviceIsRemovable" ))
                p_dbus_message_iter_get_basic( &variant, &removable );
            else if (!strcmp( name, "IdType" ))
                p_dbus_message_iter_get_basic( &variant, &type );
            else if (!strcmp( name, "DriveMediaCompatibility" ))
            {
                DBusMessageIter media;
                p_dbus_message_iter_recurse( &variant, &media );
                while (p_dbus_message_iter_get_arg_type( &media ) == DBUS_TYPE_STRING)
                {
                    const char *media_type;
                    p_dbus_message_iter_get_basic( &media, &media_type );
                    if (!strncmp( media_type, "optical_dvd", 11 ))
                        drive_type = DEVICE_DVD;
                    if (!strncmp( media_type, "floppy", 6 ))
                        drive_type = DEVICE_FLOPPY;
                    else if (!strncmp( media_type, "optical_", 8 ) && drive_type == DEVICE_UNKNOWN)
                        drive_type = DEVICE_CDROM;
                    p_dbus_message_iter_next( &media );
                }
            }
            else if (!strcmp( name, "DeviceMountPaths" ))
            {
                DBusMessageIter paths;
                p_dbus_message_iter_recurse( &variant, &paths );
                if (p_dbus_message_iter_get_arg_type( &paths ) == DBUS_TYPE_STRING)
                    p_dbus_message_iter_get_basic( &paths, &mount_point );
            }
            else if (!strcmp( name, "IdUuid" ))
            {
                char *uuid_str;
                p_dbus_message_iter_get_basic( &variant, &uuid_str );
                guid_ptr = parse_uuid( &guid, uuid_str );
            }
        }
    }

    TRACE( "udi %s device %s mount point %s uuid %s type %s removable %u\n",
           debugstr_a(udi), debugstr_a(device), debugstr_a(mount_point),
           debugstr_guid(guid_ptr), debugstr_a(type), removable );

    if (type)
    {
        if (!strcmp( type, "iso9660" ))
        {
            removable = TRUE;
            drive_type = DEVICE_CDROM;
        }
        else if (!strcmp( type, "udf" ))
        {
            removable = TRUE;
            drive_type = DEVICE_DVD;
        }
    }

    if (device)
    {
        if (removable) add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr );
        else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr );
    }

    p_dbus_message_unref( reply );
}
Esempio n. 9
0
int
cmd_remove(int argc, char *argv[])
{
	char *p;
	int ch, fd;

	/* Get the remove options */
	while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) {
		switch(ch) {
		case 'a':
			if (all > 0)
				usage_remove();
			all = 1;
			break;
		case 'b':
			if (block > 0)
				usage_remove();
			block = strtoll(optarg, &p, 10);
			if (*p != 0 || block < 1)
				usage_remove();
			break;
		case 'i':
			if (entry != NOENTRY)
				usage_remove();
			entry = strtoul(optarg, &p, 10);
			if (*p != 0 || entry == NOENTRY)
				usage_remove();
			break;
		case 's':
			if (size > 0)
				usage_remove();
			size = strtoll(optarg, &p, 10);
			if (*p != 0 || size < 1)
				usage_remove();
			break;
		case 't':
			if (!uuid_is_nil(&type, NULL))
				usage_remove();
			if (parse_uuid(optarg, &type) != 0)
				usage_remove();
			break;
		default:
			usage_remove();
		}
	}

	if (!all ^
	    (block > 0 || entry != NOENTRY || size > 0 ||
	     !uuid_is_nil(&type, NULL)))
		usage_remove();

	if (argc == optind)
		usage_remove();

	while (optind < argc) {
		fd = gpt_open(argv[optind++]);
		if (fd == -1) {
			warn("unable to open device '%s'", device_name);
			continue;
		}

		rem(fd);

		gpt_close(fd);
	}

	return (0);
}
Esempio n. 10
0
int
cmd_add(int argc, char *argv[])
{
	char *p;
	int ch, fd;

	/* Get the migrate options */
	while ((ch = getopt(argc, argv, "b:i:s:t:")) != -1) {
		switch(ch) {
		case 'b':
			if (block > 0)
				usage_add();
			block = strtoll(optarg, &p, 10);
			if (*p != 0 || block < 1)
				usage_add();
			break;
		case 'i':
			if (entry != NOENTRY)
				usage_add();
			entry = strtoul(optarg, &p, 10);
			if (*p != 0 || entry == NOENTRY)
				usage_add();
			break;
		case 's':
			if (size > 0)
				usage_add();
			size = strtoll(optarg, &p, 10);
			if (*p != 0 || size < 1)
				usage_add();
			break;
		case 't':
			if (!uuid_is_nil(&type, NULL))
				usage_add();
			if (parse_uuid(optarg, &type) != 0)
				usage_add();
			break;
		default:
			usage_add();
		}
	}

	if (argc == optind)
		usage_add();

	/* Create DragonFly 64 bit label partitions by default. */
	if (uuid_is_nil(&type, NULL)) {
		uint32_t status;

		uuid_name_lookup(&type, "DragonFly Label64", &status);
		if (status != uuid_s_ok)
			err(1, "unable to find uuid for 'DragonFly Label64'");
	}

	while (optind < argc) {
		fd = gpt_open(argv[optind++]);
		if (fd == -1) {
			warn("unable to open device '%s'", device_name);
			continue;
		}

		add(fd);

		gpt_close(fd);
	}

	return (0);
}
Esempio n. 11
0
void arrayline(char *line)
{
	char *w;

	struct mddev_ident_s mis;
	mddev_ident_t mi;

	mis.uuid_set = 0;
	mis.super_minor = UnSet;
	mis.level = UnSet;
	mis.raid_disks = UnSet;
	mis.spare_disks = UnSet;
	mis.devices = NULL;
	mis.devname = NULL;
	mis.spare_group = NULL;
	mis.autof = 0;
	mis.next = NULL;
	mis.st = NULL;
	mis.bitmap_fd = -1;
	mis.name[0] = 0;

	for (w=dl_next(line); w!=line; w=dl_next(w)) {
		if (w[0] == '/') {
			if (mis.devname)
				fprintf(stderr, Name ": only give one device per ARRAY line: %s and %s\n",
					mis.devname, w);
			else mis.devname = w;
		} else if (strncasecmp(w, "uuid=", 5)==0 ) {
			if (mis.uuid_set)
				fprintf(stderr, Name ": only specify uuid once, %s ignored.\n",
					w);
			else {
				if (parse_uuid(w+5, mis.uuid))
					mis.uuid_set = 1;
				else
					fprintf(stderr, Name ": bad uuid: %s\n", w);
			}
		} else if (strncasecmp(w, "super-minor=", 12)==0 ) {
			if (mis.super_minor != UnSet)
				fprintf(stderr, Name ": only specify super-minor once, %s ignored.\n",
					w);
			else {
				char *endptr;
				mis.super_minor= strtol(w+12, &endptr, 10);
				if (w[12]==0 || endptr[0]!=0 || mis.super_minor < 0) {
					fprintf(stderr, Name ": invalid super-minor number: %s\n",
						w);
					mis.super_minor = UnSet;
				}
			}
		} else if (strncasecmp(w, "name=", 5)==0) {
			if (mis.name[0])
				fprintf(stderr, Name ": only specify name once, %s ignored.\n",
					w);
			else if (strlen(w+5) > 32)
				fprintf(stderr, Name ": name too long, ignoring %s\n", w);
			else
				strcpy(mis.name, w+5);

		} else if (strncasecmp(w, "devices=", 8 ) == 0 ) {
			if (mis.devices)
				fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n",
					w);
			else
				mis.devices = strdup(w+8);
		} else if (strncasecmp(w, "spare-group=", 12) == 0 ) {
			if (mis.spare_group)
				fprintf(stderr, Name ": only specify one spare group per array. %s ignored.\n",
					w);
			else
				mis.spare_group = strdup(w+12);
		} else if (strncasecmp(w, "level=", 6) == 0 ) {
			/* this is mainly for compatability with --brief output */
			mis.level = map_name(pers, w+6);
		} else if (strncasecmp(w, "disks=", 6) == 0 ) {
			/* again, for compat */
			mis.raid_disks = atoi(w+6);
		} else if (strncasecmp(w, "num-devices=", 12) == 0 ) {
			/* again, for compat */
			mis.raid_disks = atoi(w+12);
		} else if (strncasecmp(w, "spares=", 7) == 0 ) {
			/* for warning if not all spares present */
			mis.spare_disks = atoi(w+7);
		} else if (strncasecmp(w, "metadata=", 9) == 0) {
			/* style of metadata on the devices. */
			int i;
			
			for(i=0; superlist[i] && !mis.st; i++)
				mis.st = superlist[i]->match_metadata_desc(w+9);

			if (!mis.st)
				fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9);
		} else if (strncasecmp(w, "auto=", 5) == 0 ) {
			/* whether to create device special files as needed */
			if (strcasecmp(w+5, "no")==0)
				mis.autof = 0;
			else if (strcasecmp(w+5,"yes")==0 || strcasecmp(w+5,"md")==0)
				mis.autof = -1;
			else {
				/* There might be digits, and maybe a hyphen, at the end */
				char *e = w+5 + strlen(w+5);
				int num = 4;
				int len;
				while (e > w+5 && isdigit(e[-1]))
					e--;
				if (*e) {
					num = atoi(e);
					if (num <= 0) num = 1;
				}
				if (e > w+5 && e[-1] == '-')
					e--;
				len = e - (w+5);
				if ((len == 3 && strncasecmp(w+5,"mdp",3)==0) ||
				    (len == 1 && strncasecmp(w+5,"p",1)==0) ||
				    (len >= 4 && strncasecmp(w+5,"part",4)==0))
					mis.autof = num;
				else 
					fprintf(stderr, Name ": auto type of \"%s\" ignored for %s\n",
						w+5, mis.devname?mis.devname:"unlabeled-array");
			}
		} else {
			fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n",
				w);
		}
	}
	if (mis.devname == NULL)
		fprintf(stderr, Name ": ARRAY line with no device\n");
	else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0)
		fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname);
	else {
		mi = malloc(sizeof(*mi));
		*mi = mis;
		mi->devname = strdup(mis.devname);
		mi->next = NULL;
		*mddevlp = mi;
		mddevlp = &mi->next;
	}
}
Esempio n. 12
0
void arrayline(char *line)
{
	char *w;

	struct mddev_ident mis;
	struct mddev_ident *mi;

	mis.uuid_set = 0;
	mis.super_minor = UnSet;
	mis.level = UnSet;
	mis.raid_disks = UnSet;
	mis.spare_disks = 0;
	mis.devices = NULL;
	mis.devname = NULL;
	mis.spare_group = NULL;
	mis.autof = 0;
	mis.next = NULL;
	mis.st = NULL;
	mis.bitmap_fd = -1;
	mis.bitmap_file = NULL;
	mis.name[0] = 0;
	mis.container = NULL;
	mis.member = NULL;

	for (w=dl_next(line); w!=line; w=dl_next(w)) {
		if (w[0] == '/' || strchr(w, '=') == NULL) {
			/* This names the device, or is '<ignore>'.
			 * The rules match those in create_mddev.
			 * 'w' must be:
			 *  /dev/md/{anything}
			 *  /dev/mdNN
			 *  /dev/md_dNN
			 *  <ignore>
			 *  or anything that doesn't start '/' or '<'
			 */
			if (strcasecmp(w, "<ignore>") == 0 ||
			    strncmp(w, "/dev/md/", 8) == 0 ||
			    (w[0] != '/' && w[0] != '<') ||
			    (strncmp(w, "/dev/md", 7) == 0 &&
			     is_number(w+7)) ||
			    (strncmp(w, "/dev/md_d", 9) == 0 &&
			     is_number(w+9))
				) {
				/* This is acceptable */;
				if (mis.devname)
					pr_err("only give one "
						"device per ARRAY line: %s and %s\n",
						mis.devname, w);
				else
					mis.devname = w;
			}else {
				pr_err("%s is an invalid name for "
					"an md device - ignored.\n", w);
			}
		} else if (strncasecmp(w, "uuid=", 5)==0 ) {
			if (mis.uuid_set)
				pr_err("only specify uuid once, %s ignored.\n",
					w);
			else {
				if (parse_uuid(w+5, mis.uuid))
					mis.uuid_set = 1;
				else
					pr_err("bad uuid: %s\n", w);
			}
		} else if (strncasecmp(w, "super-minor=", 12)==0 ) {
			if (mis.super_minor != UnSet)
				pr_err("only specify super-minor once, %s ignored.\n",
					w);
			else {
				char *endptr;
				int minor = strtol(w+12, &endptr, 10);

				if (w[12]==0 || endptr[0]!=0 || minor < 0)
					pr_err("invalid super-minor number: %s\n",
						w);
				else
					mis.super_minor = minor;
			}
		} else if (strncasecmp(w, "name=", 5)==0) {
			if (mis.name[0])
				pr_err("only specify name once, %s ignored.\n",
					w);
			else if (strlen(w+5) > 32)
				pr_err("name too long, ignoring %s\n", w);
			else
				strcpy(mis.name, w+5);

		} else if (strncasecmp(w, "bitmap=", 7) == 0) {
			if (mis.bitmap_file)
				pr_err("only specify bitmap file once. %s ignored\n",
					w);
			else
				mis.bitmap_file = xstrdup(w+7);

		} else if (strncasecmp(w, "devices=", 8 ) == 0 ) {
			if (mis.devices)
				pr_err("only specify devices once (use a comma separated list). %s ignored\n",
					w);
			else
				mis.devices = xstrdup(w+8);
		} else if (strncasecmp(w, "spare-group=", 12) == 0 ) {
			if (mis.spare_group)
				pr_err("only specify one spare group per array. %s ignored.\n",
					w);
			else
				mis.spare_group = xstrdup(w+12);
		} else if (strncasecmp(w, "level=", 6) == 0 ) {
			/* this is mainly for compatability with --brief output */
			mis.level = map_name(pers, w+6);
		} else if (strncasecmp(w, "disks=", 6) == 0 ) {
			/* again, for compat */
			mis.raid_disks = atoi(w+6);
		} else if (strncasecmp(w, "num-devices=", 12) == 0 ) {
			/* again, for compat */
			mis.raid_disks = atoi(w+12);
		} else if (strncasecmp(w, "spares=", 7) == 0 ) {
			/* for warning if not all spares present */
			mis.spare_disks = atoi(w+7);
		} else if (strncasecmp(w, "metadata=", 9) == 0) {
			/* style of metadata on the devices. */
			int i;

			for(i=0; superlist[i] && !mis.st; i++)
				mis.st = superlist[i]->match_metadata_desc(w+9);

			if (!mis.st)
				pr_err("metadata format %s unknown, ignored.\n", w+9);
		} else if (strncasecmp(w, "auto=", 5) == 0 ) {
			/* whether to create device special files as needed */
			mis.autof = parse_auto(w+5, "auto type", 0);
		} else if (strncasecmp(w, "member=", 7) == 0) {
			/* subarray within a container */
			mis.member = xstrdup(w+7);
		} else if (strncasecmp(w, "container=", 10) == 0) {
			/* the container holding this subarray.  Either a device name
			 * or a uuid */
			mis.container = xstrdup(w+10);
		} else {
			pr_err("unrecognised word on ARRAY line: %s\n",
				w);
		}
	}
	if (mis.uuid_set == 0 && mis.devices == NULL &&
	    mis.super_minor == UnSet && mis.name[0] == 0 &&
	    (mis.container == NULL || mis.member == NULL))
		pr_err("ARRAY line %s has no identity information.\n", mis.devname);
	else {
		mi = xmalloc(sizeof(*mi));
		*mi = mis;
		mi->devname = mis.devname ? xstrdup(mis.devname) : NULL;
		mi->next = NULL;
		*mddevlp = mi;
		mddevlp = &mi->next;
	}
}
Esempio n. 13
0
static int fake_xen_sysctl(int handle, struct xen_sysctl *sysctl)
{
	#define SYSCTLcmd "sysctl"
	switch (sysctl->cmd) {
	case XEN_SYSCTL_getdomaininfolist: {
		xc_domaininfo_t *info; int num, i;

		get_xen_guest_handle(info, sysctl->u.getdomaininfolist.buffer);

		marshall_command(handle, "%s,%d,%d,%d\n", SYSCTLcmd, sysctl->cmd,
		                 sysctl->u.getdomaininfolist.first_domain,
		                 sysctl->u.getdomaininfolist.max_domains);
		num = unmarshall_int(handle);
		for (i = 0; i < num; i++) {
			int uuid[16], j, flags;
			char **ret;
			
			ret = unmarshall_multiple(handle);
			if (!ret)
				return -EBADF;

			/* domid,uuid,flags */
			info->domain = atoi(ret[0]);

			parse_uuid(ret[1], uuid);
			for (j = 0; j < 16; j++)
				info->handle[j] = uuid[j] & 0xff;

			flags = atoi(ret[2]);
			info->flags = 0;
			if (flags & 0x1) info->flags |= XEN_DOMINF_dying;
			if (flags & 0x2) info->flags |= XEN_DOMINF_shutdown;
			if (flags & 0x4) info->flags |= XEN_DOMINF_paused;
			if (flags & 0x8) info->flags |= XEN_DOMINF_blocked;
			if (flags & 0x10) info->flags |= XEN_DOMINF_running;
			if (flags & 0x20) info->flags |= XEN_DOMINF_hvm_guest;
			info->flags |= ((flags >> 8) & 0xff) << XEN_DOMINF_shutdownshift;

			info->nr_online_vcpus = atoi(ret[3]);
			info->max_vcpu_id = atoi(ret[4]);

			info->tot_pages = atoi(ret[5]);
			info->max_pages = atoi(ret[6]);
			info->shared_info_frame = atoi(ret[7]);
			info->cpu_time = atoi(ret[8]);
			info->ssidref = atoi(ret[9]);

			string_split_free(ret);
			info++;

		}
		sysctl->u.getdomaininfolist.num_domains = num;
		return unmarshall_return(handle);
		}
	case XEN_SYSCTL_readconsole:
	case XEN_SYSCTL_debug_keys:
		return 0;
	case XEN_SYSCTL_physinfo: {
		char **ret;
		int sockets_per_node;

		marshall_command(handle, "%s,%d\n", SYSCTLcmd, sysctl->cmd);
		ret = unmarshall_multiple(handle);
		if (!ret) return -EBADF;

		sockets_per_node = atoi(ret[2]);

		sysctl->u.physinfo.threads_per_core = atoi(ret[0]);
		sysctl->u.physinfo.cores_per_socket = atoi(ret[1]);
#if XEN_SYSCTL_INTERFACE_VERSION < 6
		sysctl->u.physinfo.sockets_per_node = sockets_per_node;
#endif
		sysctl->u.physinfo.nr_nodes = atoi(ret[3]);
#if XEN_SYSCTL_INTERFACE_VERSION >= 6
		sysctl->u.physinfo.nr_cpus =
			sysctl->u.physinfo.threads_per_core *
			sysctl->u.physinfo.cores_per_socket *
			sockets_per_node *
			sysctl->u.physinfo.nr_nodes;
#endif
		sysctl->u.physinfo.cpu_khz = atoi(ret[4]);
		sysctl->u.physinfo.total_pages = atoi(ret[5]);
		sysctl->u.physinfo.free_pages = atoi(ret[6]);
		sysctl->u.physinfo.scrub_pages = 0;

		string_split_free(ret);
		return unmarshall_return(handle);
		}
	case XEN_SYSCTL_getcpuinfo: {
		uint64_t *info;
		int num, i;

		get_xen_guest_handle(info, sysctl->u.getcpuinfo.info);
		marshall_command(handle, "%s,%d,%d\n", SYSCTLcmd, sysctl->cmd, sysctl->u.getcpuinfo.max_cpus);
		num = unmarshall_int(handle);
		for (i = 0; i < num; i++) {
			info[i] = unmarshall_int64(handle);
		}
		return unmarshall_return(handle);
		}
	case XEN_SYSCTL_sched_id:
		return 0;
	default:
		return -EINVAL;
	}
	return 0;
}
Esempio n. 14
0
static int plooptool_mount(int argc, char **argv)
{
	int i, f, ret = 0;
	int raw = 0;
	struct ploop_mount_param mountopts = {};
	const char *component_name = NULL;

	while ((i = getopt(argc, argv, "rFf:d:m:t:u:o:b:c:")) != EOF) {
		switch (i) {
		case 'd':
			strncpy(mountopts.device, optarg, sizeof(mountopts.device)-1);
			break;
		case 'r':
			mountopts.ro = 1;
			break;
		case 'F':
			mountopts.fsck = 1;
			break;
		case 'f':
			f = parse_format_opt(optarg);
			if (f < 0) {
				usage_mount();
				return SYSEXIT_PARAM;
			}
			raw = (f == PLOOP_RAW_MODE);
			break;
		case 'm':
			mountopts.target = strdup(optarg);
			break;
		case 't':
			mountopts.fstype = strdup(optarg);
			break;
		case 'u':
			mountopts.guid = parse_uuid(optarg);
			if (!mountopts.guid)
				return SYSEXIT_PARAM;

			break;
		case 'o':
			mountopts.mount_data = strdup(optarg);
			break;
		case 'b': {
			  char * endptr;

			  mountopts.blocksize = strtoul(optarg, &endptr, 0);
			  if (*endptr != '\0') {
				  usage_mount();
				  return SYSEXIT_PARAM;
			  }
			  break;
		case 'c':
			component_name = optarg;
			break;
		}
		default:
			usage_mount();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if (argc < 1) {
		usage_mount();
		return SYSEXIT_PARAM;
	}

	if (argc == 1 && is_xml_fname(argv[0]))
	{
		struct ploop_disk_images_data *di;
		ret = ploop_open_dd(&di, argv[0]);
		if (ret)
			return ret;

		if (component_name != NULL)
			ploop_set_component_name(di, component_name);

		ret = ploop_mount_image(di, &mountopts);

		ploop_close_dd(di);
	}
	else
		ret = ploop_mount(NULL, argv, &mountopts, raw);

	return ret;
}
Esempio n. 15
0
static int plooptool_replace(int argc, char **argv)
{
	int i;
	char dev[PATH_MAX];
	char *device = NULL;
	char *mnt = NULL;
	struct ploop_replace_param param = {
		.level = -1,
	};

	while ((i = getopt(argc, argv, "d:m:l:i:u:o:")) != EOF) {
		switch (i) {
		case 'd':
			device = optarg;
			break;
		case 'm':
			mnt = optarg;
			break;
		case 'l':
			param.level = atoi(optarg);
			break;
		case 'u':
			param.guid = parse_uuid(optarg);
			if (!param.guid)
				return SYSEXIT_PARAM;
			break;
		case 'i':
			param.file = strdup(optarg);
			break;
		case 'o':
			param.cur_file = strdup(optarg);
			break;
		default:
			usage_replace();
			return SYSEXIT_PARAM;
		}
	}

	argc -= optind;
	argv += optind;

	if (!param.file) {
		fprintf(stderr, "Error: image file not specified (use -i)\n");
		usage_replace();
		return SYSEXIT_PARAM;
	}

	if ((argc == 1) && is_xml_fname(argv[0])) {
		int ret;
		struct ploop_disk_images_data *di;

		/* only one way of choosing delta to replace */
		if ( (!!param.guid) + (param.level != -1) +
				(!!param.cur_file) != 1)  {
			fprintf(stderr, "Error: either one of uuid (-u), "
					"level (-l) or current file (-o) "
					"must be specified\n");
			usage_replace();
			return SYSEXIT_PARAM;
		}

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

		ret = ploop_replace_image(di, &param);
		ploop_close_dd(di);

		return ret;
	}
	else {
		int level = param.level;

		if (argc > 0) {
			usage_replace();
			return SYSEXIT_PARAM;
		}
		if ((!!device) + (!!mnt) != 1) {
			fprintf(stderr, "Error: either device (-d), mount "
					"point (-m) or DiskDescriptor.xml "
					"must be specified\n");
			usage_replace();
			return SYSEXIT_PARAM;
		}
		if (mnt) {
			if (ploop_get_dev_by_mnt(mnt, dev, sizeof(dev))) {
				fprintf(stderr, "Unable to find ploop device "
						"by mount point %s\n", mnt);
				return SYSEXIT_PARAM;
			}
			device = dev;
		}
		/* Either level or current delta must be specified */
		if ((level != -1) + (!!param.cur_file) != 1) {
			fprintf(stderr, "Error: either one of level (-l) or "
					"current delta file (-o) must be "
					"specified\n");
			usage_replace();
			return SYSEXIT_PARAM;
		}
		if (param.cur_file) {
			int ret;

			level = find_level_by_delta(device, param.cur_file);
			if (level < 0) {
				fprintf(stderr, "Can't find level by "
						"delta file name %s",
						param.cur_file);
				return SYSEXIT_PARAM;
			}

			ret = check_deltas_same(param.cur_file, param.file);
			if (ret)
				return ret;
		}

		return replace_delta(device, level, param.file);
	}
}

int main(int argc, char **argv)
{
	char * cmd;
	int v = 3;

	/* global options */
	while (argc > 1 && argv[1][0] == '-') {
		switch (argv[1][1]) {
			case 'v':
				switch (argv[1][2]) {
				    case '\0':
					v++;
					break;
				    case 'v': /* -vvv... */
					v += strlen(&argv[1][1]);
					break;
				    default: /* -vNN */
					v = atoi(&argv[1][2]);
				}
				break;
			case '-': /* long option */
				/* fall through */
			default:
				fprintf(stderr, "Bad option %s\n", argv[1]);
				usage_summary();
				return SYSEXIT_PARAM;
		}
		argc--;
		argv++;
	}

	if (argc < 2) {
		usage_summary();
		return SYSEXIT_PARAM;
	}

	cmd = argv[1];
	argc--;
	argv++;

	ploop_set_verbose_level(v);
	init_signals();

	if (strcmp(cmd, "init") == 0)
		return plooptool_init(argc, argv);
	if (strcmp(cmd, "start") == 0)
		return plooptool_start(argc, argv);
	if (strcmp(cmd, "stop") == 0)
		return plooptool_stop(argc, argv);
	if (strcmp(cmd, "clear") == 0)
		return plooptool_clear(argc, argv);
	if (strcmp(cmd, "mount") == 0)
		return plooptool_mount(argc, argv);
	if (strcmp(cmd, "umount") == 0)
		return plooptool_umount(argc, argv);
	if (strcmp(cmd, "delete") == 0 || strcmp(cmd, "rm") == 0)
		return plooptool_rm(argc, argv);
	if (strcmp(cmd, "snapshot") == 0)
		return plooptool_snapshot(argc, argv);
	if (strcmp(cmd, "tsnapshot") == 0)
		return plooptool_tsnapshot(argc, argv);
	if (strcmp(cmd, "snapshot-switch") == 0)
		return plooptool_snapshot_switch(argc, argv);
	if (strcmp(cmd, "snapshot-delete") == 0)
		return plooptool_snapshot_delete(argc, argv);
	if (strcmp(cmd, "snapshot-merge") == 0)
		return plooptool_snapshot_merge(argc, argv);
	if (strcmp(cmd, "snapshot-list") == 0)
		return plooptool_snapshot_list(argc, argv);
	if (strcmp(cmd, "getdev") == 0)
		return plooptool_getdevice(argc, argv);
	if (strcmp(cmd, "resize") == 0)
		return plooptool_resize(argc, argv);
	if (strcmp(cmd, "convert") == 0)
		return plooptool_convert(argc, argv);
	if (strcmp(cmd, "info") == 0)
		return plooptool_info(argc, argv);
	if (strcmp(cmd, "list") == 0)
		return plooptool_list(argc, argv);
	if (strcmp(cmd, "check") == 0)
		return plooptool_check(argc, argv);
	if (strcmp(cmd, "fsck") == 0) {
		fprintf(stderr, "WARNING: ploop fsck command is obsoleted, "
				"please use ploop check\n");
		return plooptool_check(argc, argv);
	}
	if (strcmp(cmd, "grow") == 0)
		return plooptool_grow(argc, argv);
	if (strcmp(cmd, "merge") == 0)
		return plooptool_merge(argc, argv);
	if (strcmp(cmd, "stat") == 0)
		return plooptool_stat(argc, argv);
	if (strcmp(cmd, "copy") == 0)
		return plooptool_copy(argc, argv);
	if (strcmp(cmd, "replace") == 0)
		return plooptool_replace(argc, argv);

	if (cmd[0] != '-') {
		char ** nargs;

		nargs = calloc(argc+1, sizeof(char*));
		nargs[0] = malloc(sizeof("ploop-") + strlen(cmd));
		sprintf(nargs[0], "ploop-%s", cmd);
		memcpy(nargs + 1, argv + 1, (argc - 1)*sizeof(char*));
		nargs[argc] = NULL;

		execvp(nargs[0], nargs);
	}

	usage_summary();
	return SYSEXIT_PARAM;
}
Esempio n. 16
0
void arrayline(char *line)
{
	char *w;

	struct mddev_ident_s mis;
	mddev_ident_t mi;

	mis.uuid_set = 0;
	mis.super_minor = UnSet;
	mis.level = UnSet;
	mis.raid_disks = UnSet;
	mis.spare_disks = 0;
	mis.devices = NULL;
	mis.devname = NULL;
	mis.spare_group = NULL;
	mis.autof = 0;
	mis.next = NULL;
	mis.st = NULL;
	mis.bitmap_fd = -1;
	mis.bitmap_file = NULL;
	mis.name[0] = 0;

	for (w=dl_next(line); w!=line; w=dl_next(w)) {
		if (w[0] == '/') {
			if (mis.devname)
				fprintf(stderr, Name ": only give one device per ARRAY line: %s and %s\n",
					mis.devname, w);
			else mis.devname = w;
		} else if (strncasecmp(w, "uuid=", 5)==0 ) {
			if (mis.uuid_set)
				fprintf(stderr, Name ": only specify uuid once, %s ignored.\n",
					w);
			else {
				if (parse_uuid(w+5, mis.uuid))
					mis.uuid_set = 1;
				else
					fprintf(stderr, Name ": bad uuid: %s\n", w);
			}
		} else if (strncasecmp(w, "super-minor=", 12)==0 ) {
			if (mis.super_minor != UnSet)
				fprintf(stderr, Name ": only specify super-minor once, %s ignored.\n",
					w);
			else {
				char *endptr;
				mis.super_minor= strtol(w+12, &endptr, 10);
				if (w[12]==0 || endptr[0]!=0 || mis.super_minor < 0) {
					fprintf(stderr, Name ": invalid super-minor number: %s\n",
						w);
					mis.super_minor = UnSet;
				}
			}
		} else if (strncasecmp(w, "name=", 5)==0) {
			if (mis.name[0])
				fprintf(stderr, Name ": only specify name once, %s ignored.\n",
					w);
			else if (strlen(w+5) > 32)
				fprintf(stderr, Name ": name too long, ignoring %s\n", w);
			else
				strcpy(mis.name, w+5);

		} else if (strncasecmp(w, "bitmap=", 7) == 0) {
			if (mis.bitmap_file)
				fprintf(stderr, Name ": only specify bitmap file once. %s ignored\n",
					w);
			else
				mis.bitmap_file = strdup(w+7);

		} else if (strncasecmp(w, "devices=", 8 ) == 0 ) {
			if (mis.devices)
				fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n",
					w);
			else
				mis.devices = strdup(w+8);
		} else if (strncasecmp(w, "spare-group=", 12) == 0 ) {
			if (mis.spare_group)
				fprintf(stderr, Name ": only specify one spare group per array. %s ignored.\n",
					w);
			else
				mis.spare_group = strdup(w+12);
		} else if (strncasecmp(w, "level=", 6) == 0 ) {
			/* this is mainly for compatability with --brief output */
			mis.level = map_name(pers, w+6);
		} else if (strncasecmp(w, "disks=", 6) == 0 ) {
			/* again, for compat */
			mis.raid_disks = atoi(w+6);
		} else if (strncasecmp(w, "num-devices=", 12) == 0 ) {
			/* again, for compat */
			mis.raid_disks = atoi(w+12);
		} else if (strncasecmp(w, "spares=", 7) == 0 ) {
			/* for warning if not all spares present */
			mis.spare_disks = atoi(w+7);
		} else if (strncasecmp(w, "metadata=", 9) == 0) {
			/* style of metadata on the devices. */
			int i;
			
			for(i=0; superlist[i] && !mis.st; i++)
				mis.st = superlist[i]->match_metadata_desc(w+9);

			if (!mis.st)
				fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9);
		} else if (strncasecmp(w, "auto=", 5) == 0 ) {
			/* whether to create device special files as needed */
			mis.autof = parse_auto(w+5, "auto type", 0);
		} else {
			fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n",
				w);
		}
	}
	if (mis.devname == NULL)
		fprintf(stderr, Name ": ARRAY line with no device\n");
	else if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0)
		fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname);
	else {
		mi = malloc(sizeof(*mi));
		*mi = mis;
		mi->devname = strdup(mis.devname);
		mi->next = NULL;
		*mddevlp = mi;
		mddevlp = &mi->next;
	}
}
Esempio n. 17
0
int
cmd_remove(int argc, char *argv[])
{
	char *p;
	int ch;
	int flags = 0;
	gd_t gd;

	/* Get the remove options */
	while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) {
		switch(ch) {
		case 'a':
			if (all > 0)
				usage_remove();
			all = 1;
			break;
		case 'b':
			if (block > 0)
				usage_remove();
			block = strtoll(optarg, &p, 10);
			if (*p != 0 || block < 1)
				usage_remove();
			break;
		case 'i':
			if (entry > 0)
				usage_remove();
			entry = strtol(optarg, &p, 10);
			if (*p != 0 || entry < 1)
				usage_remove();
			break;
		case 's':
			if (size > 0)
				usage_remove();
			size = strtoll(optarg, &p, 10);
			if (*p != 0 || size < 1)
				usage_remove();
			break;
		case 't':
			if (!uuid_is_nil(&type, NULL))
				usage_remove();
			if (parse_uuid(optarg, &type) != 0)
				usage_remove();
			break;
		default:
			usage_remove();
		}
	}

	if (!all ^
	    (block > 0 || entry > 0 || size > 0 || !uuid_is_nil(&type, NULL)))
		usage_remove();

	if (argc == optind)
		usage_remove();

	while (optind < argc) {
		gd = gpt_open(argv[optind++], flags);
		if (gd == NULL) {
			continue;
		}

		rem(gd);

		gpt_close(gd);
	}

	return (0);
}
Esempio n. 18
0
static void udisks2_add_device( const char *udi, DBusMessageIter *dict, DBusMessageIter *block )
{
    DBusMessageIter iter, variant, paths, string;
    const char *device = NULL;
    const char *mount_point = NULL;
    const char *type = NULL;
    const char *drive = NULL;
    GUID guid, *guid_ptr = NULL;
    const char *iface, *name;
    int removable = FALSE;
    enum device_type drive_type = DEVICE_UNKNOWN;

    while ((iface = udisks_next_dict_entry( block, &iter )))
    {
        if (!strcmp( iface, "org.freedesktop.UDisks2.Filesystem" ))
        {
            while ((name = udisks_next_dict_entry( &iter, &variant )))
            {
                if (!strcmp( name, "MountPoints" ))
                {
                    p_dbus_message_iter_recurse( &variant, &paths );
                    if (p_dbus_message_iter_get_arg_type( &paths ) == DBUS_TYPE_ARRAY)
                    {
                        p_dbus_message_iter_recurse( &variant, &string );
                        mount_point = udisks2_string_from_array( &string );
                    }
                }
            }
        }
        if (!strcmp( iface, "org.freedesktop.UDisks2.Block" ))
        {
            while ((name = udisks_next_dict_entry( &iter, &variant )))
            {
                if (!strcmp( name, "Device" ))
                    device = udisks2_string_from_array( &variant );
                else if (!strcmp( name, "IdType" ))
                    p_dbus_message_iter_get_basic( &variant, &type );
                else if (!strcmp( name, "Drive" ))
                {
                    p_dbus_message_iter_get_basic( &variant, &drive );
                    udisks2_get_drive_info( drive, dict, &drive_type, &removable );
                }
                else if (!strcmp( name, "IdUUID" ))
                {
                    const char *uuid_str;
                    if (p_dbus_message_iter_get_arg_type( &variant ) == DBUS_TYPE_ARRAY)
                        uuid_str = udisks2_string_from_array( &variant );
                    else
                        p_dbus_message_iter_get_basic( &variant, &uuid_str );
                    guid_ptr = parse_uuid( &guid, uuid_str );
                }
            }
        }
    }

    TRACE( "udi %s device %s mount point %s uuid %s type %s removable %u\n",
           debugstr_a(udi), debugstr_a(device), debugstr_a(mount_point),
           debugstr_guid(guid_ptr), debugstr_a(type), removable );

    if (type)
    {
        if (!strcmp( type, "iso9660" ))
        {
            removable = TRUE;
            drive_type = DEVICE_CDROM;
        }
        else if (!strcmp( type, "udf" ))
        {
            removable = TRUE;
            drive_type = DEVICE_DVD;
        }
    }
    if (device)
    {
        if (removable) add_dos_device( -1, udi, device, mount_point, drive_type, guid_ptr );
        else if (guid_ptr) add_volume( udi, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr );
    }
}