]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/Fat.h
MdeModulePkg/FaultTolerantWriteDxe: implement standalone MM version
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Fat.h
index 2df8f78e84f5d4cae5ddc662b4eef9a7c74c2775..83552613bf7666fe42d02e7b31a374661c856618 100644 (file)
@@ -1,7 +1,8 @@
-/*++\r
+/** @file\r
+  Main header file for EFI FAT file system driver.\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials are licensed and made available\r
+Copyright (c) 2005 - 2013, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -9,18 +10,7 @@ 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
-Module Name:\r
-\r
-  Fat.h\r
-\r
-Abstract:\r
-\r
-  Main header file for EFI FAT file system driver\r
-\r
-Revision History\r
-\r
---*/\r
+**/\r
 \r
 #ifndef _FAT_H_\r
 #define _FAT_H_\r
@@ -30,9 +20,9 @@ Revision History
 #include <Guid/FileInfo.h>\r
 #include <Guid/FileSystemInfo.h>\r
 #include <Guid/FileSystemVolumeLabelInfo.h>\r
-#include <Guid/GlobalVariable.h>\r
 #include <Protocol/BlockIo.h>\r
 #include <Protocol/DiskIo.h>\r
+#include <Protocol/DiskIo2.h>\r
 #include <Protocol/SimpleFileSystem.h>\r
 #include <Protocol/UnicodeCollation.h>\r
 \r
@@ -56,6 +46,8 @@ Revision History
 #define FAT_ODIR_SIGNATURE           SIGNATURE_32 ('f', 'a', 't', 'd')\r
 #define FAT_DIRENT_SIGNATURE         SIGNATURE_32 ('f', 'a', 't', 'e')\r
 #define FAT_OFILE_SIGNATURE          SIGNATURE_32 ('f', 'a', 't', 'o')\r
+#define FAT_TASK_SIGNATURE           SIGNATURE_32 ('f', 'a', 't', 'T')\r
+#define FAT_SUBTASK_SIGNATURE        SIGNATURE_32 ('f', 'a', 't', 'S')\r
 \r
 #define ASSERT_VOLUME_LOCKED(a)      ASSERT_LOCKED (&FatFsLock)\r
 \r
@@ -126,28 +118,28 @@ typedef CHAR8                   LC_ISO_639_2;
 // The fat types we support\r
 //\r
 typedef enum {\r
-  FAT12,\r
-  FAT16,\r
-  FAT32,\r
+  Fat12,\r
+  Fat16,\r
+  Fat32,\r
   FatUndefined\r
 } FAT_VOLUME_TYPE;\r
 \r
 typedef enum {\r
-  CACHE_FAT,\r
-  CACHE_DATA,\r
-  CACHE_MAX_TYPE\r
+  CacheFat,\r
+  CacheData,\r
+  CacheMaxType\r
 } CACHE_DATA_TYPE;\r
 \r
 //\r
 // Used in FatDiskIo\r
 //\r
 typedef enum {\r
-  READ_DISK     = 0,  // raw disk read\r
-  WRITE_DISK    = 1,  // raw disk write\r
-  READ_FAT      = 2,  // read fat cache\r
-  WRITE_FAT     = 3,  // write fat cache\r
-  READ_DATA     = 6,  // read data cache\r
-  WRITE_DATA    = 7   // write data cache\r
+  ReadDisk     = 0,  // raw disk read\r
+  WriteDisk    = 1,  // raw disk write\r
+  ReadFat      = 2,  // read fat cache\r
+  WriteFat     = 3,  // write fat cache\r
+  ReadData     = 6,  // read data cache\r
+  WriteData    = 7   // write data cache\r
 } IO_MODE;\r
 \r
 #define CACHE_ENABLED(a)  ((a) >= 2)\r
@@ -182,20 +174,26 @@ typedef struct {
 //\r
 // The directory entry for opened directory\r
 //\r
-typedef struct _FAT_DIRENT {\r
+\r
+typedef struct _FAT_DIRENT FAT_DIRENT;\r
+typedef struct _FAT_ODIR FAT_ODIR;\r
+typedef struct _FAT_OFILE FAT_OFILE;\r
+typedef struct _FAT_VOLUME FAT_VOLUME;\r
+\r
+struct _FAT_DIRENT {\r
   UINTN               Signature;\r
   UINT16              EntryPos;               // The position of this directory entry in the parent directory file\r
   UINT8               EntryCount;             // The count of the directory entry in the parent directory file\r
   BOOLEAN             Invalid;                // Indicate whether this directory entry is valid\r
   CHAR16              *FileString;            // The unicode long file name for this directory entry\r
-  struct _FAT_OFILE   *OFile;                 // The OFile of the corresponding directory entry\r
-  struct _FAT_DIRENT  *ShortNameForwardLink;  // Hash successor link for short filename\r
-  struct _FAT_DIRENT  *LongNameForwardLink;   // Hash successor link for long filename\r
+  FAT_OFILE           *OFile;                 // The OFile of the corresponding directory entry\r
+  FAT_DIRENT          *ShortNameForwardLink;  // Hash successor link for short filename\r
+  FAT_DIRENT          *LongNameForwardLink;   // Hash successor link for long filename\r
   LIST_ENTRY          Link;                   // Connection of every directory entry\r
   FAT_DIRECTORY_ENTRY Entry;                  // The physical directory entry stored in disk\r
-} FAT_DIRENT;\r
+};\r
 \r
-typedef struct _FAT_ODIR {\r
+struct _FAT_ODIR {\r
   UINTN               Signature;\r
   UINT32              CurrentEndPos;          // Current end position of the directory\r
   UINT32              CurrentPos;             // Current position of the directory\r
@@ -206,23 +204,43 @@ typedef struct _FAT_ODIR {
   UINTN               DirCacheTag;            // The identification of the directory when in directory cache\r
   FAT_DIRENT          *LongNameHashTable[HASH_TABLE_SIZE];\r
   FAT_DIRENT          *ShortNameHashTable[HASH_TABLE_SIZE];\r
-} FAT_ODIR;\r
+};\r
 \r
 typedef struct {\r
   UINTN               Signature;\r
-  EFI_FILE            Handle;\r
+  EFI_FILE_PROTOCOL   Handle;\r
   UINT64              Position;\r
   BOOLEAN             ReadOnly;\r
-  struct _FAT_OFILE   *OFile;\r
-  LIST_ENTRY          Link;\r
+  FAT_OFILE          *OFile;\r
+  LIST_ENTRY          Tasks;                  // List of all FAT_TASKs\r
+  LIST_ENTRY          Link;                   // Link to other IFiles\r
 } FAT_IFILE;\r
 \r
+typedef struct {\r
+  UINTN               Signature;\r
+  EFI_FILE_IO_TOKEN   *FileIoToken;\r
+  FAT_IFILE           *IFile;\r
+  LIST_ENTRY          Subtasks;               // List of all FAT_SUBTASKs\r
+  LIST_ENTRY          Link;                   // Link to other FAT_TASKs\r
+} FAT_TASK;\r
+\r
+typedef struct {\r
+  UINTN               Signature;\r
+  EFI_DISK_IO2_TOKEN  DiskIo2Token;\r
+  FAT_TASK            *Task;\r
+  BOOLEAN             Write;\r
+  UINT64              Offset;\r
+  VOID                *Buffer;\r
+  UINTN               BufferSize;\r
+  LIST_ENTRY          Link;\r
+} FAT_SUBTASK;\r
+\r
 //\r
 // FAT_OFILE - Each opened file\r
 //\r
-typedef struct _FAT_OFILE {\r
+struct _FAT_OFILE {\r
   UINTN               Signature;\r
-  struct _FAT_VOLUME  *Volume;\r
+  FAT_VOLUME          *Volume;\r
   //\r
   // A permanant error code to return to all accesses to\r
   // this opened file\r
@@ -262,7 +280,7 @@ typedef struct _FAT_OFILE {
   //\r
   // The opened parent, full path length and currently opened child files\r
   //\r
-  struct _FAT_OFILE   *Parent;\r
+  FAT_OFILE           *Parent;\r
   UINTN               FullPathLen;\r
   LIST_ENTRY          ChildHead;\r
   LIST_ENTRY          ChildLink;\r
@@ -281,9 +299,9 @@ typedef struct _FAT_OFILE {
   // Link in Volume's reference list\r
   //\r
   LIST_ENTRY          CheckLink;\r
-} FAT_OFILE;\r
+};\r
 \r
-typedef struct _FAT_VOLUME {\r
+struct _FAT_VOLUME {\r
   UINTN                           Signature;\r
 \r
   EFI_HANDLE                      Handle;\r
@@ -297,6 +315,7 @@ typedef struct _FAT_VOLUME {
   //\r
   EFI_BLOCK_IO_PROTOCOL           *BlockIo;\r
   EFI_DISK_IO_PROTOCOL            *DiskIo;\r
+  EFI_DISK_IO2_PROTOCOL           *DiskIo2;\r
   UINT32                          MediaId;\r
   BOOLEAN                         ReadOnly;\r
 \r
@@ -343,7 +362,7 @@ typedef struct _FAT_VOLUME {
   // File Name of root OFile, it is empty string\r
   //\r
   CHAR16                          RootFileString[1];\r
-  struct _FAT_OFILE               *Root;\r
+  FAT_OFILE                       *Root;\r
 \r
   //\r
   // New OFiles are added to this list so they\r
@@ -361,296 +380,372 @@ typedef struct _FAT_VOLUME {
   // Disk Cache for this volume\r
   //\r
   VOID                            *CacheBuffer;\r
-  DISK_CACHE                      DiskCache[CACHE_MAX_TYPE];\r
-} FAT_VOLUME;\r
+  DISK_CACHE                      DiskCache[CacheMaxType];\r
+};\r
 \r
 //\r
 // Function Prototypes\r
 //\r
+\r
+/**\r
+\r
+  Implements Open() of Simple File System Protocol.\r
+\r
+  @param  FHand                 - File handle of the file serves as a starting reference point.\r
+  @param  NewHandle             - Handle of the file that is newly opened.\r
+  @param  FileName              - File name relative to FHand.\r
+  @param  OpenMode              - Open mode.\r
+  @param  Attributes            - Attributes to set if the file is created.\r
+\r
+\r
+  @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.\r
+                          The OpenMode is not supported.\r
+                          The Attributes is not the valid attributes.\r
+  @retval EFI_OUT_OF_RESOURCES  - Can not allocate the memory for file string.\r
+  @retval EFI_SUCCESS           - Open the file successfully.\r
+  @return Others                - The status of open file.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FatOpen (\r
-  IN  EFI_FILE          *FHand,\r
-  OUT EFI_FILE          **NewHandle,\r
+  IN  EFI_FILE_PROTOCOL *FHand,\r
+  OUT EFI_FILE_PROTOCOL **NewHandle,\r
   IN  CHAR16            *FileName,\r
   IN  UINT64            OpenMode,\r
   IN  UINT64            Attributes\r
   )\r
-/*++\r
-Routine Description:\r
-\r
-  Implements Open() of Simple File System Protocol.\r
+;\r
 \r
-Arguments:\r
+/**\r
 \r
-  FHand                 - File handle of the file serves as a starting reference point.\r
-  NewHandle             - Handle of the file that is newly opened.\r
-  FileName              - File name relative to FHand.\r
-  OpenMode              - Open mode.\r
-  Attributes            - Attributes to set if the file is created.\r
+  Implements OpenEx() of Simple File System Protocol.\r
 \r
-Returns:\r
+  @param  FHand                 - File handle of the file serves as a starting reference point.\r
+  @param  NewHandle             - Handle of the file that is newly opened.\r
+  @param  FileName              - File name relative to FHand.\r
+  @param  OpenMode              - Open mode.\r
+  @param  Attributes            - Attributes to set if the file is created.\r
+  @param  Token                 - A pointer to the token associated with the transaction.\r
 \r
-  EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.\r
+  @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.\r
                           The OpenMode is not supported.\r
                           The Attributes is not the valid attributes.\r
-  EFI_OUT_OF_RESOURCES  - Can not allocate the memory for file string.\r
-  EFI_SUCCESS           - Open the file successfully.\r
-  Others                - The status of open file.\r
-\r
---*/\r
-;\r
+  @retval EFI_OUT_OF_RESOURCES  - Can not allocate the memory for file string.\r
+  @retval EFI_SUCCESS           - Open the file successfully.\r
+  @return Others                - The status of open file.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-FatGetPosition (\r
-  IN  EFI_FILE          *FHand,\r
-  OUT UINT64            *Position\r
+FatOpenEx (\r
+  IN  EFI_FILE_PROTOCOL       *FHand,\r
+  OUT EFI_FILE_PROTOCOL       **NewHandle,\r
+  IN  CHAR16                  *FileName,\r
+  IN  UINT64                  OpenMode,\r
+  IN  UINT64                  Attributes,\r
+  IN OUT EFI_FILE_IO_TOKEN    *Token\r
   )\r
-/*++\r
+;\r
 \r
-Routine Description:\r
+/**\r
 \r
   Get the file's position of the file\r
 \r
-Arguments:\r
-\r
-  FHand                 - The handle of file.\r
-  Position              - The file's position of the file.\r
-\r
-Returns:\r
+  @param  FHand                 - The handle of file.\r
+  @param  Position              - The file's position of the file.\r
 \r
-  EFI_SUCCESS           - Get the info successfully.\r
-  EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
-  EFI_UNSUPPORTED       - The open file is not a file.\r
-\r
---*/\r
-;\r
+  @retval EFI_SUCCESS           - Get the info successfully.\r
+  @retval EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
+  @retval EFI_UNSUPPORTED       - The open file is not a file.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-FatGetInfo (\r
-  IN     EFI_FILE      *FHand,\r
-  IN     EFI_GUID      *Type,\r
-  IN OUT UINTN         *BufferSize,\r
-     OUT VOID          *Buffer\r
+FatGetPosition (\r
+  IN  EFI_FILE_PROTOCOL *FHand,\r
+  OUT UINT64            *Position\r
   )\r
-/*++\r
+;\r
 \r
-Routine Description:\r
+/**\r
 \r
   Get the some types info of the file into Buffer\r
 \r
-Arguments:\r
+  @param  FHand                 - The handle of file.\r
+  @param  Type                  - The type of the info.\r
+  @param  BufferSize            - Size of Buffer.\r
+  @param  Buffer                - Buffer containing volume info.\r
+\r
+  @retval EFI_SUCCESS           - Get the info successfully.\r
+  @retval EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FatGetInfo (\r
+  IN     EFI_FILE_PROTOCOL      *FHand,\r
+  IN     EFI_GUID               *Type,\r
+  IN OUT UINTN                  *BufferSize,\r
+     OUT VOID                   *Buffer\r
+  )\r
+;\r
 \r
-  FHand                 - The handle of file.\r
-  Type                  - The type of the info.\r
-  BufferSize            - Size of Buffer.\r
-  Buffer                - Buffer containing volume info.\r
+/**\r
 \r
-Returns:\r
+  Set the some types info of the file into Buffer.\r
 \r
-  EFI_SUCCESS           - Get the info successfully.\r
-  EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
+  @param  FHand                 - The handle of file.\r
+  @param  Type                  - The type of the info.\r
+  @param  BufferSize            - Size of Buffer.\r
+  @param  Buffer                - Buffer containing volume info.\r
 \r
---*/\r
-;\r
+  @retval EFI_SUCCESS           - Set the info successfully.\r
+  @retval EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FatSetInfo (\r
-  IN EFI_FILE           *FHand,\r
+  IN EFI_FILE_PROTOCOL  *FHand,\r
   IN EFI_GUID           *Type,\r
   IN UINTN              BufferSize,\r
   IN VOID               *Buffer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Set the some types info of the file into Buffer\r
-\r
-Arguments:\r
+;\r
 \r
-  FHand                 - The handle of file.\r
-  Type                  - The type of the info.\r
-  BufferSize            - Size of Buffer.\r
-  Buffer                - Buffer containing volume info.\r
+/**\r
 \r
-Returns:\r
+  Flushes all data associated with the file handle.\r
 \r
-  EFI_SUCCESS           - Set the info successfully.\r
-  EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
+  @param  FHand                 - Handle to file to flush\r
 \r
---*/\r
-;\r
+  @retval EFI_SUCCESS           - Flushed the file successfully\r
+  @retval EFI_WRITE_PROTECTED   - The volume is read only\r
+  @retval EFI_ACCESS_DENIED     - The volume is not read only\r
+                          but the file is read only\r
+  @return Others                - Flushing of the file is failed\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FatFlush (\r
-  IN EFI_FILE           *FHand\r
+  IN EFI_FILE_PROTOCOL  *FHand\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Flushes all data associated with the file handle\r
-\r
-Arguments:\r
+;\r
 \r
-  FHand                 - Handle to file to flush\r
+/**\r
 \r
-Returns:\r
+  Flushes all data associated with the file handle.\r
 \r
-  EFI_SUCCESS           - Flushed the file successfully\r
-  EFI_WRITE_PROTECTED   - The volume is read only\r
-  EFI_ACCESS_DENIED     - The volume is not read only\r
-                          but the file is read only\r
-  Others                - Flushing of the file is failed\r
+  @param  FHand                 - Handle to file to flush.\r
+  @param  Token                 - A pointer to the token associated with the transaction.\r
 \r
---*/\r
-;\r
+  @retval EFI_SUCCESS           - Flushed the file successfully.\r
+  @retval EFI_WRITE_PROTECTED   - The volume is read only.\r
+  @retval EFI_ACCESS_DENIED     - The file is read only.\r
+  @return Others                - Flushing of the file failed.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-FatClose (\r
-  IN EFI_FILE  *FHand\r
+FatFlushEx (\r
+  IN EFI_FILE_PROTOCOL  *FHand,\r
+  IN EFI_FILE_IO_TOKEN  *Token\r
   )\r
-/*++\r
+;\r
 \r
-Routine Description:\r
+/**\r
 \r
   Flushes & Closes the file handle.\r
 \r
-Arguments:\r
+  @param  FHand                 - Handle to the file to delete.\r
 \r
-  FHand                 - Handle to the file to delete.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS           - Closed the file successfully.\r
-\r
---*/\r
-;\r
+  @retval EFI_SUCCESS           - Closed the file successfully.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-FatDelete (\r
-  IN EFI_FILE           *FHand\r
+FatClose (\r
+  IN EFI_FILE_PROTOCOL  *FHand\r
   )\r
-/*++\r
+;\r
 \r
-Routine Description:\r
+/**\r
 \r
   Deletes the file & Closes the file handle.\r
 \r
-Arguments:\r
+  @param  FHand                    - Handle to the file to delete.\r
 \r
-  FHand                    - Handle to the file to delete.\r
+  @retval EFI_SUCCESS              - Delete the file successfully.\r
+  @retval EFI_WARN_DELETE_FAILURE  - Fail to delete the file.\r
 \r
-Returns:\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FatDelete (\r
+  IN EFI_FILE_PROTOCOL  *FHand\r
+  )\r
+;\r
 \r
-  EFI_SUCCESS              - Delete the file successfully.\r
-  EFI_WARN_DELETE_FAILURE  - Fail to delete the file.\r
+/**\r
 \r
---*/\r
-;\r
+  Set the file's position of the file.\r
+\r
+  @param  FHand                 - The handle of file\r
+  @param  Position              - The file's position of the file\r
+\r
+  @retval EFI_SUCCESS           - Set the info successfully\r
+  @retval EFI_DEVICE_ERROR      - Can not find the OFile for the file\r
+  @retval EFI_UNSUPPORTED       - Set a directory with a not-zero position\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FatSetPosition (\r
-  IN EFI_FILE           *FHand,\r
+  IN EFI_FILE_PROTOCOL  *FHand,\r
   IN UINT64             Position\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Set the file's position of the file\r
-\r
-Arguments:\r
+;\r
 \r
-  FHand                 - The handle of file\r
-  Position              - The file's position of the file\r
+/**\r
 \r
-Returns:\r
+  Get the file info.\r
 \r
-  EFI_SUCCESS           - Set the info successfully\r
-  EFI_DEVICE_ERROR      - Can not find the OFile for the file\r
-  EFI_UNSUPPORTED       - Set a directory with a not-zero position\r
+  @param FHand                 - The handle of the file.\r
+  @param BufferSize            - Size of Buffer.\r
+  @param Buffer                - Buffer containing read data.\r
 \r
---*/\r
-;\r
+  @retval EFI_SUCCESS           - Get the file info successfully.\r
+  @retval EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
+  @retval EFI_VOLUME_CORRUPTED  - The file type of open file is error.\r
+  @return other                 - An error occurred when operation the disk.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FatRead (\r
-  IN     EFI_FILE   *FHand,\r
-  IN OUT UINTN      *BufferSize,\r
-     OUT VOID       *Buffer\r
+  IN     EFI_FILE_PROTOCOL    *FHand,\r
+  IN OUT UINTN                *BufferSize,\r
+     OUT VOID                 *Buffer\r
   )\r
-/*++\r
+;\r
 \r
-Routine Description:\r
+/**\r
 \r
   Get the file info.\r
 \r
-Arguments:\r
+  @param FHand                 - The handle of the file.\r
+  @param Token                 - A pointer to the token associated with the transaction.\r
+\r
+  @retval EFI_SUCCESS           - Get the file info successfully.\r
+  @retval EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
+  @retval EFI_VOLUME_CORRUPTED  - The file type of open file is error.\r
+  @return other                 - An error occurred when operation the disk.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FatReadEx (\r
+  IN     EFI_FILE_PROTOCOL  *FHand,\r
+  IN OUT EFI_FILE_IO_TOKEN  *Token\r
+  )\r
+;\r
 \r
-  FHand                 - The handle of the file.\r
-  BufferSize            - Size of Buffer.\r
-  Buffer                - Buffer containing read data.\r
+/**\r
 \r
-Returns:\r
+  Set the file info.\r
 \r
-  EFI_SUCCESS           - Get the file info successfully.\r
-  EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
-  EFI_VOLUME_CORRUPTED  - The file type of open file is error.\r
-  other                 - An error occurred when operation the disk.\r
+  @param  FHand                 - The handle of the file.\r
+  @param  BufferSize            - Size of Buffer.\r
+  @param Buffer                - Buffer containing write data.\r
 \r
---*/\r
-;\r
+  @retval EFI_SUCCESS           - Set the file info successfully.\r
+  @retval EFI_WRITE_PROTECTED   - The disk is write protected.\r
+  @retval EFI_ACCESS_DENIED     - The file is read-only.\r
+  @retval EFI_DEVICE_ERROR      - The OFile is not valid.\r
+  @retval EFI_UNSUPPORTED       - The open file is not a file.\r
+                        - The writing file size is larger than 4GB.\r
+  @return other                 - An error occurred when operation the disk.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FatWrite (\r
-  IN     EFI_FILE      *FHand,\r
-  IN OUT UINTN         *BufferSize,\r
-  IN     VOID          *Buffer\r
+  IN     EFI_FILE_PROTOCOL      *FHand,\r
+  IN OUT UINTN                  *BufferSize,\r
+  IN     VOID                   *Buffer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
+;\r
 \r
-  Set the file info.\r
+/**\r
 \r
-Arguments:\r
+  Get the file info.\r
 \r
-  FHand                 - The handle of the file.\r
-  BufferSize            - Size of Buffer.\r
-  Buffer                - Buffer containing write data.\r
+  @param  FHand                 - The handle of the file.\r
+  @param  Token                 - A pointer to the token associated with the transaction.\r
 \r
-Returns:\r
+  @retval EFI_SUCCESS           - Get the file info successfully.\r
+  @retval EFI_DEVICE_ERROR      - Can not find the OFile for the file.\r
+  @retval EFI_VOLUME_CORRUPTED  - The file type of open file is error.\r
+  @return other                 - An error occurred when operation the disk.\r
 \r
-  EFI_SUCCESS           - Set the file info successfully.\r
-  EFI_WRITE_PROTECTED   - The disk is write protected.\r
-  EFI_ACCESS_DENIED     - The file is read-only.\r
-  EFI_DEVICE_ERROR      - The OFile is not valid.\r
-  EFI_UNSUPPORTED       - The open file is not a file.\r
-                        - The writing file size is larger than 4GB.\r
-  other                 - An error occurred when operation the disk.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FatWriteEx (\r
+  IN     EFI_FILE_PROTOCOL  *FHand,\r
+  IN OUT EFI_FILE_IO_TOKEN  *Token\r
+  )\r
 ;\r
 \r
 //\r
 // DiskCache.c\r
 //\r
+/**\r
+\r
+  Initialize the disk cache according to Volume's FatType.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+\r
+  @retval EFI_SUCCESS           - The disk cache is successfully initialized.\r
+  @retval EFI_OUT_OF_RESOURCES  - Not enough memory to allocate disk cache.\r
+\r
+**/\r
 EFI_STATUS\r
 FatInitializeDiskCache (\r
   IN FAT_VOLUME              *Volume\r
   );\r
 \r
+/**\r
+\r
+  Read BufferSize bytes from the position of Offset into Buffer,\r
+  or write BufferSize bytes from Buffer into the position of Offset.\r
+\r
+  Base on the parameter of CACHE_DATA_TYPE, the data access will be divided into\r
+  the access of FAT cache (CACHE_FAT) and the access of Data cache (CACHE_DATA):\r
+\r
+  1. Access of FAT cache (CACHE_FAT): Access the data in the FAT cache, if there is cache\r
+     page hit, just return the cache page; else update the related cache page and return\r
+     the right cache page.\r
+  2. Access of Data cache (CACHE_DATA):\r
+     The access data will be divided into UnderRun data, Aligned data and OverRun data;\r
+     The UnderRun data and OverRun data will be accessed by the Data cache,\r
+     but the Aligned data will be accessed with disk directly.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+  @param  CacheDataType         - The type of cache: CACHE_DATA or CACHE_FAT.\r
+  @param  IoMode                - Indicate the type of disk access.\r
+  @param  Offset                - The starting byte offset to read from.\r
+  @param  BufferSize            - Size of Buffer.\r
+  @param  Buffer                - Buffer containing cache data.\r
+  @param  Task                    point to task instance.\r
+\r
+  @retval EFI_SUCCESS           - The data was accessed correctly.\r
+  @retval EFI_MEDIA_CHANGED     - The MediaId does not match the current device.\r
+  @return Others                - An error occurred when accessing cache.\r
+\r
+**/\r
 EFI_STATUS\r
 FatAccessCache (\r
   IN     FAT_VOLUME          *Volume,\r
@@ -658,71 +753,198 @@ FatAccessCache (
   IN     IO_MODE             IoMode,\r
   IN     UINT64              Offset,\r
   IN     UINTN               BufferSize,\r
-  IN OUT UINT8               *Buffer\r
+  IN OUT UINT8               *Buffer,\r
+  IN     FAT_TASK            *Task\r
   );\r
 \r
+/**\r
+\r
+  Flush all the dirty cache back, include the FAT cache and the Data cache.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+  @param  Task                    point to task instance.\r
+\r
+  @retval EFI_SUCCESS           - Flush all the dirty cache back successfully\r
+  @return other                 - An error occurred when writing the data into the disk\r
+\r
+**/\r
 EFI_STATUS\r
 FatVolumeFlushCache (\r
-  IN FAT_VOLUME              *Volume\r
+  IN FAT_VOLUME              *Volume,\r
+  IN FAT_TASK                *Task\r
   );\r
 \r
 //\r
 // Flush.c\r
 //\r
+/**\r
+\r
+  Flush the data associated with an open file.\r
+  In this implementation, only last Mod/Access time is updated.\r
+\r
+  @param  OFile                 - The open file.\r
+\r
+  @retval EFI_SUCCESS           - The OFile is flushed successfully.\r
+  @return Others                - An error occurred when flushing this OFile.\r
+\r
+**/\r
 EFI_STATUS\r
 FatOFileFlush (\r
   IN FAT_OFILE          *OFile\r
   );\r
 \r
+/**\r
+\r
+  Check the references of the OFile.\r
+  If the OFile (that is checked) is no longer\r
+  referenced, then it is freed.\r
+\r
+  @param  OFile                 - The OFile to be checked.\r
+\r
+  @retval TRUE                  - The OFile is not referenced and freed.\r
+  @retval FALSE                 - The OFile is kept.\r
+\r
+**/\r
 BOOLEAN\r
 FatCheckOFileRef (\r
   IN FAT_OFILE          *OFile\r
   );\r
 \r
+/**\r
+\r
+  Set the OFile and its child OFile with the error Status\r
+\r
+  @param  OFile                 - The OFile whose permanent error code is to be set.\r
+  @param  Status                - Error code to be set.\r
+\r
+**/\r
 VOID\r
 FatSetVolumeError (\r
   IN FAT_OFILE          *OFile,\r
   IN EFI_STATUS         Status\r
   );\r
 \r
+/**\r
+\r
+  Close the open file instance.\r
+\r
+  @param  IFile                 - Open file instance.\r
+\r
+  @retval EFI_SUCCESS           - Closed the file successfully.\r
+\r
+**/\r
 EFI_STATUS\r
 FatIFileClose (\r
   FAT_IFILE             *IFile\r
   );\r
 \r
+/**\r
+\r
+  Set error status for a specific OFile, reference checking the volume.\r
+  If volume is already marked as invalid, and all resources are freed\r
+  after reference checking, the file system protocol is uninstalled and\r
+  the volume structure is freed.\r
+\r
+  @param  Volume                - the Volume that is to be reference checked and unlocked.\r
+  @param  OFile                 - the OFile whose permanent error code is to be set.\r
+  @param  EfiStatus             - error code to be set.\r
+  @param  Task                    point to task instance.\r
+\r
+  @retval EFI_SUCCESS           - Clean up the volume successfully.\r
+  @return Others                - Cleaning up of the volume is failed.\r
+\r
+**/\r
 EFI_STATUS\r
 FatCleanupVolume (\r
   IN FAT_VOLUME         *Volume,\r
   IN FAT_OFILE          *OFile,\r
-  IN EFI_STATUS         EfiStatus\r
+  IN EFI_STATUS         EfiStatus,\r
+  IN FAT_TASK           *Task\r
   );\r
 \r
 //\r
 // FileSpace.c\r
 //\r
+/**\r
+\r
+  Shrink the end of the open file base on the file size.\r
+\r
+  @param  OFile                 - The open file.\r
+\r
+  @retval EFI_SUCCESS           - Shrinked sucessfully.\r
+  @retval EFI_VOLUME_CORRUPTED  - There are errors in the file's clusters.\r
+\r
+**/\r
 EFI_STATUS\r
 FatShrinkEof (\r
   IN FAT_OFILE          *OFile\r
   );\r
 \r
+/**\r
+\r
+  Grow the end of the open file base on the NewSizeInBytes.\r
+\r
+  @param  OFile                 - The open file.\r
+  @param  NewSizeInBytes        - The new size in bytes of the open file.\r
+\r
+  @retval EFI_SUCCESS           - The file is grown sucessfully.\r
+  @retval EFI_UNSUPPORTED       - The file size is larger than 4GB.\r
+  @retval EFI_VOLUME_CORRUPTED  - There are errors in the files' clusters.\r
+  @retval EFI_VOLUME_FULL       - The volume is full and can not grow the file.\r
+\r
+**/\r
 EFI_STATUS\r
 FatGrowEof (\r
   IN FAT_OFILE          *OFile,\r
   IN UINT64             NewSizeInBytes\r
   );\r
 \r
+/**\r
+\r
+  Get the size of directory of the open file.\r
+\r
+  @param  Volume                - The File System Volume.\r
+  @param  Cluster               - The Starting cluster.\r
+\r
+  @return The physical size of the file starting at the input cluster, if there is error in the\r
+  cluster chain, the return value is 0.\r
+\r
+**/\r
 UINTN\r
 FatPhysicalDirSize (\r
   IN FAT_VOLUME         *Volume,\r
   IN UINTN              Cluster\r
   );\r
 \r
+/**\r
+\r
+  Get the physical size of a file on the disk.\r
+\r
+  @param  Volume                - The file system volume.\r
+  @param  RealSize              - The real size of a file.\r
+\r
+  @return The physical size of a file on the disk.\r
+\r
+**/\r
 UINT64\r
 FatPhysicalFileSize (\r
   IN FAT_VOLUME         *Volume,\r
   IN UINTN              RealSize\r
   );\r
 \r
+/**\r
+\r
+  Seek OFile to requested position, and calculate the number of\r
+  consecutive clusters from the position in the file\r
+\r
+  @param  OFile                 - The open file.\r
+  @param  Position              - The file's position which will be accessed.\r
+  @param  PosLimit              - The maximum length current reading/writing may access\r
+\r
+  @retval EFI_SUCCESS           - Set the info successfully.\r
+  @retval EFI_VOLUME_CORRUPTED  - Cluster chain corrupt.\r
+\r
+**/\r
 EFI_STATUS\r
 FatOFilePosition (\r
   IN FAT_OFILE            *OFile,\r
@@ -730,6 +952,13 @@ FatOFilePosition (
   IN UINTN                PosLimit\r
   );\r
 \r
+/**\r
+\r
+  Update the free cluster info of FatInfoSector of the volume.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+\r
+**/\r
 VOID\r
 FatComputeFreeInfo (\r
   IN FAT_VOLUME         *Volume\r
@@ -738,18 +967,55 @@ FatComputeFreeInfo (
 //\r
 // Init.c\r
 //\r
+/**\r
+\r
+  Allocates volume structure, detects FAT file system, installs protocol,\r
+  and initialize cache.\r
+\r
+  @param  Handle                - The handle of parent device.\r
+  @param  DiskIo                - The DiskIo of parent device.\r
+  @param  DiskIo2               - The DiskIo2 of parent device.\r
+  @param  BlockIo               - The BlockIo of parent devicel\r
+\r
+  @retval EFI_SUCCESS           - Allocate a new volume successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  - Can not allocate the memory.\r
+  @return Others                - Allocating a new volume failed.\r
+\r
+**/\r
 EFI_STATUS\r
 FatAllocateVolume (\r
   IN  EFI_HANDLE                     Handle,\r
   IN  EFI_DISK_IO_PROTOCOL           *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL          *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL          *BlockIo\r
   );\r
 \r
+/**\r
+\r
+  Detects FAT file system on Disk and set relevant fields of Volume.\r
+\r
+  @param Volume                - The volume structure.\r
+\r
+  @retval EFI_SUCCESS           - The Fat File System is detected successfully\r
+  @retval EFI_UNSUPPORTED       - The volume is not FAT file system.\r
+  @retval EFI_VOLUME_CORRUPTED  - The volume is corrupted.\r
+\r
+**/\r
 EFI_STATUS\r
 FatOpenDevice (\r
   IN OUT FAT_VOLUME     *Volume\r
   );\r
 \r
+/**\r
+\r
+  Called by FatDriverBindingStop(), Abandon the volume.\r
+\r
+  @param  Volume                - The volume to be abandoned.\r
+\r
+  @retval EFI_SUCCESS           - Abandoned the volume successfully.\r
+  @return Others                - Can not uninstall the protocol interfaces.\r
+\r
+**/\r
 EFI_STATUS\r
 FatAbandonVolume (\r
   IN FAT_VOLUME         *Volume\r
@@ -758,6 +1024,89 @@ FatAbandonVolume (
 //\r
 // Misc.c\r
 //\r
+/**\r
+\r
+  Create the task\r
+\r
+  @param  IFile                 - The instance of the open file.\r
+  @param  Token                 - A pointer to the token associated with the transaction.\r
+\r
+  @return FAT_TASK *            - Return the task instance.\r
+\r
+**/\r
+FAT_TASK *\r
+FatCreateTask (\r
+  FAT_IFILE           *IFile,\r
+  EFI_FILE_IO_TOKEN   *Token\r
+  );\r
+\r
+/**\r
+\r
+  Destroy the task.\r
+\r
+  @param  Task                  - The task to be destroyed.\r
+\r
+**/\r
+VOID\r
+FatDestroyTask (\r
+  FAT_TASK            *Task\r
+  );\r
+\r
+/**\r
+\r
+  Wait all non-blocking requests complete.\r
+\r
+  @param  IFile                 - The instance of the open file.\r
+\r
+**/\r
+VOID\r
+FatWaitNonblockingTask (\r
+  FAT_IFILE           *IFile\r
+  );\r
+\r
+/**\r
+\r
+  Remove the subtask from subtask list.\r
+\r
+  @param  Subtask               - The subtask to be removed.\r
+\r
+  @return LIST_ENTRY *          - The next node in the list.\r
+\r
+**/\r
+LIST_ENTRY *\r
+FatDestroySubtask (\r
+  FAT_SUBTASK         *Subtask\r
+  );\r
+\r
+/**\r
+\r
+  Execute the task.\r
+\r
+  @param  IFile                 - The instance of the open file.\r
+  @param  Task                  - The task to be executed.\r
+\r
+  @retval EFI_SUCCESS           - The task was executed sucessfully.\r
+  @return other                 - An error occurred when executing the task.\r
+\r
+**/\r
+EFI_STATUS\r
+FatQueueTask (\r
+  IN FAT_IFILE        *IFile,\r
+  IN FAT_TASK         *Task\r
+  );\r
+\r
+/**\r
+\r
+  Set the volume as dirty or not.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+  @param  IoMode                - The access mode.\r
+  @param  DirtyValue            - Set the volume as dirty or not.\r
+\r
+  @retval EFI_SUCCESS           - Set the new FAT entry value sucessfully.\r
+  @return other                 - An error occurred when operation the FAT entries.\r
+\r
+**/\r
 EFI_STATUS\r
 FatAccessVolumeDirty (\r
   IN FAT_VOLUME         *Volume,\r
@@ -765,57 +1114,141 @@ FatAccessVolumeDirty (
   IN VOID               *DirtyValue\r
   );\r
 \r
+/**\r
+\r
+  General disk access function.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+  @param  IoMode                - The access mode (disk read/write or cache access).\r
+  @param  Offset                - The starting byte offset to read from.\r
+  @param  BufferSize            - Size of Buffer.\r
+  @param  Buffer                - Buffer containing read data.\r
+  @param  Task                    point to task instance.\r
+\r
+  @retval EFI_SUCCESS           - The operation is performed successfully.\r
+  @retval EFI_VOLUME_CORRUPTED  - The accesss is\r
+  @return Others                - The status of read/write the disk\r
+\r
+**/\r
 EFI_STATUS\r
 FatDiskIo (\r
   IN FAT_VOLUME         *Volume,\r
   IN IO_MODE            IoMode,\r
   IN UINT64             Offset,\r
   IN UINTN              BufferSize,\r
-  IN OUT VOID           *Buffer\r
+  IN OUT VOID           *Buffer,\r
+  IN FAT_TASK           *Task\r
   );\r
 \r
+/**\r
+\r
+  Lock the volume.\r
+\r
+**/\r
 VOID\r
 FatAcquireLock (\r
   VOID\r
   );\r
 \r
+/**\r
+\r
+  Unlock the volume.\r
+\r
+**/\r
 VOID\r
 FatReleaseLock (\r
   VOID\r
   );\r
 \r
-BOOLEAN\r
-FatIsLocked (\r
+/**\r
+\r
+  Lock the volume.\r
+  If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.\r
+  Otherwise, EFI_SUCCESS is returned.\r
+\r
+  @retval EFI_SUCCESS           - The volume is locked.\r
+  @retval EFI_ACCESS_DENIED     - The volume could not be locked because it is already locked.\r
+\r
+**/\r
+EFI_STATUS\r
+FatAcquireLockOrFail (\r
   VOID\r
   );\r
 \r
+/**\r
+\r
+  Free directory entry.\r
+\r
+  @param  DirEnt                - The directory entry to be freed.\r
+\r
+**/\r
 VOID\r
 FatFreeDirEnt (\r
   IN FAT_DIRENT         *DirEnt\r
   );\r
 \r
+/**\r
+\r
+  Free volume structure (including the contents of directory cache and disk cache).\r
+\r
+  @param  Volume                - The volume structure to be freed.\r
+\r
+**/\r
 VOID\r
 FatFreeVolume (\r
   IN FAT_VOLUME         *Volume\r
   );\r
 \r
+/**\r
+\r
+  Translate EFI time to FAT time.\r
+\r
+  @param  ETime                 - The time of EFI_TIME.\r
+  @param  FTime                 - The time of FAT_DATE_TIME.\r
+\r
+**/\r
 VOID\r
 FatEfiTimeToFatTime (\r
   IN EFI_TIME           *ETime,\r
   OUT FAT_DATE_TIME     *FTime\r
   );\r
 \r
+/**\r
+\r
+  Translate Fat time to EFI time.\r
+\r
+  @param  FTime                 - The time of FAT_DATE_TIME.\r
+  @param  ETime                 - The time of EFI_TIME..\r
+\r
+**/\r
 VOID\r
 FatFatTimeToEfiTime (\r
   IN FAT_DATE_TIME      *FTime,\r
   OUT EFI_TIME          *ETime\r
   );\r
 \r
+/**\r
+\r
+  Get Current FAT time.\r
+\r
+  @param  FatTime               - Current FAT time.\r
+\r
+**/\r
 VOID\r
 FatGetCurrentFatTime (\r
   OUT FAT_DATE_TIME     *FatTime\r
   );\r
 \r
+/**\r
+\r
+  Check whether a time is valid.\r
+\r
+  @param  Time                  - The time of EFI_TIME.\r
+\r
+  @retval TRUE                  - The time is valid.\r
+  @retval FALSE                 - The time is not valid.\r
+\r
+**/\r
 BOOLEAN\r
 FatIsValidTime (\r
   IN EFI_TIME           *Time\r
@@ -824,11 +1257,34 @@ FatIsValidTime (
 //\r
 // UnicodeCollation.c\r
 //\r
+/**\r
+  Initialize Unicode Collation support.\r
+\r
+  It tries to locate Unicode Collation 2 protocol and matches it with current\r
+  platform language code. If for any reason the first attempt fails, it then tries to\r
+  use Unicode Collation Protocol.\r
+\r
+  @param  AgentHandle          The handle used to open Unicode Collation (2) protocol.\r
+\r
+  @retval EFI_SUCCESS          The Unicode Collation (2) protocol has been successfully located.\r
+  @retval Others               The Unicode Collation (2) protocol has not been located.\r
+\r
+**/\r
 EFI_STATUS\r
 InitializeUnicodeCollationSupport (\r
   IN EFI_HANDLE    AgentHandle\r
   );\r
 \r
+/**\r
+  Convert FAT string to unicode string.\r
+\r
+  @param  FatSize               The size of FAT string.\r
+  @param  Fat                   The FAT string.\r
+  @param  String                The unicode string.\r
+\r
+  @return None.\r
+\r
+**/\r
 VOID\r
 FatFatToStr (\r
   IN UINTN              FatSize,\r
@@ -836,6 +1292,17 @@ FatFatToStr (
   OUT CHAR16            *String\r
   );\r
 \r
+/**\r
+  Convert unicode string to Fat string.\r
+\r
+  @param  String                The unicode string.\r
+  @param  FatSize               The size of the FAT string.\r
+  @param  Fat                   The FAT string.\r
+\r
+  @retval TRUE                  Convert successfully.\r
+  @retval FALSE                 Convert error.\r
+\r
+**/\r
 BOOLEAN\r
 FatStrToFat (\r
   IN  CHAR16            *String,\r
@@ -843,16 +1310,38 @@ FatStrToFat (
   OUT CHAR8             *Fat\r
   );\r
 \r
+/**\r
+  Lowercase a string\r
+\r
+  @param  Str                   The string which will be lower-cased.\r
+\r
+**/\r
 VOID\r
 FatStrLwr (\r
   IN CHAR16             *Str\r
   );\r
 \r
+/**\r
+  Uppercase a string.\r
+\r
+  @param  Str                   The string which will be upper-cased.\r
+\r
+**/\r
 VOID\r
 FatStrUpr (\r
   IN CHAR16             *Str\r
   );\r
 \r
+/**\r
+  Performs a case-insensitive comparison of two Null-terminated Unicode strings.\r
+\r
+  @param  Str1                   A pointer to a Null-terminated Unicode string.\r
+  @param  Str2                   A pointer to a Null-terminated Unicode string.\r
+\r
+  @retval 0                    S1 is equivalent to S2.\r
+  @retval >0                   S1 is lexically greater than S2.\r
+  @retval <0                   S1 is lexically less than S2.\r
+**/\r
 INTN\r
 FatStriCmp (\r
   IN CHAR16             *Str1,\r
@@ -862,6 +1351,29 @@ FatStriCmp (
 //\r
 // Open.c\r
 //\r
+\r
+/**\r
+\r
+  Open a file for a file name relative to an existing OFile.\r
+  The IFile of the newly opened file is passed out.\r
+\r
+  @param  OFile                 - The file that serves as a starting reference point.\r
+  @param  NewIFile              - The newly generated IFile instance.\r
+  @param  FileName              - The file name relative to the OFile.\r
+  @param  OpenMode              - Open mode.\r
+  @param  Attributes            - Attributes to set if the file is created.\r
+\r
+\r
+  @retval EFI_SUCCESS           - Open the file successfully.\r
+  @retval EFI_INVALID_PARAMETER - The open mode is conflict with the attributes\r
+                          or the file name is not valid.\r
+  @retval EFI_NOT_FOUND         - Conficts between dir intention and attribute.\r
+  @retval EFI_WRITE_PROTECTED   - Can't open for write if the volume is read only.\r
+  @retval EFI_ACCESS_DENIED     - If the file's attribute is read only, and the\r
+                          open is for read-write fail it.\r
+  @retval EFI_OUT_OF_RESOURCES  - Can not allocate the memory.\r
+\r
+**/\r
 EFI_STATUS\r
 FatOFileOpen (\r
   IN FAT_OFILE          *OFile,\r
@@ -871,6 +1383,18 @@ FatOFileOpen (
   IN UINT8              Attributes\r
   );\r
 \r
+/**\r
+\r
+  Create an Open instance for the existing OFile.\r
+  The IFile of the newly opened file is passed out.\r
+\r
+  @param  OFile                 - The file that serves as a starting reference point.\r
+  @param  PtrIFile              - The newly generated IFile instance.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  - Can not allocate the memory for the IFile\r
+  @retval EFI_SUCCESS           - Create the new IFile for the OFile successfully\r
+\r
+**/\r
 EFI_STATUS\r
 FatAllocateIFile (\r
   IN FAT_OFILE          *OFile,\r
@@ -880,37 +1404,100 @@ FatAllocateIFile (
 //\r
 // OpenVolume.c\r
 //\r
+/**\r
+\r
+  Implements Simple File System Protocol interface function OpenVolume().\r
+\r
+  @param  This                  - Calling context.\r
+  @param  File                  - the Root Directory of the volume.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  - Can not allocate the memory.\r
+  @retval EFI_VOLUME_CORRUPTED  - The FAT type is error.\r
+  @retval EFI_SUCCESS           - Open the volume successfully.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FatOpenVolume (\r
   IN  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r
-  OUT EFI_FILE                        **File\r
+  OUT EFI_FILE_PROTOCOL               **File\r
   );\r
 \r
 //\r
 // ReadWrite.c\r
 //\r
+/**\r
+\r
+  This function reads data from a file or writes data to a file.\r
+  It uses OFile->PosRem to determine how much data can be accessed in one time.\r
+\r
+  @param  OFile                 - The open file.\r
+  @param  IoMode                - Indicate whether the access mode is reading or writing.\r
+  @param  Position              - The position where data will be accessed.\r
+  @param  DataBufferSize        - Size of Buffer.\r
+  @param  UserBuffer            - Buffer containing data.\r
+  @param  Task                    point to task instance.\r
+\r
+  @retval EFI_SUCCESS           - Access the data successfully.\r
+  @return other                 - An error occurred when operating on the disk.\r
+\r
+**/\r
 EFI_STATUS\r
 FatAccessOFile (\r
   IN FAT_OFILE          *OFile,\r
   IN IO_MODE            IoMode,\r
   IN UINTN              Position,\r
   IN UINTN              *DataBufferSize,\r
-  IN UINT8              *UserBuffer\r
+  IN UINT8              *UserBuffer,\r
+  IN FAT_TASK           *Task\r
   );\r
 \r
+/**\r
+\r
+  Expand OFile by appending zero bytes at the end of OFile.\r
+\r
+  @param  OFile                 - The open file.\r
+  @param  ExpandedSize          - The number of zero bytes appended at the end of the file.\r
+\r
+  @retval EFI_SUCCESS           - The file is expanded successfully.\r
+  @return other                 - An error occurred when expanding file.\r
+\r
+**/\r
 EFI_STATUS\r
 FatExpandOFile (\r
   IN FAT_OFILE          *OFile,\r
   IN UINT64             ExpandedSize\r
   );\r
 \r
+/**\r
+\r
+  Write zero pool from the WritePos to the end of OFile.\r
+\r
+  @param  OFile                 - The open file to write zero pool.\r
+  @param  WritePos              - The number of zero bytes written.\r
+\r
+  @retval EFI_SUCCESS           - Write the zero pool successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  - Not enough memory to perform the operation.\r
+  @return other                 - An error occurred when writing disk.\r
+\r
+**/\r
 EFI_STATUS\r
 FatWriteZeroPool (\r
   IN FAT_OFILE          *OFile,\r
   IN UINTN              WritePos\r
   );\r
 \r
+/**\r
+\r
+  Truncate the OFile to smaller file size.\r
+\r
+  @param  OFile                 - The open file.\r
+  @param  TruncatedSize         - The new file size.\r
+\r
+  @retval EFI_SUCCESS           - The file is truncated successfully.\r
+  @return other                 - An error occurred when truncating file.\r
+\r
+**/\r
 EFI_STATUS\r
 FatTruncateOFile (\r
   IN FAT_OFILE          *OFile,\r
@@ -920,29 +1507,83 @@ FatTruncateOFile (
 //\r
 // DirectoryManage.c\r
 //\r
+/**\r
+\r
+  Set the OFile's current directory cursor to the list head.\r
+\r
+  @param OFile                 - The directory OFile whose directory cursor is reset.\r
+\r
+**/\r
 VOID\r
 FatResetODirCursor (\r
   IN FAT_OFILE          *OFile\r
   );\r
 \r
+/**\r
+\r
+  Set the directory's cursor to the next and get the next directory entry.\r
+\r
+  @param  OFile                 - The parent OFile.\r
+  @param PtrDirEnt             - The next directory entry.\r
+\r
+  @retval EFI_SUCCESS           - We get the next directory entry successfully.\r
+  @return other                 - An error occurred when get next directory entry.\r
+\r
+**/\r
 EFI_STATUS\r
 FatGetNextDirEnt (\r
-  IN  FAT_OFILE         *OFILE,\r
+  IN  FAT_OFILE         *OFile,\r
   OUT FAT_DIRENT        **PtrDirEnt\r
   );\r
 \r
+/**\r
+\r
+  Remove this directory entry node from the list of directory entries and hash table.\r
+\r
+  @param  OFile                - The parent OFile.\r
+  @param  DirEnt               - The directory entry to be removed.\r
+\r
+  @retval EFI_SUCCESS          - The directory entry is successfully removed.\r
+  @return other                - An error occurred when removing the directory entry.\r
+\r
+**/\r
 EFI_STATUS\r
 FatRemoveDirEnt (\r
   IN FAT_OFILE          *OFile,\r
   IN FAT_DIRENT         *DirEnt\r
   );\r
 \r
+/**\r
+\r
+  Save the directory entry to disk.\r
+\r
+  @param  OFile                 - The parent OFile which needs to update.\r
+  @param  DirEnt                - The directory entry to be saved.\r
+\r
+  @retval EFI_SUCCESS           - Store the directory entry successfully.\r
+  @return other                 - An error occurred when writing the directory entry.\r
+\r
+**/\r
 EFI_STATUS\r
 FatStoreDirEnt (\r
   IN FAT_OFILE          *OFile,\r
   IN FAT_DIRENT         *DirEnt\r
   );\r
 \r
+/**\r
+\r
+  Create a directory entry in the parent OFile.\r
+\r
+  @param  OFile                 - The parent OFile.\r
+  @param  FileName              - The filename of the newly-created directory entry.\r
+  @param  Attributes            - The attribute of the newly-created directory entry.\r
+  @param  PtrDirEnt             - The pointer to the newly-created directory entry.\r
+\r
+  @retval EFI_SUCCESS           - The directory entry is successfully created.\r
+  @retval EFI_OUT_OF_RESOURCES  - Not enough memory to create the directory entry.\r
+  @return other                 - An error occurred when creating the directory entry.\r
+\r
+**/\r
 EFI_STATUS\r
 FatCreateDirEnt (\r
   IN  FAT_OFILE         *OFile,\r
@@ -951,22 +1592,60 @@ FatCreateDirEnt (
   OUT FAT_DIRENT        **PtrDirEnt\r
   );\r
 \r
+/**\r
+\r
+  Determine whether the directory entry is "." or ".." entry.\r
+\r
+  @param  DirEnt               - The corresponding directory entry.\r
+\r
+  @retval TRUE                 - The directory entry is "." or ".." directory entry\r
+  @retval FALSE                - The directory entry is not "." or ".." directory entry\r
+\r
+**/\r
 BOOLEAN\r
 FatIsDotDirEnt (\r
   IN FAT_DIRENT         *DirEnt\r
   );\r
 \r
+/**\r
+\r
+  Set the OFile's cluster and size info in its directory entry.\r
+\r
+  @param  OFile                 - The corresponding OFile.\r
+\r
+**/\r
 VOID\r
 FatUpdateDirEntClusterSizeInfo (\r
   IN FAT_OFILE          *OFile\r
   );\r
 \r
+/**\r
+\r
+  Copy all the information of DirEnt2 to DirEnt1 except for 8.3 name.\r
+\r
+  @param  DirEnt1               - The destination directory entry.\r
+  @param  DirEnt2               - The source directory entry.\r
+\r
+**/\r
 VOID\r
 FatCloneDirEnt (\r
   IN  FAT_DIRENT        *DirEnt1,\r
   IN  FAT_DIRENT        *DirEnt2\r
   );\r
 \r
+/**\r
+\r
+  Get the directory entry's info into Buffer.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+  @param  DirEnt                - The corresponding directory entry.\r
+  @param  BufferSize            - Size of Buffer.\r
+  @param  Buffer                - Buffer containing file info.\r
+\r
+  @retval EFI_SUCCESS           - Get the file info successfully.\r
+  @retval EFI_BUFFER_TOO_SMALL  - The buffer is too small.\r
+\r
+**/\r
 EFI_STATUS\r
 FatGetDirEntInfo (\r
   IN FAT_VOLUME         *Volume,\r
@@ -975,22 +1654,71 @@ FatGetDirEntInfo (
   OUT VOID              *Buffer\r
   );\r
 \r
+/**\r
+\r
+  Open the directory entry to get the OFile.\r
+\r
+  @param  Parent                - The parent OFile.\r
+  @param  DirEnt                - The directory entry to be opened.\r
+\r
+  @retval EFI_SUCCESS           - The directory entry is successfully opened.\r
+  @retval EFI_OUT_OF_RESOURCES  - not enough memory to allocate a new OFile.\r
+  @return other                 - An error occurred when opening the directory entry.\r
+\r
+**/\r
 EFI_STATUS\r
 FatOpenDirEnt (\r
   IN FAT_OFILE          *OFile,\r
   IN FAT_DIRENT         *DirEnt\r
   );\r
 \r
+/**\r
+\r
+  Create "." and ".." directory entries in the newly-created parent OFile.\r
+\r
+  @param  OFile                 - The parent OFile.\r
+\r
+  @retval EFI_SUCCESS           - The dot directory entries are successfully created.\r
+  @return other                 - An error occurred when creating the directory entry.\r
+\r
+**/\r
 EFI_STATUS\r
 FatCreateDotDirEnts (\r
   IN FAT_OFILE          *OFile\r
   );\r
 \r
+/**\r
+\r
+  Close the directory entry and free the OFile.\r
+\r
+  @param  DirEnt               - The directory entry to be closed.\r
+\r
+**/\r
 VOID\r
 FatCloseDirEnt (\r
   IN FAT_DIRENT         *DirEnt\r
   );\r
 \r
+/**\r
+\r
+  Traverse filename and open all OFiles that can be opened.\r
+  Update filename pointer to the component that can't be opened.\r
+  If more than one name component remains, returns an error;\r
+  otherwise, return the remaining name component so that the caller might choose to create it.\r
+\r
+  @param  PtrOFile              - As input, the reference OFile; as output, the located OFile.\r
+  @param  FileName              - The file name relevant to the OFile.\r
+  @param  Attributes            - The attribute of the destination OFile.\r
+  @param  NewFileName           - The remaining file name.\r
+\r
+  @retval EFI_NOT_FOUND         - The file name can't be opened and there is more than one\r
+                          components within the name left (this means the name can\r
+                          not be created either).\r
+  @retval EFI_INVALID_PARAMETER - The parameter is not valid.\r
+  @retval EFI_SUCCESS           - Open the file successfully.\r
+  @return other                 - An error occured when locating the OFile.\r
+\r
+**/\r
 EFI_STATUS\r
 FatLocateOFile (\r
   IN OUT FAT_OFILE      **PtrOFile,\r
@@ -999,12 +1727,35 @@ FatLocateOFile (
      OUT CHAR16         *NewFileName\r
   );\r
 \r
+/**\r
+\r
+  Get the directory entry for the volume.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+  @param  Name                  - The file name of the volume.\r
+\r
+  @retval EFI_SUCCESS           - Update the volume with the directory entry sucessfully.\r
+  @return others                - An error occurred when getting volume label.\r
+\r
+**/\r
 EFI_STATUS\r
 FatGetVolumeEntry (\r
   IN FAT_VOLUME         *Volume,\r
   IN CHAR16             *Name\r
   );\r
 \r
+/**\r
+\r
+  Set the relevant directory entry into disk for the volume.\r
+\r
+  @param  Volume              - FAT file system volume.\r
+  @param  Name                - The new file name of the volume.\r
+\r
+  @retval EFI_SUCCESS         - Update the Volume sucessfully.\r
+  @retval EFI_UNSUPPORTED     - The input label is not a valid volume label.\r
+  @return other               - An error occurred when setting volume label.\r
+\r
+**/\r
 EFI_STATUS\r
 FatSetVolumeEntry (\r
   IN FAT_VOLUME         *Volume,\r
@@ -1014,24 +1765,60 @@ FatSetVolumeEntry (
 //\r
 // Hash.c\r
 //\r
+/**\r
+\r
+  Search the long name hash table for the directory entry.\r
+\r
+  @param  ODir                  - The directory to be searched.\r
+  @param  LongNameString        - The long name string to search.\r
+\r
+  @return The previous long name hash node of the directory entry.\r
+\r
+**/\r
 FAT_DIRENT **\r
 FatLongNameHashSearch (\r
   IN FAT_ODIR           *ODir,\r
   IN CHAR16             *LongNameString\r
   );\r
 \r
+/**\r
+\r
+  Search the short name hash table for the directory entry.\r
+\r
+  @param  ODir                  - The directory to be searched.\r
+  @param  ShortNameString       - The short name string to search.\r
+\r
+  @return The previous short name hash node of the directory entry.\r
+\r
+**/\r
 FAT_DIRENT **\r
 FatShortNameHashSearch (\r
   IN FAT_ODIR           *ODir,\r
   IN CHAR8              *ShortNameString\r
   );\r
 \r
+/**\r
+\r
+  Insert directory entry to hash table.\r
+\r
+  @param  ODir                  - The parent directory.\r
+  @param  DirEnt                - The directory entry node.\r
+\r
+**/\r
 VOID\r
 FatInsertToHashTable (\r
   IN FAT_ODIR           *ODir,\r
   IN FAT_DIRENT         *DirEnt\r
   );\r
 \r
+/**\r
+\r
+  Delete directory entry from hash table.\r
+\r
+  @param  ODir                  - The parent directory.\r
+  @param  DirEnt                - The directory entry node.\r
+\r
+**/\r
 VOID\r
 FatDeleteFromHashTable (\r
   IN FAT_ODIR           *ODir,\r
@@ -1041,18 +1828,50 @@ FatDeleteFromHashTable (
 //\r
 // FileName.c\r
 //\r
+/**\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
+  @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
+  @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
+\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
+\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
@@ -1061,28 +1880,79 @@ FatNameToStr (
   IN CHAR16             *Str\r
   );\r
 \r
+/**\r
+\r
+  Set the caseflag value for the directory entry.\r
+\r
+  @param DirEnt                - The logical directory entry whose caseflag value is to be set.\r
+\r
+**/\r
 VOID\r
 FatSetCaseFlag (\r
   IN FAT_DIRENT         *DirEnt\r
   );\r
 \r
+/**\r
+\r
+  Convert the 8.3 ASCII fat name to cased Unicode string according to case flag.\r
+\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
 VOID\r
 FatGetFileNameViaCaseFlag (\r
-  IN  FAT_DIRENT        *DirEnt,\r
-  OUT CHAR16            *FileString\r
+  IN     FAT_DIRENT     *DirEnt,\r
+  IN OUT CHAR16         *FileString,\r
+  IN     UINTN          FileStringMax\r
   );\r
 \r
+/**\r
+\r
+  Get the Check sum for a short name.\r
+\r
+  @param  ShortNameString       - The short name for a file.\r
+\r
+  @retval Sum                   - UINT8 checksum.\r
+\r
+**/\r
 UINT8\r
 FatCheckSum (\r
   IN CHAR8              *ShortNameString\r
   );\r
 \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
+  @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
 CHAR16*\r
 FatGetNextNameComponent (\r
   IN  CHAR16            *Path,\r
   OUT CHAR16            *Name\r
   );\r
 \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
+  @param  InputFileName         - The input file name.\r
+  @param  OutputFileName        - The output file name.\r
+\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
 BOOLEAN\r
 FatFileNameIsValid (\r
   IN  CHAR16  *InputFileName,\r
@@ -1092,16 +1962,40 @@ FatFileNameIsValid (
 //\r
 // DirectoryCache.c\r
 //\r
+/**\r
+\r
+  Discard the directory structure when an OFile will be freed.\r
+  Volume will cache this directory if the OFile does not represent a deleted file.\r
+\r
+  @param  OFile                 - The OFile whose directory structure is to be discarded.\r
+\r
+**/\r
 VOID\r
 FatDiscardODir (\r
   IN FAT_OFILE    *OFile\r
   );\r
 \r
+/**\r
+\r
+  Request the directory structure when an OFile is newly generated.\r
+  If the directory structure is cached by volume, then just return this directory;\r
+  Otherwise, allocate a new one for OFile.\r
+\r
+  @param  OFile                 - The OFile which requests directory structure.\r
+\r
+**/\r
 VOID\r
 FatRequestODir (\r
   IN FAT_OFILE    *OFile\r
   );\r
 \r
+/**\r
+\r
+  Clean up all the cached directory structures when the volume is going to be abandoned.\r
+\r
+  @param  Volume                - FAT file system volume.\r
+\r
+**/\r
 VOID\r
 FatCleanupODirCache (\r
   IN FAT_VOLUME   *Volume\r
@@ -1114,6 +2008,7 @@ extern EFI_DRIVER_BINDING_PROTOCOL     gFatDriverBinding;
 extern EFI_COMPONENT_NAME_PROTOCOL     gFatComponentName;\r
 extern EFI_COMPONENT_NAME2_PROTOCOL    gFatComponentName2;\r
 extern EFI_LOCK                        FatFsLock;\r
-extern EFI_FILE                        FatFileInterface;\r
+extern EFI_LOCK                        FatTaskLock;\r
+extern EFI_FILE_PROTOCOL               FatFileInterface;\r
 \r
 #endif\r