#include #include #include /************************************** **** **** **** Yves Dorfsman, May 10th 2000 **** **** **** * * ***************************************************************************** * * 2009/02: * There are better programs out there for this purpose, please check * shred, from GUN coreutils: * * http://www.gnu.org/software/coreutils * * ***************************************************************************** ***************************************************************************** ***************************************************************************** ***************************************************************************** * * Will wipe the content of a disk. * * usage: mwipe /dev/dsk/diskname * or: touch filename ; mwipe filename * * If you use the second method, it will fill up your file system completely. * * It is very slow, I never worked on the performance, but I'm sure it * could be improved quite easily. * * MAKE SURE YOU DO UNDERSTAND WHAT THIS PROGRAM DOES BEFORE YOU USE IT * (DELETE YOUR DATA !). I AM NOT RESPONSIBLE FOR THE USE OF THIS PROGRAM. * * Principles: * ---------- * * I've heard that really there is no way to wipe out the content of a disk * and that someone that as a *lot* of cash could basically recover anything * (as long as the media hasn't been broken). * * Now I sort of remember someone else saying that it is relatively easy * to recover data, up to 5 re-writes (You still have to open the disks * and use special equipment to read the magnetic fiels of the platters). * * Don't ask me for references... I can't rememeber where I heard these, could * be talking with friends, or reading articles on the net or in magazines. * If you do have reliable sources about this subject, don't hesitate * to email them to me. * * Anyway, I decided that 5 passes should be enough for this program. * ************************************/ void onepass(void); FILE *device; char buffer[4096], smallbuff; int buffersize, retcode; main (int argc, char** argv) { /* Need one arguments */ if (argc != 2) { /* usage(argv[0]); */ return 1; } /* Check that we can open the files */ device = fopen(argv[1], "rb+"); if (device == 0) { strcpy(buffer, "\nTrying to open "); strcat(buffer, argv[1]); strcat(buffer, " for writing"); perror(buffer); /* usage(argv[0]); */ return 2; } buffersize = sizeof(buffer); printf("\n\nFirst pass..."); /* set buffers to zero, and do one pass */ smallbuff = 0; memset(buffer, smallbuff, buffersize); onepass(); printf("\nSecond pass..."); /* set buffers to one, and do one pass */ smallbuff = ~smallbuff; memset(buffer, smallbuff, buffersize); onepass(); printf("\nThird pass..."); /* set buffers back to zero, and do one pass */ smallbuff = ~smallbuff; memset(buffer, smallbuff, buffersize); onepass(); printf("\nFourth pass..."); /* set buffers back to one, and do one pass */ smallbuff = ~smallbuff; memset(buffer, 0, buffersize); onepass(); printf("\nFinal pass..."); /* set buffers to some pattern, and do one pass */ smallbuff = 0; memset(buffer, smallbuff, buffersize); strcpy(buffer, "\ \n\ If you are reading this, then you are a naughty boy.\n\ \n\ La curiosite est un vilain defaut.\n\ \n\ \n\ Pi=3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 0628620899 8628034825 3421170679 8214808651 3282306647 0938446095 5058223172 5359408128 4811174502 8410270193 8521105559 6446229489 5493038196 4428810975 6659334461 2847564823 3786783165 2712019091 4564856692 3460348610 4543266482 1339360726 0249141273 7245870066 0631558817 4881520920 9628292540 9171536436 7892590360 0113305305 4882046652 1384146951 9415116094 3305727036 5759591953 0921861173 8193261179 3105118548 0744623799 6274956735 1885752724 8912279381 8301194912 9833673362 4406566430 8602139494 6395224737 1907021798 6094370277 0539217176 2931767523 8467481846 7669405132 0005681271 4526356082 7785771342 7577896091 7363717872 1468440901 2249534301 4654958537 1050792279 6892589235 4201995611 2129021960 8640344181 5981362977 4771309960 5187072113 4999999837 2978049951 0597317328 1609631859 5024459455 3469083026 4252230825 3344685035 2619311881 7101000313 7838752886 5875332083 8142061717 7669147303 5982534904 2875546873 1159562863 8823537875 9375195778 1857780532 1712268066 1300192787 6611195909 2164201989\n\ \n\ \n\ Que j aime a faire apprendre un nombre utile aux sages\n\ immortel Archimede, artiste, ingenieur\n\ Qui de ton jugement peut priser la valeur ?\n\ Pour moi, ton probleme eut de pareils avantages.\n\ \n\ \n\ Les sanglots longs \n\ Des violons \n\ De l'automne \n\ Blessent mon coeur \n\ D'une langueur \n\ Monotone. \n\ Tout suffocant \n\ Et blême, quand \n\ Sonne l'heure, \n\ Je me souviens \n\ Des jours anciens \n\ Et je pleure ; \n\ Et je m'en vais \n\ Au vent mauvais \n\ Qui m'emporte \n\ Deçà, delà, \n\ Pareil à la \n\ Feuille morte. \n\ \n\ Paul VERLAINE, 1866\n\ \n\ \n\ \n\ UNIX is a registered trademark of The Open Group\n\ \n\ \n\ 1 ++----------------**---------------+----**-----------+--------**-----++\n\ + *+ * + * * + sin(x) ****** +\n\ 0.8 ++ * * * * * * ++\n\ | * * * * * * |\n\ 0.6 ++ * * * * * * ++\n\ * * * * * * * |\n\ 0.4 +* * * * * * * ++\n\ |* * * * * * * |\n\ 0.2 +* * * * * * * ++\n\ | * * * * * * * |\n\ 0 ++* * * * * * *++\n\ | * * * * * * *|\n\ -0.2 ++ * * * * * * *+\n\ | * * * * * * *|\n\ -0.4 ++ * * * * * * *+\n\ | * * * * * * *\n\ -0.6 ++ * * * * * * ++\n\ | * * * * * * |\n\ -0.8 ++ * * * * * * ++\n\ + * * + * * + * * +\n\ -1 ++-----**---------+----------**----+---------------**+---------------++\n\ -10 -5 0 5 10\n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ \n\ "); onepass(); fclose(device); printf("\nTerminated...\n\n"); exit(0); } void onepass(void) { /* Go to the top of the file */ fseek(device, 0, SEEK_SET); /* Use the big buffer to write fast */ retcode = 1; while (retcode == 1) retcode = fwrite(buffer, buffersize, 1, device); /* Now finish off with the one character smallbuff */ retcode = 1; while (retcode == 1) retcode = fwrite(&smallbuff, 1, 1, device); fflush(device); }