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.

913 lines
22 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Gen8dot3.c
  5. Abstract:
  6. This module implements a routine to generate 8.3 names from long names.
  7. Author:
  8. Gary Kimura [GaryKi] 26-Mar-1992
  9. Environment:
  10. Pure Utility Routines
  11. Revision History:
  12. --*/
  13. #include "ntrtlp.h"
  14. #include <stdio.h>
  15. extern PUSHORT NlsUnicodeToMbOemData;
  16. extern PUSHORT NlsOemToUnicodeData;
  17. extern PCH NlsUnicodeToOemData;
  18. extern PUSHORT NlsMbOemCodePageTables;
  19. extern BOOLEAN NlsMbOemCodePageTag;
  20. extern const PUSHORT NlsOemLeadByteInfo;
  21. extern USHORT OemDefaultChar;
  22. //
  23. // A condensed table of legal fat character values
  24. //
  25. #if defined(ALLOC_DATA_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
  26. #pragma const_seg("PAGECONST")
  27. #endif
  28. const
  29. ULONG RtlFatIllegalTable[] = { 0xffffffff,
  30. 0xfc009c04,
  31. 0x38000000,
  32. 0x10000000 };
  33. WCHAR
  34. GetNextWchar (
  35. IN PUNICODE_STRING Name,
  36. IN PULONG CurrentIndex,
  37. IN BOOLEAN SkipDots,
  38. IN BOOLEAN AllowExtendedCharacters
  39. );
  40. USHORT
  41. RtlComputeLfnChecksum (
  42. PUNICODE_STRING Name
  43. );
  44. //
  45. // BOOLEAN
  46. // IsDbcsCharacter (
  47. // IN WCHAR Wc
  48. // );
  49. //
  50. #define IsDbcsCharacter(WC) ( \
  51. ((WC) > 127) && \
  52. (HIBYTE(NlsUnicodeToMbOemData[(WC)])) \
  53. )
  54. #if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
  55. #pragma alloc_text(PAGE,RtlGenerate8dot3Name)
  56. #pragma alloc_text(PAGE,GetNextWchar)
  57. #pragma alloc_text(PAGE,RtlComputeLfnChecksum)
  58. #pragma alloc_text(PAGE,RtlIsNameLegalDOS8Dot3)
  59. #pragma alloc_text(PAGE,RtlIsValidOemCharacter)
  60. #endif
  61. VOID
  62. RtlGenerate8dot3Name (
  63. IN PUNICODE_STRING Name,
  64. IN BOOLEAN AllowExtendedCharacters,
  65. IN OUT PGENERATE_NAME_CONTEXT Context,
  66. OUT PUNICODE_STRING Name8dot3
  67. )
  68. /*++
  69. Routine Description:
  70. This routine is used to generate an 8.3 name from a long name. It can
  71. be called repeatedly to generate different 8.3 name variations for the
  72. same long name. This is necessary if the gernerated 8.3 name conflicts
  73. with an existing 8.3 name.
  74. Arguments:
  75. Name - Supplies the original long name that is being translated from.
  76. AllowExtendedCharacters - If TRUE, then extended characters, including
  77. DBCS characters, are allowed in the basis of the short name if they
  78. map to an upcased Oem character.
  79. Context - Supplies a context for the translation. This is a private structure
  80. needed by this routine to help enumerate the different long name
  81. possibilities. The caller is responsible with providing a "zeroed out"
  82. context structure on the first call for each given input name.
  83. Name8dot3 - Receives the new 8.3 name. Pool for the buffer must be allocated
  84. by the caller and should be 12 characters wide (i.e., 24 bytes).
  85. Return Value:
  86. None.
  87. --*/
  88. {
  89. BOOLEAN DbcsAware;
  90. BOOLEAN IndexAll9s = TRUE;
  91. ULONG OemLength;
  92. ULONG IndexLength;
  93. WCHAR IndexBuffer[8];
  94. ULONG i;
  95. #ifdef NTOS_KERNEL_RUNTIME
  96. extern BOOLEAN FsRtlSafeExtensions;
  97. #else
  98. BOOLEAN FsRtlSafeExtensions = TRUE;
  99. #endif
  100. DbcsAware = AllowExtendedCharacters && NlsMbOemCodePageTag;
  101. //
  102. // Check if this is the first time we are being called, and if so then
  103. // initialize the context fields.
  104. //
  105. if (Context->NameLength == 0) {
  106. ULONG LastDotIndex;
  107. ULONG CurrentIndex;
  108. BOOLEAN SkipDots;
  109. WCHAR wc;
  110. //
  111. // Skip down the name remembering the index of the last dot we
  112. // will skip over the first dot provided the name starts with
  113. // a dot.
  114. //
  115. LastDotIndex = MAXULONG;
  116. CurrentIndex = 0;
  117. SkipDots = ((Name->Length > 0) && (Name->Buffer[0] == L'.'));
  118. while ((wc = GetNextWchar( Name,
  119. &CurrentIndex,
  120. SkipDots,
  121. AllowExtendedCharacters )) != 0) {
  122. SkipDots = FALSE;
  123. if (wc == L'.') { LastDotIndex = CurrentIndex; }
  124. }
  125. //
  126. // If the LastDotIndex is the last character in the name,
  127. // then there really isn't an extension, so reset LastDotIndex.
  128. //
  129. if (LastDotIndex == Name->Length/sizeof(WCHAR)) {
  130. LastDotIndex = MAXULONG;
  131. }
  132. //
  133. // Build up the name part. This can be at most 6 characters
  134. // (because of the ~# appeneded on the end) and we skip over
  135. // dots, except the last dot, which terminates the loop.
  136. //
  137. // We exit the loop if:
  138. //
  139. // - The input Name has been exhausted
  140. // - We have consumed the input name up to the last dot
  141. // - We have filled 6 characters of short name basis
  142. //
  143. CurrentIndex = 0;
  144. OemLength = 0;
  145. Context->NameLength = 0;
  146. while ((wc = GetNextWchar( Name, &CurrentIndex, TRUE, AllowExtendedCharacters)) &&
  147. (CurrentIndex < LastDotIndex) &&
  148. (Context->NameLength < 6)) {
  149. //
  150. // If we are on a multi-byte code page we have to be careful
  151. // here because the short name (when converted to Oem) must
  152. // be 8.3 compliant. Note that if AllowExtendedCharacters
  153. // is FALSE, then GetNextWchar will never return a DBCS
  154. // character, so we don't care what kind of code page we
  155. // are on.
  156. //
  157. if (DbcsAware) {
  158. OemLength += IsDbcsCharacter(wc) ? 2 : 1;
  159. if (OemLength > 6) { break; }
  160. }
  161. //
  162. // Copy the UNICODE character into the name buffer
  163. //
  164. Context->NameBuffer[Context->NameLength++] = wc;
  165. }
  166. //
  167. // Now if the name part of the basis is 2 or less bytes (when
  168. // represented in Oem) then append a four character checksum
  169. // to make the short name space less sparse.
  170. //
  171. if ((DbcsAware ? OemLength : Context->NameLength) <= 2) {
  172. USHORT Checksum;
  173. WCHAR Nibble;
  174. Checksum =
  175. Context->Checksum = RtlComputeLfnChecksum( Name );
  176. for (i = 0; i < 4; i++, Checksum >>= 4) {
  177. Nibble = Checksum & 0xf;
  178. Nibble += Nibble <= 9 ? '0' : 'A' - 10;
  179. Context->NameBuffer[ Context->NameLength + i ] = Nibble;
  180. }
  181. Context->NameLength += 4;
  182. Context->ChecksumInserted = TRUE;
  183. }
  184. //
  185. // Now process the last extension (if there is one).
  186. // If the last dot index is not MAXULONG then we
  187. // have located the last dot in the name
  188. //
  189. if (LastDotIndex != MAXULONG) {
  190. //
  191. // Put in the "."
  192. //
  193. Context->ExtensionBuffer[0] = L'.';
  194. //
  195. // Process the extension similar to how we processed the name
  196. //
  197. // We exit the loop if:
  198. //
  199. // - The input Name has been exhausted
  200. // - We have filled . + 3 characters of extension
  201. //
  202. OemLength = 1;
  203. Context->ExtensionLength = 1;
  204. while ((wc = GetNextWchar( Name, &LastDotIndex, TRUE, AllowExtendedCharacters)) &&
  205. (Context->ExtensionLength < 4)) {
  206. if (DbcsAware) {
  207. OemLength += IsDbcsCharacter(wc) ? 2 : 1;
  208. if (OemLength > 4) { break; }
  209. }
  210. Context->ExtensionBuffer[Context->ExtensionLength++] = wc;
  211. }
  212. //
  213. // If we had to truncate the extension (i.e. input name was not
  214. // exhausted), change the last char of the truncated extension
  215. // to a ~ is user has selected safe extensions.
  216. //
  217. if (wc && FsRtlSafeExtensions) {
  218. Context->ExtensionBuffer[Context->ExtensionLength - 1] = L'~';
  219. }
  220. } else {
  221. Context->ExtensionLength = 0;
  222. }
  223. }
  224. //
  225. // In all cases we add one to the index value and this is the value
  226. // of the index we are going to generate this time around
  227. //
  228. Context->LastIndexValue += 1;
  229. //
  230. // Now if the new index value is greater than 4 then we've had too
  231. // many collisions and we should alter our basis if possible
  232. //
  233. if ((Context->LastIndexValue > 4) && !Context->ChecksumInserted) {
  234. USHORT Checksum;
  235. WCHAR Nibble;
  236. //
  237. // 'XX' is represented A DBCS character.
  238. //
  239. // LongName -> ShortName | DbcsBias Oem Unicode
  240. // -----------------------------+------------------------
  241. // XXXXThisisapen -> XX1234 | 1 6 5
  242. // XXThisisapen -> XX1234 | 1 6 5
  243. // aXXThisisapen -> a1234 | 1 5 5
  244. // aaThisisapen -> aa1234 | 0 6 6
  245. //
  246. ULONG DbcsBias;
  247. if (DbcsAware) {
  248. DbcsBias = ((IsDbcsCharacter(Context->NameBuffer[0]) ? 1 : 0) |
  249. (IsDbcsCharacter(Context->NameBuffer[1]) ? 1 : 0));
  250. } else {
  251. DbcsBias = 0;
  252. }
  253. Checksum =
  254. Context->Checksum = RtlComputeLfnChecksum( Name );
  255. for (i = (2-DbcsBias); i < (6-DbcsBias); i++, Checksum >>= 4) {
  256. Nibble = Checksum & 0xf;
  257. Nibble += Nibble <= 9 ? '0' : 'A' - 10;
  258. Context->NameBuffer[ i ] = Nibble;
  259. }
  260. Context->NameLength = (UCHAR)(6-DbcsBias);
  261. Context->LastIndexValue = 1;
  262. Context->ChecksumInserted = TRUE;
  263. }
  264. //
  265. // Now build the index buffer from high index to low index because we
  266. // use a mod & div operation to build the string from the index value.
  267. //
  268. // We also want to remember is we are about to rollover in base 10.
  269. //
  270. for (IndexLength = 1, i = Context->LastIndexValue;
  271. (IndexLength <= 7) && (i > 0);
  272. IndexLength += 1, i /= 10) {
  273. if ((IndexBuffer[ 8 - IndexLength] = (WCHAR)(L'0' + (i % 10))) != L'9') {
  274. IndexAll9s = FALSE;
  275. }
  276. }
  277. //
  278. // And tack on the preceding dash
  279. //
  280. IndexBuffer[ 8 - IndexLength ] = L'~';
  281. //
  282. // At this point everything is set up to copy to the output buffer. First
  283. // copy over the name and then only copy the index and extension if they exist
  284. //
  285. if (Context->NameLength != 0) {
  286. RtlCopyMemory( &Name8dot3->Buffer[0],
  287. &Context->NameBuffer[0],
  288. Context->NameLength * 2 );
  289. Name8dot3->Length = (USHORT)(Context->NameLength * 2);
  290. } else {
  291. Name8dot3->Length = 0;
  292. }
  293. //
  294. // Now do the index.
  295. //
  296. RtlCopyMemory( &Name8dot3->Buffer[ Name8dot3->Length/2 ],
  297. &IndexBuffer[ 8 - IndexLength ],
  298. IndexLength * 2 );
  299. Name8dot3->Length += (USHORT) (IndexLength * 2);
  300. //
  301. // Now conditionally do the extension
  302. //
  303. if (Context->ExtensionLength != 0) {
  304. RtlCopyMemory( &Name8dot3->Buffer[ Name8dot3->Length/2 ],
  305. &Context->ExtensionBuffer[0],
  306. Context->ExtensionLength * 2 );
  307. Name8dot3->Length += (USHORT) (Context->ExtensionLength * 2);
  308. }
  309. //
  310. // If current index value is all 9s, then the next value will cause the
  311. // index string to grow from it's current size. In this case recompute
  312. // Context->NameLength so that is will be correct for next time.
  313. //
  314. if (IndexAll9s) {
  315. if (DbcsAware) {
  316. for (i = 0, OemLength = 0; i < Context->NameLength; i++) {
  317. OemLength += IsDbcsCharacter(Context->NameBuffer[i]) ? 2 : 1;
  318. if (OemLength > 8 - (IndexLength + 1)) {
  319. break;
  320. }
  321. }
  322. Context->NameLength = (UCHAR)i;
  323. } else {
  324. Context->NameLength -= 1;
  325. }
  326. }
  327. //
  328. // And return to our caller
  329. //
  330. return;
  331. }
  332. BOOLEAN
  333. RtlIsValidOemCharacter (
  334. IN PWCHAR Char
  335. )
  336. /*++
  337. Routine Description:
  338. This routine determines if the best-fitted and upcased version of the
  339. input unicode char is a valid Oem character.
  340. Arguments:
  341. Char - Supplies the Unicode char and receives the best-fitted and
  342. upcased version if it was indeed valid.
  343. Return Value:
  344. TRUE if the character was valid.
  345. --*/
  346. {
  347. WCHAR UniTmp;
  348. WCHAR OemChar;
  349. //
  350. // First try to make a round trip from Unicode->Oem->Unicode.
  351. //
  352. if (!NlsMbOemCodePageTag) {
  353. UniTmp = (WCHAR)NLS_UPCASE(NlsOemToUnicodeData[(UCHAR)NlsUnicodeToOemData[*Char]]);
  354. OemChar = NlsUnicodeToOemData[UniTmp];
  355. } else {
  356. //
  357. // Convert to OEM and back to Unicode before upper casing
  358. // to ensure the visual best fits are converted and
  359. // upper cased properly.
  360. //
  361. OemChar = NlsUnicodeToMbOemData[ *Char ];
  362. if (NlsOemLeadByteInfo[HIBYTE(OemChar)]) {
  363. USHORT Entry;
  364. //
  365. // Lead byte - translate the trail byte using the table
  366. // that corresponds to this lead byte.
  367. //
  368. Entry = NlsOemLeadByteInfo[HIBYTE(OemChar)];
  369. UniTmp = (WCHAR)NlsMbOemCodePageTables[ Entry + LOBYTE(OemChar) ];
  370. } else {
  371. //
  372. // Single byte character.
  373. //
  374. UniTmp = NlsOemToUnicodeData[LOBYTE(OemChar)];
  375. }
  376. //
  377. // Now upcase this UNICODE character, and convert it to Oem.
  378. //
  379. UniTmp = (WCHAR)NLS_UPCASE(UniTmp);
  380. OemChar = NlsUnicodeToMbOemData[UniTmp];
  381. }
  382. //
  383. // Now if the final OemChar is the default one, then there was no
  384. // mapping for this UNICODE character.
  385. //
  386. if (OemChar == OemDefaultChar) {
  387. return FALSE;
  388. } else {
  389. *Char = UniTmp;
  390. return TRUE;
  391. }
  392. }
  393. //
  394. // Local support routine
  395. //
  396. WCHAR
  397. GetNextWchar (
  398. IN PUNICODE_STRING Name,
  399. IN PULONG CurrentIndex,
  400. IN BOOLEAN SkipDots,
  401. IN BOOLEAN AllowExtendedCharacters
  402. )
  403. /*++
  404. Routine Description:
  405. This routine scans the input name starting at the current index and
  406. returns the next valid character for the long name to 8.3 generation
  407. algorithm. It also updates the current index to point to the
  408. next character to examine.
  409. The user can specify if dots are skipped over or passed back. The
  410. filtering done by the procedure is:
  411. 1. Skip characters less then blanks, and larger than 127 if
  412. AllowExtendedCharacters is FALSE
  413. 2. Optionally skip over dots
  414. 3. translate the special 7 characters : + , ; = [ ] into underscores
  415. Arguments:
  416. Name - Supplies the name being examined
  417. CurrentIndex - Supplies the index to start our examination and also
  418. receives the index of one beyond the character we return.
  419. SkipDots - Indicates whether this routine will also skip over periods
  420. AllowExtendedCharacters - Tell whether charaacters >= 127 are valid.
  421. Return Value:
  422. WCHAR - returns the next wchar in the name string
  423. --*/
  424. {
  425. WCHAR wc;
  426. //
  427. // Until we find out otherwise the character we are going to return
  428. // is 0
  429. //
  430. wc = 0;
  431. //
  432. // Now loop through updating the current index until we either have a character to
  433. // return or until we exhaust the name buffer
  434. //
  435. while (*CurrentIndex < (ULONG)(Name->Length/2)) {
  436. //
  437. // Get the next character in the buffer
  438. //
  439. wc = Name->Buffer[*CurrentIndex];
  440. *CurrentIndex += 1;
  441. //
  442. // If the character is to be skipped over then reset wc to 0
  443. //
  444. if ((wc <= L' ') ||
  445. ((wc >= 127) && (!AllowExtendedCharacters || !RtlIsValidOemCharacter(&wc))) ||
  446. ((wc == L'.') && SkipDots)) {
  447. wc = 0;
  448. } else {
  449. //
  450. // We have a character to return, but first translate the character is necessary
  451. //
  452. if ((wc < 0x80) && (RtlFatIllegalTable[wc/32] & (1 << (wc%32)))) {
  453. wc = L'_';
  454. }
  455. //
  456. // Do an a-z upcase.
  457. //
  458. if ((wc >= L'a') && (wc <= L'z')) {
  459. wc -= L'a' - L'A';
  460. }
  461. //
  462. // And break out of the loop to return to our caller
  463. //
  464. break;
  465. }
  466. }
  467. //DebugTrace( 0, Dbg, "GetNextWchar -> %08x\n", wc);
  468. return wc;
  469. }
  470. //
  471. // Internal support routine
  472. //
  473. USHORT
  474. RtlComputeLfnChecksum (
  475. PUNICODE_STRING Name
  476. )
  477. /*++
  478. Routine Description:
  479. This routine computes the Chicago long file name checksum.
  480. Arguments:
  481. Name - Supplies the name to compute the checksum on. Note that one
  482. character names don't have interesting checksums.
  483. Return Value:
  484. The checksum.
  485. --*/
  486. {
  487. ULONG i;
  488. USHORT Checksum;
  489. RTL_PAGED_CODE();
  490. if (Name->Length == sizeof(WCHAR)) {
  491. return Name->Buffer[0];
  492. }
  493. Checksum = ((Name->Buffer[0] << 8) + Name->Buffer[1]) & 0xffff;
  494. //
  495. // This checksum is kinda strange because we want to still have
  496. // a good range even if all the characters are < 0x00ff.
  497. //
  498. for (i=2; i < Name->Length / sizeof(WCHAR); i+=2) {
  499. Checksum = (Checksum & 1 ? 0x8000 : 0) +
  500. (Checksum >> 1) +
  501. (Name->Buffer[i] << 8);
  502. //
  503. // Be carefull to not walk off the end of the string.
  504. //
  505. if (i+1 < Name->Length / sizeof(WCHAR)) {
  506. Checksum += Name->Buffer[i+1] & 0xffff;
  507. }
  508. }
  509. return Checksum;
  510. }
  511. BOOLEAN
  512. RtlIsNameLegalDOS8Dot3 (
  513. IN PUNICODE_STRING Name,
  514. IN OUT POEM_STRING OemName OPTIONAL,
  515. OUT PBOOLEAN NameContainsSpaces OPTIONAL
  516. )
  517. /*++
  518. Routine Description:
  519. This routine takes an input string and gives a definitive answer
  520. on whether this name can successfully be used to create a file
  521. on the FAT file system.
  522. This routine can therefore also be used to determine if a name is
  523. appropriate to be passed back to a Win31 or DOS app, i.e. whether
  524. the downlevel APP will understand the name.
  525. Note: an important part of this test is the mapping from UNICODE
  526. to Oem, which is why it is important that the input parameter be
  527. received in UNICODE.
  528. Arguments:
  529. Name - The UNICODE name to test for conformance to 8.3 symantics.
  530. OemName - If specified, will receive the Oem name corresponding
  531. to the passed in Name. Storage must be provided by the caller.
  532. The name is undefined if the routine returns FALSE.
  533. NameContainsSpaces - If the function returns TRUE, then this
  534. parameter will indicate if the names contains spaces. If
  535. the function returns FALSE, this parameter is undefined. In
  536. many instances, the alternate name is more appropriate to
  537. use if spaces are present in the principle name, even if
  538. it is 8.3 compliant.
  539. Return Value:
  540. BOOLEAN - TRUE if the passed in UNICODE name forms a valid 8.3
  541. FAT name when upcased to the current Oem code page.
  542. --*/
  543. {
  544. ULONG Index;
  545. BOOLEAN ExtensionPresent = FALSE;
  546. BOOLEAN SpacesPresent = FALSE;
  547. OEM_STRING LocalOemName;
  548. UCHAR Char;
  549. UCHAR OemBuffer[12];
  550. //
  551. // If the name is more than 12 chars, bail.
  552. //
  553. if (Name->Length > 12*sizeof(WCHAR)) {
  554. return FALSE;
  555. }
  556. //
  557. // Now upcase this name to Oem. If anything goes wrong,
  558. // return FALSE.
  559. //
  560. if (!ARGUMENT_PRESENT(OemName)) {
  561. OemName = &LocalOemName;
  562. OemName->Buffer = &OemBuffer[0];
  563. OemName->Length = 0;
  564. OemName->MaximumLength = 12;
  565. }
  566. if (!NT_SUCCESS(RtlUpcaseUnicodeStringToCountedOemString(OemName, Name, FALSE))) {
  567. return FALSE;
  568. }
  569. //
  570. // Special case . and ..
  571. //
  572. if (((OemName->Length == 1) && (OemName->Buffer[0] == '.')) ||
  573. ((OemName->Length == 2) && (OemName->Buffer[0] == '.') && (OemName->Buffer[1] == '.'))) {
  574. if (ARGUMENT_PRESENT(NameContainsSpaces)) {
  575. *NameContainsSpaces = FALSE;
  576. }
  577. return TRUE;
  578. }
  579. //
  580. // Now we are going to walk through the string looking for
  581. // illegal characters and/or incorrect syntax.
  582. //
  583. for ( Index = 0; Index < OemName->Length; Index += 1 ) {
  584. Char = OemName->Buffer[ Index ];
  585. //
  586. // Skip over and Dbcs chacters
  587. //
  588. if (NlsMbOemCodePageTag && NlsOemLeadByteInfo[Char]) {
  589. //
  590. // 1) if we're looking at base part ( !ExtensionPresent ) and the 8th byte
  591. // is in the dbcs leading byte range, it's error ( Index == 7 ). If the
  592. // length of base part is more than 8 ( Index > 7 ), it's definitely error.
  593. //
  594. // 2) if the last byte ( Index == DbcsName.Length - 1 ) is in the dbcs leading
  595. // byte range, it's error
  596. //
  597. if ((!ExtensionPresent && (Index >= 7)) ||
  598. (Index == (ULONG)(OemName->Length - 1))) {
  599. return FALSE;
  600. }
  601. Index += 1;
  602. continue;
  603. }
  604. //
  605. // Make sure this character is legal.
  606. //
  607. if ((Char < 0x80) &&
  608. (RtlFatIllegalTable[Char/32] & (1 << (Char%32)))) {
  609. return FALSE;
  610. }
  611. //
  612. // Remember if there was a space.
  613. //
  614. if (Char == ' ') {
  615. SpacesPresent = TRUE;
  616. }
  617. if (Char == '.') {
  618. //
  619. // We stepped onto a period. We require the following things:
  620. //
  621. // - There can only be one
  622. // - It can't be the first character
  623. // - The previous character can't be a space.
  624. // - There can't be more than 3 bytes following
  625. //
  626. if (ExtensionPresent ||
  627. (Index == 0) ||
  628. (OemName->Buffer[Index - 1] == ' ') ||
  629. (OemName->Length - (Index + 1) > 3)) {
  630. return FALSE;
  631. }
  632. ExtensionPresent = TRUE;
  633. }
  634. //
  635. // The base part of the name can't be more than 8 characters long.
  636. //
  637. if ((Index >= 8) && !ExtensionPresent) { return FALSE; }
  638. }
  639. //
  640. // The name cannot end in a space or a period.
  641. //
  642. if ((Char == ' ') || (Char == '.')) { return FALSE; }
  643. if (ARGUMENT_PRESENT(NameContainsSpaces)) {
  644. *NameContainsSpaces = SpacesPresent;
  645. }
  646. return TRUE;
  647. }