GuestSessionImplTasks.cpp revision 05150d9b570a7efbd6923eedcef64f2ec351b52e
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/* $Id$ */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/** @file
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * VirtualBox Main - XXX.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Copyright (C) 2012 Oracle Corporation
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * available from http://www.virtualbox.org. This file is free software;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * General Public License (GPL) as published by the Free Software
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*******************************************************************************
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync* Header Files *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync*******************************************************************************/
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync#include "GuestImpl.h"
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include "GuestSessionImpl.h"
7b9f0c34e9ea328981c99e97054bdf8684d9d620vboxsync#include "GuestCtrlImplPrivate.h"
9e7e0b61d29309a0ed7af9472c8d6d865f9e8a2dvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include "Global.h"
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include "AutoCaller.h"
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include "ConsoleImpl.h"
0fd108a555ae02f2fb557d5f2c40281999b60d15vboxsync#include "MachineImpl.h"
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#include "ProgressImpl.h"
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#include <memory> /* For auto_ptr. */
b1cc3e87518139898395f96974ecff9e6bf228fbvboxsync
b1cc3e87518139898395f96974ecff9e6bf228fbvboxsync#include <iprt/env.h>
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#include <iprt/file.h> /* For CopyTo/From. */
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
388b6b190a5407548753b7fde12fa58134ec3563vboxsync#ifdef LOG_GROUP
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync #undef LOG_GROUP
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync#endif
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
f9ce005e61f0fbb51a2cabc53d58c3485151faa9vboxsync#include <VBox/log.h>
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync/*******************************************************************************
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync* Defines *
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync*******************************************************************************/
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/**
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Update file flags.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#define UPDATEFILE_FLAG_NONE 0
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/** Copy over the file from host to the
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * guest. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#define UPDATEFILE_FLAG_COPY_FROM_ISO RT_BIT(0)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/** Execute file on the guest after it has
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * been successfully transfered. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#define UPDATEFILE_FLAG_EXECUTE RT_BIT(7)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/** File is optional, does not have to be
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * existent on the .ISO. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync#define UPDATEFILE_FLAG_OPTIONAL RT_BIT(8)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync// session task classes
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/////////////////////////////////////////////////////////////////////////////
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncGuestSessionTask::GuestSessionTask(GuestSession *pSession)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mSession = pSession;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncGuestSessionTask::~GuestSessionTask(void)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncint GuestSessionTask::getGuestProperty(const ComObjPtr<Guest> &pGuest,
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const Utf8Str &strPath, Utf8Str &strValue)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync ComObjPtr<Console> pConsole = pGuest->getConsole();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync const ComPtr<IMachine> pMachine = pConsole->machine();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Assert(!pMachine.isNull());
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Bstr strTemp, strFlags;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LONG64 i64Timestamp;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync HRESULT hr = pMachine->GetGuestProperty(Bstr(strPath).raw(),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync strTemp.asOutParam(),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync &i64Timestamp, strFlags.asOutParam());
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (SUCCEEDED(hr))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync strValue = strTemp;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VINF_SUCCESS;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VERR_NOT_FOUND;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync}
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncint GuestSessionTask::setProgress(ULONG uPercent)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync{
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (mProgress.isNull()) /* Progress is optional. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VINF_SUCCESS;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync BOOL fCanceled;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync && fCanceled)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VERR_CANCELLED;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync BOOL fCompleted;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync && fCompleted)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync AssertMsgFailed(("Setting value of an already completed progress\n"));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VINF_SUCCESS;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync HRESULT hr = mProgress->SetCurrentOperationProgress(uPercent);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (FAILED(hr))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VERR_COM_UNEXPECTED;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return VINF_SUCCESS;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync}
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncint GuestSessionTask::setProgressSuccess(void)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync{
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (mProgress.isNull()) /* Progress is optional. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VINF_SUCCESS;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync BOOL fCanceled;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync BOOL fCompleted;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync && !fCanceled
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync && !fCompleted)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync HRESULT hr = mProgress->notifyComplete(S_OK);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (FAILED(hr))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VERR_COM_UNEXPECTED; /** @todo Find a better rc. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync return VINF_SUCCESS;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync}
581f0625e43a928987623d7cf59e1b1ab61ca6c8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsyncHRESULT GuestSessionTask::setProgressErrorMsg(HRESULT hr, const Utf8Str &strMsg)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (mProgress.isNull()) /* Progress is optional. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return hr; /* Return original rc. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync BOOL fCanceled;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync BOOL fCompleted;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && !fCanceled
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && SUCCEEDED(mProgress->COMGETTER(Completed(&fCompleted)))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && !fCompleted)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync HRESULT hr2 = mProgress->notifyComplete(hr,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync COM_IIDOF(IGuestSession),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync GuestSession::getStaticComponentName(),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync strMsg.c_str());
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (FAILED(hr2))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return hr2;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync return hr; /* Return original rc. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSessionTaskCopyTo::SessionTaskCopyTo(GuestSession *pSession,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync : GuestSessionTask(pSession),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mSource(strSource),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync mSourceFile(NULL),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync mSourceOffset(0),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mSourceSize(0),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync mDest(strDest)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mCopyFileFlags = uFlags;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync/** @todo Merge this and the above call and let the above call do the open/close file handling so that the
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync * inner code only has to deal with file handles. No time now ... */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSessionTaskCopyTo::SessionTaskCopyTo(GuestSession *pSession,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PRTFILE pSourceFile, size_t cbSourceOffset, uint64_t cbSourceSize,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync const Utf8Str &strDest, uint32_t uFlags)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync : GuestSessionTask(pSession)
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync{
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync mSourceFile = pSourceFile;
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync mSourceOffset = cbSourceOffset;
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync mSourceSize = cbSourceSize;
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync mDest = strDest;
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync mCopyFileFlags = uFlags;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncSessionTaskCopyTo::~SessionTaskCopyTo(void)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsyncint SessionTaskCopyTo::Run(void)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlowThisFuncEnter();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync ComObjPtr<GuestSession> pSession = mSession;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Assert(!pSession.isNull());
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AutoCaller autoCaller(pSession);
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (mCopyFileFlags)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Utf8StrFmt(GuestSession::tr("Copy flags (%#x) not implemented yet"),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mCopyFileFlags));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync return VERR_INVALID_PARAMETER;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync int rc;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync RTFILE fileLocal;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync PRTFILE pFile = &fileLocal;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (!mSourceFile)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Does our source file exist? */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (!RTFileExists(mSource.c_str()))
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Utf8StrFmt(GuestSession::tr("Source file \"%s\" does not exist or is not a file"),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync mSource.c_str()));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync else
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = RTFileOpen(pFile, mSource.c_str(),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_FAILURE(rc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Utf8StrFmt(GuestSession::tr("Could not open source file \"%s\" for reading: %Rrc"),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync mSource.c_str(), rc));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync else
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = RTFileGetSize(*pFile, &mSourceSize);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_FAILURE(rc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync Utf8StrFmt(GuestSession::tr("Could not query file size of \"%s\": %Rrc"),
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync mSource.c_str(), rc));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync else
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync pFile = mSourceFile;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* Size + offset are optional. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync GuestProcessStartupInfo procInfo;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_CAT);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync procInfo.mFlags = ProcessCreateFlag_Hidden;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Set arguments.*/
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync procInfo.mArguments.push_back(Utf8StrFmt("--output=%s", mDest.c_str())); /** @todo Do we need path conversion? */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* Startup process. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync ComObjPtr<GuestProcess> pProcess; int guestRc;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync rc = pSession->processCreateExInteral(procInfo, pProcess);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_SUCCESS(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = pProcess->startProcess(&guestRc);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (RT_FAILURE(rc))
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync switch (rc)
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync GuestProcess::guestErrorToString(guestRc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync default:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Error while creating guest process for copying file \"%s\" from guest to host: %Rrc"),
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync mSource.c_str(), rc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_SUCCESS(rc))
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync {
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ProcessWaitResult_T waitRes;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync BYTE byBuf[_64K];
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync BOOL fCanceled = FALSE;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync uint64_t cbWrittenTotal = 0;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync uint64_t cbToRead = mSourceSize;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync for (;;)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync rc = pProcess->waitFor(ProcessWaitForFlag_StdIn,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync 30 * 1000 /* Timeout */, waitRes, &guestRc);
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync if ( RT_FAILURE(rc)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync || ( waitRes != ProcessWaitResult_StdIn
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync && waitRes != ProcessWaitResult_WaitFlagNotSupported))
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync break;
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync /* If the guest does not support waiting for stdin, we now yield in
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync * order to reduce the CPU load due to busy waiting. */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync if (waitRes == ProcessWaitResult_WaitFlagNotSupported)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync RTThreadSleep(1); /* Optional, don't check rc. */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync size_t cbRead = 0;
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync if (mSourceSize) /* If we have nothing to write, take a shortcut. */
ed9d3db07648c7e3a979105c15ad752ee9ea18devboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /** @todo Not very efficient, but works for now. */
9523921c89c66f4bececdbd5ac95aed0039eda1bvboxsync rc = RTFileSeek(*pFile, mSourceOffset + cbWrittenTotal,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync RTFILE_SEEK_BEGIN, NULL /* poffActual */);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (RT_SUCCESS(rc))
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync rc = RTFileRead(*pFile, (uint8_t*)byBuf,
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync RT_MIN(cbToRead, sizeof(byBuf)), &cbRead);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /*
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync * Some other error occured? There might be a chance that RTFileRead
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * could not resolve/map the native error code to an IPRT code, so just
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * print a generic error.
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (RT_FAILURE(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Could not read from file \"%s\" (%Rrc)"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync mSource.c_str(), rc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync Utf8StrFmt(GuestSession::tr("Seeking file \"%s\" to offset %RU64 failed: %Rrc"),
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync mSource.c_str(), cbWrittenTotal, rc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uint32_t fFlags = ProcessInputFlag_None;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Did we reach the end of the content we want to transfer (last chunk)? */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync if ( (cbRead < sizeof(byBuf))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Did we reach the last block which is exactly _64K? */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync || (cbToRead - cbRead == 0)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* ... or does the user want to cancel? */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync || ( !mProgress.isNull()
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync && fCanceled)
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync )
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlowThisFunc(("Writing last chunk cbRead=%RU64\n", cbRead));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync fFlags |= ProcessInputFlag_EndOfFile;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync uint32_t cbWritten;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(sizeof(byBuf) >= cbRead);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = pProcess->writeData(0 /* StdIn */, fFlags,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync byBuf, cbRead,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync 30 * 1000 /* Timeout */, &cbWritten, &guestRc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_FAILURE(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync switch (rc)
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync GuestProcess::guestErrorToString(guestRc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync default:
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Writing to file \"%s\" (offset %RU64) failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync mDest.c_str(), cbWrittenTotal, rc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Only subtract bytes reported written by the guest. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(cbToRead >= cbWritten);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync cbToRead -= cbWritten;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Update total bytes written to the guest. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync cbWrittenTotal += cbWritten;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(cbWrittenTotal <= mSourceSize);
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlowThisFunc(("rc=%Rrc, cbWritten=%RU32, cbToRead=%RU64, cbWrittenTotal=%RU64, cbFileSize=%RU64\n",
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc, cbWritten, cbToRead, cbWrittenTotal, mSourceSize));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Did the user cancel the operation above? */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (fCanceled)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Update the progress.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Watch out for division by zero. */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync mSourceSize > 0
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync ? rc = setProgress((ULONG)(cbWrittenTotal * 100 / mSourceSize))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync : rc = setProgress(100);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_FAILURE(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* End of file reached? */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (!cbToRead)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync } /* for */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFunc(("Copy loop ended with rc=%Rrc\n" ,rc));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if ( !fCanceled
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync || RT_SUCCESS(rc))
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /*
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * Even if we succeeded until here make sure to check whether we really transfered
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * everything.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if ( mSourceSize > 0
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync && cbWrittenTotal == 0)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync {
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync /* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync * to the destination -> access denied. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Utf8StrFmt(GuestSession::tr("Access denied when copying file \"%s\" to \"%s\""),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mSource.c_str(), mDest.c_str()));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync }
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync else if (cbWrittenTotal < mSourceSize)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync /* If we did not copy all let the user know. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed (%RU64/%RU64 bytes transfered)"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync mSource.c_str(), cbWrittenTotal, mSourceSize));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = pProcess->waitFor(ProcessWaitForFlag_Terminate,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync 30 * 1000 /* Timeout */, waitRes, &guestRc);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync if ( RT_FAILURE(rc)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync || waitRes != ProcessWaitResult_Terminate)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_FAILURE(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Waiting on termination for copying file \"%s\" failed: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync mSource.c_str(), rc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Waiting on termination for copying file \"%s\" failed with wait result %ld"),
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync mSource.c_str(), waitRes));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if (RT_SUCCESS(rc))
7e8ef90d3160234df0f254131b87af4243d79476vboxsync {
7e8ef90d3160234df0f254131b87af4243d79476vboxsync ProcessStatus_T procStatus;
7e8ef90d3160234df0f254131b87af4243d79476vboxsync LONG exitCode;
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && procStatus != ProcessStatus_TerminatedNormally)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync || ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
7e8ef90d3160234df0f254131b87af4243d79476vboxsync && exitCode != 0)
7e8ef90d3160234df0f254131b87af4243d79476vboxsync )
7e8ef90d3160234df0f254131b87af4243d79476vboxsync {
7e8ef90d3160234df0f254131b87af4243d79476vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
7e8ef90d3160234df0f254131b87af4243d79476vboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed with status %ld, exit code %ld"),
7e8ef90d3160234df0f254131b87af4243d79476vboxsync mSource.c_str(), procStatus, exitCode)); /**@todo Add stringify methods! */
7e8ef90d3160234df0f254131b87af4243d79476vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync }
7e8ef90d3160234df0f254131b87af4243d79476vboxsync }
7e8ef90d3160234df0f254131b87af4243d79476vboxsync
7e8ef90d3160234df0f254131b87af4243d79476vboxsync if (RT_SUCCESS(rc))
7e8ef90d3160234df0f254131b87af4243d79476vboxsync rc = setProgressSuccess();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (!pProcess.isNull())
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync pProcess->uninit();
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync } /* processCreateExInteral */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync if (!mSourceFile) /* Only close locally opened files. */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync RTFileClose(*pFile);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowFuncLeaveRC(rc);
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync return rc;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync}
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsyncint SessionTaskCopyTo::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync{
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, mCopyFileFlags=%x\n",
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync strDesc.c_str(), mSource.c_str(), mDest.c_str(), mCopyFileFlags));
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync mDesc = strDesc;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync mProgress = pProgress;
06ea6bcf23874b662d499b3f130024c98b2dd7a6vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync int rc = RTThreadCreate(NULL, SessionTaskCopyTo::taskThread, this,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync "gctlCpyTo");
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync LogFlowFuncLeaveRC(rc);
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync return rc;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync}
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/* static */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncint SessionTaskCopyTo::taskThread(RTTHREAD Thread, void *pvUser)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync std::auto_ptr<SessionTaskCopyTo> task(static_cast<SessionTaskCopyTo*>(pvUser));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertReturn(task.get(), VERR_GENERAL_FAILURE);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync LogFlowFunc(("pTask=%p\n", task.get()));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return task->Run();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSessionTaskCopyFrom::SessionTaskCopyFrom(GuestSession *pSession,
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync const Utf8Str &strSource, const Utf8Str &strDest, uint32_t uFlags)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync : GuestSessionTask(pSession)
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync{
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync mSource = strSource;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync mDest = strDest;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync mFlags = uFlags;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync}
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncSessionTaskCopyFrom::~SessionTaskCopyFrom(void)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync{
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync}
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsyncint SessionTaskCopyFrom::Run(void)
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync{
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync LogFlowThisFuncEnter();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync ComObjPtr<GuestSession> pSession = mSession;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync Assert(!pSession.isNull());
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync AutoCaller autoCaller(pSession);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync /*
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync * Note: There will be races between querying file size + reading the guest file's
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync * content because we currently *do not* lock down the guest file when doing the
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync * actual operations.
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync ** @todo Implement guest file locking!
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync GuestFsObjData objData; int guestRc;
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync int rc = pSession->fileQueryInfoInternal(Utf8Str(mSource), objData, &guestRc);
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync if (RT_FAILURE(rc))
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync {
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync Utf8StrFmt(GuestSession::tr("Querying guest file information for \"%s\" failed: %Rrc"),
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync mSource.c_str(), rc));
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync }
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync else if (objData.mType != FsObjType_File) /* Only single files are supported at the moment. */
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync {
1cd59fdf671ca60c64d77e3f7046aaecf7003824vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Object \"%s\" on the guest is not a file"), mSource.c_str()));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_SUCCESS(rc))
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync RTFILE fileDest;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = RTFileOpen(&fileDest, mDest.c_str(),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync RTFILE_O_WRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE); /** @todo Use the correct open modes! */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_FAILURE(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Error opening destination file \"%s\": %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync mDest.c_str(), rc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync GuestProcessStartupInfo procInfo;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync procInfo.mName = Utf8StrFmt(GuestSession::tr("Copying file \"%s\" from guest to the host to \"%s\" (%RI64 bytes)"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync mSource.c_str(), mDest.c_str(), objData.mObjectSize);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_CAT);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync procInfo.mFlags = ProcessCreateFlag_Hidden | ProcessCreateFlag_WaitForStdOut;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Set arguments.*/
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync procInfo.mArguments.push_back(mSource); /* Which file to output? */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Startup process. */
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync ComObjPtr<GuestProcess> pProcess;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync rc = pSession->processCreateExInteral(procInfo, pProcess);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_SUCCESS(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = pProcess->startProcess(&guestRc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_FAILURE(rc))
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync switch (rc)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync GuestProcess::guestErrorToString(guestRc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync default:
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Utf8StrFmt(GuestSession::tr("Error while creating guest process for copying file \"%s\" from guest to host: %Rrc"),
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync mSource.c_str(), rc));
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync break;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync }
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync else
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync ProcessWaitResult_T waitRes;
702a8ee2dc1de96f2f77e97135015d3e243186fdvboxsync BYTE byBuf[_64K];
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync BOOL fCanceled = FALSE;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uint64_t cbWrittenTotal = 0;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync uint64_t cbToRead = objData.mObjectSize;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync for (;;)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync rc = pProcess->waitFor(ProcessWaitForFlag_StdOut,
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync 30 * 1000 /* Timeout */, waitRes, &guestRc);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync if (RT_FAILURE(rc))
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync switch (rc)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync {
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync GuestProcess::guestErrorToString(guestRc));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync default:
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync Utf8StrFmt(GuestSession::tr("Error while creating guest process for copying file \"%s\" from guest to host: %Rrc"),
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync mSource.c_str(), rc));
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if ( waitRes == ProcessWaitResult_StdOut
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync || waitRes == ProcessWaitResult_WaitFlagNotSupported)
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync /* If the guest does not support waiting for stdin, we now yield in
fb41ad77bcfbdb3aaa1fc9503a37ee6a70dc6461vboxsync * order to reduce the CPU load due to busy waiting. */
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync if (waitRes == ProcessWaitResult_WaitFlagNotSupported)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync RTThreadSleep(1); /* Optional, don't check rc. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync size_t cbRead;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = pProcess->readData(OUTPUT_HANDLE_ID_STDOUT, sizeof(byBuf),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync 30 * 1000 /* Timeout */, byBuf, sizeof(byBuf),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync &cbRead, &guestRc);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_FAILURE(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync switch (rc)
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync {
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync GuestProcess::guestErrorToString(guestRc));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync default:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Utf8StrFmt(GuestSession::tr("Reading from file \"%s\" (offset %RU64) failed: %Rrc"),
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync mSource.c_str(), cbWrittenTotal, rc));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync break;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
c193ae401647c574d0ef52af57c32cf5d7c44966vboxsync
c193ae401647c574d0ef52af57c32cf5d7c44966vboxsync break;
c193ae401647c574d0ef52af57c32cf5d7c44966vboxsync }
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync
c193ae401647c574d0ef52af57c32cf5d7c44966vboxsync if (cbRead)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = RTFileWrite(fileDest, byBuf, cbRead, NULL /* No partial writes */);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_FAILURE(rc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Utf8StrFmt(GuestSession::tr("Error writing to file \"%s\" (%RU64 bytes left): %Rrc"),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync mDest.c_str(), cbToRead, rc));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync /* Only subtract bytes reported written by the guest. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync Assert(cbToRead >= cbRead);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync cbToRead -= cbRead;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* Update total bytes written to the guest. */
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync cbWrittenTotal += cbRead;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Assert(cbWrittenTotal <= (uint64_t)objData.mObjectSize);
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync /* Did the user cancel the operation above? */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if ( SUCCEEDED(mProgress->COMGETTER(Canceled(&fCanceled)))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync && fCanceled)
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc = setProgress((ULONG)(cbWrittenTotal / ((uint64_t)objData.mObjectSize / 100.0)));
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync if (RT_FAILURE(rc))
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync else
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync {
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync break;
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync }
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync } /* for */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
cd5df721f068659172f3bf95de8fedeb465f057dvboxsync LogFlowThisFunc(("rc=%Rrc, guestrc=%Rrc, waitRes=%ld, cbWrittenTotal=%RU64, cbSize=%RI64, cbToRead=%RU64\n",
ecf100db90e8e3af96312908282d3c20e754fbe8vboxsync rc, guestRc, waitRes, cbWrittenTotal, objData.mObjectSize, cbToRead));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if ( !fCanceled
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync || RT_SUCCESS(rc))
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /*
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Even if we succeeded until here make sure to check whether we really transfered
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * everything.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if ( objData.mObjectSize > 0
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && cbWrittenTotal == 0)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* If nothing was transfered but the file size was > 0 then "vbox_cat" wasn't able to write
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * to the destination -> access denied. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Access denied when copying file \"%s\" to \"%s\""),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mSource.c_str(), mDest.c_str()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else if (cbWrittenTotal < (uint64_t)objData.mObjectSize)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* If we did not copy all let the user know. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed (%RU64/%RI64 bytes transfered)"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mSource.c_str(), cbWrittenTotal, objData.mObjectSize));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ProcessStatus_T procStatus;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LONG exitCode;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if ( ( SUCCEEDED(pProcess->COMGETTER(Status(&procStatus)))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && procStatus != ProcessStatus_TerminatedNormally)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync || ( SUCCEEDED(pProcess->COMGETTER(ExitCode(&exitCode)))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && exitCode != 0)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync )
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Copying file \"%s\" failed with status %ld, exit code %d"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mSource.c_str(), procStatus, exitCode)); /**@todo Add stringify methods! */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else /* Yay, success! */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = setProgressSuccess();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (!pProcess.isNull())
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync pProcess->uninit();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync RTFileClose(fileDest);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFuncLeaveRC(rc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint SessionTaskCopyFrom::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, strDest=%s, uFlags=%x\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync strDesc.c_str(), mSource.c_str(), mDest.c_str(), mFlags));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mDesc = strDesc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mProgress = pProgress;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int rc = RTThreadCreate(NULL, SessionTaskCopyFrom::taskThread, this,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync "gctlCpyFrom");
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFuncLeaveRC(rc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync/* static */
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncint SessionTaskCopyFrom::taskThread(RTTHREAD Thread, void *pvUser)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync std::auto_ptr<SessionTaskCopyFrom> task(static_cast<SessionTaskCopyFrom*>(pvUser));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync AssertReturn(task.get(), VERR_GENERAL_FAILURE);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync LogFlowFunc(("pTask=%p\n", task.get()));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync return task->Run();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsyncSessionTaskUpdateAdditions::SessionTaskUpdateAdditions(GuestSession *pSession,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync const Utf8Str &strSource, uint32_t uFlags)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync : GuestSessionTask(pSession)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync{
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mSource = strSource;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync mFlags = uFlags;
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsyncSessionTaskUpdateAdditions::~SessionTaskUpdateAdditions(void)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync{
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync}
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsyncint SessionTaskUpdateAdditions::copyFileToGuest(GuestSession *pSession, PRTISOFSFILE pISO,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync Utf8Str const &strFileSource, const Utf8Str &strFileDest,
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync bool fOptional, uint32_t *pcbSize)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertPtrReturn(pSession, VERR_INVALID_POINTER);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync AssertPtrReturn(pISO, VERR_INVALID_POINTER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* pcbSize is optional. */
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint32_t cbOffset;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync size_t cbSize;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync int rc = RTIsoFsGetFileInfo(pISO, strFileSource.c_str(), &cbOffset, &cbSize);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (fOptional)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return VINF_SUCCESS;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(cbOffset);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(cbSize);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = RTFileSeek(pISO->file, cbOffset, RTFILE_SEEK_BEGIN, NULL);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Copy over the Guest Additions file to the guest. */
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_SUCCESS(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync LogFlowThisFunc(("Copying Guest Additions installer file \"%s\" to \"%s\" on guest ...\n",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync strFileSource.c_str(), strFileDest.c_str()));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_SUCCESS(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync SessionTaskCopyTo *pTask = new SessionTaskCopyTo(pSession /* GuestSession */,
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync &pISO->file, cbOffset, cbSize,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync strFileDest, CopyFileFlag_None);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync AssertPtrReturn(pTask, VERR_NO_MEMORY);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<Progress> pProgressCopyTo;
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync rc = pSession->startTaskAsync(Utf8StrFmt(GuestSession::tr("Copying Guest Additions installer file \"%s\" to \"%s\" on guest"),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync mSource.c_str(), strFileDest.c_str()),
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync pTask, pProgressCopyTo);
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync if (RT_SUCCESS(rc))
35e6d303696e46d969aaf9a59cc381333a483b0bvboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync BOOL fCanceled = FALSE;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync HRESULT hr = pProgressCopyTo->WaitForCompletion(-1);
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync if ( SUCCEEDED(pProgressCopyTo->COMGETTER(Canceled)(&fCanceled))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && fCanceled)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else if (FAILED(hr))
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync {
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync Assert(FAILED(hr));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync rc = VERR_GENERAL_FAILURE; /* Fudge. */
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /** @todo Note: Since there is no file locking involved at the moment, there can be modifications
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * between finished copying, the verification and the actual execution. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Determine where the installer image ended up and if it has the correct size. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFunc(("Verifying Guest Additions installer file \"%s\" ...\n",
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync strFileDest.c_str()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync GuestFsObjData objData;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync int64_t cbSizeOnGuest; int guestRc;
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync rc = pSession->fileQuerySizeInternal(strFileDest, &cbSizeOnGuest, &guestRc);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if ( RT_SUCCESS(rc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && cbSize == (uint64_t)cbSizeOnGuest)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync LogFlowThisFunc(("Guest Additions installer file \"%s\" successfully verified\n",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync strFileDest.c_str()));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync else
ca3db470494a8b6eaec69ea37468a5cda65e2da8vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(rc)) /* Size does not match. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync LogFlowThisFunc(("Size of Guest Additions installer file \"%s\" does not match: %RI64bytes copied, %RU64bytes expected\n",
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync strFileDest.c_str(), cbSizeOnGuest, cbSize));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_BROKEN_PIPE; /** @todo Find a better error. */
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync }
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync else
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync switch (rc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestProcess::guestErrorToString(guestRc));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync default:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Error while querying size for file \"%s\": %Rrc"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync strFileDest.c_str(), rc));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (pcbSize)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync *pcbSize = cbSizeOnGuest;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint SessionTaskUpdateAdditions::runFileOnGuest(GuestSession *pSession, GuestProcessStartupInfo &procInfo)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AssertPtrReturn(pSession, VERR_INVALID_POINTER);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync LogRel(("Running %s ...\n", procInfo.mName.c_str()));
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync LONG exitCode;
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync GuestProcessTool procTool; int guestRc;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync int vrc = procTool.Init(pSession, procInfo, false /* Async */, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(guestRc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(vrc))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync vrc = procTool.TerminatedOk(&exitCode);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(vrc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync switch (vrc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_NOT_EQUAL: /** @todo Special guest control rc needed! */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Running update file \"%s\" on guest terminated with exit code %ld"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mCommand.c_str(), exitCode));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestProcess::guestErrorToString(vrc));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync default:
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Error while running update file \"%s\" on guest: %Rrc"),
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync procInfo.mCommand.c_str(), vrc));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return vrc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint SessionTaskUpdateAdditions::Run(void)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync{
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowThisFuncEnter();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<GuestSession> pSession = mSession;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Assert(!pSession.isNull());
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync AutoCaller autoCaller(pSession);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync int rc = setProgress(10);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync HRESULT hr = S_OK;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogRel(("Automatic update of Guest Additions started, using \"%s\"\n", mSource.c_str()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync ComObjPtr<Guest> pGuest(mSession->getParent());
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync#if 0
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /*
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Wait for the guest being ready within 30 seconds.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync AdditionsRunLevelType_T addsRunLevel;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync uint64_t tsStart = RTTimeSystemMilliTS();
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync while ( SUCCEEDED(hr = pGuest->COMGETTER(AdditionsRunLevel)(&addsRunLevel))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && ( addsRunLevel != AdditionsRunLevelType_Userland
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && addsRunLevel != AdditionsRunLevelType_Desktop))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if ((RTTimeSystemMilliTS() - tsStart) > 30 * 1000)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_TIMEOUT;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync break;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync RTThreadSleep(100); /* Wait a bit. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (FAILED(hr)) rc = VERR_TIMEOUT;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (rc == VERR_TIMEOUT)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Guest Additions were not ready within time, giving up")));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync#else
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /*
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * For use with the GUI we don't want to wait, just return so that the manual .ISO mounting
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * can continue.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AdditionsRunLevelType_T addsRunLevel;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if ( FAILED(hr = pGuest->COMGETTER(AdditionsRunLevel)(&addsRunLevel))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync || ( addsRunLevel != AdditionsRunLevelType_Userland
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync && addsRunLevel != AdditionsRunLevelType_Desktop))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (addsRunLevel == AdditionsRunLevelType_System)
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync Utf8StrFmt(GuestSession::tr("Guest Additions are installed but not fully loaded yet, aborting automatic update")));
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync else
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Utf8StrFmt(GuestSession::tr("Guest Additions not installed or ready, aborting automatic update")));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = VERR_NOT_SUPPORTED;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#endif
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_SUCCESS(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /*
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Determine if we are able to update automatically. This only works
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * if there are recent Guest Additions installed already.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Utf8Str strAddsVer;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestAdd/Version", strAddsVer);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if ( RT_SUCCESS(rc)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync && RTStrVersionCompare(strAddsVer.c_str(), "4.1") < 0)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Utf8StrFmt(GuestSession::tr("Guest has too old Guest Additions (%s) installed for automatic updating, please update manually"),
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync strAddsVer.c_str()));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = VERR_NOT_SUPPORTED;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8Str strOSVer;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync eOSType osType;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /*
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Determine guest OS type and the required installer image.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8Str strOSType;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestInfo/OS/Product", strOSType);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_SUCCESS(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if ( strOSType.contains("Microsoft", Utf8Str::CaseInsensitive)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync || strOSType.contains("Windows", Utf8Str::CaseInsensitive))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync osType = eOSType_Windows;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /*
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * Determine guest OS version.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestInfo/OS/Release", strOSVer);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (RT_FAILURE(rc))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Unable to detected guest OS version, please update manually")));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_NOT_SUPPORTED;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Because Windows 2000 + XP and is bitching with WHQL popups even if we have signed drivers we
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * can't do automated updates here. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Windows XP 64-bit (5.2) is a Windows 2003 Server actually, so skip this here. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if ( RT_SUCCESS(rc)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync && ( strOSVer.startsWith("5.0") /* Exclude the build number. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync || strOSVer.startsWith("5.1")) /* Exclude the build number. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync )
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* If we don't have AdditionsUpdateFlag_WaitForUpdateStartOnly set we can't continue
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * because the Windows Guest Additions installer will fail because of WHQL popups. If the
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * flag is set this update routine ends successfully as soon as the installer was started
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * (and the user has to deal with it in the guest). */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (!(mFlags & AdditionsUpdateFlag_WaitForUpdateStartOnly))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Utf8StrFmt(GuestSession::tr("Windows 2000 and XP are not supported for automatic updating due to WHQL interaction, please update manually")));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync rc = VERR_NOT_SUPPORTED;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else if (strOSType.contains("Solaris", Utf8Str::CaseInsensitive))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync osType = eOSType_Solaris;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync else /* Everything else hopefully means Linux :-). */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync osType = eOSType_Linux;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync#if 1 /* Only Windows is supported (and tested) at the moment. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (osType != eOSType_Windows)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync hr = setProgressErrorMsg(VBOX_E_NOT_SUPPORTED,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Utf8StrFmt(GuestSession::tr("Detected guest OS (%s) does not support automatic Guest Additions updating, please update manually"),
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync strOSType.c_str()));
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync rc = VERR_NOT_SUPPORTED;
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync }
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync#endif
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync }
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync }
cc1ef2ef9bbc6a0ff964928d61b7298e5bfcce5fvboxsync
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync RTISOFSFILE iso;
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (RT_SUCCESS(rc))
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync {
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync /*
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync * Try to open the .ISO file to extract all needed files.
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = RTIsoFsOpen(&iso, mSource.c_str());
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_FAILURE(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Utf8StrFmt(GuestSession::tr("Unable to open Guest Additions .ISO file \"%s\": %Rrc"),
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync mSource.c_str(), rc));
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync }
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync else
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync {
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync /* Set default installation directories. */
907b6adfa052386a0666d5557bee9bdbc100c2e5vboxsync Utf8Str strUpdateDir = "/tmp/";
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync if (osType == eOSType_Windows)
687794577e2e35c3cae67e692a7f2130d1262a82vboxsync strUpdateDir = "C:\\Temp\\";
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = setProgress(5);
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Try looking up the Guest Additions installation directory. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_SUCCESS(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Try getting the installed Guest Additions version to know whether we
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * can install our temporary Guest Addition data into the original installation
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * directory.
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync *
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Because versions prior to 4.2 had bugs wrt spaces in paths we have to choose
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * a different location then.
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync bool fUseInstallDir = false;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync Utf8Str strAddsVer;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestAdd/Version", strAddsVer);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if ( RT_SUCCESS(rc)
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync && RTStrVersionCompare(strAddsVer.c_str(), "4.2r80329") > 0)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync fUseInstallDir = true;
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (fUseInstallDir)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_SUCCESS(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = getGuestProperty(pGuest, "/VirtualBox/GuestAdd/InstallDir", strUpdateDir);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync if (RT_SUCCESS(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (osType == eOSType_Windows)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync {
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync strUpdateDir.findReplace('/', '\\');
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync strUpdateDir.append("\\Update\\");
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync else
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync strUpdateDir.append("/update/");
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (RT_SUCCESS(rc))
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogRel(("Guest Additions update directory is: %s\n",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync strUpdateDir.c_str()));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Create the installation directory. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync int guestRc;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync rc = pSession->directoryCreateInternal(strUpdateDir,
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync 755 /* Mode */, DirectoryCreateFlag_Parents, &guestRc);
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (RT_FAILURE(rc))
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync switch (rc)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync case VERR_GENERAL_FAILURE: /** @todo Special guest control rc needed! */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync GuestProcess::guestErrorToString(guestRc));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync break;
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync default:
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync setProgressErrorMsg(VBOX_E_IPRT_ERROR,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync Utf8StrFmt(GuestSession::tr("Error creating installation directory \"%s\" on the guest: %Rrc"),
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync strUpdateDir.c_str(), rc));
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync break;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync }
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync }
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (RT_SUCCESS(rc))
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync rc = setProgress(10);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync if (RT_SUCCESS(rc))
81096b0da0061583a511da27088643aa949a1ec9vboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync /* Prepare the file(s) we want to copy over to the guest and
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync * (maybe) want to run. */
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync switch (osType)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync {
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync case eOSType_Windows:
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync {
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync /* Do we need to install our certificates? We do this for W2K and up. */
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync bool fInstallCert = false;
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync /* Only Windows 2000 and up need certificates to be installed. */
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync if (RTStrVersionCompare(strOSVer.c_str(), "5.0") >= 0)
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync {
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync fInstallCert = true;
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync LogRel(("Certificates for auto updating WHQL drivers will be installed\n"));
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync }
d4a9d525e6f2111d462d2d96462dced6b9ec00efvboxsync else
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync LogRel(("Skipping installation of certificates for WHQL drivers\n"));
004d74842597dacc4009803171296dfcf9398c69vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (fInstallCert)
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* Our certificate. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mFiles.push_back(InstallerFile("CERT/ORACLE_VBOX.CER",
004d74842597dacc4009803171296dfcf9398c69vboxsync strUpdateDir + "oracle-vbox.cer",
004d74842597dacc4009803171296dfcf9398c69vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO | UPDATEFILE_FLAG_OPTIONAL));
004d74842597dacc4009803171296dfcf9398c69vboxsync /* Our certificate installation utility. */
004d74842597dacc4009803171296dfcf9398c69vboxsync /* First pass: Copy over the file + execute it to remove any existing
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync * VBox certificates. */
004d74842597dacc4009803171296dfcf9398c69vboxsync GuestProcessStartupInfo siCertUtilRem;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync siCertUtilRem.mName = "VirtualBox Certificate Utility, removing old VirtualBox certificates";
004d74842597dacc4009803171296dfcf9398c69vboxsync siCertUtilRem.mArguments.push_back(Utf8Str("remove-trusted-publisher"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync siCertUtilRem.mArguments.push_back(Utf8Str("--root")); /* Add root certificate as well. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync siCertUtilRem.mArguments.push_back(Utf8Str(strUpdateDir + "oracle-vbox.cer"));
004d74842597dacc4009803171296dfcf9398c69vboxsync siCertUtilRem.mArguments.push_back(Utf8Str(strUpdateDir + "oracle-vbox.cer"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mFiles.push_back(InstallerFile("CERT/VBOXCERTUTIL.EXE",
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync strUpdateDir + "VBoxCertUtil.exe",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO | UPDATEFILE_FLAG_EXECUTE | UPDATEFILE_FLAG_OPTIONAL,
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync siCertUtilRem));
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync /* Second pass: Only execute (but don't copy) again, this time installng the
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync * recent certificates just copied over. */
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync GuestProcessStartupInfo siCertUtilAdd;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync siCertUtilAdd.mName = "VirtualBox Certificate Utility, installing VirtualBox certificates";
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync siCertUtilAdd.mArguments.push_back(Utf8Str("add-trusted-publisher"));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync siCertUtilAdd.mArguments.push_back(Utf8Str("--root")); /* Add root certificate as well. */
004d74842597dacc4009803171296dfcf9398c69vboxsync siCertUtilAdd.mArguments.push_back(Utf8Str(strUpdateDir + "oracle-vbox.cer"));
004d74842597dacc4009803171296dfcf9398c69vboxsync siCertUtilAdd.mArguments.push_back(Utf8Str(strUpdateDir + "oracle-vbox.cer"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync mFiles.push_back(InstallerFile("CERT/VBOXCERTUTIL.EXE",
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync strUpdateDir + "VBoxCertUtil.exe",
5366e994777f9d9391cf809dc77610f57270d75dvboxsync UPDATEFILE_FLAG_EXECUTE | UPDATEFILE_FLAG_OPTIONAL,
81096b0da0061583a511da27088643aa949a1ec9vboxsync siCertUtilAdd));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* The installers in different flavors, as we don't know (and can't assume)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * the guest's bitness. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS_X86.EXE",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync strUpdateDir + "VBoxWindowsAdditions-x86.exe",
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO));
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS_AMD64.EXE",
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync strUpdateDir + "VBoxWindowsAdditions-amd64.exe",
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync UPDATEFILE_FLAG_COPY_FROM_ISO));
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync /* The stub loader which decides which flavor to run. */
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync GuestProcessStartupInfo siInstaller;
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync siInstaller.mName = "VirtualBox Windows Guest Additions Installer";
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync /* Set a running timeout of 5 minutes -- the Windows Guest Additions
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * setup can take quite a while, so be on the safe side. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync siInstaller.mTimeoutMS = 5 * 60 * 1000;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync siInstaller.mArguments.push_back(Utf8Str("/S")); /* We want to install in silent mode. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync siInstaller.mArguments.push_back(Utf8Str("/l")); /* ... and logging enabled. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Don't quit VBoxService during upgrade because it still is used for this
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * piece of code we're in right now (that is, here!) ... */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync siInstaller.mArguments.push_back(Utf8Str("/no_vboxservice_exit"));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /* Tell the installer to report its current installation status
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * using a running VBoxTray instance via balloon messages in the
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * Windows taskbar. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync siInstaller.mArguments.push_back(Utf8Str("/post_installstatus"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync /* If the caller does not want to wait for out guest update process to end,
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync * complete the progress object now so that the caller can do other work. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync if (mFlags & AdditionsUpdateFlag_WaitForUpdateStartOnly)
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync siInstaller.mFlags |= ProcessCreateFlag_WaitForProcessStartOnly;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync mFiles.push_back(InstallerFile("VBOXWINDOWSADDITIONS.EXE",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync strUpdateDir + "VBoxWindowsAdditions.exe",
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync UPDATEFILE_FLAG_COPY_FROM_ISO | UPDATEFILE_FLAG_EXECUTE, siInstaller));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync }
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync case eOSType_Linux:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /** @todo Add Linux support. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync case eOSType_Solaris:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync /** @todo Add Solaris support. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync default:
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync AssertReleaseMsgFailed(("Unsupported guest type: %d\n", osType));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync break;
5366e994777f9d9391cf809dc77610f57270d75dvboxsync }
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync }
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync if (RT_SUCCESS(rc))
88cc9bf61296bc5526344415167bb2625ae1dd99vboxsync {
5366e994777f9d9391cf809dc77610f57270d75dvboxsync /* We want to spend 40% total for all copying operations. So roughly
c55bf74b54ecdfb5ebc4e5d90b620d0fee31737evboxsync * calculate the specific percentage step of each copied file. */
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync uint8_t uOffset = 20; /* Start at 20%. */
5366e994777f9d9391cf809dc77610f57270d75dvboxsync uint8_t uStep = 40 / mFiles.size();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync LogRel(("Copying over Guest Additions update files to the guest ...\n"));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync std::vector<InstallerFile>::const_iterator itFiles = mFiles.begin();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync while (itFiles != mFiles.end())
81096b0da0061583a511da27088643aa949a1ec9vboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync if (itFiles->fFlags & UPDATEFILE_FLAG_COPY_FROM_ISO)
81096b0da0061583a511da27088643aa949a1ec9vboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync bool fOptional = false;
81096b0da0061583a511da27088643aa949a1ec9vboxsync if (itFiles->fFlags & UPDATEFILE_FLAG_OPTIONAL)
81096b0da0061583a511da27088643aa949a1ec9vboxsync fOptional = true;
81096b0da0061583a511da27088643aa949a1ec9vboxsync rc = copyFileToGuest(pSession, &iso, itFiles->strSource, itFiles->strDest,
81096b0da0061583a511da27088643aa949a1ec9vboxsync fOptional, NULL /* cbSize */);
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync if (RT_FAILURE(rc))
81096b0da0061583a511da27088643aa949a1ec9vboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
81096b0da0061583a511da27088643aa949a1ec9vboxsync Utf8StrFmt(GuestSession::tr("Error while copying file \"%s\" to \"%s\" on the guest: %Rrc"),
81096b0da0061583a511da27088643aa949a1ec9vboxsync itFiles->strSource.c_str(), itFiles->strDest.c_str(), rc));
5366e994777f9d9391cf809dc77610f57270d75dvboxsync break;
81096b0da0061583a511da27088643aa949a1ec9vboxsync }
81096b0da0061583a511da27088643aa949a1ec9vboxsync }
15c6c4ce0082362b8b81e15c3605f2d3aca69a21vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync rc = setProgress(uOffset);
510567648d46488f4166e5f69ffffe3eeeeec4d9vboxsync if (RT_FAILURE(rc))
81096b0da0061583a511da27088643aa949a1ec9vboxsync break;
81096b0da0061583a511da27088643aa949a1ec9vboxsync uOffset += uStep;
81096b0da0061583a511da27088643aa949a1ec9vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync itFiles++;
81096b0da0061583a511da27088643aa949a1ec9vboxsync }
81096b0da0061583a511da27088643aa949a1ec9vboxsync }
81096b0da0061583a511da27088643aa949a1ec9vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync /* Done copying, close .ISO file. */
81096b0da0061583a511da27088643aa949a1ec9vboxsync RTIsoFsClose(&iso);
81096b0da0061583a511da27088643aa949a1ec9vboxsync
81096b0da0061583a511da27088643aa949a1ec9vboxsync if (RT_SUCCESS(rc))
81096b0da0061583a511da27088643aa949a1ec9vboxsync {
81096b0da0061583a511da27088643aa949a1ec9vboxsync /* We want to spend 35% total for all copying operations. So roughly
81096b0da0061583a511da27088643aa949a1ec9vboxsync * calculate the specific percentage step of each copied file. */
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync uint8_t uOffset = 60; /* Start at 60%. */
81096b0da0061583a511da27088643aa949a1ec9vboxsync uint8_t uStep = 35 / mFiles.size();
51da1b42a8a60004d6b24ebedd4aa3fe853e4b24vboxsync
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync LogRel(("Executing Guest Additions update files ...\n"));
d8e12fa5dd1c35282b98cb165e42b6b395cf971bvboxsync
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync std::vector<InstallerFile>::iterator itFiles = mFiles.begin();
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync while (itFiles != mFiles.end())
5366e994777f9d9391cf809dc77610f57270d75dvboxsync {
5366e994777f9d9391cf809dc77610f57270d75dvboxsync if (itFiles->fFlags & UPDATEFILE_FLAG_EXECUTE)
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync rc = runFileOnGuest(pSession, itFiles->mProcInfo);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (RT_FAILURE(rc))
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync break;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync rc = setProgress(uOffset);
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_FAILURE(rc))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync break;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync uOffset += uStep;
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync itFiles++;
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync if (RT_SUCCESS(rc))
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync LogRel(("Automatic update of Guest Additions succeeded\n"));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync rc = setProgressSuccess();
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync }
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if (RT_FAILURE(rc))
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync if (rc == VERR_CANCELLED)
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync {
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync LogRel(("Automatic update of Guest Additions was canceled\n"));
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync hr = setProgressErrorMsg(VBOX_E_IPRT_ERROR,
4121d226ac899f17e13aff3aff42b603c8b5c1fevboxsync Utf8StrFmt(GuestSession::tr("Installation was canceled")));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync else
3ff8aa7d3c74cfbe8da5f77b8ea6c748cc79213avboxsync {
5366e994777f9d9391cf809dc77610f57270d75dvboxsync Utf8Str strError = Utf8StrFmt("No further error information available (%Rrc)", rc);
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync if (!mProgress.isNull()) /* Progress object is optional. */
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync {
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync ComPtr<IVirtualBoxErrorInfo> pError;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync hr = mProgress->COMGETTER(ErrorInfo)(pError.asOutParam());
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync Assert(!pError.isNull());
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if (SUCCEEDED(hr))
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync {
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync Bstr strVal;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync hr = pError->COMGETTER(Text)(strVal.asOutParam());
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync if ( SUCCEEDED(hr)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync && strVal.isNotEmpty())
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync strError = strVal;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogRel(("Automatic update of Guest Additions failed: %s\n", strError.c_str()));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogRel(("Please install Guest Additions manually\n"));
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync }
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync LogFlowFuncLeaveRC(rc);
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync return rc;
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync}
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsync
4171ffb38eb8720b2ae9a8d13e95103ab26cfd12vboxsyncint SessionTaskUpdateAdditions::RunAsync(const Utf8Str &strDesc, ComObjPtr<Progress> &pProgress)
b8bb9c9f6b8ebfd0a7d6df0c0289f9fe80241750vboxsync{
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync LogFlowThisFunc(("strDesc=%s, strSource=%s, uFlags=%x\n",
5050fc8de0b121eab1b738d7c1007cde4903284dvboxsync strDesc.c_str(), mSource.c_str(), mFlags));
462e60a19d02a99b2b1a5c08dff74bb0808d707cvboxsync
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync mDesc = strDesc;
e378dfdadd62aadc0a012c9953322d979d7606e6vboxsync mProgress = pProgress;
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync int rc = RTThreadCreate(NULL, SessionTaskUpdateAdditions::taskThread, this,
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync 0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync "gctlUpGA");
5f2b03bf7695dabd71222dba123532a3f76828c1vboxsync LogFlowFuncLeaveRC(rc);
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync return rc;
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync}
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsync/* static */
7862f4bd000f1eb6c86289f5ac2849e9cf943ca9vboxsyncint SessionTaskUpdateAdditions::taskThread(RTTHREAD Thread, void *pvUser)
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync{
40c1a23e86c79b24a917a43c186b2e54504d12c1vboxsync std::auto_ptr<SessionTaskUpdateAdditions> task(static_cast<SessionTaskUpdateAdditions*>(pvUser));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync AssertReturn(task.get(), VERR_GENERAL_FAILURE);
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync LogFlowFunc(("pTask=%p\n", task.get()));
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync return task->Run();
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync}
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync
3fb3de312d1ff675e0f7cc62a7d46cbb1d5d9353vboxsync