Example #1
0
int
main(int argc, char **argv){
	int fd;

	if (argc != 3) {
		fprintf(stderr,
			"usage: %s diskdevice partitionnr\n",
			argv[0]);
		exit(1);
	}
	if ((fd = open(argv[1], O_RDONLY)) < 0) {
		perror(argv[1]);
		exit(1);
	}

	if (partx_del_partition(fd, atoi(argv[2])) == -1) {
		perror("BLKPG");
		exit(1);
	}
	return 0;
}
Example #2
0
int main(int argc, char **argv)
{
	int c, fd;

	static const struct option longopts[] = {
		{"help", no_argument, 0, 'h'},
		{"version", no_argument, 0, 'V'},
		{NULL, no_argument, 0, '0'},
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
		switch (c) {
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		case 'h':
			usage(stdout);
		default:
			errtryhelp(EXIT_FAILURE);
		}

	if (argc != 3)
		usage(stderr);


	if ((fd = open(argv[1], O_RDONLY)) < 0)
		err(EXIT_FAILURE, _("cannot open %s"), argv[1]);

	if (partx_del_partition(fd,
			strtou32_or_err(argv[2], _("invalid partition number argument"))))
		err(EXIT_FAILURE, _("failed to remove partition"));

	return EXIT_SUCCESS;
}