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.

200 lines
5.5 KiB

  1. /*
  2. * INTERNAL.H
  3. *
  4. * Internal header
  5. *
  6. * DRIVEARB.DLL - Shared Drive Aribiter for shared disks and libraries
  7. * - inter-machine sharing client
  8. * - inter-app sharing service
  9. *
  10. * Author: ErvinP
  11. *
  12. * (c) 2000 Microsoft Corporation
  13. *
  14. */
  15. #define DRIVEARB_SIG 'AvrD'
  16. enum driveStates {
  17. /*
  18. * Note: this value designates that the driveContext block
  19. * within the file mapping is FREE
  20. */
  21. DRIVESTATE_NONE = 0,
  22. // local node owns drive and no app is using it
  23. DRIVESTATE_AVAILABLE_LOCALLY,
  24. // local node owns drive and some local app is using it
  25. DRIVESTATE_INUSE_LOCALLY,
  26. // local node does NOT own the drive
  27. DRIVESTATE_UNAVAILABLE_LOCALLY,
  28. };
  29. enum clientStates {
  30. CLIENTSTATE_NONE = 0,
  31. CLIENTSTATE_INACTIVE, // client session not using nor waiting for drive
  32. CLIENTSTATE_WAITING, // client session waiting for drive
  33. CLIENTSTATE_ACTIVE, // client session owns the drive
  34. };
  35. /*
  36. * This is our internal context for a drive
  37. */
  38. typedef struct {
  39. DWORD sig;
  40. enum driveStates state;
  41. DWORD numCurrentReaders;
  42. DWORD numCurrentWriters;
  43. BOOL denyRead;
  44. BOOL denyWrite;
  45. /*
  46. * Drive mutex, mapped to by clients' sessionDriveMutex
  47. */
  48. HANDLE mutex;
  49. /*
  50. * Drive event, mapped to by clients' sessionDriveEvent
  51. */
  52. HANDLE event;
  53. /*
  54. * The number of open sessions on this drive
  55. */
  56. DWORD sessionReferenceCount;
  57. /*
  58. * The number of sessions waiting on this drive
  59. */
  60. DWORD numWaitingSessions;
  61. /*
  62. * The drives filemap has been reallocated.
  63. * We mark this flag in each driveContext so that
  64. * each session can see it.
  65. * Client needs to reopen a handle to its drive when
  66. * this is set.
  67. */
  68. BOOL isReallocated;
  69. char driveName[MAX_PATH+1];
  70. // BUGBUG - pad the end of this struct for alignment
  71. } driveContext;
  72. /*
  73. * This is our internal context for a single client session's
  74. * use of a particular drive.
  75. */
  76. typedef struct {
  77. DWORD sig;
  78. enum clientStates state;
  79. DWORD shareFlags;
  80. /*
  81. * This process' local handle for the
  82. * shared drives file mapping.
  83. */
  84. HANDLE hDrivesFileMap;
  85. /*
  86. * This process' local pointer for its view
  87. * of its drive's portion of the shared drives file mapping.
  88. */
  89. driveContext *driveViewPtr;
  90. /*
  91. * Index into the shared drives fileMap of this
  92. * session's drive context
  93. */
  94. DWORD driveIndex;
  95. /*
  96. * Process-local handles to shared synchronization objects
  97. */
  98. HANDLE sessionDriveMutex;
  99. HANDLE sessionDriveEvent;
  100. /*
  101. * Callback to forcibly invalidate the client's handle.
  102. * Used only in case of error.
  103. */
  104. INVALIDATE_DRIVE_HANDLE_PROC invalidateHandleProc;
  105. /*
  106. * Process-local Distributed Lock Manager handles
  107. */
  108. dlm_nodeid_t sessionDlmHandle;
  109. dlm_lockid_t sessionDlmLockHandle;
  110. } clientSessionContext;
  111. #define DRIVES_FILEMAP_NAME "DRIVEARB_DrivesFileMap"
  112. #define GLOBAL_MUTEX_NAME "DRIVEARB_GlobalMutex"
  113. #define DRIVE_MUTEX_NAME_PREFIX "DRIVEARB_DriveMutex_"
  114. #define DRIVE_EVENT_NAME_PREFIX "DRIVEARB_DriveEvent_"
  115. #define DRIVES_FILEMAP_INITIAL_SIZE 4
  116. // BUGBUG REMOVE - debug only
  117. #define DBGMSG(msg, arg) \
  118. { \
  119. char _dbgMsg[100]; \
  120. wsprintf(_dbgMsg, "%s: %xh=%d.", msg, (arg), (arg)); \
  121. MessageBox(NULL, (LPSTR)_dbgMsg, "DriveArb debug message", MB_OK); \
  122. }
  123. #define ASSERT(fact) if (!(fact)){ MessageBox(NULL, (LPSTR)#fact, (LPSTR)"DriveArb assertion failed", MB_OK); }
  124. BOOL InitDrivesFileMappingForProcess();
  125. VOID DestroyDrivesFileMappingForProcess();
  126. BOOL GrowDrivesFileMapping(DWORD newNumDrives);
  127. driveContext *NewDriveContext(LPSTR driveName);
  128. VOID FreeDriveContext(driveContext *drive);
  129. DWORD GetDriveIndexByName(LPSTR driveName);
  130. clientSessionContext *NewClientSession(LPSTR driveName);
  131. VOID FreeClientSession(clientSessionContext *session);
  132. BOOL LOCKDriveForSession(clientSessionContext *session);
  133. VOID UNLOCKDriveForSession(clientSessionContext *session);
  134. BOOL InitializeClientArbitration(clientSessionContext *session);
  135. VOID ShutDownClientArbitration(clientSessionContext *session);
  136. BOOL AcquireNodeLevelOwnership(clientSessionContext *session);
  137. VOID ReleaseNodeLevelOwnership(clientSessionContext *session);
  138. DWORD MyStrNCpy(LPSTR destStr, LPSTR srcStr, DWORD maxChars);
  139. BOOL MyCompareStringsI(LPSTR s, LPSTR p);
  140. extern HANDLE g_hSharedGlobalMutex;
  141. extern HANDLE g_allDrivesFileMap;
  142. extern driveContext *g_allDrivesViewPtr;
  143. extern DWORD g_numDrivesInFileMap;