/* verifycd - compare cd image to iso file on disk ** keithl@keithl.com January 7, 2004 ** ** compile with: cc -o verifycd verifycd.c */ #include #include #include #include #include #define PROG "verifycd" #define BUFSIZE 512 #define BUFPERMEG 2048 #define DEBUG 1 int bufcnt ; int megcnt ; int size_cd ; int size_hd ; char cdbuf[ BUFSIZE ]; char hdbuf[ BUFSIZE ]; char *cdptr; char *hdptr; char *bufend; int cd; int hd; int main(int argc, char *argv[] ) { // check arguments if( argc != 3 ) { fprintf( stderr, "usage: verifycd \n" ); return 2; } // open cdrom and hd files if( ( cd = open( argv[1] , O_RDONLY , 0 ) ) < 0 ) { fprintf( stderr, "%s: cannot open cdrom drive %s\n", PROG, argv[1] ); return 2; } if( ( hd = open( argv[2] , O_RDONLY , 0 ) ) < 0 ) { fprintf( stderr, "%s: cannot open file %s\n", PROG, argv[2] ); return 2; } // buffer loop bufcnt = 0; megcnt = 0; do { size_cd = read( cd, cdbuf , BUFSIZE ); size_hd = read( hd, hdbuf , BUFSIZE ); // check for short CD if ( (size_hd > 0 ) && ( size_hd > size_cd ) ) { close( cd ); close( hd ); fprintf( stderr, "hd=%03d cd=%03d\n", size_hd, size_cd ); fprintf( stderr, "%s FAILED - CD image too short\n", PROG ); return 1; } cdptr = cdbuf ; hdptr = hdbuf ; bufend = cdbuf + size_cd ; // byte loop - compare buffered data while ( cdptr < bufend ) { if ( *(cdptr++) != *(hdptr++) ) { close( cd ); close( hd ); fprintf( stderr, "%s FAILED - images differ\n", PROG ); return 1; } } // progress counter if( ++bufcnt >= BUFPERMEG ) { fprintf( stdout, "%4d MB\r", ++megcnt ); fflush( stdout ); bufcnt = 0 ; } } while ( size_cd == BUFSIZE ); // end of buffer loop, end of files close( cd ); close( hd ); fprintf( stderr, "%s SUCCEEDED - images OK\n", PROG ); return 0; }