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.

1009 lines
24 KiB

  1. /*++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. NameSup.c
  5. Abstract:
  6. This module implements the Fat Name support routines
  7. // @@BEGIN_DDKSPLIT
  8. Author:
  9. Gary Kimura [GaryKi] & Tom Miller [TomM] 20-Feb-1990
  10. Revision History:
  11. // @@END_DDKSPLIT
  12. --*/
  13. #include "FatProcs.h"
  14. #define Dbg (DEBUG_TRACE_NAMESUP)
  15. #ifdef ALLOC_PRAGMA
  16. #pragma alloc_text(PAGE, Fat8dot3ToString)
  17. #pragma alloc_text(PAGE, FatIsNameInExpression)
  18. #pragma alloc_text(PAGE, FatStringTo8dot3)
  19. #pragma alloc_text(PAGE, FatSetFullFileNameInFcb)
  20. #pragma alloc_text(PAGE, FatGetUnicodeNameFromFcb)
  21. #pragma alloc_text(PAGE, FatUnicodeToUpcaseOem)
  22. #pragma alloc_text(PAGE, FatSelectNames)
  23. #pragma alloc_text(PAGE, FatEvaluateNameCase)
  24. #pragma alloc_text(PAGE, FatSpaceInName)
  25. #endif
  26. BOOLEAN
  27. FatIsNameInExpression (
  28. IN PIRP_CONTEXT IrpContext,
  29. IN OEM_STRING Expression,
  30. IN OEM_STRING Name
  31. )
  32. /*++
  33. Routine Description:
  34. This routine compare a name and an expression and tells the caller if
  35. the name is equal to or not equal to the expression. The input name
  36. cannot contain wildcards, while the expression may contain wildcards.
  37. Arguments:
  38. Expression - Supplies the input expression to check against
  39. The caller must have already upcased the Expression.
  40. Name - Supplies the input name to check for. The caller must have
  41. already upcased the name.
  42. Return Value:
  43. BOOLEAN - TRUE if Name is an element in the set of strings denoted
  44. by the input Expression and FALSE otherwise.
  45. --*/
  46. {
  47. //
  48. // Call the appropriate FsRtl routine do to the real work
  49. //
  50. return FsRtlIsDbcsInExpression( &Expression,
  51. &Name );
  52. UNREFERENCED_PARAMETER( IrpContext );
  53. }
  54. VOID
  55. FatStringTo8dot3 (
  56. IN PIRP_CONTEXT IrpContext,
  57. IN OEM_STRING InputString,
  58. OUT PFAT8DOT3 Output8dot3
  59. )
  60. /*++
  61. Routine Description:
  62. Convert a string into fat 8.3 format. The string must not contain
  63. any wildcards.
  64. Arguments:
  65. InputString - Supplies the input string to convert
  66. Output8dot3 - Receives the converted string, the memory must be supplied
  67. by the caller.
  68. Return Value:
  69. None.
  70. --*/
  71. {
  72. ULONG i;
  73. ULONG j;
  74. DebugTrace(+1, Dbg, "FatStringTo8dot3\n", 0);
  75. DebugTrace( 0, Dbg, "InputString = %Z\n", &InputString);
  76. ASSERT( InputString.Length <= 12 );
  77. //
  78. // Make the output name all blanks
  79. //
  80. RtlFillMemory( Output8dot3, 11, UCHAR_SP );
  81. //
  82. // Copy over the first part of the file name. Stop when we get to
  83. // the end of the input string or a dot.
  84. //
  85. for (i = 0;
  86. (i < (ULONG)InputString.Length) && (InputString.Buffer[i] != '.');
  87. i += 1) {
  88. (*Output8dot3)[i] = InputString.Buffer[i];
  89. }
  90. //
  91. // Check if we need to process an extension
  92. //
  93. if (i < (ULONG)InputString.Length) {
  94. //
  95. // Make sure we have a dot and then skip over it.
  96. //
  97. ASSERT( (InputString.Length - i) <= 4 );
  98. ASSERT( InputString.Buffer[i] == '.' );
  99. i += 1;
  100. //
  101. // Copy over the extension. Stop when we get to the
  102. // end of the input string.
  103. //
  104. for (j = 8; (i < (ULONG)InputString.Length); j += 1, i += 1) {
  105. (*Output8dot3)[j] = InputString.Buffer[i];
  106. }
  107. }
  108. //
  109. // Before we return check if we should translate the first character
  110. // from 0xe5 to 0x5.
  111. //
  112. if ((*Output8dot3)[0] == 0xe5) {
  113. (*Output8dot3)[0] = FAT_DIRENT_REALLY_0E5;
  114. }
  115. DebugTrace(-1, Dbg, "FatStringTo8dot3 -> (VOID)\n", 0);
  116. UNREFERENCED_PARAMETER( IrpContext );
  117. return;
  118. }
  119. VOID
  120. Fat8dot3ToString (
  121. IN PIRP_CONTEXT IrpContext,
  122. IN PDIRENT Dirent,
  123. IN BOOLEAN RestoreCase,
  124. OUT POEM_STRING OutputString
  125. )
  126. /*++
  127. Routine Description:
  128. Convert fat 8.3 format into a string. The 8.3 name must be well formed.
  129. Arguments:
  130. Dirent - Supplies the input 8.3 name to convert
  131. RestoreCase - If TRUE, then the magic reserved bits are used to restore
  132. the original case.
  133. OutputString - Receives the converted name, the memory must be supplied
  134. by the caller.
  135. Return Value:
  136. None
  137. --*/
  138. {
  139. ULONG DirentIndex, StringIndex;
  140. ULONG BaseLength, ExtensionLength;
  141. DebugTrace(+1, Dbg, "Fat8dot3ToString\n", 0);
  142. //
  143. // First, find the length of the base component.
  144. //
  145. for (BaseLength = 8; BaseLength > 0; BaseLength -= 1) {
  146. if (Dirent->FileName[BaseLength - 1] != UCHAR_SP) {
  147. break;
  148. }
  149. }
  150. //
  151. // Now find the length of the extension.
  152. //
  153. for (ExtensionLength = 3; ExtensionLength > 0; ExtensionLength -= 1) {
  154. if (Dirent->FileName[8 + ExtensionLength - 1] != UCHAR_SP) {
  155. break;
  156. }
  157. }
  158. //
  159. // If there was a base part, copy it and check the case. Don't forget
  160. // if the first character needs to be changed from 0x05 to 0xe5.
  161. //
  162. if (BaseLength != 0) {
  163. RtlCopyMemory( OutputString->Buffer, Dirent->FileName, BaseLength );
  164. if (OutputString->Buffer[0] == FAT_DIRENT_REALLY_0E5) {
  165. OutputString->Buffer[0] = (CHAR)0xe5;
  166. }
  167. //
  168. // Now if we are to restore case, look for A-Z
  169. //
  170. if (FatData.ChicagoMode &&
  171. RestoreCase &&
  172. FlagOn(Dirent->NtByte, FAT_DIRENT_NT_BYTE_8_LOWER_CASE)) {
  173. for (StringIndex = 0; StringIndex < BaseLength; StringIndex += 1) {
  174. //
  175. // Depending on whether the media was built in a system that was
  176. // running with "code page invariance" (see FatEvaluateNameCase),
  177. // there could be double-byte OEM characters lying in wait here.
  178. // Gotta skip them.
  179. //
  180. if (FsRtlIsLeadDbcsCharacter(OutputString->Buffer[StringIndex])) {
  181. StringIndex += 1;
  182. continue;
  183. }
  184. if ((OutputString->Buffer[StringIndex] >= 'A') &&
  185. (OutputString->Buffer[StringIndex] <= 'Z')) {
  186. OutputString->Buffer[StringIndex] += 'a' - 'A';
  187. }
  188. }
  189. }
  190. }
  191. //
  192. // If there was an extension, copy that over. Else we now know the
  193. // size of the string.
  194. //
  195. if (ExtensionLength != 0) {
  196. PUCHAR o, d;
  197. //
  198. // Now add the dot
  199. //
  200. OutputString->Buffer[BaseLength++] = '.';
  201. //
  202. // Copy over the extension into the output buffer.
  203. //
  204. o = &OutputString->Buffer[BaseLength];
  205. d = &Dirent->FileName[8];
  206. switch (ExtensionLength) {
  207. case 3:
  208. *o++ = *d++;
  209. case 2:
  210. *o++ = *d++;
  211. case 1:
  212. *o++ = *d++;
  213. }
  214. //
  215. // Set the output string length
  216. //
  217. OutputString->Length = (USHORT)(BaseLength + ExtensionLength);
  218. //
  219. // Now if we are to restore case, look for A-Z
  220. //
  221. if (FatData.ChicagoMode &&
  222. RestoreCase &&
  223. FlagOn(Dirent->NtByte, FAT_DIRENT_NT_BYTE_3_LOWER_CASE)) {
  224. for (StringIndex = BaseLength;
  225. StringIndex < OutputString->Length;
  226. StringIndex++ ) {
  227. //
  228. // Depending on whether the media was built in a system that was
  229. // running with "code page invariance" (see FatEvaluateNameCase),
  230. // there could be double-byte OEM characters lying in wait here.
  231. // Gotta skip them.
  232. //
  233. if (FsRtlIsLeadDbcsCharacter(OutputString->Buffer[StringIndex])) {
  234. StringIndex += 1;
  235. continue;
  236. }
  237. if ((OutputString->Buffer[StringIndex] >= 'A') &&
  238. (OutputString->Buffer[StringIndex] <= 'Z')) {
  239. OutputString->Buffer[StringIndex] += 'a' - 'A';
  240. }
  241. }
  242. }
  243. } else {
  244. //
  245. // Set the output string length
  246. //
  247. OutputString->Length = (USHORT)BaseLength;
  248. }
  249. //
  250. // And return to our caller
  251. //
  252. DebugTrace(-1, Dbg, "Fat8dot3ToString, OutputString = \"%Z\" -> VOID\n", OutputString);
  253. UNREFERENCED_PARAMETER( IrpContext );
  254. return;
  255. }
  256. VOID
  257. FatGetUnicodeNameFromFcb (
  258. IN PIRP_CONTEXT IrpContext,
  259. IN PFCB Fcb,
  260. IN OUT PUNICODE_STRING Lfn
  261. )
  262. /*++
  263. Routine Description:
  264. This routine will return the unicode name for a given Fcb. If the
  265. file has an LFN, it will return this. Otherwise it will return
  266. the UNICODE conversion of the Oem name, properly cased.
  267. Arguments:
  268. Fcb - Supplies the Fcb to query.
  269. Lfn - Supplies a string that already has enough storage for the
  270. full unicode name.
  271. Return Value:
  272. None
  273. --*/
  274. {
  275. PDIRENT Dirent;
  276. PBCB DirentBcb = NULL;
  277. ULONG DirentByteOffset;
  278. CCB LocalCcb;
  279. ASSERT((MAX_LFN_CHARACTERS * sizeof( WCHAR)) == Lfn->MaximumLength);
  280. //
  281. // We'll start by locating the dirent for the name.
  282. //
  283. FatStringTo8dot3( IrpContext,
  284. Fcb->ShortName.Name.Oem,
  285. &LocalCcb.OemQueryTemplate.Constant );
  286. LocalCcb.Flags = 0;
  287. LocalCcb.UnicodeQueryTemplate.Length = 0;
  288. LocalCcb.ContainsWildCards = FALSE;
  289. FatLocateDirent( IrpContext,
  290. Fcb->ParentDcb,
  291. &LocalCcb,
  292. Fcb->LfnOffsetWithinDirectory,
  293. &Dirent,
  294. &DirentBcb,
  295. &DirentByteOffset,
  296. NULL,
  297. Lfn);
  298. try {
  299. //
  300. // If we didn't find the Dirent, something is terribly wrong.
  301. //
  302. if ((DirentBcb == NULL) ||
  303. (DirentByteOffset != Fcb->DirentOffsetWithinDirectory)) {
  304. FatRaiseStatus( IrpContext, STATUS_FILE_INVALID );
  305. }
  306. //
  307. // Check for the easy case.
  308. //
  309. if (Lfn->Length == 0) {
  310. NTSTATUS Status;
  311. OEM_STRING ShortName;
  312. UCHAR ShortNameBuffer[12];
  313. //
  314. // If we thought that there was an LFN here and didn't find one,
  315. // we're as dead. This shouldn't happen in normal operation, but
  316. // if someone scrambles a directory by hand ...
  317. //
  318. ASSERT( Fcb->LfnOffsetWithinDirectory == Fcb->DirentOffsetWithinDirectory );
  319. if (Fcb->LfnOffsetWithinDirectory != Fcb->DirentOffsetWithinDirectory) {
  320. FatRaiseStatus( IrpContext, STATUS_FILE_INVALID );
  321. }
  322. //
  323. // There is no LFN, so manufacture a UNICODE name.
  324. //
  325. ShortName.Length = 0;
  326. ShortName.MaximumLength = 12;
  327. ShortName.Buffer = ShortNameBuffer;
  328. Fat8dot3ToString( IrpContext, Dirent, TRUE, &ShortName );
  329. //
  330. // OK, now convert this string to UNICODE
  331. //
  332. Status = RtlOemStringToCountedUnicodeString( Lfn,
  333. &ShortName,
  334. FALSE );
  335. ASSERT( Status == STATUS_SUCCESS );
  336. }
  337. } finally {
  338. FatUnpinBcb( IrpContext, DirentBcb );
  339. }
  340. }
  341. VOID
  342. FatSetFullFileNameInFcb (
  343. IN PIRP_CONTEXT IrpContext,
  344. IN PFCB Fcb
  345. )
  346. /*++
  347. Routine Description:
  348. If the FullFileName field in the Fcb has not yet been filled in, we
  349. proceed to do so.
  350. Arguments:
  351. Fcb - Supplies the file.
  352. Return Value:
  353. None
  354. --*/
  355. {
  356. if (Fcb->FullFileName.Buffer == NULL) {
  357. UNICODE_STRING Lfn;
  358. PFCB TmpFcb = Fcb;
  359. PFCB StopFcb;
  360. PWCHAR TmpBuffer;
  361. ULONG PathLength = 0;
  362. //
  363. // We will assume we do this infrequently enough, that it's OK to
  364. // to a pool allocation here.
  365. //
  366. Lfn.Length = 0;
  367. Lfn.MaximumLength = MAX_LFN_CHARACTERS * sizeof(WCHAR);
  368. Lfn.Buffer = FsRtlAllocatePoolWithTag( PagedPool,
  369. MAX_LFN_CHARACTERS * sizeof(WCHAR),
  370. TAG_FILENAME_BUFFER );
  371. try {
  372. //
  373. // First determine how big the name will be. If we find an
  374. // ancestor with a FullFileName, our work is easier.
  375. //
  376. while (TmpFcb != Fcb->Vcb->RootDcb) {
  377. if ((TmpFcb != Fcb) && (TmpFcb->FullFileName.Buffer != NULL)) {
  378. PathLength += TmpFcb->FullFileName.Length;
  379. Fcb->FullFileName.Buffer = FsRtlAllocatePoolWithTag( PagedPool,
  380. PathLength,
  381. TAG_FILENAME_BUFFER );
  382. RtlCopyMemory( Fcb->FullFileName.Buffer,
  383. TmpFcb->FullFileName.Buffer,
  384. TmpFcb->FullFileName.Length );
  385. break;
  386. }
  387. PathLength += TmpFcb->FinalNameLength + sizeof(WCHAR);
  388. TmpFcb = TmpFcb->ParentDcb;
  389. }
  390. //
  391. // If FullFileName.Buffer is still NULL, allocate it.
  392. //
  393. if (Fcb->FullFileName.Buffer == NULL) {
  394. Fcb->FullFileName.Buffer = FsRtlAllocatePoolWithTag( PagedPool,
  395. PathLength,
  396. TAG_FILENAME_BUFFER );
  397. }
  398. StopFcb = TmpFcb;
  399. TmpFcb = Fcb;
  400. TmpBuffer = Fcb->FullFileName.Buffer + PathLength / sizeof(WCHAR);
  401. Fcb->FullFileName.Length =
  402. Fcb->FullFileName.MaximumLength = (USHORT)PathLength;
  403. while (TmpFcb != StopFcb) {
  404. FatGetUnicodeNameFromFcb( IrpContext,
  405. TmpFcb,
  406. &Lfn );
  407. TmpBuffer -= Lfn.Length / sizeof(WCHAR);
  408. RtlCopyMemory( TmpBuffer, Lfn.Buffer, Lfn.Length );
  409. TmpBuffer -= 1;
  410. *TmpBuffer = L'\\';
  411. TmpFcb = TmpFcb->ParentDcb;
  412. }
  413. } finally {
  414. if (AbnormalTermination()) {
  415. if (Fcb->FullFileName.Buffer) {
  416. ExFreePool( Fcb->FullFileName.Buffer );
  417. Fcb->FullFileName.Buffer = NULL;
  418. }
  419. }
  420. ExFreePool( Lfn.Buffer );
  421. }
  422. }
  423. }
  424. VOID
  425. FatUnicodeToUpcaseOem (
  426. IN PIRP_CONTEXT IrpContext,
  427. IN POEM_STRING OemString,
  428. IN PUNICODE_STRING UnicodeString
  429. )
  430. /*++
  431. Routine Description:
  432. This routine is our standard routine for trying to use stack space
  433. if possible when calling RtlUpcaseUnicodeStringToCountedOemString().
  434. If an unmappable character is encountered, we set the destination
  435. length to 0.
  436. Arguments:
  437. OemString - Specifies the destination string. Space is already assumed to
  438. be allocated. If there is not enough, then we allocate enough
  439. space.
  440. UnicodeString - Specifies the source string.
  441. Return Value:
  442. None.
  443. --*/
  444. {
  445. NTSTATUS Status;
  446. Status = RtlUpcaseUnicodeStringToCountedOemString( OemString,
  447. UnicodeString,
  448. FALSE );
  449. if (Status == STATUS_BUFFER_OVERFLOW) {
  450. OemString->Buffer = NULL;
  451. OemString->Length = 0;
  452. OemString->MaximumLength = 0;
  453. Status = RtlUpcaseUnicodeStringToCountedOemString( OemString,
  454. UnicodeString,
  455. TRUE );
  456. }
  457. if (!NT_SUCCESS(Status)) {
  458. if (Status == STATUS_UNMAPPABLE_CHARACTER) {
  459. OemString->Length = 0;
  460. } else {
  461. FatNormalizeAndRaiseStatus( IrpContext, Status );
  462. }
  463. }
  464. return;
  465. }
  466. VOID
  467. FatSelectNames (
  468. IN PIRP_CONTEXT IrpContext,
  469. IN PDCB Parent,
  470. IN POEM_STRING OemName,
  471. IN PUNICODE_STRING UnicodeName,
  472. IN OUT POEM_STRING ShortName,
  473. IN PUNICODE_STRING SuggestedShortName OPTIONAL,
  474. IN OUT BOOLEAN *AllLowerComponent,
  475. IN OUT BOOLEAN *AllLowerExtension,
  476. IN OUT BOOLEAN *CreateLfn
  477. )
  478. /*++
  479. Routine Description:
  480. This routine takes the original UNICODE string that the user specified,
  481. and the upcased Oem equivolent. This routine then decides if the OemName
  482. is acceptable for dirent, or whether a short name has to be manufactured.
  483. Two values are returned to the caller. One tells the caller if the name
  484. happens to be all lower case < 0x80. In this special case we don't
  485. have to create an Lfn. Also we tell the caller if it must create an LFN.
  486. Arguments:
  487. OemName - Supplies the proposed short Oem name.
  488. ShortName - If this OemName is OK for storeage in a dirent it is copied to
  489. this string, otherwise this string is filled with a name that is OK.
  490. If OemName and ShortName are the same string, no copy is done.
  491. UnicodeName - Provides the original final name.
  492. SuggestedShortName - a first-try short name to try before auto-generation
  493. is used
  494. AllLowerComponent - Returns whether this component was all lower case.
  495. AllLowerExtension - Returns wheather the extension was all lower case.
  496. CreateLfn - Tells the caller if we must create an LFN for the UnicodeName or
  497. SuggestedLongName
  498. Return Value:
  499. None.
  500. --*/
  501. {
  502. BOOLEAN GenerateShortName;
  503. PAGED_CODE();
  504. //
  505. // First see if we must generate a short name.
  506. //
  507. if ((OemName->Length == 0) ||
  508. !FatIsNameShortOemValid( IrpContext, *OemName, FALSE, FALSE, FALSE ) ||
  509. FatSpaceInName( IrpContext, UnicodeName )) {
  510. WCHAR ShortNameBuffer[12];
  511. UNICODE_STRING ShortUnicodeName;
  512. GENERATE_NAME_CONTEXT Context;
  513. BOOLEAN TrySuggestedShortName;
  514. PDIRENT Dirent;
  515. PBCB Bcb = NULL;
  516. ULONG ByteOffset;
  517. NTSTATUS Status;
  518. GenerateShortName = TRUE;
  519. TrySuggestedShortName = (SuggestedShortName != NULL);
  520. //
  521. // Now generate a short name.
  522. //
  523. ShortUnicodeName.Length = 0;
  524. ShortUnicodeName.MaximumLength = 12 * sizeof(WCHAR);
  525. ShortUnicodeName.Buffer = ShortNameBuffer;
  526. RtlZeroMemory( &Context, sizeof( GENERATE_NAME_CONTEXT ) );
  527. try {
  528. while ( TRUE ) {
  529. FatUnpinBcb( IrpContext, Bcb );
  530. if (TrySuggestedShortName) {
  531. //
  532. // Try our caller's candidate first. Note that this must have
  533. // been uppercased previously.
  534. //
  535. ShortUnicodeName.Length = SuggestedShortName->Length;
  536. ShortUnicodeName.MaximumLength = SuggestedShortName->MaximumLength;
  537. ShortUnicodeName.Buffer = SuggestedShortName->Buffer;
  538. TrySuggestedShortName = FALSE;
  539. } else {
  540. RtlGenerate8dot3Name( UnicodeName, TRUE, &Context, &ShortUnicodeName );
  541. }
  542. //
  543. // We have a candidate, make sure it doesn't exist.
  544. //
  545. Status = RtlUnicodeStringToCountedOemString( ShortName,
  546. &ShortUnicodeName,
  547. FALSE );
  548. ASSERT( Status == STATUS_SUCCESS );
  549. FatLocateSimpleOemDirent( IrpContext,
  550. Parent,
  551. ShortName,
  552. &Dirent,
  553. &Bcb,
  554. &ByteOffset );
  555. if (Bcb == NULL) {
  556. leave;
  557. }
  558. }
  559. } finally {
  560. FatUnpinBcb( IrpContext, Bcb );
  561. }
  562. } else {
  563. //
  564. // Only do this copy if the two string are indeed different.
  565. //
  566. if (ShortName != OemName) {
  567. ShortName->Length = OemName->Length;
  568. RtlCopyMemory( ShortName->Buffer, OemName->Buffer, OemName->Length );
  569. }
  570. GenerateShortName = FALSE;
  571. }
  572. //
  573. // Now see if the caller will have to use unicode string as an LFN
  574. //
  575. if (GenerateShortName) {
  576. *CreateLfn = TRUE;
  577. *AllLowerComponent = FALSE;
  578. *AllLowerExtension = FALSE;
  579. } else {
  580. FatEvaluateNameCase( IrpContext,
  581. UnicodeName,
  582. AllLowerComponent,
  583. AllLowerExtension,
  584. CreateLfn );
  585. }
  586. return;
  587. }
  588. VOID
  589. FatEvaluateNameCase (
  590. IN PIRP_CONTEXT IrpContext,
  591. IN PUNICODE_STRING UnicodeName,
  592. IN OUT BOOLEAN *AllLowerComponent,
  593. IN OUT BOOLEAN *AllLowerExtension,
  594. IN OUT BOOLEAN *CreateLfn
  595. )
  596. /*++
  597. Routine Description:
  598. This routine takes a UNICODE string and sees if it is eligible for
  599. the special case optimization.
  600. Arguments:
  601. UnicodeName - Provides the original final name.
  602. AllLowerComponent - Returns whether this compoent was all lower case.
  603. AllLowerExtension - Returns wheather the extension was all lower case.
  604. CreateLfn - Tells the call if we must create an LFN for the UnicodeName.
  605. Return Value:
  606. None.
  607. --*/
  608. {
  609. ULONG i;
  610. UCHAR Uppers = 0;
  611. UCHAR Lowers = 0;
  612. BOOLEAN ExtensionPresent = FALSE;
  613. *CreateLfn = FALSE;
  614. for (i = 0; i < UnicodeName->Length / sizeof(WCHAR); i++) {
  615. WCHAR c;
  616. c = UnicodeName->Buffer[i];
  617. if ((c >= 'A') && (c <= 'Z')) {
  618. Uppers += 1;
  619. } else if ((c >= 'a') && (c <= 'z')) {
  620. Lowers += 1;
  621. } else if ((c >= 0x0080) && FatData.CodePageInvariant) {
  622. break;
  623. }
  624. //
  625. // If we come to a period, figure out if the extension was
  626. // all one case.
  627. //
  628. if (c == L'.') {
  629. *CreateLfn = (Lowers != 0) && (Uppers != 0);
  630. *AllLowerComponent = !(*CreateLfn) && (Lowers != 0);
  631. ExtensionPresent = TRUE;
  632. //
  633. // Now reset the uppers and lowers count.
  634. //
  635. Uppers = Lowers = 0;
  636. }
  637. }
  638. //
  639. // Now check again for creating an LFN.
  640. //
  641. *CreateLfn = (*CreateLfn ||
  642. (i != UnicodeName->Length / sizeof(WCHAR)) ||
  643. ((Lowers != 0) && (Uppers != 0)));
  644. //
  645. // Now we know the final state of CreateLfn, update the two
  646. // "AllLower" booleans.
  647. //
  648. if (ExtensionPresent) {
  649. *AllLowerComponent = !(*CreateLfn) && *AllLowerComponent;
  650. *AllLowerExtension = !(*CreateLfn) && (Lowers != 0);
  651. } else {
  652. *AllLowerComponent = !(*CreateLfn) && (Lowers != 0);
  653. *AllLowerExtension = FALSE;
  654. }
  655. return;
  656. }
  657. BOOLEAN
  658. FatSpaceInName (
  659. IN PIRP_CONTEXT IrpContext,
  660. IN PUNICODE_STRING UnicodeName
  661. )
  662. /*++
  663. Routine Description:
  664. This routine takes a UNICODE string and sees if it contains any spaces.
  665. Arguments:
  666. UnicodeName - Provides the final name.
  667. Return Value:
  668. BOOLEAN - TRUE if it does, FALSE if it doesn't.
  669. --*/
  670. {
  671. ULONG i;
  672. for (i=0; i < UnicodeName->Length/sizeof(WCHAR); i++) {
  673. if (UnicodeName->Buffer[i] == L' ') {
  674. return TRUE;
  675. }
  676. }
  677. return FALSE;
  678. }