summaryrefslogtreecommitdiff
path: root/MdePkg
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2018-08-17 14:55:23 +0200
committerLaszlo Ersek <lersek@redhat.com>2018-08-22 10:31:47 +0200
commit5dbc768f1cd988b87932ba2f176caa006064018d (patch)
treec3a82e3703e6bc0d96766f16905123cabe79505c /MdePkg
parente0c93c9b76153bc5a95bf174dab9805ec2f2942c (diff)
downloadedk2-5dbc768f1cd988b87932ba2f176caa006064018d.zip
edk2-5dbc768f1cd988b87932ba2f176caa006064018d.tar.gz
edk2-5dbc768f1cd988b87932ba2f176caa006064018d.tar.bz2
MdePkg/UefiLib: don't special-case EFI_FILE_MODE_CREATE in OpenMode
While reviewing the patch that would land as 768b611136d0 ("MdePkg/UefiLib: introduce EfiOpenFileByDevicePath()", 2018-08-16), Ray pointed out that distinguishing EFI_FILE_MODE_CREATE was wasteful. Per spec, if the file to create exists, then EFI_FILE_MODE_CREATE is ignored by EFI_FILE_PROTOCOL.Open(), and the existent file is opened. Therefore we don't need an attempt to "open-but-not-create" first, and a fallback to "open-and-create-too" second -- that behavior is internal to EFI_FILE_PROTOCOL.Open(). Remove the special-casing of EFI_FILE_MODE_CREATE. Cc: Liming Gao <liming.gao@intel.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Ruiyu Ni <ruiyu.ni@intel.com> Suggested-by: Ruiyu Ni <ruiyu.ni@intel.com> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1074 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Include/Library/UefiLib.h19
-rw-r--r--MdePkg/Library/UefiLib/UefiLib.c40
2 files changed, 9 insertions, 50 deletions
diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h
index f950f1c..f80067f 100644
--- a/MdePkg/Include/Library/UefiLib.h
+++ b/MdePkg/Include/Library/UefiLib.h
@@ -1533,12 +1533,7 @@ EfiLocateProtocolBuffer (
On the remaining device path, the longest initial sequence of
FILEPATH_DEVICE_PATH nodes is node-wise traversed with
- EFI_FILE_PROTOCOL.Open(). For the pathname fragment specified by each
- traversed FILEPATH_DEVICE_PATH node, EfiOpenFileByDevicePath() first masks
- EFI_FILE_MODE_CREATE out of OpenMode, and passes 0 for Attributes. If
- EFI_FILE_PROTOCOL.Open() fails, and OpenMode includes EFI_FILE_MODE_CREATE,
- then the operation is retried with the caller's OpenMode and Attributes
- unmodified.
+ EFI_FILE_PROTOCOL.Open().
(As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attributes
includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a single
@@ -1570,18 +1565,10 @@ EfiLocateProtocolBuffer (
the last node in FilePath.
@param[in] OpenMode The OpenMode parameter to pass to
- EFI_FILE_PROTOCOL.Open(). For each
- FILEPATH_DEVICE_PATH node in FilePath,
- EfiOpenFileByDevicePath() first opens the specified
- pathname fragment with EFI_FILE_MODE_CREATE masked
- out of OpenMode and with Attributes set to 0, and
- only retries the operation with EFI_FILE_MODE_CREATE
- unmasked and Attributes propagated if the first open
- attempt fails.
+ EFI_FILE_PROTOCOL.Open().
@param[in] Attributes The Attributes parameter to pass to
- EFI_FILE_PROTOCOL.Open(), when EFI_FILE_MODE_CREATE
- is propagated unmasked in OpenMode.
+ EFI_FILE_PROTOCOL.Open().
@retval EFI_SUCCESS The file or directory has been opened or
created.
diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c
index 7bcac56..39d0ce2 100644
--- a/MdePkg/Library/UefiLib/UefiLib.c
+++ b/MdePkg/Library/UefiLib/UefiLib.c
@@ -1730,12 +1730,7 @@ EfiLocateProtocolBuffer (
On the remaining device path, the longest initial sequence of
FILEPATH_DEVICE_PATH nodes is node-wise traversed with
- EFI_FILE_PROTOCOL.Open(). For the pathname fragment specified by each
- traversed FILEPATH_DEVICE_PATH node, EfiOpenFileByDevicePath() first masks
- EFI_FILE_MODE_CREATE out of OpenMode, and passes 0 for Attributes. If
- EFI_FILE_PROTOCOL.Open() fails, and OpenMode includes EFI_FILE_MODE_CREATE,
- then the operation is retried with the caller's OpenMode and Attributes
- unmodified.
+ EFI_FILE_PROTOCOL.Open().
(As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attributes
includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a single
@@ -1767,18 +1762,10 @@ EfiLocateProtocolBuffer (
the last node in FilePath.
@param[in] OpenMode The OpenMode parameter to pass to
- EFI_FILE_PROTOCOL.Open(). For each
- FILEPATH_DEVICE_PATH node in FilePath,
- EfiOpenFileByDevicePath() first opens the specified
- pathname fragment with EFI_FILE_MODE_CREATE masked
- out of OpenMode and with Attributes set to 0, and
- only retries the operation with EFI_FILE_MODE_CREATE
- unmasked and Attributes propagated if the first open
- attempt fails.
+ EFI_FILE_PROTOCOL.Open().
@param[in] Attributes The Attributes parameter to pass to
- EFI_FILE_PROTOCOL.Open(), when EFI_FILE_MODE_CREATE
- is propagated unmasked in OpenMode.
+ EFI_FILE_PROTOCOL.Open().
@retval EFI_SUCCESS The file or directory has been opened or
created.
@@ -1889,32 +1876,17 @@ EfiOpenFileByDevicePath (
}
//
- // Open the next pathname fragment with EFI_FILE_MODE_CREATE masked out and
- // with Attributes set to 0.
+ // Open or create the file corresponding to the next pathname fragment.
//
Status = LastFile->Open (
LastFile,
&NextFile,
PathName,
- OpenMode & ~(UINT64)EFI_FILE_MODE_CREATE,
- 0
+ OpenMode,
+ Attributes
);
//
- // Retry with EFI_FILE_MODE_CREATE and the original Attributes if the first
- // attempt failed, and the caller specified EFI_FILE_MODE_CREATE.
- //
- if (EFI_ERROR (Status) && (OpenMode & EFI_FILE_MODE_CREATE) != 0) {
- Status = LastFile->Open (
- LastFile,
- &NextFile,
- PathName,
- OpenMode,
- Attributes
- );
- }
-
- //
// Release any AlignedPathName on both error and success paths; PathName is
// no longer needed.
//