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.

89 lines
2.2 KiB

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