EFI_STATUS FileDelete ( IN EFI_FILE *File ) { SEMIHOST_FCB *Fcb = NULL; EFI_STATUS Status; CHAR8 *FileName; UINTN NameSize; Fcb = SEMIHOST_FCB_FROM_THIS(File); if (!Fcb->IsRoot) { // Get the filename from the Fcb NameSize = AsciiStrLen (Fcb->FileName); FileName = AllocatePool (NameSize + 1); AsciiStrCpy (FileName, Fcb->FileName); // Close the file if it's open. Disregard return status, // since it might give an error if the file isn't open. File->Close (File); // Call the semihost interface to delete the file. Status = SemihostFileRemove (FileName); } else { Status = EFI_UNSUPPORTED; } return Status; }
/** Close and delete a file. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to delete. @retval EFI_SUCCESS The file was closed and deleted. @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not deleted. @retval EFI_INVALID_PARAMETER The parameter "This" is NULL. **/ EFI_STATUS FileDelete ( IN EFI_FILE *This ) { SEMIHOST_FCB *Fcb; RETURN_STATUS Return; CHAR8 *FileName; UINTN NameSize; if (This == NULL) { return EFI_INVALID_PARAMETER; } Fcb = SEMIHOST_FCB_FROM_THIS (This); if (!Fcb->IsRoot) { // Get the filename from the Fcb NameSize = AsciiStrLen (Fcb->FileName); FileName = AllocatePool (NameSize + 1); AsciiStrCpy (FileName, Fcb->FileName); // Close the file if it's open. Disregard return status, // since it might give an error if the file isn't open. This->Close (This); // Call the semihost interface to delete the file. Return = SemihostFileRemove (FileName); if (RETURN_ERROR (Return)) { return EFI_WARN_DELETE_FAILURE; } return EFI_SUCCESS; } else { return EFI_WARN_DELETE_FAILURE; } }