25 #include <tdelocale.h>
28 #include <tdeapplication.h>
33 if (fileName.isEmpty())
35 kdError() <<
"KShred: missing file name in constructor" << endl;
41 file->setName(fileName);
42 if (!file->open(IO_ReadWrite))
44 kdError() <<
"KShred: cannot open file '" << fileName.local8Bit().data() <<
"' for writing\n" << endl;
49 fileSize = file->size();
86 unsigned char buff[4096];
87 memset((
void *) buff,
byte, 4096);
90 for (
unsigned int todo = fileSize; todo > 0; todo -= n)
92 n = (todo > 4096 ? 4096 : todo);
93 if (!writeData(buff, n))
109 for (
unsigned int todo = fileSize; todo > 0; todo -= n)
111 n = (todo > size ? size : todo);
112 if (!writeData(data, n))
127 long int buff[4096 /
sizeof(
long int)];
130 for (
unsigned int todo = fileSize; todo > 0; todo -= n)
132 n = (todo > 4096 ? 4096 : todo);
134 int limit = (n +
sizeof(
long int) - 1) /
sizeof(
long int);
135 for (
int i = 0; i < limit; i++)
136 buff[i] = kapp->random();
138 if (!writeData((
unsigned char *) buff, n))
151 if (fileName.isEmpty())
154 KShred shredder(fileName);
155 return shredder.
shred();
160 KShred::writeData(
unsigned char *data,
unsigned int size)
162 unsigned int ret = 0;
165 while ((ret < size) && (file->putch((
int) data[ret]) >= 0))
168 if ((totalBytes > 0) && (ret > 0))
172 tbpc = ((
unsigned int) (totalBytes / 100)) == 0 ? 1 : totalBytes / 100;
173 fspc = ((
unsigned int) (fileSize / 100)) == 0 ? 1 : fileSize / 100;
176 unsigned int pc = (
unsigned int) (bytesWritten / tbpc);
177 if (pc > lastSignalled)
194 return (fsync(file->handle()) == 0);
211 unsigned char p[6][3] = {{0222, 0111, 044}, {0111, 044, 0222},
212 { 044, 0222, 0111}, {0155, 0266, 0333},
213 {0266, 0333, 0155}, {0333, 0155, 0266}};
214 TQString msg = i18n(
"Shredding: pass %1 of 35");
219 totalBytes = fileSize * 35;
222 for (
int ctr = 0; ctr < 4; ctr++)
238 for (
unsigned int ctr = 0; ctr < 3; ctr++)
246 for (
unsigned int ctr = 0; ctr <= 255 ; ctr += 17)
254 for (
unsigned int ctr = 0; ctr < 6; ctr++)
262 for (
int ctr = 0; ctr < 4; ctr++)
277 #include "kshred.moc"
bool fill1s()
Writes all 1's over the entire file and flushes the file buffers.
bool fillpattern(unsigned char *pattern, unsigned int size)
Writes the specified byte array over the entire file and flushes the file buffers.
void infoMessage(const TQString &message)
bool shred()
Shreds a file by writing a series of values over it (uses fill0s, then fill1s, then fillrandom,...
bool fillrandom()
Writes random bites over the entire file and flushes the file buffers.
bool fill0s()
Writes all 0's over the entire file and flushes the file buffers.
KShred(TQString fileName)
Initialize the class using the name of the file to 'shred'.
bool fillbyte(unsigned int byte)
Writes the specified byte over the entire file and flushes the file buffers.
void processedSize(TDEIO::filesize_t bytes)