Last active
December 19, 2015 10:29
-
-
Save gregjurman/5941205 to your computer and use it in GitHub Desktop.
520bps to 512bps
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 <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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./520to512 Disk0.520.img | pv > Disk0.512.img