mirror of
				https://github.com/acidanthera/audk.git
				synced 2025-10-31 11:13:53 +01:00 
			
		
		
		
	ShellPkg: Fixes CP function to prevent copying of files if destination does not have adequate storage.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Matt Stanbro <Matthew.A.Stanbro@intel.com> Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14203 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
		
							parent
							
								
									7c8e7960ef
								
							
						
					
					
						commit
						f06be00e7a
					
				| @ -13,6 +13,8 @@ | ||||
| **/ | ||||
| 
 | ||||
| #include "UefiShellLevel2CommandsLib.h" | ||||
| #include <Guid/FileSystemInfo.h> | ||||
| #include <Guid/FileSystemVolumeLabelInfo.h> | ||||
| 
 | ||||
| /**
 | ||||
|   Function to take a list of files to copy and a destination location and do | ||||
| @ -72,7 +74,11 @@ CopySingleFile( | ||||
|   UINTN                 Size; | ||||
|   EFI_SHELL_FILE_INFO   *List; | ||||
|   SHELL_STATUS          ShellStatus; | ||||
| 
 | ||||
|   UINT64                SourceFileSize; | ||||
|   UINT64                DestFileSize; | ||||
|   EFI_FILE_PROTOCOL     *DestVolumeFP; | ||||
|   EFI_FILE_SYSTEM_INFO  *DestVolumeInfo; | ||||
|   UINTN                 DestVolumeInfoSize; | ||||
| 
 | ||||
|   ASSERT(Resp != NULL); | ||||
| 
 | ||||
| @ -80,6 +86,7 @@ CopySingleFile( | ||||
|   DestHandle      = NULL; | ||||
|   Response        = *Resp; | ||||
|   List            = NULL; | ||||
|   DestVolumeInfo  = NULL; | ||||
| 
 | ||||
|   ReadSize = PcdGet16(PcdShellFileOperationSize); | ||||
|   // Why bother copying a file to itself
 | ||||
| @ -171,6 +178,55 @@ CopySingleFile( | ||||
|       Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0); | ||||
|       ASSERT_EFI_ERROR(Status); | ||||
| 
 | ||||
|       //
 | ||||
|       //get file size of source file and freespace available on destination volume
 | ||||
|       //
 | ||||
|       ShellGetFileSize(SourceHandle, &SourceFileSize); | ||||
|       ShellGetFileSize(DestHandle, &DestFileSize); | ||||
| 
 | ||||
|       //
 | ||||
|       //if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space
 | ||||
|       //
 | ||||
|       if(DestFileSize < SourceFileSize){ | ||||
|         SourceFileSize -= DestFileSize; | ||||
|       } else { | ||||
|         SourceFileSize = 0; | ||||
|       } | ||||
| 
 | ||||
|       //
 | ||||
|       //get the system volume info to check the free space
 | ||||
|       //
 | ||||
|       DestVolumeFP = ConvertShellHandleToEfiFileProtocol(DestHandle); | ||||
|       DestVolumeInfo = NULL; | ||||
|       DestVolumeInfoSize = 0; | ||||
|       Status = DestVolumeFP->GetInfo( | ||||
|         DestVolumeFP, | ||||
|         &gEfiFileSystemInfoGuid, | ||||
|         &DestVolumeInfoSize, | ||||
|         DestVolumeInfo | ||||
|         ); | ||||
| 
 | ||||
|       if (Status == EFI_BUFFER_TOO_SMALL) { | ||||
|         DestVolumeInfo = AllocateZeroPool(DestVolumeInfoSize); | ||||
|         Status = DestVolumeFP->GetInfo( | ||||
|           DestVolumeFP, | ||||
|           &gEfiFileSystemInfoGuid, | ||||
|           &DestVolumeInfoSize, | ||||
|           DestVolumeInfo | ||||
|           ); | ||||
|       } | ||||
| 
 | ||||
|       //
 | ||||
|       //check if enough space available on destination drive to complete copy
 | ||||
|       //
 | ||||
|       if (DestVolumeInfo->FreeSpace < SourceFileSize) { | ||||
|         //
 | ||||
|         //not enough space on destination directory to copy file
 | ||||
|         //
 | ||||
|         SHELL_FREE_NON_NULL(DestVolumeInfo); | ||||
|         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle); | ||||
|         return(SHELL_VOLUME_FULL); | ||||
|       } else { | ||||
|         //
 | ||||
|         // copy data between files
 | ||||
|         //
 | ||||
| @ -178,10 +234,11 @@ CopySingleFile( | ||||
|         ASSERT(Buffer != NULL); | ||||
|         while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) { | ||||
|           Status = ShellReadFile(SourceHandle, &ReadSize, Buffer); | ||||
|       ASSERT_EFI_ERROR(Status); | ||||
|           Status = ShellWriteFile(DestHandle, &ReadSize, Buffer); | ||||
|         } | ||||
|       } | ||||
|       SHELL_FREE_NON_NULL(DestVolumeInfo); | ||||
|     } | ||||
| 
 | ||||
|   //
 | ||||
|   // close files
 | ||||
| @ -454,6 +511,7 @@ ValidateAndCopyFiles( | ||||
|   } | ||||
| 
 | ||||
|   return (ShellStatus); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  | ||||
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user