2018-09-13 16:11:07 -07:00
|
|
|
/** @file
|
|
|
|
|
File system level API library interface
|
|
|
|
|
|
2018-11-21 14:35:49 -07:00
|
|
|
Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
|
2018-09-13 16:11:07 -07:00
|
|
|
|
|
|
|
|
This program and the accompanying materials are licensed and made available
|
|
|
|
|
under the terms and conditions of the BSD License which accompanies this
|
|
|
|
|
distribution. The full text of the license may be found at
|
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
|
#include <Library/FileSystemLib.h>
|
2018-11-21 14:35:49 -07:00
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
|
|
|
|
|
|
OS_FILE_SYSTEM_TYPE mCurrentFsType = EnumFileSystemMax;
|
|
|
|
|
FILE_SYSTEM_FUNC mFileSystemFuncs[EnumFileSystemTypeAuto];
|
2018-09-13 16:11:07 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Loads file into memory by its name.
|
|
|
|
|
|
|
|
|
|
@param[in] FsHandle FAT file system handle.
|
|
|
|
|
@param[in] FileName The file name to get.
|
|
|
|
|
@param[out] FileBufferPtr Allocated file buffer pointer.
|
|
|
|
|
@param[out] FileSize Pointer to file buffer size.
|
|
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The file was loaded correctly.
|
|
|
|
|
@retval EFI_INVALID_PARAMETER Parameter is not valid.
|
|
|
|
|
@retval EFI_DEVICE_ERROR A device error occurred.
|
|
|
|
|
@retval EFI_NOT_FOUND A requested file cannot be found.
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Insufficant memory resource pool.
|
|
|
|
|
@retval EFI_BUFFER_TOO_SMALL Buffer size is too small.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
EFI_STATUS
|
|
|
|
|
EFIAPI
|
|
|
|
|
GetFileByName (
|
|
|
|
|
IN EFI_HANDLE FsHandle,
|
|
|
|
|
IN CHAR16 *FileName,
|
|
|
|
|
OUT VOID **FileBuffer,
|
|
|
|
|
OUT UINTN *FileSize
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
|
2018-11-21 14:35:49 -07:00
|
|
|
if (mCurrentFsType >= EnumFileSystemTypeAuto) {
|
|
|
|
|
return EFI_NOT_READY;
|
2018-09-13 16:11:07 -07:00
|
|
|
}
|
|
|
|
|
|
2018-11-21 14:35:49 -07:00
|
|
|
if (mFileSystemFuncs[mCurrentFsType].GetFileByName == NULL) {
|
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mFileSystemFuncs[mCurrentFsType].GetFileByName (FsHandle, FileName, FileBuffer, FileSize);
|
|
|
|
|
|
2018-09-13 16:11:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Initialize file systems.
|
|
|
|
|
|
|
|
|
|
@param[in] SwPart Software partition index.
|
|
|
|
|
@param[in] FsType Filesystem type.
|
|
|
|
|
@param[in] PartHandle Partition handle.
|
|
|
|
|
@param[out] FsHandle FAT file system handle.
|
|
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The file system was initialized successfully.
|
|
|
|
|
@retval EFI_INVALID_PARAMETER Parameter is not valid.
|
|
|
|
|
@retval EFI_NOT_FOUND FAT file system was not detected on this partition.
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Insufficant memory resource pool.
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
EFI_STATUS
|
|
|
|
|
EFIAPI
|
|
|
|
|
InitFileSystem (
|
|
|
|
|
IN UINT32 SwPart,
|
|
|
|
|
IN UINT32 FsType,
|
|
|
|
|
IN EFI_HANDLE PartHandle,
|
|
|
|
|
OUT EFI_HANDLE *FsHandle
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
EFI_STATUS Status;
|
2018-11-21 14:35:49 -07:00
|
|
|
UINT32 Type;
|
2018-09-13 16:11:07 -07:00
|
|
|
|
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
2018-11-21 14:35:49 -07:00
|
|
|
|
|
|
|
|
if (FsType >= EnumFileSystemMax) {
|
|
|
|
|
return Status;
|
2018-09-13 16:11:07 -07:00
|
|
|
}
|
|
|
|
|
|
2018-11-21 14:35:49 -07:00
|
|
|
if (mCurrentFsType == EnumFileSystemMax) {
|
|
|
|
|
Type = EnumFileSystemTypeFat;
|
|
|
|
|
if (FixedPcdGet32 (PcdSupportedFileSystemMask) & (1 << Type)) {
|
|
|
|
|
mFileSystemFuncs[Type].InitFileSystem = FatInitFileSystem;
|
|
|
|
|
mFileSystemFuncs[Type].GetFileByName = FatGetFileByName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Type = EnumFileSystemTypeExt2;
|
|
|
|
|
if (FixedPcdGet32 (PcdSupportedFileSystemMask) & (1 << Type)) {
|
|
|
|
|
mFileSystemFuncs[Type].InitFileSystem = ExtInitFileSystem;
|
|
|
|
|
mFileSystemFuncs[Type].GetFileByName = ExtGetFileByName;
|
|
|
|
|
}
|
|
|
|
|
mCurrentFsType = EnumFileSystemTypeAuto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Type = EnumFileSystemTypeFat; Type < EnumFileSystemTypeAuto; Type++) {
|
2019-01-03 13:18:25 -08:00
|
|
|
if (mFileSystemFuncs[Type].InitFileSystem == NULL) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ((FsType == EnumFileSystemTypeAuto) || (FsType == Type)) {
|
2018-11-21 14:35:49 -07:00
|
|
|
Status = mFileSystemFuncs[Type].InitFileSystem (SwPart, PartHandle, FsHandle);
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
|
mCurrentFsType = Type;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-09-13 16:11:07 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Status;
|
2018-11-21 14:35:49 -07:00
|
|
|
}
|