Created
November 29, 2012 08:16
-
-
Save orangejulius/4167529 to your computer and use it in GitHub Desktop.
C program to write 4096 bytes starting at a random 512b sector, with sector offset passed in from the command line. Try it with your 4K sector hard drive (or SSD): non zero offsets will significantly reduce performance. Use only on an empty disk
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 <unistd.h> | |
#include <stdio.h> | |
#include <fcntl.h> | |
char buffer[4096]; | |
int main(int argc, char *argv[]) | |
{ | |
int fd, i, off; | |
long bk, byte; | |
if (argc<2) { | |
off = 0; | |
} else { | |
off = atoi(argv[1]); | |
} | |
srandom(off); | |
fd = open("/dev/sdc", O_RDWR | O_SYNC); | |
for (i=0; i<1000; i++) { | |
bk = random() % 200000000; | |
byte = bk * 4096 + off * 512; | |
lseek64(fd, byte, SEEK_SET); | |
write(fd, buffer, 4096); | |
} | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment