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.

2063 lines
46 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. FsRtl.h
  5. Abstract:
  6. This module defines all of the general File System Rtl routines
  7. Author:
  8. Gary Kimura [GaryKi] 30-Jul-1990
  9. Revision History:
  10. --*/
  11. #ifndef _FSRTL_
  12. #define _FSRTL_
  13. // begin_ntifs
  14. //
  15. // The following are globally used definitions for an LBN and a VBN
  16. //
  17. typedef ULONG LBN;
  18. typedef LBN *PLBN;
  19. typedef ULONG VBN;
  20. typedef VBN *PVBN;
  21. // end_ntifs
  22. //
  23. // The following routine is called during phase 1 initialization to allow
  24. // us to create the pool of file system threads and the associated
  25. // synchronization resources.
  26. //
  27. NTKERNELAPI
  28. BOOLEAN
  29. FsRtlInitSystem (
  30. );
  31. // begin_ntifs
  32. //
  33. // Every file system that uses the cache manager must have FsContext
  34. // of the file object point to a common fcb header structure.
  35. // end_ntifs
  36. // Either the normal or advanced FsRtl Header.
  37. // begin_ntifs
  38. //
  39. typedef enum _FAST_IO_POSSIBLE {
  40. FastIoIsNotPossible = 0,
  41. FastIoIsPossible,
  42. FastIoIsQuestionable
  43. } FAST_IO_POSSIBLE;
  44. // end_ntifs
  45. // Changes to this structure will affect FSRTL_ADVANCED_FCB_HEADER.
  46. // begin_ntifs
  47. typedef struct _FSRTL_COMMON_FCB_HEADER {
  48. CSHORT NodeTypeCode;
  49. CSHORT NodeByteSize;
  50. //
  51. // General flags available to FsRtl.
  52. //
  53. UCHAR Flags;
  54. //
  55. // Indicates if fast I/O is possible or if we should be calling
  56. // the check for fast I/O routine which is found via the driver
  57. // object.
  58. //
  59. UCHAR IsFastIoPossible; // really type FAST_IO_POSSIBLE
  60. //
  61. // Second Flags Field
  62. //
  63. UCHAR Flags2;
  64. //
  65. // The following reserved field should always be 0
  66. //
  67. UCHAR Reserved;
  68. PERESOURCE Resource;
  69. PERESOURCE PagingIoResource;
  70. LARGE_INTEGER AllocationSize;
  71. LARGE_INTEGER FileSize;
  72. LARGE_INTEGER ValidDataLength;
  73. } FSRTL_COMMON_FCB_HEADER;
  74. typedef FSRTL_COMMON_FCB_HEADER *PFSRTL_COMMON_FCB_HEADER;
  75. //
  76. // This Fcb header is used for files which support caching
  77. // of compressed data, and related new support.
  78. //
  79. // We start out by prefixing this structure with the normal
  80. // FsRtl header from above, which we have to do two different
  81. // ways for c++ or c.
  82. //
  83. #ifdef __cplusplus
  84. typedef struct _FSRTL_ADVANCED_FCB_HEADER:FSRTL_COMMON_FCB_HEADER {
  85. #else // __cplusplus
  86. typedef struct _FSRTL_ADVANCED_FCB_HEADER {
  87. //
  88. // Put in the standard FsRtl header fields
  89. //
  90. FSRTL_COMMON_FCB_HEADER ;
  91. #endif // __cplusplus
  92. //
  93. // The following two fields are supported only if
  94. // Flags2 contains FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS
  95. //
  96. //
  97. // This is a pointer to a Fast Mutex which may be used to
  98. // properly synchronize access to the FsRtl header. The
  99. // Fast Mutex must be nonpaged.
  100. //
  101. PFAST_MUTEX FastMutex;
  102. //
  103. // This is a pointer to a list of context structures belonging to
  104. // filesystem filter drivers that are linked above the filesystem.
  105. // Each structure is headed by FSRTL_FILTER_CONTEXT.
  106. //
  107. LIST_ENTRY FilterContexts;
  108. } FSRTL_ADVANCED_FCB_HEADER;
  109. typedef FSRTL_ADVANCED_FCB_HEADER *PFSRTL_ADVANCED_FCB_HEADER;
  110. //
  111. // Define FsRtl common header flags
  112. //
  113. #define FSRTL_FLAG_FILE_MODIFIED (0x01)
  114. #define FSRTL_FLAG_FILE_LENGTH_CHANGED (0x02)
  115. #define FSRTL_FLAG_LIMIT_MODIFIED_PAGES (0x04)
  116. //
  117. // Following flags determine how the modified page writer should
  118. // acquire the file. These flags can't change while either resource
  119. // is acquired. If neither of these flags is set then the
  120. // modified/mapped page writer will attempt to acquire the paging io
  121. // resource shared.
  122. //
  123. #define FSRTL_FLAG_ACQUIRE_MAIN_RSRC_EX (0x08)
  124. #define FSRTL_FLAG_ACQUIRE_MAIN_RSRC_SH (0x10)
  125. //
  126. // This flag will be set by the Cache Manager if a view is mapped
  127. // to a file.
  128. //
  129. #define FSRTL_FLAG_USER_MAPPED_FILE (0x20)
  130. // This flag indicates that the file system is using the
  131. // FSRTL_ADVANCED_FCB_HEADER structure instead of the FSRTL_COMMON_FCB_HEADER
  132. // structure.
  133. //
  134. #define FSRTL_FLAG_ADVANCED_HEADER (0x40)
  135. // This flag determines whether there currently is an Eof advance
  136. // in progress. All such advances must be serialized.
  137. //
  138. #define FSRTL_FLAG_EOF_ADVANCE_ACTIVE (0x80)
  139. //
  140. // Flag values for Flags2
  141. //
  142. // All unused bits are reserved and should NOT be modified.
  143. //
  144. //
  145. // If this flag is set, the Cache Manager will allow modified writing
  146. // in spite of the value of FsContext2.
  147. //
  148. #define FSRTL_FLAG2_DO_MODIFIED_WRITE (0x01)
  149. //
  150. // If this flag is set, the additional fields FilterContexts and FastMutex
  151. // are supported in FSRTL_COMMON_HEADER, and can be used to associate
  152. // context for filesystem filters with streams.
  153. //
  154. #define FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS (0x02)
  155. //
  156. // If this flag is set, the cache manager will flush and purge the cache map when
  157. // a user first maps a file
  158. //
  159. #define FSRTL_FLAG2_PURGE_WHEN_MAPPED (0x04)
  160. //
  161. // The following constants are used to block top level Irp processing when
  162. // (in either the fast io or cc case) file system resources have been
  163. // acquired above the file system, or we are in an Fsp thread.
  164. //
  165. #define FSRTL_FSP_TOP_LEVEL_IRP 0x01
  166. #define FSRTL_CACHE_TOP_LEVEL_IRP 0x02
  167. #define FSRTL_MOD_WRITE_TOP_LEVEL_IRP 0x03
  168. #define FSRTL_FAST_IO_TOP_LEVEL_IRP 0x04
  169. #define FSRTL_MAX_TOP_LEVEL_IRP_FLAG 0x04
  170. //
  171. // The following structure is used to synchronize Eof extends.
  172. //
  173. typedef struct _EOF_WAIT_BLOCK {
  174. LIST_ENTRY EofWaitLinks;
  175. KEVENT Event;
  176. } EOF_WAIT_BLOCK;
  177. typedef EOF_WAIT_BLOCK *PEOF_WAIT_BLOCK;
  178. // begin_ntosp
  179. //
  180. // Normal uncompressed Copy and Mdl Apis
  181. //
  182. NTKERNELAPI
  183. BOOLEAN
  184. FsRtlCopyRead (
  185. IN PFILE_OBJECT FileObject,
  186. IN PLARGE_INTEGER FileOffset,
  187. IN ULONG Length,
  188. IN BOOLEAN Wait,
  189. IN ULONG LockKey,
  190. OUT PVOID Buffer,
  191. OUT PIO_STATUS_BLOCK IoStatus,
  192. IN PDEVICE_OBJECT DeviceObject
  193. );
  194. NTKERNELAPI
  195. BOOLEAN
  196. FsRtlCopyWrite (
  197. IN PFILE_OBJECT FileObject,
  198. IN PLARGE_INTEGER FileOffset,
  199. IN ULONG Length,
  200. IN BOOLEAN Wait,
  201. IN ULONG LockKey,
  202. IN PVOID Buffer,
  203. OUT PIO_STATUS_BLOCK IoStatus,
  204. IN PDEVICE_OBJECT DeviceObject
  205. );
  206. // end_ntifs
  207. NTKERNELAPI
  208. BOOLEAN
  209. FsRtlMdlRead (
  210. IN PFILE_OBJECT FileObject,
  211. IN PLARGE_INTEGER FileOffset,
  212. IN ULONG Length,
  213. IN ULONG LockKey,
  214. OUT PMDL *MdlChain,
  215. OUT PIO_STATUS_BLOCK IoStatus
  216. );
  217. BOOLEAN
  218. FsRtlMdlReadComplete (
  219. IN PFILE_OBJECT FileObject,
  220. IN PMDL MdlChain
  221. );
  222. // end_ntosp
  223. NTKERNELAPI
  224. BOOLEAN
  225. FsRtlPrepareMdlWrite (
  226. IN PFILE_OBJECT FileObject,
  227. IN PLARGE_INTEGER FileOffset,
  228. IN ULONG Length,
  229. IN ULONG LockKey,
  230. OUT PMDL *MdlChain,
  231. OUT PIO_STATUS_BLOCK IoStatus
  232. );
  233. BOOLEAN
  234. FsRtlMdlWriteComplete (
  235. IN PFILE_OBJECT FileObject,
  236. IN PLARGE_INTEGER FileOffset,
  237. IN PMDL MdlChain
  238. );
  239. // begin_ntifs
  240. NTKERNELAPI
  241. BOOLEAN
  242. FsRtlMdlReadDev (
  243. IN PFILE_OBJECT FileObject,
  244. IN PLARGE_INTEGER FileOffset,
  245. IN ULONG Length,
  246. IN ULONG LockKey,
  247. OUT PMDL *MdlChain,
  248. OUT PIO_STATUS_BLOCK IoStatus,
  249. IN PDEVICE_OBJECT DeviceObject
  250. );
  251. NTKERNELAPI
  252. BOOLEAN
  253. FsRtlMdlReadCompleteDev (
  254. IN PFILE_OBJECT FileObject,
  255. IN PMDL MdlChain,
  256. IN PDEVICE_OBJECT DeviceObject
  257. );
  258. NTKERNELAPI
  259. BOOLEAN
  260. FsRtlPrepareMdlWriteDev (
  261. IN PFILE_OBJECT FileObject,
  262. IN PLARGE_INTEGER FileOffset,
  263. IN ULONG Length,
  264. IN ULONG LockKey,
  265. OUT PMDL *MdlChain,
  266. OUT PIO_STATUS_BLOCK IoStatus,
  267. IN PDEVICE_OBJECT DeviceObject
  268. );
  269. NTKERNELAPI
  270. BOOLEAN
  271. FsRtlMdlWriteCompleteDev (
  272. IN PFILE_OBJECT FileObject,
  273. IN PLARGE_INTEGER FileOffset,
  274. IN PMDL MdlChain,
  275. IN PDEVICE_OBJECT DeviceObject
  276. );
  277. //
  278. // In Irps, compressed reads and writes are designated by the
  279. // subfunction IRP_MN_COMPRESSED must be set and the Compressed
  280. // Data Info buffer must be described by the following structure
  281. // pointed to by Irp->Tail.Overlay.AuxiliaryBuffer.
  282. //
  283. typedef struct _FSRTL_AUXILIARY_BUFFER {
  284. //
  285. // Buffer description with length.
  286. //
  287. PVOID Buffer;
  288. ULONG Length;
  289. //
  290. // Flags
  291. //
  292. ULONG Flags;
  293. //
  294. // Pointer to optional Mdl mapping buffer for file system use
  295. //
  296. PMDL Mdl;
  297. } FSRTL_AUXILIARY_BUFFER;
  298. typedef FSRTL_AUXILIARY_BUFFER *PFSRTL_AUXILIARY_BUFFER;
  299. //
  300. // If this flag is set, the auxiliary buffer structure is
  301. // deallocated on Irp completion. The caller has the
  302. // option in this case of appending this structure to the
  303. // structure being described, causing it all to be
  304. // deallocated at once. If this flag is clear, no deallocate
  305. // occurs.
  306. //
  307. #define FSRTL_AUXILIARY_FLAG_DEALLOCATE 0x00000001
  308. // end_ntifs
  309. //
  310. // The following routines are intended to be called by Mm to avoid deadlocks.
  311. // They prerequire file system resources before acquire Mm resources.
  312. //
  313. //
  314. // This macro is called once when the ModifiedPageWriter is started.
  315. //
  316. #define FsRtlSetTopLevelIrpForModWriter() { \
  317. IoSetTopLevelIrp((PIRP)FSRTL_MOD_WRITE_TOP_LEVEL_IRP); \
  318. }
  319. NTKERNELAPI
  320. BOOLEAN
  321. FsRtlAcquireFileForModWrite (
  322. IN PFILE_OBJECT FileObject,
  323. IN PLARGE_INTEGER EndingOffset,
  324. OUT PERESOURCE *ResourceToRelease
  325. );
  326. NTKERNELAPI
  327. NTSTATUS
  328. FsRtlAcquireFileForModWriteEx (
  329. IN PFILE_OBJECT FileObject,
  330. IN PLARGE_INTEGER EndingOffset,
  331. OUT PERESOURCE *ResourceToRelease
  332. );
  333. NTKERNELAPI
  334. VOID
  335. FsRtlReleaseFileForModWrite (
  336. IN PFILE_OBJECT FileObject,
  337. IN PERESOURCE ResourceToRelease
  338. );
  339. NTKERNELAPI
  340. VOID
  341. FsRtlAcquireFileForCcFlush (
  342. IN PFILE_OBJECT FileObject
  343. );
  344. NTKERNELAPI
  345. NTSTATUS
  346. FsRtlAcquireFileForCcFlushEx (
  347. IN PFILE_OBJECT FileObject
  348. );
  349. NTKERNELAPI
  350. VOID
  351. FsRtlReleaseFileForCcFlush (
  352. IN PFILE_OBJECT FileObject
  353. );
  354. NTKERNELAPI
  355. NTSTATUS
  356. FsRtlAcquireToCreateMappedSection (
  357. IN PFILE_OBJECT FileObject,
  358. IN ULONG SectionPageProtection
  359. );
  360. NTKERNELAPI
  361. NTSTATUS
  362. FsRtlAcquireFileExclusiveCommon (
  363. IN PFILE_OBJECT FileObject,
  364. IN FS_FILTER_SECTION_SYNC_TYPE SyncType,
  365. IN ULONG SectionPageProtection
  366. );
  367. // begin_ntifs
  368. //
  369. // The following two routines are called from NtCreateSection to avoid
  370. // deadlocks with the file systems.
  371. //
  372. NTKERNELAPI
  373. VOID
  374. FsRtlAcquireFileExclusive (
  375. IN PFILE_OBJECT FileObject
  376. );
  377. NTKERNELAPI
  378. VOID
  379. FsRtlReleaseFile (
  380. IN PFILE_OBJECT FileObject
  381. );
  382. //
  383. // These routines provide a simple interface for the common operations
  384. // of query/set file size.
  385. //
  386. NTSTATUS
  387. FsRtlGetFileSize(
  388. IN PFILE_OBJECT FileObject,
  389. IN OUT PLARGE_INTEGER FileSize
  390. );
  391. // end_ntifs
  392. NTSTATUS
  393. FsRtlSetFileSize(
  394. IN PFILE_OBJECT FileObject,
  395. IN OUT PLARGE_INTEGER FileSize
  396. );
  397. // begin_ntddk begin_ntifs
  398. //
  399. // Determine if there is a complete device failure on an error.
  400. //
  401. NTKERNELAPI
  402. BOOLEAN
  403. FsRtlIsTotalDeviceFailure(
  404. IN NTSTATUS Status
  405. );
  406. // end_ntddk
  407. //
  408. // Byte range file lock routines, implemented in FileLock.c
  409. //
  410. // The file lock info record is used to return enumerated information
  411. // about a file lock
  412. //
  413. typedef struct _FILE_LOCK_INFO {
  414. //
  415. // A description of the current locked range, and if the lock
  416. // is exclusive or shared
  417. //
  418. LARGE_INTEGER StartingByte;
  419. LARGE_INTEGER Length;
  420. BOOLEAN ExclusiveLock;
  421. //
  422. // The following fields describe the owner of the lock.
  423. //
  424. ULONG Key;
  425. PFILE_OBJECT FileObject;
  426. PVOID ProcessId;
  427. //
  428. // The following field is used internally by FsRtl
  429. //
  430. LARGE_INTEGER EndingByte;
  431. } FILE_LOCK_INFO;
  432. typedef FILE_LOCK_INFO *PFILE_LOCK_INFO;
  433. //
  434. // The following two procedure prototypes are used by the caller of the
  435. // file lock package to supply an alternate routine to call when
  436. // completing an IRP and when unlocking a byte range. Note that the only
  437. // utility to us this interface is currently the redirector, all other file
  438. // system will probably let the IRP complete normally with IoCompleteRequest.
  439. // The user supplied routine returns any value other than success then the
  440. // lock package will remove any lock that we just inserted.
  441. //
  442. typedef NTSTATUS (*PCOMPLETE_LOCK_IRP_ROUTINE) (
  443. IN PVOID Context,
  444. IN PIRP Irp
  445. );
  446. typedef VOID (*PUNLOCK_ROUTINE) (
  447. IN PVOID Context,
  448. IN PFILE_LOCK_INFO FileLockInfo
  449. );
  450. //
  451. // A FILE_LOCK is an opaque structure but we need to declare the size of
  452. // it here so that users can allocate space for one.
  453. //
  454. typedef struct _FILE_LOCK {
  455. //
  456. // The optional procedure to call to complete a request
  457. //
  458. PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine;
  459. //
  460. // The optional procedure to call when unlocking a byte range
  461. //
  462. PUNLOCK_ROUTINE UnlockRoutine;
  463. //
  464. // FastIoIsQuestionable is set to true whenever the filesystem require
  465. // additional checking about whether the fast path can be taken. As an
  466. // example Ntfs requires checking for disk space before the writes can
  467. // occur.
  468. //
  469. BOOLEAN FastIoIsQuestionable;
  470. BOOLEAN SpareC[3];
  471. //
  472. // FsRtl lock information
  473. //
  474. PVOID LockInformation;
  475. //
  476. // Contains continuation information for FsRtlGetNextFileLock
  477. //
  478. FILE_LOCK_INFO LastReturnedLockInfo;
  479. PVOID LastReturnedLock;
  480. } FILE_LOCK;
  481. typedef FILE_LOCK *PFILE_LOCK;
  482. PFILE_LOCK
  483. FsRtlAllocateFileLock (
  484. IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL,
  485. IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL
  486. );
  487. VOID
  488. FsRtlFreeFileLock (
  489. IN PFILE_LOCK FileLock
  490. );
  491. NTKERNELAPI
  492. VOID
  493. FsRtlInitializeFileLock (
  494. IN PFILE_LOCK FileLock,
  495. IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL,
  496. IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL
  497. );
  498. NTKERNELAPI
  499. VOID
  500. FsRtlUninitializeFileLock (
  501. IN PFILE_LOCK FileLock
  502. );
  503. NTKERNELAPI
  504. NTSTATUS
  505. FsRtlProcessFileLock (
  506. IN PFILE_LOCK FileLock,
  507. IN PIRP Irp,
  508. IN PVOID Context OPTIONAL
  509. );
  510. NTKERNELAPI
  511. BOOLEAN
  512. FsRtlCheckLockForReadAccess (
  513. IN PFILE_LOCK FileLock,
  514. IN PIRP Irp
  515. );
  516. NTKERNELAPI
  517. BOOLEAN
  518. FsRtlCheckLockForWriteAccess (
  519. IN PFILE_LOCK FileLock,
  520. IN PIRP Irp
  521. );
  522. NTKERNELAPI
  523. BOOLEAN
  524. FsRtlFastCheckLockForRead (
  525. IN PFILE_LOCK FileLock,
  526. IN PLARGE_INTEGER StartingByte,
  527. IN PLARGE_INTEGER Length,
  528. IN ULONG Key,
  529. IN PFILE_OBJECT FileObject,
  530. IN PVOID ProcessId
  531. );
  532. NTKERNELAPI
  533. BOOLEAN
  534. FsRtlFastCheckLockForWrite (
  535. IN PFILE_LOCK FileLock,
  536. IN PLARGE_INTEGER StartingByte,
  537. IN PLARGE_INTEGER Length,
  538. IN ULONG Key,
  539. IN PVOID FileObject,
  540. IN PVOID ProcessId
  541. );
  542. NTKERNELAPI
  543. PFILE_LOCK_INFO
  544. FsRtlGetNextFileLock (
  545. IN PFILE_LOCK FileLock,
  546. IN BOOLEAN Restart
  547. );
  548. NTKERNELAPI
  549. NTSTATUS
  550. FsRtlFastUnlockSingle (
  551. IN PFILE_LOCK FileLock,
  552. IN PFILE_OBJECT FileObject,
  553. IN LARGE_INTEGER UNALIGNED *FileOffset,
  554. IN PLARGE_INTEGER Length,
  555. IN PEPROCESS ProcessId,
  556. IN ULONG Key,
  557. IN PVOID Context OPTIONAL,
  558. IN BOOLEAN AlreadySynchronized
  559. );
  560. NTKERNELAPI
  561. NTSTATUS
  562. FsRtlFastUnlockAll (
  563. IN PFILE_LOCK FileLock,
  564. IN PFILE_OBJECT FileObject,
  565. IN PEPROCESS ProcessId,
  566. IN PVOID Context OPTIONAL
  567. );
  568. NTKERNELAPI
  569. NTSTATUS
  570. FsRtlFastUnlockAllByKey (
  571. IN PFILE_LOCK FileLock,
  572. IN PFILE_OBJECT FileObject,
  573. IN PEPROCESS ProcessId,
  574. IN ULONG Key,
  575. IN PVOID Context OPTIONAL
  576. );
  577. NTKERNELAPI
  578. BOOLEAN
  579. FsRtlPrivateLock (
  580. IN PFILE_LOCK FileLock,
  581. IN PFILE_OBJECT FileObject,
  582. IN PLARGE_INTEGER FileOffset,
  583. IN PLARGE_INTEGER Length,
  584. IN PEPROCESS ProcessId,
  585. IN ULONG Key,
  586. IN BOOLEAN FailImmediately,
  587. IN BOOLEAN ExclusiveLock,
  588. OUT PIO_STATUS_BLOCK Iosb,
  589. IN PIRP Irp,
  590. IN PVOID Context,
  591. IN BOOLEAN AlreadySynchronized
  592. );
  593. //
  594. // BOOLEAN
  595. // FsRtlFastLock (
  596. // IN PFILE_LOCK FileLock,
  597. // IN PFILE_OBJECT FileObject,
  598. // IN PLARGE_INTEGER FileOffset,
  599. // IN PLARGE_INTEGER Length,
  600. // IN PEPROCESS ProcessId,
  601. // IN ULONG Key,
  602. // IN BOOLEAN FailImmediately,
  603. // IN BOOLEAN ExclusiveLock,
  604. // OUT PIO_STATUS_BLOCK Iosb,
  605. // IN PVOID Context OPTIONAL,
  606. // IN BOOLEAN AlreadySynchronized
  607. // );
  608. //
  609. #define FsRtlFastLock(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11) ( \
  610. FsRtlPrivateLock( A1, /* FileLock */ \
  611. A2, /* FileObject */ \
  612. A3, /* FileOffset */ \
  613. A4, /* Length */ \
  614. A5, /* ProcessId */ \
  615. A6, /* Key */ \
  616. A7, /* FailImmediately */ \
  617. A8, /* ExclusiveLock */ \
  618. A9, /* Iosb */ \
  619. NULL, /* Irp */ \
  620. A10, /* Context */ \
  621. A11 /* AlreadySynchronized */ ) \
  622. )
  623. //
  624. // BOOLEAN
  625. // FsRtlAreThereCurrentFileLocks (
  626. // IN PFILE_LOCK FileLock
  627. // );
  628. //
  629. #define FsRtlAreThereCurrentFileLocks(FL) ( \
  630. ((FL)->FastIoIsQuestionable))
  631. //
  632. // Filesystem property tunneling, implemented in tunnel.c
  633. //
  634. //
  635. // Tunnel cache structure
  636. //
  637. typedef struct {
  638. //
  639. // Mutex for cache manipulation
  640. //
  641. FAST_MUTEX Mutex;
  642. //
  643. // Splay Tree of tunneled information keyed by
  644. // DirKey ## Name
  645. //
  646. PRTL_SPLAY_LINKS Cache;
  647. //
  648. // Timer queue used to age entries out of the main cache
  649. //
  650. LIST_ENTRY TimerQueue;
  651. //
  652. // Keep track of the number of entries in the cache to prevent
  653. // excessive use of memory
  654. //
  655. USHORT NumEntries;
  656. } TUNNEL, *PTUNNEL;
  657. NTKERNELAPI
  658. VOID
  659. FsRtlInitializeTunnelCache (
  660. IN TUNNEL *Cache);
  661. NTKERNELAPI
  662. VOID
  663. FsRtlAddToTunnelCache (
  664. IN TUNNEL *Cache,
  665. IN ULONGLONG DirectoryKey,
  666. IN UNICODE_STRING *ShortName,
  667. IN UNICODE_STRING *LongName,
  668. IN BOOLEAN KeyByShortName,
  669. IN ULONG DataLength,
  670. IN VOID *Data);
  671. NTKERNELAPI
  672. BOOLEAN
  673. FsRtlFindInTunnelCache (
  674. IN TUNNEL *Cache,
  675. IN ULONGLONG DirectoryKey,
  676. IN UNICODE_STRING *Name,
  677. OUT UNICODE_STRING *ShortName,
  678. OUT UNICODE_STRING *LongName,
  679. IN OUT ULONG *DataLength,
  680. OUT VOID *Data);
  681. NTKERNELAPI
  682. VOID
  683. FsRtlDeleteKeyFromTunnelCache (
  684. IN TUNNEL *Cache,
  685. IN ULONGLONG DirectoryKey);
  686. NTKERNELAPI
  687. VOID
  688. FsRtlDeleteTunnelCache (
  689. IN TUNNEL *Cache);
  690. //
  691. // Dbcs name support routines, implemented in DbcsName.c
  692. //
  693. //
  694. // The following enumerated type is used to denote the result of name
  695. // comparisons
  696. //
  697. typedef enum _FSRTL_COMPARISON_RESULT {
  698. LessThan = -1,
  699. EqualTo = 0,
  700. GreaterThan = 1
  701. } FSRTL_COMPARISON_RESULT;
  702. #ifdef NLS_MB_CODE_PAGE_TAG
  703. #undef NLS_MB_CODE_PAGE_TAG
  704. #endif // NLS_MB_CODE_PAGE_TAG
  705. // end_ntifs
  706. #if defined(_NTIFS_) || defined(_NTDRIVER_)
  707. // begin_ntifs
  708. #define LEGAL_ANSI_CHARACTER_ARRAY (*FsRtlLegalAnsiCharacterArray) // ntosp
  709. #define NLS_MB_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
  710. #define NLS_OEM_LEAD_BYTE_INFO (*NlsOemLeadByteInfo) // ntosp
  711. // end_ntifs
  712. #else
  713. #define LEGAL_ANSI_CHARACTER_ARRAY FsRtlLegalAnsiCharacterArray
  714. #define NLS_MB_CODE_PAGE_TAG NlsMbOemCodePageTag
  715. #define NLS_OEM_LEAD_BYTE_INFO NlsOemLeadByteInfo
  716. #endif
  717. // begin_ntifs begin_ntosp
  718. extern UCHAR const* const LEGAL_ANSI_CHARACTER_ARRAY;
  719. extern PUSHORT NLS_OEM_LEAD_BYTE_INFO; // Lead byte info. for ACP
  720. //
  721. // These following bit values are set in the FsRtlLegalDbcsCharacterArray
  722. //
  723. #define FSRTL_FAT_LEGAL 0x01
  724. #define FSRTL_HPFS_LEGAL 0x02
  725. #define FSRTL_NTFS_LEGAL 0x04
  726. #define FSRTL_WILD_CHARACTER 0x08
  727. #define FSRTL_OLE_LEGAL 0x10
  728. #define FSRTL_NTFS_STREAM_LEGAL (FSRTL_NTFS_LEGAL | FSRTL_OLE_LEGAL)
  729. //
  730. // The following macro is used to determine if an Ansi character is wild.
  731. //
  732. #define FsRtlIsAnsiCharacterWild(C) ( \
  733. FsRtlTestAnsiCharacter((C), FALSE, FALSE, FSRTL_WILD_CHARACTER) \
  734. )
  735. //
  736. // The following macro is used to determine if an Ansi character is Fat legal.
  737. //
  738. #define FsRtlIsAnsiCharacterLegalFat(C,WILD_OK) ( \
  739. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_FAT_LEGAL) \
  740. )
  741. //
  742. // The following macro is used to determine if an Ansi character is Hpfs legal.
  743. //
  744. #define FsRtlIsAnsiCharacterLegalHpfs(C,WILD_OK) ( \
  745. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_HPFS_LEGAL) \
  746. )
  747. //
  748. // The following macro is used to determine if an Ansi character is Ntfs legal.
  749. //
  750. #define FsRtlIsAnsiCharacterLegalNtfs(C,WILD_OK) ( \
  751. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_LEGAL) \
  752. )
  753. //
  754. // The following macro is used to determine if an Ansi character is
  755. // legal in an Ntfs stream name
  756. //
  757. #define FsRtlIsAnsiCharacterLegalNtfsStream(C,WILD_OK) ( \
  758. FsRtlTestAnsiCharacter((C), TRUE, (WILD_OK), FSRTL_NTFS_STREAM_LEGAL) \
  759. )
  760. //
  761. // The following macro is used to determine if an Ansi character is legal,
  762. // according to the caller's specification.
  763. //
  764. #define FsRtlIsAnsiCharacterLegal(C,FLAGS) ( \
  765. FsRtlTestAnsiCharacter((C), TRUE, FALSE, (FLAGS)) \
  766. )
  767. //
  768. // The following macro is used to test attributes of an Ansi character,
  769. // according to the caller's specified flags.
  770. //
  771. #define FsRtlTestAnsiCharacter(C, DEFAULT_RET, WILD_OK, FLAGS) ( \
  772. ((SCHAR)(C) < 0) ? DEFAULT_RET : \
  773. FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  774. (FLAGS) | \
  775. ((WILD_OK) ? FSRTL_WILD_CHARACTER : 0) ) \
  776. )
  777. //
  778. // The following two macros use global data defined in ntos\rtl\nlsdata.c
  779. //
  780. // BOOLEAN
  781. // FsRtlIsLeadDbcsCharacter (
  782. // IN UCHAR DbcsCharacter
  783. // );
  784. //
  785. // /*++
  786. //
  787. // Routine Description:
  788. //
  789. // This routine takes the first bytes of a Dbcs character and
  790. // returns whether it is a lead byte in the system code page.
  791. //
  792. // Arguments:
  793. //
  794. // DbcsCharacter - Supplies the input character being examined
  795. //
  796. // Return Value:
  797. //
  798. // BOOLEAN - TRUE if the input character is a dbcs lead and
  799. // FALSE otherwise
  800. //
  801. // --*/
  802. //
  803. //
  804. #define FsRtlIsLeadDbcsCharacter(DBCS_CHAR) ( \
  805. (BOOLEAN)((UCHAR)(DBCS_CHAR) < 0x80 ? FALSE : \
  806. (NLS_MB_CODE_PAGE_TAG && \
  807. (NLS_OEM_LEAD_BYTE_INFO[(UCHAR)(DBCS_CHAR)] != 0))) \
  808. )
  809. NTKERNELAPI
  810. VOID
  811. FsRtlDissectDbcs (
  812. IN ANSI_STRING InputName,
  813. OUT PANSI_STRING FirstPart,
  814. OUT PANSI_STRING RemainingPart
  815. );
  816. NTKERNELAPI
  817. BOOLEAN
  818. FsRtlDoesDbcsContainWildCards (
  819. IN PANSI_STRING Name
  820. );
  821. NTKERNELAPI
  822. BOOLEAN
  823. FsRtlIsDbcsInExpression (
  824. IN PANSI_STRING Expression,
  825. IN PANSI_STRING Name
  826. );
  827. NTKERNELAPI
  828. BOOLEAN
  829. FsRtlIsFatDbcsLegal (
  830. IN ANSI_STRING DbcsName,
  831. IN BOOLEAN WildCardsPermissible,
  832. IN BOOLEAN PathNamePermissible,
  833. IN BOOLEAN LeadingBackslashPermissible
  834. );
  835. // end_ntosp
  836. NTKERNELAPI
  837. BOOLEAN
  838. FsRtlIsHpfsDbcsLegal (
  839. IN ANSI_STRING DbcsName,
  840. IN BOOLEAN WildCardsPermissible,
  841. IN BOOLEAN PathNamePermissible,
  842. IN BOOLEAN LeadingBackslashPermissible
  843. );
  844. //
  845. // Exception filter routines, implemented in Filter.c
  846. //
  847. NTKERNELAPI
  848. NTSTATUS
  849. FsRtlNormalizeNtstatus (
  850. IN NTSTATUS Exception,
  851. IN NTSTATUS GenericException
  852. );
  853. NTKERNELAPI
  854. BOOLEAN
  855. FsRtlIsNtstatusExpected (
  856. IN NTSTATUS Exception
  857. );
  858. //
  859. // The following procedures are used to allocate executive pool and raise
  860. // insufficient resource status if pool isn't currently available.
  861. //
  862. #define FsRtlAllocatePoolWithTag(PoolType, NumberOfBytes, Tag) \
  863. ExAllocatePoolWithTag((POOL_TYPE)((PoolType) | POOL_RAISE_IF_ALLOCATION_FAILURE), \
  864. NumberOfBytes, \
  865. Tag)
  866. #define FsRtlAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, Tag) \
  867. ExAllocatePoolWithQuotaTag((POOL_TYPE)((PoolType) | POOL_RAISE_IF_ALLOCATION_FAILURE), \
  868. NumberOfBytes, \
  869. Tag)
  870. //
  871. // The following function allocates a resource from the FsRtl pool.
  872. //
  873. NTKERNELAPI
  874. PERESOURCE
  875. FsRtlAllocateResource (
  876. );
  877. //
  878. // Large Integer Mapped Control Blocks routines, implemented in LargeMcb.c
  879. //
  880. // Originally this structure was truly opaque and code outside largemcb was
  881. // never allowed to examine or alter the structures. However, for performance
  882. // reasons we want to allow ntfs the ability to quickly truncate down the
  883. // mcb without the overhead of an actual call to largemcb.c. So to do that we
  884. // need to export the structure. This structure is not exact. The Mapping field
  885. // is declared here as a pvoid but largemcb.c it is a pointer to mapping pairs.
  886. //
  887. typedef struct _LARGE_MCB {
  888. PFAST_MUTEX FastMutex;
  889. ULONG MaximumPairCount;
  890. ULONG PairCount;
  891. POOL_TYPE PoolType;
  892. PVOID Mapping;
  893. } LARGE_MCB;
  894. typedef LARGE_MCB *PLARGE_MCB;
  895. NTKERNELAPI
  896. VOID
  897. FsRtlInitializeLargeMcb (
  898. IN PLARGE_MCB Mcb,
  899. IN POOL_TYPE PoolType
  900. );
  901. NTKERNELAPI
  902. VOID
  903. FsRtlUninitializeLargeMcb (
  904. IN PLARGE_MCB Mcb
  905. );
  906. NTKERNELAPI
  907. VOID
  908. FsRtlResetLargeMcb (
  909. IN PLARGE_MCB Mcb,
  910. IN BOOLEAN SelfSynchronized
  911. );
  912. NTKERNELAPI
  913. VOID
  914. FsRtlTruncateLargeMcb (
  915. IN PLARGE_MCB Mcb,
  916. IN LONGLONG Vbn
  917. );
  918. NTKERNELAPI
  919. BOOLEAN
  920. FsRtlAddLargeMcbEntry (
  921. IN PLARGE_MCB Mcb,
  922. IN LONGLONG Vbn,
  923. IN LONGLONG Lbn,
  924. IN LONGLONG SectorCount
  925. );
  926. NTKERNELAPI
  927. VOID
  928. FsRtlRemoveLargeMcbEntry (
  929. IN PLARGE_MCB Mcb,
  930. IN LONGLONG Vbn,
  931. IN LONGLONG SectorCount
  932. );
  933. NTKERNELAPI
  934. BOOLEAN
  935. FsRtlLookupLargeMcbEntry (
  936. IN PLARGE_MCB Mcb,
  937. IN LONGLONG Vbn,
  938. OUT PLONGLONG Lbn OPTIONAL,
  939. OUT PLONGLONG SectorCountFromLbn OPTIONAL,
  940. OUT PLONGLONG StartingLbn OPTIONAL,
  941. OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL,
  942. OUT PULONG Index OPTIONAL
  943. );
  944. NTKERNELAPI
  945. BOOLEAN
  946. FsRtlLookupLastLargeMcbEntry (
  947. IN PLARGE_MCB Mcb,
  948. OUT PLONGLONG Vbn,
  949. OUT PLONGLONG Lbn
  950. );
  951. NTKERNELAPI
  952. BOOLEAN
  953. FsRtlLookupLastLargeMcbEntryAndIndex (
  954. IN PLARGE_MCB OpaqueMcb,
  955. OUT PLONGLONG LargeVbn,
  956. OUT PLONGLONG LargeLbn,
  957. OUT PULONG Index
  958. );
  959. NTKERNELAPI
  960. ULONG
  961. FsRtlNumberOfRunsInLargeMcb (
  962. IN PLARGE_MCB Mcb
  963. );
  964. NTKERNELAPI
  965. BOOLEAN
  966. FsRtlGetNextLargeMcbEntry (
  967. IN PLARGE_MCB Mcb,
  968. IN ULONG RunIndex,
  969. OUT PLONGLONG Vbn,
  970. OUT PLONGLONG Lbn,
  971. OUT PLONGLONG SectorCount
  972. );
  973. NTKERNELAPI
  974. BOOLEAN
  975. FsRtlSplitLargeMcb (
  976. IN PLARGE_MCB Mcb,
  977. IN LONGLONG Vbn,
  978. IN LONGLONG Amount
  979. );
  980. //
  981. // Mapped Control Blocks routines, implemented in Mcb.c
  982. //
  983. // An MCB is an opaque structure but we need to declare the size of
  984. // it here so that users can allocate space for one. Consequently the
  985. // size computation here must be updated by hand if the MCB changes.
  986. //
  987. typedef struct _MCB {
  988. LARGE_MCB DummyFieldThatSizesThisStructureCorrectly;
  989. } MCB;
  990. typedef MCB *PMCB;
  991. NTKERNELAPI
  992. VOID
  993. FsRtlInitializeMcb (
  994. IN PMCB Mcb,
  995. IN POOL_TYPE PoolType
  996. );
  997. NTKERNELAPI
  998. VOID
  999. FsRtlUninitializeMcb (
  1000. IN PMCB Mcb
  1001. );
  1002. NTKERNELAPI
  1003. VOID
  1004. FsRtlTruncateMcb (
  1005. IN PMCB Mcb,
  1006. IN VBN Vbn
  1007. );
  1008. NTKERNELAPI
  1009. BOOLEAN
  1010. FsRtlAddMcbEntry (
  1011. IN PMCB Mcb,
  1012. IN VBN Vbn,
  1013. IN LBN Lbn,
  1014. IN ULONG SectorCount
  1015. );
  1016. NTKERNELAPI
  1017. VOID
  1018. FsRtlRemoveMcbEntry (
  1019. IN PMCB Mcb,
  1020. IN VBN Vbn,
  1021. IN ULONG SectorCount
  1022. );
  1023. NTKERNELAPI
  1024. BOOLEAN
  1025. FsRtlLookupMcbEntry (
  1026. IN PMCB Mcb,
  1027. IN VBN Vbn,
  1028. OUT PLBN Lbn,
  1029. OUT PULONG SectorCount OPTIONAL,
  1030. OUT PULONG Index
  1031. );
  1032. NTKERNELAPI
  1033. BOOLEAN
  1034. FsRtlLookupLastMcbEntry (
  1035. IN PMCB Mcb,
  1036. OUT PVBN Vbn,
  1037. OUT PLBN Lbn
  1038. );
  1039. NTKERNELAPI
  1040. ULONG
  1041. FsRtlNumberOfRunsInMcb (
  1042. IN PMCB Mcb
  1043. );
  1044. NTKERNELAPI
  1045. BOOLEAN
  1046. FsRtlGetNextMcbEntry (
  1047. IN PMCB Mcb,
  1048. IN ULONG RunIndex,
  1049. OUT PVBN Vbn,
  1050. OUT PLBN Lbn,
  1051. OUT PULONG SectorCount
  1052. );
  1053. //
  1054. // Fault Tolerance routines, implemented in FaultTol.c
  1055. //
  1056. // The routines in this package implement routines that help file
  1057. // systems interact with the FT device drivers.
  1058. //
  1059. NTKERNELAPI
  1060. NTSTATUS
  1061. FsRtlBalanceReads (
  1062. IN PDEVICE_OBJECT TargetDevice
  1063. );
  1064. // end_ntifs
  1065. NTKERNELAPI
  1066. NTSTATUS
  1067. FsRtlSyncVolumes (
  1068. IN PDEVICE_OBJECT TargetDevice,
  1069. IN PLARGE_INTEGER ByteOffset OPTIONAL,
  1070. IN PLARGE_INTEGER ByteCount
  1071. );
  1072. // begin_ntifs
  1073. //
  1074. // Oplock routines, implemented in Oplock.c
  1075. //
  1076. // An OPLOCK is an opaque structure, we declare it as a PVOID and
  1077. // allocate the actual memory only when needed.
  1078. //
  1079. typedef PVOID OPLOCK, *POPLOCK;
  1080. typedef
  1081. VOID
  1082. (*POPLOCK_WAIT_COMPLETE_ROUTINE) (
  1083. IN PVOID Context,
  1084. IN PIRP Irp
  1085. );
  1086. typedef
  1087. VOID
  1088. (*POPLOCK_FS_PREPOST_IRP) (
  1089. IN PVOID Context,
  1090. IN PIRP Irp
  1091. );
  1092. NTKERNELAPI
  1093. VOID
  1094. FsRtlInitializeOplock (
  1095. IN OUT POPLOCK Oplock
  1096. );
  1097. NTKERNELAPI
  1098. VOID
  1099. FsRtlUninitializeOplock (
  1100. IN OUT POPLOCK Oplock
  1101. );
  1102. NTKERNELAPI
  1103. NTSTATUS
  1104. FsRtlOplockFsctrl (
  1105. IN POPLOCK Oplock,
  1106. IN PIRP Irp,
  1107. IN ULONG OpenCount
  1108. );
  1109. NTKERNELAPI
  1110. NTSTATUS
  1111. FsRtlCheckOplock (
  1112. IN POPLOCK Oplock,
  1113. IN PIRP Irp,
  1114. IN PVOID Context,
  1115. IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL,
  1116. IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL
  1117. );
  1118. NTKERNELAPI
  1119. BOOLEAN
  1120. FsRtlOplockIsFastIoPossible (
  1121. IN POPLOCK Oplock
  1122. );
  1123. NTKERNELAPI
  1124. BOOLEAN
  1125. FsRtlCurrentBatchOplock (
  1126. IN POPLOCK Oplock
  1127. );
  1128. //
  1129. // Volume lock/unlock notification routines, implemented in PnP.c
  1130. //
  1131. // These routines provide PnP volume lock notification support
  1132. // for all filesystems.
  1133. //
  1134. #define FSRTL_VOLUME_DISMOUNT 1
  1135. #define FSRTL_VOLUME_DISMOUNT_FAILED 2
  1136. #define FSRTL_VOLUME_LOCK 3
  1137. #define FSRTL_VOLUME_LOCK_FAILED 4
  1138. #define FSRTL_VOLUME_UNLOCK 5
  1139. #define FSRTL_VOLUME_MOUNT 6
  1140. NTKERNELAPI
  1141. NTSTATUS
  1142. FsRtlNotifyVolumeEvent (
  1143. IN PFILE_OBJECT FileObject,
  1144. IN ULONG EventCode
  1145. );
  1146. //
  1147. // Notify Change routines, implemented in Notify.c
  1148. //
  1149. // These routines provide Notify Change support for all filesystems.
  1150. // Any of the 'Full' notify routines will support returning the
  1151. // change information into the user's buffer.
  1152. //
  1153. typedef PVOID PNOTIFY_SYNC;
  1154. typedef
  1155. BOOLEAN (*PCHECK_FOR_TRAVERSE_ACCESS) (
  1156. IN PVOID NotifyContext,
  1157. IN PVOID TargetContext,
  1158. IN PSECURITY_SUBJECT_CONTEXT SubjectContext
  1159. );
  1160. typedef
  1161. BOOLEAN (*PFILTER_REPORT_CHANGE) (
  1162. IN PVOID NotifyContext,
  1163. IN PVOID FilterContext
  1164. );
  1165. NTKERNELAPI
  1166. VOID
  1167. FsRtlNotifyInitializeSync (
  1168. IN PNOTIFY_SYNC *NotifySync
  1169. );
  1170. NTKERNELAPI
  1171. VOID
  1172. FsRtlNotifyUninitializeSync (
  1173. IN PNOTIFY_SYNC *NotifySync
  1174. );
  1175. // end_ntifs
  1176. NTKERNELAPI
  1177. VOID
  1178. FsRtlNotifyChangeDirectory (
  1179. IN PNOTIFY_SYNC NotifySync,
  1180. IN PVOID FsContext,
  1181. IN PSTRING FullDirectoryName,
  1182. IN PLIST_ENTRY NotifyList,
  1183. IN BOOLEAN WatchTree,
  1184. IN ULONG CompletionFilter,
  1185. IN PIRP NotifyIrp
  1186. );
  1187. // begin_ntifs
  1188. NTKERNELAPI
  1189. VOID
  1190. FsRtlNotifyFullChangeDirectory (
  1191. IN PNOTIFY_SYNC NotifySync,
  1192. IN PLIST_ENTRY NotifyList,
  1193. IN PVOID FsContext,
  1194. IN PSTRING FullDirectoryName,
  1195. IN BOOLEAN WatchTree,
  1196. IN BOOLEAN IgnoreBuffer,
  1197. IN ULONG CompletionFilter,
  1198. IN PIRP NotifyIrp,
  1199. IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL,
  1200. IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL
  1201. );
  1202. NTKERNELAPI
  1203. VOID
  1204. FsRtlNotifyFilterChangeDirectory (
  1205. IN PNOTIFY_SYNC NotifySync,
  1206. IN PLIST_ENTRY NotifyList,
  1207. IN PVOID FsContext,
  1208. IN PSTRING FullDirectoryName,
  1209. IN BOOLEAN WatchTree,
  1210. IN BOOLEAN IgnoreBuffer,
  1211. IN ULONG CompletionFilter,
  1212. IN PIRP NotifyIrp,
  1213. IN PCHECK_FOR_TRAVERSE_ACCESS TraverseCallback OPTIONAL,
  1214. IN PSECURITY_SUBJECT_CONTEXT SubjectContext OPTIONAL,
  1215. IN PFILTER_REPORT_CHANGE FilterCallback OPTIONAL
  1216. );
  1217. NTKERNELAPI
  1218. VOID
  1219. FsRtlNotifyFilterReportChange (
  1220. IN PNOTIFY_SYNC NotifySync,
  1221. IN PLIST_ENTRY NotifyList,
  1222. IN PSTRING FullTargetName,
  1223. IN USHORT TargetNameOffset,
  1224. IN PSTRING StreamName OPTIONAL,
  1225. IN PSTRING NormalizedParentName OPTIONAL,
  1226. IN ULONG FilterMatch,
  1227. IN ULONG Action,
  1228. IN PVOID TargetContext,
  1229. IN PVOID FilterContext
  1230. );
  1231. // end_ntifs
  1232. NTKERNELAPI
  1233. VOID
  1234. FsRtlNotifyReportChange (
  1235. IN PNOTIFY_SYNC NotifySync,
  1236. IN PLIST_ENTRY NotifyList,
  1237. IN PSTRING FullTargetName,
  1238. IN PSTRING TargetName,
  1239. IN ULONG FilterMatch
  1240. );
  1241. // begin_ntifs
  1242. NTKERNELAPI
  1243. VOID
  1244. FsRtlNotifyFullReportChange (
  1245. IN PNOTIFY_SYNC NotifySync,
  1246. IN PLIST_ENTRY NotifyList,
  1247. IN PSTRING FullTargetName,
  1248. IN USHORT TargetNameOffset,
  1249. IN PSTRING StreamName OPTIONAL,
  1250. IN PSTRING NormalizedParentName OPTIONAL,
  1251. IN ULONG FilterMatch,
  1252. IN ULONG Action,
  1253. IN PVOID TargetContext
  1254. );
  1255. NTKERNELAPI
  1256. VOID
  1257. FsRtlNotifyCleanup (
  1258. IN PNOTIFY_SYNC NotifySync,
  1259. IN PLIST_ENTRY NotifyList,
  1260. IN PVOID FsContext
  1261. );
  1262. //
  1263. // Unicode Name support routines, implemented in Name.c
  1264. //
  1265. // The routines here are used to manipulate unicode names
  1266. //
  1267. //
  1268. // The following macro is used to determine if a character is wild.
  1269. //
  1270. #define FsRtlIsUnicodeCharacterWild(C) ( \
  1271. (((C) >= 0x40) ? FALSE : FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  1272. FSRTL_WILD_CHARACTER ) ) \
  1273. )
  1274. NTKERNELAPI
  1275. VOID
  1276. FsRtlDissectName (
  1277. IN UNICODE_STRING Path,
  1278. OUT PUNICODE_STRING FirstName,
  1279. OUT PUNICODE_STRING RemainingName
  1280. );
  1281. NTKERNELAPI
  1282. BOOLEAN
  1283. FsRtlDoesNameContainWildCards (
  1284. IN PUNICODE_STRING Name
  1285. );
  1286. NTKERNELAPI
  1287. BOOLEAN
  1288. FsRtlAreNamesEqual (
  1289. PCUNICODE_STRING ConstantNameA,
  1290. PCUNICODE_STRING ConstantNameB,
  1291. IN BOOLEAN IgnoreCase,
  1292. IN PCWCH UpcaseTable OPTIONAL
  1293. );
  1294. NTKERNELAPI
  1295. BOOLEAN
  1296. FsRtlIsNameInExpression (
  1297. IN PUNICODE_STRING Expression,
  1298. IN PUNICODE_STRING Name,
  1299. IN BOOLEAN IgnoreCase,
  1300. IN PWCH UpcaseTable OPTIONAL
  1301. );
  1302. //
  1303. // Stack Overflow support routine, implemented in StackOvf.c
  1304. //
  1305. typedef
  1306. VOID
  1307. (*PFSRTL_STACK_OVERFLOW_ROUTINE) (
  1308. IN PVOID Context,
  1309. IN PKEVENT Event
  1310. );
  1311. NTKERNELAPI
  1312. VOID
  1313. FsRtlPostStackOverflow (
  1314. IN PVOID Context,
  1315. IN PKEVENT Event,
  1316. IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine
  1317. );
  1318. NTKERNELAPI
  1319. VOID
  1320. FsRtlPostPagingFileStackOverflow (
  1321. IN PVOID Context,
  1322. IN PKEVENT Event,
  1323. IN PFSRTL_STACK_OVERFLOW_ROUTINE StackOverflowRoutine
  1324. );
  1325. //
  1326. // UNC Provider support
  1327. //
  1328. NTKERNELAPI
  1329. NTSTATUS
  1330. FsRtlRegisterUncProvider(
  1331. IN OUT PHANDLE MupHandle,
  1332. IN PUNICODE_STRING RedirectorDeviceName,
  1333. IN BOOLEAN MailslotsSupported
  1334. );
  1335. NTKERNELAPI
  1336. VOID
  1337. FsRtlDeregisterUncProvider(
  1338. IN HANDLE Handle
  1339. );
  1340. // end_ntifs
  1341. // begin_ntifs
  1342. //
  1343. // File System Filter PerStream Context Support
  1344. //
  1345. //
  1346. // Filesystem filter drivers use these APIs to associate context
  1347. // with open streams (for filesystems that support this).
  1348. //
  1349. //
  1350. // OwnerId should uniquely identify a particular filter driver
  1351. // (e.g. the address of the driver's device object).
  1352. // InstanceId can be used to distinguish distinct contexts associated
  1353. // by a filter driver with a single stream (e.g. the address of the
  1354. // PerStream Context structure).
  1355. //
  1356. //
  1357. // This structure needs to be embedded within the users context that
  1358. // they want to associate with a given stream
  1359. //
  1360. typedef struct _FSRTL_PER_STREAM_CONTEXT {
  1361. //
  1362. // This is linked into the StreamContext list inside the
  1363. // FSRTL_ADVANCED_FCB_HEADER structure.
  1364. //
  1365. LIST_ENTRY Links;
  1366. //
  1367. // A Unique ID for this filter (ex: address of Driver Object, Device
  1368. // Object, or Device Extension)
  1369. //
  1370. PVOID OwnerId;
  1371. //
  1372. // An optional ID to differentiate different contexts for the same
  1373. // filter.
  1374. //
  1375. PVOID InstanceId;
  1376. //
  1377. // A callback routine which is called by the underlying file system
  1378. // when the stream is being torn down. When this routine is called
  1379. // the given context has already been removed from the context linked
  1380. // list. The callback routine cannot recursively call down into the
  1381. // filesystem or acquire any of their resources which they might hold
  1382. // when calling the filesystem outside of the callback. This must
  1383. // be defined.
  1384. //
  1385. PFREE_FUNCTION FreeCallback;
  1386. } FSRTL_PER_STREAM_CONTEXT, *PFSRTL_PER_STREAM_CONTEXT;
  1387. //
  1388. // This will initialize the given FSRTL_PER_STREAM_CONTEXT structure. This
  1389. // should be used before calling "FsRtlInsertPerStreamContext".
  1390. //
  1391. #define FsRtlInitPerStreamContext( _fc, _owner, _inst, _cb) \
  1392. ((_fc)->OwnerId = (_owner), \
  1393. (_fc)->InstanceId = (_inst), \
  1394. (_fc)->FreeCallback = (_cb))
  1395. //
  1396. // Given a FileObject this will return the StreamContext pointer that
  1397. // needs to be passed into the other FsRtl PerStream Context routines.
  1398. //
  1399. #define FsRtlGetPerStreamContextPointer(_fo) \
  1400. ((PFSRTL_ADVANCED_FCB_HEADER)((_fo)->FsContext))
  1401. //
  1402. // This will test to see if PerStream contexts are supported for the given
  1403. // FileObject
  1404. //
  1405. #define FsRtlSupportsPerStreamContexts(_fo) \
  1406. ((NULL != FsRtlGetPerStreamContextPointer(_fo)) && \
  1407. FlagOn(FsRtlGetPerStreamContextPointer(_fo)->Flags2, \
  1408. FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS))
  1409. //
  1410. // Associate the context at Ptr with the given stream. The Ptr structure
  1411. // should be filled in by the caller before calling this routine (see
  1412. // FsRtlInitPerStreamContext). If the underlying filesystem does not support
  1413. // filter contexts, STATUS_INVALID_DEVICE_REQUEST will be returned.
  1414. //
  1415. NTKERNELAPI
  1416. NTSTATUS
  1417. FsRtlInsertPerStreamContext (
  1418. IN PFSRTL_ADVANCED_FCB_HEADER PerStreamContext,
  1419. IN PFSRTL_PER_STREAM_CONTEXT Ptr
  1420. );
  1421. //
  1422. // Lookup a filter context associated with the stream specified. The first
  1423. // context matching OwnerId (and InstanceId, if present) is returned. By not
  1424. // specifying InstanceId, a filter driver can search for any context that it
  1425. // has previously associated with a stream. If no matching context is found,
  1426. // NULL is returned. If the file system does not support filter contexts,
  1427. // NULL is returned.
  1428. //
  1429. NTKERNELAPI
  1430. PFSRTL_PER_STREAM_CONTEXT
  1431. FsRtlLookupPerStreamContextInternal (
  1432. IN PFSRTL_ADVANCED_FCB_HEADER StreamContext,
  1433. IN PVOID OwnerId OPTIONAL,
  1434. IN PVOID InstanceId OPTIONAL
  1435. );
  1436. #define FsRtlLookupPerStreamContext(_sc, _oid, _iid) \
  1437. (((NULL != (_sc)) && \
  1438. FlagOn((_sc)->Flags2,FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS) && \
  1439. !IsListEmpty(&(_sc)->FilterContexts)) ? \
  1440. FsRtlLookupPerStreamContextInternal((_sc), (_oid), (_iid)) : \
  1441. NULL)
  1442. //
  1443. // Normally, contexts should be deleted when the file system notifies the
  1444. // filter that the stream is being closed. There are cases when a filter
  1445. // may want to remove all existing contexts for a specific volume. This
  1446. // routine should be called at those times. This routine should NOT be
  1447. // called for the following cases:
  1448. // - Inside your FreeCallback handler - The underlying file system has
  1449. // already removed it from the linked list).
  1450. // - Inside your IRP_CLOSE handler - If you do this then you will not
  1451. // be notified when the stream is torn down.
  1452. //
  1453. // This functions identically to FsRtlLookupPerStreamContext, except that the
  1454. // returned context has been removed from the list.
  1455. //
  1456. NTKERNELAPI
  1457. PFSRTL_PER_STREAM_CONTEXT
  1458. FsRtlRemovePerStreamContext (
  1459. IN PFSRTL_ADVANCED_FCB_HEADER StreamContext,
  1460. IN PVOID OwnerId OPTIONAL,
  1461. IN PVOID InstanceId OPTIONAL
  1462. );
  1463. //
  1464. // APIs for file systems to use for initializing and cleaning up
  1465. // the Advaned FCB Header fields for PerStreamContext support
  1466. //
  1467. //
  1468. // This will properly initialize the advanced header so that it can be
  1469. // used with PerStream contexts.
  1470. // Note: A fast mutex must be placed in an advanced header. It is the
  1471. // caller's responsibility to properly create and initialize this
  1472. // mutex before calling this macro. The mutex field is only set
  1473. // if a non-NULL value is passed in.
  1474. //
  1475. #define FsRtlSetupAdvancedHeader( _advhdr, _fmutx ) \
  1476. { \
  1477. SetFlag( (_advhdr)->Flags, FSRTL_FLAG_ADVANCED_HEADER ); \
  1478. SetFlag( (_advhdr)->Flags2, FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS ); \
  1479. InitializeListHead( &(_advhdr)->FilterContexts ); \
  1480. if ((_fmutx) != NULL) { \
  1481. (_advhdr)->FastMutex = (_fmutx); \
  1482. } \
  1483. }
  1484. //
  1485. // File systems call this API to free any filter contexts still associated
  1486. // with an FSRTL_COMMON_FCB_HEADER that they are tearing down.
  1487. // The FreeCallback routine for each filter context will be called.
  1488. //
  1489. NTKERNELAPI
  1490. VOID
  1491. FsRtlTeardownPerStreamContexts (
  1492. IN PFSRTL_ADVANCED_FCB_HEADER AdvancedHeader
  1493. );
  1494. // end_ntifs
  1495. //
  1496. // File System Filter PerFileObject Context Support
  1497. //
  1498. //
  1499. // Filesystem filter drivers use these APIs to associate context
  1500. // with individual open files. For now these are only supported on file
  1501. // objects with a FileObject extension which are only created by using
  1502. // IoCreateFileSpecifyDeviceObjectHint.
  1503. //
  1504. //
  1505. // OwnerId should uniquely identify a particular filter driver
  1506. // (e.g. the address of the driver's device object).
  1507. // InstanceId can be used to distinguish distinct contexts associated
  1508. // by a filter driver with a single stream (e.g. the address of the
  1509. // fileobject).
  1510. //
  1511. //
  1512. // This structure needs to be embedded within the users context that
  1513. // they want to associate with a given stream
  1514. //
  1515. typedef struct _FSRTL_PER_FILEOBJECT_CONTEXT {
  1516. //
  1517. // This is linked into the File Object
  1518. //
  1519. LIST_ENTRY Links;
  1520. //
  1521. // A Unique ID for this filter (ex: address of Driver Object, Device
  1522. // Object, or Device Extension)
  1523. //
  1524. PVOID OwnerId;
  1525. //
  1526. // An optional ID to differentiate different contexts for the same
  1527. // filter.
  1528. //
  1529. PVOID InstanceId;
  1530. } FSRTL_PER_FILEOBJECT_CONTEXT, *PFSRTL_PER_FILEOBJECT_CONTEXT;
  1531. //
  1532. // This will initialize the given FSRTL_PER_FILEOBJECT_CONTEXT structure. This
  1533. // should be used before calling "FsRtlInsertPerFileObjectContext".
  1534. //
  1535. #define FsRtlInitPerFileObjectContext( _fc, _owner, _inst ) \
  1536. ((_fc)->OwnerId = (_owner), \
  1537. (_fc)->InstanceId = (_inst)) \
  1538. //
  1539. // This will test to see if PerFileObject contexts are supported for the given
  1540. // FileObject
  1541. //
  1542. #define FsRtlSupportsPerFileObjectContexts(_fo) \
  1543. FlagOn((_fo)->Flags,FO_FILE_OBJECT_HAS_EXTENSION)
  1544. //
  1545. // Associate the context at Ptr with the given FileObject. The Ptr
  1546. // structure should be filled in by the caller before calling this
  1547. // routine (see FsRtlInitPerFileObjectContext). If this file object does not
  1548. // support filter contexts, STATUS_INVALID_DEVICE_REQUEST will be returned.
  1549. //
  1550. NTKERNELAPI
  1551. NTSTATUS
  1552. FsRtlInsertPerFileObjectContext (
  1553. IN PFILE_OBJECT FileObject,
  1554. IN PFSRTL_PER_FILEOBJECT_CONTEXT Ptr
  1555. );
  1556. //
  1557. // Lookup a filter context associated with the FileObject specified. The first
  1558. // context matching OwnerId (and InstanceId, if present) is returned. By not
  1559. // specifying InstanceId, a filter driver can search for any context that it
  1560. // has previously associated with a stream. If no matching context is found,
  1561. // NULL is returned. If the FileObject does not support contexts,
  1562. // NULL is returned.
  1563. //
  1564. NTKERNELAPI
  1565. PFSRTL_PER_FILEOBJECT_CONTEXT
  1566. FsRtlLookupPerFileObjectContext (
  1567. IN PFILE_OBJECT FileObject,
  1568. IN PVOID OwnerId OPTIONAL,
  1569. IN PVOID InstanceId OPTIONAL
  1570. );
  1571. //
  1572. // Normally, contexts should be deleted when the IoManager notifies the
  1573. // filter that the FileObject is being freed. There are cases when a filter
  1574. // may want to remove all existing contexts for a specific volume. This
  1575. // routine should be called at those times. This routine should NOT be
  1576. // called for the following case:
  1577. // - Inside your FreeCallback handler - The IoManager has already removed
  1578. // it from the linked list.
  1579. //
  1580. // This functions identically to FsRtlLookupPerFileObjectContext, except that
  1581. // the returned context has been removed from the list.
  1582. //
  1583. NTKERNELAPI
  1584. PFSRTL_PER_FILEOBJECT_CONTEXT
  1585. FsRtlRemovePerFileObjectContext (
  1586. IN PFILE_OBJECT FileObject,
  1587. IN PVOID OwnerId OPTIONAL,
  1588. IN PVOID InstanceId OPTIONAL
  1589. );
  1590. //
  1591. // Internal routine to free the context control structure
  1592. //
  1593. VOID
  1594. FsRtlPTeardownPerFileObjectContexts (
  1595. IN PFILE_OBJECT FileObject
  1596. );
  1597. // begin_ntifs
  1598. //++
  1599. //
  1600. // VOID
  1601. // FsRtlCompleteRequest (
  1602. // IN PIRP Irp,
  1603. // IN NTSTATUS Status
  1604. // );
  1605. //
  1606. // Routine Description:
  1607. //
  1608. // This routine is used to complete an IRP with the indicated
  1609. // status. It does the necessary raise and lower of IRQL.
  1610. //
  1611. // Arguments:
  1612. //
  1613. // Irp - Supplies a pointer to the Irp to complete
  1614. //
  1615. // Status - Supplies the completion status for the Irp
  1616. //
  1617. // Return Value:
  1618. //
  1619. // None.
  1620. //
  1621. //--
  1622. #define FsRtlCompleteRequest(IRP,STATUS) { \
  1623. (IRP)->IoStatus.Status = (STATUS); \
  1624. IoCompleteRequest( (IRP), IO_DISK_INCREMENT ); \
  1625. }
  1626. //++
  1627. //
  1628. // VOID
  1629. // FsRtlEnterFileSystem (
  1630. // );
  1631. //
  1632. // Routine Description:
  1633. //
  1634. // This routine is used when entering a file system (e.g., through its
  1635. // Fsd entry point). It ensures that the file system cannot be suspended
  1636. // while running and thus block other file I/O requests. Upon exit
  1637. // the file system must call FsRtlExitFileSystem.
  1638. //
  1639. // Arguments:
  1640. //
  1641. // Return Value:
  1642. //
  1643. // None.
  1644. //
  1645. //--
  1646. #define FsRtlEnterFileSystem() { \
  1647. KeEnterCriticalRegion(); \
  1648. }
  1649. //++
  1650. //
  1651. // VOID
  1652. // FsRtlExitFileSystem (
  1653. // );
  1654. //
  1655. // Routine Description:
  1656. //
  1657. // This routine is used when exiting a file system (e.g., through its
  1658. // Fsd entry point).
  1659. //
  1660. // Arguments:
  1661. //
  1662. // Return Value:
  1663. //
  1664. // None.
  1665. //
  1666. //--
  1667. #define FsRtlExitFileSystem() { \
  1668. KeLeaveCriticalRegion(); \
  1669. }
  1670. VOID
  1671. FsRtlIncrementCcFastReadNotPossible( VOID );
  1672. VOID
  1673. FsRtlIncrementCcFastReadWait( VOID );
  1674. VOID
  1675. FsRtlIncrementCcFastReadNoWait( VOID );
  1676. VOID
  1677. FsRtlIncrementCcFastReadResourceMiss( VOID );
  1678. //
  1679. // Returns TRUE if the given fileObject represents a paging file, returns
  1680. // FALSE otherwise.
  1681. //
  1682. LOGICAL
  1683. FsRtlIsPagingFile (
  1684. IN PFILE_OBJECT FileObject
  1685. );
  1686. // end_ntifs
  1687. #endif // _FSRTL_