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.

104 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. quorum.c
  5. Abstract:
  6. Implements quorum for cm, uses UNC file for now
  7. Author:
  8. Ahmed Mohamed (ahmedm) 12, 01, 2000
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntdef.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <windows.h>
  16. //#include <winioctl.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <assert.h>
  21. // Quorum stuff
  22. static HANDLE DlmQhd = 0;
  23. static char *default_qfile="\\DosDevices\\UNC\\ahmedm\\tmp\\gs.qrm";
  24. extern char *WINAPI config_get_qfile();
  25. BOOLEAN
  26. QuormAcquire()
  27. {
  28. OBJECT_ATTRIBUTES objattrs;
  29. UNICODE_STRING cwspath;
  30. NTSTATUS status;
  31. IO_STATUS_BLOCK iostatus;
  32. WCHAR buf[128];
  33. int n;
  34. char *qfile;
  35. if (DlmQhd)
  36. return TRUE;
  37. qfile = config_get_qfile();
  38. if (!qfile) {
  39. qfile = default_qfile;
  40. }
  41. // no-quorum is specified
  42. if (qfile[0] == '\0')
  43. return TRUE;
  44. // convert to unicode
  45. n = MultiByteToWideChar(CP_ACP, 0, qfile, strlen(qfile), buf, sizeof(buf));
  46. buf[n] = buf[n+1] = '\0';
  47. RtlInitUnicodeString(&cwspath, buf);
  48. InitializeObjectAttributes(&objattrs, &cwspath, OBJ_CASE_INSENSITIVE,
  49. NULL, NULL);
  50. status = NtCreateFile(&DlmQhd,
  51. SYNCHRONIZE | DELETE,
  52. &objattrs,
  53. &iostatus,
  54. 0,
  55. FILE_ATTRIBUTE_NORMAL,
  56. 0,
  57. FILE_CREATE,
  58. FILE_DELETE_ON_CLOSE | FILE_NON_DIRECTORY_FILE,
  59. NULL,
  60. 0);
  61. if (status != STATUS_SUCCESS) {
  62. if (status != STATUS_OBJECT_NAME_COLLISION) {
  63. printf("Quorm '%s' failed %x\n", qfile, status);
  64. }
  65. return FALSE;
  66. }
  67. return TRUE;
  68. }
  69. void
  70. QuormInit()
  71. {
  72. DlmQhd = 0;
  73. }
  74. void
  75. QuormRelease()
  76. {
  77. if (DlmQhd) {
  78. NtClose(DlmQhd);
  79. DlmQhd = 0;
  80. }
  81. }