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.

291 lines
9.2 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993 - 1993.
  5. //
  6. // File: $(CTCAIROLE)\filemnk\testsrc\pathgen\pathgen.hxx
  7. //
  8. // Contents: Header file for CPathGen path generator class
  9. //
  10. // Classes: CPathGen
  11. //
  12. // Methods:
  13. // public
  14. // CPathGen
  15. // ~CPathGen
  16. // Dump
  17. // DumpPrefixList
  18. // GetMediaType
  19. // GetName
  20. // GetNumVariations
  21. // GetPath
  22. // GetPrefix
  23. // GetSeed
  24. // GetRedirVolume
  25. // GetVolume
  26. // MangleLongFileName
  27. // SetToRootDirectory
  28. // private
  29. // BuildPrefixList
  30. // BuildUserList
  31. // CreatePathTree
  32. // CreatePathList
  33. // CreatePlayground
  34. // DestroyDiskPathTree
  35. // DestroyDiskPathList
  36. // DestroyMemPathList
  37. // DestroyMemPathTree
  38. // DestroyPrefixes
  39. // DumpTree
  40. // GetPathFromTree
  41. // GetPathFromList
  42. // GenPathTreeElements
  43. // GenPathListElements
  44. // PickBody
  45. // PickFileName
  46. // SetNumVariations
  47. // SetTreeRoot
  48. // SetVolume
  49. //
  50. //
  51. // History: 30-Jun-93 DarrylA Created.
  52. // 22-Nov-94 EricHans Change sharing name to uppercase.
  53. // 15-Dec-95 EricHans Add MangleLongFileName method
  54. //
  55. //----------------------------------------------------------------------
  56. #ifndef _PATHGEN_H_
  57. #define _PATHGEN_H_
  58. // DECLARE_DEBUG(fmkt);
  59. #define MAX_VARIATIONS 0xffff // this is huge! but possible
  60. // The size of this number must fit in TESTSHARE_CREATION_STRING
  61. #define MAX_SHARE_INDEX ULONG_MAX
  62. // The format size for the %u should be at least large enough for
  63. // MAX_SHARE_INDEX which is currently 8 decimal places so that we
  64. // stay below the LM2.0 limit which is currently 12 chars long
  65. #define TESTSHARE_CREATION_STRINGW L"CPG%08X"
  66. #define TESTSHARE_CREATION_STRINGA "CPG%08X"
  67. #ifndef MINLEVELLENGTH
  68. #define MINLEVELLENGTH 1 // length of minimum path
  69. #endif
  70. #ifndef MAXFSLEN
  71. #define MAXFSLEN sizeof(L"HPFS")
  72. #endif
  73. #ifndef MIN_BIND_NAME_LEN
  74. #define MIN_BIND_NAME_LEN (sizeof("z.ext") - 1)
  75. #endif
  76. // the drive letter c is insignificant
  77. #define VOLROOT_NAMELEN (sizeof("c:\\") - 1)
  78. #ifndef BIGBUF
  79. #define BIGBUF 2048
  80. #endif
  81. #define TREE 1
  82. #define LIST 2
  83. // BUGBUG - there is a bug in the NT file system handling that does not
  84. // allow it to utilize the entire length of MAX_PATH_LEN. The number 15
  85. // used here was determined experimentally.
  86. #ifndef MAX_PATH_LEN
  87. #define MAX_PATH_LEN _MAX_DIR - 15
  88. #endif
  89. typedef enum PREFIXTYPES // pfxt
  90. {
  91. PREFIX_NONE = 0,
  92. PREFIX_RELATIVE_ROOT,
  93. PREFIX_RELATIVE_PATH,
  94. PREFIX_LOCAL_ROOT,
  95. PREFIX_LOCAL_VOLUME,
  96. PREFIX_UNC_BKSLSH,
  97. PREFIX_UNC_EXMRK,
  98. PREFIX_RELATIVE_SHARE,
  99. PREFIX_ABSOLUTE_SHARE,
  100. PREFIX_DFS_MACHINE,
  101. PREFIX_DFS_DOMAIN,
  102. PREFIX_DFS_ORG,
  103. PREFIX_NUM_DEF_PREFIXES,
  104. PREFIX_RANDOM // used to tell enumerator to return random prefix
  105. } PrefixTypes;
  106. // Enumerated disk media types
  107. enum MediaType { FAT, HPFS, NTFS, OFS, UNKNOWN, UNINIT, FATEXTENDED };
  108. typedef struct PATHBINTREE // pbt
  109. {
  110. ULONG ulPosition;
  111. LPWSTR wcsPathElement;
  112. struct PATHBINTREE *pbtLeft;
  113. struct PATHBINTREE *pbtRight;
  114. } PathBinTree, *LPPathBinTree;
  115. #ifndef _BUGBUG_CAIRO_
  116. // Need to define DFS_ROOT to satisfy compiler in non-Cairo builds
  117. enum DFS_ROOT
  118. {
  119. DFS_ROOT_MACH,
  120. DFS_ROOT_DOM,
  121. DFS_ROOT_ORG
  122. };
  123. #endif
  124. // Global flag used to externally enable the use of an unmappable wchar in
  125. // the character set passed to datagen
  126. extern BOOL fUseUnicodeUnmappableWCHAR;
  127. // Helper functions
  128. BOOL CreateDir(LPWSTR wcsPath);
  129. ULONG FindItemCount(LPWSTR wcsItems, WCHAR wcDelim);
  130. LPWSTR FixupUNCName(LPWSTR wcsPath);
  131. HRESULT GetDfsBasedPath(LPWSTR wcsPath, LPWSTR *wcsDFSPath, DFS_ROOT dfsRoot);
  132. LPWSTR GetMachineName(void);
  133. LPWSTR wcsNEWdup(LPWSTR wcs);
  134. class CPathGen
  135. {
  136. public:
  137. CPathGen(ULONG ulNumVariations,
  138. ULONG ulSeed,
  139. WCHAR wcVolume,
  140. LPWSTR wcsTreeRoot,
  141. ULONG ulNumDirs,
  142. LPWSTR wcsUserPaths,
  143. LPWSTR wcsUserPrefixes,
  144. BOOL fCreateStorage,
  145. HRESULT *hrStatus);
  146. ~CPathGen();
  147. void Dump(void);
  148. void DumpPrefixList(void);
  149. MediaType GetMediaType(void);
  150. HRESULT GetName(LPWSTR *pwcsName, ULONG ulMaxLen);
  151. HRESULT GetName(LPWSTR *pwcsName, ULONG ulMaxLen, ULONG ulExtLen);
  152. HRESULT GetName(LPWSTR *pwcsName, ULONG ulMaxLen, LPCWSTR pwcsExt);
  153. inline ULONG GetNumVariations(void) { return m_culNumVariations; }
  154. LPWSTR GetPath(ULONG ulPath);
  155. LPWSTR GetPrefix(ULONG ulPrefix);
  156. inline ULONG GetSeed(void) { return m_ulSeed; }
  157. WCHAR GetRedirVolume(void);
  158. inline WCHAR GetVolume(void) { return m_wcVolume; }
  159. HRESULT MangleLongFileName(LPCWSTR wcsLongName, LPWSTR wcsMangledName);
  160. void SetToRootDirectory(void);
  161. private:
  162. void BuildPrefixList(LPWSTR wcsUserPrefixes);
  163. ULONG BuildUserList(LPWSTR wcsUserPrefixes, LPWSTR **wcsList);
  164. LPPathBinTree CreatePathTree(ULONG culSize,
  165. ULONG ulNewPosition,
  166. ULONG ulCurrentLevel,
  167. ULONG culLengthSoFar);
  168. HRESULT CreatePathList(ULONG culLengthSoFar, LPWSTR wcsPath,
  169. PULONG pulCount);
  170. void CreatePlayground(DWORD dwType, LPWSTR wcsUserPaths);
  171. void DestroyDiskPathTree(LPPathBinTree ppbtTree);
  172. void DestroyDiskPathList(LPWSTR *wcsPathList);
  173. void DestroyMemPathList(void);
  174. void DestroyMemPathTree(LPPathBinTree ppbtTree);
  175. void DestroyPrefixes(void);
  176. void DumpTree(LPPathBinTree ppbtTree);
  177. void GetPathFromTree(ULONG ulPath, LPPathBinTree ppbtTree, LPWSTR wcsPath);
  178. void GetPathFromList(ULONG ulPath, LPWSTR wcsPath);
  179. void GenPathTreeElements(LPPathBinTree pbtPathTree);
  180. void GenPathListElements(LPWSTR *pwcsPathList);
  181. ULONG PickBody(void);
  182. ULONG PickFileName(void);
  183. void SetNumVariations(ULONG ulNumVariations);
  184. void SetTreeRoot(LPWSTR wcsTreeRoot);
  185. void SetVolume(WCHAR wcVolume);
  186. // Member variables
  187. BOOL m_fDefPrefixes; // are we using our default prefixes
  188. DG_UNICODE m_dguNames; // string generator
  189. DG_INTEGER m_dgiIndex; // index generator
  190. MediaType m_mtMedia; // file system of test root
  191. LPPathBinTree m_ppbtPathTree; // binary tree of path info
  192. LPWSTR *m_pwcsPathList; // array of directory strings
  193. LPWSTR *m_pwcsPrefixList; // array of prefix strings
  194. LPWSTR m_wcsTreeRoot; // root of test tree
  195. WCHAR m_wcVolume; // volume letter of test root
  196. ULONG m_ulSeed; // seed used by data generators
  197. ULONG m_culBasePathLen; // length of longest prefix + other
  198. // things that can be predetermined
  199. ULONG m_culNumDirs; // number of directories to create
  200. ULONG m_culNumLevels; // number of levels in tree
  201. ULONG m_culNumVariations; // number of variations to create
  202. ULONG m_culNumPrefixes; // number of prefixes available
  203. ULONG *m_aulFirstElement; // element # of top dir in dir list
  204. BOOL m_fCreateStorage; // should we create dirs on disk
  205. LPWSTR m_wcsValidCharSet; // pointer to valid set for this media
  206. LPWSTR m_wcsTestShare; // sharename
  207. };
  208. //+---------------------------------------------------------------------
  209. //
  210. // Function: NumLevels
  211. //
  212. // Synopsis: returns number of levels required in a binary tree
  213. //
  214. // Arguments: [ulNum] -- number of items going into tree
  215. //
  216. // History: 25-Aug-93 DarrylA Created.
  217. //
  218. //----------------------------------------------------------------------
  219. inline ULONG NumLevels(ULONG ulNum)
  220. {
  221. ULONG ulLevels = 0;
  222. while(0 != ulNum)
  223. {
  224. ++ulLevels;
  225. ulNum >>= 1;
  226. }
  227. return ulLevels;
  228. }
  229. //+---------------------------------------------------------------------
  230. //
  231. // Function: AdjustToNextPowerOf2
  232. //
  233. // Synopsis: returns next power of 2 > ul
  234. //
  235. // Arguments: [ul] -- number to convert
  236. //
  237. // History: 25-Aug-93 DarrylA Created.
  238. //
  239. //----------------------------------------------------------------------
  240. inline ULONG AdjustToNextPowerOf2(ULONG ul)
  241. {
  242. ULONG ulNum = 1L;
  243. // if ul > msb set on a ULONG, next power of 2 is > ULONG
  244. if((~(ULONG_MAX >> 1) < ul))
  245. {
  246. RaiseException((ULONG) E_FAIL, 0, 0, NULL);
  247. }
  248. // We need to return a power of 2 that is GREATER than ul so we can
  249. // subtract 1 and still get at least ul variations
  250. while(ulNum <= ul && ulNum != 0L)
  251. {
  252. ulNum <<= 1;
  253. }
  254. return ulNum;
  255. }
  256. #endif // _PATHGEN_H_