Exemple #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;
}
static int probe_superblocks(blkid_probe pr)
{
    struct stat st;
    int rc;

    if (fstat(blkid_probe_get_fd(pr), &st))
        return -1;

    blkid_probe_enable_partitions(pr, 1);

    if (!S_ISCHR(st.st_mode) &&
            blkid_probe_get_size(pr) <= 1024 * 1440 &&
            blkid_probe_is_wholedisk(pr)) {
        /*
         * check if the small disk is partitioned, if yes then
         * don't probe for filesystems.
         */
        blkid_probe_enable_superblocks(pr, 0);

        rc = blkid_do_fullprobe(pr);
        if (rc < 0)
            return rc;        /* -1 = error, 1 = nothing, 0 = success */

        if (blkid_probe_lookup_value(pr, "PTTYPE", NULL, NULL) == 0)
            return 0;        /* partition table detected */
    }

    blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
    blkid_probe_enable_superblocks(pr, 1);

    return blkid_do_safeprobe(pr);
}
Exemple #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;
}
Exemple #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;
}