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.

206 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1998-2002 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. //
  14. // Data used to track a file cache entry.
  15. //
  16. typedef struct _UL_FILE_CACHE_ENTRY
  17. {
  18. //
  19. // Signature.
  20. //
  21. ULONG Signature;
  22. //
  23. // Sector-size information gleaned from the file system.
  24. //
  25. ULONG BytesPerSector;
  26. //
  27. // File-length information gleaned from the file system.
  28. //
  29. LARGE_INTEGER EndOfFile;
  30. //
  31. // A pre-referenced file object pointer for this file. This pointer
  32. // is valid in *any* thread/process context.
  33. //
  34. PFILE_OBJECT pFileObject;
  35. //
  36. // The *correct* device object referenced by the above file object.
  37. //
  38. PDEVICE_OBJECT pDeviceObject;
  39. //
  40. // Fast I/O routines.
  41. //
  42. PFAST_IO_MDL_READ pMdlRead;
  43. PFAST_IO_MDL_READ_COMPLETE pMdlReadComplete;
  44. } UL_FILE_CACHE_ENTRY, *PUL_FILE_CACHE_ENTRY;
  45. #define UL_FILE_CACHE_ENTRY_SIGNATURE MAKE_SIGNATURE('FILE')
  46. #define UL_FILE_CACHE_ENTRY_SIGNATURE_X MAKE_FREE_SIGNATURE(UL_FILE_CACHE_ENTRY_SIGNATURE)
  47. #define IS_VALID_FILE_CACHE_ENTRY( entry ) \
  48. HAS_VALID_SIGNATURE(entry, UL_FILE_CACHE_ENTRY_SIGNATURE)
  49. //
  50. // A file buffer contains the results of a read from a file cache entry.
  51. // The file cache read and read complete routines take pointers to this
  52. // structure. A read fills it in, and a read complete frees the data.
  53. //
  54. typedef struct _UL_FILE_BUFFER
  55. {
  56. //
  57. // The file that provided the data.
  58. //
  59. PUL_FILE_CACHE_ENTRY pFileCacheEntry;
  60. //
  61. // The data read from the file. Filled in by
  62. // the read routines.
  63. //
  64. PMDL pMdl;
  65. //
  66. // If we have to allocate our own buffer to hold file data
  67. // we'll save a pointer to the data buffer here.
  68. //
  69. PUCHAR pFileData;
  70. //
  71. // Information about the data buffers.
  72. // Filled in by the read routine's caller.
  73. //
  74. ULARGE_INTEGER FileOffset;
  75. ULONG RelativeOffset;
  76. ULONG Length;
  77. //
  78. // Completion routine and context information set by the caller.
  79. //
  80. PIO_COMPLETION_ROUTINE pCompletionRoutine;
  81. PVOID pContext;
  82. } UL_FILE_BUFFER, *PUL_FILE_BUFFER;
  83. NTSTATUS
  84. InitializeFileCache(
  85. VOID
  86. );
  87. VOID
  88. TerminateFileCache(
  89. VOID
  90. );
  91. //
  92. // Routines to create, reference and release a cache entry.
  93. //
  94. NTSTATUS
  95. UlCreateFileEntry(
  96. IN HANDLE FileHandle,
  97. IN OUT PUL_FILE_CACHE_ENTRY pFileCacheEntry
  98. );
  99. VOID
  100. UlDestroyFileCacheEntry(
  101. IN PUL_FILE_CACHE_ENTRY pFileCacheEntry
  102. );
  103. //
  104. // Read and read complete routines.
  105. //
  106. // The fast versions complete immediately, but sometimes fail.
  107. // The normal versions use an IRP provided by the caller.
  108. //
  109. NTSTATUS
  110. UlReadFileEntry(
  111. IN OUT PUL_FILE_BUFFER pFileBuffer,
  112. IN PIRP pIrp
  113. );
  114. NTSTATUS
  115. UlReadFileEntryFast(
  116. IN OUT PUL_FILE_BUFFER pFileBuffer
  117. );
  118. NTSTATUS
  119. UlReadCompleteFileEntry(
  120. IN PUL_FILE_BUFFER pFileBuffer,
  121. IN PIRP pIrp
  122. );
  123. NTSTATUS
  124. UlReadCompleteFileEntryFast(
  125. IN PUL_FILE_BUFFER pFileBuffer
  126. );
  127. //
  128. // UL_FILE_BUFFER macros.
  129. //
  130. #define IS_FILE_BUFFER_IN_USE(fbuf) ((fbuf)->pFileCacheEntry)
  131. //
  132. // Dummy MdlRead and MdlReadComplete routines.
  133. //
  134. BOOLEAN
  135. UlFailMdlReadDev(
  136. IN PFILE_OBJECT FileObject,
  137. IN PLARGE_INTEGER FileOffset,
  138. IN ULONG Length,
  139. IN ULONG LockKey,
  140. OUT PMDL *MdlChain,
  141. OUT PIO_STATUS_BLOCK IoStatus,
  142. IN PDEVICE_OBJECT DeviceObject
  143. );
  144. BOOLEAN
  145. UlFailMdlReadCompleteDev(
  146. IN PFILE_OBJECT FileObject,
  147. IN PMDL MdlChain,
  148. IN PDEVICE_OBJECT DeviceObject
  149. );
  150. #endif // _FILECACHE_H_