lets "secure rm" with buffers of 64k per write and handle dangling

tail too.



SVN revision: 77146
This commit is contained in:
Carsten Haitzler 2012-09-27 09:59:36 +00:00
parent 5d1a85b837
commit 17ce568685
1 changed files with 13 additions and 5 deletions

View File

@ -1679,6 +1679,7 @@ _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
if (_e_fm_op_abort) goto finish;
static int fd = -1;
static char *buf = NULL;
off_t pos, sz;
if (fd == -1)
{
@ -1702,7 +1703,7 @@ _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
!S_ISREG(st2.st_mode))
goto finish;
if ((buf = malloc(st2.st_size)) == NULL)
if ((buf = malloc(65536)) == NULL)
goto finish;
task->src.st.st_size = st2.st_size;
@ -1711,10 +1712,17 @@ _e_fm_op_destroy_atom(E_Fm_Op_Task *task)
if (lseek(fd, SEEK_SET, 0) == -1)
goto finish;
if (_e_fm_op_random_buf(buf, task->src.st.st_size) == -1)
memset(buf, 0xFF, task->src.st.st_size);
if (write(fd, buf, task->src.st.st_size) != task->src.st.st_size)
goto finish;
for (pos = 0; pos < task->src.st.st_size; pos += 65536)
{
sz = 65536;
if ((task->src.st.st_size - pos) < sz) sz = task->src.st.st_size - pos;
if (_e_fm_op_random_buf(buf, sz) == -1) memset(buf, 0xff, sz);
if (write(fd, buf, sz) != sz)
{
fsync(fd);
goto finish;
}
}
if (fsync(fd) == -1)
goto finish;