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.

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