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.

224 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. filecache.h
  5. Abstract:
  6. This module contains declarations for the open file handle cache.
  7. Author:
  8. Keith Moore (keithmo) 21-Aug-1998
  9. Revision History:
  10. --*/
  11. #ifndef _FILECACHE_H_
  12. #define _FILECACHE_H_
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. //
  17. // Data used to track a file cache entry.
  18. //
  19. typedef struct _UL_FILE_CACHE_ENTRY
  20. {
  21. //
  22. // Signature.
  23. //
  24. ULONG Signature;
  25. //
  26. // A reference count.
  27. //
  28. LONG ReferenceCount;
  29. //
  30. // A pre-referenced file object pointer for this file. This pointer
  31. // is valid in *any* thread/process context.
  32. //
  33. PFILE_OBJECT pFileObject;
  34. //
  35. // The *correct* device object referenced by the above file object.
  36. //
  37. PDEVICE_OBJECT pDeviceObject;
  38. //
  39. // Fast I/O routines.
  40. //
  41. PFAST_IO_MDL_READ pMdlRead;
  42. PFAST_IO_MDL_READ_COMPLETE pMdlReadComplete;
  43. //
  44. // The name of the file.
  45. //
  46. UNICODE_STRING FileName;
  47. //
  48. // The open file handle. Note that this handle is only valid
  49. // in the context of the system process.
  50. //
  51. HANDLE FileHandle;
  52. //
  53. // A work item for deferred operations.
  54. //
  55. UL_WORK_ITEM WorkItem;
  56. //
  57. // File-specific information gleaned from the file system.
  58. //
  59. FILE_STANDARD_INFORMATION FileInfo;
  60. } UL_FILE_CACHE_ENTRY, *PUL_FILE_CACHE_ENTRY;
  61. #define UL_FILE_CACHE_ENTRY_SIGNATURE ((ULONG)'ELIF')
  62. #define UL_FILE_CACHE_ENTRY_SIGNATURE_X MAKE_FREE_SIGNATURE(UL_FILE_CACHE_ENTRY_SIGNATURE)
  63. #define IS_VALID_FILE_CACHE_ENTRY( entry ) \
  64. ( (entry)->Signature == UL_FILE_CACHE_ENTRY_SIGNATURE )
  65. //
  66. // A file buffer contains the results of a read from a file cache entry.
  67. // The file cache read and read complete routines take pointers to this
  68. // structure. A read fills it in, and a read complete frees the data.
  69. //
  70. typedef struct _UL_FILE_BUFFER
  71. {
  72. //
  73. // The file that provided the data.
  74. //
  75. PUL_FILE_CACHE_ENTRY pFileCacheEntry;
  76. //
  77. // The data read from the file. Filled in by
  78. // the read routines.
  79. //
  80. PMDL pMdl;
  81. //
  82. // If we have to allocate our own buffer to hold file data
  83. // we'll save a pointer to the data buffer here.
  84. //
  85. PUCHAR pFileData;
  86. //
  87. // Information about the data buffers.
  88. // Filled in by the read routine's caller.
  89. //
  90. LARGE_INTEGER FileOffset;
  91. ULONG Length;
  92. //
  93. // Completion routine and context information set by the caller.
  94. //
  95. PIO_COMPLETION_ROUTINE pCompletionRoutine;
  96. PVOID pContext;
  97. } UL_FILE_BUFFER, *PUL_FILE_BUFFER;
  98. NTSTATUS
  99. InitializeFileCache(
  100. VOID
  101. );
  102. VOID
  103. TerminateFileCache(
  104. VOID
  105. );
  106. //
  107. // Routines to create, reference and release a cache entry.
  108. //
  109. NTSTATUS
  110. UlCreateFileEntry(
  111. IN PUNICODE_STRING pFileName OPTIONAL,
  112. IN HANDLE FileHandle OPTIONAL,
  113. IN KPROCESSOR_MODE AccessMode,
  114. OUT PUL_FILE_CACHE_ENTRY *pFileCacheEntry
  115. );
  116. VOID
  117. ReferenceCachedFile(
  118. IN PUL_FILE_CACHE_ENTRY pFileCacheEntry
  119. );
  120. VOID
  121. DereferenceCachedFile(
  122. IN PUL_FILE_CACHE_ENTRY pFileCacheEntry
  123. );
  124. //
  125. // Read and read complete routines.
  126. //
  127. // The fast versions complete immediately, but sometimes fail.
  128. // The normal versions use an IRP provided by the caller.
  129. //
  130. NTSTATUS
  131. UlReadFileEntry(
  132. IN OUT PUL_FILE_BUFFER pFileBuffer,
  133. IN PIRP pIrp
  134. );
  135. NTSTATUS
  136. UlReadFileEntryFast(
  137. IN OUT PUL_FILE_BUFFER pFileBuffer
  138. );
  139. NTSTATUS
  140. UlReadCompleteFileEntry(
  141. IN PUL_FILE_BUFFER pFileBuffer,
  142. IN PIRP pIrp
  143. );
  144. NTSTATUS
  145. UlReadCompleteFileEntryFast(
  146. IN PUL_FILE_BUFFER pFileBuffer
  147. );
  148. //
  149. // UL_FILE_BUFFER macros.
  150. //
  151. #define INITIALIZE_FILE_BUFFER(fbuf) \
  152. do { \
  153. (fbuf)->pFileCacheEntry = NULL; \
  154. (fbuf)->pMdl = NULL; \
  155. (fbuf)->pFileData = NULL; \
  156. (fbuf)->FileOffset.QuadPart = 0; \
  157. (fbuf)->Length = 0; \
  158. } while (0)
  159. #define IS_FILE_BUFFER_IN_USE(fbuf) ((fbuf)->pFileCacheEntry)
  160. #ifdef __cplusplus
  161. }; // extern "C"
  162. #endif
  163. #endif // _FILECACHE_H_