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.

513 lines
12 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. File Name:
  4. asrpriv.c
  5. Abstract:
  6. Private header file containing definitions and function
  7. prototypes for items used across the ASR Files.
  8. Notes:
  9. Naming conventions:
  10. _AsrpXXX private ASR Macros
  11. AsrpXXX private ASR routines
  12. AsrXXX Publically defined and documented routines
  13. Author:
  14. Guhan Suriyanarayanan (guhans) 27-May-2000
  15. Revision History:
  16. 27-May-2000 guhans
  17. Moved common items from asr.c to asrpriv.h
  18. --*/
  19. #ifndef _INC_ASRPRIV_H_
  20. #define _INC_ASRPRIV_H_
  21. #include <ntddscsi.h> // PSCSI_ADDRESS
  22. //
  23. // --------
  24. // #defines and constants common to the ASR modules.
  25. // --------
  26. //
  27. //
  28. // Size of temporary buffers used in ASR.
  29. //
  30. #define ASR_BUFFER_SIZE 4096
  31. //
  32. // Maximum length of \??\Volume{Guid}
  33. //
  34. #define ASR_CCH_MAX_VOLUME_GUID 64
  35. //
  36. // Maximum length of \Device\Harddisk1234\Partition1234
  37. //
  38. #define ASR_CCH_DEVICE_PATH_FORMAT 60
  39. extern const WCHAR ASR_WSZ_DEVICE_PATH_FORMAT[];
  40. //
  41. // \??\Volume{
  42. //
  43. extern const WCHAR ASR_WSZ_VOLUME_PREFIX[];
  44. extern const WCHAR ASR_SIF_SYSTEM_SECTION[];
  45. extern const WCHAR ASR_SIF_BUSES_SECTION[];
  46. extern const WCHAR ASR_SIF_MBR_DISKS_SECTION[];
  47. extern const WCHAR ASR_SIF_GPT_DISKS_SECTION[];
  48. extern const WCHAR ASR_SIF_MBR_PARTITIONS_SECTION[];
  49. extern const WCHAR ASR_SIF_GPT_PARTITIONS_SECTION[];
  50. typedef enum _SecurityAttributeType
  51. {
  52. esatUndefined = 0,
  53. esatMutex,
  54. esatSemaphore,
  55. esatEvent,
  56. esatFile
  57. } SecurityAttributeType;
  58. //
  59. // --------
  60. // typedefs common to the ASR modules.
  61. // --------
  62. //
  63. typedef struct _ASR_PTN_INFO {
  64. //
  65. // The GUID of the volume on this partition. For 0x42 parititions,
  66. // this value is a blank string.
  67. //
  68. WCHAR szVolumeGuid[ASR_CCH_MAX_VOLUME_GUID];
  69. //
  70. // next pointer in chain sorted by starting offset
  71. //
  72. struct _ASR_PTN_INFO *pOffsetNext;
  73. //
  74. // next pointer in chain sorted by partition length
  75. //
  76. struct _ASR_PTN_INFO *pLengthNext;
  77. //
  78. // The index into the PartitionEntry[] array
  79. //
  80. DWORD SlotIndex;
  81. DWORD ClusterSize;
  82. //
  83. // Special flags for the partition that we're interested in.
  84. // Currently, the values defined are
  85. // 0: not interesting
  86. // 1: Boot partition
  87. // 2: System partition
  88. //
  89. // Care must be taken that this partition flag is in sync with
  90. // the partition flags defined in setupdd.sys
  91. //
  92. USHORT PartitionFlags;
  93. //
  94. // FAT, FAT32, NTFS
  95. //
  96. UCHAR FileSystemType;
  97. UCHAR Reserved;
  98. //
  99. // The partition table entry for this partition.
  100. //
  101. PARTITION_INFORMATION_EX PartitionInfo;
  102. } ASR_PTN_INFO, *PASR_PTN_INFO;
  103. typedef struct _ASR_PTN_INFO_LIST {
  104. //
  105. // This list is sorted by the starting offset of the partitions
  106. //
  107. PASR_PTN_INFO pOffsetHead;
  108. PASR_PTN_INFO pOffsetTail;
  109. //
  110. // This chain is through the same list, but is sorted by the
  111. // partition lengths.
  112. //
  113. PASR_PTN_INFO pLengthHead;
  114. PASR_PTN_INFO pLengthTail;
  115. DWORD numTotalPtns;
  116. DWORD numExtendedPtns;
  117. } ASR_PTN_INFO_LIST, *PASR_PTN_INFO_LIST;
  118. //
  119. // Info about each disk on the system. An ASR_DISK_INFO
  120. // struct will exist for each physical disk that exists
  121. // on the system.
  122. //
  123. typedef struct _ASR_DISK_INFO {
  124. struct _ASR_DISK_INFO *pNext;
  125. //
  126. // Device Path used to open the Disk.
  127. // Obtained from SetupDiGetDeviceInterfaceDetail
  128. //
  129. PWSTR DevicePath;
  130. //
  131. // Partition layout information for partitions on the disk
  132. //
  133. PDRIVE_LAYOUT_INFORMATION_EX pDriveLayoutEx;
  134. //
  135. // Geometry: obtained from IOCTL_GET_DRIVE_GEOMETRY call
  136. //
  137. PDISK_GEOMETRY pDiskGeometry;
  138. //
  139. //
  140. // Information about partition 0 = the entire disk
  141. //
  142. PPARTITION_INFORMATION_EX pPartition0Ex;
  143. //
  144. // Additional Information about the partitions, including volume Guid, FS-Type, etc
  145. //
  146. PASR_PTN_INFO PartitionInfoTable;
  147. PSCSI_ADDRESS pScsiAddress;
  148. // For sif disks, this points to the physical disk they've been assigned
  149. // to, and vice versa. Used only at restore time.
  150. //
  151. struct _ASR_DISK_INFO *AssignedTo;
  152. DWORD sizeDriveLayoutEx;
  153. DWORD sizeDiskGeometry;
  154. DWORD sizePartition0Ex;
  155. DWORD sizePartitionInfoTable;
  156. //
  157. // Device number for disk, constant through sessions
  158. //
  159. ULONG DeviceNumber;
  160. ULONG SifDiskKey;
  161. ULONG SifBusKey;
  162. DEVINST ParentDevInst;
  163. //
  164. // Flag on whether this disk is Critical. At backup time, the backup
  165. // app provides us with this info. At restore time, the Critical disks
  166. // are expected to be restored by textmode Setup, before
  167. // RestoreNonCriticalDisks is called. Critical disks are not
  168. // re-partitioned by RestoreNonCriticalDisks.
  169. //
  170. BOOL IsCritical;
  171. //
  172. // A flag set to TRUE (at restore time) if a disk has the same signature
  173. // (or DiskId, for GPT disks) as specified in asr.sif, and if all the
  174. // partitions specified in asr.sif exist. Intact disks are not re-partitioned
  175. // by RestoreNonCriticalDisks.
  176. //
  177. BOOL IsIntact;
  178. //
  179. // If the struct is packed
  180. //
  181. BOOL IsPacked;
  182. BOOL IsClusterShared;
  183. BOOL IsAligned;
  184. //
  185. // This is needed at restore time, since the signature is read in before
  186. // the drive layout is created (and we need a temporary holding place).
  187. //
  188. DWORD TempSignature;
  189. WORD wReserved;
  190. //
  191. // Information about the bus this disk is on. This is only
  192. // used to group all the disks on a bus together.
  193. //
  194. STORAGE_BUS_TYPE BusType;
  195. //
  196. // GPT or MBR
  197. //
  198. PARTITION_STYLE Style;
  199. } ASR_DISK_INFO, *PASR_DISK_INFO;
  200. //
  201. // Info about the system--only one struct exists globally.
  202. //
  203. typedef struct _ASR_SYSTEM_INFO {
  204. //
  205. // Boot (Windows) Directory
  206. //
  207. PWSTR BootDirectory;
  208. //
  209. // OsLoader Path
  210. //
  211. PWSTR SystemPath;
  212. //
  213. // Platform = x86 or ia64
  214. //
  215. PWSTR Platform;
  216. // Name of the backup app
  217. // Passed in by backup app
  218. // PWSTR Provider;
  219. PWSTR pwReserved;
  220. //
  221. // Disk Auto-extension:
  222. // Passed in by backup app
  223. //
  224. BOOL AutoExtendEnabled;
  225. DWORD sizeComputerName;
  226. //
  227. // Obtained from GetComputerName
  228. //
  229. WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  230. //
  231. // Obtained from GetOsVersionEx
  232. //
  233. OSVERSIONINFOEX OsVersionEx;
  234. //
  235. // TimeZone info we save and restore
  236. //
  237. TIME_ZONE_INFORMATION TimeZoneInformation;
  238. } ASR_SYSTEM_INFO, *PASR_SYSTEM_INFO;
  239. //
  240. // --------
  241. // Macros common to the ASR modules.
  242. // --------
  243. //
  244. //
  245. // Macro Description:
  246. // This macro wraps calls that are expected to return SUCCESS (retcode).
  247. // If ErrorCondition occurs, it sets the LocalStatus to the ErrorCode
  248. // passed in, calls SetLastError() to set the Last Error to ErrorCode,
  249. // and jumps to the EXIT label in the calling function
  250. //
  251. // Arguments:
  252. // ErrorCondition // Result of some function call or conditional expression.
  253. // LocalStatus // Status variable in the calling function
  254. // LONG ErrorCode // An ErrorCode specific to the error and calling function
  255. //
  256. #define _AsrpErrExitCode( ErrorCondition, LocalStatus, ErrorCode ) { \
  257. \
  258. if ((BOOL) ErrorCondition) { \
  259. \
  260. LocalStatus = (DWORD) ErrorCode; \
  261. \
  262. SetLastError((DWORD) ErrorCode); \
  263. \
  264. goto EXIT; \
  265. } \
  266. }
  267. //
  268. // Simple macro to check a pointer, free it if non-NULL, and set it to NULL.
  269. //
  270. #define _AsrpHeapFree( p ) \
  271. if ( p ) { \
  272. HeapFree(heapHandle, 0L, p); \
  273. p = NULL; \
  274. }
  275. //
  276. // Simple macro to check if a handle is valid and close it
  277. //
  278. #define _AsrpCloseHandle( h ) \
  279. if ((h) && (INVALID_HANDLE_VALUE != h)) { \
  280. CloseHandle(h); \
  281. h = NULL; \
  282. }
  283. #define _AsrpIsVolumeGuid(data, numBytes) \
  284. ( \
  285. ((96 == numBytes) || ((98 == numBytes) && data[48] == '\\')) && \
  286. (!_wcsnicmp(L"\\??\\Volume{", data, 11)) && \
  287. L'-' == data[19] && \
  288. L'-' == data[24] && \
  289. L'-' == data[29] && \
  290. L'-' == data[34] && \
  291. L'}' == data[47] \
  292. )
  293. //
  294. // --------
  295. // debug #defines
  296. // --------
  297. //
  298. #define _asrerror THIS_MODULE, __LINE__, DPFLTR_ERROR_LEVEL
  299. #define _asrwarn THIS_MODULE, __LINE__, DPFLTR_WARNING_LEVEL
  300. #define _asrlog THIS_MODULE, __LINE__, DPFLTR_TRACE_LEVEL
  301. //
  302. // In pre-release mode, let's log everything so it's easier to debug
  303. //
  304. #ifdef PRERELEASE
  305. #define _asrinfo THIS_MODULE, __LINE__, DPFLTR_TRACE_LEVEL
  306. #else
  307. #define _asrinfo THIS_MODULE, __LINE__, DPFLTR_INFO_LEVEL
  308. #endif
  309. //
  310. // --------
  311. // routines common to the ASR modules.
  312. // --------
  313. //
  314. //
  315. // Implemented in asrback.c
  316. //
  317. BOOL
  318. AsrpConstructSecurityAttributes(
  319. PSECURITY_ATTRIBUTES psaSecurityAttributes,
  320. SecurityAttributeType eSaType,
  321. BOOL bIncludeBackupOperator
  322. );
  323. VOID
  324. AsrpCleanupSecurityAttributes(
  325. PSECURITY_ATTRIBUTES psaSecurityAttributes
  326. );
  327. BOOL
  328. AsrpGetMountPoints(
  329. IN PCWSTR DeviceName,
  330. IN CONST DWORD SizeDeviceName,
  331. PMOUNTMGR_MOUNT_POINTS *pMountPointsOut // caller must free this
  332. );
  333. BOOL
  334. AsrpInitLayoutInformation(
  335. IN CONST PASR_SYSTEM_INFO pSystemInfo,
  336. IN OUT PASR_DISK_INFO pDiskList,
  337. OUT PULONG MaxDeviceNumber OPTIONAL,
  338. IN BOOL AllDetailsForLocalDisks,
  339. IN BOOL AllDetailsForOfflineClusteredDisks
  340. );
  341. BOOL
  342. AsrpInitDiskInformation(
  343. OUT PASR_DISK_INFO *ppDiskList
  344. );
  345. BOOL
  346. AsrpFreeNonFixedMedia(
  347. IN OUT PASR_DISK_INFO *ppDiskList
  348. );
  349. VOID
  350. AsrpFreeStateInformation(
  351. IN OUT PASR_DISK_INFO *ppDiskList,
  352. IN OUT PASR_SYSTEM_INFO pSystemInfo
  353. );
  354. VOID
  355. AsrpFreePartitionList(
  356. IN OUT PASR_PTN_INFO_LIST *ppPtnList
  357. );
  358. //
  359. // Implemented in asrclus.c
  360. //
  361. BOOL
  362. AsrpIsOfflineClusteredDisk(
  363. IN CONST HANDLE hDisk
  364. );
  365. BOOL
  366. AsrpInitClusterSharedDisks(
  367. IN PASR_DISK_INFO OriginalDiskList
  368. );
  369. //
  370. // Implemented in setupasr.c
  371. //
  372. PWSTR // must be freed by caller
  373. AsrpExpandEnvStrings(
  374. IN CONST PCWSTR OriginalString
  375. );
  376. BOOL
  377. AsrIsEnabled(VOID);
  378. VOID
  379. AsrpInitialiseLogFile();
  380. VOID
  381. AsrpInitialiseErrorFile();
  382. VOID
  383. AsrpPrintDbgMsg(
  384. IN CONST char Module,
  385. IN CONST ULONG Line,
  386. IN CONST ULONG MesgLevel,
  387. IN PCSTR FormatString,
  388. ...);
  389. VOID
  390. AsrpCloseLogFiles();
  391. #endif // _INC_ASRPRIV_H_