GuestCtrlImplDir.cpp revision a7014c99617f226a35a6a46a5b4bddcc6e0c17e0
/* $Id: */
/** @file
* VirtualBox Guest Control - Guest directory handling.
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "GuestImpl.h"
#include "GuestCtrlImplPrivate.h"
#include "GuestDirEntryImpl.h"
#include "Global.h"
#include "ConsoleImpl.h"
#include "ProgressImpl.h"
#include "VMMDev.h"
#include "AutoCaller.h"
#include "Logging.h"
#ifdef VBOX_WITH_GUEST_CONTROL
#endif
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
if (directoryHandleExists(aHandle))
{
return S_OK;
}
return setError(VBOX_E_IPRT_ERROR,
#endif
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
/* Do not allow anonymous executions (with system rights). */
LogRel(("Creating guest directory \"%s\" as user \"%s\" ...\n",
return directoryCreateInternal(aDirectory,
#endif
}
#ifdef VBOX_WITH_GUEST_CONTROL
{
using namespace guestControl;
AutoCaller autoCaller(this);
/* Validate flags. */
if (aFlags != DirectoryCreateFlag_None)
{
if (!(aFlags & DirectoryCreateFlag_Parents))
{
}
}
try
{
/*
* Prepare tool command line.
*/
if (aMode > 0)
{
char szMode[16];
}
}
{
rc = E_OUTOFMEMORY;
}
return rc;
}
/**
* Creates a new directory handle ID and returns it. Returns VERR_TOO_MUCH_DATA
* if no free handles left, otherwise VINF_SUCCESS (or some other IPRT error).
*
* @return IPRT status code.
* @param puHandle Pointer where the handle gets stored to. Optional.
* @param uPID PID of guest process running the associated "vbox_ls".
* @param aDirectory Directory the handle is assigned to.
* @param aFilter Directory filter. Optional.
* @param uFlags Directory open flags.
*
*/
{
/* aFilter is optional. */
/* uFlags are optional. */
int rc = VERR_TOO_MUCH_DATA;
{
/* Create a new context ID ... */
{
rc = VINF_SUCCESS;
if (puHandle)
*puHandle = uHandleTry;
break;
}
}
return rc;
}
/**
* Destroys a previously created directory handle and its
* associated data.
*
* @return IPRT status code.
* @param uHandle Handle to destroy.
*/
{
{
/* Destroy raw guest stream buffer - not used
* anymore. */
/* Remove callback context (not used anymore). */
}
}
#if 0
STDMETHODIMP Guest::DirectoryExists(IN_BSTR aDirectory, IN_BSTR aUsername, IN_BSTR aPassword, BOOL *aExists)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
/* Do not allow anonymous executions (with system rights). */
return directoryExistsInternal(aDirectory,
#endif
}
#endif
#ifdef VBOX_WITH_GUEST_CONTROL
HRESULT Guest::directoryExistsInternal(IN_BSTR aDirectory, IN_BSTR aUsername, IN_BSTR aPassword, BOOL *aExists)
{
using namespace guestControl;
AutoCaller autoCaller(this);
int rc;
NULL /* No RTFSOBJINFO needed */,
{
switch (rc)
{
case VINF_SUCCESS:
break;
case VERR_FILE_NOT_FOUND:
break;
default:
break;
}
}
return hr;
}
#endif
/**
* Gets the associated PID from a directory handle.
*
* @param uHandle Directory handle to get PID for.
*/
{
return 0;
}
/**
* Returns the next directory entry of an open guest directory.
* Returns VERR_NO_DATA if no more entries available or VERR_NOT_FOUND
* if directory handle is invalid.
*
* @return IPRT status code.
* @param uHandle Directory handle to get entry for.
* @param streamBlock Reference that receives the next stream block data.
*/
{
// LOCK DOES NOT WORK HERE!?
//AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
{
#ifdef DEBUG
#endif
ProcessOutputFlag_None /* StdOut */,
}
return VERR_NOT_FOUND;
}
/**
* Checks whether a specified directory handle exists (is valid)
* or not.
*
* @return bool True if handle exists, false if not.
* @param uHandle Directory handle to check.
*/
{
return true;
return false;
}
#endif /* VBOX_WITH_GUEST_CONTROL */
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
/* Do not allow anonymous executions (with system rights). */
#endif
}
#ifdef VBOX_WITH_GUEST_CONTROL
{
using namespace guestControl;
AutoCaller autoCaller(this);
/* Validate flags. No flags supported yet. */
if (aFlags != DirectoryOpenFlag_None)
try
{
/*
* Prepare tool command line.
*/
/* We need to get output which is machine-readable in form
* of "key=value\0..key=value\0\0". */
/* We want the long output format. Handy for getting a lot of
* details we could (should?) use (later). */
/* As we want to keep this stuff simple we don't do recursive (-R)
* or dereferencing (--dereference) lookups here. This has to be done by
* the user. */
/* Construct and hand in actual directory name + filter we want to open. */
char *pszDirectoryFinal;
if (Utf8Filter.isEmpty())
else
if (!pszDirectoryFinal)
/* We only start the directory listing and requesting stdout data but don't get its
* data here; this is done in sequential IGuest::DirectoryRead calls then. */
{
/* Assign new directory handle ID. */
if (RT_SUCCESS(rc))
{
*aHandle = uHandleNew;
}
else
if (pRC)
}
}
{
hr = E_OUTOFMEMORY;
}
return hr;
}
int *pRC)
{
using namespace guestControl;
/** @todo Search directory cache first? */
/* aUsername is optional. */
/* aPassword is optional. */
/* aObjInfo is optional. */
AutoCaller autoCaller(this);
try
{
/*
* Prepare tool command line.
*/
/* We need to get output which is machine-readable in form
* of "key=value\0..key=value\0\0". */
/* Only the actual file name to chekc is needed for now. */
/*
* Execute guest process.
*/
hr = executeAndWaitForTool(Bstr(VBOXSERVICE_TOOL_STAT).raw(), Bstr("Querying directory information").raw(),
{
int rc = VINF_SUCCESS;
{
if (!pszFsType) /* Attribute missing? */
rc = VERR_NOT_FOUND;
if ( RT_SUCCESS(rc)
{
/* This is not critical for Main, so don't set hr --
* we will take care of rc then. */
}
if ( RT_SUCCESS(rc)
&& aObjInfo) /* Do we want object details? */
{
}
}
else
rc = VERR_NO_DATA;
if (pRC)
}
}
{
hr = E_OUTOFMEMORY;
}
return hr;
}
#endif /* VBOX_WITH_GUEST_CONTROL */
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else /* VBOX_WITH_GUEST_CONTROL */
using namespace guestControl;
AutoCaller autoCaller(this);
try
{
if (RT_SUCCESS(rc))
{
if (streamBlock.GetCount())
{
{
}
else
{
#ifdef DEBUG
streamBlock.Dump();
#endif
}
}
else
{
/* No more directory entries to read. That's fine. */
}
}
else
}
{
hr = E_OUTOFMEMORY;
}
return hr;
#endif
}