Ejemplo n.º 1
0
static struct wipe_desc *
do_wipe(struct wipe_desc *wp, const char *devname, int noact, int all, int quiet, int force)
{
	int flags;
	blkid_probe pr;
	struct wipe_desc *w, *wp0 = clone_offset(wp);
	int zap = all ? 1 : wp->zap;

	flags = O_RDWR;
	if (!force)
		flags |= O_EXCL;
	pr = new_probe(devname, flags);
	if (!pr)
		return NULL;

	while (blkid_do_probe(pr) == 0) {
		wp = get_desc_for_probe(wp, pr);
		if (!wp)
			break;

		/* Check if offset is in provided list */
		w = wp0;
		while(w && w->offset != wp->offset)
			w = w->next;
		if (wp0 && !w)
			continue;

		/* Mark done if found in provided list */
		if (w)
			w->on_disk = wp->on_disk;

		if (!wp->on_disk)
			continue;

		if (zap)
			do_wipe_real(pr, devname, wp, noact, quiet);
	}

	for (w = wp0; w != NULL; w = w->next) {
		if (!w->on_disk && !quiet)
			warnx(_("%s: offset 0x%jx not found"), devname, w->offset);
	}

	fsync(blkid_probe_get_fd(pr));
	close(blkid_probe_get_fd(pr));
	blkid_free_probe(pr);
	free_wipe(wp0);

	return wp;
}
Ejemplo n.º 2
0
static struct wipe_desc *
read_offsets(struct wipe_desc *wp, const char *devname)
{
	blkid_probe pr = new_probe(devname, 0);

	if (!pr)
		return NULL;

	while (blkid_do_probe(pr) == 0) {
		wp = get_desc_for_probe(wp, pr);
		if (!wp)
			break;
	}

	blkid_free_probe(pr);
	return wp;
}
Ejemplo n.º 3
0
static struct wipe_desc *
do_wipe(struct wipe_desc *wp, const char *devname, int flags)
{
	int mode = O_RDWR, reread = 0;
	blkid_probe pr;
	struct wipe_desc *w, *wp0;
	int zap = (flags & WP_FL_ALL) ? 1 : wp->zap;
	char *backup = NULL;

	if (!(flags & WP_FL_FORCE))
		mode |= O_EXCL;
	pr = new_probe(devname, mode);
	if (!pr)
		return NULL;

	if (zap && (flags & WP_FL_BACKUP)) {
		const char *home = getenv ("HOME");
		if (!home)
			errx(EXIT_FAILURE, _("failed to create a signature backup, $HOME undefined"));
		xasprintf (&backup, "%s/wipefs-%s-", home, basename(devname));
	}

	wp0 = clone_offset(wp);

	while (blkid_do_probe(pr) == 0) {
		wp = get_desc_for_probe(wp, pr);
		if (!wp)
			break;

		/* Check if offset is in provided list */
		w = wp0;
		while(w && w->offset != wp->offset)
			w = w->next;
		if (wp0 && !w)
			continue;

		/* Mark done if found in provided list */
		if (w)
			w->on_disk = wp->on_disk;

		if (!wp->on_disk)
			continue;

		if (zap) {
			if (backup)
				do_backup(wp, backup);
			do_wipe_real(pr, devname, wp, flags);
			if (wp->is_parttable)
				reread = 1;
		}
	}

	for (w = wp0; w != NULL; w = w->next) {
		if (!w->on_disk && !(flags & WP_FL_QUIET))
			warnx(_("%s: offset 0x%jx not found"), devname, w->offset);
	}

	fsync(blkid_probe_get_fd(pr));

	if (reread)
		rereadpt(blkid_probe_get_fd(pr), devname);

	close(blkid_probe_get_fd(pr));
	blkid_free_probe(pr);
	free_wipe(wp0);
	free(backup);

	return wp;
}
Ejemplo n.º 4
0
static struct wipe_desc *
do_wipe(struct wipe_desc *wp, const char *devname, int flags)
{
	int mode = O_RDWR, reread = 0, need_force = 0;
	blkid_probe pr;
	struct wipe_desc *w, *wp0;
	int zap = (flags & WP_FL_ALL) ? 1 : wp->zap;
	char *backup = NULL;

	if (!(flags & WP_FL_FORCE))
		mode |= O_EXCL;
	pr = new_probe(devname, mode);
	if (!pr)
		return NULL;

	if (zap && (flags & WP_FL_BACKUP)) {
		const char *home = getenv ("HOME");
		char *tmp = xstrdup(devname);

		if (!home)
			errx(EXIT_FAILURE, _("failed to create a signature backup, $HOME undefined"));
		xasprintf (&backup, "%s/wipefs-%s-", home, basename(tmp));
		free(tmp);
	}

	wp0 = clone_offset(wp);

	while (blkid_do_probe(pr) == 0) {
		wp = get_desc_for_probe(wp, pr);
		if (!wp)
			break;

		/* Check if offset is in provided list */
		w = wp0;
		while(w && w->offset != wp->offset)
			w = w->next;
		if (wp0 && !w)
			continue;

		/* Mark done if found in provided list */
		if (w)
			w->on_disk = wp->on_disk;

		if (!wp->on_disk)
			continue;

		if (!(flags & WP_FL_FORCE)
		    && wp->is_parttable
		    && !blkid_probe_is_wholedisk(pr)) {
			warnx(_("%s: ignoring nested \"%s\" partition table "
				"on non-whole disk device"), devname, wp->type);
			need_force = 1;
			continue;
		}

		if (zap) {
			if (backup)
				do_backup(wp, backup);
			do_wipe_real(pr, devname, wp, flags);
			if (wp->is_parttable)
				reread = 1;
		}
	}

	for (w = wp0; w != NULL; w = w->next) {
		if (!w->on_disk && !(flags & WP_FL_QUIET))
			warnx(_("%s: offset 0x%jx not found"), devname, (uintmax_t)w->offset);
	}

	if (need_force)
		warnx(_("Use the --force option to force erase."));

	fsync(blkid_probe_get_fd(pr));

#ifdef BLKRRPART
	if (reread && (mode & O_EXCL))
		rereadpt(blkid_probe_get_fd(pr), devname);
#endif

	close(blkid_probe_get_fd(pr));
	blkid_free_probe(pr);
	free_wipe(wp0);
	free(backup);

	return wp;
}