VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp@ 99073

Last change on this file since 99073 was 99073, checked in by vboxsync, 2 years ago

Guest Control/Main: Always dereference symlinks by default when opening directories, as we want to show its contents rather than working directly on the link.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 39.3 KB
Line 
1/* $Id: GuestDirectoryImpl.cpp 99073 2023-03-20 17:34:02Z vboxsync $ */
2/** @file
3 * VirtualBox Main - Guest directory handling.
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_MAIN_GUESTDIRECTORY
33#include "LoggingNew.h"
34
35#ifndef VBOX_WITH_GUEST_CONTROL
36# error "VBOX_WITH_GUEST_CONTROL must defined in this file"
37#endif
38#include "GuestImpl.h"
39#include "GuestDirectoryImpl.h"
40#include "GuestSessionImpl.h"
41#include "GuestCtrlImplPrivate.h"
42#include "VirtualBoxErrorInfoImpl.h"
43
44#include "Global.h"
45#include "AutoCaller.h"
46#include "VBoxEvents.h"
47
48#include <VBox/com/array.h>
49#include <VBox/com/listeners.h>
50#include <VBox/AssertGuest.h>
51
52
53/**
54 * Internal listener class to serve events in an
55 * active manner, e.g. without polling delays.
56 */
57class GuestDirectoryListener
58{
59public:
60
61 GuestDirectoryListener(void)
62 {
63 }
64
65 virtual ~GuestDirectoryListener()
66 {
67 }
68
69 HRESULT init(GuestDirectory *pDir)
70 {
71 AssertPtrReturn(pDir, E_POINTER);
72 mDir = pDir;
73 return S_OK;
74 }
75
76 void uninit(void)
77 {
78 mDir = NULL;
79 }
80
81 STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
82 {
83 switch (aType)
84 {
85 case VBoxEventType_OnGuestDirectoryStateChanged:
86 RT_FALL_THROUGH();
87 case VBoxEventType_OnGuestDirectoryRead:
88 {
89 AssertPtrReturn(mDir, E_POINTER);
90 int vrc2 = mDir->signalWaitEvent(aType, aEvent);
91 RT_NOREF(vrc2);
92#ifdef DEBUG_andy
93 LogFlowFunc(("Signalling events of type=%RU32, dir=%p resulted in vrc=%Rrc\n",
94 aType, mDir, vrc2));
95#endif
96 break;
97 }
98
99 default:
100 AssertMsgFailed(("Unhandled event %RU32\n", aType));
101 break;
102 }
103
104 return S_OK;
105 }
106
107private:
108
109 /** Weak pointer to the guest directory object to listen for. */
110 GuestDirectory *mDir;
111};
112typedef ListenerImpl<GuestDirectoryListener, GuestDirectory *> GuestDirectoryListenerImpl;
113
114VBOX_LISTENER_DECLARE(GuestDirectoryListenerImpl)
115
116// constructor / destructor
117/////////////////////////////////////////////////////////////////////////////
118
119DEFINE_EMPTY_CTOR_DTOR(GuestDirectory)
120
121HRESULT GuestDirectory::FinalConstruct(void)
122{
123 LogFlowThisFunc(("\n"));
124 return BaseFinalConstruct();
125}
126
127void GuestDirectory::FinalRelease(void)
128{
129 LogFlowThisFuncEnter();
130 uninit();
131 BaseFinalRelease();
132 LogFlowThisFuncLeave();
133}
134
135// public initializer/uninitializer for internal purposes only
136/////////////////////////////////////////////////////////////////////////////
137
138int GuestDirectory::init(Console *pConsole, GuestSession *pSession, ULONG aObjectID, const GuestDirectoryOpenInfo &openInfo)
139{
140 LogFlowThisFunc(("pConsole=%p, pSession=%p, aObjectID=%RU32, strPath=%s, enmFilter=%#x, fFlags=%x\n",
141 pConsole, pSession, aObjectID, openInfo.mPath.c_str(), openInfo.menmFilter, openInfo.mFlags));
142
143 AssertPtrReturn(pConsole, VERR_INVALID_POINTER);
144 AssertPtrReturn(pSession, VERR_INVALID_POINTER);
145
146 /* Enclose the state transition NotReady->InInit->Ready. */
147 AutoInitSpan autoInitSpan(this);
148 AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
149
150 int vrc = bindToSession(pConsole, pSession, aObjectID);
151 if (RT_SUCCESS(vrc))
152 {
153 mSession = pSession;
154 mObjectID = aObjectID;
155
156 mData.mOpenInfo = openInfo;
157 mData.mStatus = DirectoryStatus_Undefined;
158 mData.mLastError = VINF_SUCCESS;
159
160 unconst(mEventSource).createObject();
161 HRESULT hr = mEventSource->init();
162 if (FAILED(hr))
163 vrc = VERR_COM_UNEXPECTED;
164 }
165
166 if (RT_SUCCESS(vrc))
167 {
168 try
169 {
170 GuestDirectoryListener *pListener = new GuestDirectoryListener();
171 ComObjPtr<GuestDirectoryListenerImpl> thisListener;
172 HRESULT hr = thisListener.createObject();
173 if (SUCCEEDED(hr))
174 hr = thisListener->init(pListener, this);
175
176 if (SUCCEEDED(hr))
177 {
178 com::SafeArray <VBoxEventType_T> eventTypes;
179 eventTypes.push_back(VBoxEventType_OnGuestDirectoryStateChanged);
180 eventTypes.push_back(VBoxEventType_OnGuestDirectoryRead);
181 hr = mEventSource->RegisterListener(thisListener,
182 ComSafeArrayAsInParam(eventTypes),
183 TRUE /* Active listener */);
184 if (SUCCEEDED(hr))
185 {
186 vrc = baseInit();
187 if (RT_SUCCESS(vrc))
188 {
189 mLocalListener = thisListener;
190 }
191 }
192 else
193 vrc = VERR_COM_UNEXPECTED;
194 }
195 else
196 vrc = VERR_COM_UNEXPECTED;
197 }
198 catch(std::bad_alloc &)
199 {
200 vrc = VERR_NO_MEMORY;
201 }
202 }
203
204 /* Confirm a successful initialization when it's the case. */
205 if (RT_SUCCESS(vrc))
206 autoInitSpan.setSucceeded();
207 else
208 autoInitSpan.setFailed();
209
210 LogFlowFuncLeaveRC(vrc);
211 return vrc;
212}
213
214/**
215 * Uninitializes the instance.
216 * Called from FinalRelease().
217 */
218void GuestDirectory::uninit(void)
219{
220 LogFlowThisFuncEnter();
221
222 /* Enclose the state transition Ready->InUninit->NotReady. */
223 AutoUninitSpan autoUninitSpan(this);
224 if (autoUninitSpan.uninitDone())
225 return;
226
227 LogFlowThisFuncLeave();
228}
229
230// implementation of private wrapped getters/setters for attributes
231/////////////////////////////////////////////////////////////////////////////
232
233HRESULT GuestDirectory::getDirectoryName(com::Utf8Str &aDirectoryName)
234{
235 LogFlowThisFuncEnter();
236
237 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
238
239 aDirectoryName = mData.mOpenInfo.mPath;
240
241 return S_OK;
242}
243
244HRESULT GuestDirectory::getEventSource(ComPtr<IEventSource> &aEventSource)
245{
246 /* No need to lock - lifetime constant. */
247 mEventSource.queryInterfaceTo(aEventSource.asOutParam());
248
249 return S_OK;
250}
251
252HRESULT GuestDirectory::getFilter(com::Utf8Str &aFilter)
253{
254 LogFlowThisFuncEnter();
255
256 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
257
258 aFilter = mData.mOpenInfo.mFilter;
259
260 return S_OK;
261}
262
263HRESULT GuestDirectory::getId(ULONG *aId)
264{
265 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
266
267 *aId = mObjectID;
268
269 return S_OK;
270}
271
272HRESULT GuestDirectory::getStatus(DirectoryStatus_T *aStatus)
273{
274 LogFlowThisFuncEnter();
275
276 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
277
278 *aStatus = mData.mStatus;
279
280 return S_OK;
281}
282
283// private methods
284/////////////////////////////////////////////////////////////////////////////
285
286/**
287 * Entry point for guest side directory callbacks.
288 *
289 * @returns VBox status code.
290 * @param pCbCtx Host callback context.
291 * @param pSvcCb Host callback data.
292 */
293int GuestDirectory::i_callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
294{
295 AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
296 AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
297
298 LogFlowThisFunc(("strPath=%s, uContextID=%RU32, uMessage=%RU32, pSvcCb=%p\n",
299 mData.mOpenInfo.mPath.c_str(), pCbCtx->uContextID, pCbCtx->uMessage, pSvcCb));
300
301 int vrc;
302 switch (pCbCtx->uMessage)
303 {
304 case GUEST_MSG_DISCONNECTED:
305 /** @todo vrc = i_onGuestDisconnected(pCbCtx, pSvcCb); */
306 vrc = VINF_SUCCESS; /// @todo To be implemented
307 break;
308
309 case GUEST_MSG_DIR_NOTIFY:
310 {
311 vrc = i_onDirNotify(pCbCtx, pSvcCb);
312 break;
313 }
314
315 default:
316 /* Silently ignore not implemented functions. */
317 vrc = VERR_NOT_SUPPORTED;
318 break;
319 }
320
321 LogFlowFuncLeaveRC(vrc);
322 return vrc;
323}
324
325/**
326 * Opens the directory on the guest side.
327 *
328 * @return VBox status code.
329 * @param pvrcGuest Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
330 */
331int GuestDirectory::i_open(int *pvrcGuest)
332{
333 int vrc;
334#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
335 if ((mSession->i_getParent()->i_getGuestControlFeatures0() & VBOX_GUESTCTRL_GF_0_TOOLBOX_AS_CMDS))
336 {
337 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
338
339 GuestWaitEvent *pEvent = NULL;
340 GuestEventTypes eventTypes;
341 try
342 {
343 eventTypes.push_back(VBoxEventType_OnGuestDirectoryStateChanged);
344
345 vrc = registerWaitEvent(eventTypes, &pEvent);
346 }
347 catch (std::bad_alloc &)
348 {
349 vrc = VERR_NO_MEMORY;
350 }
351
352 if (RT_FAILURE(vrc))
353 return vrc;
354
355 /* Prepare HGCM call. */
356 VBOXHGCMSVCPARM paParms[8];
357 int i = 0;
358 HGCMSvcSetU32(&paParms[i++], pEvent->ContextID());
359 HGCMSvcSetStr(&paParms[i++], mData.mOpenInfo.mPath.c_str());
360 HGCMSvcSetU32(&paParms[i++], mData.mOpenInfo.menmFilter);
361 HGCMSvcSetU32(&paParms[i++], mData.mOpenInfo.mFlags);
362 HGCMSvcSetU32(&paParms[i++], GSTCTLFSOBJATTRADD_UNIX /* Implicit */);
363 HGCMSvcSetU32(&paParms[i++], GSTCTL_PATH_F_ON_LINK /* Ditto */ );
364
365 alock.release(); /* Drop lock before sending. */
366
367 vrc = sendMessage(HOST_MSG_DIR_OPEN, i, paParms);
368 if (RT_SUCCESS(vrc))
369 vrc = i_waitForStatusChange(pEvent, 30 * 1000, NULL /* FileStatus */, pvrcGuest);
370 }
371 else
372#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
373 {
374 vrc = i_openViaToolbox(pvrcGuest);
375 }
376
377 return vrc;
378}
379
380#ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT
381/**
382 * Opens the directory on the guest side (legacy version).
383 *
384 * @returns VBox status code.
385 * @param pvrcGuest Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
386 *
387 * @note This uses an own guest process via the built-in toolbox in VBoxSerivce.
388 */
389int GuestDirectory::i_openViaToolbox(int *pvrcGuest)
390{
391 /* Start the directory process on the guest. */
392 GuestProcessStartupInfo procInfo;
393 procInfo.mName.printf(tr("Opening directory \"%s\""), mData.mOpenInfo.mPath.c_str());
394 procInfo.mTimeoutMS = 5 * 60 * 1000; /* 5 minutes timeout. */
395 procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
396 procInfo.mExecutable= Utf8Str(VBOXSERVICE_TOOL_LS);
397
398 procInfo.mArguments.push_back(procInfo.mExecutable);
399 procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
400 /* We want the long output format which contains all the object details. */
401 procInfo.mArguments.push_back(Utf8Str("-l"));
402 /* Always dereference symlinks by default when opening directories, as we want to show its
403 * contents rather than working directly on the link.
404 *
405 * Newer Linux distros such as Ubuntu 22.10 symlink /bin to /usr/bin, for example. */
406 if (!(mData.mOpenInfo.mFlags & DirectoryOpenFlag_NoSymlinks)) /* Check if the caller explicitly forbids this. */
407 procInfo.mArguments.push_back(Utf8Str("--dereference"));
408 /** @todo Recursion support? */
409 procInfo.mArguments.push_back(mData.mOpenInfo.mPath); /* The directory we want to open. */
410
411 /*
412 * Start the process synchronously and keep it around so that we can use
413 * it later in subsequent read() calls.
414 */
415 int vrc = mData.mProcessTool.init(mSession, procInfo, false /*fAsync*/, NULL /*pvrcGuest*/);
416 if (RT_SUCCESS(vrc))
417 {
418 /* As we need to know if the directory we were about to open exists and and is accessible,
419 * do the first read here in order to return a meaningful status here. */
420 int vrcGuest = VERR_IPE_UNINITIALIZED_STATUS;
421 vrc = i_readInternal(mData.mObjData, &vrcGuest);
422 if (RT_FAILURE(vrc))
423 {
424 /*
425 * We need to actively terminate our process tool in case of an error here,
426 * as this otherwise would be done on (directory) object destruction implicitly.
427 * This in turn then will run into a timeout, as the directory object won't be
428 * around anymore at that time. Ugly, but that's how it is for the moment.
429 */
430 /* ignore rc */ mData.mProcessTool.terminate(30 * RT_MS_1SEC, NULL /* pvrcGuest */);
431 }
432
433 if (pvrcGuest)
434 *pvrcGuest = vrcGuest;
435 }
436
437 return vrc;
438}
439#endif /* VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT */
440
441/**
442 * Called when the guest side notifies the host of a directory event.
443 *
444 * @returns VBox status code.
445 * @param pCbCtx Host callback context.
446 * @param pSvcCbData Host callback data.
447 */
448int GuestDirectory::i_onDirNotify(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
449{
450#ifndef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
451 RT_NOREF(pCbCtx, pSvcCbData);
452 return VERR_NOT_SUPPORTED;
453#else
454 AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
455 AssertPtrReturn(pSvcCbData, VERR_INVALID_POINTER);
456
457 LogFlowThisFuncEnter();
458
459 if (pSvcCbData->mParms < 3)
460 return VERR_INVALID_PARAMETER;
461
462 int idx = 1; /* Current parameter index. */
463 CALLBACKDATA_DIR_NOTIFY dataCb;
464 RT_ZERO(dataCb);
465 /* pSvcCb->mpaParms[0] always contains the context ID. */
466 HGCMSvcGetU32(&pSvcCbData->mpaParms[idx++], &dataCb.uType);
467 HGCMSvcGetU32(&pSvcCbData->mpaParms[idx++], &dataCb.rc);
468
469 int vrcGuest = (int)dataCb.rc; /* uint32_t vs. int. */
470
471 LogFlowThisFunc(("uType=%RU32, vrcGuest=%Rrc\n", dataCb.uType, vrcGuest));
472
473 if (RT_FAILURE(vrcGuest))
474 {
475 /** @todo Set status? */
476
477 /* Ignore return code, as the event to signal might not be there (anymore). */
478 signalWaitEventInternal(pCbCtx, vrcGuest, NULL /* pPayload */);
479 return VINF_SUCCESS; /* Report to the guest. */
480 }
481
482 int vrc = VERR_NOT_SUPPORTED; /* Play safe by default. */
483
484 ComObjPtr<VirtualBoxErrorInfo> errorInfo;
485 HRESULT hrc = errorInfo.createObject();
486 ComAssertComRCRet(hrc, VERR_COM_UNEXPECTED);
487 if (RT_FAILURE(vrcGuest))
488 {
489 hrc = errorInfo->initEx(VBOX_E_GSTCTL_GUEST_ERROR, vrcGuest,
490 COM_IIDOF(IGuestDirectory), getComponentName(),
491 i_guestErrorToString(vrcGuest, mData.mOpenInfo.mPath.c_str()));
492 ComAssertComRCRet(hrc, VERR_COM_UNEXPECTED);
493 }
494
495 switch (dataCb.uType)
496 {
497 case GUEST_DIR_NOTIFYTYPE_ERROR:
498 {
499 vrc = i_setStatus(DirectoryStatus_Error, vrcGuest);
500 break;
501 }
502
503 case GUEST_DIR_NOTIFYTYPE_OPEN:
504 {
505 AssertBreakStmt(pSvcCbData->mParms >= 4, vrc = VERR_INVALID_PARAMETER);
506 vrc = HGCMSvcGetU32(&pSvcCbData->mpaParms[idx++], &dataCb.u.open.uHandle /* Guest native file handle */);
507 AssertRCBreak(vrc);
508 vrc = i_setStatus(DirectoryStatus_Open, vrcGuest);
509 break;
510 }
511
512 case GUEST_DIR_NOTIFYTYPE_CLOSE:
513 {
514 vrc = i_setStatus(DirectoryStatus_Close, vrcGuest);
515 break;
516 }
517
518 case GUEST_DIR_NOTIFYTYPE_READ:
519 {
520 ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mParms == 6, ("mParms=%u\n", pSvcCbData->mParms),
521 vrc = VERR_WRONG_PARAMETER_COUNT);
522 ASSERT_GUEST_MSG_STMT_BREAK(pSvcCbData->mpaParms[idx].type == VBOX_HGCM_SVC_PARM_PTR,
523 ("type=%u\n", pSvcCbData->mpaParms[idx].type),
524 vrc = VERR_WRONG_PARAMETER_TYPE);
525 PGSTCTLDIRENTRYEX pEntry;
526 uint32_t cbEntry;
527 vrc = HGCMSvcGetPv(&pSvcCbData->mpaParms[idx++], (void **)&pEntry, &cbEntry);
528 AssertRCBreak(vrc);
529 AssertBreakStmt( cbEntry >= RT_UOFFSETOF(GSTCTLDIRENTRYEX, szName[2])
530 && cbEntry <= GSTCTL_DIRENTRY_MAX_SIZE, VERR_INVALID_PARAMETER);
531 dataCb.u.read.pEntry = (PGSTCTLDIRENTRYEX)RTMemDup(pEntry, cbEntry);
532 AssertPtrBreakStmt(dataCb.u.read.pEntry, vrc = VERR_NO_MEMORY);
533 dataCb.u.read.cbEntry = cbEntry;
534
535 char *pszUser;
536 uint32_t cbUser;
537 vrc = HGCMSvcGetStr(&pSvcCbData->mpaParms[idx++], &pszUser, &cbUser);
538 AssertRCBreak(vrc);
539 dataCb.u.read.pszUser = RTStrDup(pszUser);
540 AssertPtrBreakStmt(dataCb.u.read.pszUser, vrc = VERR_NO_MEMORY);
541 dataCb.u.read.cbUser = cbUser;
542
543 char *pszGroups;
544 uint32_t cbGroups;
545 vrc = HGCMSvcGetStr(&pSvcCbData->mpaParms[idx++], &pszGroups, &cbGroups);
546 AssertRCBreak(vrc);
547 dataCb.u.read.pszGroups = RTStrDup(pszGroups);
548 AssertPtrBreakStmt(dataCb.u.read.pszGroups, vrc = VERR_NO_MEMORY);
549 dataCb.u.read.cbGroups = cbGroups;
550
551 /** @todo ACLs not implemented yet. */
552
553 GuestFsObjData fsObjData(dataCb.u.read.pEntry->szName);
554 vrc = fsObjData.FromGuestFsObjInfo(&dataCb.u.read.pEntry->Info);
555 AssertRCBreak(vrc);
556 ComObjPtr<GuestFsObjInfo> ptrFsObjInfo;
557 hrc = ptrFsObjInfo.createObject();
558 ComAssertComRCBreak(hrc, vrc = VERR_COM_UNEXPECTED);
559 vrc = ptrFsObjInfo->init(fsObjData);
560 AssertRCBreak(vrc);
561
562 ::FireGuestDirectoryReadEvent(mEventSource, mSession, this,
563 dataCb.u.read.pEntry->szName, ptrFsObjInfo, dataCb.u.read.pszUser, dataCb.u.read.pszGroups);
564 break;
565 }
566
567 case GUEST_DIR_NOTIFYTYPE_REWIND:
568 {
569 /* Note: This does not change the overall status of the directory (i.e. open). */
570 ::FireGuestDirectoryStateChangedEvent(mEventSource, mSession, this, DirectoryStatus_Rewind, errorInfo);
571 break;
572 }
573
574 default:
575 AssertFailed();
576 break;
577 }
578
579 try
580 {
581 if (RT_SUCCESS(vrc))
582 {
583 GuestWaitEventPayload payload(dataCb.uType, &dataCb, sizeof(dataCb));
584
585 /* Ignore return code, as the event to signal might not be there (anymore). */
586 signalWaitEventInternal(pCbCtx, vrcGuest, &payload);
587 }
588 else /* OOM situation, wrong HGCM parameters or smth. not expected. */
589 {
590 /* Ignore return code, as the event to signal might not be there (anymore). */
591 signalWaitEventInternalEx(pCbCtx, vrc, 0 /* guestRc */, NULL /* pPayload */);
592 }
593 }
594 catch (int vrcEx) /* Thrown by GuestWaitEventPayload constructor. */
595 {
596 /* Also try to signal the waiter, to let it know of the OOM situation.
597 * Ignore return code, as the event to signal might not be there (anymore). */
598 signalWaitEventInternalEx(pCbCtx, vrcEx, 0 /* guestRc */, NULL /* pPayload */);
599 vrc = vrcEx;
600 }
601
602 LogFlowThisFunc(("uType=%RU32, rcGuest=%Rrc, vrc=%Rrc\n", dataCb.uType, vrcGuest, vrc));
603 return vrc;
604#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
605}
606
607/**
608 * Converts a given guest directory error to a string.
609 *
610 * @returns Error string.
611 * @param vrcGuest Guest directory error to return string for.
612 * @param pcszWhat Hint of what was involved when the error occurred.
613 */
614/* static */
615Utf8Str GuestDirectory::i_guestErrorToString(int vrcGuest, const char *pcszWhat)
616{
617 AssertPtrReturn(pcszWhat, "");
618
619#define CASE_MSG(a_iRc, ...) \
620 case a_iRc: strErr.printf(__VA_ARGS__); break;
621
622 Utf8Str strErr;
623 switch (vrcGuest)
624 {
625 CASE_MSG(VERR_ACCESS_DENIED, tr("Access to guest directory \"%s\" is denied"), pcszWhat);
626 CASE_MSG(VERR_ALREADY_EXISTS, tr("Guest directory \"%s\" already exists"), pcszWhat);
627 CASE_MSG(VERR_CANT_CREATE, tr("Guest directory \"%s\" cannot be created"), pcszWhat);
628 CASE_MSG(VERR_DIR_NOT_EMPTY, tr("Guest directory \"%s\" is not empty"), pcszWhat);
629 default:
630 strErr.printf(tr("Error %Rrc for guest directory \"%s\" occurred\n"), vrcGuest, pcszWhat);
631 break;
632 }
633
634#undef CASE_MSG
635
636 return strErr;
637}
638
639/**
640 * @copydoc GuestObject::i_onUnregister
641 */
642int GuestDirectory::i_onUnregister(void)
643{
644 LogFlowThisFuncEnter();
645
646 int vrc = VINF_SUCCESS;
647
648 LogFlowFuncLeaveRC(vrc);
649 return vrc;
650}
651
652/**
653 * @copydoc GuestObject::i_onSessionStatusChange
654 */
655int GuestDirectory::i_onSessionStatusChange(GuestSessionStatus_T enmSessionStatus)
656{
657 RT_NOREF(enmSessionStatus);
658
659 LogFlowThisFuncEnter();
660
661 int vrc = VINF_SUCCESS;
662
663 LogFlowFuncLeaveRC(vrc);
664 return vrc;
665}
666
667/**
668 * Closes this guest directory and removes it from the
669 * guest session's directory list.
670 *
671 * @return VBox status code.
672 * @param pvrcGuest Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
673 */
674int GuestDirectory::i_close(int *pvrcGuest)
675{
676 int vrc;
677#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
678 if (mSession->i_getParent()->i_getGuestControlFeatures0() & VBOX_GUESTCTRL_GF_0_TOOLBOX_AS_CMDS)
679 {
680 GuestWaitEvent *pEvent = NULL;
681 GuestEventTypes eventTypes;
682 try
683 {
684 eventTypes.push_back(VBoxEventType_OnGuestDirectoryStateChanged);
685
686 vrc = registerWaitEvent(eventTypes, &pEvent);
687 }
688 catch (std::bad_alloc &)
689 {
690 vrc = VERR_NO_MEMORY;
691 }
692
693 if (RT_FAILURE(vrc))
694 return vrc;
695
696 /* Prepare HGCM call. */
697 VBOXHGCMSVCPARM paParms[2];
698 int i = 0;
699 HGCMSvcSetU32(&paParms[i++], pEvent->ContextID());
700 HGCMSvcSetU32(&paParms[i++], mObjectID /* Guest directory handle */);
701
702 vrc = sendMessage(HOST_MSG_DIR_CLOSE, i, paParms);
703 if (RT_SUCCESS(vrc))
704 {
705 vrc = pEvent->Wait(30 * 1000);
706 if (RT_SUCCESS(vrc))
707 {
708 // Nothing to do here.
709 }
710 else if (pEvent->HasGuestError() && pvrcGuest)
711 *pvrcGuest = pEvent->GuestResult();
712 }
713 }
714 else
715#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
716 {
717 vrc = i_closeViaToolbox(pvrcGuest);
718 }
719
720 AssertPtr(mSession);
721 int vrc2 = mSession->i_directoryUnregister(this);
722 if (RT_SUCCESS(vrc))
723 vrc = vrc2;
724
725 LogFlowThisFunc(("Returning vrc=%Rrc\n", vrc));
726 return vrc;
727}
728
729#ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT
730/**
731 * Closes this guest directory and removes it from the guest session's directory list (legacy version).
732 *
733 * @return VBox status code.
734 * @param pvrcGuest Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
735 *
736 * @note This uses an own guest process via the built-in toolbox in VBoxSerivce.
737 */
738int GuestDirectory::i_closeViaToolbox(int *pvrcGuest)
739{
740 return mData.mProcessTool.terminate(30 * 1000 /* 30s timeout */, pvrcGuest);
741}
742#endif /* VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT */
743
744/**
745 * Reads the next directory entry, internal version.
746 *
747 * @return VBox status code. Will return VERR_NO_MORE_FILES if no more entries are available.
748 * @param objData Where to store the read directory entry as internal object data.
749 * @param pvrcGuest Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
750 */
751int GuestDirectory::i_readInternal(GuestFsObjData &objData, int *pvrcGuest)
752{
753 AssertPtrReturn(pvrcGuest, VERR_INVALID_POINTER);
754
755 int vrc;
756
757#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
758 if (mSession->i_getParent()->i_getGuestControlFeatures0() & VBOX_GUESTCTRL_GF_0_TOOLBOX_AS_CMDS)
759 {
760 GuestWaitEvent *pEvent = NULL;
761 GuestEventTypes eventTypes;
762 try
763 {
764 vrc = registerWaitEvent(eventTypes, &pEvent);
765 }
766 catch (std::bad_alloc &)
767 {
768 vrc = VERR_NO_MEMORY;
769 }
770
771 if (RT_FAILURE(vrc))
772 return vrc;
773
774 /* Prepare HGCM call. */
775 VBOXHGCMSVCPARM paParms[4];
776 int i = 0;
777 HGCMSvcSetU32(&paParms[i++], pEvent->ContextID());
778 HGCMSvcSetU32(&paParms[i++], mObjectID /* Guest directory handle */);
779
780 vrc = sendMessage(HOST_MSG_DIR_READ, i, paParms);
781 if (RT_SUCCESS(vrc))
782 {
783 vrc = pEvent->Wait(30 * 1000);
784 if (RT_SUCCESS(vrc))
785 {
786 PCALLBACKDATA_DIR_NOTIFY const pDirNotify = (PCALLBACKDATA_DIR_NOTIFY)pEvent->Payload().Raw();
787 AssertPtrReturn(pDirNotify, VERR_INVALID_POINTER);
788 int vrcGuest = (int)pDirNotify->rc;
789 if (RT_SUCCESS(vrcGuest))
790 {
791 AssertReturn(pDirNotify->uType == GUEST_DIR_NOTIFYTYPE_READ, VERR_INVALID_PARAMETER);
792 AssertPtrReturn(pDirNotify->u.read.pEntry, VERR_INVALID_POINTER);
793 objData.Init(pDirNotify->u.read.pEntry->szName);
794 vrc = objData.FromGuestFsObjInfo(&pDirNotify->u.read.pEntry->Info,
795 pDirNotify->u.read.pszUser, pDirNotify->u.read.pszGroups);
796 RTMemFree(pDirNotify->u.read.pEntry);
797 RTStrFree(pDirNotify->u.read.pszUser);
798 RTStrFree(pDirNotify->u.read.pszGroups);
799 }
800 else
801 {
802 if (pvrcGuest)
803 *pvrcGuest = vrcGuest;
804 vrc = VERR_GSTCTL_GUEST_ERROR;
805 }
806 }
807 else if (pEvent->HasGuestError() && pvrcGuest)
808 *pvrcGuest = pEvent->GuestResult();
809 }
810 }
811 else
812#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
813 {
814 vrc = i_readInternalViaToolbox(objData, pvrcGuest);
815 }
816
817 LogFlowThisFunc(("Returning vrc=%Rrc\n", vrc));
818 return vrc;
819}
820
821#ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT
822/**
823 * Reads the next directory entry, internal version (legacy version).
824 *
825 * @return VBox status code. Will return VERR_NO_MORE_FILES if no more entries are available.
826 * @param objData Where to store the read directory entry as internal object data.
827 * @param pvrcGuest Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
828 *
829 * @note This uses an own guest process via the built-in toolbox in VBoxSerivce.
830 */
831int GuestDirectory::i_readInternalViaToolbox(GuestFsObjData &objData, int *pvrcGuest)
832{
833 GuestToolboxStreamBlock curBlock;
834 int vrc = mData.mProcessTool.waitEx(GUESTPROCESSTOOL_WAIT_FLAG_STDOUT_BLOCK, &curBlock, pvrcGuest);
835 if (RT_SUCCESS(vrc))
836 {
837 /*
838 * Note: The guest process can still be around to serve the next
839 * upcoming stream block next time.
840 */
841 if (!mData.mProcessTool.isRunning())
842 vrc = mData.mProcessTool.getTerminationStatus(); /* Tool process is not running (anymore). Check termination status. */
843
844 if (RT_SUCCESS(vrc))
845 {
846 if (curBlock.GetCount()) /* Did we get content? */
847 {
848 if (curBlock.GetString("name"))
849 {
850 vrc = objData.FromToolboxLs(curBlock, true /* fLong */);
851 }
852 else
853 vrc = VERR_PATH_NOT_FOUND;
854 }
855 else
856 {
857 /* Nothing to read anymore. Tell the caller. */
858 vrc = VERR_NO_MORE_FILES;
859 }
860 }
861 }
862
863 return vrc;
864}
865#endif /* VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT */
866
867/**
868 * Reads the next directory entry.
869 *
870 * @return VBox status code. Will return VERR_NO_MORE_FILES if no more entries are available.
871 * @param fsObjInfo Where to store the read directory entry.
872 * @param pvrcGuest Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
873 */
874int GuestDirectory::i_read(ComObjPtr<GuestFsObjInfo> &fsObjInfo, int *pvrcGuest)
875{
876 AssertPtrReturn(pvrcGuest, VERR_INVALID_POINTER);
877
878 /* Create the FS info object. */
879 HRESULT hr = fsObjInfo.createObject();
880 if (FAILED(hr))
881 return VERR_COM_UNEXPECTED;
882
883 int vrc;
884
885 /* If we have a valid object data cache, read from it. */
886 if (mData.mObjData.mName.isNotEmpty())
887 {
888 vrc = fsObjInfo->init(mData.mObjData);
889 if (RT_SUCCESS(vrc))
890 {
891 mData.mObjData.mName = ""; /* Mark the object data as being empty (beacon). */
892 }
893 }
894 else /* Otherwise ask the guest for the next object data. */
895 {
896
897 GuestFsObjData objData;
898 vrc = i_readInternal(objData, pvrcGuest);
899 if (RT_SUCCESS(vrc))
900 vrc = fsObjInfo->init(objData);
901 }
902
903 LogFlowThisFunc(("Returning vrc=%Rrc\n", vrc));
904 return vrc;
905}
906
907/**
908 * Rewinds the directory reading.
909 *
910 * @returns VBox status code.
911 * @retval VERR_GSTCTL_GUEST_ERROR when an error from the guest side has been received.
912 * @param uTimeoutMS Timeout (in ms) to wait.
913 * @param pvrcGuest Where to store the guest result code in case VERR_GSTCTL_GUEST_ERROR is returned.
914 */
915int GuestDirectory::i_rewind(uint32_t uTimeoutMS, int *pvrcGuest)
916{
917 RT_NOREF(pvrcGuest);
918#ifndef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
919 RT_NOREF(uTimeoutMS, pvrcGuest);
920#else
921 /* Only available for Guest Additions 7.1+. */
922 if (mSession->i_getParent()->i_getGuestControlFeatures0() & VBOX_GUESTCTRL_GF_0_TOOLBOX_AS_CMDS)
923 {
924 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
925
926 int vrc;
927
928 GuestWaitEvent *pEvent = NULL;
929 GuestEventTypes eventTypes;
930 try
931 {
932 eventTypes.push_back(VBoxEventType_OnGuestDirectoryStateChanged);
933 vrc = registerWaitEvent(eventTypes, &pEvent);
934 }
935 catch (std::bad_alloc &)
936 {
937 vrc = VERR_NO_MEMORY;
938 }
939
940 if (RT_FAILURE(vrc))
941 return vrc;
942
943 /* Prepare HGCM call. */
944 VBOXHGCMSVCPARM paParms[4];
945 int i = 0;
946 HGCMSvcSetU32(&paParms[i++], pEvent->ContextID());
947 HGCMSvcSetU32(&paParms[i++], mObjectID /* Directory handle */);
948
949 alock.release(); /* Drop lock before sending. */
950
951 vrc = sendMessage(HOST_MSG_DIR_REWIND, i, paParms);
952 if (RT_SUCCESS(vrc))
953 {
954 VBoxEventType_T evtType;
955 ComPtr<IEvent> pIEvent;
956 vrc = waitForEvent(pEvent, uTimeoutMS, &evtType, pIEvent.asOutParam());
957 if (RT_SUCCESS(vrc))
958 {
959 if (evtType == VBoxEventType_OnGuestDirectoryStateChanged)
960 {
961 ComPtr<IGuestDirectoryStateChangedEvent> pEvt = pIEvent;
962 Assert(!pEvt.isNull());
963 }
964 else
965 vrc = VWRN_GSTCTL_OBJECTSTATE_CHANGED;
966 }
967 else if (pEvent->HasGuestError()) /* Return guest vrc if available. */
968 vrc = pEvent->GuestResult();
969 }
970
971 unregisterWaitEvent(pEvent);
972 return vrc;
973 }
974#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
975
976 return VERR_NOT_SUPPORTED;
977}
978
979/**
980 * Sets the current internal directory object status.
981 *
982 * @returns VBox status code.
983 * @param enmStatus New directory status to set.
984 * @param vrcDir New result code to set.
985 *
986 * @note Takes the write lock.
987 */
988int GuestDirectory::i_setStatus(DirectoryStatus_T enmStatus, int vrcDir)
989{
990 LogFlowThisFuncEnter();
991
992 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
993
994 LogFlowThisFunc(("oldStatus=%RU32, newStatus=%RU32, vrcDir=%Rrc\n", mData.mStatus, enmStatus, vrcDir));
995
996#ifdef VBOX_STRICT
997 if (enmStatus == DirectoryStatus_Error)
998 AssertMsg(RT_FAILURE(vrcDir), ("Guest vrc must be an error (%Rrc)\n", vrcDir));
999 else
1000 AssertMsg(RT_SUCCESS(vrcDir), ("Guest vrc must not be an error (%Rrc)\n", vrcDir));
1001#endif
1002
1003 if (mData.mStatus != enmStatus)
1004 {
1005 mData.mStatus = enmStatus;
1006 mData.mLastError = vrcDir;
1007
1008 ComObjPtr<VirtualBoxErrorInfo> errorInfo;
1009 HRESULT hrc = errorInfo.createObject();
1010 ComAssertComRCRet(hrc, VERR_COM_UNEXPECTED);
1011 if (RT_FAILURE(vrcDir))
1012 {
1013 hrc = errorInfo->initEx(VBOX_E_GSTCTL_GUEST_ERROR, vrcDir,
1014 COM_IIDOF(IGuestDirectory), getComponentName(),
1015 i_guestErrorToString(vrcDir, mData.mOpenInfo.mPath.c_str()));
1016 ComAssertComRCRet(hrc, VERR_COM_UNEXPECTED);
1017 }
1018 /* Note: On vrcDir success, errorInfo is set to S_OK and also sent via the event below. */
1019
1020 alock.release(); /* Release lock before firing off event. */
1021
1022 ::FireGuestDirectoryStateChangedEvent(mEventSource, mSession, this, mData.mStatus, errorInfo);
1023 }
1024
1025 return VINF_SUCCESS;
1026}
1027
1028/**
1029 * Waits for a guest directory status change.
1030 *
1031 * @note Similar code in GuestFile::i_waitForStatusChange().
1032 *
1033 * @returns VBox status code.
1034 * @retval VERR_GSTCTL_GUEST_ERROR when an error from the guest side has been received.
1035 * @param pEvent Guest wait event to wait for.
1036 * @param uTimeoutMS Timeout (in ms) to wait.
1037 * @param penmStatus Where to return the directoy status on success.
1038 * @param prcGuest Where to return the guest error when VERR_GSTCTL_GUEST_ERROR was returned.
1039 */
1040int GuestDirectory::i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS,
1041 DirectoryStatus_T *penmStatus, int *prcGuest)
1042{
1043 AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
1044 /* penmStatus is optional. */
1045
1046 VBoxEventType_T evtType;
1047 ComPtr<IEvent> pIEvent;
1048 int vrc = waitForEvent(pEvent, uTimeoutMS, &evtType, pIEvent.asOutParam());
1049 if (RT_SUCCESS(vrc))
1050 {
1051 AssertReturn(evtType == VBoxEventType_OnGuestDirectoryStateChanged, VERR_WRONG_TYPE);
1052 ComPtr<IGuestDirectoryStateChangedEvent> pDirectoryEvent = pIEvent;
1053 AssertReturn(!pDirectoryEvent.isNull(), VERR_COM_UNEXPECTED);
1054
1055 HRESULT hr;
1056 if (penmStatus)
1057 {
1058 hr = pDirectoryEvent->COMGETTER(Status)(penmStatus);
1059 ComAssertComRC(hr);
1060 }
1061
1062 ComPtr<IVirtualBoxErrorInfo> errorInfo;
1063 hr = pDirectoryEvent->COMGETTER(Error)(errorInfo.asOutParam());
1064 ComAssertComRC(hr);
1065
1066 LONG lGuestRc;
1067 hr = errorInfo->COMGETTER(ResultDetail)(&lGuestRc);
1068 ComAssertComRC(hr);
1069
1070 LogFlowThisFunc(("resultDetail=%RI32 (%Rrc)\n", lGuestRc, lGuestRc));
1071
1072 if (RT_FAILURE((int)lGuestRc))
1073 vrc = VERR_GSTCTL_GUEST_ERROR;
1074
1075 if (prcGuest)
1076 *prcGuest = (int)lGuestRc;
1077 }
1078 /* waitForEvent may also return VERR_GSTCTL_GUEST_ERROR like we do above, so make prcGuest is set. */
1079 /** @todo Also see todo in GuestFile::i_waitForStatusChange(). */
1080 else if (vrc == VERR_GSTCTL_GUEST_ERROR && prcGuest)
1081 *prcGuest = pEvent->GuestResult();
1082 Assert(vrc != VERR_GSTCTL_GUEST_ERROR || !prcGuest || *prcGuest != (int)0xcccccccc);
1083
1084 return vrc;
1085}
1086
1087// implementation of public methods
1088/////////////////////////////////////////////////////////////////////////////
1089HRESULT GuestDirectory::close()
1090{
1091 AutoCaller autoCaller(this);
1092 if (FAILED(autoCaller.hrc())) return autoCaller.hrc();
1093
1094 LogFlowThisFuncEnter();
1095
1096 HRESULT hrc = S_OK;
1097
1098 int vrcGuest = VERR_IPE_UNINITIALIZED_STATUS;
1099 int vrc = i_close(&vrcGuest);
1100 if (RT_FAILURE(vrc))
1101 {
1102 switch (vrc)
1103 {
1104 case VERR_GSTCTL_GUEST_ERROR:
1105 {
1106 GuestErrorInfo ge(GuestErrorInfo::Type_Directory, vrcGuest, mData.mOpenInfo.mPath.c_str());
1107 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrcGuest, tr("Closing guest directory failed: %s"),
1108 GuestBase::getErrorAsString(ge).c_str());
1109 break;
1110 }
1111 case VERR_NOT_SUPPORTED:
1112 /* Silently skip old Guest Additions which do not support killing the
1113 * the guest directory handling process. */
1114 break;
1115
1116 default:
1117 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
1118 tr("Closing guest directory \"%s\" failed: %Rrc"), mData.mOpenInfo.mPath.c_str(), vrc);
1119 break;
1120 }
1121 }
1122
1123 return hrc;
1124}
1125
1126HRESULT GuestDirectory::read(ComPtr<IFsObjInfo> &aObjInfo)
1127{
1128 AutoCaller autoCaller(this);
1129 if (FAILED(autoCaller.hrc())) return autoCaller.hrc();
1130
1131 LogFlowThisFuncEnter();
1132
1133 HRESULT hrc = S_OK;
1134
1135 ComObjPtr<GuestFsObjInfo> fsObjInfo;
1136 int vrcGuest = VERR_IPE_UNINITIALIZED_STATUS;
1137 int vrc = i_read(fsObjInfo, &vrcGuest);
1138 if (RT_SUCCESS(vrc))
1139 {
1140 /* Return info object to the caller. */
1141 hrc = fsObjInfo.queryInterfaceTo(aObjInfo.asOutParam());
1142 }
1143 else
1144 {
1145 switch (vrc)
1146 {
1147 case VERR_GSTCTL_GUEST_ERROR:
1148 {
1149 GuestErrorInfo ge(
1150#ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT
1151 GuestErrorInfo::Type_ToolLs
1152#else
1153 GuestErrorInfo::Type_Fs
1154#endif
1155 , vrcGuest, mData.mOpenInfo.mPath.c_str());
1156 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrcGuest, tr("Reading guest directory failed: %s"),
1157 GuestBase::getErrorAsString(ge).c_str());
1158 break;
1159 }
1160
1161#ifdef VBOX_WITH_GSTCTL_TOOLBOX_SUPPORT
1162 case VERR_GSTCTL_PROCESS_EXIT_CODE:
1163 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Reading guest directory \"%s\" failed: %Rrc"),
1164 mData.mOpenInfo.mPath.c_str(), mData.mProcessTool.getRc());
1165 break;
1166#endif
1167 case VERR_PATH_NOT_FOUND:
1168 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Reading guest directory \"%s\" failed: Path not found"),
1169 mData.mOpenInfo.mPath.c_str());
1170 break;
1171
1172 case VERR_NO_MORE_FILES:
1173 /* See SDK reference. */
1174 hrc = setErrorBoth(VBOX_E_OBJECT_NOT_FOUND, vrc, tr("Reading guest directory \"%s\" failed: No more entries"),
1175 mData.mOpenInfo.mPath.c_str());
1176 break;
1177
1178 default:
1179 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Reading guest directory \"%s\" returned unhandled error: %Rrc\n"),
1180 mData.mOpenInfo.mPath.c_str(), vrc);
1181 break;
1182 }
1183 }
1184
1185 LogFlowThisFunc(("Returning hrc=%Rhrc / vrc=%Rrc\n", hrc, vrc));
1186 return hrc;
1187}
1188
1189HRESULT GuestDirectory::rewind(void)
1190{
1191 AutoCaller autoCaller(this);
1192 if (FAILED(autoCaller.hrc())) return autoCaller.hrc();
1193
1194 int vrcGuest = VERR_IPE_UNINITIALIZED_STATUS;
1195 int vrc = i_rewind(30 * 1000 /* Timeout in ms */, &vrcGuest);
1196 if (RT_SUCCESS(vrc))
1197 return S_OK;
1198
1199 GuestErrorInfo ge(GuestErrorInfo::Type_Directory, vrcGuest, mData.mOpenInfo.mPath.c_str());
1200 return setErrorBoth(VBOX_E_IPRT_ERROR, vrcGuest, tr("Rewinding guest directory failed: %s"),
1201 GuestBase::getErrorAsString(ge).c_str());
1202}
1203
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette