VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibSharedFolders.cpp@ 31013

Last change on this file since 31013 was 31013, checked in by vboxsync, 14 years ago

export to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: VBoxGuestR3LibSharedFolders.cpp 31013 2010-07-22 16:15:11Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, shared folders.
4 */
5
6/*
7 * Copyright (C) 2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/string.h>
32#include <iprt/mem.h>
33#include <iprt/assert.h>
34#include <iprt/cpp/autores.h>
35#include <iprt/stdarg.h>
36#include <VBox/log.h>
37#include <VBox/shflsvc.h> /** @todo File should be moved to VBox/HostServices/SharedFolderSvc.h */
38
39#include "VBGLR3Internal.h"
40
41/**
42 * Connects to the shared folder service.
43 *
44 * @returns VBox status code
45 * @param pu32ClientId Where to put the client id on success. The client id
46 * must be passed to all the other calls to the service.
47 */
48VBGLR3DECL(int) VbglR3SharedFolderConnect(uint32_t *pu32ClientId)
49{
50 VBoxGuestHGCMConnectInfo Info;
51 Info.result = VERR_WRONG_ORDER;
52 Info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
53 RT_ZERO(Info.Loc.u);
54 strcpy(Info.Loc.u.host.achName, "VBoxSharedFolders");
55 Info.u32ClientID = UINT32_MAX; /* try make valgrid shut up. */
56
57 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &Info, sizeof(Info));
58 if (RT_SUCCESS(rc))
59 {
60 rc = Info.result;
61 if (RT_SUCCESS(rc))
62 *pu32ClientId = Info.u32ClientID;
63 }
64 return rc;
65}
66
67
68/**
69 * Disconnect from the shared folder service.
70 *
71 * @returns VBox status code.
72 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
73 */
74VBGLR3DECL(int) VbglR3SharedFolderDisconnect(uint32_t u32ClientId)
75{
76 VBoxGuestHGCMDisconnectInfo Info;
77 Info.result = VERR_WRONG_ORDER;
78 Info.u32ClientID = u32ClientId;
79
80 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Info, sizeof(Info));
81 if (RT_SUCCESS(rc))
82 rc = Info.result;
83 return rc;
84}
85
86
87/**
88 * Get the list of available shared folders.
89 *
90 * @returns VBox status code.
91 * @param u32ClientId The client id returned by VbglR3InvsSvcConnect().
92 * @param bAutoMountOnly Flag whether only auto-mounted shared folders should be reported.
93 * @param paMappings Pointer to a preallocated array which will retrieve the mapping info.
94 * @param cbMappings Size (in bytes) of the provided array.
95 * @param pcMapCount Number of mappings returned.
96 */
97VBGLR3DECL(int) VbglR3SharedFolderGetMappings(uint32_t u32ClientId, bool bAutoMountOnly,
98 VBGLR3SHAREDFOLDERMAPPING paMappings[], uint32_t cbMappings,
99 uint32_t *pcMapCount)
100{
101 int rc;
102
103 AssertPtr(pcMapCount);
104
105 VBoxSFQueryMappings Msg;
106
107 Msg.callInfo.result = VERR_WRONG_ORDER;
108 Msg.callInfo.u32ClientID = u32ClientId;
109 Msg.callInfo.u32Function = SHFL_FN_QUERY_MAPPINGS;
110 Msg.callInfo.cParms = 3;
111
112 /* Set the mapping flags. */
113 uint32_t u32Flags = 0; /* @todo SHFL_MF_UTF8 is not implemented yet. */
114 if (bAutoMountOnly) /* We only want the mappings which get auto-mounted. */
115 u32Flags |= SHFL_MF_AUTOMOUNT;
116 VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
117
118 /* Init the rest of the message. */
119 VbglHGCMParmUInt32Set(&Msg.numberOfMappings, *pcMapCount);
120 VbglHGCMParmPtrSet(&Msg.mappings, &paMappings[0], cbMappings);
121
122 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
123 if (RT_SUCCESS(rc))
124 {
125 VbglHGCMParmUInt32Get(&Msg.numberOfMappings, pcMapCount);
126 rc = Msg.callInfo.result;
127 }
128 return rc;
129}
130
131
132/**
133 * Get the real name of a shared folder.
134 *
135 * @returns VBox status code.
136 * @param u32ClientId The client id returned by VbglR3InvsSvcConnect().
137 * @param u32Root Root ID of shared folder to get the name for.
138 * @param ppszName Name of the shared folder.
139 * @param pcbLen Length (in bytes) of shared folder name.
140 */
141VBGLR3DECL(int) VbglR3SharedFolderGetName(uint32_t u32ClientId, uint32_t u32Root,
142 char **ppszName, uint32_t *pcbLen)
143{
144 int rc;
145
146 AssertPtr(ppszName);
147 AssertPtr(pcbLen);
148
149 VBoxSFQueryMapName Msg;
150
151 Msg.callInfo.result = VERR_WRONG_ORDER;
152 Msg.callInfo.u32ClientID = u32ClientId;
153 Msg.callInfo.u32Function = SHFL_FN_QUERY_MAP_NAME;
154 Msg.callInfo.cParms = 2;
155
156 uint32_t cbString = sizeof(SHFLSTRING) + SHFL_MAX_LEN;
157 PSHFLSTRING pString = (PSHFLSTRING)RTMemAlloc(cbString);
158 if (pString)
159 {
160 RT_ZERO(*pString);
161 ShflStringInitBuffer(pString, SHFL_MAX_LEN);
162
163 VbglHGCMParmUInt32Set(&Msg.root, u32Root);
164 VbglHGCMParmPtrSet(&Msg.name, pString, cbString);
165
166 rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
167 if (RT_SUCCESS(rc))
168 {
169 *ppszName = NULL;
170 rc = RTUtf16ToUtf8Ex((PCRTUTF16)&pString->String.ucs2, RTSTR_MAX,
171 ppszName, (size_t)pcbLen, NULL);
172 if (RT_SUCCESS(rc))
173 rc = Msg.callInfo.result;
174 }
175 RTMemFree(pString);
176 }
177 else
178 rc = VERR_INVALID_PARAMETER;
179 return rc;
180}
181
Note: See TracBrowser for help on using the repository browser.

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