30 IN CONST EFI_FILE_PROTOCOL *Directory,
31 OUT EFI_FILE_PROTOCOL **NewHandle,
32 IN CONST CHAR16 *FileName,
33 IN CONST UINT64 OpenMode,
34 IN CONST UINT64 Attributes
42 ASSERT (NewHandle != NULL);
43 Length = StrLen (FileName);
45 DEBUG ((DEBUG_INFO,
"OCFS: Filename %s has trailing slash\n", FileName));
51 Status = Directory->Open (
52 (EFI_FILE_PROTOCOL *)Directory,
65 if ( (Status == EFI_WRITE_PROTECTED)
66 && (OpenMode == EFI_FILE_MODE_READ)
68 && (*NewHandle != NULL))
72 "OCFS: Avoid invalid WP error for Filename %s\n",
84 IN EFI_HANDLE FileSystemHandle,
85 IN CONST EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath,
86 OUT EFI_FILE_PROTOCOL **File,
92 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;
93 EFI_FILE_PROTOCOL *LastFile;
94 CONST EFI_DEVICE_PATH_PROTOCOL *FilePathNode;
95 CHAR16 *AlignedPathName;
98 EFI_FILE_PROTOCOL *NextFile;
100 ASSERT (FileSystemHandle != NULL);
101 ASSERT (RemainingDevicePath != NULL);
104 Status =
gBS->OpenProtocol (
107 (VOID **)&FileSystem,
110 EFI_OPEN_PROTOCOL_GET_PROTOCOL
112 if (EFI_ERROR (Status)) {
120 Status = FileSystem->OpenVolume (FileSystem, &LastFile);
121 if (EFI_ERROR (Status)) {
128 FilePathNode = RemainingDevicePath;
129 while (!IsDevicePathEnd (FilePathNode)) {
130 if ((DevicePathType (FilePathNode) != MEDIA_DEVICE_PATH) ||
131 (DevicePathSubType (FilePathNode) != MEDIA_FILEPATH_DP))
133 Status = EFI_INVALID_PARAMETER;
143 AlignedPathName = AllocateCopyPool (
144 (DevicePathNodeLength (FilePathNode) -
145 SIZE_OF_FILEPATH_DEVICE_PATH),
146 ((CONST FILEPATH_DEVICE_PATH *)FilePathNode)->
PathName
148 if (AlignedPathName == NULL) {
149 Status = EFI_OUT_OF_RESOURCES;
158 PathLength = StrLen (AlignedPathName);
159 if ((PathLength > 0) && (AlignedPathName[PathLength - 1] ==
'\\')) {
160 AlignedPathName[PathLength - 1] =
'\0';
176 FreePool (AlignedPathName);
178 if (EFI_ERROR (Status)) {
185 LastFile->Close (LastFile);
187 FilePathNode = NextDevicePathNode (FilePathNode);
194 LastFile->Close (LastFile);
200 ASSERT (EFI_ERROR (Status));
EFI_STATUS OcSafeFileOpen(IN CONST EFI_FILE_PROTOCOL *Directory, OUT EFI_FILE_PROTOCOL **NewHandle, IN CONST CHAR16 *FileName, IN CONST UINT64 OpenMode, IN CONST UINT64 Attributes)
EFI_STATUS EFIAPI OcOpenFileByRemainingDevicePath(IN EFI_HANDLE FileSystemHandle, IN CONST EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath, OUT EFI_FILE_PROTOCOL **File, IN UINT64 OpenMode, IN UINT64 Attributes)