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.

408 lines
13 KiB

  1. /***************************************************************************
  2. **
  3. ** File: SetupKit.h
  4. ** Purpose: Toolkit types, defines, and prototypes.
  5. ** Notes:
  6. **
  7. ****************************************************************************/
  8. #ifndef SETUPKIT_H
  9. #define SETUPKIT_H
  10. #ifdef __cplusplus
  11. extern "C" { /* Assume C declarations for C++ */
  12. #endif
  13. /*
  14. ** Purpose:
  15. ** Calculates the number of bytes that a string occupies (not including
  16. ** the terminating zero character).
  17. ** Arguments:
  18. ** sz: string whose length is to be calculated.
  19. ** Returns:
  20. ** 0 if sz was NULL.
  21. ** The number of bytes from the beginning of the string to its
  22. ** terminating zero character.
  23. */
  24. #define CbStrLen(sz) ((CB)lstrlen(sz))
  25. /*
  26. ** Purpose:
  27. ** Checks if the string is empty
  28. ** Arguments:
  29. ** sz:
  30. ** Returns:
  31. ** 0 if sz was NULL.
  32. ** 1 otherwise
  33. */
  34. #define FEmptySz(sz) ((BOOL)((sz) == szNull || *(sz) == chEos))
  35. #define FValidSz(sz) (!FEmptySz(sz))
  36. /*
  37. * CHaracter Physical representation datatype
  38. */
  39. typedef BYTE CHP; /* CHaracter Physical */
  40. typedef CHP * PCHP; /* Ptr to CHaracter Physical */
  41. typedef CB CCHP; /* Count of CHaracter Physical */
  42. typedef CCHP * PCCHP; /* Ptr to Count of CHaracter Physical */
  43. #define pchpNull ((PCHP)NULL)
  44. #define pcchpNull ((PCCHP)NULL)
  45. #define CbFromCchp(cchp) ((CB)(cchp))
  46. /*
  47. * CHaracter Logical representation datatype
  48. */
  49. typedef CHP CHL; /* CHaracter Logical */
  50. typedef CHL * PCHL; /* Ptr to CHaracter Logical */
  51. typedef PCHL * PPCHL; /* Ptr to Ptr to CHaracter Logical */
  52. typedef CB CCHL; /* Count of CHaracter Logical */
  53. #define pchlNull ((PCHL)NULL)
  54. #define ppchlNull ((PPCHL)NULL)
  55. #define cchpFullPathMax ((CCHP)(_MAX_PATH))
  56. #define cchGrpNameMax 30 /* right for win31, WfW, WinNT */
  57. #ifdef OLD
  58. #define cchGrpNameMax ((CB)(LOWORD(GetVersion()) == 0x0003 ? 24 : 29))
  59. #endif /* OLD */
  60. /*
  61. * Maximum size block that can be allocated (bytes).
  62. */
  63. #define cbAllocMax ((CB)65520)
  64. /*
  65. * Path Verification Routines
  66. */
  67. typedef UINT FPV; /* Flags for Path Validation */
  68. #define fpvSub 0x0000 /* Must be subpath, cannot have Drive or UNC */
  69. #define fpvUnc 0x0001 /* Validate UNC path, \\Node\share */
  70. #define fpvDrive 0x0002 /* Validate Drive at start of path */
  71. #define fpvFile 0x0004 /* Validate filename only, no subdirectories */
  72. #define fpvDir 0x0010 /* Allow trailing directory separator */
  73. #define fpvFat 0x0020 /* Restrict to only 8.3 FAT name, no LFNs */
  74. #define fpvFull (fpvDrive | fpvUnc) /* Full path, with Drive or UNC */
  75. #define fpvModule (fpvDrive | fpvUnc | fpvFile) /* Valid executable name */
  76. /*
  77. ** Purpose:
  78. ** Checks the validity of a filepath or filename.
  79. ** Allowable filepath components are controlled by bit flags.
  80. ** Default behavior is to allow directories with filename.
  81. ** Leading backslash is not permitted in directory name.
  82. ** Arguments:
  83. ** szcPath: non-NULL string to validate
  84. ** fpvFlags: pathname options flags
  85. ** Returns:
  86. ** fTrue if szcPath is valid for requested type
  87. ** fFalse if invalid path
  88. ***************************************************************************/
  89. BOOL PUBLIC FValidFilePath ( SZC szcPath, FPV fpvFlags );
  90. #define FValidDir(szcDir) FValidFilePath(szcDir, fpvFull | fpvDir)
  91. #define FValidPath(szcPath) FValidFilePath(szcPath, fpvFull)
  92. #define FValidSubDir(szc) FValidFilePath(szc, fpvDir)
  93. #define FValidSubPath(szc) FValidFilePath(szc, fpvSub)
  94. #define FValidFATSubPath(szc) FValidFilePath(szc, fpvFat)
  95. #define FValidFileName(szc) FValidFilePath(szc, fpvFile)
  96. #define FValidDllFileName(szc) FValidFilePath(szc, fpvModule)
  97. #define FValidDstDir(szcDir) FValidFilePath(szcDir, fpvDrive | fpvDir)
  98. #define FValidInfSect(cszcSect) \
  99. (FValidSz(cszcSect) && !strchr(cszcSect, ']'))
  100. #define FValidIniFile(szcFile) \
  101. (FValidPath(szcFile) \
  102. || CrcStringCompareI(szcFile, "WIN.INI") == crcEqual)
  103. /* String manipulation routines */
  104. /*
  105. ** Purpose:
  106. ** Advances a string pointer to the beginning of the next valid
  107. ** character. This may include skipping a double-byte character.
  108. ** Arguments:
  109. ** sz: the string pointer to advance. It can be NULL or empty, or else
  110. ** it must point at the beginning of a valid character.
  111. ** Returns:
  112. ** NULL if sz was NULL.
  113. ** sz unchanged if it was an empty string (*sz == '\0').
  114. ** sz advanced past the current character and to the beginning of the
  115. ** next valid character.
  116. */
  117. #define SzNextChar(sz) AnsiNext(sz)
  118. /*
  119. ** Purpose:
  120. ** Retreats a string pointer to the beginning of the previous valid
  121. ** character. This may include skipping a double-byte character.
  122. ** Arguments:
  123. ** szStart: string pointer to the beginning of a valid character that
  124. ** equals or preceeds the character szCur.
  125. ** szCur: string pointer to retreat. It can be NULL or empty, or
  126. ** can point to any byte in a valid character.
  127. ** Returns:
  128. ** NULL if szCur was NULL.
  129. ** sz unchanged if szStart was NULL or if szCur equaled szStart.
  130. ** sz retreated past the current character and to the beginning of the
  131. ** previous valid character.
  132. */
  133. #define SzPrevChar(szStart, szCur) AnsiPrev(szStart, szCur)
  134. /*
  135. ** Purpose:
  136. ** Copies a string from one buffer to another.
  137. ** Arguments:
  138. ** szDst: string pointer to destination buffer. This can be NULL or
  139. ** else it must contain enough storage to copy szSrc with its
  140. ** terminating zero character.
  141. ** szSrc: string pointer to source buffer. This can be NULL or else
  142. ** must point to a zero terminated string (can be empty).
  143. ** Returns:
  144. ** NULL if either szDst or szSrc is NULL.
  145. ** szDst signifying the operation succeeded.
  146. */
  147. #define SzStrCopy(szDst, szSrc) lstrcpy(szDst, szSrc)
  148. /*
  149. ** Purpose:
  150. ** Appends a string from one buffer to another.
  151. ** Arguments:
  152. ** szDst: string pointer to destination buffer. This can be NULL or
  153. ** else it must contain a zero terminated string (can be empty)
  154. ** and enough storage to append szSrc with its terminating zero
  155. ** character.
  156. ** szSrc: string pointer to source buffer. This can be NULL or else
  157. ** must point to a zero terminated string (can be empty).
  158. ** Returns:
  159. ** NULL if either szDst or szSrc is NULL.
  160. ** szDst signifying the operation succeeded.
  161. */
  162. #define SzStrCat(szDst, szSrc) lstrcat(szDst, szSrc)
  163. /*
  164. ** Purpose:
  165. ** Converts a zero-terminated string to upper case.
  166. ** Arguments:
  167. ** sz: the string to convert to upper case. sz must be non-NULL though
  168. ** it can be empty.
  169. ** Returns:
  170. ** A pointer to the converted string.
  171. */
  172. /* REVIEW: define SzStrUpper(sz) (sz) */
  173. /*
  174. ** Purpose:
  175. ** Converts a zero-terminated string to lower case.
  176. ** Arguments:
  177. ** sz: the string to convert to lower case. sz must be non-NULL though
  178. ** it can be empty.
  179. ** Returns:
  180. ** A pointer to the converted string.
  181. */
  182. #define SzStrLower(sz) AnsiLower(sz)
  183. /* Memory Handling routines */
  184. extern PB WINAPI PbAlloc ( CB cb );
  185. extern BOOL WINAPI FFree ( PB pb, CB cb );
  186. extern PB WINAPI PbRealloc ( PB pb, CB cbNew, CB cbOld );
  187. #define FHandleOOM() HandleOOM()
  188. /*
  189. ** Purpose:
  190. ** Frees the memory used by an sz. This assumes the terminating
  191. ** zero occupies the final byte of the allocated buffer.
  192. ** Arguments:
  193. ** sz: the buffer to free. this must be non-NULL though it can point
  194. ** at an empty string.
  195. ** Returns:
  196. ** fTrue if the Free() operation succeeds.
  197. ** fFalse if the Free() operation fails.
  198. */
  199. #define FFreeSz(sz) FFree((PB)(sz), CbStrLen(sz)+1)
  200. /*
  201. ** Purpose:
  202. ** Shrinks a buffer to exactly fit a string.
  203. ** Arguments:
  204. ** sz: the string for which the buffer should shrink to. sz must be
  205. ** non-NULL though it can be empty.
  206. ** cb: the size in bytes for the buffer that was originally allocated.
  207. ** cb must be greater than or equal to CbStrLen(sz) + 1.
  208. ** Returns:
  209. ** A pointer to the original string if the Realloc() operation succeeds.
  210. ** NULL if the Realloc() operation fails.
  211. */
  212. #define SzReallocSz(sz, cb) (SZ)(PbRealloc((PB)(sz), (CbStrLen(sz)+1), cb))
  213. /*
  214. * File Handle structure
  215. * Fields:
  216. * hFile: Win32 file handle.
  217. * iDosfh: Only used to avoid changing old source code, same as hFile
  218. * szPath: Full path used when the file was opened.
  219. */
  220. typedef union _fh /* File Handle structure */
  221. {
  222. INT iDosfh; /* temp until code converted */
  223. HANDLE hFile;
  224. } FH;
  225. /*
  226. * File Handle datatype
  227. */
  228. typedef FH * PFH; /* Ptr to File Handle structure */
  229. typedef PFH * PPFH; /* Ptr to Ptr to File Handle structure */
  230. #define pfhNull ((PFH)NULL)
  231. #define ppfhNull ((PPFH)NULL)
  232. /*
  233. * Open File Mode datatype
  234. */
  235. typedef UINT OFM; /* Open File Mode */
  236. #define ofmExist ((OFM)OF_EXIST)
  237. #define ofmRead ((OFM)OF_READ | OF_SHARE_DENY_WRITE)
  238. #define ofmReadCompat ((OFM)OF_READ | OF_SHARE_COMPAT)
  239. #define ofmWrite ((OFM)OF_WRITE | OF_SHARE_EXCLUSIVE)
  240. #define ofmReadWrite ((OFM)OF_READWRITE | OF_SHARE_EXCLUSIVE)
  241. #define ofmCreate ((OFM)OF_CREATE | OF_SHARE_EXCLUSIVE)
  242. /*
  243. * Seek File Mode datatype
  244. */
  245. typedef UINT SFM; /* Seek File Mode */
  246. #define sfmSet ((SFM)FILE_BEGIN)
  247. #define sfmCur ((SFM)FILE_CURRENT)
  248. #define sfmEnd ((SFM)FILE_END)
  249. /*
  250. * Long File Address datatype
  251. */
  252. typedef unsigned long LFA; /* Long File Address */
  253. #define lfaSeekError ((LFA)HFILE_ERROR)
  254. /*
  255. * Expanded Error Return Code
  256. */
  257. typedef unsigned int EERC; /* Expanded Error Return Code */
  258. #define eercOkay ((EERC)0)
  259. #define eercAbort ((EERC)1)
  260. #define eercRetry ((EERC)2)
  261. #define eercIgnore ((EERC)3)
  262. /* File handling routines */
  263. extern EERC WINAPI EercOpenFile ( PPFH ppfh, CSZC cszcFile, OFM ofm,
  264. BOOL fVital );
  265. extern BOOL WINAPI FFileExist ( CSZC cszcFile, OFM ofm );
  266. extern BOOL WINAPI FCloseFile ( PFH pfh );
  267. extern CB WINAPI CbReadFile ( PFH pfh, PB pbBuf, CB cbMax );
  268. extern CB WINAPI CbWriteFile ( PFH pfh, PB pbBuf, CB cbMax );
  269. extern LFA WINAPI LfaSeekFile ( PFH pfh, LONG l, SFM sfm );
  270. extern BOOL WINAPI FChmodFile ( CSZC cszcFileName, INT wFlags, BOOL fVital );
  271. extern SZC WINAPI DriveNumToRootPath( INT iDrive );
  272. typedef unsigned int IDDT; /* Insert Disk Dialog Type */
  273. #define iddtStandard ((IDDT)1)
  274. #define iddtHddi ((IDDT)2)
  275. #define iddtHddiMaint ((IDDT)3)
  276. /* Media source file handling routines */
  277. extern EERC WINAPI EercOpenSrcFile ( PPFH ppfh, UINT did, SZ szSrcDir,
  278. SZ szFile, BOOL fWrite );
  279. extern EERC WINAPI EercOpenSrcFileEx ( PPFH ppfh, UINT did, SZ szSrcDir,
  280. SZ szFile, BOOL fWrite, BOOL fVital, IDDT iddt );
  281. extern EERC WINAPI EercReadSrcFile ( PFH pfh, PB pbBuf, CB cbMax );
  282. extern EERC WINAPI EercWriteSrcFile ( PFH pfh, PB pbBuf, CB cbMax );
  283. extern BOOL WINAPI FCloseSrcFile( PFH pfh, BOOL fRdOnly );
  284. extern EERC WINAPI EercFindHddiFloppy ( SZ szSrcDir, DWORD dwDrives,
  285. PCH pchDrive, BOOL fVital, IDDT iddt );
  286. /*
  287. * SetErrorMode type
  288. */
  289. typedef unsigned int SEM; /* SetErrorMode type */
  290. /*
  291. * Comparison Return Code datatype
  292. */
  293. typedef INT CRC; /* Comparison Return Code */
  294. #define crcError ((CRC)(-2))
  295. #define crcEqual ((CRC) 0 )
  296. #define crcFirstHigher ((CRC) 1 )
  297. #define crcSecondHigher ((CRC)(-1))
  298. extern SZ PUBLIC SzDupl ( CSZC cszc );
  299. extern CRC WINAPI CrcStringCompare ( CSZC cszc1, CSZC cszc2 );
  300. extern CRC WINAPI CrcStringCompareI ( CSZC cszc1, CSZC cszc2 );
  301. extern SZ WINAPI SzLastChar ( CSZC cszc );
  302. extern CB WINAPI CbStrCopyToBuffer ( PB pbBuf, CB cbMax, CSZC cszcSrc );
  303. /*
  304. * BindImage API, exported from MSSETUP.DLL, and/or IMAGEHLP.DLL
  305. */
  306. #define IMAGEHELP_DLL "imagehlp.dll"
  307. #define BINDIMAGE_PROC "BindImage"
  308. typedef BOOL (WINAPI *PFNBindImage)( SZ szImage, SZ szDllPath, SZ szSymPath);
  309. extern BOOL WINAPI BindImage( SZ szImage, SZ szDllPath, SZ szSymPath);
  310. /*
  311. * API to set Admin mode in toolkit DLL
  312. */
  313. VOID WINAPI SetAdminMode ( VOID ); /* called only by ACMSETUP.EXE */
  314. BOOL WINAPI IsAdminMode ( VOID );
  315. /* Like FStampResource, but only reads the data into the buffer.
  316. */
  317. BOOL WINAPI FReadResource ( SZ szFilePath, UINT uiResType, UINT uiResId,
  318. SZ szData, CB cbData, BOOL fNotCopied );
  319. #ifdef __cplusplus
  320. } /* End of extern "C" { */
  321. #endif
  322. #endif /* SETUPKIT_H */