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.

1629 lines
43 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. NtfsExp.h
  5. Abstract:
  6. This module defines the exports from NtOfs.SYS for use exclusively by
  7. Transactions and Encryption.
  8. *********************************
  9. *No other clients are supported.*
  10. *********************************
  11. Author:
  12. Mark Zbikowski [MarkZ] 7-Dec-1995
  13. Jeff Havens [JHavens]
  14. Brian Andrew [BrianAn]
  15. Gary Kimura [GaryKi]
  16. Tom Miller [TomM]
  17. Revision History:
  18. --*/
  19. #ifndef _NTFS_
  20. //
  21. // The MFT Segment Reference is an address in the MFT tagged with
  22. // a circularly reused sequence number set at the time that the MFT
  23. // Segment Reference was valid. Note that this format limits the
  24. // size of the Master File Table to 2**48 segments. So, for
  25. // example, with a 1KB segment size the maximum size of the master
  26. // file would be 2**58 bytes, or 2**28 gigabytes.
  27. //
  28. typedef struct _FILE_REFERENCE {
  29. //
  30. // First a 48 bit segment number.
  31. //
  32. ULONG SegmentNumberLowPart; // offset = 0x000
  33. USHORT SegmentNumberHighPart; // offset = 0x004
  34. //
  35. // Now a 16 bit nonzero sequence number. A value of 0 is
  36. // reserved to allow the possibility of a routine accepting
  37. // 0 as a sign that the sequence number check should be
  38. // repressed.
  39. //
  40. USHORT SequenceNumber; // offset = 0x006
  41. } FILE_REFERENCE, *PFILE_REFERENCE; // sizeof = 0x008
  42. #endif
  43. //
  44. // Big picture view of the interaction between extensions and NtOfs:
  45. //
  46. // NtOfs exports a number of interfaces that give abstract access to
  47. // on-disk structures and attempt to hide, as much as possible, the
  48. // implementation details.
  49. //
  50. // V/Q/X are implemented as DLL's that link to NtOfs.Sys. NtOfs can load
  51. // and function in absence of these DLL's.
  52. //
  53. // All communication between user-mode code and V/Q/X occurs via the
  54. // Nt Io API which is routed through NtOfs. Client code will open either
  55. // an NtOfs Volume, Directory, or File and will issue NtIo calls to the
  56. // resultant handle.
  57. //
  58. // NtOfs will create an IrpContext, decode the file object appropriately,
  59. // and call out to entry points in V/Q/X that are registered at load-time.
  60. //
  61. // V/Q/X will perform whatever actions are necessary utilizing NtOfs exports
  62. // and then return from the original call from NtOfs an NTSTATUS code. NtOfs
  63. // will perform the appropriate CompleteIrp calls, posting for STATUS_PENDING,
  64. // etc.
  65. //
  66. // No exceptions can be raised across the NtOfs export or NtOfs import
  67. // interfaces. All user-buffer access and validation will occur in the
  68. // code that uses it. Since user buffers may disappear at any time, any
  69. // client of these buffers must wrap access to the buffers in an exception
  70. // clause.
  71. //
  72. // V/Q/X may perform activities in threads separate from the original
  73. // requestor. For these cases, NtOfs will provide a means where calls separate
  74. // from a user-mode request can be accepted. Typically, this means "cloning"
  75. // an IrpContext.
  76. //
  77. //
  78. // Opaque handle definitions.
  79. //
  80. //
  81. // ISSUE: Most NtOfs internal routines rely on having an IrpContext passed in
  82. // along with FCB and SCB pointers. Rather than exposing FCB and IrpContext
  83. // as separate contexts, should we wrap these up into a separate structure and
  84. // pass it along?
  85. //
  86. typedef struct _FCB *OBJECT_HANDLE;
  87. typedef struct _SCB *ATTRIBUTE_HANDLE;
  88. typedef struct _SCB *INDEX_HANDLE;
  89. typedef struct _READ_CONTEXT *PREAD_CONTEXT;
  90. typedef ULONG SECURITY_ID;
  91. typedef struct _CI_CALL_BACK CI_CALL_BACK, *PCI_CALL_BACK;
  92. typedef struct _VIEW_CALL_BACK VIEW_CALL_BACK, *PVIEW_CALL_BACK;
  93. typedef struct _IRP_CONTEXT *PIRP_CONTEXT;
  94. //
  95. // Map Handle. This structure defines a byte range of the file which is mapped
  96. // or pinned, and stores the Bcb returned from the Cache Manager.
  97. //
  98. typedef struct _MAP_HANDLE {
  99. //
  100. // Range being mapped or pinned
  101. //
  102. LONGLONG FileOffset;
  103. ULONG Length;
  104. //
  105. // Virtual address corresponding to FileOffset
  106. //
  107. PVOID Buffer;
  108. //
  109. // Bcb pointer returned from Cache Manager
  110. //
  111. PVOID Bcb;
  112. } MAP_HANDLE, *PMAP_HANDLE;
  113. //
  114. // Quick Index Hint. This is stream offset information returned by
  115. // NtOfsFindRecord, and taken as input to NtOfsUpdateRecord, to allow
  116. // quick updates to index records in the event that they have not
  117. // moved. This structure must always have the same size and alignment
  118. // as QUICK_INDEX in ntfsstru.h.
  119. //
  120. typedef struct _QUICK_INDEX_HINT {
  121. LONGLONG HintData[3];
  122. } QUICK_INDEX_HINT, *PQUICK_INDEX_HINT;
  123. //
  124. // Index structures
  125. //
  126. typedef struct {
  127. ULONG KeyLength;
  128. PVOID Key;
  129. } INDEX_KEY, *PINDEX_KEY;
  130. typedef struct {
  131. ULONG DataLength;
  132. PVOID Data;
  133. } INDEX_DATA, *PINDEX_DATA;
  134. typedef struct {
  135. INDEX_KEY KeyPart;
  136. INDEX_DATA DataPart;
  137. } INDEX_ROW, *PINDEX_ROW;
  138. //
  139. // COLLATION_FUNCTION returns LessThan if Key1 precedes Key2
  140. // EqualTo if Key1 is identical to Key2
  141. // GreaterThan if Key1 follows Key2
  142. //
  143. typedef FSRTL_COMPARISON_RESULT (*PCOLLATION_FUNCTION) (
  144. IN PINDEX_KEY Key1,
  145. IN PINDEX_KEY Key2,
  146. IN PVOID CollationData
  147. );
  148. typedef struct _UPCASE_TABLE_AND_KEY {
  149. //
  150. // Pointer to a table of upcased unicode characters indexed by character to
  151. // be upcased.
  152. //
  153. PWCH UpcaseTable;
  154. //
  155. // Size of UpcaseTable in unicode characters
  156. //
  157. ULONG UpcaseTableSize;
  158. //
  159. // Optional addtional pointer.
  160. //
  161. INDEX_KEY Key;
  162. } UPCASE_TABLE_AND_KEY, *PUPCASE_TABLE_AND_KEY;
  163. //
  164. // Wait for new length block used to synchronize a thread with FileSize
  165. // exceeding the specified Length.
  166. //
  167. typedef struct _WAIT_FOR_NEW_LENGTH {
  168. //
  169. // Link words for multiple waiters on the Scb.
  170. //
  171. LIST_ENTRY WaitList;
  172. //
  173. // Set event when FileSize exceeds this length.
  174. //
  175. LONGLONG Length;
  176. //
  177. // Event to set when new length achieved.
  178. //
  179. KEVENT Event;
  180. //
  181. // Irp to complete when new length achieved. (If Irp present, Event is
  182. // ignored.)
  183. //
  184. PIRP Irp;
  185. //
  186. // Stream we are waiting on.
  187. //
  188. ATTRIBUTE_HANDLE Stream;
  189. //
  190. // Status code for operation that caused the new length to be satisfied.
  191. // It may be STATUS_CANCELLED, STATUS_TIMEOUT or STATUS_SUCCESS
  192. // or a request specific status.
  193. //
  194. NTSTATUS Status;
  195. //
  196. // Flags.
  197. //
  198. ULONG Flags;
  199. } WAIT_FOR_NEW_LENGTH, *PWAIT_FOR_NEW_LENGTH;
  200. #define NTFS_WAIT_FLAG_ASYNC (0x00000001)
  201. //
  202. // Standard collation functions for simple indices
  203. //
  204. FSRTL_COMPARISON_RESULT
  205. NtOfsCollateUlong ( // Both must be single Ulong
  206. IN PINDEX_KEY Key1,
  207. IN PINDEX_KEY Key2,
  208. IN PVOID CollationData // Don't care, may be NULL
  209. );
  210. FSRTL_COMPARISON_RESULT
  211. NtOfsCollateUlongs ( // Lengths do not have to be equal
  212. IN PINDEX_KEY Key1,
  213. IN PINDEX_KEY Key2,
  214. IN PVOID CollationData // Don't care, may be NULL
  215. );
  216. FSRTL_COMPARISON_RESULT
  217. NtOfsCollateSid (
  218. IN PINDEX_KEY Key1,
  219. IN PINDEX_KEY Key2,
  220. IN PVOID CollationData // Don't care, may be NULL
  221. );
  222. FSRTL_COMPARISON_RESULT
  223. NtOfsCollateUnicode (
  224. IN PINDEX_KEY Key1,
  225. IN PINDEX_KEY Key2,
  226. IN PVOID CollationData // PUPCASE_TABLE_AND_KEY (with no key)
  227. );
  228. //
  229. // Standard match functions for simple indices
  230. //
  231. NTSTATUS
  232. NtOfsMatchAll (
  233. IN PINDEX_ROW IndexRow,
  234. IN OUT PVOID MatchData // Don't care, may be NULL
  235. );
  236. NTSTATUS
  237. NtOfsMatchUlongExact (
  238. IN PINDEX_ROW IndexRow, // Both must be single Ulong
  239. IN OUT PVOID MatchData // PINDEX_KEY describing Ulong
  240. );
  241. NTSTATUS
  242. NtOfsMatchUlongsExact ( // Lengths do not have to be equal
  243. IN PINDEX_ROW IndexRow,
  244. IN OUT PVOID MatchData // PINDEX_KEY describing Ulongs
  245. );
  246. NTSTATUS
  247. NtOfsMatchUnicodeExpression (
  248. IN PINDEX_ROW IndexRow,
  249. IN OUT PVOID MatchData // PUPCASE_TABLE_AND_KEY with Uni expression (must have wildcards)
  250. );
  251. NTSTATUS
  252. NtOfsMatchUnicodeString (
  253. IN PINDEX_ROW IndexRow,
  254. IN OUT PVOID MatchData // PUPCASE_TABLE_AND_KEY with Uni string (no wildcards)
  255. );
  256. //
  257. // MATCH_FUNCTION returns
  258. // STATUS_SUCCESS if the IndexRow matches
  259. // STATUS_NO_MATCH if the IndexRow does not match, but the enumeration should
  260. // continue
  261. // STATUS_NO_MORE_MATCHES if the IndexRow does not match, and the enumeration
  262. // should terminate
  263. //
  264. typedef NTSTATUS (*PMATCH_FUNCTION) (IN PINDEX_ROW IndexRow, IN OUT PVOID MatchData);
  265. //
  266. // CREATE_OPTIONS - common flags governing creation/opening of objects
  267. //
  268. typedef enum _CREATE_OPTIONS
  269. {
  270. CREATE_NEW = 0,
  271. CREATE_OR_OPEN = 1,
  272. OPEN_EXISTING = 2
  273. } CREATE_OPTIONS;
  274. //
  275. // EXCLUSION - Form of exclusion desired when opening an object
  276. //
  277. typedef enum _EXCLUSION
  278. {
  279. SHARED = 0,
  280. EXCLUSIVE
  281. } EXCLUSION;
  282. //
  283. // Additional Dos Attribute indicating Content Index status of an object.
  284. // If this is set on a document, it suppresses indexing. It is inherited
  285. // from a parent directory at create time. This is stored in the
  286. // DUPLICATED_INFORMATION structure.
  287. //
  288. #define SUPPRESS_CONTENT_INDEX (0x20000000)
  289. //
  290. // Define the size of the index buffer/bucket for view indexes, in bytes.
  291. //
  292. #define NTOFS_VIEW_INDEX_BUFFER_SIZE (0x1000)
  293. //
  294. // Exported constants.
  295. //
  296. //
  297. // NtOfsContentIndexSystemFile is the repository for all CI related data on the
  298. // disk.
  299. extern FILE_REFERENCE NtOfsContentIndexSystemFile;
  300. #if defined(_NTFSPROC_)
  301. #define NTFSAPI
  302. #else
  303. #define NTFSAPI //DECLSPEC_IMPORT
  304. #endif
  305. ////////////////////////////////////////////////////////////////////////////////
  306. //
  307. // Index API - These encapsulate the NtOfs BTree mechanisms.
  308. //
  309. //
  310. // NtOfsCreateIndex creates or opens a named index attribute in an object. The
  311. // ObjectHandle has been acquired exclusive and the returned handle is not
  312. // acquired. The collation data is interpreted only by the CollationFunction.
  313. //
  314. // IndexHandles retain a "seek" position where enumerations (NtOfsReadRecords)
  315. // may continue. This seek position may be updated by the routines as described
  316. // below.
  317. //
  318. // If DeleteCollationData is 1, ExFreePool will be called on CollationData, either
  319. // immediately if the index already exists, or when the index is deleted some time
  320. // after the final close. If NtOfsCreateIndex returns an error, then CollationData
  321. // must be deleted by the caller. If specified as 0, then ColloationData will not
  322. // be deleted.
  323. //
  324. NTFSAPI
  325. NTSTATUS
  326. NtOfsCreateIndex (
  327. IN PIRP_CONTEXT IrpContext,
  328. IN OBJECT_HANDLE ObjectHandle,
  329. IN UNICODE_STRING Name,
  330. IN CREATE_OPTIONS CreateOptions,
  331. IN ULONG DeleteCollationData,
  332. IN ULONG CollationRule,
  333. IN PCOLLATION_FUNCTION CollationFunction,
  334. IN PVOID CollationData OPTIONAL,
  335. OUT INDEX_HANDLE *IndexHandle
  336. );
  337. //
  338. // NtOfsFindRecord finds a single record in an index stream for read-only access
  339. // or in preparation for calling NtOfsUpdateRecord.
  340. //
  341. NTFSAPI
  342. NTSTATUS
  343. NtOfsFindRecord (
  344. IN PIRP_CONTEXT IrpContext,
  345. IN INDEX_HANDLE IndexHandle,
  346. IN PINDEX_KEY IndexKey,
  347. OUT PINDEX_ROW IndexRow,
  348. OUT PMAP_HANDLE MapHandle,
  349. IN OUT PQUICK_INDEX_HINT QuickIndexHint OPTIONAL
  350. );
  351. //
  352. // NtOfsFindRecord finds a single record in an index stream for read-only access
  353. // or in preparation for calling NtOfsUpdateRecord.
  354. //
  355. NTFSAPI
  356. NTSTATUS
  357. NtOfsFindLastRecord (
  358. IN PIRP_CONTEXT IrpContext,
  359. IN INDEX_HANDLE IndexHandle,
  360. IN PINDEX_KEY MaxIndexKey,
  361. OUT PINDEX_ROW IndexRow,
  362. OUT PMAP_HANDLE MapHandle
  363. );
  364. //
  365. // NtOfsAddRecords performs bulk, logged inserts into an index. The index will
  366. // be acquired exclusive for this call. Each record added must have a unique
  367. // (with regards to the collation function) key. No maps are currently
  368. // outstanding on this index. If SequentialInsertMode is nonzero, this is a hint
  369. // to the index package to keep all BTree buffers as full as possible, by splitting
  370. // as close to the end of the buffer as possible. If specified as zero, random
  371. // inserts are assumed, and buffers are always split in the middle for better balance.
  372. //
  373. // This call may update the IndexHandle seek position
  374. //
  375. NTFSAPI
  376. VOID
  377. NtOfsAddRecords (
  378. IN PIRP_CONTEXT IrpContext,
  379. IN INDEX_HANDLE IndexHandle,
  380. IN ULONG Count,
  381. IN PINDEX_ROW IndexRow,
  382. IN ULONG SequentialInsertMode
  383. );
  384. //
  385. // NtOfsDeleteRecords performs bulk, logged deletion from an index. The index
  386. // will be acquired exclusive for this call. No maps are currently outstanding
  387. // on this index.
  388. //
  389. // This call may update the IndexHandle seek position
  390. //
  391. NTFSAPI
  392. VOID
  393. NtOfsDeleteRecords (
  394. IN PIRP_CONTEXT IrpContext,
  395. IN INDEX_HANDLE IndexHandle,
  396. IN ULONG Count,
  397. IN PINDEX_KEY IndexKey
  398. );
  399. //
  400. // NtOfsReadRecords applies a match function to a block of contiguous records in
  401. // the BTree starting either at a given IndexKey or beginning where it last left
  402. // off.
  403. //
  404. // IndexKey is an optional point at which to begin the enumeration. The
  405. // seek position of IndexHandle is set to return the next logical record
  406. // on the next NtOfsReadRecords call.
  407. //
  408. // NtOfsReadRecords will seek to the appropriate point in the BTree (as defined
  409. // by the IndexKey or saved position and the CollateFunction) and begin calling
  410. // MatchFunction for each record. It continues doing this while MatchFunction
  411. // returns STATUS_SUCCESS. If MatchFunction returns STATUS_NO_MORE_MATCHES,
  412. // NtOfsReadRecords will cache this result and not call MatchFunction again until
  413. // called with a non-NULL IndexKey.
  414. //
  415. // NtOfsReadRecords returns the last status code returned by MatchFunction.
  416. //
  417. // The IndexHandle does not have to be acquired as it is acquired shared for the
  418. // duration of the call. NtOfsReadRecords may
  419. // return with STATUS_SUCCESS without filling the output buffer (say, every 10
  420. // index pages) to reduce lock contention.
  421. //
  422. // NtOfsReadRecords will read up to Count rows, comprising up to BufferLength
  423. // bytes in total and will fill in the Rows[] array for each row returned.
  424. //
  425. // Note that this call is self-synchronized, such that successive calls to
  426. // the routine are guaranteed to make progress through the index and to return
  427. // items in Collation order, in spite of Add and Delete record calls being
  428. // interspersed with Read records calls.
  429. //
  430. NTFSAPI
  431. NTSTATUS
  432. NtOfsReadRecords (
  433. IN PIRP_CONTEXT IrpContext,
  434. IN INDEX_HANDLE IndexHandle,
  435. IN OUT PREAD_CONTEXT *ReadContext,
  436. IN OPTIONAL PINDEX_KEY IndexKey,
  437. IN PMATCH_FUNCTION MatchFunction,
  438. IN PVOID MatchData,
  439. IN OUT ULONG *Count,
  440. OUT PINDEX_ROW Rows,
  441. IN ULONG BufferLength,
  442. OUT PVOID Buffer
  443. );
  444. NTFSAPI
  445. VOID
  446. NtOfsFreeReadContext (
  447. IN PREAD_CONTEXT ReadContext
  448. );
  449. //
  450. // NtOfsUpdateRecord updates a single record in place. It is guaranteed that the
  451. // length of the data/key portion of the record does not change. The index will
  452. // be acquired exclusive for this call.
  453. //
  454. // This call may update the IndexHandle seek position
  455. //
  456. NTFSAPI
  457. VOID
  458. NtOfsUpdateRecord (
  459. IN PIRP_CONTEXT IrpContext,
  460. IN INDEX_HANDLE IndexHandle,
  461. IN ULONG Count,
  462. IN PINDEX_ROW IndexRow,
  463. IN OUT PQUICK_INDEX_HINT QuickIndexHint OPTIONAL,
  464. IN OUT PMAP_HANDLE MapHandle OPTIONAL
  465. );
  466. //
  467. // NtOfsCloseIndex closes an index handle. The index must not be acquired for this
  468. // call. No outstanding maps are allowed.
  469. //
  470. NTFSAPI
  471. VOID
  472. NtOfsCloseIndex (
  473. IN PIRP_CONTEXT IrpContext,
  474. IN INDEX_HANDLE IndexHandle
  475. );
  476. //
  477. // NtOfsDeleteIndex removes an index attribute from an object. The object will be
  478. // acquired exclusive for this call.
  479. //
  480. NTFSAPI
  481. VOID
  482. NtOfsDeleteIndex (
  483. IN PIRP_CONTEXT IrpContext,
  484. IN OBJECT_HANDLE ObjectHandle,
  485. IN INDEX_HANDLE IndexHandle
  486. );
  487. ////////////////////////////////////////////////////////////////////////////////
  488. //
  489. // Map API - These encapsulate the NtOfs/Cache manager interactions
  490. //
  491. //
  492. // NtOfsInitializeMapHandle initializes a map handle so it can be safely
  493. // released at any time.
  494. //
  495. // NTFSAPI
  496. // VOID
  497. // NtOfsInitializeMapHandle (
  498. // IN PMAP_HANDLE Map
  499. // );
  500. //
  501. #define NtOfsInitializeMapHandle( M ) { (M)->Bcb = NULL; }
  502. //
  503. // NtOfsMapAttribute maps a portion of the specified attribute and returns a pointer
  504. // to the memory. The memory mapped may not span a mapping window. Multiple maps
  505. // are allowed through different handles in different threads. The data is not
  506. // preread nor is the memory pinned.
  507. //
  508. #ifndef _NTFSPROC_
  509. NTFSAPI
  510. VOID
  511. NtOfsMapAttribute (
  512. IN PIRP_CONTEXT IrpContext,
  513. IN ATTRIBUTE_HANDLE Attribute,
  514. IN LONGLONG Offset,
  515. IN ULONG Length,
  516. OUT PVOID *Buffer,
  517. OUT PMAP_HANDLE MapHandle
  518. );
  519. #else
  520. #ifdef MAPCOUNT_DBG
  521. #define NtOfsMapAttribute(I,S,O,L,B,M) ( \
  522. CcMapData((S)->FileObject, (PLARGE_INTEGER)&(O), (L), TRUE, &(M)->Bcb, (B)), \
  523. (I)->MapCount++, \
  524. (M)->FileOffset = (O), \
  525. (M)->Length = (L), \
  526. (M)->Buffer = *(PVOID *)(B) \
  527. )
  528. #else
  529. #define NtOfsMapAttribute(I,S,O,L,B,M) ( \
  530. CcMapData((S)->FileObject, (PLARGE_INTEGER)&(O), (L), TRUE, &(M)->Bcb, (B)), \
  531. (M)->FileOffset = (O), \
  532. (M)->Length = (L), \
  533. (M)->Buffer = *(PVOID *)(B) \
  534. )
  535. #endif
  536. #endif
  537. //
  538. // NtOfsPreparePinWrite maps and pins a portion of the specified attribute and
  539. // returns a pointer to the memory. This is equivalent to doing a NtOfsMapAttribute
  540. // followed by NtOfsPinRead and NtOfsDirty but is more efficient.
  541. //
  542. #ifndef _NTFSPROC_
  543. NTFSAPI
  544. VOID
  545. NtOfsPreparePinWrite (
  546. IN PIRP_CONTEXT IrpContext,
  547. IN ATTRIBUTE_HANDLE Attribute,
  548. IN LONGLONG Offset,
  549. IN ULONG Length,
  550. OUT PVOID *Buffer,
  551. OUT PMAP_HANDLE MapHandle
  552. );
  553. #else
  554. #ifdef MAPCOUNT_DBG
  555. #define NtOfsPreparePinWrite(I,S,O,L,B,M) { \
  556. if (((O) + (L)) > (S)->Header.AllocationSize.QuadPart) { \
  557. ExRaiseStatus(STATUS_END_OF_FILE); \
  558. } \
  559. CcPreparePinWrite((S)->FileObject, (PLARGE_INTEGER)&(O), (L), FALSE, TRUE, &(M)->Bcb, (B)); \
  560. (I)->MapCount++; \
  561. (M)->FileOffset = (O); \
  562. (M)->Length = (L); \
  563. (M)->Buffer = (B); \
  564. }
  565. #else
  566. #define NtOfsPreparePinWrite(I,S,O,L,B,M) { \
  567. if (((O) + (L)) > (S)->Header.AllocationSize.QuadPart) { \
  568. ExRaiseStatus(STATUS_END_OF_FILE); \
  569. } \
  570. CcPreparePinWrite((S)->FileObject, (PLARGE_INTEGER)&(O), (L), FALSE, TRUE, &(M)->Bcb, (B)); \
  571. (M)->FileOffset = (O); \
  572. (M)->Length = (L); \
  573. (M)->Buffer = (B); \
  574. }
  575. #endif
  576. #endif
  577. //
  578. // NtOfsPinRead pins a section of a map and read in all pages from the mapped
  579. // attribute. Offset and Length must describe a byte range which is equal to
  580. // or included by the original mapped range.
  581. //
  582. #ifndef _NTFSPROC_
  583. NTFSAPI
  584. VOID
  585. NtOfsPinRead(
  586. IN PIRP_CONTEXT IrpContext,
  587. IN ATTRIBUTE_HANDLE Attribute,
  588. IN LONGLONG Offset,
  589. IN ULONG Length,
  590. OUT PMAP_HANDLE MapHandle
  591. );
  592. #else
  593. #ifdef MAPCOUNT_DBG
  594. #define NtOfsPinRead(I,S,O,L,M) { \
  595. ASSERT((M)->Bcb != NULL); \
  596. ASSERT(((O) >= (M)->FileOffset) && (((O) + (L)) <= ((M)->FileOffset + (M)->Length))); \
  597. CcPinMappedData((S)->FileObject, (PLARGE_INTEGER)&(O), (L), TRUE, &(M)->Bcb); \
  598. (I)->MapCount++; \
  599. (M)->FileOffset = (O); \
  600. (M)->Length = (L); \
  601. }
  602. #else
  603. #define NtOfsPinRead(I,S,O,L,M) { \
  604. ASSERT((M)->Bcb != NULL); \
  605. ASSERT(((O) >= (M)->FileOffset) && (((O) + (L)) <= ((M)->FileOffset + (M)->Length))); \
  606. CcPinMappedData((S)->FileObject, (PLARGE_INTEGER)&(O), (L), TRUE, &(M)->Bcb); \
  607. (M)->FileOffset = (O); \
  608. (M)->Length = (L); \
  609. }
  610. #endif
  611. #endif
  612. //
  613. // NtOfsDirty marks a map as being dirty (eligible for lazy writer access) and
  614. // marks the pages with an optional LSN for coordination with LFS. This call
  615. // is invalid unless the map has been pinned.
  616. //
  617. // NTFSAPI
  618. // NtOfsDirty (
  619. // IN PIRP_CONTEXT IrpContext,
  620. // IN PMAP_HANDLE MapHandle,
  621. // PLSN Lsn OPTIONAL
  622. // );
  623. #define NtOfsDirty(I,M,L) {CcSetDirtyPinnedData((M)->Bcb,(L));}
  624. //
  625. // NtOfsReleaseMap unmaps/unpins a mapped portion of an attribute.
  626. //
  627. #ifndef _NTFSPROC_
  628. NTFSAPI
  629. VOID
  630. NtOfsReleaseMap (
  631. IN PIRP_CONTEXT IrpContext,
  632. IN PMAP_HANDLE MapHandle
  633. );
  634. #else
  635. #ifdef MAPCOUNT_DBG
  636. #define NtOfsReleaseMap(IC,M) { \
  637. if ((M)->Bcb != NULL) { \
  638. CcUnpinData((M)->Bcb); \
  639. (IC)->MapCount--; \
  640. (M)->Bcb = NULL; \
  641. } \
  642. }
  643. #else
  644. #define NtOfsReleaseMap(IC,M) { \
  645. if ((M)->Bcb != NULL) { \
  646. CcUnpinData((M)->Bcb); \
  647. (M)->Bcb = NULL; \
  648. } \
  649. }
  650. #endif
  651. #endif
  652. //
  653. // NtOfsPutData writes data into an attribute in a recoverable fashion. The
  654. // caller must have opened the attribute with LogNonresidentToo.
  655. //
  656. // NtOfsPutData will write the data atomically and update the mapped image,
  657. // subject to the normal lazy commit of the transaction.
  658. //
  659. NTFSAPI
  660. VOID
  661. NtOfsPutData (
  662. IN PIRP_CONTEXT IrpContext,
  663. IN ATTRIBUTE_HANDLE Attribute,
  664. IN LONGLONG Offset,
  665. IN ULONG Length,
  666. IN PVOID Data OPTIONAL
  667. );
  668. ////////////////////////////////////////////////////////////////////////////////
  669. //
  670. // Attribute API - These encapsulate access to attributes on files/directories
  671. // and summary catalogs
  672. //
  673. //
  674. // NtOfsCreateAttribute will create or open a data attribute and return a handle
  675. // that will allow mapping operations.
  676. //
  677. // For attributes that wish to have logging behavior, LogNonresidentToo must be
  678. // set to true. See the discussion on NtOfsPutData (in the mapping section
  679. // above).
  680. //
  681. NTFSAPI
  682. NTSTATUS
  683. NtOfsCreateAttribute (
  684. IN PIRP_CONTEXT IrpContext,
  685. IN OBJECT_HANDLE ObjectHandle,
  686. IN UNICODE_STRING Name,
  687. IN CREATE_OPTIONS CreateOptions,
  688. IN ULONG LogNonresidentToo,
  689. OUT ATTRIBUTE_HANDLE *AttributeHandle
  690. );
  691. //
  692. // NtOfsCreateAttributeEx will create or open an attribute and return a handle
  693. // that will allow mapping operations. If a standard data attribute is to be
  694. // used, call NtOfsCreateAttribute instead. This function is here for callers
  695. // who need to use a different attribute type code.
  696. //
  697. // For attributes that wish to have logging behavior, LogNonresidentToo must be
  698. // set to true. See the discussion on NtOfsPutData (in the mapping section
  699. // above).
  700. //
  701. NTFSAPI
  702. NTSTATUS
  703. NtOfsCreateAttributeEx (
  704. IN PIRP_CONTEXT IrpContext,
  705. IN OBJECT_HANDLE ObjectHandle,
  706. IN UNICODE_STRING Name,
  707. IN ULONG AttributeTypeCode,
  708. IN CREATE_OPTIONS CreateOptions,
  709. IN ULONG LogNonresidentToo,
  710. OUT ATTRIBUTE_HANDLE *AttributeHandle
  711. );
  712. //
  713. // Valid AttributeTypeCode values for NtOfsCreateAttributeEx:
  714. //
  715. #define $LOGGED_UTILITY_STREAM (0x100)
  716. //
  717. // NtOfsCloseAttribute releases the attribute. The attribute is not acquired. No
  718. // outstanding maps are active.
  719. //
  720. NTFSAPI
  721. VOID
  722. NtOfsCloseAttribute (
  723. IN PIRP_CONTEXT IrpContext,
  724. IN ATTRIBUTE_HANDLE AttributeHandle
  725. );
  726. //
  727. // NtOfsDeleteAttribute releases all storage associated with the attribute. The
  728. // object will be acquired exclusive. The attribute will be acquired exclusive.
  729. // No outstanding maps are active.
  730. //
  731. NTFSAPI
  732. VOID
  733. NtOfsDeleteAttribute (
  734. IN PIRP_CONTEXT IrpContext,
  735. IN OBJECT_HANDLE ObjectHandle,
  736. IN ATTRIBUTE_HANDLE AttributeHandle
  737. );
  738. //
  739. // NtOfsQueryLength returns the current length of user data within the attribute.
  740. // The attribute may be mapped. The attribute may be acquired.
  741. //
  742. NTFSAPI
  743. LONGLONG
  744. NtOfsQueryLength (
  745. IN ATTRIBUTE_HANDLE AttributeHandle
  746. );
  747. //
  748. // NtOfsSetLength sets the current EOF on the given attribute. The attribute
  749. // may not be mapped to the view containing Length, or any subsequent view.
  750. // The attribute will be acquired exclusive.
  751. //
  752. NTFSAPI
  753. VOID
  754. NtOfsSetLength (
  755. IN PIRP_CONTEXT IrpContext,
  756. IN ATTRIBUTE_HANDLE Attribute,
  757. IN LONGLONG Length
  758. );
  759. //
  760. // NtOfsWaitForNewLength allows the caller to wait for the specified length to
  761. // be exceeded, or optionally timeout, if the specified Irp has not been cancelled.
  762. //
  763. NTFSAPI
  764. NTSTATUS
  765. NtOfsWaitForNewLength (
  766. IN ATTRIBUTE_HANDLE Attribute,
  767. IN LONGLONG Length,
  768. IN ULONG Async,
  769. IN PIRP Irp,
  770. IN PDRIVER_CANCEL CancelRoutine,
  771. IN PLARGE_INTEGER Timeout OPTIONAL
  772. );
  773. //
  774. // This routine may be called any time FileSize has changed to wake any threads
  775. // waiting for a particular FileSize change. Or specify WakeAll to unconditionally
  776. // wake all waiters.
  777. //
  778. VOID
  779. NtOfsPostNewLength (
  780. IN PIRP_CONTEXT IrpContext OPTIONAL,
  781. IN ATTRIBUTE_HANDLE Attribute,
  782. IN BOOLEAN WakeAll
  783. );
  784. //
  785. // NtOfsDecommit releases storage associated with a range of the attribute. It does
  786. // not change the EOF marker nor does it change the logical position of data within
  787. // the attribute. The range of the attribute being released may be mapped or
  788. // pinned.
  789. //
  790. // Reads from decommitted ranges should return zero (although Query will never read
  791. // from these ranges).
  792. //
  793. // Writes to decommitted pages should fail or be nooped (although Query will never
  794. // write to these ranges).
  795. //
  796. // This call will purge, so none of the views overlapping the specified range may
  797. // be mapped.
  798. //
  799. NTFSAPI
  800. VOID
  801. NtOfsDecommit (
  802. IN PIRP_CONTEXT IrpContext,
  803. IN ATTRIBUTE_HANDLE Attribute,
  804. IN LONGLONG Offset,
  805. IN LONGLONG Length
  806. );
  807. //
  808. // NtOfsFlushAttribute flushes all cached data to the disk and returns upon
  809. // completion. If the attribute is LogNonresidentToo, then only the log file
  810. // is flushed. Optionally, the range may be purged as well. If the attribute
  811. // is purged, then there can be no mapped views.
  812. //
  813. NTFSAPI
  814. VOID
  815. NtOfsFlushAttribute (
  816. IN PIRP_CONTEXT IrpContext,
  817. IN ATTRIBUTE_HANDLE Attribute,
  818. IN ULONG Purge
  819. );
  820. //
  821. // NtOfsQueryAttributeSecurityId returns the security ID for the attribute if
  822. // present.
  823. //
  824. NTFSAPI
  825. VOID
  826. NtOfsQueryAttributeSecurityId (
  827. IN PIRP_CONTEXT IrpContext,
  828. IN ATTRIBUTE_HANDLE Attribute,
  829. OUT SECURITY_ID *SecurityId
  830. );
  831. ////////////////////////////////////////////////////////////////////////////////
  832. //
  833. // Concurrency control API
  834. //
  835. // As a rule, these routines are not required. All NtOfs routines are
  836. // self-synchronized as atomic actions, or as parts of a top-level action when
  837. // called within a top-level action routine.
  838. //
  839. // ISSUE: In particular, supporting the exclusive access call is an implementation
  840. // problem for Ntfs. Wrapping top-level actions is the best way to preserve
  841. // exclusive access across calls.
  842. //
  843. VOID
  844. NtOfsAcquireObjectShared (
  845. HANDLE ObjectHandle
  846. );
  847. // VOID
  848. // NtOfsAcquireObjectExclusive (
  849. // HANDLE ObjectHandle
  850. // );
  851. VOID
  852. NtOfsReleaseObject (
  853. HANDLE ObjectHandle
  854. );
  855. // Debugging routines
  856. BOOLEAN
  857. NtOfsIsObjectAcquiredExclusive (
  858. HANDLE ObjectHandle
  859. );
  860. BOOLEAN
  861. NtOfsIsObjectAcquiredShared (
  862. HANDLE ObjectHandle
  863. );
  864. ////////////////////////////////////////////////////////////////////////////////
  865. //
  866. // File/Directory/Etc API
  867. //
  868. //
  869. // NtOfsOpenByFileReference opens an object given a file reference. The file is
  870. // assumed to exist; this call cannot be used to create a file. The returned
  871. // handle is acquired according to the input exclusion.
  872. //
  873. NTFSAPI
  874. NTSTATUS
  875. NtOfsOpenByFileReference (
  876. IN PIRP_CONTEXT IrpContext,
  877. IN FILE_REFERENCE FileReference,
  878. IN EXCLUSION Exclusion,
  879. OUT OBJECT_HANDLE *ObjectHandle
  880. );
  881. //
  882. // NtOfsCreateRelativeObject opens or creates an object relative to a specified
  883. // parent object. The parent will be acquired exclusive. The child is opened
  884. // acquired according to the input exclusion.
  885. //
  886. // ISSUE: When creating an object, is the transaction committed before this
  887. // call returns?
  888. //
  889. NTFSAPI
  890. NTSTATUS
  891. NtOfsCreateRelativeObject (
  892. IN PIRP_CONTEXT IrpContext,
  893. IN OBJECT_HANDLE ParentObjectHandle,
  894. IN UNICODE_STRING Name,
  895. IN CREATE_OPTIONS CreateOptions,
  896. IN EXCLUSION Exclusion,
  897. OUT OBJECT_HANDLE *ObjectHandle
  898. );
  899. //
  900. // NtOfsCloseObject releases the object handle.
  901. //
  902. NTFSAPI
  903. NTSTATUS
  904. NtOfsCloseObject (
  905. IN PIRP_CONTEXT IrpContext,
  906. IN OBJECT_HANDLE ObjectHandle
  907. );
  908. //
  909. // NtOfsDeleteObject deletes the object. No user-mode handle is attached to
  910. // the object. No attributes are currently open. The object is acquired
  911. // exclusive.
  912. //
  913. NTFSAPI
  914. NTSTATUS
  915. NtOfsDeleteObject (
  916. IN PIRP_CONTEXT IrpContext,
  917. IN OBJECT_HANDLE ObjectHandle
  918. );
  919. //
  920. // NtOfsDeleteAllAttributes deletes all attributes of the object. No attribute
  921. // is open. The object is acquired exclusive.
  922. //
  923. NTFSAPI
  924. NTSTATUS
  925. NtOfsDeleteAllAttributes (
  926. IN PIRP_CONTEXT IrpContext,
  927. IN OBJECT_HANDLE ObjectHandle
  928. );
  929. //
  930. // NtOfsQueryPathFromRoot returns *A* path from the root to a node. In the
  931. // presence of hard links, several paths may exist, however, only one needs
  932. // to be returned. Memory for the file name is provided by the caller.
  933. //
  934. NTFSAPI
  935. NTSTATUS
  936. NtOfsQueryPathFromRoot (
  937. IN PIRP_CONTEXT IrpContext,
  938. IN FILE_REFERENCE FileReference,
  939. OUT UNICODE_STRING *PathName
  940. );
  941. //
  942. // NtOfsQueryFileName returns the final component in the path name into a
  943. // caller-supplied buffer. In the presence of hard links, several names
  944. // may exist, however, only one needs to be returned.
  945. //
  946. NTFSAPI
  947. NTSTATUS
  948. NtOfsQueryFileName (
  949. IN PIRP_CONTEXT IrpContext,
  950. IN FILE_REFERENCE FileReference,
  951. OUT UNICODE_STRING *FileName
  952. );
  953. //
  954. // NtOfsQueryFileReferenceFromName returns the file reference named by the path
  955. //
  956. NTFSAPI
  957. NTSTATUS
  958. NtOfsQueryFileReferenceFromName (
  959. IN PIRP_CONTEXT IrpContext,
  960. IN UNICODE_STRING Name,
  961. OUT FILE_REFERENCE *FileReference
  962. );
  963. //
  964. // This call must be very fast; it is a very common call made by CI/Query.
  965. //
  966. NTFSAPI
  967. NTSTATUS
  968. NtOfsQueryFileReferenceFromHandle (
  969. IN OBJECT_HANDLE Object,
  970. OUT FILE_REFERENCE *FileReference
  971. );
  972. //
  973. // NtOfsQueryObjectSecurityId returns the security Id associated with an object.
  974. // The object is acquired shared or exclusive. This call must be very fast
  975. //
  976. NTFSAPI
  977. NTSTATUS
  978. NtOfsQueryObjectSecurityId (
  979. IN PIRP_CONTEXT IrpContext,
  980. IN OBJECT_HANDLE ObjectHandle,
  981. OUT SECURITY_ID *SecurityId
  982. );
  983. ////////////////////////////////////////////////////////////////////////////////
  984. //
  985. // Scope API
  986. //
  987. //
  988. // NtOfsIsAncestorOf must quickly tell if one file is an ancestor of the given
  989. // child. In the presence of hard links, we may pick a "preferred" path (i.e.
  990. // we don't have to travel to all ancestors). This call must be reasonably fast
  991. // since this is a very frequent call from Query.
  992. //
  993. NTFSAPI
  994. NTSTATUS
  995. NtOfsIsAncestorOf (
  996. IN PIRP_CONTEXT IrpContext,
  997. IN FILE_REFERENCE Ancestor,
  998. IN FILE_REFERENCE Child
  999. );
  1000. //
  1001. // NtOfsGetParentFileReferenceFromHandle is used to retrieve the FileReference
  1002. // of the parent of the named object. With hard links the "first" parent may
  1003. // be chosen. This call needs to be reasonably efficient.
  1004. //
  1005. NTFSAPI
  1006. NTSTATUS
  1007. NtOfsGetParentFileReferenceFromHandle (
  1008. IN PIRP_CONTEXT IrpContext,
  1009. IN OBJECT_HANDLE ChildObject,
  1010. OUT FILE_REFERENCE *ParentFileReference
  1011. );
  1012. ////////////////////////////////////////////////////////////////////////////////
  1013. //
  1014. // Security API
  1015. //
  1016. // NtOfs maintains a "per-IrpContext" cache that speeds up security validation.
  1017. // Clients clear the cache (at the beginning of a query, say) and then do
  1018. // successive probes which may populate the cache.
  1019. //
  1020. //
  1021. // NtOfsClearSecurityCache clears the cache.
  1022. //
  1023. NTFSAPI
  1024. NTSTATUS
  1025. NtOfsClearSecurityCache (
  1026. IN PIRP_CONTEXT IrpContext
  1027. );
  1028. //
  1029. // NtOfsIsAccessGranted uses the Se routines to validate access and caches the
  1030. // result for the specified SecurityId and DesiredAccess. The cache is first
  1031. // probed to see if the access can be granted immediately. If the SecurityId is
  1032. // not found, the corresponding ACL is retrieved and tested with the supplied
  1033. // access state and DesiredAccess. The result of this test is cached and
  1034. // returned.
  1035. //
  1036. NTFSAPI
  1037. NTSTATUS
  1038. NtOfsIsAccessGranted (
  1039. IN PIRP_CONTEXT IrpContext,
  1040. IN SECURITY_ID SecurityId,
  1041. IN ACCESS_MASK DesiredAccess,
  1042. IN ACCESS_STATE *SecurityAccessState
  1043. );
  1044. ////////////////////////////////////////////////////////////////////////////////
  1045. //
  1046. // Worker thread stuff. Worker threads are needed for building new indexes
  1047. //
  1048. ////////////////////////////////////////////////////////////////////////////////
  1049. //
  1050. // Miscellaneous information query/set
  1051. //
  1052. //
  1053. // Content Index may need to mark the volume as dirty to allow garbage collection
  1054. // of orphan objects by CHKDSK.
  1055. //
  1056. NTFSAPI
  1057. NTSTATUS
  1058. NtOfsMarkVolumeCorrupt (
  1059. IN PIRP_CONTEXT IrpContext,
  1060. IN ULONG NewState,
  1061. IN ULONG StateMask,
  1062. OUT ULONG *OldState
  1063. );
  1064. //
  1065. // NtOfsQueryVolumeStatistics returns the current capacity and free space on a
  1066. // volume. Ci uses this for heuristics to decide on when to trigger master merge,
  1067. // when to suppress master merge, etc.
  1068. //
  1069. NTFSAPI
  1070. NTSTATUS
  1071. NtOfsQueryVolumeStatistics (
  1072. IN PIRP_CONTEXT IrpContext,
  1073. OUT LONGLONG *TotalClusters,
  1074. OUT LONGLONG *FreeClusters
  1075. );
  1076. //
  1077. // Query needs to retain some state in the NtOfs Ccb.
  1078. //
  1079. NTFSAPI
  1080. NTSTATUS
  1081. NtOfsQueryHandleState (
  1082. IN PIRP_CONTEXT IrpContext,
  1083. OUT VOID *OldData
  1084. );
  1085. NTFSAPI
  1086. NTSTATUS
  1087. NtOfsSetHandleState (
  1088. IN PIRP_CONTEXT IrpContext,
  1089. IN VOID *Data
  1090. );
  1091. //
  1092. // Generic unwrapping routines that get access to SCB/IRPC and FCB/IRPC
  1093. // pairs.
  1094. //
  1095. NTFSAPI
  1096. NTSTATUS
  1097. NtOfsQueryAttributeHandle (
  1098. IN PIRP_CONTEXT IrpContext,
  1099. OUT ATTRIBUTE_HANDLE *AttributeHandle
  1100. );
  1101. NTFSAPI
  1102. NTSTATUS
  1103. NtOfsQueryObjectHandle (
  1104. IN PIRP_CONTEXT IrpContext,
  1105. OUT OBJECT_HANDLE *ObjectHandle
  1106. );
  1107. //
  1108. // Create a context in which the caller can perform I/O in separate.
  1109. // threads. This means creating an IRP/IRP_CONTEXT. Each IrpContext corresponds
  1110. // to one I/O activity at a time. Multiple IrpContexts may be active in a thread
  1111. // at a single time.
  1112. //
  1113. NTFSAPI
  1114. NTSTATUS
  1115. NtOfsCloneIrpContext (
  1116. IN PIRP_CONTEXT IrpContext,
  1117. OUT PIRP_CONTEXT *NewIrpContext
  1118. );
  1119. //
  1120. // NtOfsCompleteRequest completes an IrpContext that has been previously cloned.
  1121. // All other FsCtl Irps are completed by Ntfs.
  1122. //
  1123. NTFSAPI
  1124. NTSTATUS
  1125. NtOfsCompleteRequest (
  1126. IN PIRP_CONTEXT IrpContext,
  1127. NTSTATUS Status
  1128. );
  1129. ////////////////////////////////////////////////////////////////////////////////
  1130. //
  1131. // Iterators. While each iterator is created through a separate API, each one
  1132. // must support two operations:
  1133. // Next - this fills a buffer with as many records as possible
  1134. // Close - this releases the iterator.
  1135. //
  1136. typedef struct _BASE_FILE_SEGMENT_ITERATOR BASE_FILE_SEGMENT_ITERATOR;
  1137. typedef struct _USN_ITERATOR USN_ITERATOR;
  1138. //
  1139. // The types of iterators are:
  1140. //
  1141. // Scope iterate over a directory (optionally RECURSIVE)
  1142. // (implemented in Query)
  1143. // View iterate over the rows in a view with a partial key match
  1144. // (implemented in View)
  1145. // BaseFileSegment iterate over all base file record segments
  1146. // (implemented in NtOfs)
  1147. // SummaryCatalog iterate over all rows in a summary catalog
  1148. // Usn iterate over all objects with Usn's in a specific range
  1149. // (implmented in NtOfs)
  1150. //
  1151. // Each iteration is passed a buffer which is filled (as much as possible) with
  1152. // a packed array of:
  1153. // FILE_REFERENCE
  1154. // DUPLICATED_INFORMATION
  1155. // STAT_INFORMATION
  1156. // for each enumerated object. The output length is the length in bytes that
  1157. // was filled in with the enumeration request.
  1158. NTFSAPI
  1159. NTSTATUS
  1160. NtOfsCreateBaseFileSegmentIterator (
  1161. IN PIRP_CONTEXT IrpContext,
  1162. OUT BASE_FILE_SEGMENT_ITERATOR *Iterator
  1163. );
  1164. NTFSAPI
  1165. NTSTATUS
  1166. NtOfsNextBaseFileSegmentIteration (
  1167. IN PIRP_CONTEXT IrpContext,
  1168. IN BASE_FILE_SEGMENT_ITERATOR *Iterator,
  1169. IN OUT ULONG *BufferLength,
  1170. IN OUT PVOID Buffer
  1171. );
  1172. NTFSAPI
  1173. NTSTATUS
  1174. NtOfsCloseBaseFileSegmentIterator (
  1175. IN PIRP_CONTEXT IrpContext,
  1176. IN BASE_FILE_SEGMENT_ITERATOR *Iterator
  1177. );
  1178. NTFSAPI
  1179. NTSTATUS
  1180. NtOfsCreateUsnIterator (
  1181. IN PIRP_CONTEXT IrpContext,
  1182. IN USN BeginningUsn,
  1183. IN USN EndingUsn,
  1184. OUT USN_ITERATOR *Iterator
  1185. );
  1186. NTFSAPI
  1187. NTSTATUS
  1188. NtOfsNextUsnIteration (
  1189. IN PIRP_CONTEXT IrpContext,
  1190. IN USN_ITERATOR *Iterator,
  1191. IN OUT ULONG *BufferLength,
  1192. IN OUT PVOID Buffer
  1193. );
  1194. NTFSAPI
  1195. NTSTATUS
  1196. NtOfsCloseUsnIterator (
  1197. IN PIRP_CONTEXT IrpContext,
  1198. IN USN_ITERATOR *Iterator
  1199. );
  1200. ////////////////////////////////////////////////////////////////////////////////
  1201. //
  1202. // Infrastructure support.
  1203. //
  1204. // V/C/X register callbacks with NtOfs when they are loaded. Until they are loaded
  1205. // NtOfs will call default routines (that do nothing).
  1206. //
  1207. typedef enum _NTFS_ADDON_TYPES {
  1208. Encryption = 3
  1209. } NTFS_ADDON_TYPES;
  1210. ////////////////////////////////////////////////////////////////////////////////
  1211. //
  1212. // Encryption
  1213. //
  1214. //
  1215. // Stream Create Status for FileDirFlag
  1216. //
  1217. #define STREAM_NEW_OR_EXIST_MASK 0x000f0000
  1218. #define FILE_DIR_TYPE_MASK 0x000000ff
  1219. #define FILE_NEW 0x00000001
  1220. #define FILE_EXISTING 0x00000002
  1221. #define DIRECTORY_NEW 0x00000004
  1222. #define DIRECTORY_EXISTING 0x00000008
  1223. #define EXISTING_FILE_ENCRYPTED 0x00000010
  1224. #define STREAM_NEW 0x00010000
  1225. #define STREAM_EXISTING 0x00020000
  1226. //
  1227. // Encryption flag for EncryptionFlag
  1228. //
  1229. #define STREAM_ENCRYPTED 0x00000001
  1230. #define FILE_ENCRYPTED 0x00000002
  1231. //
  1232. // Access flags
  1233. //
  1234. // NB -- These values are NOT arbitrary. Notice also that they are not
  1235. // in value order, they are grouped according to their meaning.
  1236. // Their values correspond to FILE_READ_DATA, etc. and
  1237. // TOKEN_HAS_BACKUP_PRIVILEGE, etc.
  1238. //
  1239. #define READ_DATA_ACCESS 0x01
  1240. #define WRITE_DATA_ACCESS 0x02
  1241. #define APPEND_DATA_ACCESS 0x04
  1242. #define EXECUTE_ACCESS 0x20
  1243. #define READ_ATTRIBUTES_ACCESS 0x80
  1244. #define WRITE_ATTRIBUTES_ACCESS 0x100
  1245. #define BACKUP_ACCESS 0x08
  1246. #define RESTORE_ACCESS 0x10
  1247. #define TRAVERSE_ACCESS 0x40
  1248. #define MANAGE_VOLUME_ACCESS 0x200
  1249. //
  1250. // Volume State
  1251. //
  1252. #define READ_ONLY_VOLUME 0x00000001
  1253. typedef NTSTATUS
  1254. (*ENCRYPTED_FILE_CREATE) (
  1255. IN OBJECT_HANDLE FileHdl,
  1256. IN OBJECT_HANDLE ParentDir OPTIONAL,
  1257. IN PIO_STACK_LOCATION IrpSp,
  1258. IN ULONG FileDirFlag,
  1259. IN ULONG VolumeState,
  1260. IN PIRP_CONTEXT IrpContext,
  1261. IN PDEVICE_OBJECT VolDo,
  1262. IN PVOID FileKeyContext,
  1263. IN OUT PVOID *PKeyContext,
  1264. IN OUT ULONG *ContextLength,
  1265. IN OUT PVOID *PCreateContext,
  1266. IN OUT PBOOLEAN Reserved
  1267. );
  1268. typedef NTSTATUS
  1269. (*ENCRYPTED_FILE_PRE_CREATE) (
  1270. IN PDEVICE_OBJECT VolDo,
  1271. IN PIRP Irp,
  1272. IN PFILE_OBJECT FileObject
  1273. );
  1274. typedef NTSTATUS
  1275. (*ENCRYPTED_FILE_POST_CREATE) (
  1276. IN PDEVICE_OBJECT VolDo,
  1277. IN PIRP Irp,
  1278. IN PFILE_OBJECT FileObject,
  1279. IN NTSTATUS Status,
  1280. IN OUT PVOID *PCreateContext
  1281. );
  1282. typedef NTSTATUS
  1283. (*ENCRYPTED_FILE_SYSTEM_CONTROL) (
  1284. IN PVOID PInputBuffer OPTIONAL,
  1285. IN ULONG InputDataLength,
  1286. OUT PVOID OutputBuffer OPTIONAL,
  1287. IN OUT ULONG *OutputBufferLength OPTIONAL,
  1288. IN ULONG EncryptionFlag,
  1289. IN ULONG AccessFlag,
  1290. IN ULONG VolumeState,
  1291. IN ULONG FsControlCode,
  1292. IN OBJECT_HANDLE FileHdl,
  1293. IN PIRP_CONTEXT IrpContext,
  1294. IN PDEVICE_OBJECT VolDo,
  1295. IN ATTRIBUTE_HANDLE Attribute,
  1296. IN OUT PVOID *PContext OPTIONAL,
  1297. IN OUT ULONG *ContextLength OPTIONAL
  1298. );
  1299. typedef NTSTATUS
  1300. (*ENCRYPTED_FILE_PRE_FILE_SYSTEM_CONTROL) (
  1301. IN PDEVICE_OBJECT VolDo,
  1302. IN PIRP Irp,
  1303. IN PFILE_OBJECT FileObject
  1304. );
  1305. typedef NTSTATUS
  1306. (*ENCRYPTED_FILE_READ)(
  1307. IN OUT PUCHAR InOutBuffer,
  1308. IN PLARGE_INTEGER Offset,
  1309. IN ULONG BufferSize,
  1310. IN PVOID Context
  1311. );
  1312. typedef NTSTATUS
  1313. (*ENCRYPTED_FILE_WRITE)(
  1314. IN PUCHAR InBuffer,
  1315. OUT PUCHAR OutBuffer,
  1316. IN PLARGE_INTEGER Offset,
  1317. IN ULONG BufferSize,
  1318. IN PUCHAR Context
  1319. );
  1320. typedef VOID
  1321. (*ENCRYPTED_FILE_CLEANUP)(
  1322. IN OUT PVOID *Context
  1323. );
  1324. #define ENCRYPTION_CURRENT_INTERFACE_VERSION 3
  1325. #define ENCRYPTION_ALL_STREAMS 0x00000001
  1326. #define ENCRYPTION_ALLOW_COMPRESSION 0x00000002
  1327. typedef struct _ENCRYPTION_CALL_BACK {
  1328. ULONG InterfaceVersion;
  1329. ULONG ImplementationFlags;
  1330. ENCRYPTED_FILE_CREATE FileCreate;
  1331. ENCRYPTED_FILE_PRE_CREATE PreCreate;
  1332. ENCRYPTED_FILE_POST_CREATE PostCreate;
  1333. ENCRYPTED_FILE_SYSTEM_CONTROL FileSystemControl_1;
  1334. ENCRYPTED_FILE_SYSTEM_CONTROL FileSystemControl_2;
  1335. ENCRYPTED_FILE_PRE_FILE_SYSTEM_CONTROL PreFileSystemControl;
  1336. ENCRYPTED_FILE_READ AfterReadProcess;
  1337. ENCRYPTED_FILE_WRITE BeforeWriteProcess;
  1338. ENCRYPTED_FILE_CLEANUP CleanUp;
  1339. } ENCRYPTION_CALL_BACK, *PENCRYPTION_CALL_BACK;
  1340. //
  1341. // NtOfsRegisterCallBacks supplies a call table to NtOfs. Each table has an
  1342. // interface version number. If the interface version does not exactly match
  1343. // what NtOfs expects, the call will fail.
  1344. //
  1345. NTFSAPI
  1346. NTSTATUS
  1347. NtOfsRegisterCallBacks (
  1348. NTFS_ADDON_TYPES NtfsAddonType,
  1349. PVOID CallBackTable
  1350. );