mirror of the now-defunct rocklinux.org
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.

95 lines
2.5 KiB

  1. /* gcc -O2 -Wall cdromchk.c -o cdromchk
  2. *
  3. * --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. *
  5. * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. * Please add additional copyright information _after_ the line containing
  7. * the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. * the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. *
  10. * ROCK Linux: rock-src/misc/archive/cdromchk.c
  11. * ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  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; either version 2 of the License, or
  16. * (at your option) any later version. A copy of the GNU General Public
  17. * License can be found at Documentation/COPYING.
  18. *
  19. * Many people helped and are helping developing ROCK Linux. Please
  20. * have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. * file for details.
  22. *
  23. * --- ROCK-COPYRIGHT-NOTE-END ---
  24. */
  25. #include <stdio.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <fcntl.h>
  29. #include <unistd.h>
  30. #include <errno.h>
  31. #include <string.h>
  32. int main(int argc, char ** argv) {
  33. int cdrom,file;
  34. char buf1[4096];
  35. char buf2[4096];
  36. int rc1,rc2,rc3;
  37. int c1=0,c2=0;
  38. if (argc != 3) {
  39. fprintf(stderr,"Usage: %s <cdrom> <iso-file>\n",argv[0]);
  40. return 1;
  41. }
  42. fprintf(stderr,"Checking CD-ROM ...");
  43. if ( (cdrom=open(argv[1],O_RDONLY|O_SYNC)) == 0 ) {
  44. fprintf(stderr,"\n%s: Can't open %s: %s\n",
  45. argv[0],argv[1],strerror(errno));
  46. return 1;
  47. }
  48. if ( (file=open(argv[2],O_RDONLY)) == 0 ) {
  49. fprintf(stderr,"\n%s: Can't open %s: %s\n",
  50. argv[0],argv[2],strerror(errno));
  51. return 1;
  52. }
  53. while ( (rc1=read(file,buf1,4096)) > 0 ) {
  54. for (rc2=0; rc2 < rc1; rc2+=rc3) {
  55. rc3=read(cdrom,buf2+rc2,rc1-rc2);
  56. if (rc3 == -1) {
  57. fprintf(stderr,"\n%s: cdrom read error: %s\n",
  58. argv[0],strerror(errno));
  59. return 1;
  60. }
  61. if (rc3 == 0) break;
  62. }
  63. if (rc2 != rc1) {
  64. fprintf(stderr,"\n%s: cdrom read error: %d of "
  65. "%d bytes\n",argv[0],rc2,rc1);
  66. return 1;
  67. }
  68. if (memcmp(buf1,buf2,rc2)) {\
  69. fprintf(stderr,"\n%s: cdrom data differs from "
  70. "the iso file\n",argv[0]);
  71. return 1;
  72. }
  73. c1+=rc2; c2+=rc2;
  74. if (c1 > (1048576*16)) {
  75. c1=0;
  76. fprintf(stderr,".");
  77. }
  78. }
  79. if (rc1 == -1) {
  80. fprintf(stderr,"\n%s: file read error: %s\n",
  81. argv[0],strerror(errno));
  82. return 1;
  83. }
  84. fprintf(stderr," OK (%d MB).\n",c2/1048576);
  85. return 0;
  86. }