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.

135 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. chngcnt.c
  5. Abstract:
  6. User mode program to retrive media change counts from a scsi driver
  7. Author:
  8. 13-May-1995 Peter Wieland (peterwie)
  9. Revision History:
  10. --*/
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <windows.h>
  14. #include <winioctl.h>
  15. #include <ntddpar.h>
  16. #include "..\..\..\..\inc\ntddvdm.h"
  17. int __cdecl main(int argc, char *argv[]) {
  18. HANDLE h;
  19. ULONG in;
  20. ULONG out;
  21. ULONG bytesBack;
  22. UCHAR cmd;
  23. ULONG num;
  24. UCHAR buf[128];
  25. ULONG ioctlCode;
  26. h = CreateFile(argv[1],
  27. GENERIC_READ | GENERIC_WRITE,
  28. FILE_SHARE_READ | FILE_SHARE_WRITE,
  29. NULL,
  30. OPEN_EXISTING,
  31. FILE_ATTRIBUTE_NORMAL,
  32. NULL);
  33. if(h == INVALID_HANDLE_VALUE) {
  34. printf("Error [%d] opening device %s\n", GetLastError(), argv[1]);
  35. return -1;
  36. }
  37. do {
  38. printf("Command>");
  39. fflush(stdout);
  40. if((gets(buf) == NULL) && (feof(stdin))) {
  41. printf("EOF - exiting\n");
  42. break;
  43. }
  44. cmd = 'x';
  45. num = 75;
  46. bytesBack = 0;
  47. in = out = 0xff;
  48. sscanf(buf, "%c %d", &cmd, &num);
  49. switch(cmd) {
  50. case 'c': {
  51. printf("IOCTL_VDM_PAR_WRITE_CONTROL_PORT %d\n", num);
  52. ioctlCode = IOCTL_VDM_PAR_WRITE_CONTROL_PORT;
  53. in = num;
  54. break;
  55. }
  56. case 's': {
  57. printf("IOCTL_VDM_PAR_READ_STATUS_PORT\n");
  58. ioctlCode = IOCTL_VDM_PAR_READ_STATUS_PORT;
  59. out = 0;
  60. break;
  61. }
  62. case 'w': {
  63. printf("IOCTL_VDM_PAR_WRITE_DATA_PORT %d\n", num);
  64. ioctlCode = IOCTL_VDM_PAR_WRITE_DATA_PORT;
  65. in = num;
  66. break;
  67. }
  68. case 'q': {
  69. printf("Quitting\n");
  70. goto Done;
  71. break;
  72. }
  73. default: {
  74. printf("Unknown command %c\n", cmd);
  75. ioctlCode = 0;
  76. break;
  77. }
  78. }
  79. if(ioctlCode == 0) {
  80. continue;
  81. }
  82. if(!DeviceIoControl(h,
  83. ioctlCode,
  84. &in,
  85. sizeof(in),
  86. &out,
  87. sizeof(out),
  88. &bytesBack,
  89. NULL )) {
  90. printf("Error [%d] sending ioctl\n", GetLastError());
  91. continue;
  92. } else {
  93. printf("Ioctl sent - %d bytes back - %d back\n", bytesBack, out);
  94. }
  95. } while(TRUE);
  96. Done:
  97. CloseHandle(h);
  98. return 0;
  99. }