Skip to content

Instantly share code, notes, and snippets.

@orangejulius
Created November 29, 2012 08:16
Show Gist options
  • Save orangejulius/4167529 to your computer and use it in GitHub Desktop.
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
#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