]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/FileName.c
MdeModulePkg/FaultTolerantWriteDxe: implement standalone MM version
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / FileName.c
index 09690fb07649e606db329badaf0066dadbcbe11f..8aa37456ab1c1509e6d858244af5793c54cd4f83 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
+/** @file\r
+  Functions for manipulating file names.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution. The full text of the license may be found at\r
@@ -9,45 +10,28 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
+**/\r
 \r
-Module Name:\r
-\r
-  FileName.c\r
-\r
-Abstract:\r
+#include "Fat.h"\r
 \r
-  Functions for manipulating file names\r
+/**\r
 \r
-Revision History\r
+  This function checks whether the input FileName is a valid 8.3 short name.\r
+  If the input FileName is a valid 8.3, the output is the 8.3 short name;\r
+  otherwise, the output is the base tag of 8.3 short name.\r
 \r
---*/\r
+  @param  FileName              - The input unicode filename.\r
+  @param  File8Dot3Name         - The output ascii 8.3 short name or base tag of 8.3 short name.\r
 \r
-#include "Fat.h"\r
+  @retval TRUE                  - The input unicode filename is a valid 8.3 short name.\r
+  @retval FALSE                 - The input unicode filename is not a valid 8.3 short name.\r
 \r
+**/\r
 BOOLEAN\r
 FatCheckIs8Dot3Name (\r
   IN  CHAR16    *FileName,\r
   OUT CHAR8     *File8Dot3Name\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function checks whether the input FileName is a valid 8.3 short name.\r
-  If the input FileName is a valid 8.3, the output is the 8.3 short name;\r
-  otherwise, the output is the base tag of 8.3 short name.\r
-\r
-Arguments:\r
-\r
-  FileName              - The input unicode filename.\r
-  File8Dot3Name         - The output ascii 8.3 short name or base tag of 8.3 short name.\r
-\r
-Returns:\r
-\r
-  TRUE                  - The input unicode filename is a valid 8.3 short name.\r
-  FALSE                 - The input unicode filename is not a valid 8.3 short name.\r
-\r
---*/\r
 {\r
   BOOLEAN PossibleShortName;\r
   CHAR16  *TempName;\r
@@ -59,7 +43,7 @@ Returns:
   PossibleShortName = TRUE;\r
   SeparateDot       = NULL;\r
   SetMem (File8Dot3Name, FAT_NAME_LEN, ' ');\r
-  for (TempName = FileName; *TempName; TempName++) {\r
+  for (TempName = FileName; *TempName != '\0'; TempName++) {\r
     if (*TempName == L'.') {\r
       SeparateDot = TempName;\r
     }\r
@@ -118,28 +102,22 @@ Returns:
   return PossibleShortName;\r
 }\r
 \r
-STATIC\r
-UINTN\r
-FatTrimAsciiTrailingBlanks (\r
-  IN CHAR8        *Name,\r
-  IN UINTN        Len\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Trim the trailing blanks of fat name.\r
 \r
-Arguments:\r
-\r
-  Name                  - The Char8 string needs to be trimed.\r
-  Len                   - The length of the fat name.\r
-\r
-Returns:\r
+  @param  Name                  - The Char8 string needs to be trimed.\r
+  @param  Len                   - The length of the fat name.\r
 \r
   The real length of the fat name after the trailing blanks are trimmed.\r
 \r
---*/\r
+**/\r
+STATIC\r
+UINTN\r
+FatTrimAsciiTrailingBlanks (\r
+  IN CHAR8        *Name,\r
+  IN UINTN        Len\r
+  )\r
 {\r
   while (Len > 0 && Name[Len - 1] == ' ') {\r
     Len--;\r
@@ -148,6 +126,17 @@ Returns:
   return Len;\r
 }\r
 \r
+/**\r
+\r
+  Convert the ascii fat name to the unicode string and strip trailing spaces,\r
+  and if necessary, convert the unicode string to lower case.\r
+\r
+  @param  FatName               - The Char8 string needs to be converted.\r
+  @param  Len                   - The length of the fat name.\r
+  @param  LowerCase             - Indicate whether to convert the string to lower case.\r
+  @param  Str                   - The result of the convertion.\r
+\r
+**/\r
 VOID\r
 FatNameToStr (\r
   IN  CHAR8            *FatName,\r
@@ -155,25 +144,6 @@ FatNameToStr (
   IN  UINTN            LowerCase,\r
   OUT CHAR16           *Str\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Convert the ascii fat name to the unicode string and strip trailing spaces,\r
-  and if necessary, convert the unicode string to lower case.\r
-\r
-Arguments:\r
-\r
-  FatName               - The Char8 string needs to be converted.\r
-  Len                   - The length of the fat name.\r
-  LowerCase             - Indicate whether to convert the string to lower case.\r
-  Str                   - The result of the convertion.\r
-\r
-Returns:\r
-\r
-  None.\r
-\r
---*/\r
 {\r
   //\r
   // First, trim the trailing blanks\r
@@ -192,27 +162,19 @@ Returns:
   }\r
 }\r
 \r
+/**\r
+\r
+  This function generates 8Dot3 name from user specified name for a newly created file.\r
+\r
+  @param  Parent                - The parent directory.\r
+  @param  DirEnt                - The directory entry whose 8Dot3Name needs to be generated.\r
+\r
+**/\r
 VOID\r
 FatCreate8Dot3Name (\r
   IN FAT_OFILE    *Parent,\r
   IN FAT_DIRENT   *DirEnt\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function generates 8Dot3 name from user specified name for a newly created file.\r
-\r
-Arguments:\r
-\r
-  Parent                - The parent directory.\r
-  DirEnt                - The directory entry whose 8Dot3Name needs to be generated.\r
-\r
-Returns:\r
-\r
-  None.\r
-\r
---*/\r
 {\r
   CHAR8 *ShortName;\r
   CHAR8 *ShortNameChar;\r
@@ -275,34 +237,27 @@ Returns:
   }\r
 }\r
 \r
-STATIC\r
-UINT8\r
-FatCheckNameCase (\r
-  IN CHAR16           *Str,\r
-  IN UINT8            InCaseFlag\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Check the string is lower case or upper case\r
   and it is used by fatname to dir entry count\r
 \r
-Arguments:\r
-\r
-  Str                   - The string which needs to be checked.\r
-  InCaseFlag            - The input case flag which is returned when the string is lower case.\r
-\r
-Returns:\r
+  @param Str                   - The string which needs to be checked.\r
+  @param InCaseFlag            - The input case flag which is returned when the string is lower case.\r
 \r
-  OutCaseFlag           - The output case flag.\r
+  @retval OutCaseFlag           - The output case flag.\r
 \r
---*/\r
+**/\r
+STATIC\r
+UINT8\r
+FatCheckNameCase (\r
+  IN CHAR16           *Str,\r
+  IN UINT8            InCaseFlag\r
+  )\r
 {\r
   CHAR16  Buffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];\r
   UINT8   OutCaseFlag;\r
 \r
-  ASSERT (StrSize (Str) <= sizeof (Buffer));\r
   //\r
   // Assume the case of input string is mixed\r
   //\r
@@ -311,7 +266,7 @@ Returns:
   // Lower case a copy of the string, if it matches the\r
   // original then the string is lower case\r
   //\r
-  StrCpy (Buffer, Str);\r
+  StrCpyS (Buffer, ARRAY_SIZE (Buffer), Str);\r
   FatStrLwr (Buffer);\r
   if (StrCmp (Str, Buffer) == 0) {\r
     OutCaseFlag = InCaseFlag;\r
@@ -320,7 +275,7 @@ Returns:
   // Upper case a copy of the string, if it matches the\r
   // original then the string is upper case\r
   //\r
-  StrCpy (Buffer, Str);\r
+  StrCpyS (Buffer, ARRAY_SIZE (Buffer), Str);\r
   FatStrUpr (Buffer);\r
   if (StrCmp (Str, Buffer) == 0) {\r
     OutCaseFlag = 0;\r
@@ -329,25 +284,17 @@ Returns:
   return OutCaseFlag;\r
 }\r
 \r
-VOID\r
-FatSetCaseFlag (\r
-  IN FAT_DIRENT   *DirEnt\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Set the caseflag value for the directory entry.\r
 \r
-Arguments:\r
-\r
-  DirEnt                - The logical directory entry whose caseflag value is to be set.\r
-\r
-Returns:\r
+  @param DirEnt                - The logical directory entry whose caseflag value is to be set.\r
 \r
-  None.\r
-\r
---*/\r
+**/\r
+VOID\r
+FatSetCaseFlag (\r
+  IN FAT_DIRENT   *DirEnt\r
+  )\r
 {\r
   CHAR16  LfnBuffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];\r
   CHAR16  *TempCharPtr;\r
@@ -390,27 +337,21 @@ Returns:
   }\r
 }\r
 \r
-VOID\r
-FatGetFileNameViaCaseFlag (\r
-  IN  FAT_DIRENT    *DirEnt,\r
-  OUT CHAR16        *FileString\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Convert the 8.3 ASCII fat name to cased Unicode string according to case flag.\r
 \r
-Arguments:\r
-\r
-  DirEnt                - The corresponding directory entry.\r
-  FileString            - The output Unicode file name.\r
-\r
-Returns:\r
-\r
-  None.\r
+  @param  DirEnt                - The corresponding directory entry.\r
+  @param  FileString            - The output Unicode file name.\r
+  @param  FileStringMax           The max length of FileString.\r
 \r
---*/\r
+**/\r
+VOID\r
+FatGetFileNameViaCaseFlag (\r
+  IN     FAT_DIRENT   *DirEnt,\r
+  IN OUT CHAR16       *FileString,\r
+  IN     UINTN        FileStringMax\r
+  )\r
 {\r
   UINT8   CaseFlag;\r
   CHAR8   *File8Dot3Name;\r
@@ -425,63 +366,51 @@ Returns:
   FatNameToStr (File8Dot3Name + FAT_MAIN_NAME_LEN, FAT_EXTEND_NAME_LEN, CaseFlag & FAT_CASE_EXT_LOWER, &TempExt[1]);\r
   if (TempExt[1] != 0) {\r
     TempExt[0] = L'.';\r
-    StrCat (FileString, TempExt);\r
+    StrCatS (FileString, FileStringMax, TempExt);\r
   }\r
 }\r
 \r
-UINT8\r
-FatCheckSum (\r
-  IN CHAR8  *ShortNameString\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Get the Check sum for a short name.\r
 \r
-Arguments:\r
+  @param  ShortNameString       - The short name for a file.\r
 \r
-  ShortNameString       - The short name for a file.\r
+  @retval Sum                   - UINT8 checksum.\r
 \r
-Returns:\r
-\r
-  Sum                   - UINT8 checksum.\r
-\r
---*/\r
+**/\r
+UINT8\r
+FatCheckSum (\r
+  IN CHAR8  *ShortNameString\r
+  )\r
 {\r
   UINTN ShortNameLen;\r
   UINT8 Sum;\r
   Sum = 0;\r
   for (ShortNameLen = FAT_NAME_LEN; ShortNameLen != 0; ShortNameLen--) {\r
-    Sum = (UINT8)(((Sum & 1) ? 0x80 : 0) + (Sum >> 1) + *ShortNameString++);\r
+    Sum = (UINT8)((((Sum & 1) != 0) ? 0x80 : 0) + (Sum >> 1) + *ShortNameString++);\r
   }\r
 \r
   return Sum;\r
 }\r
 \r
-CHAR16 *\r
-FatGetNextNameComponent (\r
-  IN  CHAR16      *Path,\r
-  OUT CHAR16      *Name\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Takes Path as input, returns the next name component\r
   in Name, and returns the position after Name (e.g., the\r
   start of the next name component)\r
 \r
-Arguments:\r
-\r
-  Path                  - The path of one file.\r
-  Name                  - The next name component in Path.\r
-\r
-Returns:\r
+  @param  Path                  - The path of one file.\r
+  @param  Name                  - The next name component in Path.\r
 \r
   The position after Name in the Path\r
 \r
---*/\r
+**/\r
+CHAR16 *\r
+FatGetNextNameComponent (\r
+  IN  CHAR16      *Path,\r
+  OUT CHAR16      *Name\r
+  )\r
 {\r
   while (*Path != 0 && *Path != PATH_NAME_SEPARATOR) {\r
     *Name++ = *Path++;\r
@@ -497,31 +426,24 @@ Returns:
   return Path;\r
 }\r
 \r
-BOOLEAN\r
-FatFileNameIsValid (\r
-  IN  CHAR16  *InputFileName,\r
-  OUT CHAR16  *OutputFileName\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Check whether the IFileName is valid long file name. If the IFileName is a valid\r
   long file name, then we trim the possible leading blanks and leading/trailing dots.\r
   the trimmed filename is stored in OutputFileName\r
 \r
-Arguments:\r
+  @param  InputFileName         - The input file name.\r
+  @param  OutputFileName        - The output file name.\r
 \r
-  InputFileName         - The input file name.\r
-  OutputFileName        - The output file name.\r
+  @retval TRUE                  - The InputFileName is a valid long file name.\r
+  @retval FALSE                 - The InputFileName is not a valid long file name.\r
 \r
-\r
-Returns:\r
-\r
-  TRUE                  - The InputFileName is a valid long file name.\r
-  FALSE                 - The InputFileName is not a valid long file name.\r
-\r
---*/\r
+**/\r
+BOOLEAN\r
+FatFileNameIsValid (\r
+  IN  CHAR16  *InputFileName,\r
+  OUT CHAR16  *OutputFileName\r
+  )\r
 {\r
   CHAR16  *TempNamePointer;\r
   CHAR16  TempChar;\r