Skip to content

Instantly share code, notes, and snippets.

@toboqus
Created November 17, 2015 13:31
Show Gist options
  • Save toboqus/847d64a619d787a748f4 to your computer and use it in GitHub Desktop.
Save toboqus/847d64a619d787a748f4 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
int fd = open("/dev/sdd", O_WRONLY);
if (fd < 0) {
fprintf(stderr, "Error opening device file.\n");
return EXIT_FAILURE;
}
// Write 0's all over the disk, in chunks of 512 bytes.
char* zeros = calloc(1, 512);
ssize_t written, total = 0;
do {
total += written = write(fd, zeros, 512);
printf("\rBytes written: %ld", total);
} while (written == 512);
printf("\nDone!\n");
close(fd);
free(zeros);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment