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.

259 lines
4.6 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. //SetFileModes(
  28. // BOOL Spool,
  29. // DWORD Mode,
  30. // DWORD ShareMode,
  31. // DWORD Disp,
  32. // DWORD Flags
  33. // );
  34. HRESULT
  35. GetFileItemHandle(
  36. HANDLE FilePoolHandle,
  37. HANDLE * FileItem,
  38. LPWSTR FromFilename
  39. );
  40. HRESULT
  41. GetNameFromHandle(
  42. HANDLE FileItem,
  43. PWSTR * FileNameStr,
  44. BOOL IsSpool
  45. );
  46. HANDLE
  47. GetCurrentWriter(
  48. HANDLE FileItem,
  49. BOOL IsSpool
  50. );
  51. HRESULT
  52. GetWriterFromHandle(
  53. HANDLE FileItem,
  54. HANDLE * File,
  55. BOOL IsSpool
  56. );
  57. HRESULT
  58. GetReaderFromHandle(
  59. HANDLE FileItem,
  60. HANDLE * File
  61. );
  62. HRESULT
  63. FinishedReading(
  64. HANDLE FileItem
  65. );
  66. HRESULT
  67. FinishedWriting(
  68. HANDLE FileItem,
  69. BOOL IsSpool
  70. );
  71. HRESULT
  72. ReleasePoolHandle(
  73. HANDLE * FileItem
  74. );
  75. HRESULT
  76. RemoveFromFilePool(
  77. HANDLE* FileItem,
  78. BOOL Delete
  79. );
  80. VOID
  81. CloseFiles(
  82. HANDLE FileItem,
  83. BOOL CloseShad
  84. );
  85. HRESULT
  86. ChangeFilePoolBasePath(
  87. HANDLE * FilePoolHandle,
  88. LPCTSTR BasePath
  89. );
  90. HRESULT
  91. DestroyFilePool(
  92. HANDLE* FilePool,
  93. BOOL DeleteFiles
  94. );
  95. BOOL
  96. TrimPool(
  97. HANDLE FilePoolHandle
  98. );
  99. HRESULT
  100. ConvertFileExt(
  101. PWSTR Filename,
  102. PCWSTR ExtFrom,
  103. PCWSTR ExtTo
  104. );
  105. // Returns bitmap indicating which files needed to be opened. Bitmap reset when
  106. // the pool handle is released.
  107. // Indicates which files in the pool item needed creating.
  108. #define FP_SPL_READER_CREATED 0x00000001
  109. #define FP_SPL_WRITER_CREATED 0x00000002
  110. #define FP_SHD_CREATED 0x00000004
  111. #define FP_ALL_FILES_CREATED (FP_SPL_READER_CREATED | \
  112. FP_SPL_WRITER_CREATED | \
  113. FP_SHD_CREATED)
  114. HRESULT
  115. GetFileCreationInfo(
  116. HANDLE FileItem,
  117. PDWORD BitMap
  118. );
  119. #ifdef __cplusplus
  120. }
  121. struct Modes
  122. {
  123. DWORD Mode;
  124. DWORD Flags;
  125. DWORD ShareMode;
  126. DWORD Disp;
  127. };
  128. struct FileListItem
  129. {
  130. struct FileListItem * FLNext;
  131. struct FileListItem * FLPrev;
  132. class FilePool * FP;
  133. VOID EnterCritSec();
  134. VOID LeaveCritSec();
  135. CRITICAL_SECTION CritSec;
  136. DWORD Status;
  137. DWORD TimeStamp;
  138. LPWSTR SplFilename;
  139. LPWSTR ShdFilename;
  140. HANDLE SplWriteHandle;
  141. HANDLE SplReadHandle;
  142. HANDLE ShdWriteHandle;
  143. //
  144. // Indicates whether or not the spool and/or shadow file was created for the
  145. // client of this pool item.
  146. //
  147. DWORD CreateInfo;
  148. };
  149. #define FP_STATUS_SPL_WRITING 0x00000001
  150. #define FP_STATUS_SPL_READING 0x00000002
  151. #define FP_STATUS_SHD_WRITING 0x00000004
  152. class FilePool
  153. {
  154. CRITICAL_SECTION FilePoolCritSec;
  155. struct FileListItem * FreeFiles;
  156. struct FileListItem * FileInUse;
  157. struct FileListItem * EndUsedFiles;
  158. struct FileListItem * EndFreeFiles;
  159. struct Modes SplModes;
  160. struct Modes ShdModes;
  161. LPWSTR FilePreNumStr;
  162. LPWSTR SplFileExt;
  163. LPWSTR ShdFileExt;
  164. DWORD CurrentNum;
  165. DWORD PoolTimeout;
  166. LONG MaxFiles;
  167. LONG FreeSize;
  168. LONG UsedSize;
  169. HRESULT InitFilePoolVars();
  170. LPWSTR GetNextFileName();
  171. VOID GetNextFileNameNoAlloc(PWSTR Filename);
  172. HRESULT CreatePoolFile(struct FileListItem ** Item, PWSTR Filename);
  173. public:
  174. BOOL DeleteEmptyFilesOnClose;
  175. LPWSTR FileBase;
  176. FilePool(
  177. DWORD PTimeout,
  178. DWORD MaxFreeFiles
  179. );
  180. ~FilePool();
  181. HRESULT AllocInit(
  182. LPCTSTR BasePath,
  183. LPCTSTR PreNumStr,
  184. LPCTSTR SplExt,
  185. LPCTSTR ShdExt
  186. );
  187. HRESULT GetWriteFileStruct(struct FileListItem ** File, PWSTR Filename);
  188. HRESULT ReleasePoolHandle(struct FileListItem * File);
  189. HRESULT CreateSplReader(struct FileListItem * Item);
  190. HRESULT CreateSplWriter(struct FileListItem * Item);
  191. HRESULT CreateShdWriter(struct FileListItem * Item);
  192. HRESULT RemoveFromPool(struct FileListItem * File, BOOL Delete);
  193. BOOL TrimPool(VOID);
  194. VOID EnterCritSec();
  195. VOID LeaveCritSec();
  196. void* operator new(size_t n);
  197. void operator delete(void* p, size_t n);
  198. };
  199. #endif