Пример #1
0
int main(int argc, char **argv, char **envp)
{
    int target, source, ret;
    char *sourcefname = NULL;
    size_t wsize = DEFAULT_WSIZE;

    /* Parse options */
    while (1) {
        ret = getopt(argc, argv, "f:s:");
        if (ret == -1)
            break;
        switch(ret) {
        case 'f':
            sourcefname = optarg;
            break;
        case 's':
            wsize = (size_t)atol(optarg);
            if (wsize < 1)
                die("incorrect size", 0);
            break;
        default:
            die("unknown getopt failure", 0);
            break;
        }
    }
    if (argc - optind != 1)
        usage("you must specify one target device", argv[0]);

    /* Get target */
    target = open(argv[optind], O_WRONLY);
    if (target < 0)
        die("failed to open device", 1);

    /* Get source */
    if (sourcefname) {
        source = open(sourcefname, O_RDONLY);
        if (source < 0)
            die("failed to open source", 1);
    } else {
        source = 0;
    }

    /* Wipe device */
    ret = do_wipe(source, target, wsize);

    /* Clean up */
    close(source);
    close(target);
    if (ret)
        die("failed to wipe device", 0);
    return 0;
}
Пример #2
0
int unlink( const char *pathname )
{
	struct stat st;

	lstat(pathname, &st);
//printf("%x %d %d\n", st.st_mode, S_ISLNK(st.st_mode), S_ISREG(st.st_mode));
	if (S_ISREG(st.st_mode)==1) {
		if (do_wipe(pathname, st.st_blksize))
			return -1;
	}

	return (int)(__unlink( pathname ));
}
Пример #3
0
int unlink (const char *pathname) {
    struct stat st;

    if (!__REAL_unlink__)
        _libwipe_init ();
    lstat (pathname, &st);
    //printf("%x %d %d\n", st.st_mode, S_ISLNK(st.st_mode), S_ISREG(st.st_mode));
    if (S_ISREG (st.st_mode)==1) {
        pf ("[libwipe] wipe %s\n", pathname);
        if (do_wipe (pathname, st.st_blksize)) {
            p ("[libwipe] wipe has failed\n");
            return -1;
        }
    }
    if (__REAL_unlink__) {
        int ret = (int)(__REAL_unlink__ (pathname));
        pf ("[libwipe] rm %s\n", pathname);
        return ret;
    }
    pf ("[libwipe] real unlink not resolved %p\n", __REAL_unlink__);
    return 0;
}
Пример #4
0
int
main(int argc, char **argv)
{
	struct wipe_desc *wp = NULL;
	int c, all = 0, has_offset = 0, noact = 0, mode = 0;
	const char *fname;

	struct option longopts[] = {
	    { "all",       0, 0, 'a' },
	    { "help",      0, 0, 'h' },
	    { "no-act",    0, 0, 'n' },
	    { "offset",    1, 0, 'o' },
	    { "parsable",  0, 0, 'p' },
	    { NULL,        0, 0, 0 }
	};

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

	while ((c = getopt_long(argc, argv, "ahno:p", longopts, NULL)) != -1) {
		switch(c) {
		case 'a':
			all++;
			break;
		case 'h':
			usage(stdout);
			break;
		case 'n':
			noact++;
			break;
		case 'o':
			wp = add_offset(wp, strtoll_offset(optarg), 1);
			has_offset++;
			break;
		case 'p':
			mode = WP_MODE_PARSABLE;
			break;
		default:
			usage(stderr);
			break;
		}
	}

	if (wp && all)
		errx(EXIT_FAILURE, _("--offset and --all are mutually exclusive"));
	if (optind == argc)
		usage(stderr);

	fname = argv[optind++];

	wp = read_offsets(wp, fname, all);

	if (wp) {
		if (has_offset || all)
			do_wipe(wp, fname, noact);
		else
			print_all(wp, mode);

		free_wipe(wp);
	}
	return EXIT_SUCCESS;
}
Пример #5
0
int
main(int argc, char **argv)
{
	struct wipe_desc *wp0 = NULL, *wp;
	int c, all = 0, has_offset = 0, noact = 0, quiet = 0;
	int mode = WP_MODE_PRETTY;

	static const struct option longopts[] = {
	    { "all",       0, 0, 'a' },
	    { "help",      0, 0, 'h' },
	    { "no-act",    0, 0, 'n' },
	    { "offset",    1, 0, 'o' },
	    { "parsable",  0, 0, 'p' },
	    { "quiet",     0, 0, 'q' },
	    { "types",     1, 0, 't' },
	    { "version",   0, 0, 'V' },
	    { NULL,        0, 0, 0 }
	};

	static const ul_excl_t excl[] = {       /* rows and cols in in ASCII order */
		{ 'a','o' },
		{ 0 }
	};
	int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;

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

	while ((c = getopt_long(argc, argv, "ahno:pqt:V", longopts, NULL)) != -1) {

		err_exclusive_options(c, longopts, excl, excl_st);

		switch(c) {
		case 'a':
			all++;
			break;
		case 'h':
			usage(stdout);
			break;
		case 'n':
			noact++;
			break;
		case 'o':
			wp0 = add_offset(wp0, strtosize_or_err(optarg,
					 _("invalid offset argument")), 1);
			has_offset++;
			break;
		case 'p':
			mode = WP_MODE_PARSABLE;
			break;
		case 'q':
			quiet++;
			break;
		case 't':
			type_pattern = optarg;
			break;
		case 'V':
			printf(_("%s from %s\n"), program_invocation_short_name,
				PACKAGE_STRING);
			return EXIT_SUCCESS;
		default:
			usage(stderr);
			break;
		}
	}

	if (optind == argc)
		usage(stderr);

	if (!all && !has_offset) {
		/*
		 * Print only
		 */
		while (optind < argc) {
			wp0 = read_offsets(NULL, argv[optind++]);
			if (wp0)
				print_all(wp0, mode);
			free_wipe(wp0);
		}
	} else {
		/*
		 * Erase
		 */
		while (optind < argc) {
			wp = clone_offset(wp0);
			wp = do_wipe(wp, argv[optind++], noact, all, quiet);
			free_wipe(wp);
		}
	}

	return EXIT_SUCCESS;
}
Пример #6
0
int
main(int argc, char **argv)
{
	struct wipe_desc *wp0 = NULL, *wp;
	int c, has_offset = 0, flags = 0;
	int mode = WP_MODE_PRETTY;

	static const struct option longopts[] = {
	    { "all",       0, 0, 'a' },
	    { "backup",    0, 0, 'b' },
	    { "force",     0, 0, 'f' },
	    { "help",      0, 0, 'h' },
	    { "no-act",    0, 0, 'n' },
	    { "offset",    1, 0, 'o' },
	    { "parsable",  0, 0, 'p' },
	    { "quiet",     0, 0, 'q' },
	    { "types",     1, 0, 't' },
	    { "version",   0, 0, 'V' },
	    { NULL,        0, 0, 0 }
	};

	static const ul_excl_t excl[] = {       /* rows and cols in in ASCII order */
		{ 'a','o' },
		{ 0 }
	};
	int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;

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

	while ((c = getopt_long(argc, argv, "afhno:pqt:V", longopts, NULL)) != -1) {

		err_exclusive_options(c, longopts, excl, excl_st);

		switch(c) {
		case 'a':
			flags |= WP_FL_ALL;
			break;
		case 'b':
			flags |= WP_FL_BACKUP;
			break;
		case 'f':
			flags |= WP_FL_FORCE;
			break;
		case 'h':
			usage(stdout);
			break;
		case 'n':
			flags |= WP_FL_NOACT;
			break;
		case 'o':
			wp0 = add_offset(wp0, strtosize_or_err(optarg,
					 _("invalid offset argument")), 1);
			has_offset++;
			break;
		case 'p':
			mode = WP_MODE_PARSABLE;
			break;
		case 'q':
			flags |= WP_FL_QUIET;
			break;
		case 't':
			type_pattern = optarg;
			break;
		case 'V':
			printf(UTIL_LINUX_VERSION);
			return EXIT_SUCCESS;
		default:
			usage(stderr);
			break;
		}
	}

	if (optind == argc)
		usage(stderr);

	if ((flags & WP_FL_BACKUP) && !((flags & WP_FL_ALL) || has_offset))
		warnx(_("The --backup option is meaningless in this context"));

	if (!(flags & WP_FL_ALL) && !has_offset) {
		/*
		 * Print only
		 */
		while (optind < argc) {
			wp0 = read_offsets(NULL, argv[optind++]);
			if (wp0)
				print_all(wp0, mode);
			free_wipe(wp0);
		}
	} else {
		/*
		 * Erase
		 */
		while (optind < argc) {
			wp = clone_offset(wp0);
			wp = do_wipe(wp, argv[optind++], flags);
			free_wipe(wp);
		}
	}

	return EXIT_SUCCESS;
}