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.

370 lines
6.2 KiB

  1. /*++
  2. Header file for reparse point stress test
  3. Modification History:
  4. 08/18/97 anandn created
  5. --*/
  6. //
  7. // include system headers..
  8. //
  9. #include <nt.h>
  10. #include <ntrtl.h>
  11. #include <nturtl.h>
  12. #include <ntioapi.h>
  13. #include <windows.h>
  14. #include <winioctl.h>
  15. #include <winbase.h>
  16. #include <wtypes.h>
  17. #include <winver.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <time.h>
  21. #include <math.h>
  22. #define THREAD __declspec(thread) //thread local storage
  23. typedef ULONG TAG; // define a datatype for Tag
  24. #define NO_GLE ERROR_SUCCESS
  25. #define NO_TAG_SET IO_REPARSE_TAG_RESERVED_ZERO
  26. #define FILE_CLOSED INVALID_HANDLE_VALUE
  27. //
  28. // #def all our constants..
  29. //
  30. #define FIRST_USER_TAG (0x02) // first user tag
  31. #define MAX_USER_TAG ((TAG) 0xFFFF) // max tag settable by user
  32. #define MAX_ULONGLONG (~(ULONGLONG) 0)
  33. #define MAX_ULONG (~(ULONG) 0)
  34. #define PAGE_SIZE (0x1000) // system page size
  35. #define LINE_LENGTH 80 // 80 chars in a line
  36. #define FS_NAME_SIZE 20 // max size for a FS name.eg:"NTFS","FAT" etc..
  37. #define DRV_NAME_SIZE 2 // size of drive name string eg: "c:"
  38. #define MAX_DRIVES 26 // maximum number of drive letters
  39. #define MAX_DELAY 50 // maximum delay time in msecs
  40. #define MAX_TEST_FILES (1000)
  41. #define MIN_TEST_FILES (50)
  42. #define CHAR_CODES "."
  43. //
  44. // number of check values for data verification..
  45. //
  46. #define NUM_CHECK_BYTES 5
  47. //
  48. // logging options
  49. //
  50. #define LOG_OPTIONS ( TLS_REFRESH | TLS_SEV2 | TLS_WARN | TLS_PASS | \
  51. TLS_MONITOR | TLS_VARIATION | \
  52. TLS_SYSTEM | TLS_INFO )
  53. #define LOG_INFO(m) LogMessage( m, TLS_INFO, NO_GLE );
  54. #define LOG_WARN(m) LogMessage( m, TLS_WARN, NO_GLE );
  55. #define LOG_SEV2(m) LogMessage( m, TLS_SEV2, NO_GLE );
  56. #define LOG_INFO_GLE(m) LogMessage( m, TLS_INFO, GetLastError() );
  57. #define LOG_WARN_GLE(m) LogMessage( m, TLS_WARN, GetLastError() );
  58. #define LOG_SEV2_GLE(m) LogMessage( m, TLS_SEV2, GetLastError() );
  59. //
  60. // SZE returns the number of elements in an array
  61. //
  62. #define SZE(a) (sizeof(a)/sizeof(a[0]))
  63. //
  64. // Loops over each value in table passed in
  65. // WARNING: Assumption here is x is root name of both global array and
  66. // index variable. i.e. if x is foo, ifoo is index and gafoo is gloabl
  67. // array being looped over
  68. //
  69. #define FOR_EACH(x) for ( i##x = 0; i##x < SZE(ga##x); i##x++ )
  70. //
  71. // exception code raised for sev2 logging
  72. //
  73. #define EXCEPTION_CODE_SEV2 (0xE0000002)
  74. //
  75. // raise a severity2 exception
  76. //
  77. #define RAISE_EXCEPTION_SEV2 RaiseException( EXCEPTION_CODE_SEV2, 0,0,0);
  78. //
  79. // free a pointer if not null
  80. //
  81. #define FREE(ptr) if (NULL != (ptr)) { \
  82. free( ptr ); \
  83. ptr = NULL; \
  84. }
  85. //
  86. // few sleep times..
  87. //
  88. #define FIVE_SECS 5000
  89. #define TWO_SECS 2000
  90. #define ONE_SECS 1000
  91. enum TESTFILE_STATUS { FILE_LOCKED, FILE_FREE };
  92. enum TESTFILE_TYPE { ITS_A_FILE, ITS_A_DIR };
  93. //
  94. // the Options struct is filled from command line arguments
  95. //
  96. typedef struct {
  97. CHAR szProgramName[MAX_PATH + 1]; // name of test program (ie argv[0])
  98. CHAR Drive; // drive to test
  99. CHAR szTestDir[MAX_PATH + 1]; // test dir to use on specified drive
  100. DWORD dwMaxTestFiles;
  101. DWORD dwMinTestFiles;
  102. } OPTIONS, *POPTIONS;
  103. //
  104. // Central struc that holds info for a test file..
  105. //
  106. struct TESTFILE_INFO_NODE {
  107. WORD wFileStatus;
  108. HANDLE hFile;
  109. TAG RPTag;
  110. USHORT usDataBuffSize;
  111. BYTE CheckBytes[NUM_CHECK_BYTES];
  112. struct TESTFILE_INFO_NODE* pNext;
  113. WCHAR FileName[1];
  114. };
  115. typedef struct TESTFILE_INFO_NODE TESTFILE_INFO_NODE;
  116. typedef TESTFILE_INFO_NODE* PTESTFILE_INFO_NODE;
  117. //
  118. // function prototypes
  119. //
  120. VOID
  121. ParseArgs(INT argc, CHAR* argv[], POPTIONS pOptions);
  122. VOID
  123. PrintUsage( CHAR szProgramName[], CHAR szErrorString[] );
  124. VOID
  125. Initialize( OPTIONS Options );
  126. VOID
  127. Stress( OPTIONS Options );
  128. VOID
  129. Cleanup( OPTIONS Options );
  130. VOID
  131. ExceptionHandler( DWORD dwExceptionCode );
  132. HANDLE
  133. GetNewHandleIfClosed( PTESTFILE_INFO_NODE pNode );
  134. DWORD WINAPI
  135. CreateFileThread( LPVOID lpvThreadParam );
  136. DWORD WINAPI
  137. CloseOrDeleteFileThread( LPVOID lpvThreadParam );
  138. DWORD WINAPI
  139. RPSetThread( LPVOID lpvThreadParam );
  140. DWORD WINAPI
  141. RPGetThread( LPVOID lpvThreadParam );
  142. DWORD WINAPI
  143. RPDelThread( LPVOID lpvThreadParam );
  144. BOOL
  145. RPSet(PTESTFILE_INFO_NODE pNode,
  146. TAG RPTag, PUCHAR pDataBuff, USHORT usDataBuffSize);
  147. BOOL
  148. RPGet(CHAR szFileName[], BYTE **ppOutBuff);
  149. BOOL
  150. RPDel( PTESTFILE_INFO_NODE pNode );
  151. VOID
  152. SelectAndLockRandomNode( TESTFILE_INFO_NODE **ppNode, CHAR s[] );
  153. VOID
  154. ReleaseNodeLock( PTESTFILE_INFO_NODE pNode );
  155. BOOL
  156. AddToTestFileList( HANDLE hFile, CHAR szFileName[] );
  157. BOOL
  158. DeleteFromTestFileList( PTESTFILE_INFO_NODE pNode );
  159. TAG
  160. GetTagToSet( VOID );
  161. VOID
  162. DumpBuff( PBYTE pData, WORD wSize );
  163. VOID
  164. GenerateTempFileName( LPSTR lpFileName );
  165. HANDLE
  166. CreateRPFile( CHAR szFileName[] );
  167. HANDLE
  168. OpenHandleToVolume(CHAR szVolName[]);
  169. BOOL
  170. IsFileSysNtfs(CHAR szVolRoot[]);
  171. VOID
  172. StartLogSession(CHAR szProgName[]);
  173. VOID
  174. EndLogSession(DWORD dwExitCode);
  175. ULONG
  176. HiPart(ULONGLONG n);
  177. ULONG
  178. LoPart(ULONGLONG n);
  179. VOID
  180. LogMessage( CHAR szLogMsg[], ULONG dwLevel, DWORD gle );
  181. VOID
  182. LogAtLevel( CHAR szOutMsg[], ULONG dwLevel );
  183. VOID
  184. GenerateReparsePoints( VOID );
  185. VOID
  186. SetReparsePoint( CHAR szFileName[],
  187. TAG Tag,
  188. UCHAR szData[] );
  189. TAG
  190. GetTagToSet( VOID );
  191. VOID
  192. GetReparsePoint( VOID );
  193. VOID
  194. DeleteReparsePoint( VOID );
  195. VOID
  196. PrintError(char szWhatFailed[], int flag);
  197. HANDLE
  198. RPOpen (LPSTR szFileName, LPSTR szOption );
  199. VOID
  200. SzToWsz ( OUT WCHAR *Unicode,
  201. IN char *Ansi ) ;
  202. VOID
  203. WszToSz ( OUT char *Ansi,
  204. IN WCHAR *Unicode );
  205. NTSTATUS OpenObject (
  206. WCHAR *pwszFile,
  207. ULONG CreateOptions,
  208. ULONG DesiredAccess,
  209. ULONG ShareAccess,
  210. ULONG CreateDisposition,
  211. IO_STATUS_BLOCK *IoStatusBlock,
  212. HANDLE *ObjectHandle);