[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
rm hack
This is my first post to this list (I've spent a lot of time at misc@), and
certainly my first post where I'm actually contributing something, so please
pardon me if my ettiquete is imperfect.
I realized the other day that I'd like to be able to tell rm how many times
to overwrite something before I deleted it, instead of just relying on the
-P flag to do it three times. After sitting there annoyed for a while, I
realized that, duh, OpenBSD is open-source -- so I could just add the
functionality myself.
Thus, I've sat down and made a small, but hopefully useful, hack to rm; I've
attached a source diff for your perusal. Basically, I've taken the
rm_overwrite function's passthrough behavior and made it into a loop, which
runs as many times as the user specifies. User input is obtained through the
new -o flag, so -P's behavior is preserved. As far as I can tell, it works,
and I've not been able to break it yet.
I'd like to have the overwrite loop use a (possibly pseudo)random hex bit
each time through, but I'm not quite sure how to do that; I figured you all
might be able to give some suggestions on how to do so.
In any case, please see if you can break my work. If you can, I'll fix it;
if not, I'd like to see it added to -current.
Thanks,
Alex Kirk
68a69
> long owrite;
89a91,92
> extern char *optarg;
> char *endptr;
94c97
< while ((ch = getopt(argc, argv, "dfiPRrW")) != -1)
---
> while ((ch = getopt(argc, argv, "dfiPRrWo:")) != -1)
116a120,125
> case 'o':
> Pflag = 1;
> owrite = strtol(optarg, &endptr, 10);
> if (optarg[0] == 0 || *endptr != '\0')
> usage();
> break;
317a327
> int z, y;
343,348c353,362
< PASS(0xff);
< if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
< goto err;
< PASS(0x00);
< if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
< goto err;
---
> if (owrite == NULL)
> y = 2;
> else
> y = (owrite - 1);
> for (z = 0; z < y; z++)
> {
> PASS(0xee);
> if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
> goto err;
> }
441c455
< (void)fprintf(stderr, "usage: rm [-dfiPRrW] file ...\n");
---
> (void)fprintf(stderr, "usage: rm [-dfiPRrWo] [n] file ...\n");
- Follow-Ups:
- Re: rm hack
- From: Chris Palmer <cecibean@bitstream.net>
- Re: rm hack
- From: Phil Pennock <Phil.Pennock@globnix.org>