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.

287 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1990 - 2000 Microsoft Corporation
  3. Module Name:
  4. filepool.cxx
  5. Abstract:
  6. Contains the headers for handling Filepools for the Spooler. Contains the C++ object definitions
  7. and the C wrapper function headers.
  8. Author:
  9. Bryan Kilian (BryanKil) 5-Apr-1995
  10. Revision History:
  11. --*/
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. #define FP_LARGE_SIZE 200*1024 // 200K
  17. HRESULT
  18. CreateFilePool(
  19. HANDLE * FilePoolHandle,
  20. LPCTSTR BasePath,
  21. LPCTSTR PreNumStr,
  22. LPCTSTR SplExt,
  23. LPCTSTR ShdExt,
  24. DWORD PoolTimeout,
  25. DWORD MaxFiles
  26. );
  27. HRESULT
  28. GetFileItemHandle(
  29. HANDLE FilePoolHandle,
  30. HANDLE * FileItem,
  31. LPWSTR FromFilename
  32. );
  33. HRESULT
  34. GetNameFromHandle(
  35. HANDLE FileItem,
  36. PWSTR * FileNameStr,
  37. BOOL IsSpool
  38. );
  39. HANDLE
  40. GetCurrentWriter(
  41. HANDLE FileItem,
  42. BOOL IsSpool
  43. );
  44. HRESULT
  45. GetWriterFromHandle(
  46. HANDLE FileItem,
  47. HANDLE * File,
  48. BOOL IsSpool
  49. );
  50. HRESULT
  51. GetReaderFromHandle(
  52. HANDLE FileItem,
  53. HANDLE * File
  54. );
  55. HRESULT
  56. FinishedReading(
  57. HANDLE FileItem
  58. );
  59. HRESULT
  60. FinishedWriting(
  61. HANDLE FileItem,
  62. BOOL IsSpool
  63. );
  64. HRESULT
  65. ReleasePoolHandle(
  66. HANDLE * FileItem
  67. );
  68. HRESULT
  69. RemoveFromFilePool(
  70. HANDLE* FileItem,
  71. BOOL Delete
  72. );
  73. VOID
  74. CloseFiles(
  75. HANDLE FileItem,
  76. BOOL CloseShad
  77. );
  78. HRESULT
  79. ForceCloseJobPoolFiles(
  80. HANDLE FileItem
  81. );
  82. VOID
  83. CloseFilesCheck(
  84. struct FileListItem *pItem,
  85. enum ECloseHandle eCloseHandle
  86. );
  87. HRESULT
  88. ChangeFilePoolBasePath(
  89. HANDLE * FilePoolHandle,
  90. LPCTSTR BasePath
  91. );
  92. HRESULT
  93. DestroyFilePool(
  94. HANDLE* FilePool,
  95. BOOL DeleteFiles
  96. );
  97. BOOL
  98. TrimPool(
  99. HANDLE FilePoolHandle
  100. );
  101. HRESULT
  102. ConvertFileExt(
  103. PWSTR Filename,
  104. PCWSTR ExtFrom,
  105. PCWSTR ExtTo
  106. );
  107. typedef enum
  108. {
  109. kDontRecycle
  110. } EFileItemState;
  111. HRESULT
  112. SetFileItemState(
  113. IN HANDLE hFileItem,
  114. IN EFileItemState eState
  115. );
  116. // Returns bitmap indicating which files needed to be opened. Bitmap reset when
  117. // the pool handle is released.
  118. // Indicates which files in the pool item needed creating.
  119. #define FP_SPL_READER_CREATED 0x00000001
  120. #define FP_SPL_WRITER_CREATED 0x00000002
  121. #define FP_SHD_CREATED 0x00000004
  122. #define FP_ALL_FILES_CREATED (FP_SPL_READER_CREATED | \
  123. FP_SPL_WRITER_CREATED | \
  124. FP_SHD_CREATED)
  125. HRESULT
  126. GetFileCreationInfo(
  127. HANDLE FileItem,
  128. PDWORD BitMap
  129. );
  130. #ifdef __cplusplus
  131. }
  132. enum ECloseHandle
  133. {
  134. kCloseWriteHandle,
  135. kCloseReadHandle,
  136. kCloseShdHandle
  137. };
  138. struct Modes
  139. {
  140. DWORD Mode;
  141. DWORD Flags;
  142. DWORD ShareMode;
  143. DWORD Disp;
  144. };
  145. struct FileListItem
  146. {
  147. struct FileListItem * FLNext;
  148. struct FileListItem * FLPrev;
  149. class FilePool * FP;
  150. VOID EnterCritSec();
  151. VOID LeaveCritSec();
  152. CRITICAL_SECTION CritSec;
  153. DWORD Status;
  154. DWORD TimeStamp;
  155. LPWSTR SplFilename;
  156. LPWSTR ShdFilename;
  157. HANDLE SplWriteHandle;
  158. HANDLE SplReadHandle;
  159. HANDLE ShdWriteHandle;
  160. //
  161. // Indicates whether or not the spool and/or shadow file was created for the
  162. // client of this pool item.
  163. //
  164. DWORD CreateInfo;
  165. };
  166. #define FP_STATUS_SPL_WRITING 0x00000001
  167. #define FP_STATUS_SPL_READING 0x00000002
  168. #define FP_STATUS_SHD_WRITING 0x00000004
  169. #define FP_STATUS_SPL_READ_CLOSED 0x00000008
  170. #define FP_STATUS_SPL_WRITE_CLOSED 0x00000010
  171. #define FP_STATUS_SHD_CLOSED 0x00000020
  172. #define FP_STATUS_ITEM_DONT_RECYCLE 0x00000040
  173. class FilePool
  174. {
  175. CRITICAL_SECTION FilePoolCritSec;
  176. struct FileListItem * FreeFiles;
  177. struct FileListItem * FileInUse;
  178. struct FileListItem * EndUsedFiles;
  179. struct FileListItem * EndFreeFiles;
  180. struct Modes SplModes;
  181. struct Modes ShdModes;
  182. LPWSTR FilePreNumStr;
  183. LPWSTR SplFileExt;
  184. LPWSTR ShdFileExt;
  185. DWORD CurrentNum;
  186. DWORD PoolTimeout;
  187. LONG MaxFiles;
  188. LONG FreeSize;
  189. LONG UsedSize;
  190. HRESULT InitFilePoolVars();
  191. LPWSTR GetNextFileName();
  192. HRESULT GetNextFileNameNoAlloc(PWSTR Filename, SIZE_T cchFilename);
  193. HRESULT CreatePoolFile(struct FileListItem ** Item, PWSTR Filename);
  194. public:
  195. BOOL DeleteEmptyFilesOnClose;
  196. LPWSTR FileBase;
  197. FilePool(
  198. DWORD PTimeout,
  199. DWORD MaxFreeFiles
  200. );
  201. ~FilePool();
  202. HRESULT AllocInit(
  203. LPCTSTR BasePath,
  204. LPCTSTR PreNumStr,
  205. LPCTSTR SplExt,
  206. LPCTSTR ShdExt
  207. );
  208. HRESULT GetWriteFileStruct(struct FileListItem ** File, PWSTR Filename);
  209. HRESULT ReleasePoolHandle(struct FileListItem * File);
  210. HRESULT CreateSplReader(struct FileListItem * Item);
  211. HRESULT CreateSplWriter(struct FileListItem * Item);
  212. HRESULT CreateShdWriter(struct FileListItem * Item);
  213. HRESULT RemoveFromPool(struct FileListItem * File, BOOL Delete);
  214. BOOL TrimPool(VOID);
  215. VOID EnterCritSec();
  216. VOID LeaveCritSec();
  217. void* operator new(size_t n);
  218. void operator delete(void* p, size_t n);
  219. };
  220. HRESULT
  221. FPSetFileItemState(
  222. IN FileListItem *pItem,
  223. IN EFileItemState eFileItemState
  224. );
  225. #endif