1 /* gcc -O2 -Wall cdromchk.c -o cdromchk
3 * --- T2-COPYRIGHT-NOTE-BEGIN ---
4 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
6 * T2 SDE: misc/archive/cdromchk.c
7 * Copyright (C) 2004 - 2005 The T2 SDE Project
8 * Copyright (C) 1998 - 2003 ROCK Linux Project
10 * More information can be found in the files COPYING and README.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2 of the License. A copy of the
15 * GNU General Public License can be found in the file COPYING.
16 * --- T2-COPYRIGHT-NOTE-END ---
20 #include <sys/types.h>
27 int main(int argc
, char ** argv
) {
35 fprintf(stderr
,"Usage: %s <cdrom> <iso-file>\n",argv
[0]);
39 fprintf(stderr
,"Checking CD-ROM ...");
41 if ( (cdrom
=open(argv
[1],O_RDONLY
|O_SYNC
)) == 0 ) {
42 fprintf(stderr
,"\n%s: Can't open %s: %s\n",
43 argv
[0],argv
[1],strerror(errno
));
47 if ( (file
=open(argv
[2],O_RDONLY
)) == 0 ) {
48 fprintf(stderr
,"\n%s: Can't open %s: %s\n",
49 argv
[0],argv
[2],strerror(errno
));
53 while ( (rc1
=read(file
,buf1
,4096)) > 0 ) {
54 for (rc2
=0; rc2
< rc1
; rc2
+=rc3
) {
55 rc3
=read(cdrom
,buf2
+rc2
,rc1
-rc2
);
57 fprintf(stderr
,"\n%s: cdrom read error: %s\n",
58 argv
[0],strerror(errno
));
64 fprintf(stderr
,"\n%s: cdrom read error: %d of "
65 "%d bytes\n",argv
[0],rc2
,rc1
);
68 if (memcmp(buf1
,buf2
,rc2
)) {\
69 fprintf(stderr
,"\n%s: cdrom data differs from "
70 "the iso file\n",argv
[0]);
74 if (c1
> (1048576*16)) {
81 fprintf(stderr
,"\n%s: file read error: %s\n",
82 argv
[0],strerror(errno
));
86 fprintf(stderr
," OK (%d MB).\n",c2
/1048576);