示例#1
0
int main(int argc, char * const argv[])
{
	if (initial_check(argc, argv))
		return 1;

	node = argv[1];

	libubi = libubi_open();
	if (libubi == NULL) {
		failed("libubi_open");
		return 1;
	}

	if (ubi_get_dev_info(libubi, node, &dev_info)) {
		failed("ubi_get_dev_info");
		goto close;
	}

	if (mkvol_basic())
		goto close;

	if (mkvol_alignment())
		goto close;

	if (mkvol_multiple())
		goto close;

	libubi_close(libubi);
	return 0;

close:
	libubi_close(libubi);
	return 1;
}
示例#2
0
int main(int argc, char * const argv[])
{
	if (initial_check(argc, argv))
		return 1;

	node = argv[1];

	libubi = libubi_open();
	if (libubi == NULL) {
		failed("libubi_open");
		return 1;
	}

	if (ubi_get_dev_info(libubi, node, &dev_info)) {
		failed("ubi_get_dev_info");
		goto close;
	}

	if (test_basic(UBI_DYNAMIC_VOLUME))
		goto close;
	if (test_basic(UBI_STATIC_VOLUME))
		goto close;
	if (test_rsvol(UBI_DYNAMIC_VOLUME))
		goto close;
	if (test_rsvol(UBI_STATIC_VOLUME))
		goto close;

	libubi_close(libubi);
	return 0;

close:
	libubi_close(libubi);
	return 1;
}
/**
 * __initial_check - check that common prerequisites which are required to run
 * tests.
 *
 * @test  test name
 * @argc  count of command-line arguments
 * @argv  command-line arguments
 *
 * This function returns %0 if all is fine and test may be run and %-1 if not.
 */
int __initial_check(const char *test, int argc, char * const argv[])
{
	libubi_t libubi;
	struct ubi_dev_info dev_info;

	/*
	 * All tests require UBI character device name as the first parameter,
	 * check this.
	 */
	if (argc < 2) {
		__err_msg(test, __FUNCTION__, __LINE__,
			  "UBI character device node is not specified");
		return -1;
	}

	libubi = libubi_open();
	if (libubi == NULL) {
		__failed(test, __FUNCTION__, __LINE__, "libubi_open");
		return -1;
	}

	if (ubi_get_dev_info(libubi, argv[1], &dev_info)) {
		__failed(test, __FUNCTION__, __LINE__, "ubi_get_dev_info");
		goto close;
	}

	if (dev_info.avail_lebs < MIN_AVAIL_EBS) {
		__err_msg(test, __FUNCTION__, __LINE__,
			  "insufficient available eraseblocks %d on UBI "
			  "device, required %d",
			  dev_info.avail_lebs, MIN_AVAIL_EBS);
		goto close;
	}

	if (dev_info.vol_count != 0) {
		__err_msg(test, __FUNCTION__, __LINE__,
			  "device %s is not empty", argv[1]);
		goto close;
	}

	libubi_close(libubi);
	return 0;

close:
	libubi_close(libubi);
	return -1;
}
示例#4
0
int main(int argc, char * const argv[])
{
	int i, ret;
	pthread_t threads[THREADS_NUM];

	if (initial_check(argc, argv))
		return 1;

	node = argv[1];

	libubi = libubi_open();
	if (libubi == NULL) {
		failed("libubi_open");
		return 1;
	}

	if (ubi_get_dev_info(libubi, node, &dev_info)) {
		failed("ubi_get_dev_info");
		goto close;
	}

	for (i = 0; i < THREADS_NUM; i++) {
		ret = pthread_create(&threads[i], NULL, &the_thread, (void*)(long)i);
		if (ret) {
			failed("pthread_create");
			goto close;
		}
	}

	for (i = 0; i < THREADS_NUM; i++)
		pthread_join(threads[i], NULL);

	libubi_close(libubi);
	return 0;

close:
	libubi_close(libubi);
	return 1;
}
示例#5
0
文件: io_paral.c 项目: mobilipia/iods
int main(int argc, char * const argv[])
{
	int i, ret;
	pthread_t threads[THREADS_NUM];
	struct ubi_mkvol_request req;
	long long mem_limit;

	if (initial_check(argc, argv))
		return 1;

	node = argv[1];

	libubi = libubi_open();
	if (libubi == NULL) {
		failed("libubi_open");
		return 1;
	}

	if (ubi_get_dev_info(libubi, node, &dev_info)) {
		failed("ubi_get_dev_info");
		goto close;
	}

	req.alignment = 1;
	mem_limit = memory_limit();
	if (mem_limit && mem_limit < dev_info.avail_bytes)
		total_bytes = req.bytes =
				(mem_limit / dev_info.eb_size / THREADS_NUM)
				* dev_info.eb_size;
	else
		total_bytes = req.bytes =
				((dev_info.avail_ebs - 3) / THREADS_NUM)
				* dev_info.eb_size;
	for (i = 0; i < THREADS_NUM; i++) {
		char name[100];

		req.vol_id = i;
		sprintf(&name[0], TESTNAME":%d", i);
		req.name = &name[0];
		req.vol_type = (i & 1) ? UBI_STATIC_VOLUME : UBI_DYNAMIC_VOLUME;

		if (ubi_mkvol(libubi, node, &req)) {
			failed("ubi_mkvol");
			goto remove;
		}
	}

	/* Create one volume with static data to make WL work more */
	req.vol_id = THREADS_NUM;
	req.name = TESTNAME ":static";
	req.vol_type = UBI_DYNAMIC_VOLUME;
	req.bytes = 3*dev_info.eb_size;
	if (ubi_mkvol(libubi, node, &req)) {
		failed("ubi_mkvol");
		goto remove;
	}

	for (i = 0; i < THREADS_NUM; i++) {
		ret = pthread_create(&threads[i], NULL, &the_thread, (void*)i);
		if (ret) {
			failed("pthread_create");
			goto remove;
		}
	}

	for (i = 0; i < THREADS_NUM; i++)
		pthread_join(threads[i], NULL);

	for (i = 0; i <= THREADS_NUM; i++) {
		if (ubi_rmvol(libubi, node, i)) {
			failed("ubi_rmvol");
			goto remove;
		}
	}

	libubi_close(libubi);
	return 0;

remove:
	for (i = 0; i <= THREADS_NUM; i++)
		ubi_rmvol(libubi, node, i);

close:
	libubi_close(libubi);
	return 1;
}
示例#6
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;
}