]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/Open.c
SecurityPkg-Opal(2): Enhance AHCI Bar MMIO region check.
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Open.c
index b6369cf0b3af10d19cada1b4d8a8658b64a51832..1d864d1248c8d30d85560515e337af0a99933c9c 100644 (file)
@@ -1,7 +1,7 @@
 /*++\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 - 2014, 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
@@ -62,10 +62,20 @@ Returns:
 \r
   IFile->Signature = FAT_IFILE_SIGNATURE;\r
 \r
-  CopyMem (&(IFile->Handle), &FatFileInterface, sizeof (EFI_FILE));\r
+  CopyMem (&(IFile->Handle), &FatFileInterface, sizeof (EFI_FILE_PROTOCOL));\r
+\r
+  //\r
+  // Report the correct revision number based on the DiskIo2 availability\r
+  //\r
+  if (OFile->Volume->DiskIo2 != NULL) {\r
+    IFile->Handle.Revision = EFI_FILE_PROTOCOL_REVISION2;\r
+  } else {\r
+    IFile->Handle.Revision = EFI_FILE_PROTOCOL_REVISION;\r
+  }\r
 \r
   IFile->OFile = OFile;\r
   InsertTailList (&OFile->Opens, &IFile->Link);\r
+  InitializeListHead (&IFile->Tasks);\r
 \r
   *PtrIFile = IFile;\r
   return EFI_SUCCESS;\r
@@ -114,6 +124,7 @@ Returns:
   UINT8       FileAttributes;\r
   BOOLEAN     WriteMode;\r
 \r
+  DirEnt = NULL;\r
   Volume = OFile->Volume;\r
   ASSERT_VOLUME_LOCKED (Volume);\r
   WriteMode = (BOOLEAN) (OpenMode & EFI_FILE_MODE_WRITE);\r
@@ -149,6 +160,7 @@ Returns:
       return Status;\r
     }\r
 \r
+    ASSERT (DirEnt != NULL);\r
     Status = FatOpenDirEnt (OFile, DirEnt);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -189,17 +201,18 @@ Returns:
 \r
 EFI_STATUS\r
 EFIAPI\r
-FatOpen (\r
-  IN  EFI_FILE   *FHand,\r
-  OUT EFI_FILE   **NewHandle,\r
-  IN  CHAR16     *FileName,\r
-  IN  UINT64     OpenMode,\r
-  IN  UINT64     Attributes\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
 Routine Description:\r
 \r
-  Implements Open() of Simple File System Protocol.\r
+  Implements OpenEx() of Simple File System Protocol.\r
 \r
 Arguments:\r
 \r
@@ -208,6 +221,7 @@ Arguments:
   FileName              - File name relative to FHand.\r
   OpenMode              - Open mode.\r
   Attributes            - Attributes to set if the file is created.\r
+  Token                 - A pointer to the token associated with the transaction.\r
 \r
 Returns:\r
 \r
@@ -224,6 +238,7 @@ Returns:
   FAT_IFILE   *NewIFile;\r
   FAT_OFILE   *OFile;\r
   EFI_STATUS  Status;\r
+  FAT_TASK    *Task;\r
 \r
   //\r
   // Perform some parameter checking\r
@@ -243,21 +258,33 @@ Returns:
   default:\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   //\r
-  // Check for valid attributes\r
-  //\r
-  if (Attributes & (~EFI_FILE_VALID_ATTR)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Can't open for create and apply the read only attribute\r
+  // Check for valid Attributes for file creation case. \r
   //\r
-  if ((OpenMode & EFI_FILE_MODE_CREATE) && (Attributes & EFI_FILE_READ_ONLY)) {\r
+  if (((OpenMode & EFI_FILE_MODE_CREATE) != 0) && (Attributes & (EFI_FILE_READ_ONLY | (~EFI_FILE_VALID_ATTR))) != 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   IFile = IFILE_FROM_FHAND (FHand);\r
   OFile = IFile->OFile;\r
+  Task  = NULL;\r
+\r
+  if (Token == NULL) {\r
+    FatWaitNonblockingTask (IFile);\r
+  } else {\r
+    //\r
+    // Caller shouldn't call the non-blocking interfaces if the low layer doesn't support DiskIo2.\r
+    // But if it calls, the below check can avoid crash.\r
+    //\r
+    if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    Task = FatCreateTask (IFile, Token);\r
+    if (Task == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
 \r
   //\r
   // Lock\r
@@ -278,8 +305,52 @@ Returns:
   //\r
   // Unlock\r
   //\r
-  Status = FatCleanupVolume (OFile->Volume, NULL, Status);\r
+  Status = FatCleanupVolume (OFile->Volume, NULL, Status, Task);\r
   FatReleaseLock ();\r
 \r
+  if (Token != NULL) {\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = FatQueueTask (IFile, Task);\r
+    } else {\r
+      FatDestroyTask (Task);\r
+    }\r
+  }\r
+\r
   return Status;\r
 }\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FatOpen (\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
+Arguments:\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
+\r
+Returns:\r
+\r
+  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
+  return FatOpenEx (FHand, NewHandle, FileName, OpenMode, Attributes, NULL);\r
+}\r