mirror of https://github.com/acidanthera/audk.git
Change BlockIo drivers to return EFI_NO_MEDIA or EFI_MEDIA_CHANGED even the Buffer/BufferSize/Lba is invalid so that caller can probe the media status easier.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11584 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
fd776d390d
commit
fcf5e49dc9
|
@ -842,6 +842,11 @@ BlockIoReadWrite (
|
|||
//
|
||||
// Check parameters.
|
||||
//
|
||||
Media = This->Media;
|
||||
if (MediaId != Media->MediaId) {
|
||||
return EFI_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
if (Buffer == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
@ -850,11 +855,6 @@ BlockIoReadWrite (
|
|||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
Media = This->Media;
|
||||
if (MediaId != Media->MediaId) {
|
||||
return EFI_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
BlockSize = Media->BlockSize;
|
||||
if ((BufferSize % BlockSize) != 0) {
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/** @file
|
||||
SCSI disk driver that layers on every SCSI IO protocol in the system.
|
||||
|
||||
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
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
|
||||
|
@ -454,17 +454,8 @@ ScsiDiskReadBlocks (
|
|||
BOOLEAN MediaChange;
|
||||
EFI_TPL OldTpl;
|
||||
|
||||
MediaChange = FALSE;
|
||||
if (Buffer == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (BufferSize == 0) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
||||
|
||||
MediaChange = FALSE;
|
||||
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
||||
ScsiDiskDevice = SCSI_DISK_DEV_FROM_THIS (This);
|
||||
|
||||
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {
|
||||
|
@ -502,6 +493,16 @@ ScsiDiskReadBlocks (
|
|||
goto Done;
|
||||
}
|
||||
|
||||
if (Buffer == NULL) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
if (BufferSize == 0) {
|
||||
Status = EFI_SUCCESS;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
if (BufferSize % BlockSize != 0) {
|
||||
Status = EFI_BAD_BUFFER_SIZE;
|
||||
goto Done;
|
||||
|
@ -569,17 +570,8 @@ ScsiDiskWriteBlocks (
|
|||
BOOLEAN MediaChange;
|
||||
EFI_TPL OldTpl;
|
||||
|
||||
MediaChange = FALSE;
|
||||
if (Buffer == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (BufferSize == 0) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
||||
|
||||
MediaChange = FALSE;
|
||||
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
||||
ScsiDiskDevice = SCSI_DISK_DEV_FROM_THIS (This);
|
||||
|
||||
if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {
|
||||
|
@ -617,6 +609,16 @@ ScsiDiskWriteBlocks (
|
|||
goto Done;
|
||||
}
|
||||
|
||||
if (BufferSize == 0) {
|
||||
Status = EFI_SUCCESS;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
if (Buffer == NULL) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
if (BufferSize % BlockSize != 0) {
|
||||
Status = EFI_BAD_BUFFER_SIZE;
|
||||
goto Done;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/** @file
|
||||
USB Mass Storage Driver that manages USB Mass Storage Device and produces Block I/O Protocol.
|
||||
|
||||
Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
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
|
||||
|
@ -113,13 +113,6 @@ UsbMassReadBlocks (
|
|||
EFI_TPL OldTpl;
|
||||
UINTN TotalBlock;
|
||||
|
||||
//
|
||||
// First, validate the parameters
|
||||
//
|
||||
if ((Buffer == NULL) || (BufferSize == 0)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// Raise TPL to TPL_NOTIFY to serialize all its operations
|
||||
// to protect shared data structures.
|
||||
|
@ -140,6 +133,26 @@ UsbMassReadBlocks (
|
|||
}
|
||||
}
|
||||
|
||||
if (!(Media->MediaPresent)) {
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (MediaId != Media->MediaId) {
|
||||
Status = EFI_MEDIA_CHANGED;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (BufferSize == 0) {
|
||||
Status = EFI_SUCCESS;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (Buffer == NULL) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// BufferSize must be a multiple of the intrinsic block size of the device.
|
||||
//
|
||||
|
@ -158,16 +171,6 @@ UsbMassReadBlocks (
|
|||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (!(Media->MediaPresent)) {
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (MediaId != Media->MediaId) {
|
||||
Status = EFI_MEDIA_CHANGED;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
Status = UsbBootReadBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((EFI_D_ERROR, "UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status));
|
||||
|
@ -221,13 +224,6 @@ UsbMassWriteBlocks (
|
|||
EFI_TPL OldTpl;
|
||||
UINTN TotalBlock;
|
||||
|
||||
//
|
||||
// First, validate the parameters
|
||||
//
|
||||
if ((Buffer == NULL) || (BufferSize == 0)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// Raise TPL to TPL_NOTIFY to serialize all its operations
|
||||
// to protect shared data structures.
|
||||
|
@ -248,6 +244,26 @@ UsbMassWriteBlocks (
|
|||
}
|
||||
}
|
||||
|
||||
if (!(Media->MediaPresent)) {
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (MediaId != Media->MediaId) {
|
||||
Status = EFI_MEDIA_CHANGED;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (BufferSize == 0) {
|
||||
Status = EFI_SUCCESS;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (Buffer == NULL) {
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// BufferSize must be a multiple of the intrinsic block size of the device.
|
||||
//
|
||||
|
@ -266,16 +282,6 @@ UsbMassWriteBlocks (
|
|||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (!(Media->MediaPresent)) {
|
||||
Status = EFI_NO_MEDIA;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
if (MediaId != Media->MediaId) {
|
||||
Status = EFI_MEDIA_CHANGED;
|
||||
goto ON_EXIT;
|
||||
}
|
||||
|
||||
//
|
||||
// Try to write the data even the device is marked as ReadOnly,
|
||||
// and clear the status should the write succeed.
|
||||
|
|
|
@ -465,6 +465,37 @@ PartitionReset (
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
Probe the media status and return EFI_NO_MEDIA or EFI_MEDIA_CHANGED
|
||||
for no media or media change case. Otherwise DefaultStatus is returned.
|
||||
|
||||
@param DiskIo Pointer to the DiskIo instance.
|
||||
@param MediaId Id of the media, changes every time the media is replaced.
|
||||
@param DefaultStatus The default status to return when it's not the no media
|
||||
or media change case.
|
||||
|
||||
@retval EFI_NO_MEDIA There is no media.
|
||||
@retval EFI_MEDIA_CHANGED The media was changed.
|
||||
@retval others The default status to return.
|
||||
**/
|
||||
EFI_STATUS
|
||||
ProbeMediaStatus (
|
||||
IN EFI_DISK_IO_PROTOCOL *DiskIo,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_STATUS DefaultStatus
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Read 1 byte from offset 0 but passing NULL as buffer pointer
|
||||
//
|
||||
Status = DiskIo->ReadDisk (DiskIo, MediaId, 0, 1, NULL);
|
||||
if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {
|
||||
return Status;
|
||||
}
|
||||
return DefaultStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
Read by using the Disk IO protocol on the parent device. Lba addresses
|
||||
|
@ -501,12 +532,12 @@ PartitionReadBlocks (
|
|||
Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);
|
||||
|
||||
if (BufferSize % Private->BlockSize != 0) {
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_BAD_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;
|
||||
if (Offset + BufferSize > Private->End) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_INVALID_PARAMETER);
|
||||
}
|
||||
//
|
||||
// Because some kinds of partition have different block size from their parent
|
||||
|
@ -552,12 +583,12 @@ PartitionWriteBlocks (
|
|||
Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);
|
||||
|
||||
if (BufferSize % Private->BlockSize != 0) {
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_BAD_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;
|
||||
if (Offset + BufferSize > Private->End) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_INVALID_PARAMETER);
|
||||
}
|
||||
//
|
||||
// Because some kinds of partition have different block size from their parent
|
||||
|
|
Loading…
Reference in New Issue