On Mon, Jul 23, 2012 at 11:51:05PM -0400, Ted Unangst wrote:
> I bring more love to everybody's favorite rm option.
>
> So I'm wiping a file from a fairly slow USB stick and it's taking
> forever. I don't really give a shit about some guy with a quantum
> tachyon microscope taking it apart, I just want the files to be gone
> enough that a simple undelete tool won't bring them back. The three
> wipes is the charm approach of rm -P is a little heavy handed.
If your USB "stick" is flash based, then you might be wasting your time
even trying to overwrite the file.
> What I propose is making -P wipe the file once each time it's
> provided. I get the simple whack the data for good option I want, the
> paranoid weirdos get the rm `jot -b -P 4096` scrubber they want.
I find the usage a little odd. What about something like 'rm -P -n 4096
filename', where '-n iterations' is optional and defaults to 3 if not
specified (and meaningless without -P). I don't know if anyone actually
relies on the current behavior, but that would keep a single '-P' the
same.
> @@ -308,14 +308,11 @@ rm_overwrite(char *file, struct stat *sb
> if ((buf = malloc(bsize)) == NULL)
> err(1, "%s: malloc", file);
>
> - if (!pass(0xff, fd, sbp->st_size, buf, bsize) || fsync(fd) ||
> - lseek(fd, (off_t)0, SEEK_SET))
> - goto err;
> - if (!pass(0x00, fd, sbp->st_size, buf, bsize) || fsync(fd) ||
> - lseek(fd, (off_t)0, SEEK_SET))
> - goto err;
> - if (!pass(0xff, fd, sbp->st_size, buf, bsize) || fsync(fd))
> - goto err;
> + for (i = 0; i < Pcount; i++) {
> + if (!pass(i & 0x1 ? 0xff : 0x00, fd, sbp->st_size, buf, bsize)
> ||
> + fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
> + goto err;
> + }
> close(fd);
> free(buf);
> return (1);
>
This chunk no longer matches the manual page. It reverses the pattern
mentioned. Rather than 0xff, 0x00, 0xff, etc... this change does 0x00,
0xff, 0x00, etc.