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.

499 lines
10 KiB

  1. /*++
  2. Copyright (c) 1996-1998 Microsoft Corporation
  3. Module Name:
  4. disksp.h
  5. Abstract:
  6. Disks Resource DLL private definitions.
  7. Author:
  8. Rod Gamache (rodga) 29-Mar-1996
  9. Revision History:
  10. --*/
  11. #include "clusres.h"
  12. #include "ntddscsi.h"
  13. #include "ntddft.h"
  14. #include "clusdisk.h"
  15. #include "clusrtl.h"
  16. #include "diskinfo.h"
  17. #include "clusstor.h"
  18. #define DiskpLogEvent ClusResLogEvent
  19. #define DiskpSetResourceStatus ClusResSetResourceStatus
  20. #define DISKS_PRINT printf
  21. #define FTSET_PRINT printf
  22. #define CLUSDISK_REGISTRY_AVAILABLE_DISKS \
  23. TEXT("System\\CurrentControlSet\\Services\\ClusDisk\\Parameters\\AvailableDisks")
  24. #define CLUSDISK_REGISTRY_SIGNATURES \
  25. TEXT("System\\CurrentControlSet\\Services\\ClusDisk\\Parameters\\Signatures")
  26. #define CLUSREG_VALUENAME_MANAGEDISKSONSYSTEMBUSES TEXT("ManageDisksOnSystemBuses")
  27. #define DEVICE_CLUSDISK0 TEXT("\\Device\\ClusDisk0")
  28. #define DISKS_REG_CLUSTER_QUORUM TEXT("Cluster\\Quorum")
  29. #define DISKS_REG_QUORUM_PATH CLUSREG_NAME_QUORUM_PATH
  30. #define DEVICE_HARDDISK TEXT("\\Device\\Harddisk%u")
  31. #define DEVICE_HARDDISK_PARTITION_FMT TEXT("\\Device\\Harddisk%u\\Partition%u")
  32. //
  33. // This string is needed to convert the \Device\HarddiskX\PartitionY name to
  34. // the Vol{GUID} name. Note that the trailing backslash is required!
  35. //
  36. #define GLOBALROOT_HARDDISK_PARTITION_FMT TEXT("\\\\\?\\GLOBALROOT\\Device\\Harddisk%u\\Partition%u\\")
  37. #define UNINITIALIZED_UCHAR (UCHAR)-1
  38. #define MIN_USABLE_QUORUM_PARTITION_LENGTH 50 * 1000 * 1000 // 50 MB
  39. extern PLOG_EVENT_ROUTINE DiskpLogEvent;
  40. extern HANDLE DiskspClusDiskZero;
  41. //extern PSTR PartitionName;
  42. //extern PSTR DiskName;
  43. typedef struct _ARBITRATION_INFO {
  44. CLRTL_WORK_ITEM WorkItem;
  45. DWORD SectorSize;
  46. CRITICAL_SECTION DiskLock;
  47. DWORD InputData;
  48. DWORD OutputData;
  49. HANDLE ControlHandle; // Moved here from DISK_INFO //
  50. BOOL ReservationError; // Moved here from DISK_INFO //
  51. BOOL StopReserveInProgress;
  52. LONG CheckReserveInProgress;
  53. DWORD ArbitrateCount;
  54. } ARBITRATION_INFO, *PARBITRATION_INFO;
  55. typedef struct _MOUNTIE_VOLUME *PMOUNTIE_VOLUME;
  56. typedef struct _MOUNTIE_INFO {
  57. DWORD HarddiskNo;
  58. DWORD DriveLetters;
  59. DWORD NeedsUpdate;
  60. DWORD VolumeStructSize;
  61. PMOUNTIE_VOLUME Volume;
  62. DWORD UpdateThreadIsActive;
  63. } MOUNTIE_INFO, *PMOUNTIE_INFO;
  64. typedef struct _DISK_PARAMS {
  65. DWORD Signature;
  66. LPWSTR SerialNumber;
  67. LPWSTR Drive;
  68. DWORD SkipChkdsk;
  69. DWORD ConditionalMount;
  70. LPWSTR MPVolGuids; // REG_MULTI_SZ string of Volume{GUIDS}
  71. DWORD MPVolGuidsSize; // Number of bytes, not number of WCHARs!
  72. DWORD UseMountPoints;
  73. LPWSTR VolGuid;
  74. } DISK_PARAMS, *PDISK_PARAMS;
  75. //
  76. // DISK_INFO structures are common to both the physical disk resource
  77. // and the FT set resource. The underlying SCSI/filter driver interfaces
  78. // deal with DISK_INFO structures. Each one represents a physical disk.
  79. //
  80. typedef struct _DISK_INFO {
  81. LIST_ENTRY ListEntry;
  82. DISK_PARAMS Params;
  83. DWORD PhysicalDrive;
  84. HANDLE FileHandle;
  85. DWORD FailStatus;
  86. } DISK_INFO, *PDISK_INFO;
  87. typedef struct _MOUNTPOINT_INFO {
  88. DWORD MPUpdateThreadIsActive;
  89. CRITICAL_SECTION MPLock;
  90. BOOL Initialized;
  91. DWORD MPListCreateInProcess;
  92. } MOUNTPOINT_INFO, *PMOUNTPOINT_INFO;
  93. //
  94. // DISK_RESOURCE structures are used by the physical disk resource.
  95. // It encapsulates a DISK_INFO structure that represents the physical
  96. // disk. Each DISK_RESOURCE may contain multiple partitions.
  97. //
  98. typedef struct _DISK_RESOURCE {
  99. LIST_ENTRY ListEntry; // Linkage onto list of online disks
  100. LIST_ENTRY PnpWatchedListEntry; // Lingage onto list of PNP watched disks
  101. DISK_INFO DiskInfo;
  102. RESOURCE_HANDLE ResourceHandle;
  103. HKEY ResourceKey;
  104. HKEY ResourceParametersKey;
  105. HKEY ClusDiskParametersKey;
  106. // HANDLE StopTimerHandle;
  107. BOOL Reserved;
  108. BOOL Valid;
  109. BOOL Inserted;
  110. BOOL Attached;
  111. CLUS_WORKER OnlineThread;
  112. CLUS_WORKER OfflineThread;
  113. PQUORUM_RESOURCE_LOST LostQuorum;
  114. PFULL_DISK_INFO DiskCpInfo; // returned from DiskGetFullDiskInfo
  115. DWORD DiskCpSize;
  116. MOUNTPOINT_INFO MPInfo;
  117. ARBITRATION_INFO ArbitrationInfo;
  118. MOUNTIE_INFO MountieInfo;
  119. BOOL IgnoreMPNotifications;
  120. } DISK_RESOURCE, *PDISK_RESOURCE;
  121. //
  122. // FTSET_RESOURCE structures are used by the FT set resource.
  123. // It encapsulates a list of DISK_INFO structures that represent
  124. // the physical members of the FT set.
  125. //
  126. typedef struct _FTSET_RESOURCE {
  127. LIST_ENTRY ListEntry; // Linkage onto list of online FT sets
  128. LIST_ENTRY MemberList;
  129. HANDLE FtSetHandle;
  130. HKEY ResourceKey;
  131. HKEY ResourceParametersKey;
  132. HKEY ClusDiskParametersKey;
  133. HANDLE StopTimerHandle;
  134. HANDLE ReservationThread;
  135. BOOL Valid;
  136. BOOL Attached;
  137. BOOL Inserted;
  138. CLUS_WORKER OnlineThread;
  139. RESOURCE_HANDLE ResourceHandle;
  140. DWORD SignatureLength;
  141. LPWSTR SignatureList;
  142. PFULL_FTSET_INFO FtSetInfo; // returned from DiskGetFullFtSetInfo
  143. DWORD FtSetSize;
  144. PQUORUM_RESOURCE_LOST LostQuorum;
  145. } FTSET_RESOURCE, *PFTSET_RESOURCE;
  146. #define FtRoot(_res_) CONTAINING_RECORD((_res_)->MemberList.Flink, \
  147. DISK_INFO, \
  148. ListEntry)
  149. typedef struct _SCSI_ADDRESS_ENTRY {
  150. SCSI_ADDRESS ScsiAddress;
  151. struct _SCSI_ADDRESS_ENTRY *Next;
  152. } SCSI_ADDRESS_ENTRY, *PSCSI_ADDRESS_ENTRY;
  153. BOOL
  154. IsVolumeDirty(
  155. IN UCHAR DriveLetter
  156. );
  157. #if 0
  158. DWORD
  159. GetSymbolicLink(
  160. IN PCHAR RootName,
  161. IN OUT PCHAR ObjectName // Assumes this points at a MAX_PATH length buffer
  162. );
  163. #endif
  164. LPWSTR
  165. GetRegParameter(
  166. IN HKEY RegKey,
  167. IN LPCWSTR ValueName
  168. );
  169. #if 0
  170. HANDLE
  171. OpenObject(
  172. PCHAR Directory,
  173. PCHAR Name
  174. );
  175. #endif
  176. DWORD
  177. AssignDriveLetters(
  178. HANDLE FileHandle,
  179. PDISK_INFO DiskInfo
  180. );
  181. DWORD
  182. RemoveDriveLetters(
  183. HANDLE FileHandle,
  184. PDISK_INFO DiskInfo
  185. );
  186. DWORD
  187. SetDiskState(
  188. PDISK_RESOURCE ResourceEntry,
  189. UCHAR NewDiskState
  190. );
  191. #define GoOnline( ResEntry ) SetDiskState( ResEntry, DiskOnline )
  192. #define GoOffline( ResEntry ) SetDiskState( ResEntry, DiskOffline )
  193. DWORD
  194. DoAttach(
  195. DWORD Signature,
  196. RESOURCE_HANDLE ResourceHandle,
  197. BOOLEAN InstallMode
  198. );
  199. DWORD
  200. DoDetach(
  201. DWORD Signature,
  202. RESOURCE_HANDLE ResourceHandle
  203. );
  204. DWORD
  205. StartReserveEx(
  206. OUT HANDLE *FileHandle,
  207. LPVOID InputData,
  208. DWORD InputDataSize,
  209. RESOURCE_HANDLE ResourceHandle
  210. );
  211. DWORD
  212. StopReserve(
  213. HANDLE FileHandle,
  214. RESOURCE_HANDLE ResourceHandle
  215. );
  216. DWORD
  217. DiskpSetThreadPriority(
  218. VOID
  219. );
  220. DWORD
  221. GetRegDwordValue(
  222. IN LPWSTR RegKeyName,
  223. IN LPWSTR ValueName,
  224. OUT LPDWORD ValueBuffer
  225. );
  226. //
  227. // Common registry routines.
  228. //
  229. BOOLEAN
  230. GetAssignedDriveLetter(
  231. ULONG Signature,
  232. ULONG PartitionNumber,
  233. PUCHAR DriveLetter,
  234. PUSHORT FtGroup,
  235. PBOOL AssignDriveLetter
  236. );
  237. //
  238. // Common SCSI routines.
  239. //
  240. DWORD
  241. GetScsiAddress(
  242. IN DWORD Signature,
  243. OUT LPDWORD ScsiAddress,
  244. OUT LPDWORD DiskNumber
  245. );
  246. DWORD
  247. ClusDiskGetAvailableDisks(
  248. OUT PVOID OutBuffer,
  249. IN DWORD OutBufferSize,
  250. OUT LPDWORD BytesReturned
  251. );
  252. DWORD
  253. GetDiskInfo(
  254. IN DWORD Signature,
  255. OUT PVOID *OutBuffer,
  256. IN DWORD OutBufferSize,
  257. OUT LPDWORD BytesReturned
  258. );
  259. VOID
  260. CleanupScsiAddressList(
  261. PSCSI_ADDRESS_ENTRY AddressList
  262. );
  263. BOOL
  264. IsBusInList(
  265. PSCSI_ADDRESS DiskAddr,
  266. PSCSI_ADDRESS_ENTRY AddressList
  267. );
  268. BOOL
  269. IsDiskInList(
  270. PSCSI_ADDRESS DiskAddr,
  271. PSCSI_ADDRESS_ENTRY AddressList
  272. );
  273. DWORD
  274. GetCriticalDisks(
  275. PSCSI_ADDRESS_ENTRY *AddressList
  276. );
  277. DWORD
  278. GetPagefileDisks(
  279. PSCSI_ADDRESS_ENTRY *AddressList
  280. );
  281. DWORD
  282. GetCrashdumpDisks(
  283. PSCSI_ADDRESS_ENTRY *AddressList
  284. );
  285. DWORD
  286. GetSerialNumber(
  287. IN DWORD Signature,
  288. OUT LPWSTR *SerialNumber
  289. );
  290. DWORD
  291. GetSignatureFromSerialNumber(
  292. IN LPWSTR SerialNumber,
  293. OUT LPDWORD Signature
  294. );
  295. DWORD
  296. RetrieveSerialNumber(
  297. HANDLE DevHandle,
  298. LPWSTR *SerialNumber
  299. );
  300. //
  301. // Common routines for handling logical volumes
  302. //
  303. DWORD
  304. DisksDriveIsAlive(
  305. IN PDISK_RESOURCE ResourceEntry,
  306. IN BOOL Online
  307. );
  308. DWORD
  309. DisksMountDrives(
  310. IN PDISK_INFO DiskInfo,
  311. IN PDISK_RESOURCE ResourceEntry,
  312. IN DWORD Signature
  313. );
  314. DWORD
  315. DisksDismountDrive(
  316. IN PDISK_RESOURCE ResourceEntry,
  317. IN DWORD Signature
  318. );
  319. //
  320. // PnP stuff
  321. //
  322. DWORD
  323. DiskspGetQuorumPath(
  324. OUT LPWSTR* lpQuorumLogPath
  325. );
  326. DWORD
  327. DiskspSetQuorumPath(
  328. IN LPWSTR QuorumLogPath
  329. );
  330. DWORD
  331. WaitForDriveLetters(
  332. IN DWORD DriveLetters,
  333. IN PDISK_RESOURCE ResourceEntry,
  334. IN DWORD TimeOutInSeconds
  335. );
  336. //
  337. // [HACKHACK] Currently, there is not polically correct way
  338. // for the resource to learn whether it is a quorum resource or not
  339. //
  340. DWORD
  341. GetQuorumSignature(
  342. OUT PDWORD QuorumSignature
  343. );
  344. DWORD
  345. StartNotificationWatcherThread(
  346. VOID
  347. );
  348. VOID
  349. StopNotificationWatcher(
  350. VOID
  351. );
  352. VOID
  353. WatchDisk(
  354. IN PDISK_RESOURCE ResourceEntry
  355. );
  356. VOID
  357. StopWatchingDisk(
  358. IN PDISK_RESOURCE ResourceEntry
  359. );
  360. BOOL
  361. IsDiskInPnpVolumeList(
  362. PDISK_RESOURCE ResourceEntry,
  363. BOOL UpdateVolumeList
  364. );
  365. DWORD
  366. QueueWaitForVolumeEvent(
  367. HANDLE Event,
  368. PDISK_RESOURCE ResourceEntry
  369. );
  370. DWORD
  371. RemoveWaitForVolumeEvent(
  372. PDISK_RESOURCE ResourceEntry
  373. );
  374. //
  375. // Mount point list processing.
  376. //
  377. VOID
  378. DisksMountPointCleanup(
  379. PDISK_RESOURCE ResourceEntry
  380. );
  381. VOID
  382. DisksMountPointInitialize(
  383. PDISK_RESOURCE ResourceEntry
  384. );
  385. DWORD
  386. DisksProcessMountPointInfo(
  387. PDISK_RESOURCE ResourceEntry
  388. );
  389. DWORD
  390. DisksProcessMPControlCode(
  391. PDISK_RESOURCE ResourceEntry,
  392. DWORD ControlCode
  393. );
  394. DWORD
  395. DisksUpdateMPList(
  396. PDISK_RESOURCE ResourceEntry
  397. );
  398. DWORD
  399. PostMPInfoIntoRegistry(
  400. PDISK_RESOURCE ResourceEntry
  401. );
  402. DWORD
  403. UpdateCachedDriveLayout(
  404. IN HANDLE DiskHandle
  405. );