VirtualBox

source: vbox/trunk/src/VBox/Additions/os2/VBoxSF/VBoxSFInternal.h@ 76143

Last change on this file since 76143 was 76143, checked in by vboxsync, 6 years ago

SharedFolders,os2/VBoxSF: Added SHFL_FN_SET_FILE_SIZE for setting the file size without needing to passing an mostly unused buffer (SHFLOBJINFO). Deprecated most of VbglR0SfXxxx and continued hacking on replacements using OS/2 as testbed. bugref:9172

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 32.6 KB
Line 
1/** $Id: VBoxSFInternal.h 76143 2018-12-10 21:24:46Z vboxsync $ */
2/** @file
3 * VBoxSF - OS/2 Shared Folder IFS, Internal Header.
4 */
5
6/*
7 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31#ifndef ___VBoxSFInternal_h___
32#define ___VBoxSFInternal_h___
33
34
35#define INCL_BASE
36#define INCL_ERROR
37#define INCL_LONGLONG
38#define OS2EMX_PLAIN_CHAR
39#include <os2ddk/bsekee.h>
40#include <os2ddk/devhlp.h>
41#include <os2ddk/unikern.h>
42#include <os2ddk/fsd.h>
43#undef RT_MAX
44
45#include <iprt/types.h>
46#include <iprt/assert.h>
47#include <iprt/list.h>
48#include <VBox/VBoxGuestLibSharedFolders.h>
49#include <VBox/VBoxGuest.h>
50
51
52/** Allocation header used by RTMemAlloc.
53 * This should be subtracted from round numbers. */
54#define ALLOC_HDR_SIZE (0x10 + 4)
55
56
57/**
58 * A shared folder
59 */
60typedef struct VBOXSFFOLDER
61{
62 /** For the shared folder list. */
63 RTLISTNODE ListEntry;
64 /** Magic number (VBOXSFFOLDER_MAGIC). */
65 uint32_t u32Magic;
66 /** Number of active references to this folder. */
67 uint32_t volatile cRefs;
68 /** Number of open files referencing this folder. */
69 uint32_t volatile cOpenFiles;
70 /** Number of open searches referencing this folder. */
71 uint32_t volatile cOpenSearches;
72 /** Number of drives this is attached to. */
73 uint8_t volatile cDrives;
74
75 /** The host folder handle. */
76 VBGLSFMAP hHostFolder;
77
78 /** OS/2 volume handle. */
79 USHORT hVpb;
80
81 /** The length of the name and tag, including zero terminators and such. */
82 uint16_t cbNameAndTag;
83 /** The length of the folder name. */
84 uint8_t cchName;
85 /** The shared folder name. If there is a tag it follows as a second string. */
86 char szName[RT_FLEXIBLE_ARRAY];
87} VBOXSFFOLDER;
88/** Pointer to a shared folder. */
89typedef VBOXSFFOLDER *PVBOXSFFOLDER;
90/** Magic value for VBOXSFVP (Neal Town Stephenson). */
91#define VBOXSFFOLDER_MAGIC UINT32_C(0x19591031)
92
93/** The shared mutex protecting folders list, drives and the connection. */
94extern MutexLock_t g_MtxFolders;
95/** List of active folder (PVBOXSFFOLDER). */
96extern RTLISTANCHOR g_FolderHead;
97
98
99/**
100 * VBoxSF Volume Parameter Structure.
101 *
102 * @remarks Overlays the 36 byte VPFSD structure (fsd.h).
103 * @note No self pointer as the kernel may reallocate these.
104 */
105typedef struct VBOXSFVP
106{
107 /** Magic value (VBOXSFVP_MAGIC). */
108 uint32_t u32Magic;
109 /** The folder. */
110 PVBOXSFFOLDER pFolder;
111} VBOXSFVP;
112AssertCompile(sizeof(VBOXSFVP) <= sizeof(VPFSD));
113/** Pointer to a VBOXSFVP struct. */
114typedef VBOXSFVP *PVBOXSFVP;
115/** Magic value for VBOXSFVP (Laurence van Cott Niven). */
116#define VBOXSFVP_MAGIC UINT32_C(0x19380430)
117
118
119/**
120 * VBoxSF Current Directory Structure.
121 *
122 * @remark Overlays the 8 byte CDFSD structure (fsd.h).
123 */
124typedef struct VBOXSFCD
125{
126 uint32_t u32Dummy;
127} VBOXSFCD;
128AssertCompile(sizeof(VBOXSFCD) <= sizeof(CDFSD));
129/** Pointer to a VBOXSFCD struct. */
130typedef VBOXSFCD *PVBOXSFCD;
131
132
133/**
134 * VBoxSF System File Structure.
135 *
136 * @remark Overlays the 30 byte SFFSD structure (fsd.h).
137 */
138typedef struct VBOXSFSYFI
139{
140 /** Magic value (VBOXSFSYFI_MAGIC). */
141 uint32_t u32Magic;
142 /** Self pointer for quick 16:16 to flat translation. */
143 struct VBOXSFSYFI *pSelf;
144 /** The host file handle. */
145 SHFLHANDLE hHostFile;
146 /** The shared folder (referenced). */
147 PVBOXSFFOLDER pFolder;
148} VBOXSFSYFI;
149AssertCompile(sizeof(VBOXSFSYFI) <= sizeof(SFFSD));
150/** Pointer to a VBOXSFSYFI struct. */
151typedef VBOXSFSYFI *PVBOXSFSYFI;
152/** Magic value for VBOXSFSYFI (Jon Ellis Meacham). */
153#define VBOXSFSYFI_MAGIC UINT32_C(0x19690520)
154
155
156/**
157 * VBoxSF File Search Buffer (header).
158 */
159typedef struct VBOXSFFSBUF
160{
161 /** A magic number (VBOXSFFSBUF_MAGIC). */
162 uint32_t u32Magic;
163 /** Amount of buffer space allocated after this header. */
164 uint32_t cbBuf;
165 /** The filter string (full path), NULL if all files are request. */
166 PSHFLSTRING pFilter;
167 /** Must have attributes (shifted down DOS attributes). */
168 uint8_t fMustHaveAttribs;
169 /** Non-matching attributes (shifted down DOS attributes). */
170 uint8_t fExcludedAttribs;
171 /** Set if FF_ATTR_LONG_FILENAME. */
172 bool fLongFilenames : 1;
173 uint8_t bPadding1;
174 /** The local time offset to use for this search. */
175 int16_t cMinLocalTimeDelta;
176 uint8_t abPadding2[2];
177 /** Number of valid bytes in the buffer. */
178 uint32_t cbValid;
179 /** Number of entries left in the buffer. */
180 uint32_t cEntriesLeft;
181 /** The next entry. */
182 PSHFLDIRINFO pEntry;
183 /** Staging area for staging a full FILEFINDBUF4L (+ 32 safe bytes). */
184 uint8_t abStaging[RT_ALIGN_32(sizeof(FILEFINDBUF4L) + 32, 8)];
185} VBOXSFFSBUF;
186AssertCompileSizeAlignment(VBOXSFFSBUF, 8);
187/** Pointer to a file search buffer. */
188typedef VBOXSFFSBUF *PVBOXSFFSBUF;
189/** Magic number for VBOXSFFSBUF (Robert Anson Heinlein). */
190#define VBOXSFFSBUF_MAGIC UINT32_C(0x19070707)
191/** Minimum buffer size. */
192#define VBOXSFFSBUF_MIN_SIZE ( RT_ALIGN_32(sizeof(VBOXSFFSBUF) + sizeof(SHFLDIRINFO) + CCHMAXPATHCOMP * 4 + ALLOC_HDR_SIZE, 64) \
193 - ALLOC_HDR_SIZE)
194
195
196/**
197 * VBoxSF File Search Structure.
198 *
199 * @remark Overlays the 24 byte FSFSD structure (fsd.h).
200 * @note No self pointer as the kernel may reallocate these.
201 */
202typedef struct VBOXSFFS
203{
204 /** Magic value (VBOXSFFS_MAGIC). */
205 uint32_t u32Magic;
206 /** The last file position position. */
207 uint32_t offLastFile;
208 /** The host directory handle. */
209 SHFLHANDLE hHostDir;
210 /** The shared folder (referenced). */
211 PVBOXSFFOLDER pFolder;
212 /** Search data buffer. */
213 PVBOXSFFSBUF pBuf;
214} VBOXSFFS;
215AssertCompile(sizeof(VBOXSFFS) <= sizeof(FSFSD));
216/** Pointer to a VBOXSFFS struct. */
217typedef VBOXSFFS *PVBOXSFFS;
218/** Magic number for VBOXSFFS (Isaak Azimov). */
219#define VBOXSFFS_MAGIC UINT32_C(0x19200102)
220
221
222extern VBGLSFCLIENT g_SfClient;
223
224PSHFLSTRING vboxSfOs2StrAlloc(size_t cwcLength);
225PSHFLSTRING vboxSfOs2StrDup(PCSHFLSTRING pSrc);
226void vboxSfOs2StrFree(PSHFLSTRING pStr);
227
228APIRET vboxSfOs2ResolvePath(const char *pszPath, PVBOXSFCD pCdFsd, LONG offCurDirEnd,
229 PVBOXSFFOLDER *ppFolder, PSHFLSTRING *ppStrFolderPath);
230APIRET vboxSfOs2ResolvePathEx(const char *pszPath, PVBOXSFCD pCdFsd, LONG offCurDirEnd, uint32_t offStrInBuf,
231 PVBOXSFFOLDER *ppFolder, void **ppvBuf);
232void vboxSfOs2ReleasePathAndFolder(PSHFLSTRING pStrPath, PVBOXSFFOLDER pFolder);
233void vboxSfOs2ReleaseFolder(PVBOXSFFOLDER pFolder);
234APIRET vboxSfOs2ConvertStatusToOs2(int vrc, APIRET rcDefault);
235int16_t vboxSfOs2GetLocalTimeDelta(void);
236void vboxSfOs2DateTimeFromTimeSpec(FDATE *pDosDate, FTIME *pDosTime, RTTIMESPEC SrcTimeSpec, int16_t cMinLocalTimeDelta);
237PRTTIMESPEC vboxSfOs2DateTimeToTimeSpec(FDATE DosDate, FTIME DosTime, int16_t cMinLocalTimeDelta, PRTTIMESPEC pDstTimeSpec);
238APIRET vboxSfOs2FileStatusFromObjInfo(PBYTE pbDst, ULONG cbDst, ULONG uLevel, SHFLFSOBJINFO const *pSrc);
239APIRET vboxSfOs2SetInfoCommonWorker(PVBOXSFFOLDER pFolder, SHFLHANDLE hHostFile, ULONG fAttribs,
240 PFILESTATUS pTimestamps, PSHFLFSOBJINFO pObjInfoBuf, uint32_t offObjInfoInAlloc);
241APIRET vboxSfOs2MakeEmptyEaList(PEAOP pEaOp, ULONG uLevel);
242APIRET vboxSfOs2MakeEmptyEaListEx(PEAOP pEaOp, ULONG uLevel, uint32_t *pcbWritten, ULONG *poffError);
243
244DECLASM(PVBOXSFVP) Fsh32GetVolParams(USHORT hVbp, PVPFSI *ppVpFsi /*optional*/);
245
246
247/** @name Host request helpers
248 *
249 * @todo generalize these and put back into VbglR0Sf.
250 *
251 * @{ */
252
253
254/** Request structure for vboxSfOs2HostReqMapFolderWithBuf. */
255typedef struct VBOXSFMAPFOLDERWITHBUFREQ
256{
257 VBGLIOCIDCHGCMFASTCALL Hdr;
258 VMMDevHGCMCall Call;
259 VBoxSFParmMapFolder Parms;
260 union
261 {
262 HGCMPageListInfo PgLst;
263 uint8_t abPadding[8 + sizeof(RTGCPHYS64) * 2 /*RT_UOFFSETOF(HGCMPageListInfo, aPages[2])*/];
264 } u;
265} VBOXSFMAPFOLDERWITHBUFREQ;
266
267/**
268 * SHFL_FN_MAP_FOLDER request.
269 */
270DECLINLINE(int) vboxSfOs2HostReqMapFolderWithBuf(VBOXSFMAPFOLDERWITHBUFREQ *pReq, PSHFLSTRING pStrName,
271 RTUTF16 wcDelimiter, bool fCaseSensitive)
272{
273 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
274 pReq->Parms.id32Root.u.value32 = SHFL_ROOT_NIL;
275
276 pReq->Parms.uc32Delimiter.type = VMMDevHGCMParmType_32bit;
277 pReq->Parms.uc32Delimiter.u.value32 = wcDelimiter;
278
279 pReq->Parms.fCaseSensitive.type = VMMDevHGCMParmType_32bit;
280 pReq->Parms.fCaseSensitive.u.value32 = fCaseSensitive;
281
282 AssertReturn(pStrName->u16Size <= PAGE_SIZE - SHFLSTRING_HEADER_SIZE, VERR_FILENAME_TOO_LONG);
283 pReq->Parms.pStrName.type = VMMDevHGCMParmType_PageList;
284 pReq->Parms.pStrName.u.PageList.size = SHFLSTRING_HEADER_SIZE + pStrName->u16Size;
285 pReq->Parms.pStrName.u.PageList.offset = RT_UOFFSETOF(VBOXSFMAPFOLDERWITHBUFREQ, u.PgLst) - sizeof(VBGLIOCIDCHGCMFASTCALL);
286 pReq->u.PgLst.flags = VBOX_HGCM_F_PARM_DIRECTION_BOTH;
287 pReq->u.PgLst.aPages[0] = VbglR0PhysHeapGetPhysAddr(pStrName);
288 pReq->u.PgLst.offFirstPage = (uint16_t)(pReq->u.PgLst.aPages[0] & PAGE_OFFSET_MASK);
289 pReq->u.PgLst.aPages[0] &= ~(RTGCPHYS)PAGE_OFFSET_MASK;
290 uint32_t cbReq;
291 if (PAGE_SIZE - pReq->u.PgLst.offFirstPage <= pStrName->u16Size + SHFLSTRING_HEADER_SIZE)
292 {
293 pReq->u.PgLst.cPages = 1;
294 cbReq = RT_UOFFSETOF(VBOXSFMAPFOLDERWITHBUFREQ, u.PgLst.aPages[1]);
295 }
296 else
297 {
298 pReq->u.PgLst.aPages[1] = pReq->u.PgLst.aPages[0] + PAGE_SIZE;
299 pReq->u.PgLst.cPages = 2;
300 cbReq = RT_UOFFSETOF(VBOXSFMAPFOLDERWITHBUFREQ, u.PgLst.aPages[2]);
301 }
302
303 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
304 SHFL_FN_MAP_FOLDER, SHFL_CPARMS_MAP_FOLDER, cbReq);
305
306 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, cbReq);
307 if (RT_SUCCESS(vrc))
308 vrc = pReq->Call.header.result;
309 return vrc;
310}
311
312
313
314/** Request structure used by vboxSfOs2HostReqUnmapFolder. */
315typedef struct VBOXSFUNMAPFOLDERREQ
316{
317 VBGLIOCIDCHGCMFASTCALL Hdr;
318 VMMDevHGCMCall Call;
319 VBoxSFParmUnmapFolder Parms;
320} VBOXSFUNMAPFOLDERREQ;
321
322
323/**
324 * SHFL_FN_UNMAP_FOLDER request.
325 */
326DECLINLINE(int) vboxSfOs2HostReqUnmapFolderSimple(uint32_t idRoot)
327{
328 VBOXSFUNMAPFOLDERREQ *pReq = (VBOXSFUNMAPFOLDERREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
329 if (pReq)
330 {
331 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
332 pReq->Parms.id32Root.u.value32 = idRoot;
333
334 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
335 SHFL_FN_UNMAP_FOLDER, SHFL_CPARMS_UNMAP_FOLDER, sizeof(*pReq));
336
337 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
338 if (RT_SUCCESS(vrc))
339 vrc = pReq->Call.header.result;
340
341 VbglR0PhysHeapFree(pReq);
342 return vrc;
343 }
344 return VERR_NO_MEMORY;
345}
346
347
348/** Request structure for vboxSfOs2HostReqCreate. */
349typedef struct VBOXSFCREATEREQ
350{
351 VBGLIOCIDCHGCMFASTCALL Hdr;
352 VMMDevHGCMCall Call;
353 VBoxSFParmCreate Parms;
354 SHFLCREATEPARMS CreateParms;
355 SHFLSTRING StrPath;
356} VBOXSFCREATEREQ;
357
358/**
359 * SHFL_FN_CREATE request.
360 */
361DECLINLINE(int) vboxSfOs2HostReqCreate(PVBOXSFFOLDER pFolder, VBOXSFCREATEREQ *pReq)
362{
363 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
364 SHFL_FN_CREATE, SHFL_CPARMS_CREATE,
365 RT_UOFFSETOF(VBOXSFCREATEREQ, StrPath.String) + pReq->StrPath.u16Size);
366
367 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
368 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
369
370 pReq->Parms.pStrPath.type = VMMDevHGCMParmType_Embedded;
371 pReq->Parms.pStrPath.u.Embedded.cbData = SHFLSTRING_HEADER_SIZE + pReq->StrPath.u16Size;
372 pReq->Parms.pStrPath.u.Embedded.offData = RT_UOFFSETOF(VBOXSFCREATEREQ, StrPath) - sizeof(VBGLIOCIDCHGCMFASTCALL);
373 pReq->Parms.pStrPath.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
374
375 pReq->Parms.pCreateParms.type = VMMDevHGCMParmType_Embedded;
376 pReq->Parms.pCreateParms.u.Embedded.cbData = sizeof(pReq->CreateParms);
377 pReq->Parms.pCreateParms.u.Embedded.offData = RT_UOFFSETOF(VBOXSFCREATEREQ, CreateParms) - sizeof(VBGLIOCIDCHGCMFASTCALL);
378 pReq->Parms.pCreateParms.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_BOTH;
379
380 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr,
381 RT_UOFFSETOF(VBOXSFCREATEREQ, StrPath.String) + pReq->StrPath.u16Size);
382 if (RT_SUCCESS(vrc))
383 vrc = pReq->Call.header.result;
384 return vrc;
385}
386
387
388/** Request structure for vboxSfOs2HostReqClose. */
389typedef struct VBOXSFCLOSEREQ
390{
391 VBGLIOCIDCHGCMFASTCALL Hdr;
392 VMMDevHGCMCall Call;
393 VBoxSFParmClose Parms;
394} VBOXSFCLOSEREQ;
395
396/**
397 * SHFL_FN_CLOSE request.
398 */
399DECLINLINE(int) vboxSfOs2HostReqClose(PVBOXSFFOLDER pFolder, VBOXSFCLOSEREQ *pReq, uint64_t hHostFile)
400{
401 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
402 SHFL_FN_CLOSE, SHFL_CPARMS_CLOSE, sizeof(*pReq));
403
404 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
405 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
406
407 pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
408 pReq->Parms.u64Handle.u.value64 = hHostFile;
409
410 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
411 if (RT_SUCCESS(vrc))
412 vrc = pReq->Call.header.result;
413 return vrc;
414}
415
416/**
417 * SHFL_FN_CLOSE request, allocate request buffer.
418 */
419DECLINLINE(int) vboxSfOs2HostReqCloseSimple(PVBOXSFFOLDER pFolder, uint64_t hHostFile)
420{
421 VBOXSFCLOSEREQ *pReq = (VBOXSFCLOSEREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
422 if (pReq)
423 {
424 int vrc = vboxSfOs2HostReqClose(pFolder, pReq, hHostFile);
425 VbglR0PhysHeapFree(pReq);
426 return vrc;
427 }
428 return VERR_NO_MEMORY;
429}
430
431
432/** Request structure for vboxSfOs2HostReqQueryVolInfo. */
433typedef struct VBOXSFVOLINFOREQ
434{
435 VBGLIOCIDCHGCMFASTCALL Hdr;
436 VMMDevHGCMCall Call;
437 VBoxSFParmInformation Parms;
438 SHFLVOLINFO VolInfo;
439} VBOXSFVOLINFOREQ;
440
441/**
442 * SHFL_FN_INFORMATION[SHFL_INFO_VOLUME | SHFL_INFO_GET] request.
443 */
444DECLINLINE(int) vboxSfOs2HostReqQueryVolInfo(PVBOXSFFOLDER pFolder, VBOXSFVOLINFOREQ *pReq, uint64_t hHostFile)
445{
446 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
447 SHFL_FN_INFORMATION, SHFL_CPARMS_INFORMATION, sizeof(*pReq));
448
449 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
450 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
451
452 pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
453 pReq->Parms.u64Handle.u.value64 = hHostFile;
454
455 pReq->Parms.f32Flags.type = VMMDevHGCMParmType_32bit;
456 pReq->Parms.f32Flags.u.value32 = SHFL_INFO_VOLUME | SHFL_INFO_GET;
457
458 pReq->Parms.cb32.type = VMMDevHGCMParmType_32bit;
459 pReq->Parms.cb32.u.value32 = sizeof(pReq->VolInfo);
460
461 pReq->Parms.pInfo.type = VMMDevHGCMParmType_Embedded;
462 pReq->Parms.pInfo.u.Embedded.cbData = sizeof(pReq->VolInfo);
463 pReq->Parms.pInfo.u.Embedded.offData = RT_UOFFSETOF(VBOXSFVOLINFOREQ, VolInfo) - sizeof(VBGLIOCIDCHGCMFASTCALL);
464 pReq->Parms.pInfo.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_FROM_HOST;
465
466 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
467 if (RT_SUCCESS(vrc))
468 vrc = pReq->Call.header.result;
469 return vrc;
470}
471
472
473/** Request structure for vboxSfOs2HostReqSetObjInfo & vboxSfOs2HostReqQueryObjInfo. */
474typedef struct VBOXSFOBJINFOREQ
475{
476 VBGLIOCIDCHGCMFASTCALL Hdr;
477 VMMDevHGCMCall Call;
478 VBoxSFParmInformation Parms;
479 SHFLFSOBJINFO ObjInfo;
480} VBOXSFOBJINFOREQ;
481
482/**
483 * SHFL_FN_INFORMATION[SHFL_INFO_GET | SHFL_INFO_FILE] request.
484 */
485DECLINLINE(int) vboxSfOs2HostReqQueryObjInfo(PVBOXSFFOLDER pFolder, VBOXSFOBJINFOREQ *pReq, uint64_t hHostFile)
486{
487 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
488 SHFL_FN_INFORMATION, SHFL_CPARMS_INFORMATION, sizeof(*pReq));
489
490 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
491 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
492
493 pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
494 pReq->Parms.u64Handle.u.value64 = hHostFile;
495
496 pReq->Parms.f32Flags.type = VMMDevHGCMParmType_32bit;
497 pReq->Parms.f32Flags.u.value32 = SHFL_INFO_GET | SHFL_INFO_FILE;
498
499 pReq->Parms.cb32.type = VMMDevHGCMParmType_32bit;
500 pReq->Parms.cb32.u.value32 = sizeof(pReq->ObjInfo);
501
502 pReq->Parms.pInfo.type = VMMDevHGCMParmType_Embedded;
503 pReq->Parms.pInfo.u.Embedded.cbData = sizeof(pReq->ObjInfo);
504 pReq->Parms.pInfo.u.Embedded.offData = RT_UOFFSETOF(VBOXSFOBJINFOREQ, ObjInfo) - sizeof(VBGLIOCIDCHGCMFASTCALL);
505 pReq->Parms.pInfo.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_FROM_HOST;
506
507 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
508 if (RT_SUCCESS(vrc))
509 vrc = pReq->Call.header.result;
510 return vrc;
511}
512
513
514/**
515 * SHFL_FN_INFORMATION[SHFL_INFO_SET | SHFL_INFO_FILE] request.
516 */
517DECLINLINE(int) vboxSfOs2HostReqSetObjInfo(PVBOXSFFOLDER pFolder, VBOXSFOBJINFOREQ *pReq, uint64_t hHostFile)
518{
519 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
520 SHFL_FN_INFORMATION, SHFL_CPARMS_INFORMATION, sizeof(*pReq));
521
522 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
523 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
524
525 pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
526 pReq->Parms.u64Handle.u.value64 = hHostFile;
527
528 pReq->Parms.f32Flags.type = VMMDevHGCMParmType_32bit;
529 pReq->Parms.f32Flags.u.value32 = SHFL_INFO_SET | SHFL_INFO_FILE;
530
531 pReq->Parms.cb32.type = VMMDevHGCMParmType_32bit;
532 pReq->Parms.cb32.u.value32 = sizeof(pReq->ObjInfo);
533
534 pReq->Parms.pInfo.type = VMMDevHGCMParmType_Embedded;
535 pReq->Parms.pInfo.u.Embedded.cbData = sizeof(pReq->ObjInfo);
536 pReq->Parms.pInfo.u.Embedded.offData = RT_UOFFSETOF(VBOXSFOBJINFOREQ, ObjInfo) - sizeof(VBGLIOCIDCHGCMFASTCALL);
537 pReq->Parms.pInfo.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_BOTH;
538
539 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
540 if (RT_SUCCESS(vrc))
541 vrc = pReq->Call.header.result;
542 return vrc;
543}
544
545
546/** Request structure for vboxSfOs2HostReqSetObjInfo. */
547typedef struct VBOXSFOBJINFOWITHBUFREQ
548{
549 VBGLIOCIDCHGCMFASTCALL Hdr;
550 VMMDevHGCMCall Call;
551 VBoxSFParmInformation Parms;
552 union
553 {
554 HGCMPageListInfo PgLst;
555 uint8_t abPadding[8 + sizeof(RTGCPHYS64) * 2 /*RT_UOFFSETOF(HGCMPageListInfo, aPages[2])*/];
556 } u;
557} VBOXSFOBJINFOWITHBUFREQ;
558
559/**
560 * SHFL_FN_INFORMATION[SHFL_INFO_SET | SHFL_INFO_FILE] request, with separate
561 * buffer (on the physical heap).
562 */
563DECLINLINE(int) vboxSfOs2HostReqSetObjInfoWithBuf(PVBOXSFFOLDER pFolder, VBOXSFOBJINFOWITHBUFREQ *pReq, uint64_t hHostFile,
564 PSHFLFSOBJINFO pObjInfo, uint32_t offObjInfoInAlloc)
565{
566 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
567 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
568
569 pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
570 pReq->Parms.u64Handle.u.value64 = hHostFile;
571
572 pReq->Parms.f32Flags.type = VMMDevHGCMParmType_32bit;
573 pReq->Parms.f32Flags.u.value32 = SHFL_INFO_SET | SHFL_INFO_FILE;
574
575 pReq->Parms.cb32.type = VMMDevHGCMParmType_32bit;
576 pReq->Parms.cb32.u.value32 = sizeof(*pObjInfo);
577
578 pReq->Parms.pInfo.type = VMMDevHGCMParmType_PageList;
579 pReq->Parms.pInfo.u.PageList.size = sizeof(*pObjInfo);
580 pReq->Parms.pInfo.u.PageList.offset = RT_UOFFSETOF(VBOXSFOBJINFOREQ, ObjInfo) - sizeof(VBGLIOCIDCHGCMFASTCALL);
581 pReq->u.PgLst.flags = VBOX_HGCM_F_PARM_DIRECTION_BOTH;
582 pReq->u.PgLst.aPages[0] = VbglR0PhysHeapGetPhysAddr((uint8_t *)pObjInfo - offObjInfoInAlloc) + offObjInfoInAlloc;
583 pReq->u.PgLst.offFirstPage = (uint16_t)(pReq->u.PgLst.aPages[0] & PAGE_OFFSET_MASK);
584 pReq->u.PgLst.aPages[0] &= ~(RTGCPHYS)PAGE_OFFSET_MASK;
585 uint32_t cbReq;
586 if (PAGE_SIZE - pReq->u.PgLst.offFirstPage <= sizeof(*pObjInfo))
587 {
588 pReq->u.PgLst.cPages = 1;
589 cbReq = RT_UOFFSETOF(VBOXSFOBJINFOWITHBUFREQ, u.PgLst.aPages[1]);
590 }
591 else
592 {
593 pReq->u.PgLst.aPages[1] = pReq->u.PgLst.aPages[0] + PAGE_SIZE;
594 pReq->u.PgLst.cPages = 2;
595 cbReq = RT_UOFFSETOF(VBOXSFOBJINFOWITHBUFREQ, u.PgLst.aPages[2]);
596 }
597
598 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
599 SHFL_FN_INFORMATION, SHFL_CPARMS_INFORMATION, cbReq);
600
601 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, cbReq);
602 if (RT_SUCCESS(vrc))
603 vrc = pReq->Call.header.result;
604 return vrc;
605}
606
607
608/** Request structure for vboxSfOs2HostReqRemove. */
609typedef struct VBOXSFREMOVEREQ
610{
611 VBGLIOCIDCHGCMFASTCALL Hdr;
612 VMMDevHGCMCall Call;
613 VBoxSFParmRemove Parms;
614 SHFLSTRING StrPath;
615} VBOXSFREMOVEREQ;
616
617/**
618 * SHFL_FN_REMOVE request.
619 */
620DECLINLINE(int) vboxSfOs2HostReqRemove(PVBOXSFFOLDER pFolder, VBOXSFREMOVEREQ *pReq, uint32_t fFlags)
621{
622 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
623 SHFL_FN_REMOVE, SHFL_CPARMS_REMOVE,
624 RT_UOFFSETOF(VBOXSFREMOVEREQ, StrPath.String) + pReq->StrPath.u16Size);
625
626 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
627 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
628
629 pReq->Parms.pStrPath.type = VMMDevHGCMParmType_Embedded;
630 pReq->Parms.pStrPath.u.Embedded.cbData = SHFLSTRING_HEADER_SIZE + pReq->StrPath.u16Size;
631 pReq->Parms.pStrPath.u.Embedded.offData = RT_UOFFSETOF(VBOXSFREMOVEREQ, StrPath) - sizeof(VBGLIOCIDCHGCMFASTCALL);
632 pReq->Parms.pStrPath.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
633
634 pReq->Parms.f32Flags.type = VMMDevHGCMParmType_32bit;
635 pReq->Parms.f32Flags.u.value32 = fFlags;
636
637 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr,
638 RT_UOFFSETOF(VBOXSFREMOVEREQ, StrPath.String) + pReq->StrPath.u16Size);
639 if (RT_SUCCESS(vrc))
640 vrc = pReq->Call.header.result;
641 return vrc;
642}
643
644
645/** Request structure for vboxSfOs2HostReqRename. */
646typedef struct VBOXSFRENAMEWITHSRCBUFREQ
647{
648 VBGLIOCIDCHGCMFASTCALL Hdr;
649 VMMDevHGCMCall Call;
650 VBoxSFParmRename Parms;
651 union
652 {
653 HGCMPageListInfo PgLst;
654 uint8_t abPadding[8 + sizeof(RTGCPHYS64) * 2 /*RT_UOFFSETOF(HGCMPageListInfo, aPages[2])*/];
655 } u;
656 SHFLSTRING StrDstPath;
657} VBOXSFRENAMEWITHSRCBUFREQ;
658
659/**
660 * SHFL_FN_REMOVE request.
661 */
662DECLINLINE(int) vboxSfOs2HostReqRenameWithSrcBuf(PVBOXSFFOLDER pFolder, VBOXSFRENAMEWITHSRCBUFREQ *pReq,
663 PSHFLSTRING pSrcStr, uint32_t fFlags)
664{
665 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
666 SHFL_FN_RENAME, SHFL_CPARMS_RENAME,
667 RT_UOFFSETOF(VBOXSFRENAMEWITHSRCBUFREQ, StrDstPath.String) + pReq->StrDstPath.u16Size);
668
669 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
670 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
671
672 /** @todo Using page lists for contiguous buffers sucks. */
673 AssertReturn(pSrcStr->u16Size <= PAGE_SIZE - SHFLSTRING_HEADER_SIZE, VERR_FILENAME_TOO_LONG);
674 pReq->Parms.pStrSrcPath.type = VMMDevHGCMParmType_PageList;
675 pReq->Parms.pStrSrcPath.u.PageList.size = SHFLSTRING_HEADER_SIZE + pSrcStr->u16Size;
676 pReq->Parms.pStrSrcPath.u.PageList.offset = RT_UOFFSETOF(VBOXSFRENAMEWITHSRCBUFREQ, u.PgLst) - sizeof(VBGLIOCIDCHGCMFASTCALL);
677 pReq->u.PgLst.flags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
678 pReq->u.PgLst.aPages[0] = VbglR0PhysHeapGetPhysAddr(pSrcStr);
679 pReq->u.PgLst.offFirstPage = (uint16_t)(pReq->u.PgLst.aPages[0] & PAGE_OFFSET_MASK);
680 pReq->u.PgLst.aPages[0] &= ~(RTGCPHYS)PAGE_OFFSET_MASK;
681 if (PAGE_SIZE - pReq->u.PgLst.offFirstPage <= SHFLSTRING_HEADER_SIZE + pSrcStr->u16Size)
682 {
683 pReq->u.PgLst.aPages[1] = NIL_RTGCPHYS64;
684 pReq->u.PgLst.cPages = 1;
685 }
686 else
687 {
688 pReq->u.PgLst.aPages[1] = pReq->u.PgLst.aPages[0] + PAGE_SIZE;
689 pReq->u.PgLst.cPages = 2;
690 }
691
692 pReq->Parms.pStrDstPath.type = VMMDevHGCMParmType_Embedded;
693 pReq->Parms.pStrDstPath.u.Embedded.cbData = SHFLSTRING_HEADER_SIZE + pReq->StrDstPath.u16Size;
694 pReq->Parms.pStrDstPath.u.Embedded.offData = RT_UOFFSETOF(VBOXSFRENAMEWITHSRCBUFREQ, StrDstPath) - sizeof(VBGLIOCIDCHGCMFASTCALL);
695 pReq->Parms.pStrDstPath.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
696
697 pReq->Parms.f32Flags.type = VMMDevHGCMParmType_32bit;
698 pReq->Parms.f32Flags.u.value32 = fFlags;
699
700 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr,
701 RT_UOFFSETOF(VBOXSFRENAMEWITHSRCBUFREQ, StrDstPath.String) + pReq->StrDstPath.u16Size);
702 if (RT_SUCCESS(vrc))
703 vrc = pReq->Call.header.result;
704 return vrc;
705}
706
707
708/** Request structure for vboxSfOs2HostReqFlush. */
709typedef struct VBOXSFFLUSHREQ
710{
711 VBGLIOCIDCHGCMFASTCALL Hdr;
712 VMMDevHGCMCall Call;
713 VBoxSFParmFlush Parms;
714} VBOXSFFLUSHREQ;
715
716/**
717 * SHFL_FN_FLUSH request.
718 */
719DECLINLINE(int) vboxSfOs2HostReqFlush(PVBOXSFFOLDER pFolder, VBOXSFFLUSHREQ *pReq, uint64_t hHostFile)
720{
721 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
722 SHFL_FN_FLUSH, SHFL_CPARMS_FLUSH, sizeof(*pReq));
723
724 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
725 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
726
727 pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
728 pReq->Parms.u64Handle.u.value64 = hHostFile;
729
730 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
731 if (RT_SUCCESS(vrc))
732 vrc = pReq->Call.header.result;
733 return vrc;
734}
735
736/**
737 * SHFL_FN_FLUSH request, allocate request buffer.
738 */
739DECLINLINE(int) vboxSfOs2HostReqFlushSimple(PVBOXSFFOLDER pFolder, uint64_t hHostFile)
740{
741 VBOXSFFLUSHREQ *pReq = (VBOXSFFLUSHREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
742 if (pReq)
743 {
744 int vrc = vboxSfOs2HostReqFlush(pFolder, pReq, hHostFile);
745 VbglR0PhysHeapFree(pReq);
746 return vrc;
747 }
748 return VERR_NO_MEMORY;
749}
750
751
752/** Request structure for vboxSfOs2HostReqSetFileSize. */
753typedef struct VBOXSFSETFILESIZEREQ
754{
755 VBGLIOCIDCHGCMFASTCALL Hdr;
756 VMMDevHGCMCall Call;
757 VBoxSFParmSetFileSize Parms;
758} VBOXSFSETFILESIZEREQ;
759
760/**
761 * SHFL_FN_SET_FILE_SIZE request.
762 */
763DECLINLINE(int) vboxSfOs2HostReqSetFileSize(PVBOXSFFOLDER pFolder, VBOXSFSETFILESIZEREQ *pReq,
764 uint64_t hHostFile, uint64_t cbNewSize)
765{
766 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
767 SHFL_FN_SET_FILE_SIZE, SHFL_CPARMS_SET_FILE_SIZE, sizeof(*pReq));
768
769 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
770 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
771
772 pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
773 pReq->Parms.u64Handle.u.value64 = hHostFile;
774
775 pReq->Parms.cb64NewSize.type = VMMDevHGCMParmType_64bit;
776 pReq->Parms.cb64NewSize.u.value64 = cbNewSize;
777
778 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
779 if (RT_SUCCESS(vrc))
780 vrc = pReq->Call.header.result;
781 return vrc;
782}
783
784/**
785 * SHFL_FN_SET_FILE_SIZE request, allocate request buffer.
786 */
787DECLINLINE(int) vboxSfOs2HostReqSetFileSizeSimple(PVBOXSFFOLDER pFolder, uint64_t hHostFile, uint64_t cbNewSize)
788{
789 VBOXSFSETFILESIZEREQ *pReq = (VBOXSFSETFILESIZEREQ *)VbglR0PhysHeapAlloc(sizeof(*pReq));
790 if (pReq)
791 {
792 int vrc = vboxSfOs2HostReqSetFileSize(pFolder, pReq, hHostFile, cbNewSize);
793 VbglR0PhysHeapFree(pReq);
794 return vrc;
795 }
796 return VERR_NO_MEMORY;
797}
798
799
800/** Request structure for vboxSfOs2HostReqRead. */
801typedef struct VBOXSFREADEMBEDDEDREQ
802{
803 VBGLIOCIDCHGCMFASTCALL Hdr;
804 VMMDevHGCMCall Call;
805 VBoxSFParmRead Parms;
806 uint8_t abData[RT_FLEXIBLE_ARRAY];
807} VBOXSFREADEMBEDDEDREQ;
808
809/**
810 * SHFL_FN_INFORMATION[SHFL_INFO_GET | SHFL_INFO_FILE] request.
811 */
812DECLINLINE(int) vboxSfOs2HostReqReadEmbedded(PVBOXSFFOLDER pFolder, VBOXSFREADEMBEDDEDREQ *pReq, uint64_t hHostFile,
813 uint64_t offRead, uint32_t cbToRead)
814{
815 VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
816 SHFL_FN_READ, SHFL_CPARMS_READ, RT_UOFFSETOF(VBOXSFREADEMBEDDEDREQ, abData[0]) + cbToRead);
817
818 pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
819 pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
820
821 pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
822 pReq->Parms.u64Handle.u.value64 = hHostFile;
823
824 pReq->Parms.off64Read.type = VMMDevHGCMParmType_64bit;
825 pReq->Parms.off64Read.u.value64 = offRead;
826
827 pReq->Parms.cb32Read.type = VMMDevHGCMParmType_32bit;
828 pReq->Parms.cb32Read.u.value32 = cbToRead;
829
830 pReq->Parms.pBuf.type = VMMDevHGCMParmType_Embedded;
831 pReq->Parms.pBuf.u.Embedded.cbData = cbToRead;
832 pReq->Parms.pBuf.u.Embedded.offData = RT_UOFFSETOF(VBOXSFREADEMBEDDEDREQ, abData[0]) - sizeof(VBGLIOCIDCHGCMFASTCALL);
833 pReq->Parms.pBuf.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_FROM_HOST;
834
835 int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, RT_UOFFSETOF(VBOXSFREADEMBEDDEDREQ, abData[0]) + cbToRead);
836 if (RT_SUCCESS(vrc))
837 vrc = pReq->Call.header.result;
838 return vrc;
839}
840
841
842/** @} */
843
844#endif
845
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