OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.1 KiB

  1. /* gcc -O2 -Wall cdromchk.c -o cdromchk
  2. *
  3. * --- T2-COPYRIGHT-NOTE-BEGIN ---
  4. * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  5. *
  6. * T2 SDE: misc/archive/cdromchk.c
  7. * Copyright (C) 2004 - 2006 The T2 SDE Project
  8. * Copyright (C) 1998 - 2003 Clifford Wolf
  9. *
  10. * More information can be found in the files COPYING and README.
  11. *
  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 ---
  17. */
  18. #include <stdio.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <fcntl.h>
  22. #include <unistd.h>
  23. #include <errno.h>
  24. #include <string.h>
  25. int main(int argc, char ** argv) {
  26. int cdrom,file;
  27. char buf1[4096];
  28. char buf2[4096];
  29. int rc1,rc2,rc3;
  30. int c1=0,c2=0;
  31. if (argc != 3) {
  32. fprintf(stderr,"Usage: %s <cdrom> <iso-file>\n",argv[0]);
  33. return 1;
  34. }
  35. fprintf(stderr,"Checking CD-ROM ...");
  36. if ( (cdrom=open(argv[1],O_RDONLY|O_SYNC)) == 0 ) {
  37. fprintf(stderr,"\n%s: Can't open %s: %s\n",
  38. argv[0],argv[1],strerror(errno));
  39. return 1;
  40. }
  41. if ( (file=open(argv[2],O_RDONLY)) == 0 ) {
  42. fprintf(stderr,"\n%s: Can't open %s: %s\n",
  43. argv[0],argv[2],strerror(errno));
  44. return 1;
  45. }
  46. while ( (rc1=read(file,buf1,4096)) > 0 ) {
  47. for (rc2=0; rc2 < rc1; rc2+=rc3) {
  48. rc3=read(cdrom,buf2+rc2,rc1-rc2);
  49. if (rc3 == -1) {
  50. fprintf(stderr,"\n%s: cdrom read error: %s\n",
  51. argv[0],strerror(errno));
  52. return 1;
  53. }
  54. if (rc3 == 0) break;
  55. }
  56. if (rc2 != rc1) {
  57. fprintf(stderr,"\n%s: cdrom read error: %d of "
  58. "%d bytes\n",argv[0],rc2,rc1);
  59. return 1;
  60. }
  61. if (memcmp(buf1,buf2,rc2)) {\
  62. fprintf(stderr,"\n%s: cdrom data differs from "
  63. "the iso file\n",argv[0]);
  64. return 1;
  65. }
  66. c1+=rc2; c2+=rc2;
  67. if (c1 > (1048576*16)) {
  68. c1=0;
  69. fprintf(stderr,".");
  70. }
  71. }
  72. if (rc1 == -1) {
  73. fprintf(stderr,"\n%s: file read error: %s\n",
  74. argv[0],strerror(errno));
  75. return 1;
  76. }
  77. fprintf(stderr," OK (%d MB).\n",c2/1048576);
  78. return 0;
  79. }