Created
November 17, 2015 13:31
-
-
Save toboqus/847d64a619d787a748f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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