Exemple #1
0
static int do_ubirename(int argc, char *argv[])
{
	struct ubi_rnvol_req req;
	u32 ubi_num;
	int i, j, fd, ret;

	if ((argc < 4) || (argc % 2))
		return COMMAND_ERROR_USAGE;

	req.count = (argc / 2) - 1;
	if (req.count > UBI_MAX_RNVOL) {
		printf("too many volume renames. (max: %u)\n", UBI_MAX_RNVOL);
		return COMMAND_ERROR_USAGE;
	}

	fd = open(argv[1], O_WRONLY);
	if (fd < 0) {
		perror("unable to open the UBI device");
		return 1;
	}

	ret = ioctl(fd, UBI_IOCGETUBINUM, &ubi_num);

	close(fd);

	if (ret) {
		printf("failed to get ubi num for %s: %s\n", argv[1], strerror(-ret));
		return 1;
	}

	for (i = 2, j = 0; i < argc; ++j, i += 2) {
		req.ents[j].vol_id = get_vol_id(ubi_num, argv[i]);

		if (req.ents[j].vol_id < 0) {
			printf("Volume '%s' does not exist on %s\n", argv[i], argv[1]);
			ret = -EINVAL;
			goto err;
		}

		strncpy(req.ents[j].name, argv[i + 1], UBI_MAX_VOLUME_NAME);
		req.ents[j].name_len = strlen(req.ents[j].name);
	}

	ret = ubi_api_rename_volumes(ubi_num, &req);
	if (ret)
		printf("failed to rename: %s", strerror(-ret));
err:
	return ret ? 1 : 0;
};
Exemple #2
0
int main(int argc, char * const argv[])
{
	int i, err;
	int count = 0;
	libubi_t libubi;
	struct ubi_dev_info dev_info;
	struct ubi_rnvol_req rnvol;
	const char *node;

	if (argc < 3 || (argc & 1) == 1) {
		errmsg("too few arguments");
		fprintf(stderr, "%s\n", usage);
		return -1;
	}

	if (argc > UBI_MAX_RNVOL + 2) {
		errmsg("too many volumes to re-name, max. is %d",
		       UBI_MAX_RNVOL);
		return -1;
	}

	node = argv[1];
	libubi = libubi_open();
	if (!libubi) {
		if (errno == 0)
			return errmsg("UBI is not present in the system");
		return sys_errmsg("cannot open libubi");
	}

	err = ubi_probe_node(libubi, node);
	if (err == 2) {
		errmsg("\"%s\" is an UBI volume node, not an UBI device node",
		       node);
		goto out_libubi;
	} else if (err < 0) {
		if (errno == ENODEV)
			errmsg("\"%s\" is not an UBI device node", node);
		else
			sys_errmsg("error while probing \"%s\"", node);
		goto out_libubi;
	}

	err = ubi_get_dev_info(libubi, node, &dev_info);
	if (err == -1) {
		sys_errmsg("cannot get information about UBI device \"%s\"", node);
		goto out_libubi;
	}

	for (i = 2; i < argc; i += 2) {
		err = get_vol_id(libubi, &dev_info, argv[i]);
		if (err == -1) {
			errmsg("\"%s\" volume not found", argv[i]);
			goto out_libubi;
		}

		rnvol.ents[count].vol_id = err;
		rnvol.ents[count].name_len = strlen(argv[i + 1]);
		strcpy(rnvol.ents[count++].name, argv[i + 1]);
	}

	rnvol.count = count;

	err = ubi_rnvols(libubi, node, &rnvol);
	if (err == -1) {
		sys_errmsg("cannot rename volumes");
		goto out_libubi;
	}

	libubi_close(libubi);
	return 0;

out_libubi:
	libubi_close(libubi);
	return -1;
}