1 | /** $Id: VBoxSFInternal.h 76118 2018-12-10 13:07:58Z 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 | */
|
---|
60 | typedef 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. */
|
---|
89 | typedef 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. */
|
---|
94 | extern MutexLock_t g_MtxFolders;
|
---|
95 | /** List of active folder (PVBOXSFFOLDER). */
|
---|
96 | extern 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 | */
|
---|
105 | typedef struct VBOXSFVP
|
---|
106 | {
|
---|
107 | /** Magic value (VBOXSFVP_MAGIC). */
|
---|
108 | uint32_t u32Magic;
|
---|
109 | /** The folder. */
|
---|
110 | PVBOXSFFOLDER pFolder;
|
---|
111 | } VBOXSFVP;
|
---|
112 | AssertCompile(sizeof(VBOXSFVP) <= sizeof(VPFSD));
|
---|
113 | /** Pointer to a VBOXSFVP struct. */
|
---|
114 | typedef 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 | */
|
---|
124 | typedef struct VBOXSFCD
|
---|
125 | {
|
---|
126 | uint32_t u32Dummy;
|
---|
127 | } VBOXSFCD;
|
---|
128 | AssertCompile(sizeof(VBOXSFCD) <= sizeof(CDFSD));
|
---|
129 | /** Pointer to a VBOXSFCD struct. */
|
---|
130 | typedef VBOXSFCD *PVBOXSFCD;
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * VBoxSF System File Structure.
|
---|
135 | *
|
---|
136 | * @remark Overlays the 30 byte SFFSD structure (fsd.h).
|
---|
137 | */
|
---|
138 | typedef 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;
|
---|
149 | AssertCompile(sizeof(VBOXSFSYFI) <= sizeof(SFFSD));
|
---|
150 | /** Pointer to a VBOXSFSYFI struct. */
|
---|
151 | typedef 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 | */
|
---|
159 | typedef 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;
|
---|
186 | AssertCompileSizeAlignment(VBOXSFFSBUF, 8);
|
---|
187 | /** Pointer to a file search buffer. */
|
---|
188 | typedef 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 | */
|
---|
202 | typedef 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;
|
---|
215 | AssertCompile(sizeof(VBOXSFFS) <= sizeof(FSFSD));
|
---|
216 | /** Pointer to a VBOXSFFS struct. */
|
---|
217 | typedef VBOXSFFS *PVBOXSFFS;
|
---|
218 | /** Magic number for VBOXSFFS (Isaak Azimov). */
|
---|
219 | #define VBOXSFFS_MAGIC UINT32_C(0x19200102)
|
---|
220 |
|
---|
221 |
|
---|
222 | extern VBGLSFCLIENT g_SfClient;
|
---|
223 |
|
---|
224 | PSHFLSTRING vboxSfOs2StrAlloc(size_t cwcLength);
|
---|
225 | PSHFLSTRING vboxSfOs2StrDup(PCSHFLSTRING pSrc);
|
---|
226 | void vboxSfOs2StrFree(PSHFLSTRING pStr);
|
---|
227 |
|
---|
228 | APIRET vboxSfOs2ResolvePath(const char *pszPath, PVBOXSFCD pCdFsd, LONG offCurDirEnd,
|
---|
229 | PVBOXSFFOLDER *ppFolder, PSHFLSTRING *ppStrFolderPath);
|
---|
230 | APIRET vboxSfOs2ResolvePathEx(const char *pszPath, PVBOXSFCD pCdFsd, LONG offCurDirEnd, uint32_t offStrInBuf,
|
---|
231 | PVBOXSFFOLDER *ppFolder, void **ppvBuf);
|
---|
232 | void vboxSfOs2ReleasePathAndFolder(PSHFLSTRING pStrPath, PVBOXSFFOLDER pFolder);
|
---|
233 | void vboxSfOs2ReleaseFolder(PVBOXSFFOLDER pFolder);
|
---|
234 | APIRET vboxSfOs2ConvertStatusToOs2(int vrc, APIRET rcDefault);
|
---|
235 | int16_t vboxSfOs2GetLocalTimeDelta(void);
|
---|
236 | void vboxSfOs2DateTimeFromTimeSpec(FDATE *pDosDate, FTIME *pDosTime, RTTIMESPEC SrcTimeSpec, int16_t cMinLocalTimeDelta);
|
---|
237 | PRTTIMESPEC vboxSfOs2DateTimeToTimeSpec(FDATE DosDate, FTIME DosTime, int16_t cMinLocalTimeDelta, PRTTIMESPEC pDstTimeSpec);
|
---|
238 | APIRET vboxSfOs2FileStatusFromObjInfo(PBYTE pbDst, ULONG cbDst, ULONG uLevel, SHFLFSOBJINFO const *pSrc);
|
---|
239 | APIRET vboxSfOs2SetInfoCommonWorker(PVBOXSFFOLDER pFolder, SHFLHANDLE hHostFile, ULONG fAttribs,
|
---|
240 | PFILESTATUS pTimestamps, PSHFLFSOBJINFO pObjInfoBuf);
|
---|
241 | APIRET vboxSfOs2MakeEmptyEaList(PEAOP pEaOp, ULONG uLevel);
|
---|
242 | APIRET vboxSfOs2MakeEmptyEaListEx(PEAOP pEaOp, ULONG uLevel, uint32_t *pcbWritten, ULONG *poffError);
|
---|
243 |
|
---|
244 | DECLASM(PVBOXSFVP) Fsh32GetVolParams(USHORT hVbp, PVPFSI *ppVpFsi /*optional*/);
|
---|
245 |
|
---|
246 |
|
---|
247 |
|
---|
248 | /** Request structure for vboxSfOs2HostReqCreate. */
|
---|
249 | typedef struct VBOXSFCREATEREQ
|
---|
250 | {
|
---|
251 | VBGLIOCIDCHGCMFASTCALL Hdr;
|
---|
252 | VMMDevHGCMCall Call;
|
---|
253 | VBoxSFParmCreate Parms;
|
---|
254 | SHFLCREATEPARMS CreateParms;
|
---|
255 | SHFLSTRING StrPath;
|
---|
256 | } VBOXSFCREATEREQ;
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * SHFL_FN_CREATE request.
|
---|
260 | */
|
---|
261 | DECLINLINE(int) vboxSfOs2HostReqCreate(PVBOXSFFOLDER pFolder, VBOXSFCREATEREQ *pReq)
|
---|
262 | {
|
---|
263 | VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
|
---|
264 | SHFL_FN_CREATE, SHFL_CPARMS_CREATE,
|
---|
265 | RT_UOFFSETOF(VBOXSFCREATEREQ, StrPath.String) + pReq->StrPath.u16Size);
|
---|
266 |
|
---|
267 | pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
|
---|
268 | pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
|
---|
269 |
|
---|
270 | pReq->Parms.pStrPath.type = VMMDevHGCMParmType_Embedded;
|
---|
271 | pReq->Parms.pStrPath.u.Embedded.cbData = SHFLSTRING_HEADER_SIZE + pReq->StrPath.u16Size;
|
---|
272 | pReq->Parms.pStrPath.u.Embedded.offData = RT_UOFFSETOF(VBOXSFCREATEREQ, StrPath) - sizeof(VBGLIOCIDCHGCMFASTCALL);
|
---|
273 | pReq->Parms.pStrPath.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_TO_HOST;
|
---|
274 |
|
---|
275 | pReq->Parms.pCreateParms.type = VMMDevHGCMParmType_Embedded;
|
---|
276 | pReq->Parms.pCreateParms.u.Embedded.cbData = sizeof(pReq->CreateParms);
|
---|
277 | pReq->Parms.pCreateParms.u.Embedded.offData = RT_UOFFSETOF(VBOXSFCREATEREQ, CreateParms) - sizeof(VBGLIOCIDCHGCMFASTCALL);
|
---|
278 | pReq->Parms.pCreateParms.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_BOTH;
|
---|
279 |
|
---|
280 | int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr,
|
---|
281 | RT_UOFFSETOF(VBOXSFCREATEREQ, StrPath.String) + pReq->StrPath.u16Size);
|
---|
282 | if (RT_SUCCESS(vrc))
|
---|
283 | vrc = pReq->Call.header.result;
|
---|
284 | return vrc;
|
---|
285 | }
|
---|
286 |
|
---|
287 |
|
---|
288 | /** Request structure for vboxSfOs2HostReqCreate. */
|
---|
289 | typedef struct VBOXSFCLOSEREQ
|
---|
290 | {
|
---|
291 | VBGLIOCIDCHGCMFASTCALL Hdr;
|
---|
292 | VMMDevHGCMCall Call;
|
---|
293 | VBoxSFParmClose Parms;
|
---|
294 | } VBOXSFCLOSEREQ;
|
---|
295 |
|
---|
296 | /**
|
---|
297 | * SHFL_FN_CLOSE request.
|
---|
298 | */
|
---|
299 | DECLINLINE(int) vboxSfOs2HostReqClose(PVBOXSFFOLDER pFolder, VBOXSFCLOSEREQ *pReq, uint64_t uHandle)
|
---|
300 | {
|
---|
301 | VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
|
---|
302 | SHFL_FN_CLOSE, SHFL_CPARMS_CLOSE, sizeof(*pReq));
|
---|
303 |
|
---|
304 | pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
|
---|
305 | pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
|
---|
306 |
|
---|
307 | pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
|
---|
308 | pReq->Parms.u64Handle.u.value64 = uHandle;
|
---|
309 |
|
---|
310 | int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
|
---|
311 | if (RT_SUCCESS(vrc))
|
---|
312 | vrc = pReq->Call.header.result;
|
---|
313 | return vrc;
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 | /** Request structure for vboxSfOs2HostReqQueryVolInfo. */
|
---|
318 | typedef struct VBOXSFVOLINFOREQ
|
---|
319 | {
|
---|
320 | VBGLIOCIDCHGCMFASTCALL Hdr;
|
---|
321 | VMMDevHGCMCall Call;
|
---|
322 | VBoxSFParmInformation Parms;
|
---|
323 | SHFLVOLINFO VolInfo;
|
---|
324 | } VBOXSFVOLINFOREQ;
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * SHFL_FN_INFORMATION[SHFL_INFO_VOLUME | SHFL_INFO_GET] request.
|
---|
328 | */
|
---|
329 | DECLINLINE(int) vboxSfOs2HostReqQueryVolInfo(PVBOXSFFOLDER pFolder, VBOXSFVOLINFOREQ *pReq, uint64_t uHandle)
|
---|
330 | {
|
---|
331 | VBGLIOCIDCHGCMFASTCALL_INIT(&pReq->Hdr, VbglR0PhysHeapGetPhysAddr(pReq), &pReq->Call, g_SfClient.idClient,
|
---|
332 | SHFL_FN_INFORMATION, SHFL_CPARMS_INFORMATION, sizeof(*pReq));
|
---|
333 |
|
---|
334 | pReq->Parms.id32Root.type = VMMDevHGCMParmType_32bit;
|
---|
335 | pReq->Parms.id32Root.u.value32 = pFolder->hHostFolder.root;
|
---|
336 |
|
---|
337 | pReq->Parms.u64Handle.type = VMMDevHGCMParmType_64bit;
|
---|
338 | pReq->Parms.u64Handle.u.value64 = uHandle;
|
---|
339 |
|
---|
340 | pReq->Parms.f32Flags.type = VMMDevHGCMParmType_32bit;
|
---|
341 | pReq->Parms.f32Flags.u.value32 = SHFL_INFO_VOLUME | SHFL_INFO_GET;
|
---|
342 |
|
---|
343 | pReq->Parms.cb32.type = VMMDevHGCMParmType_32bit;
|
---|
344 | pReq->Parms.cb32.u.value32 = sizeof(pReq->VolInfo);
|
---|
345 |
|
---|
346 | pReq->Parms.pInfo.type = VMMDevHGCMParmType_Embedded;
|
---|
347 | pReq->Parms.pInfo.u.Embedded.cbData = sizeof(pReq->VolInfo);
|
---|
348 | pReq->Parms.pInfo.u.Embedded.offData = RT_UOFFSETOF(VBOXSFVOLINFOREQ, VolInfo) - sizeof(VBGLIOCIDCHGCMFASTCALL);
|
---|
349 | pReq->Parms.pInfo.u.Embedded.fFlags = VBOX_HGCM_F_PARM_DIRECTION_FROM_HOST;
|
---|
350 |
|
---|
351 | int vrc = VbglR0HGCMFastCall(g_SfClient.handle, &pReq->Hdr, sizeof(*pReq));
|
---|
352 | if (RT_SUCCESS(vrc))
|
---|
353 | vrc = pReq->Call.header.result;
|
---|
354 | return vrc;
|
---|
355 | }
|
---|
356 |
|
---|
357 |
|
---|
358 | #endif
|
---|
359 |
|
---|