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.

557 lines
18 KiB

  1. /****************************************************************************************************************
  2. FILENAME: SysStruc.h
  3. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  4. DESCRIPTION:
  5. This contains the windows NT file system data strucutures that we need to use. The headers used by NTFS
  6. cannot be included directly since they contain kernel mode stuff, so this contains simply the data
  7. structures we need.
  8. /****************************************************************************************************************/
  9. #ifndef _SYSSTRUC_H_
  10. #define _SYSSTRUC_H_
  11. //Makes sure the following structures are not aligned on memory
  12. //boundaries. They are byte for byte representative of how they should
  13. //be in memory.
  14. #include "pshpack1.h" //0.0E00 DO NOT MOVE
  15. //This is the format of a standard FAT16 boot sector. Kept here for reference.
  16. //typedef struct {
  17. // UCHAR Jump[3];
  18. // UCHAR Name[8];
  19. // USHORT BytesPerSector;
  20. // UCHAR SectorsPerCluster;
  21. // USHORT BootSectors;
  22. // UCHAR Fats;
  23. // USHORT RootDirs;
  24. // USHORT TotalSectors;
  25. // UCHAR Media;
  26. // USHORT SectorsPerFat;
  27. // USHORT SectorsPerTrack;
  28. // USHORT Heads;
  29. // DWORD HiddenSectors;
  30. // DWORD BigTotalSectors;
  31. //}BOOTSECTOR;
  32. //This is the NTFS boot sector. Kept here for reference.
  33. //typedef struct _PACKED_BOOT_SECTOR {
  34. // UCHAR /* 0x000 */ Jump[3];
  35. // UCHAR /* 0x003 */ Oem[8];
  36. // USHORT /* 0x00B */ BytesPerSector;
  37. // UCHAR /* 0x00D */ SectorsPerCluster;
  38. // USHORT /* 0x00E */ ReservedSectors; // (zero)
  39. // UCHAR /* 0x010 */ Fats; // (zero)
  40. // USHORT /* 0x011 */ RootEntries; // (zero)
  41. // USHORT /* 0x013 */ Sectors; // (zero)
  42. // UCHAR /* 0x015 */ Media;
  43. // USHORT /* 0x016 */ SectorsPerFat; // (zero)
  44. // USHORT /* 0x018 */ SectorsPerTrack;
  45. // USHORT /* 0x01A */ Heads;
  46. // DWORD /* 0x01C */ HiddenSectors; // (zero)
  47. // DWORD /* 0x020 */ LargeSectors; // (zero)
  48. // UCHAR /* 0x024 */ Unused[4];
  49. // LONGLONG /* 0x028 */ NumberSectors;
  50. // LCN /* 0x030 */ MftStartLcn;
  51. // LCN /* 0x038 */ Mft2StartLcn;
  52. // ULONG /* 0x040 */ ClustersPerFileRecordSegment;
  53. // ULONG /* 0x044 */ DefaultClustersPerIndexAllocationBuffer;
  54. // LONGLONG /* 0x048 */ SerialNumber;
  55. // ULONG /* 0x050 */ Checksum;
  56. // UCHAR /* 0x054 */ BootStrap[0x200-0x044];
  57. //} PACKED_BOOT_SECTOR; // sizeof = 0x200
  58. //This is the format of a standard FAT directory entry.
  59. typedef struct {
  60. UCHAR Name[8];
  61. UCHAR Ext[3];
  62. BYTE Attribute;
  63. BYTE Reserved;
  64. BYTE CreateTimeMillisecs;
  65. USHORT CreateTime;
  66. USHORT CreateDate;
  67. USHORT LastAccessDate;
  68. USHORT ClusterHigh;
  69. BYTE Time[2];
  70. BYTE Date[2];
  71. USHORT ClusterLow;
  72. DWORD FileSize;
  73. }DIRSTRUC;
  74. //Undoes the byte alignment disabling done by pshpack1.h above.
  75. #include "poppack.h" //0.0E00 DO NOT MOVE
  76. //On NTFS - this is the first file record number to begin defragging at (skip all the system entries).
  77. #define FIRST_USER_FILE_NUMBER 16
  78. //On NTFS - the FRN of the root directory.
  79. #define ROOT_FILE_NAME_INDEX_NUMBER (5) //File Record Number of the Root Directory
  80. /*************************************************************************************************************
  81. From PRIVATE\NTOS\INC\LFS.H
  82. /************************************************************************************************************/
  83. //The format of an NTFS data structure.
  84. //Shouldn't this be gotten out of a standard windows header file?
  85. typedef struct _MULTI_SECTOR_HEADER {
  86. UCHAR Signature[4];
  87. USHORT UpdateSequenceArrayOffset;
  88. USHORT UpdateSequenceArraySize;
  89. } MULTI_SECTOR_HEADER, *PMULTI_SECTOR_HEADER;
  90. typedef LARGE_INTEGER LSN, *PLSN;
  91. /*************************************************************************************************************
  92. From PRIVATE\NTOS\CNTFS\NTFS.H
  93. /************************************************************************************************************/
  94. //The format of another standard structure found in an NTFS FRS.
  95. typedef struct _MFT_SEGMENT_REFERENCE {
  96. ULONG LowPart; // offset = 0x000
  97. USHORT HighPart; // offset = 0x004
  98. USHORT SequenceNumber; // offset = 0x006
  99. } MFT_SEGMENT_REFERENCE, *PMFT_SEGMENT_REFERENCE; // sizeof = 0x008
  100. typedef MFT_SEGMENT_REFERENCE FILE_REFERENCE, *PFILE_REFERENCE;
  101. typedef USHORT UPDATE_SEQUENCE_NUMBER, *PUPDATE_SEQUENCE_NUMBER;
  102. typedef UPDATE_SEQUENCE_NUMBER UPDATE_SEQUENCE_ARRAY[1];
  103. //The format of an NTFS FRS Header.
  104. typedef struct _FILE_RECORD_SEGMENT_HEADER {
  105. MULTI_SECTOR_HEADER MultiSectorHeader; // offset = 0x000
  106. LSN Lsn; // offset = 0x008
  107. USHORT SequenceNumber; // offset = 0x010
  108. USHORT ReferenceCount; // offset = 0x012
  109. USHORT FirstAttributeOffset; // offset = 0x014
  110. USHORT Flags; // offset = 0x016
  111. ULONG FirstFreeByte; // offset = x0018
  112. ULONG BytesAvailable; // offset = 0x01C
  113. FILE_REFERENCE BaseFileRecordSegment; // offset = 0x020
  114. USHORT NextAttributeInstance; // offset = 0x028
  115. UPDATE_SEQUENCE_ARRAY UpdateArrayForCreateOnly; // offset = 0x02A
  116. } FILE_RECORD_SEGMENT_HEADER;
  117. typedef FILE_RECORD_SEGMENT_HEADER *PFILE_RECORD_SEGMENT_HEADER;
  118. #define FILE_RECORD_SEGMENT_IN_USE (0x0001)
  119. #define FILE_FILE_NAME_INDEX_PRESENT (0x0002)
  120. typedef ULONG ATTRIBUTE_TYPE_CODE;
  121. typedef LONGLONG VCN;
  122. typedef VCN *PVCN;
  123. //The format of an NTFS FRS attribute header - specifies what type of attributes follow.
  124. typedef struct _ATTRIBUTE_RECORD_HEADER {
  125. ATTRIBUTE_TYPE_CODE TypeCode; // offset = 0x000
  126. ULONG RecordLength; // offset = 0x004
  127. UCHAR FormCode; // offset = 0x008
  128. UCHAR NameLength; // offset = 0x009
  129. USHORT NameOffset; // offset = 0x00A
  130. USHORT Flags; // offset = 0x00C
  131. USHORT Instance; // offset = 0x00E
  132. union {
  133. struct {
  134. ULONG ValueLength; // offset = 0x010
  135. USHORT ValueOffset; // offset = 0x014
  136. UCHAR ResidentFlags; // offset = 0x016
  137. UCHAR Reserved; // offset = 0x017
  138. } Resident;
  139. struct {
  140. VCN LowestVcn; // offset = 0x010
  141. VCN HighestVcn; // offset = 0x018
  142. USHORT MappingPairsOffset; // offset = 0x020
  143. UCHAR CompressionUnit; // offset = 0x022
  144. UCHAR Reserved[5]; // offset = 0x023
  145. LONGLONG AllocatedLength; // offset = 0x028
  146. LONGLONG FileSize; // offset = 0x030
  147. LONGLONG ValidDataLength; // offset = 0x038
  148. LONGLONG TotalAllocated; // offset = 0x040
  149. } Nonresident;
  150. } Form;
  151. } ATTRIBUTE_RECORD_HEADER;
  152. typedef ATTRIBUTE_RECORD_HEADER *PATTRIBUTE_RECORD_HEADER;
  153. //The different types of NTFS attributes. This would be in TypeCode of the ATTRIBUTE_RECORD_HEADER structure above.
  154. #define $UNUSED (0X0)
  155. #define $STANDARD_INFORMATION (0x10)
  156. #define $ATTRIBUTE_LIST (0x20)
  157. #define $FILE_NAME (0x30)
  158. #define $VOLUME_VERSION (0x40)
  159. #define $SECURITY_DESCRIPTOR (0x50)
  160. #define $VOLUME_NAME (0x60)
  161. #define $VOLUME_INFORMATION (0x70)
  162. #define $DATA (0x80)
  163. #define $INDEX_ROOT (0x90)
  164. #define $INDEX_ALLOCATION (0xA0)
  165. #define $BITMAP (0xB0)
  166. #define $SYMBOLIC_LINK (0xC0)
  167. #define $EA_INFORMATION (0xD0)
  168. #define $EA (0xE0)
  169. #define $FIRST_USER_DEFINED_ATTRIBUTE (0x100)
  170. #define $END (0xFFFFFFFF)
  171. //These specify whether the attribute is resident or not and go in the FormCode entry of the ATTRIBUTE_RECORD_HEADER structure above.
  172. #define RESIDENT_FORM (0x00)
  173. #define NONRESIDENT_FORM (0x01)
  174. typedef struct _DUPLICATED_INFORMATION {
  175. LONGLONG CreationTime; // offset = 0x000
  176. LONGLONG LastModificationTime; // offset = 0x008
  177. LONGLONG LastChangeTime; // offset = 0x010
  178. LONGLONG LastAccessTime; // offset = 0x018
  179. LONGLONG AllocatedLength; // offset = 0x020
  180. LONGLONG FileSize; // offset = 0x028
  181. ULONG FileAttributes; // offset = 0x030
  182. USHORT PackedEaSize; // offset = 0x034
  183. USHORT Reserved; // offset = 0x036
  184. } DUPLICATED_INFORMATION; // sizeof = 0x038
  185. typedef DUPLICATED_INFORMATION *PDUPLICATED_INFORMATION;
  186. //If we have an attribute list, this is the format of the entries in it.
  187. typedef struct _ATTRIBUTE_LIST_ENTRY {
  188. ATTRIBUTE_TYPE_CODE AttributeTypeCode; // offset = 0x000
  189. USHORT RecordLength; // offset = 0x004
  190. UCHAR AttributeNameLength; // offset = 0x006
  191. UCHAR AttributeNameOffset; // offset = 0x007
  192. VCN LowestVcn; // offset = 0x008
  193. MFT_SEGMENT_REFERENCE SegmentReference; // offset = 0x010
  194. USHORT Instance; // offset = 0x018
  195. WCHAR AttributeName[1]; // offset = 0x01A
  196. } ATTRIBUTE_LIST_ENTRY;
  197. typedef ATTRIBUTE_LIST_ENTRY *PATTRIBUTE_LIST_ENTRY;
  198. //This the the format of a standard information attribute structure.
  199. typedef struct _STANDARD_INFORMATION {
  200. LONGLONG CreationTime; // offset = 0x000
  201. LONGLONG LastModificationTime; // offset = 0x008
  202. LONGLONG LastChangeTime; // offset = 0x010
  203. LONGLONG LastAccessTime; // offset = 0x018
  204. ULONG FileAttributes; // offset = 0x020
  205. ULONG MaximumVersions; // offset = 0x024
  206. ULONG VersionNumber; // offset = 0x028
  207. ULONG Reserved; // offset = 0x02c
  208. } STANDARD_INFORMATION; // sizeof = 0x030
  209. typedef STANDARD_INFORMATION *PSTANDARD_INFORMATION;
  210. //This is the format of a file name attribute structure.
  211. typedef struct _FILE_NAME {
  212. FILE_REFERENCE ParentDirectory; // offset = 0x000
  213. DUPLICATED_INFORMATION Info; // offset = 0x008
  214. UCHAR FileNameLength; // offset = 0x040
  215. UCHAR Flags; // offset = 0x041
  216. WCHAR FileName[1]; // offset = 0x042
  217. } FILE_NAME;
  218. typedef FILE_NAME *PFILE_NAME;
  219. #define FILE_NAME_NTFS (0x01)
  220. //Contains the version number for the volume, and the dirty bit.
  221. typedef struct _VOLUME_INFORMATION {
  222. LONGLONG Reserved;
  223. UCHAR MajorVersion; // offset = 0x000
  224. UCHAR MinorVersion; // offset = 0x001
  225. USHORT VolumeFlags; // offset = 0x002
  226. } VOLUME_INFORMATION; // sizeof = 0x004
  227. typedef VOLUME_INFORMATION *PVOLUME_INFORMATION;
  228. //Dirty volume flags.
  229. #define VOLUME_DIRTY (0x0001)
  230. #define VOLUME_RESIZE_LOG_FILE (0x0002) //This one unused?
  231. #define VOLUME_UPGRADE_ON_MOUNT (0x0004)
  232. /****************************************************************************************************************
  233. These are required for the Razzle build
  234. */
  235. // begin_ntndis
  236. //
  237. // NTSTATUS
  238. //
  239. typedef LONG NTSTATUS;
  240. /*lint -e624 */ // Don't complain about different typedefs. // winnt
  241. typedef NTSTATUS *PNTSTATUS;
  242. /*lint +e624 */ // Resume checking for different typedefs. // winnt
  243. //
  244. // Status values are 32 bit values layed out as follows:
  245. //
  246. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  247. // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  248. // +---+-+-------------------------+-------------------------------+
  249. // |Sev|C| Facility | Code |
  250. // +---+-+-------------------------+-------------------------------+
  251. //
  252. // where
  253. //
  254. // Sev - is the severity code
  255. //
  256. // 00 - Success
  257. // 01 - Informational
  258. // 10 - Warning
  259. // 11 - Error
  260. //
  261. // C - is the Customer code flag
  262. //
  263. // Facility - is the facility code
  264. //
  265. // Code - is the facility's status code
  266. //
  267. //
  268. // Generic test for success on any status value (non-negative numbers
  269. // indicate success).
  270. //
  271. #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
  272. //
  273. // Generic test for information on any status value.
  274. //
  275. #define NT_INFORMATION(Status) ((ULONG)(Status) >> 30 == 1)
  276. //
  277. // Generic test for warning on any status value.
  278. //
  279. #define NT_WARNING(Status) ((ULONG)(Status) >> 30 == 2)
  280. //
  281. // Generic test for error on any status value.
  282. //
  283. #define NT_ERROR(Status) ((ULONG)(Status) >> 30 == 3)
  284. // begin_winnt
  285. #define APPLICATION_ERROR_MASK 0x20000000
  286. #define ERROR_SEVERITY_SUCCESS 0x00000000
  287. #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
  288. #define ERROR_SEVERITY_WARNING 0x80000000
  289. #define ERROR_SEVERITY_ERROR 0xC0000000
  290. // end_winnt
  291. // end_ntndis
  292. // begin_ntddk begin_nthal
  293. //
  294. // Define the base asynchronous I/O argument types
  295. //
  296. // end_ntddk end_nthal
  297. #define STATUS_BUFFER_OVERFLOW ((NTSTATUS)0x80000005L)
  298. /*************************************************************************************************************
  299. From PUBLIC\SDK\INC\WINBASE.H
  300. These are the declarations for the GUID-base volume functions
  301. /************************************************************************************************************/
  302. #ifndef FindFirstVolume
  303. #if !defined(_KERNEL32_)
  304. #define WINBASEAPI DECLSPEC_IMPORT
  305. #else
  306. #define WINBASEAPI
  307. #endif
  308. WINBASEAPI
  309. HANDLE
  310. WINAPI
  311. FindFirstVolumeA(
  312. LPSTR lpszVolumeName,
  313. DWORD cchBufferLength
  314. );
  315. WINBASEAPI
  316. HANDLE
  317. WINAPI
  318. FindFirstVolumeW(
  319. LPWSTR lpszVolumeName,
  320. DWORD cchBufferLength
  321. );
  322. #ifdef UNICODE
  323. #define FindFirstVolume FindFirstVolumeW
  324. #else
  325. #define FindFirstVolume FindFirstVolumeA
  326. #endif // !UNICODE
  327. WINBASEAPI
  328. BOOL
  329. WINAPI
  330. FindNextVolumeA(
  331. HANDLE hFindVolume,
  332. LPSTR lpszVolumeName,
  333. DWORD cchBufferLength
  334. );
  335. WINBASEAPI
  336. BOOL
  337. WINAPI
  338. FindNextVolumeW(
  339. HANDLE hFindVolume,
  340. LPWSTR lpszVolumeName,
  341. DWORD cchBufferLength
  342. );
  343. #ifdef UNICODE
  344. #define FindNextVolume FindNextVolumeW
  345. #else
  346. #define FindNextVolume FindNextVolumeA
  347. #endif // !UNICODE
  348. WINBASEAPI
  349. BOOL
  350. WINAPI
  351. FindVolumeClose(
  352. HANDLE hFindVolume
  353. );
  354. WINBASEAPI
  355. HANDLE
  356. WINAPI
  357. FindFirstVolumeMountPointA(
  358. LPCSTR lpszRootPathName,
  359. LPSTR lpszVolumeMountPoint,
  360. DWORD cchBufferLength
  361. );
  362. WINBASEAPI
  363. HANDLE
  364. WINAPI
  365. FindFirstVolumeMountPointW(
  366. LPCWSTR lpszRootPathName,
  367. LPWSTR lpszVolumeMountPoint,
  368. DWORD cchBufferLength
  369. );
  370. #ifdef UNICODE
  371. #define FindFirstVolumeMountPoint FindFirstVolumeMountPointW
  372. #else
  373. #define FindFirstVolumeMountPoint FindFirstVolumeMountPointA
  374. #endif // !UNICODE
  375. WINBASEAPI
  376. BOOL
  377. WINAPI
  378. FindNextVolumeMountPointA(
  379. HANDLE hFindVolumeMountPoint,
  380. LPSTR lpszVolumeMountPoint,
  381. DWORD cchBufferLength
  382. );
  383. WINBASEAPI
  384. BOOL
  385. WINAPI
  386. FindNextVolumeMountPointW(
  387. HANDLE hFindVolumeMountPoint,
  388. LPWSTR lpszVolumeMountPoint,
  389. DWORD cchBufferLength
  390. );
  391. #ifdef UNICODE
  392. #define FindNextVolumeMountPoint FindNextVolumeMountPointW
  393. #else
  394. #define FindNextVolumeMountPoint FindNextVolumeMountPointA
  395. #endif // !UNICODE
  396. WINBASEAPI
  397. BOOL
  398. WINAPI
  399. FindVolumeMountPointClose(
  400. HANDLE hFindVolumeMountPoint
  401. );
  402. WINBASEAPI
  403. BOOL
  404. WINAPI
  405. SetVolumeMountPointA(
  406. LPCSTR lpszVolumeMountPoint,
  407. LPCSTR lpszVolumeName
  408. );
  409. WINBASEAPI
  410. BOOL
  411. WINAPI
  412. SetVolumeMountPointW(
  413. LPCWSTR lpszVolumeMountPoint,
  414. LPCWSTR lpszVolumeName
  415. );
  416. #ifdef UNICODE
  417. #define SetVolumeMountPoint SetVolumeMountPointW
  418. #else
  419. #define SetVolumeMountPoint SetVolumeMountPointA
  420. #endif // !UNICODE
  421. WINBASEAPI
  422. BOOL
  423. WINAPI
  424. DeleteVolumeMountPointA(
  425. LPCSTR lpszVolumeMountPoint
  426. );
  427. WINBASEAPI
  428. BOOL
  429. WINAPI
  430. DeleteVolumeMountPointW(
  431. LPCWSTR lpszVolumeMountPoint
  432. );
  433. #ifdef UNICODE
  434. #define DeleteVolumeMountPoint DeleteVolumeMountPointW
  435. #else
  436. #define DeleteVolumeMountPoint DeleteVolumeMountPointA
  437. #endif // !UNICODE
  438. WINBASEAPI
  439. BOOL
  440. WINAPI
  441. GetVolumeNameForVolumeMountPointA(
  442. LPCSTR lpszVolumeMountPoint,
  443. LPSTR lpszVolumeName,
  444. DWORD cchBufferLength
  445. );
  446. WINBASEAPI
  447. BOOL
  448. WINAPI
  449. GetVolumeNameForVolumeMountPointW(
  450. LPCWSTR lpszVolumeMountPoint,
  451. LPWSTR lpszVolumeName,
  452. DWORD cchBufferLength
  453. );
  454. #ifdef UNICODE
  455. #define GetVolumeNameForVolumeMountPoint GetVolumeNameForVolumeMountPointW
  456. #else
  457. #define GetVolumeNameForVolumeMountPoint GetVolumeNameForVolumeMountPointA
  458. #endif // !UNICODE
  459. WINBASEAPI
  460. BOOL
  461. WINAPI
  462. GetVolumePathNameA(
  463. LPCSTR lpszFileName,
  464. LPSTR lpszVolumePathName,
  465. DWORD cchBufferLength
  466. );
  467. WINBASEAPI
  468. BOOL
  469. WINAPI
  470. GetVolumePathNameW(
  471. LPCWSTR lpszFileName,
  472. LPWSTR lpszVolumePathName,
  473. DWORD cchBufferLength
  474. );
  475. #ifdef UNICODE
  476. #define GetVolumePathName GetVolumePathNameW
  477. #else
  478. #define GetVolumePathName GetVolumePathNameA
  479. #endif // !UNICODE
  480. #endif // #ifndef FindFirstVolume
  481. #endif //#define _SYSSTRUC_H_