Remove probe for removable media from FileLib, it was getting called way too much. Now it is in the EBL shell device command. Cleanup some spacing issues in the lib code.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10454 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
andrewfish 2010-05-04 16:29:32 +00:00
parent 2a9fe5409d
commit f6381f4c3d
3 changed files with 111 additions and 113 deletions

View File

@ -51,6 +51,7 @@
#include <Library/DevicePathLib.h> #include <Library/DevicePathLib.h>
#include <Library/UefiLib.h> #include <Library/UefiLib.h>
#include <Library/EblNetworkLib.h> #include <Library/EblNetworkLib.h>
#include <Library/TimerLib.h>
#include <IndustryStandard/Pci.h> #include <IndustryStandard/Pci.h>

View File

@ -210,12 +210,34 @@ EblDeviceCmd (
UINTN Index; UINTN Index;
UINTN CurrentRow; UINTN CurrentRow;
UINTN Max; UINTN Max;
EFI_OPEN_FILE *File;
CurrentRow = 0; CurrentRow = 0;
// Need to call here to make sure Device Counts are valid // Need to call here to make sure Device Counts are valid
EblUpdateDeviceLists (); EblUpdateDeviceLists ();
//
// Probe for media insertion/removal in removable media devices
//
Max = EfiGetDeviceCounts (EfiOpenBlockIo);
if (Max != 0) {
for (Index = 0; Index < Max; Index++) {
File = EfiDeviceOpenByType (EfiOpenBlockIo, Index);
if (File != NULL) {
if (File->FsBlockIoMedia->RemovableMedia) {
if (File->FsBlockIoMedia->MediaPresent) {
gBS->DisconnectController (File->EfiHandle, NULL, NULL);
}
gBS->ConnectController (File->EfiHandle, NULL, NULL, TRUE);
}
EfiClose (File);
}
}
}
// Now we can print out the info...
Max = EfiGetDeviceCounts (EfiOpenFirmwareVolume); Max = EfiGetDeviceCounts (EfiOpenFirmwareVolume);
if (Max != 0) { if (Max != 0) {
AsciiPrint ("Firmware Volume Devices:\n"); AsciiPrint ("Firmware Volume Devices:\n");
@ -730,7 +752,7 @@ EblFileCopyCmd (
UINTN Size; UINTN Size;
UINTN Offset; UINTN Offset;
UINTN Chunk = FILE_COPY_CHUNK; UINTN Chunk = FILE_COPY_CHUNK;
if (Argc < 3) { if (Argc < 3) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -759,13 +781,13 @@ EblFileCopyCmd (
Status = EfiRead(Source, Buffer, &Chunk); Status = EfiRead(Source, Buffer, &Chunk);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
AsciiPrint("Read file error\n"); AsciiPrint("Read file error %r\n", Status);
goto Exit; goto Exit;
} }
Status = EfiWrite(Destination, Buffer, &Chunk); Status = EfiWrite(Destination, Buffer, &Chunk);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
AsciiPrint("Write file error\n"); AsciiPrint("Write file error %r\n", Status);
goto Exit; goto Exit;
} }
} }
@ -776,17 +798,18 @@ EblFileCopyCmd (
Status = EfiRead(Source, Buffer, &Chunk); Status = EfiRead(Source, Buffer, &Chunk);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
AsciiPrint("Read file error\n"); AsciiPrint("Read file error %r\n", Status);
goto Exit; goto Exit;
} }
Status = EfiWrite(Destination, Buffer, &Chunk); Status = EfiWrite(Destination, Buffer, &Chunk);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
AsciiPrint("Write file error\n"); AsciiPrint("Write file error %r\n", Status);
goto Exit; goto Exit;
} }
} }
Exit: Exit:
if (Source != NULL) { if (Source != NULL) {
Status = EfiClose(Source); Status = EfiClose(Source);
@ -794,7 +817,6 @@ Exit:
AsciiPrint("Source close error %r\n", Status); AsciiPrint("Source close error %r\n", Status);
} }
} }
if (Destination != NULL) { if (Destination != NULL) {
Status = EfiClose(Destination); Status = EfiClose(Destination);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {

View File

@ -100,8 +100,8 @@ Internal worker function to validate a File handle.
**/ **/
BOOLEAN BOOLEAN
FileHandleValid ( FileHandleValid (
IN EFI_OPEN_FILE *File IN EFI_OPEN_FILE *File
) )
{ {
EFI_OPEN_FILE_GUARD *GuardFile; EFI_OPEN_FILE_GUARD *GuardFile;
@ -123,8 +123,8 @@ Internal worker function. If Buffer is not NULL free it.
**/ **/
VOID VOID
EblFreePool ( EblFreePool (
IN VOID *Buffer IN VOID *Buffer
) )
{ {
if (Buffer != NULL) { if (Buffer != NULL) {
FreePool (Buffer); FreePool (Buffer);
@ -137,45 +137,20 @@ Update Device List Global Variables
**/ **/
VOID VOID
EblUpdateDeviceLists ( EblUpdateDeviceLists (
VOID VOID
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN Size; UINTN Size;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
EFI_BLOCK_IO_PROTOCOL *BlkIo;
EFI_FILE_HANDLE Root; EFI_FILE_HANDLE Root;
UINTN Index; UINTN Index;
BOOLEAN Update;
if (mBlkIo != NULL) { if (mBlkIo != NULL) {
FreePool (mBlkIo); FreePool (mBlkIo);
} }
gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo); gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);
//
// This is a trick to trigger the gBS->ReinstallProtocolInterface () in a removable media
// device to make a filesystem layer on. Probing devices will detect if media has been
// inserted and create
//
for (Index =0, Update = FALSE; Index < mBlkIoCount; Index++) {
Status = gBS->HandleProtocol (mBlkIo[Index], &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);
if (!EFI_ERROR (Status)) {
if (BlkIo->Media->RemovableMedia) {
gBS->DisconnectController (mBlkIo[Index], NULL, NULL);
gBS->ConnectController (mBlkIo[Index], NULL, NULL, TRUE);
Update = TRUE;
}
}
}
if (Update) {
// In case we caused media to be detected that contains a partition (SD Card, ...) rescan
if (mBlkIo != NULL) {
FreePool (mBlkIo);
}
gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);
}
if (mFv != NULL) { if (mFv != NULL) {
@ -248,10 +223,10 @@ and it can be used with mFs[] to find the handle that needs to be opened
**/ **/
BOOLEAN BOOLEAN
EblMatchVolumeName ( EblMatchVolumeName (
IN CHAR8 *PathName, IN CHAR8 *PathName,
IN UINTN FileStart, IN UINTN FileStart,
OUT UINTN *MatchIndex OUT UINTN *MatchIndex
) )
{ {
UINTN Index; UINTN Index;
UINTN Compare; UINTN Compare;
@ -297,8 +272,8 @@ Return the number of devices of the current type active in the system
**/ **/
UINTN UINTN
EfiGetDeviceCounts ( EfiGetDeviceCounts (
IN EFI_OPEN_FILE_TYPE DeviceType IN EFI_OPEN_FILE_TYPE DeviceType
) )
{ {
switch (DeviceType) { switch (DeviceType) {
case EfiOpenLoadFile: case EfiOpenLoadFile:
@ -316,9 +291,9 @@ EfiGetDeviceCounts (
EFI_STATUS EFI_STATUS
ConvertIpStringToEfiIp ( ConvertIpStringToEfiIp (
IN CHAR8 *PathName, IN CHAR8 *PathName,
OUT EFI_IP_ADDRESS *ServerIp OUT EFI_IP_ADDRESS *ServerIp
) )
{ {
CHAR8 *Str; CHAR8 *Str;
@ -362,8 +337,8 @@ text. Easy way to extract numbers from strings like blk7:.
**/ **/
UINTN UINTN
EblConvertDevStringToNumber ( EblConvertDevStringToNumber (
IN CHAR8 *Str IN CHAR8 *Str
) )
{ {
UINTN Max; UINTN Max;
UINTN Index; UINTN Index;
@ -392,10 +367,10 @@ Internal work function to fill in EFI_OPEN_FILE information for the Fs and BlkIo
**/ **/
EFI_STATUS EFI_STATUS
EblFileDevicePath ( EblFileDevicePath (
IN OUT EFI_OPEN_FILE *File, IN OUT EFI_OPEN_FILE *File,
IN CHAR8 *FileName, IN CHAR8 *FileName,
IN CONST UINT64 OpenMode IN CONST UINT64 OpenMode
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN Size; UINTN Size;
@ -481,9 +456,9 @@ EblFileDevicePath (
EFI_STATUS EFI_STATUS
CompareGuidToString ( CompareGuidToString (
IN EFI_GUID *Guid, IN EFI_GUID *Guid,
IN CHAR8 *String IN CHAR8 *String
) )
{ {
CHAR8 AsciiGuid[64]; CHAR8 AsciiGuid[64];
CHAR8 *StringPtr; CHAR8 *StringPtr;
@ -528,10 +503,10 @@ Internal work function to fill in EFI_OPEN_FILE information for the FV
**/ **/
EFI_STATUS EFI_STATUS
EblFvFileDevicePath ( EblFvFileDevicePath (
IN OUT EFI_OPEN_FILE *File, IN OUT EFI_OPEN_FILE *File,
IN CHAR8 *FileName, IN CHAR8 *FileName,
IN CONST UINT64 OpenMode IN CONST UINT64 OpenMode
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_STATUS GetNextFileStatus; EFI_STATUS GetNextFileStatus;
@ -678,10 +653,10 @@ For any file that is opened with EfiOpen() must be closed with EfiClose().
**/ **/
EFI_OPEN_FILE * EFI_OPEN_FILE *
EfiOpen ( EfiOpen (
IN CHAR8 *PathName, IN CHAR8 *PathName,
IN CONST UINT64 OpenMode, IN CONST UINT64 OpenMode,
IN CONST EFI_SECTION_TYPE SectionType IN CONST EFI_SECTION_TYPE SectionType
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_OPEN_FILE *File; EFI_OPEN_FILE *File;
@ -937,9 +912,9 @@ ErrorExit:
EFI_STATUS EFI_STATUS
EfiCopyFile ( EfiCopyFile (
IN CHAR8 *DestinationFile, IN CHAR8 *DestinationFile,
IN CHAR8 *SourceFile IN CHAR8 *SourceFile
) )
{ {
EFI_OPEN_FILE *Source = NULL; EFI_OPEN_FILE *Source = NULL;
EFI_OPEN_FILE *Destination = NULL; EFI_OPEN_FILE *Destination = NULL;
@ -976,13 +951,13 @@ EfiCopyFile (
Status = EfiRead(Source, Buffer, &Chunk); Status = EfiRead(Source, Buffer, &Chunk);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
AsciiPrint("Read file error\n"); AsciiPrint("Read file error %r\n", Status);
goto Exit; goto Exit;
} }
Status = EfiWrite(Destination, Buffer, &Chunk); Status = EfiWrite(Destination, Buffer, &Chunk);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
AsciiPrint("Write file error\n"); AsciiPrint("Write file error %r\n", Status);
goto Exit; goto Exit;
} }
} }
@ -1038,9 +1013,9 @@ Use DeviceType and Index to form a valid PathName and try and open it.
**/ **/
EFI_OPEN_FILE * EFI_OPEN_FILE *
EfiDeviceOpenByType ( EfiDeviceOpenByType (
IN EFI_OPEN_FILE_TYPE DeviceType, IN EFI_OPEN_FILE_TYPE DeviceType,
IN UINTN Index IN UINTN Index
) )
{ {
CHAR8 *DevStr; CHAR8 *DevStr;
CHAR8 Path[MAX_CMD_LINE]; CHAR8 Path[MAX_CMD_LINE];
@ -1083,8 +1058,8 @@ EfiOpen().
**/ **/
EFI_STATUS EFI_STATUS
EfiClose ( EfiClose (
IN EFI_OPEN_FILE *File IN EFI_OPEN_FILE *File
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT64 TftpBufferSize; UINT64 TftpBufferSize;
@ -1117,21 +1092,21 @@ EfiClose (
if ((File->Type == EfiOpenLoadFile) || if ((File->Type == EfiOpenLoadFile) ||
((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) || ((File->Type == EfiOpenTftp) && (File->IsBufferValid == TRUE)) ||
((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) { ((File->Type == EfiOpenFirmwareVolume) && (File->IsBufferValid == TRUE))) {
EblFreePool(File->Buffer); EblFreePool(File->Buffer);
} }
EblFreePool (File->DevicePath); EblFreePool (File->DevicePath);
EblFreePool (File->DeviceName); EblFreePool (File->DeviceName);
EblFreePool (File->FsFileInfo); EblFreePool (File->FsFileInfo);
EblFreePool (File->FsInfo); EblFreePool (File->FsInfo);
if (File->FsFileHandle != NULL) { if (File->FsFileHandle != NULL) {
File->FsFileHandle->Close (File->FsFileHandle); File->FsFileHandle->Close (File->FsFileHandle);
} }
// Need to free File and it's Guard structures // Need to free File and it's Guard structures
EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File)); EblFreePool (BASE_CR (File, EFI_OPEN_FILE_GUARD, File));
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -1147,9 +1122,9 @@ LoadFile is an exception as a load file size is set to zero.
**/ **/
UINTN UINTN
EfiTell ( EfiTell (
IN EFI_OPEN_FILE *File, IN EFI_OPEN_FILE *File,
OUT EFI_LBA *CurrentPosition OPTIONAL OUT EFI_LBA *CurrentPosition OPTIONAL
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT64 BufferSize = 0; UINT64 BufferSize = 0;
@ -1221,10 +1196,10 @@ EfiSeekEnd : Only supported if Offset is zero to seek to end of file.
**/ **/
EFI_STATUS EFI_STATUS
EfiSeek ( EfiSeek (
IN EFI_OPEN_FILE *File, IN EFI_OPEN_FILE *File,
IN EFI_LBA Offset, IN EFI_LBA Offset,
IN EFI_SEEK_TYPE SeekType IN EFI_SEEK_TYPE SeekType
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT64 CurrentPosition; UINT64 CurrentPosition;
@ -1280,8 +1255,8 @@ EfiSeek (
EFI_STATUS EFI_STATUS
CacheTftpFile ( CacheTftpFile (
IN OUT EFI_OPEN_FILE *File IN OUT EFI_OPEN_FILE *File
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT64 TftpBufferSize; UINT64 TftpBufferSize;
@ -1341,10 +1316,10 @@ FV, and TFTP case you must read the entire file.
**/ **/
EFI_STATUS EFI_STATUS
EfiRead ( EfiRead (
IN EFI_OPEN_FILE *File, IN EFI_OPEN_FILE *File,
OUT VOID *Buffer, OUT VOID *Buffer,
OUT UINTN *BufferSize OUT UINTN *BufferSize
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT32 AuthenticationStatus; UINT32 AuthenticationStatus;
@ -1472,10 +1447,10 @@ must be.
**/ **/
EFI_STATUS EFI_STATUS
EfiReadAllocatePool ( EfiReadAllocatePool (
IN EFI_OPEN_FILE *File, IN EFI_OPEN_FILE *File,
OUT VOID **Buffer, OUT VOID **Buffer,
OUT UINTN *BufferSize OUT UINTN *BufferSize
) )
{ {
if (!FileHandleValid (File)) { if (!FileHandleValid (File)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -1511,10 +1486,10 @@ Write data back to the file. For TFTP case you must write the entire file.
**/ **/
EFI_STATUS EFI_STATUS
EfiWrite ( EfiWrite (
IN EFI_OPEN_FILE *File, IN EFI_OPEN_FILE *File,
OUT VOID *Buffer, OUT VOID *Buffer,
OUT UINTN *BufferSize OUT UINTN *BufferSize
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_FV_WRITE_FILE_DATA FileData; EFI_FV_WRITE_FILE_DATA FileData;
@ -1628,9 +1603,9 @@ directory names.
**/ **/
CHAR8 * CHAR8 *
ExpandPath ( ExpandPath (
IN CHAR8 *Cwd, IN CHAR8 *Cwd,
IN CHAR8 *Path IN CHAR8 *Path
) )
{ {
CHAR8 *NewPath; CHAR8 *NewPath;
CHAR8 *Work, *Start, *End; CHAR8 *Work, *Start, *End;
@ -1705,8 +1680,8 @@ the path does not contain a device name, The CWD is prepended to the path.
**/ **/
EFI_STATUS EFI_STATUS
EfiSetCwd ( EfiSetCwd (
IN CHAR8 *Cwd IN CHAR8 *Cwd
) )
{ {
EFI_OPEN_FILE *File; EFI_OPEN_FILE *File;
UINTN Len; UINTN Len;
@ -1781,8 +1756,8 @@ this funciton.
**/ **/
CHAR8 * CHAR8 *
EfiGetCwd ( EfiGetCwd (
VOID VOID
) )
{ {
if (gCwd == NULL) { if (gCwd == NULL) {
return ""; return "";