Skip to content

Instantly share code, notes, and snippets.

@gregjurman
Last active December 19, 2015 10:29
Show Gist options
  • Save gregjurman/5941205 to your computer and use it in GitHub Desktop.
Save gregjurman/5941205 to your computer and use it in GitHub Desktop.
520bps to 512bps
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, const char *argv[]) {
const char *filename = argv[1];
uint8_t *buffer;
fprintf(stderr, "Converting %s from 520bps to 512bps\n", filename);
FILE * inFile = fopen(filename, "rb");
buffer = (uint8_t*) malloc(sizeof(uint8_t)*512);
fprintf(stderr, "Buffer size: %i\n", sizeof(uint8_t)*512);
while(fread(buffer, 512, 1, inFile) == 1) {
fwrite(buffer, 512, 1, stdout);
if(fseek(inFile, 8, SEEK_CUR) && (feof(inFile) == 0))
{
fprintf(stderr, "Error reading file: %i\n", ferror(inFile));
break;
}
if(feof(inFile))
{
break;
}
}
}
@gregjurman
Copy link
Author

Usage: ./520to512 Disk0.520.img | pv > Disk0.512.img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment