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.

1068 lines
25 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. PrefxSup.c
  5. Abstract:
  6. This module implements the Ntfs Prefix support routines
  7. Author:
  8. Gary Kimura [GaryKi] 21-May-1991
  9. Revision History:
  10. --*/
  11. #include "NtfsProc.h"
  12. //
  13. // The Bug check file id for this module
  14. //
  15. #define BugCheckFileId (NTFS_BUG_CHECK_PREFXSUP)
  16. //
  17. // The debug trace level for this module
  18. //
  19. #define Dbg (DEBUG_TRACE_PREFXSUP)
  20. //
  21. // Local procedures
  22. //
  23. #ifdef NTFS_CHECK_SPLAY
  24. VOID
  25. NtfsCheckSplay (
  26. IN PRTL_SPLAY_LINKS Root
  27. );
  28. #endif
  29. #ifdef ALLOC_PRAGMA
  30. #pragma alloc_text(PAGE, NtfsFindPrefix)
  31. #pragma alloc_text(PAGE, NtfsFindNameLink)
  32. #pragma alloc_text(PAGE, NtfsInsertNameLink)
  33. #pragma alloc_text(PAGE, NtfsInsertPrefix)
  34. #pragma alloc_text(PAGE, NtfsRemovePrefix)
  35. #ifdef NTFS_CHECK_SPLAY
  36. #pragma alloc_text(PAGE, NtfsCheckSplay)
  37. #endif
  38. #endif
  39. VOID
  40. NtfsInsertPrefix (
  41. IN PLCB Lcb,
  42. IN ULONG CreateFlags
  43. )
  44. /*++
  45. Routine Description:
  46. This routine inserts the names in the given Lcb into the links for the
  47. parent.
  48. Arguments:
  49. Lcb - This is the link to insert.
  50. CreateFlags - Indicates if we should insert the case-insensitive name.
  51. Return Value:
  52. None.
  53. --*/
  54. {
  55. PAGED_CODE();
  56. ASSERT( (Lcb->Scb == NULL) ||
  57. NtfsIsExclusiveScb( Lcb->Scb ) );
  58. //
  59. // Attempt to insert the case-insensitive name. It is possible that
  60. // we can't enter this name.
  61. //
  62. if (FlagOn( CreateFlags, CREATE_FLAG_IGNORE_CASE )) {
  63. if (!FlagOn( Lcb->LcbState, LCB_STATE_IGNORE_CASE_IN_TREE ) &&
  64. NtfsInsertNameLink( &Lcb->Scb->ScbType.Index.IgnoreCaseNode,
  65. &Lcb->IgnoreCaseLink )) {
  66. SetFlag( Lcb->LcbState, LCB_STATE_IGNORE_CASE_IN_TREE );
  67. }
  68. } else if (!FlagOn( Lcb->LcbState, LCB_STATE_EXACT_CASE_IN_TREE )) {
  69. if (!NtfsInsertNameLink( &Lcb->Scb->ScbType.Index.ExactCaseNode,
  70. &Lcb->ExactCaseLink )) {
  71. NtfsBugCheck( 0, 0, 0 );
  72. }
  73. SetFlag( Lcb->LcbState, LCB_STATE_EXACT_CASE_IN_TREE );
  74. }
  75. return;
  76. }
  77. VOID
  78. NtfsRemovePrefix (
  79. IN PLCB Lcb
  80. )
  81. /*++
  82. Routine Description:
  83. This routine deletes all of the Prefix entries that exist for the input
  84. Lcb.
  85. Arguments:
  86. Lcb - Supplies the Lcb whose prefixes are to be removed
  87. Return Value:
  88. None.
  89. --*/
  90. {
  91. PAGED_CODE();
  92. //
  93. // Remove the case-insensitive link.
  94. //
  95. if (FlagOn( Lcb->LcbState, LCB_STATE_IGNORE_CASE_IN_TREE )) {
  96. NtfsRemoveNameLink( &Lcb->Scb->ScbType.Index.IgnoreCaseNode,
  97. &Lcb->IgnoreCaseLink );
  98. ClearFlag( Lcb->LcbState, LCB_STATE_IGNORE_CASE_IN_TREE );
  99. }
  100. //
  101. // Now do the same for the exact case name.
  102. //
  103. if (FlagOn( Lcb->LcbState, LCB_STATE_EXACT_CASE_IN_TREE )) {
  104. NtfsRemoveNameLink( &Lcb->Scb->ScbType.Index.ExactCaseNode,
  105. &Lcb->ExactCaseLink );
  106. ClearFlag( Lcb->LcbState, LCB_STATE_EXACT_CASE_IN_TREE );
  107. }
  108. return;
  109. }
  110. PLCB
  111. NtfsFindPrefix (
  112. IN PIRP_CONTEXT IrpContext,
  113. IN PSCB StartingScb,
  114. OUT PFCB *CurrentFcb,
  115. OUT PLCB *LcbForTeardown,
  116. IN OUT UNICODE_STRING FullFileName,
  117. IN OUT PULONG CreateFlags,
  118. OUT PUNICODE_STRING RemainingName
  119. )
  120. /*++
  121. Routine Description:
  122. This routine begins from the given Scb and walks through all of
  123. components of the name looking for the longest match in the prefix
  124. splay trees. The search is relative to the starting Scb so the
  125. full name may not begin with a '\'. On return this routine will
  126. update Current Fcb with the lowest point it has travelled in the
  127. tree. It will also hold only that resource on return and it must
  128. hold that resource.
  129. Arguments:
  130. StartingScb - Supplies the Scb to start the search from.
  131. CurrentFcb - Address to store the lowest Fcb we find on this search.
  132. On return we will have acquired this Fcb.
  133. LcbForTeardown - If we encounter an Lcb we must teardown on error we
  134. store it here.
  135. FullFileName - Supplies the input string to search for. After the search the
  136. buffer for this string will be modified so that for the characters that did
  137. match will be the exact case of what we found.
  138. CreateFlags - Flags for the create option - we are interested in whether
  139. this is a case-insensitive compare and we also will set the dos only component flag
  140. RemainingName - Returns the string when the prefix no longer matches.
  141. For example, if the input string is "alpha\beta" only matches the
  142. root directory then the remaining string is "alpha\beta". If the
  143. same string matches an LCB for "alpha" then the remaining string is
  144. "beta".
  145. Return Value:
  146. PLCB - Returns a pointer to the Lcb corresponding to the longest match
  147. in the splay tree. NULL if we didn't even find one entry.
  148. --*/
  149. {
  150. PSCB LastScb = NULL;
  151. PLCB LastLcb = NULL;
  152. PLCB ThisLcb;
  153. PNAME_LINK NameLink;
  154. UNICODE_STRING NextComponent;
  155. UNICODE_STRING Tail;
  156. BOOLEAN DroppedParent;
  157. BOOLEAN NeedSnapShot = FALSE;
  158. PAGED_CODE();
  159. //
  160. // Start by setting the remaining name to the full name to be parsed.
  161. //
  162. *RemainingName = FullFileName;
  163. //
  164. // If there are no characters left or the starting Scb is not an index
  165. // or the name begins with a ':' or the Fcb denotes a reparse point
  166. // then return without looking up the name.
  167. //
  168. if (RemainingName->Length == 0 ||
  169. StartingScb->AttributeTypeCode != $INDEX_ALLOCATION ||
  170. RemainingName->Buffer[0] == L':' ||
  171. FlagOn( (StartingScb->Fcb)->Info.FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT )) {
  172. return NULL;
  173. }
  174. //
  175. // Loop until we find the longest matching prefix.
  176. //
  177. while (TRUE) {
  178. ASSERT( NtfsIsExclusiveScb( StartingScb ) );
  179. //
  180. // Get the next component off of the list.
  181. //
  182. NtfsDissectName( *RemainingName,
  183. &NextComponent,
  184. &Tail );
  185. //
  186. // Check if this name is in the splay tree for this Scb.
  187. //
  188. if (FlagOn( *CreateFlags, CREATE_FLAG_IGNORE_CASE )) {
  189. NameLink = NtfsFindNameLink( &StartingScb->ScbType.Index.IgnoreCaseNode,
  190. &NextComponent );
  191. ThisLcb = CONTAINING_RECORD( NameLink, LCB, IgnoreCaseLink );
  192. } else {
  193. NameLink = NtfsFindNameLink( &StartingScb->ScbType.Index.ExactCaseNode,
  194. &NextComponent );
  195. ThisLcb = CONTAINING_RECORD( NameLink, LCB, ExactCaseLink );
  196. }
  197. //
  198. // If we didn't find a match then return the Fcb for the current Scb.
  199. //
  200. if (NameLink == NULL) {
  201. if (NeedSnapShot) {
  202. //
  203. // NtfsCreateScb was not called on the StartingScb so take a
  204. // snapshot now.
  205. //
  206. NtfsSnapshotScb( IrpContext, StartingScb );
  207. }
  208. return LastLcb;
  209. }
  210. //
  211. // If this is a case-insensitive match then copy the exact case of the name into
  212. // the input buffer.
  213. //
  214. if (FlagOn( *CreateFlags, CREATE_FLAG_IGNORE_CASE )) {
  215. RtlCopyMemory( NextComponent.Buffer,
  216. ThisLcb->ExactCaseLink.LinkName.Buffer,
  217. NextComponent.Length );
  218. }
  219. //
  220. // Update the caller's remaining name string to reflect the fact that we found
  221. // a match.
  222. //
  223. *RemainingName = Tail;
  224. //
  225. // Before we give up the previous Lcb check if the name was a DOS-ONLY
  226. // name and set the return boolean if so.
  227. //
  228. if (LastLcb != NULL &&
  229. LastLcb->FileNameAttr->Flags == FILE_NAME_DOS) {
  230. SetFlag( *CreateFlags, CREATE_FLAG_DOS_ONLY_COMPONENT );
  231. }
  232. //
  233. // Update the pointers to the Lcb.
  234. //
  235. LastLcb = ThisLcb;
  236. DroppedParent = FALSE;
  237. //
  238. // We want to acquire the next Fcb and release the one we currently
  239. // have. Try to do a fast acquire.
  240. //
  241. if (!NtfsAcquireFcbWithPaging( IrpContext, ThisLcb->Fcb, ACQUIRE_DONT_WAIT )) {
  242. //
  243. // Reference the link and Fcb so they don't go away.
  244. //
  245. ThisLcb->ReferenceCount += 1;
  246. NtfsAcquireFcbTable( IrpContext, StartingScb->Vcb );
  247. ThisLcb->Fcb->ReferenceCount += 1;
  248. NtfsReleaseFcbTable( IrpContext, StartingScb->Vcb );
  249. //
  250. // Set the IrpContext to acquire paging io resources if our target
  251. // has one. This will lock the MappedPageWriter out of this file.
  252. //
  253. if (ThisLcb->Fcb->PagingIoResource != NULL) {
  254. SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_ACQUIRE_PAGING );
  255. }
  256. NtfsReleaseScbWithPaging( IrpContext, StartingScb );
  257. NtfsAcquireFcbWithPaging( IrpContext, ThisLcb->Fcb, 0 );
  258. NtfsAcquireExclusiveScb( IrpContext, StartingScb );
  259. ThisLcb->ReferenceCount -= 1;
  260. NtfsReleaseScb( IrpContext, StartingScb );
  261. NtfsAcquireFcbTable( IrpContext, StartingScb->Vcb );
  262. ThisLcb->Fcb->ReferenceCount -= 1;
  263. NtfsReleaseFcbTable( IrpContext, StartingScb->Vcb );
  264. DroppedParent = TRUE;
  265. } else {
  266. //
  267. // Don't forget to release the starting Scb.
  268. //
  269. NtfsReleaseScbWithPaging( IrpContext, StartingScb );
  270. }
  271. *LcbForTeardown = ThisLcb;
  272. *CurrentFcb = ThisLcb->Fcb;
  273. //
  274. // It is possible that the Lcb we just found could have been removed
  275. // from the prefix table in the window where we dropped the parent Scb.
  276. // In that case we need to check that it is still in the prefix
  277. // table. If not then raise CANT_WAIT to force a rescan through the
  278. // prefix table.
  279. //
  280. if (DroppedParent &&
  281. !FlagOn( ThisLcb->LcbState,
  282. LCB_STATE_IGNORE_CASE_IN_TREE | LCB_STATE_EXACT_CASE_IN_TREE )) {
  283. NtfsRaiseStatus( IrpContext, STATUS_CANT_WAIT, NULL, NULL );
  284. }
  285. //
  286. // If we found a match but the Fcb is uninitialized or is not a directory
  287. // then we are done. Also finished if the remaining name length is 0.
  288. //
  289. if (!FlagOn( ThisLcb->Fcb->FcbState, FCB_STATE_DUP_INITIALIZED ) ||
  290. !IsDirectory( &ThisLcb->Fcb->Info ) ||
  291. RemainingName->Length == 0) {
  292. return LastLcb;
  293. }
  294. //
  295. // Get the Scb for the $INDEX_ALLOCATION for this Fcb.
  296. //
  297. LastScb = StartingScb;
  298. // Since the SCB is usually track on the end of the SCB look
  299. // for it in the FCB first.
  300. if (FlagOn( ThisLcb->Fcb->FcbState, FCB_STATE_COMPOUND_INDEX ) &&
  301. (SafeNodeType( &((PFCB_INDEX) ThisLcb->Fcb)->Scb ) == NTFS_NTC_SCB_INDEX)) {
  302. NeedSnapShot = TRUE;
  303. StartingScb = (PSCB) &((PFCB_INDEX) ThisLcb->Fcb)->Scb;
  304. ASSERT(!FlagOn( StartingScb->ScbState, SCB_STATE_ATTRIBUTE_DELETED) &&
  305. (StartingScb->AttributeTypeCode == $INDEX_ALLOCATION) &&
  306. NtfsAreNamesEqual( IrpContext->Vcb->UpcaseTable, &StartingScb->AttributeName, &NtfsFileNameIndex, FALSE ));
  307. } else {
  308. NeedSnapShot = FALSE;
  309. StartingScb = NtfsCreateScb( IrpContext,
  310. ThisLcb->Fcb,
  311. $INDEX_ALLOCATION,
  312. &NtfsFileNameIndex,
  313. FALSE,
  314. NULL );
  315. }
  316. //
  317. // If there is no normalized name in this Scb, find it now.
  318. //
  319. if ((StartingScb->ScbType.Index.NormalizedName.Length == 0) &&
  320. (LastScb->ScbType.Index.NormalizedName.Length != 0)) {
  321. NtfsUpdateNormalizedName( IrpContext, LastScb, StartingScb, NULL, FALSE );
  322. }
  323. }
  324. }
  325. BOOLEAN
  326. NtfsInsertNameLink (
  327. IN PRTL_SPLAY_LINKS *RootNode,
  328. IN PNAME_LINK NameLink
  329. )
  330. /*++
  331. Routine Description:
  332. This routine will insert a name in the splay tree pointed to
  333. by RootNode.
  334. The name could already exist in this tree for a case-insensitive tree.
  335. In that case we simply return FALSE and do nothing.
  336. Arguments:
  337. RootNode - Supplies a pointer to the table.
  338. NameLink - Contains the new link to enter.
  339. Return Value:
  340. BOOLEAN - TRUE if the name is inserted, FALSE otherwise.
  341. --*/
  342. {
  343. FSRTL_COMPARISON_RESULT Comparison;
  344. PNAME_LINK Node;
  345. ULONG i;
  346. ULONG MinLength;
  347. PAGED_CODE();
  348. RtlInitializeSplayLinks( &NameLink->Links );
  349. //
  350. // If we are the first entry in the tree, just become the root.
  351. //
  352. if (*RootNode == NULL) {
  353. *RootNode = &NameLink->Links;
  354. return TRUE;
  355. }
  356. #ifdef NTFS_CHECK_SPLAY
  357. NtfsCheckSplay( *RootNode );
  358. #endif
  359. Node = CONTAINING_RECORD( *RootNode, NAME_LINK, Links );
  360. while (TRUE) {
  361. //
  362. // Lets assume that we are appending to a directory and are greater than
  363. // all entries.
  364. //
  365. Comparison = LessThan;
  366. //
  367. // If the first characters match then we need to do a full string compare.
  368. //
  369. if (Node->LinkName.Buffer[0] == NameLink->LinkName.Buffer[0]) {
  370. //
  371. // Figure out the minimum of the two lengths
  372. //
  373. if (Node->LinkName.Length < NameLink->LinkName.Length) {
  374. MinLength = Node->LinkName.Length;
  375. } else {
  376. MinLength = NameLink->LinkName.Length;
  377. }
  378. //
  379. // Loop through looking at all of the characters in both strings
  380. // testing for equalilty, less than, and greater than
  381. //
  382. i = (ULONG) RtlCompareMemory( Node->LinkName.Buffer, NameLink->LinkName.Buffer, MinLength );
  383. //
  384. // Check if we didn't match up to the length of the shorter name.
  385. //
  386. if (i < MinLength) {
  387. if (Node->LinkName.Buffer[i / sizeof( WCHAR )] > NameLink->LinkName.Buffer[i / sizeof( WCHAR )]) {
  388. Comparison = GreaterThan;
  389. }
  390. //
  391. // We match up to the length of the shorter string. If the lengths are different
  392. // then move down the splay tree.
  393. //
  394. } else if (Node->LinkName.Length > NameLink->LinkName.Length) {
  395. Comparison = GreaterThan;
  396. //
  397. // Exit if the strings are the same length.
  398. //
  399. } else if (Node->LinkName.Length == NameLink->LinkName.Length) {
  400. return FALSE;
  401. }
  402. //
  403. // Compare the first characters to figure out the comparison value.
  404. //
  405. } else if (Node->LinkName.Buffer[0] > NameLink->LinkName.Buffer[0]) {
  406. Comparison = GreaterThan;
  407. }
  408. //
  409. // If the tree prefix is greater than the new prefix then
  410. // we go down the left subtree
  411. //
  412. if (Comparison == GreaterThan) {
  413. //
  414. // We want to go down the left subtree, first check to see
  415. // if we have a left subtree
  416. //
  417. if (RtlLeftChild( &Node->Links ) == NULL) {
  418. //
  419. // there isn't a left child so we insert ourselves as the
  420. // new left child
  421. //
  422. RtlInsertAsLeftChild( &Node->Links, &NameLink->Links );
  423. //
  424. // and exit the while loop
  425. //
  426. *RootNode = RtlSplay( &NameLink->Links );
  427. break;
  428. } else {
  429. //
  430. // there is a left child so simply go down that path, and
  431. // go back to the top of the loop
  432. //
  433. Node = CONTAINING_RECORD( RtlLeftChild( &Node->Links ),
  434. NAME_LINK,
  435. Links );
  436. }
  437. } else {
  438. //
  439. // The tree prefix is either less than or a proper prefix
  440. // of the new string. We treat both cases as less than when
  441. // we do insert. So we want to go down the right subtree,
  442. // first check to see if we have a right subtree
  443. //
  444. if (RtlRightChild( &Node->Links ) == NULL) {
  445. //
  446. // These isn't a right child so we insert ourselves as the
  447. // new right child
  448. //
  449. RtlInsertAsRightChild( &Node->Links, &NameLink->Links );
  450. //
  451. // and exit the while loop
  452. //
  453. *RootNode = RtlSplay( &NameLink->Links );
  454. break;
  455. } else {
  456. //
  457. // there is a right child so simply go down that path, and
  458. // go back to the top of the loop
  459. //
  460. Node = CONTAINING_RECORD( RtlRightChild( &Node->Links ),
  461. NAME_LINK,
  462. Links );
  463. }
  464. }
  465. }
  466. #ifdef NTFS_CHECK_SPLAY
  467. NtfsCheckSplay( *RootNode );
  468. #endif
  469. return TRUE;
  470. }
  471. PNAME_LINK
  472. NtfsFindNameLink (
  473. IN PRTL_SPLAY_LINKS *RootNode,
  474. IN PUNICODE_STRING Name
  475. )
  476. /*++
  477. Routine Description:
  478. This routine searches through a splay link tree looking for a match for the
  479. input name. If we find the corresponding name we will rebalance the
  480. tree.
  481. Arguments:
  482. RootNode - Supplies the parent to search.
  483. Name - This is the name to search for. Note if we are doing a case
  484. insensitive search the name would have been upcased already.
  485. Return Value:
  486. PNAME_LINK - The name link found or NULL if there is no match.
  487. --*/
  488. {
  489. PNAME_LINK Node;
  490. PRTL_SPLAY_LINKS Links;
  491. ULONG i;
  492. ULONG MinLength;
  493. PAGED_CODE();
  494. Links = *RootNode;
  495. #ifdef NTFS_CHECK_SPLAY
  496. if (Links != NULL) {
  497. NtfsCheckSplay( Links );
  498. }
  499. #endif
  500. while (Links != NULL) {
  501. Node = CONTAINING_RECORD( Links, NAME_LINK, Links );
  502. //
  503. // If the first characters are equal then compare the full strings.
  504. //
  505. if (Node->LinkName.Buffer[0] == Name->Buffer[0]) {
  506. //
  507. // Figure out the minimum of the two lengths
  508. //
  509. if (Node->LinkName.Length < Name->Length) {
  510. MinLength = Node->LinkName.Length;
  511. } else {
  512. MinLength = Name->Length;
  513. }
  514. //
  515. // Loop through looking at all of the characters in both strings
  516. // testing for equalilty, less than, and greater than
  517. //
  518. i = (ULONG) RtlCompareMemory( Node->LinkName.Buffer, Name->Buffer, MinLength );
  519. //
  520. // Check if we didn't match up to the length of the shorter name.
  521. //
  522. if (i < MinLength) {
  523. if (Node->LinkName.Buffer[i / sizeof( WCHAR )] < Name->Buffer[i / sizeof( WCHAR )]) {
  524. //
  525. // The prefix is less than the full name
  526. // so we go down the right child
  527. //
  528. Links = RtlRightChild( Links );
  529. } else {
  530. //
  531. // The prefix is greater than the full name
  532. // so we go down the left child
  533. //
  534. Links = RtlLeftChild( Links );
  535. }
  536. //
  537. // We match up to the length of the shorter string. If the lengths are different
  538. // then move down the splay tree.
  539. //
  540. } else if (Node->LinkName.Length < Name->Length) {
  541. //
  542. // The prefix is less than the full name
  543. // so we go down the right child
  544. //
  545. Links = RtlRightChild( Links );
  546. } else if (Node->LinkName.Length > Name->Length) {
  547. //
  548. // The prefix is greater than the full name
  549. // so we go down the left child
  550. //
  551. Links = RtlLeftChild( Links );
  552. //
  553. // The strings are of equal lengths.
  554. //
  555. } else {
  556. *RootNode = RtlSplay( Links );
  557. #ifdef NTFS_CHECK_SPLAY
  558. NtfsCheckSplay( *RootNode );
  559. #endif
  560. return Node;
  561. }
  562. //
  563. // The first characters are different. Use them as a key for which
  564. // way to branch.
  565. //
  566. } else if (Node->LinkName.Buffer[0] < Name->Buffer[0]) {
  567. //
  568. // The prefix is less than the full name
  569. // so we go down the right child
  570. //
  571. Links = RtlRightChild( Links );
  572. } else {
  573. //
  574. // The prefix is greater than the full name
  575. // so we go down the left child
  576. //
  577. Links = RtlLeftChild( Links );
  578. }
  579. }
  580. //
  581. // We didn't find the Link.
  582. //
  583. return NULL;
  584. }
  585. //
  586. // Local support routine
  587. //
  588. FSRTL_COMPARISON_RESULT
  589. NtfsFullCompareNames (
  590. IN PUNICODE_STRING NameA,
  591. IN PUNICODE_STRING NameB
  592. )
  593. /*++
  594. Routine Description:
  595. This function compares two names as fast as possible. Note that since
  596. this comparison is case sensitive we can do a direct memory comparison.
  597. Arguments:
  598. NameA & NameB - The names to compare.
  599. Return Value:
  600. COMPARISON - returns
  601. LessThan if NameA < NameB lexicalgraphically,
  602. GreaterThan if NameA > NameB lexicalgraphically,
  603. EqualTo if NameA is equal to NameB
  604. --*/
  605. {
  606. ULONG i;
  607. ULONG MinLength;
  608. PAGED_CODE();
  609. //
  610. // Figure out the minimum of the two lengths
  611. //
  612. if (NameA->Length < NameB->Length) {
  613. MinLength = NameA->Length;
  614. } else {
  615. MinLength = NameB->Length;
  616. }
  617. //
  618. // Loop through looking at all of the characters in both strings
  619. // testing for equalilty, less than, and greater than
  620. //
  621. i = (ULONG) RtlCompareMemory( NameA->Buffer, NameB->Buffer, MinLength );
  622. if (i < MinLength) {
  623. return (NameA->Buffer[i / sizeof( WCHAR )] < NameB->Buffer[i / sizeof( WCHAR )] ?
  624. LessThan :
  625. GreaterThan);
  626. }
  627. if (NameA->Length < NameB->Length) {
  628. return LessThan;
  629. }
  630. if (NameA->Length > NameB->Length) {
  631. return GreaterThan;
  632. }
  633. return EqualTo;
  634. }
  635. #ifdef NTFS_CHECK_SPLAY
  636. VOID
  637. NtfsCheckSplay (
  638. IN PRTL_SPLAY_LINKS Root
  639. )
  640. {
  641. PRTL_SPLAY_LINKS Current;
  642. PAGED_CODE();
  643. Current = Root;
  644. //
  645. // Root must point to itself.
  646. //
  647. if (Current->Parent != Current) {
  648. KdPrint(("NTFS: Bad splay root\n", 0));
  649. DbgBreakPoint();
  650. }
  651. goto LeftChild;
  652. while (TRUE) {
  653. LeftChild:
  654. //
  655. // If there is a left child then verify it.
  656. //
  657. if (Current->LeftChild != NULL) {
  658. //
  659. // The child can't point to itself and
  660. // the current node must be the parent of the
  661. // child.
  662. //
  663. if ((Current->LeftChild == Current) ||
  664. (Current->LeftChild->Parent != Current)) {
  665. KdPrint(("NTFS: Bad left child\n", 0));
  666. DbgBreakPoint();
  667. }
  668. //
  669. // Go to the left child and verify it.
  670. //
  671. Current = Current->LeftChild;
  672. goto LeftChild;
  673. }
  674. //
  675. // If there is no left child then check for a right child.
  676. //
  677. goto RightChild;
  678. RightChild:
  679. //
  680. // If there is a right child then verify it.
  681. //
  682. if (Current->RightChild != NULL) {
  683. //
  684. // The child can't point to itself and
  685. // the current node must be the parent of the
  686. // child.
  687. //
  688. if ((Current->RightChild == Current) ||
  689. (Current->RightChild->Parent != Current)) {
  690. KdPrint(("NTFS: Bad Right child\n", 0));
  691. DbgBreakPoint();
  692. }
  693. //
  694. // Go to the right child and verify it. We always
  695. // start in the left child of a new node.
  696. //
  697. Current = Current->RightChild;
  698. goto LeftChild;
  699. }
  700. //
  701. // There is no right child. If we are a right child then move up to
  702. // the parent and keep going until we reach the root or reach a left child.
  703. //
  704. goto Parent;
  705. Parent:
  706. //
  707. // We may be in the root now.
  708. //
  709. if (Current == Root) {
  710. return;
  711. }
  712. //
  713. // If we are a left child then go to the parent and look for a right child.
  714. //
  715. if (Current == Current->Parent->LeftChild) {
  716. Current = Current->Parent;
  717. goto RightChild;
  718. }
  719. //
  720. // We are a right child. Go to the parent and check again.
  721. //
  722. Current = Current->Parent;
  723. goto Parent;
  724. }
  725. }
  726. #endif