Leaked source code of windows server 2003
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.

185 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. read.c
  5. Abstract:
  6. dump cd tracks/sectors to wav files
  7. Environment:
  8. User mode only
  9. Revision History:
  10. 05-26-98 : Created
  11. --*/
  12. #include "common.h"
  13. #define LARGEST_SECTORS_PER_READ 27 // about 64k of data
  14. ULONG32
  15. CddumpDumpLba(
  16. HANDLE CdromHandle,
  17. HANDLE OutHandle,
  18. ULONG StartAddress,
  19. ULONG EndAddress
  20. )
  21. {
  22. RAW_READ_INFO info; // fill in for the read request
  23. PUCHAR sample;
  24. ULONG bytesReturned;
  25. ULONG currentLba;
  26. ULONG temp;
  27. ULONG sectorsPerRead;
  28. sample = NULL;
  29. currentLba = StartAddress;
  30. sectorsPerRead = LARGEST_SECTORS_PER_READ;
  31. TRY {
  32. sample = malloc(RAW_SECTOR_SIZE*LARGEST_SECTORS_PER_READ);
  33. if (sample == NULL) {
  34. printf("DumpLba => No memory for sample\n");
  35. LEAVE;
  36. }
  37. DebugPrint((3, "DumpLba => Largest Sectors Per Read: %d\n",
  38. LARGEST_SECTORS_PER_READ));
  39. while (sectorsPerRead != 0) {
  40. while (currentLba + sectorsPerRead <= EndAddress) {
  41. //
  42. // do a read of sectorsPerRead sectors
  43. //
  44. info.DiskOffset.QuadPart = (ULONGLONG)(currentLba*(ULONGLONG)2048);
  45. info.SectorCount = sectorsPerRead;
  46. info.TrackMode = CDDA;
  47. DebugPrint((3, "DumpLba => (%d) read from %8d to %8d:",
  48. sectorsPerRead, currentLba,
  49. currentLba + sectorsPerRead - 1));
  50. if(!DeviceIoControl(CdromHandle,
  51. IOCTL_CDROM_RAW_READ,
  52. &info, // pointer to inputbuffer
  53. sizeof(RAW_READ_INFO), // sizeof inputbuffer
  54. sample, // pointer to outputbuffer
  55. RAW_SECTOR_SIZE * sectorsPerRead, // sizeof outputbuffer
  56. &bytesReturned, // pointer to number of bytes returned
  57. FALSE // ???
  58. )
  59. ) {
  60. DWORD error = GetLastError();
  61. if (error == ERROR_INVALID_PARAMETER) {
  62. printf("ERROR_INVALID_PARAMTER for read size %x, "
  63. "trying smaller transfer\n", sectorsPerRead);
  64. break; // out of inner while() loop
  65. } else {
  66. printf("Error %d sending IOCTL_CDROM_RAW_READ for sector %d\n",
  67. GetLastError(), currentLba);
  68. LEAVE;
  69. }
  70. }
  71. if (bytesReturned != RAW_SECTOR_SIZE * sectorsPerRead) {
  72. printf("Only returned %d of %d bytes for read %d\n",
  73. bytesReturned,
  74. RAW_SECTOR_SIZE * sectorsPerRead,
  75. currentLba
  76. );
  77. LEAVE;
  78. }
  79. //
  80. // write that buffer out
  81. //
  82. DebugPrint((3, "DumpLba => (%d) write from %8d to %8d:",
  83. sectorsPerRead, currentLba,
  84. currentLba + sectorsPerRead - 1));
  85. if (!WriteFile(OutHandle,
  86. sample,
  87. RAW_SECTOR_SIZE * sectorsPerRead,
  88. &temp,
  89. NULL)) {
  90. printf("Unable to write data for read %d\n", currentLba);
  91. LEAVE;
  92. }
  93. //
  94. // increment currentLba
  95. //
  96. currentLba += sectorsPerRead;
  97. } // currentLba + sectorsPerRead <= EndAddress
  98. sectorsPerRead /= 2;
  99. } // sectorsPerRead != 0
  100. } FINALLY {
  101. if (sample) {
  102. free(sample);
  103. }
  104. }
  105. return 0;
  106. }
  107. PCDROM_TOC
  108. CddumpGetToc(
  109. HANDLE device
  110. )
  111. {
  112. PCDROM_TOC toc;
  113. ULONG bytesReturned;
  114. ULONG errorValue;
  115. toc = (PCDROM_TOC)malloc( sizeof(CDROM_TOC) );
  116. if ( toc == NULL ) {
  117. printf( "Insufficient memory\n" );
  118. return NULL;
  119. }
  120. if( !DeviceIoControl( device,
  121. IOCTL_CDROM_READ_TOC,
  122. NULL, // pointer to inputbuffer
  123. 0, // sizeof inputbuffer
  124. toc, // pointer to outputbuffer
  125. sizeof(CDROM_TOC), // sizeof outputbuffer
  126. &bytesReturned, // pointer to number of bytes returned
  127. FALSE //
  128. )
  129. ) {
  130. errorValue = GetLastError();
  131. printf( "Error %d sending IOCTL_CDROM_READ_TOC\n", errorValue );
  132. free( toc );
  133. return NULL;
  134. }
  135. return toc;
  136. }