Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

680 lines
16 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ColatSup.c
  5. Abstract:
  6. This module implements the collation routine callbacks for Ntfs
  7. Author:
  8. Tom Miller [TomM] 26-Nov-1991
  9. Revision History:
  10. --*/
  11. #include "NtfsProc.h"
  12. //
  13. // Local debug trace level
  14. //
  15. #define Dbg (DEBUG_TRACE_INDEXSUP)
  16. FSRTL_COMPARISON_RESULT
  17. NtfsFileCompareValues (
  18. IN PWCH UnicodeTable,
  19. IN ULONG UnicodeTableSize,
  20. IN PVOID Value,
  21. IN PINDEX_ENTRY IndexEntry,
  22. IN FSRTL_COMPARISON_RESULT WildCardIs,
  23. IN BOOLEAN IgnoreCase
  24. );
  25. BOOLEAN
  26. NtfsFileIsInExpression (
  27. IN PWCH UnicodeTable,
  28. IN PVOID Value,
  29. IN PINDEX_ENTRY IndexEntry,
  30. IN BOOLEAN IgnoreCase
  31. );
  32. BOOLEAN
  33. NtfsFileIsEqual (
  34. IN PWCH UnicodeTable,
  35. IN PVOID Value,
  36. IN PINDEX_ENTRY IndexEntry,
  37. IN BOOLEAN IgnoreCase
  38. );
  39. BOOLEAN
  40. NtfsFileContainsWildcards (
  41. IN PVOID Value
  42. );
  43. VOID
  44. NtfsFileUpcaseValue (
  45. IN PWCH UnicodeTable,
  46. IN ULONG UnicodeTableSize,
  47. IN PVOID Value
  48. );
  49. FSRTL_COMPARISON_RESULT
  50. DummyCompareValues (
  51. IN PWCH UnicodeTable,
  52. IN ULONG UnicodeTableSize,
  53. IN PVOID Value,
  54. IN PINDEX_ENTRY IndexEntry,
  55. IN FSRTL_COMPARISON_RESULT WildCardIs,
  56. IN BOOLEAN IgnoreCase
  57. );
  58. BOOLEAN
  59. DummyIsInExpression (
  60. IN PWCH UnicodeTable,
  61. IN PVOID Value,
  62. IN PINDEX_ENTRY IndexEntry,
  63. IN BOOLEAN IgnoreCase
  64. );
  65. BOOLEAN
  66. DummyIsEqual (
  67. IN PWCH UnicodeTable,
  68. IN PVOID Value,
  69. IN PINDEX_ENTRY IndexEntry,
  70. IN BOOLEAN IgnoreCase
  71. );
  72. BOOLEAN
  73. DummyContainsWildcards (
  74. IN PVOID Value
  75. );
  76. VOID
  77. DummyUpcaseValue (
  78. IN PWCH UnicodeTable,
  79. IN ULONG UnicodeTableSize,
  80. IN OUT PVOID Value
  81. );
  82. PCOMPARE_VALUES NtfsCompareValues[COLLATION_NUMBER_RULES] = {&DummyCompareValues,
  83. &NtfsFileCompareValues,
  84. &DummyCompareValues};
  85. PIS_IN_EXPRESSION NtfsIsInExpression[COLLATION_NUMBER_RULES] = {&DummyIsInExpression,
  86. &NtfsFileIsInExpression,
  87. &DummyIsInExpression};
  88. PARE_EQUAL NtfsIsEqual[COLLATION_NUMBER_RULES] = {&DummyIsEqual,
  89. &NtfsFileIsEqual,
  90. &DummyIsEqual};
  91. PCONTAINS_WILDCARD NtfsContainsWildcards[COLLATION_NUMBER_RULES] = {&DummyContainsWildcards,
  92. &NtfsFileContainsWildcards,
  93. &DummyContainsWildcards};
  94. PUPCASE_VALUE NtfsUpcaseValue[COLLATION_NUMBER_RULES] = {&DummyUpcaseValue,
  95. &NtfsFileUpcaseValue,
  96. &DummyUpcaseValue};
  97. #ifdef ALLOC_PRAGMA
  98. #pragma alloc_text(PAGE, DummyCompareValues)
  99. #pragma alloc_text(PAGE, DummyContainsWildcards)
  100. #pragma alloc_text(PAGE, DummyIsEqual)
  101. #pragma alloc_text(PAGE, DummyIsInExpression)
  102. #pragma alloc_text(PAGE, DummyUpcaseValue)
  103. #pragma alloc_text(PAGE, NtfsFileCompareValues)
  104. #pragma alloc_text(PAGE, NtfsFileContainsWildcards)
  105. #pragma alloc_text(PAGE, NtfsFileIsEqual)
  106. #pragma alloc_text(PAGE, NtfsFileIsInExpression)
  107. #pragma alloc_text(PAGE, NtfsFileNameIsInExpression)
  108. #pragma alloc_text(PAGE, NtfsFileNameIsEqual)
  109. #pragma alloc_text(PAGE, NtfsFileUpcaseValue)
  110. #endif
  111. FSRTL_COMPARISON_RESULT
  112. NtfsFileCompareValues (
  113. IN PWCH UnicodeTable,
  114. IN ULONG UnicodeTableSize,
  115. IN PVOID Value,
  116. IN PINDEX_ENTRY IndexEntry,
  117. IN FSRTL_COMPARISON_RESULT WildCardIs,
  118. IN BOOLEAN IgnoreCase
  119. )
  120. /*++
  121. RoutineDescription:
  122. This routine is called to compare a file name expression (the value) with
  123. a file name from the index to see if it is less than, equal to or greater
  124. than. If a wild card is encountered in the expression, WildCardIs is
  125. returned.
  126. Arguments:
  127. Value - Pointer to the value expression, which is a FILE_NAME.
  128. IndexEntry - Pointer to the index entry being compared to.
  129. WildCardIs - Value to be returned if a wild card is encountered in the
  130. expression.
  131. IgnoreCase - whether case should be ignored or not.
  132. ReturnValue:
  133. Result of the comparison
  134. --*/
  135. {
  136. PFILE_NAME ValueName, IndexName;
  137. UNICODE_STRING ValueString, IndexString;
  138. PAGED_CODE();
  139. //
  140. // Point to the file name attribute records.
  141. //
  142. ValueName = (PFILE_NAME)Value;
  143. IndexName = (PFILE_NAME)(IndexEntry + 1);
  144. //
  145. // Build the unicode strings and call namesup.
  146. //
  147. ValueString.Length =
  148. ValueString.MaximumLength = (USHORT)ValueName->FileNameLength << 1;
  149. ValueString.Buffer = &ValueName->FileName[0];
  150. IndexString.Length =
  151. IndexString.MaximumLength = (USHORT)IndexName->FileNameLength << 1;
  152. IndexString.Buffer = &IndexName->FileName[0];
  153. return NtfsCollateNames( UnicodeTable,
  154. UnicodeTableSize,
  155. &ValueString,
  156. &IndexString,
  157. WildCardIs,
  158. IgnoreCase );
  159. }
  160. BOOLEAN
  161. NtfsFileIsInExpression (
  162. IN PWCH UnicodeTable,
  163. IN PVOID Value,
  164. IN PINDEX_ENTRY IndexEntry,
  165. IN BOOLEAN IgnoreCase
  166. )
  167. /*++
  168. RoutineDescription:
  169. This routine is called to compare a file name expression (the value) with
  170. a file name from the index to see if the file name is a match in this expression.
  171. Arguments:
  172. Value - Pointer to the value expression, which is a FILE_NAME.
  173. IndexEntry - Pointer to the index entry being compared to.
  174. IgnoreCase - whether case should be ignored or not.
  175. ReturnValue:
  176. TRUE - if the file name is in the specified expression.
  177. --*/
  178. {
  179. PFILE_NAME ValueName, IndexName;
  180. UNICODE_STRING ValueString, IndexString;
  181. PAGED_CODE();
  182. if (NtfsSegmentNumber( &IndexEntry->FileReference ) < FIRST_USER_FILE_NUMBER &&
  183. NtfsProtectSystemFiles) {
  184. return FALSE;
  185. }
  186. //
  187. // Point to the file name attribute records.
  188. //
  189. ValueName = (PFILE_NAME)Value;
  190. IndexName = (PFILE_NAME)(IndexEntry + 1);
  191. //
  192. // Build the unicode strings and call namesup.
  193. //
  194. ValueString.Length =
  195. ValueString.MaximumLength = (USHORT)ValueName->FileNameLength << 1;
  196. ValueString.Buffer = &ValueName->FileName[0];
  197. IndexString.Length =
  198. IndexString.MaximumLength = (USHORT)IndexName->FileNameLength << 1;
  199. IndexString.Buffer = &IndexName->FileName[0];
  200. return NtfsIsNameInExpression( UnicodeTable,
  201. &ValueString,
  202. &IndexString,
  203. IgnoreCase );
  204. }
  205. BOOLEAN
  206. NtfsFileIsEqual (
  207. IN PWCH UnicodeTable,
  208. IN PVOID Value,
  209. IN PINDEX_ENTRY IndexEntry,
  210. IN BOOLEAN IgnoreCase
  211. )
  212. /*++
  213. RoutineDescription:
  214. This routine is called to compare a constant file name (the value) with
  215. a file name from the index to see if the file name is an exact match.
  216. Arguments:
  217. Value - Pointer to the value expression, which is a FILE_NAME.
  218. IndexEntry - Pointer to the index entry being compared to.
  219. IgnoreCase - whether case should be ignored or not.
  220. ReturnValue:
  221. TRUE - if the file name is a constant match.
  222. --*/
  223. {
  224. PFILE_NAME ValueName, IndexName;
  225. UNICODE_STRING ValueString, IndexString;
  226. PAGED_CODE();
  227. //
  228. // Point to the file name attribute records.
  229. //
  230. ValueName = (PFILE_NAME)Value;
  231. IndexName = (PFILE_NAME)(IndexEntry + 1);
  232. //
  233. // Build the unicode strings and call namesup.
  234. //
  235. ValueString.Length =
  236. ValueString.MaximumLength = (USHORT)ValueName->FileNameLength << 1;
  237. ValueString.Buffer = &ValueName->FileName[0];
  238. IndexString.Length =
  239. IndexString.MaximumLength = (USHORT)IndexName->FileNameLength << 1;
  240. IndexString.Buffer = &IndexName->FileName[0];
  241. return NtfsAreNamesEqual( UnicodeTable,
  242. &ValueString,
  243. &IndexString,
  244. IgnoreCase );
  245. }
  246. BOOLEAN
  247. NtfsFileContainsWildcards (
  248. IN PVOID Value
  249. )
  250. /*++
  251. RoutineDescription:
  252. This routine is called to see if a file name attribute contains wildcards.
  253. Arguments:
  254. Value - Pointer to the value expression, which is a FILE_NAME.
  255. ReturnValue:
  256. TRUE - if the file name contains a wild card.
  257. --*/
  258. {
  259. PFILE_NAME ValueName;
  260. UNICODE_STRING ValueString;
  261. PAGED_CODE();
  262. //
  263. // Point to the file name attribute records.
  264. //
  265. ValueName = (PFILE_NAME)Value;
  266. //
  267. // Build the unicode strings and call namesup.
  268. //
  269. ValueString.Length =
  270. ValueString.MaximumLength = (USHORT)ValueName->FileNameLength << 1;
  271. ValueString.Buffer = &ValueName->FileName[0];
  272. return FsRtlDoesNameContainWildCards( &ValueString );
  273. }
  274. VOID
  275. NtfsFileUpcaseValue (
  276. IN PWCH UnicodeTable,
  277. IN ULONG UnicodeTableSize,
  278. IN PVOID Value
  279. )
  280. /*++
  281. RoutineDescription:
  282. This routine is called to upcase a file name attribute in place.
  283. Arguments:
  284. Value - Pointer to the value expression, which is a FILE_NAME.
  285. ValueLength - Length of the value expression in bytes.
  286. ReturnValue:
  287. None.
  288. --*/
  289. {
  290. PFILE_NAME ValueName;
  291. UNICODE_STRING ValueString;
  292. PAGED_CODE();
  293. //
  294. // Point to the file name attribute records.
  295. //
  296. ValueName = (PFILE_NAME)Value;
  297. //
  298. // Build the unicode strings and call namesup.
  299. //
  300. ValueString.Length =
  301. ValueString.MaximumLength = (USHORT)ValueName->FileNameLength << 1;
  302. ValueString.Buffer = &ValueName->FileName[0];
  303. NtfsUpcaseName( UnicodeTable, UnicodeTableSize, &ValueString );
  304. return;
  305. }
  306. //
  307. // The other collation rules are currently unused.
  308. //
  309. FSRTL_COMPARISON_RESULT
  310. DummyCompareValues (
  311. IN PWCH UnicodeTable,
  312. IN ULONG UnicodeTableSize,
  313. IN PVOID Value,
  314. IN PINDEX_ENTRY IndexEntry,
  315. IN FSRTL_COMPARISON_RESULT WildCardIs,
  316. IN BOOLEAN IgnoreCase
  317. )
  318. {
  319. //
  320. // Most parameters are ignored since this is a catch-all for
  321. // a corrupt volume. We simply raise to indicate the corruption
  322. //
  323. UNREFERENCED_PARAMETER( UnicodeTable );
  324. UNREFERENCED_PARAMETER( UnicodeTableSize );
  325. UNREFERENCED_PARAMETER( IgnoreCase );
  326. UNREFERENCED_PARAMETER( WildCardIs );
  327. UNREFERENCED_PARAMETER( IndexEntry );
  328. UNREFERENCED_PARAMETER( Value );
  329. PAGED_CODE();
  330. ASSERTMSG("Unused collation rule\n", FALSE);
  331. return EqualTo;
  332. }
  333. BOOLEAN
  334. DummyIsInExpression (
  335. IN PWCH UnicodeTable,
  336. IN PVOID Value,
  337. IN PINDEX_ENTRY IndexEntry,
  338. IN BOOLEAN IgnoreCase
  339. )
  340. {
  341. //
  342. // Most parameters are ignored since this is a catch-all for
  343. // a corrupt volume. We simply raise to indicate the corruption
  344. //
  345. UNREFERENCED_PARAMETER( UnicodeTable );
  346. UNREFERENCED_PARAMETER( Value );
  347. UNREFERENCED_PARAMETER( IndexEntry );
  348. UNREFERENCED_PARAMETER( IgnoreCase );
  349. PAGED_CODE();
  350. ASSERTMSG("Unused collation rule\n", FALSE);
  351. return EqualTo;
  352. }
  353. BOOLEAN
  354. DummyIsEqual (
  355. IN PWCH UnicodeTable,
  356. IN PVOID Value,
  357. IN PINDEX_ENTRY IndexEntry,
  358. IN BOOLEAN IgnoreCase
  359. )
  360. {
  361. //
  362. // Most parameters are ignored since this is a catch-all for
  363. // a corrupt volume. We simply raise to indicate the corruption
  364. //
  365. UNREFERENCED_PARAMETER( UnicodeTable );
  366. UNREFERENCED_PARAMETER( Value );
  367. UNREFERENCED_PARAMETER( IndexEntry );
  368. UNREFERENCED_PARAMETER( IgnoreCase );
  369. PAGED_CODE();
  370. ASSERTMSG("Unused collation rule\n", FALSE);
  371. return EqualTo;
  372. }
  373. BOOLEAN
  374. DummyContainsWildcards (
  375. IN PVOID Value
  376. )
  377. {
  378. //
  379. // Most parameters are ignored since this is a catch-all for
  380. // a corrupt volume. We simply raise to indicate the corruption
  381. //
  382. UNREFERENCED_PARAMETER( Value );
  383. PAGED_CODE();
  384. ASSERTMSG("Unused collation rule\n", FALSE);
  385. return EqualTo;
  386. }
  387. VOID
  388. DummyUpcaseValue (
  389. IN PWCH UnicodeTable,
  390. IN ULONG UnicodeTableSize,
  391. IN PVOID Value
  392. )
  393. {
  394. //
  395. // Most parameters are ignored since this is a catch-all for
  396. // a corrupt volume. We simply raise to indicate the corruption
  397. //
  398. UNREFERENCED_PARAMETER( UnicodeTable );
  399. UNREFERENCED_PARAMETER( UnicodeTableSize );
  400. UNREFERENCED_PARAMETER( Value );
  401. PAGED_CODE();
  402. ASSERTMSG("Unused collation rule\n", FALSE);
  403. return;
  404. }
  405. //
  406. // The following routines are not general index match functions, but rather
  407. // specific file name match functions used only for automatic Dos Name generation.
  408. //
  409. BOOLEAN
  410. NtfsFileNameIsInExpression (
  411. IN PWCH UnicodeTable,
  412. IN PFILE_NAME ExpressionName,
  413. IN PFILE_NAME FileName,
  414. IN BOOLEAN IgnoreCase
  415. )
  416. /*++
  417. RoutineDescription:
  418. This is a special match routine for matching FILE_NAME attributes only,
  419. which is used only by the special code paths dealing with automatically
  420. generated short names.
  421. This routine is called to compare a file name expression (the value) with
  422. a file name from the index to see if the file name is a match in this expression.
  423. Arguments:
  424. ExpressionName - pointer to the expression for file name.
  425. FileName - Pointer to the FileName to match.
  426. IgnoreCase - whether case should be ignored or not.
  427. ReturnValue:
  428. TRUE - if the file name is in the specified expression.
  429. --*/
  430. {
  431. UNICODE_STRING ExpressionString, FileString;
  432. PAGED_CODE();
  433. //
  434. // Build the unicode strings and call namesup.
  435. //
  436. ExpressionString.Length =
  437. ExpressionString.MaximumLength = (USHORT)ExpressionName->FileNameLength << 1;
  438. ExpressionString.Buffer = &ExpressionName->FileName[0];
  439. FileString.Length =
  440. FileString.MaximumLength = (USHORT)FileName->FileNameLength << 1;
  441. FileString.Buffer = &FileName->FileName[0];
  442. return NtfsIsNameInExpression( UnicodeTable,
  443. &ExpressionString,
  444. &FileString,
  445. IgnoreCase );
  446. }
  447. BOOLEAN
  448. NtfsFileNameIsEqual (
  449. IN PWCH UnicodeTable,
  450. IN PFILE_NAME ExpressionName,
  451. IN PFILE_NAME FileName,
  452. IN BOOLEAN IgnoreCase
  453. )
  454. /*++
  455. RoutineDescription:
  456. This is a special match routine for matching FILE_NAME attributes only,
  457. which is used only by the special code paths dealing with automatically
  458. generated short names.
  459. This routine is called to compare a constant file name (the value) with
  460. a file name from the index to see if the file name is an exact match.
  461. Arguments:
  462. ExpressionName - pointer to the expression for file name.
  463. FileName - Pointer to the FileName to match.
  464. IgnoreCase - whether case should be ignored or not.
  465. ReturnValue:
  466. TRUE - if the file name is a constant match.
  467. --*/
  468. {
  469. UNICODE_STRING ExpressionString, FileString;
  470. PAGED_CODE();
  471. //
  472. // Build the unicode strings and call namesup.
  473. //
  474. ExpressionString.Length =
  475. ExpressionString.MaximumLength = (USHORT)ExpressionName->FileNameLength << 1;
  476. ExpressionString.Buffer = &ExpressionName->FileName[0];
  477. FileString.Length =
  478. FileString.MaximumLength = (USHORT)FileName->FileNameLength << 1;
  479. FileString.Buffer = &FileName->FileName[0];
  480. return NtfsAreNamesEqual( UnicodeTable,
  481. &ExpressionString,
  482. &FileString,
  483. IgnoreCase );
  484. }