Skip to content

Instantly share code, notes, and snippets.

@jklmnn
Last active September 12, 2017 17:30
Show Gist options
  • Save jklmnn/9219433acddb39ef1289fa82ef00bcc2 to your computer and use it in GitHub Desktop.
Save jklmnn/9219433acddb39ef1289fa82ef00bcc2 to your computer and use it in GitHub Desktop.
Get the working sectors of a block device. Uses the output of bad sectors created by badblocks. Thanks to @nikp123
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *fp = fopen(argv[1], "rb");
if(!fp) return 1;
int last = 0, bigdiff = 0, num;
while(fscanf(fp, "%d", &num) > 0){
if((num - last) > bigdiff) {
printf("Overthrow: %#x > %#x (%#x-%#x)\n", num-last, bigdiff, last, num);
bigdiff = num - last;
}
last = num;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment