commit - b291c869cbfdb96669bac5b1b9408099382794a3
commit + b74a38eb041629ca0ca404631bffb3de98520e5f
blob - fd085f8bcb1505db21904cb2fed0ac05bd08a0e6
blob + 330c0ece7b66f80f23de991d38908ae89d2bfe8f
--- shreddisk.c
+++ shreddisk.c
" damage is done! [y|n]: ";
char string5[] = "What do you want to write? [1:null, 2:0, 3:rand]: ";
+unsigned int shredding = 0;
+
void
sh_sig(int sig)
{
/* re-enable the cursor and exit */
+ if (shredding && sig == SIGINT)
+ do {
+ char quit[BUFF];
+ unsigned int si;
+ printf("\r "
+ " "
+ "\rDo you really want to quit? [y|n]: ");
+ fflush(stdout);
+ fgets(quit, sizeof(quit), stdin);
+ quit[strlen(quit) - 1] = '\0';
+ for (si = 0; si < strlen(quit); si++)
+ quit[si] = tolower(quit[si]);
+ if (strcmp(quit, "n") == 0 || strcmp(quit, "no") == 0) {
+ printf("\n");
+ return;
+ } else if (strcmp(quit, "y") == 0 ||
+ strcmp(quit, "yes") == 0) {
+ printf("\n");
+ break;
+ }
+ } while (1);
printf("\e[?25h");
printf("\n\n");
exit(1);
printf("\n\n%s\n%s\n%s\n\n", string0, string1, string0);
do {
+baddev:
printf("%s", string2);
fgets(dev, sizeof(dev), stdin);
} while (strlen(dev) < 4 || strlen(dev) > BUFF);
dev[strlen(dev) - 1] = '\0';
+ dev_fd = opendev(dev, O_RDWR, OPENDEV_PART, &realdev);
+
+ if (dev_fd < 0) {
+ printf("\nCould not open device %s\n\n", dev);
+ goto baddev;
+ } else {
+ if (ioctl(dev_fd, DIOCGPDINFO, &lab) < 0) {
+ printf("\nDevice %s does not exist\n\n", dev);
+ memset(&dev, 0, sizeof(dev));
+ goto baddev;
+ }
+ sectors = DL_GETDSIZE(&lab);
+ total_bytes = sectors * lab.d_secsize;
+ if (close(dev_fd) == -1) {
+ printf("\nCould not close fd %d\n\n", dev_fd);
+ memset(&dev, 0, sizeof(dev));
+ goto done;
+ }
+ if ((dd = fopen(realdev, "w")) == NULL) {
+ printf("\nCould not open device %s\n\n", realdev);
+ memset(&dev, 0, sizeof(dev));
+ goto baddev;
+ }
+ }
+
printf("\n");
do {
break;
} while (1);
- dev_fd = opendev(dev, O_RDWR, OPENDEV_PART, &realdev);
-
- if (dev_fd < 0) {
- printf("\nCould not open device %s\n\n", dev);
- goto done;
- } else {
- if (ioctl(dev_fd, DIOCGPDINFO, &lab) < 0) {
- printf("\nDevice %s does not exist\n\n", dev);
- goto done;
- }
- sectors = DL_GETDSIZE(&lab);
- total_bytes = sectors * lab.d_secsize;
- if (close(dev_fd) == -1) {
- printf("\nCould not close fd %d\n\n", dev_fd);
- goto done;
- }
- if ((dd = fopen(realdev, "w")) == NULL) {
- printf("\nCould not open device %s\n\n", realdev);
- goto done;
- }
- }
-
if (pledge("stdio unveil", NULL) == -1)
err(1, "pledge");
if (unveil(realdev, "w") != 0)
printf("\nShredding %s: %0.0f bytes", dev, total_bytes);
+ shredding = 1;
start = time(NULL);
for (i_pass = 0; i_pass < passes; i_pass++) {