Source code of Windows XP (NT5)
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.

82 lines
2.3 KiB

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #undef NDEBUG
  5. #include <assert.h>
  6. #include <windows.h>
  7. #include <winsock.h>
  8. #include <winioctl.h>
  9. #define SETUP_SERVER 1
  10. #define CLOSE_SERVER 2
  11. #define IOCTL_ISCSI_BASE FILE_DEVICE_NETWORK
  12. #define IOCTL_ISCSI_SETUP_SERVER CTL_CODE(IOCTL_ISCSI_BASE, 0x0000, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  13. #define IOCTL_ISCSI_CLOSE_SERVER CTL_CODE(IOCTL_ISCSI_BASE, 0x0001, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  14. int __cdecl main(int argc, char *argv[])
  15. {
  16. HANDLE hDevice;
  17. ULONG controlCode = 0;
  18. USHORT choice;
  19. DWORD nBytes = 0;
  20. BOOLEAN retVal;
  21. printf("\nThis program will setup or close iSCSI server node\n");
  22. printf("\n Select the operation to perform : \n\n");
  23. printf(" 1. Setup server node\n");
  24. printf(" 2. Close server node\n\n");
  25. printf(" Enter choice (1 or 2) : ");
  26. scanf("%d", &choice);
  27. switch (choice) {
  28. case SETUP_SERVER: {
  29. printf("\n Will setup iSCSI server\n\n");
  30. controlCode = IOCTL_ISCSI_SETUP_SERVER;
  31. break;
  32. }
  33. case CLOSE_SERVER: {
  34. printf("\n Will close iSCSI server\n\n");
  35. controlCode = IOCTL_ISCSI_CLOSE_SERVER;
  36. break;
  37. }
  38. default: {
  39. printf("\n Invalid entry %d. Enter 1 or 2\n", choice);
  40. return 0;
  41. }
  42. } // switch (choice)
  43. hDevice = CreateFile("\\\\.\\iScsiServer",
  44. (GENERIC_READ | GENERIC_WRITE),
  45. (FILE_SHARE_READ | FILE_SHARE_WRITE), 0,
  46. OPEN_EXISTING, 0, NULL
  47. );
  48. if (hDevice != INVALID_HANDLE_VALUE) {
  49. if (!DeviceIoControl(hDevice,
  50. controlCode,
  51. NULL,
  52. 0,
  53. NULL,
  54. 0,
  55. &nBytes,
  56. NULL )) {
  57. printf(" IOCTL failed. Error %d\n",
  58. GetLastError());
  59. } else {
  60. printf(" IOCTL succeeded\n");
  61. }
  62. CloseHandle(hDevice);
  63. } else {
  64. printf(" Invalid Handle on opening iScsi server. Error : %d\n",
  65. GetLastError());
  66. }
  67. return 0;
  68. }