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.

659 lines
15 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. spdrpriv.h
  5. Abstract:
  6. Header file for disaster recovery symbols in text-mode setup. These
  7. symbols are not to be referenced by modules other than those in the
  8. ASR family.
  9. Revision History:
  10. Initial Code Michael Peterson (v-michpe) 13.May.1997
  11. Code cleanup and changes Guhan Suriyanarayanan (guhans) 21.Aug.1999
  12. --*/
  13. #pragma once
  14. #if defined(ULONG_MAX) && !defined(_INC_LIMITS)
  15. #undef ULONG_MAX
  16. #endif
  17. #include <limits.h>
  18. #ifndef _SPDRPRIV_DEFN_
  19. #define _SPDRPRIV_DEFN_
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // Data Types //
  22. ///////////////////////////////////////////////////////////////////////////////
  23. //
  24. // For the InstallFiles section, we allow the file to end up on
  25. // one of the following directories.
  26. //
  27. typedef enum _AsrCopyDirEnum {
  28. _Temp = 0,
  29. _Tmp,
  30. _SystemRoot,
  31. _Default
  32. } AsrCopyDirEnum;
  33. #define ASR_ALWAYS_PROMPT_FOR_MEDIA 0x00000001
  34. #define ASR_PROMPT_USER_ON_MEDIA_ERROR 0x00000002
  35. #define ASR_FILE_IS_REQUIRED 0x00000004
  36. #define ASR_OVERWRITE_ON_COLLISION 0x00000010
  37. #define ASR_PROMPT_USER_ON_COLLISION 0x00000020
  38. typedef struct _SIF_INSTALLFILE_RECORD {
  39. struct _SIF_INSTALLFILE_RECORD *Next;
  40. PWSTR SystemKey;
  41. PWSTR CurrKey;
  42. PWSTR SourceMediaExternalLabel;
  43. PWSTR DiskDeviceName;
  44. PWSTR SourceFilePath;
  45. PWSTR DestinationFilePath;
  46. PWSTR VendorString;
  47. DWORD Flags;
  48. AsrCopyDirEnum CopyToDirectory;
  49. } SIF_INSTALLFILE_RECORD, *PSIF_INSTALLFILE_RECORD;
  50. typedef struct _SIF_INSTALLFILE_LIST {
  51. PSIF_INSTALLFILE_RECORD First;
  52. ULONG Count;
  53. } SIF_INSTALLFILE_LIST, *PSIF_INSTALLFILE_LIST;
  54. typedef struct _SIF_PARTITION_RECORD {
  55. GUID PartitionTypeGuid; // GPT only
  56. GUID PartitionIdGuid; // GPT only
  57. ULONG64 GptAttributes; // GPT only
  58. ULONGLONG StartSector;
  59. ULONGLONG SectorCount;
  60. ULONGLONG SizeMB; // value is calculated
  61. struct _SIF_PARTITION_RECORD *Next;
  62. struct _SIF_PARTITION_RECORD *Prev;
  63. PWSTR PartitionName; // GPT only
  64. //
  65. // This member is valid iff this a boot partition record. Otherwise, this
  66. // member is NULL
  67. //
  68. PWSTR NtDirectoryName;
  69. PWSTR CurrPartKey;
  70. PWSTR DiskKey;
  71. PWSTR VolumeGuid; // May be NULL
  72. //
  73. // If this is a descriptor or container record, then this member
  74. // refers to the logical disk record it contains. Otherwise, the
  75. // value of this member is NULL. Valid only for MBR partitions.
  76. //
  77. PWSTR LogicalDiskKey;
  78. //
  79. // If this is a logical disk partition record, then this member
  80. // refers to its Descriptor or Container partition record. Otherwise,
  81. // the value of this member is NULL. Valid only for MBR partitions.
  82. //
  83. PWSTR DescriptorKey;
  84. //
  85. // This is a bit mask. Valid bits are
  86. // 1: Boot partition (ASR_PTN_MASK_BOOT)
  87. // 2: System partition (ASR_PTN_MASK_SYS)
  88. // 4: DC1--tbd (ASR_PTN_MASK_DC1)
  89. // 8: DC2--tbd (ASR_PTN_MASK_DC1)
  90. //
  91. ULONG PartitionFlag;
  92. DWORD ClusterSize;
  93. DWORD PartitionTableEntryIndex;
  94. //
  95. // GPT or MBR
  96. //
  97. PARTITION_STYLE PartitionStyle;
  98. //
  99. // The values of these members are read directly from the asr.sif file
  100. //
  101. UCHAR PartitionType; // mbr only
  102. UCHAR ActiveFlag; // mbr only
  103. UCHAR FileSystemType;
  104. BOOLEAN IsPrimaryRecord;
  105. //
  106. // These can only be true for MBR partitions. All GPT partitions are
  107. // primary partitions.
  108. //
  109. BOOLEAN IsContainerRecord;
  110. BOOLEAN IsDescriptorRecord;
  111. BOOLEAN IsLogicalDiskRecord;
  112. BOOLEAN WillBeAutoextended;
  113. // Used for dynamic disks.
  114. BOOLEAN NeedsLdmRetype;
  115. BOOLEAN IsAligned;
  116. } SIF_PARTITION_RECORD, *PSIF_PARTITION_RECORD;
  117. typedef struct _SIF_PARTITION_RECORD_LIST {
  118. ULONGLONG DiskSectorCount;
  119. ULONGLONG LastUsedSector;
  120. ULONGLONG TotalMbRequired;
  121. PSIF_PARTITION_RECORD First;
  122. PSIF_PARTITION_RECORD Last;
  123. ULONG ElementCount;
  124. } SIF_PARTITION_RECORD_LIST, *PSIF_PARTITION_RECORD_LIST;
  125. typedef struct _SIF_DISK_RECORD {
  126. GUID SifDiskGptId; // Valid only for GPT disks
  127. ULONGLONG TotalSectors;
  128. //
  129. // The values of these members are calculated from the partition records
  130. // referencing this disk. If the disk does not contain an extended
  131. // partition, then the value of the ExtendedPartitionStartSector is
  132. // ULONG_MAX and the ExtendedPartitionSectorCount is zero (0).
  133. //
  134. ULONGLONG ExtendedPartitionStartSector;
  135. ULONGLONG ExtendedPartitionSectorCount;
  136. ULONGLONG ExtendedPartitionEndSector;
  137. ULONGLONG LastUsedSector;
  138. ULONGLONG LastUsedAlignedSector;
  139. PSIF_PARTITION_RECORD_LIST PartitionList;
  140. struct _DISK_PARTITION_SET *pSetRecord;
  141. //
  142. // The values of these members are read directly from the asr.sif
  143. // file.
  144. //
  145. PWSTR SystemKey;
  146. PWSTR CurrDiskKey;
  147. ULONG SifDiskNumber;
  148. DWORD BytesPerSector;
  149. DWORD SectorsPerTrack;
  150. DWORD TracksPerCylinder;
  151. ULONG BusKey;
  152. //
  153. // This is only valid if this is an MBR disk
  154. //
  155. ULONG SifDiskMbrSignature;
  156. ULONG MaxGptPartitionCount;
  157. STORAGE_BUS_TYPE BusType;
  158. //
  159. // Either an MBR or a GPT Disk
  160. //
  161. PARTITION_STYLE PartitionStyle;
  162. //
  163. // If this record has been assigned to a partition set, this value
  164. // is TRUE. Unassigned disk records are FALSE;
  165. //
  166. BOOLEAN Assigned;
  167. BOOLEAN ContainsSystemPartition;
  168. BOOLEAN ContainsNtPartition;
  169. BOOLEAN IsCritical;
  170. } SIF_DISK_RECORD, *PSIF_DISK_RECORD;
  171. typedef struct _DISK_PARTITION_SET {
  172. ULONGLONG ActualDiskSizeMB;
  173. PSIF_DISK_RECORD pDiskRecord;
  174. PWSTR NtPartitionKey;
  175. ULONG ActualDiskSignature;
  176. ULONG Index;
  177. PARTITION_STYLE PartitionStyle;
  178. BOOLEAN PartitionsIntact;
  179. BOOLEAN IsReplacementDisk;
  180. BOOLEAN IsAligned;
  181. } DISK_PARTITION_SET, *PDISK_PARTITION_SET, **DISK_PARTITION_SET_TABLE;
  182. typedef struct _ASR_PHYSICAL_DISK_INFO {
  183. ULONGLONG TrueDiskSize; // size of partition0
  184. ULONG BusKey; // used for grouping
  185. DWORD ControllerNumber;
  186. STORAGE_BUS_TYPE BusType; // scsi, ide, 1394, etc
  187. UCHAR PortNumber;
  188. } ASR_PHYSICAL_DISK_INFO, *PASR_PHYSICAL_DISK_INFO;
  189. ///////////////////////////////////////////////////////////////////////////////
  190. // Macro Declaration Section //
  191. ///////////////////////////////////////////////////////////////////////////////
  192. #define BYTES_PER_SECTOR(d) (HardDisks[(d)].Geometry.BytesPerSector)
  193. #define SECTORS_PER_TRACK(disk) (HardDisks[(disk)].Geometry.SectorsPerTrack)
  194. #define DISK_IS_REMOVABLE(d) (HardDisks[(d)].Characteristics & FILE_REMOVABLE_MEDIA)
  195. #define STRING_TO_LONG(s) (SpStringToLong((s),NULL,10))
  196. #define COMPARE_KEYS(k1,k2) (STRING_TO_LONG(k1) == STRING_TO_LONG(k2))
  197. #define STRING_TO_ULONG(str) (ULONG) SpAsrStringToULong(str, NULL, 10)
  198. #define STRING_TO_ULONGLONG(str) (ULONGLONG) SpAsrStringToULongLong(str, NULL, 10)
  199. #define STRING_TO_LONGLONG(str) (LONGLONG) SpAsrStringToLongLong(str, NULL, 10)
  200. #define STRING_TO_HEX(str) SpStringToLong(str + 2, NULL, 16)
  201. #define IsRecognizedFatPartition(PartitionType) ( \
  202. (PartitionType == PARTITION_HUGE) \
  203. )
  204. #define IsRecognizedFat32Partition(PartitionType) ( \
  205. (PartitionType == PARTITION_FAT32) \
  206. )
  207. #define IsRecognizedNtfsPartition(PartitionType) ( \
  208. (PartitionType == PARTITION_IFS) \
  209. )
  210. #define INTERNAL_ERROR(msg) \
  211. SpAsrRaiseInternalError(THIS_MODULE,THIS_MODULE_CODE,__LINE__,msg)
  212. #define BYTES_PER_MB 1048576 // 2^20, or 1024*1024
  213. #define ASR_PTN_MASK_BOOT 1
  214. #define ASR_PTN_MASK_SYS 2
  215. #define ASR_PTN_MASK_DC1 4
  216. #define ASR_PTN_MASK_DC2 8
  217. //
  218. // Debug Trace Messages
  219. //
  220. #define _asrinfo DPFLTR_SETUP_ID, ((ASRMODE_NORMAL == SpAsrGetAsrMode()) ? DPFLTR_INFO_LEVEL: DPFLTR_ERROR_LEVEL)
  221. #define _asrwarn DPFLTR_SETUP_ID, ((ASRMODE_NORMAL == SpAsrGetAsrMode()) ? DPFLTR_WARNING_LEVEL: DPFLTR_ERROR_LEVEL)
  222. #define _asrerr DPFLTR_SETUP_ID, DPFLTR_ERROR_LEVEL
  223. #define DbgMesg \
  224. KdPrintEx((_asrinfo, " ")); \
  225. KdPrintEx
  226. #define DbgStatusMesg \
  227. KdPrintEx((_asrinfo, "ASR [%ws:%4d] (.) ", THIS_MODULE, __LINE__)); \
  228. KdPrintEx
  229. #define DbgErrorMesg \
  230. KdPrintEx((_asrwarn, "ASR [%ws:%4d] (!) ", THIS_MODULE, __LINE__)); \
  231. KdPrintEx
  232. #define DbgFatalMesg \
  233. KdPrintEx((_asrerr, "ASR [%ws:%4d] (X) ", THIS_MODULE, __LINE__)); \
  234. KdPrintEx
  235. ///////////////////////////////////////////////////////////////////////////////
  236. // Global Variable Declarations //
  237. ///////////////////////////////////////////////////////////////////////////////
  238. // Defined in spdrpset.c
  239. DISK_PARTITION_SET_TABLE Gbl_PartitionSetTable1;
  240. DISK_PARTITION_SET_TABLE Gbl_PartitionSetTable2;
  241. PVOID Gbl_HandleToDrStateFile;
  242. // Imported from non-Asr modules
  243. extern WCHAR TemporaryBuffer[];
  244. //
  245. PWSTR ASR_SIF_SYSTEM_KEY;
  246. ///////////////////////////////////////////////////////////////////////////////
  247. // Functions Declaration Section //
  248. ///////////////////////////////////////////////////////////////////////////////
  249. //
  250. // Exported from spdrsif.c
  251. //
  252. //
  253. // [VERSION] section functions
  254. //
  255. VOID
  256. SpAsrCheckAsrStateFileVersion();
  257. //
  258. // [SYSTEMS] section functions
  259. //
  260. PWSTR
  261. SpAsrGetNtDirectoryPathBySystemKey(IN PWSTR SystemKey);
  262. BOOLEAN
  263. SpAsrGetAutoExtend(IN PWSTR SystemKey);
  264. //
  265. // [ASRFLAGS] section functions
  266. //
  267. BOOLEAN
  268. SpAsrGetSilentRepartitionFlag(IN PWSTR SystemKey);
  269. //
  270. // [DISKS.MBR] and [DISKS.GPT] sections functions
  271. //
  272. ULONG
  273. SpAsrGetMbrDiskRecordCount(VOID);
  274. ULONG
  275. SpAsrGetGptDiskRecordCount(VOID);
  276. ULONG
  277. SpAsrGetDiskRecordCount();
  278. PWSTR
  279. SpAsrGetDiskKey(
  280. IN PARTITION_STYLE Style, // GPT or MBR
  281. IN ULONG Index
  282. );
  283. PSIF_DISK_RECORD
  284. SpAsrGetDiskRecord(
  285. IN PARTITION_STYLE PartitionStyle,
  286. IN PWSTR DiskKey
  287. );
  288. PSIF_DISK_RECORD
  289. SpAsrCopyDiskRecord(IN PSIF_DISK_RECORD pInput);
  290. //
  291. // [PARTITIONS.MBR] and [PARTITIONS.GPT] section functions
  292. //
  293. ULONG
  294. SpAsrGetMbrPartitionRecordCount(VOID);
  295. ULONG
  296. SpAsrGetGptPartitionRecordCount(VOID);
  297. PWSTR
  298. SpAsrGetMbrPartitionKey(IN ULONG Index);
  299. PWSTR
  300. SpAsrGetGptPartitionKey(IN ULONG Index);
  301. PWSTR
  302. SpAsrGetDiskKeyByMbrPartitionKey(IN PWSTR PartitionKey);
  303. PWSTR
  304. SpAsrGetDiskKeyByGptPartitionKey(IN PWSTR PartitionKey);
  305. ULONGLONG
  306. SpAsrGetSectorCountByMbrDiskKey(IN PWSTR DiskKey);
  307. ULONGLONG
  308. SpAsrGetSectorCountByGptDiskKey(IN PWSTR DiskKey);
  309. PSIF_PARTITION_RECORD
  310. SpAsrGetMbrPartitionRecord(IN PWSTR PartitionKey);
  311. PSIF_PARTITION_RECORD
  312. SpAsrGetGptPartitionRecord(IN PWSTR PartitionKey);
  313. PSIF_PARTITION_RECORD
  314. SpAsrCopyPartitionRecord(IN PSIF_PARTITION_RECORD pInput);
  315. PSIF_PARTITION_RECORD_LIST
  316. SpAsrCopyPartitionRecordList(PSIF_PARTITION_RECORD_LIST pSrcList);
  317. VOID
  318. SpAsrInsertPartitionRecord(
  319. IN PSIF_PARTITION_RECORD_LIST pList,
  320. IN PSIF_PARTITION_RECORD pRec
  321. );
  322. PSIF_PARTITION_RECORD
  323. SpAsrPopNextPartitionRecord(IN PSIF_PARTITION_RECORD_LIST pList);
  324. // [INSTALLFILES] section functions
  325. PSIF_INSTALLFILE_RECORD
  326. SpAsrRemoveInstallFileRecord(IN SIF_INSTALLFILE_LIST *InstallFileList);
  327. VOID
  328. SpAsrDeleteInstallFileRecord(IN OUT PSIF_INSTALLFILE_RECORD pRec);
  329. PSIF_INSTALLFILE_LIST
  330. SpAsrInit3rdPartyFileList(IN PCWSTR SetupSourceDevicePath);
  331. //
  332. // Exported from spdrpset.c
  333. //
  334. ULONGLONG
  335. SpAsrGetTrueDiskSectorCount(IN ULONG Disk);
  336. VOID
  337. SpAsrCreatePartitionSets(
  338. IN PWSTR SetupSourceDevicePath,
  339. IN PWSTR DirectoryOnSetupSource
  340. );
  341. PDISK_REGION
  342. SpAsrDiskPartitionExists(
  343. IN ULONG Disk,
  344. IN PSIF_PARTITION_RECORD pRec
  345. );
  346. VOID SpAsrDbgDumpPartitionSets(VOID);
  347. VOID SpAsrDbgDumpPartitionLists(BYTE DataOption, PWSTR Msg);
  348. //
  349. // Exported from spdrmmgr.c
  350. //
  351. NTSTATUS
  352. SpAsrDeleteMountPoint(IN PWSTR PartitionDevicePath);
  353. NTSTATUS
  354. SpAsrSetVolumeGuid(
  355. IN PDISK_REGION pRegion,
  356. IN PWSTR VolumeGuid
  357. );
  358. WCHAR
  359. SpAsrGetPartitionDriveLetter(IN PDISK_REGION pRegion);
  360. NTSTATUS
  361. SpAsrSetPartitionDriveLetter(
  362. IN PDISK_REGION pRegion,
  363. IN WCHAR DriveLetter);
  364. //
  365. // Exported from spdrutil.c
  366. //
  367. ULONGLONG
  368. SpAsrConvertSectorsToMB(
  369. IN ULONGLONG SectorCount,
  370. IN ULONG BytesPerSector);
  371. PWSTR
  372. SpAsrGetRegionName(IN PDISK_REGION pRegion);
  373. ULONG
  374. SpAsrGetActualDiskSignature(IN ULONG Disk);
  375. PVOID
  376. SpAsrMemAlloc(
  377. IN ULONG Size,
  378. IN BOOLEAN IsErrorFatal);
  379. BOOLEAN
  380. SpAsrIsValidBootDrive(PWSTR NtDir);
  381. BOOLEAN
  382. SpAsrIsBootPartitionRecord(IN ULONG CriticalPartitionFlag);
  383. BOOLEAN
  384. SpAsrIsSystemPartitionRecord(IN ULONG CriticalPartitionFlag);
  385. VOID
  386. SpAsrDeleteStorageVolumes();
  387. VOID
  388. SpAsrRaiseFatalError(
  389. IN ULONG ErrorCode,
  390. IN PWSTR KdPrintStr);
  391. VOID
  392. SpAsrRaiseFatalErrorWs(
  393. IN ULONG ErrorCode,
  394. IN PWSTR KdPrintStr,
  395. IN PWSTR MessagStr
  396. );
  397. VOID
  398. SpAsrRaiseFatalErrorWsWs(
  399. IN ULONG ErrorCode,
  400. IN PWSTR KdPrintStr,
  401. IN PWSTR MessagStr1,
  402. IN PWSTR MessagStr2
  403. );
  404. VOID
  405. SpAsrRaiseFatalErrorWsLu(
  406. IN ULONG ErrorCode,
  407. IN PWSTR KdPrintStr,
  408. IN PWSTR MessagStr,
  409. IN ULONG MessagVal
  410. );
  411. VOID
  412. SpAsrRaiseFatalErrorLu(
  413. IN ULONG ErrorCode,
  414. IN PWSTR KdPrintStr,
  415. IN ULONG MessagVal
  416. );
  417. VOID
  418. SpAsrRaiseFatalErrorLuLu(
  419. IN ULONG ErrorCode,
  420. IN PWSTR KdPrintStr,
  421. IN ULONG MessagVal1,
  422. IN ULONG MessagVal2
  423. );
  424. BOOL
  425. SpAsrFileErrorDeleteSkipAbort(
  426. IN ULONG ErrorCode,
  427. IN PWSTR DestinationFile
  428. );
  429. BOOL
  430. SpAsrFileErrorRetrySkipAbort(
  431. IN ULONG ErrorCode,
  432. IN PWSTR SourceFile,
  433. IN PWSTR Label,
  434. IN PWSTR Vendor,
  435. IN BOOL AllowSkip
  436. );
  437. VOID
  438. SpAsrRaiseInternalError(
  439. IN PWSTR ModuleName,
  440. IN PWSTR ModuleCode,
  441. IN ULONG LineNumber,
  442. IN PWSTR KdPrintStr);
  443. ULONGLONG
  444. SpAsrStringToULongLong(
  445. IN PWSTR String,
  446. OUT PWCHAR *EndOfValue,
  447. IN unsigned Radix
  448. );
  449. LONGLONG
  450. SpAsrStringToLongLong(
  451. IN PWSTR String,
  452. OUT PWCHAR *EndOfValue,
  453. IN unsigned Radix
  454. );
  455. ULONG
  456. SpAsrStringToULong(
  457. IN PWSTR String,
  458. OUT PWCHAR *EndOfValue,
  459. IN unsigned Radix
  460. );
  461. VOID
  462. SpAsrGuidFromString(
  463. IN OUT GUID* Guid,
  464. IN PWSTR GuidString
  465. );
  466. BOOLEAN
  467. SpAsrIsZeroGuid(
  468. IN GUID * Guid
  469. );
  470. VOID SpAsrDeleteMountedDevicesKey(VOID);
  471. #endif // _SPDRPRIV_DEFN_