commit bfd05a231834e67d6bf0732c287769c7c8231569
parent dcf3e2a3e5e43dfabcf16523cfafcf0c9dc5e2fd
Author: aabacchus <ben@bvnf.space>
Date: Tue, 14 Sep 2021 17:38:39 +0100
shred: write one byte at a time, fsync the changes
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/shred.c b/src/shred.c
@@ -23,10 +23,15 @@ fill_with_zeroes(const char *filename)
long int bytes_to_write = stat_struct.st_size;
for(int i = 0; i < bytes_to_write; i++)
- if(write(fd, "\0\0\0\0\0", bytes_to_write + 2048) == -1) {
+ if(write(fd, "\0", 1) == -1) {
fprintf(stderr, "shred: %s: %s\n", filename, strerror(errno));
return 1;
}
+ if(fsync(fd) == -1) {
+ fprintf(stderr, "shred: %s: %s\n", filename, strerror(errno));
+ return 1;
+ }
+ close(fd);
return 0;
}