1 | /** @file
|
---|
2 | *
|
---|
3 | * Shared Folders:
|
---|
4 | * VBox Shared Folders.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "mappings.h"
|
---|
20 | #include "vbsf.h"
|
---|
21 | #include "shflhandle.h"
|
---|
22 |
|
---|
23 | #include <iprt/alloc.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 | #include <iprt/fs.h>
|
---|
26 | #include <iprt/dir.h>
|
---|
27 | #include <iprt/file.h>
|
---|
28 | #include <iprt/path.h>
|
---|
29 | #include <iprt/string.h>
|
---|
30 | #include <iprt/uni.h>
|
---|
31 |
|
---|
32 | #undef LogFlow
|
---|
33 | #define LogFlow Log
|
---|
34 |
|
---|
35 | void vbsfStripLastComponent (char *pszFullPath, uint32_t cbFullPathRoot)
|
---|
36 | {
|
---|
37 | RTUNICP cp;
|
---|
38 |
|
---|
39 | /* Do not strip root. */
|
---|
40 | char *s = pszFullPath + cbFullPathRoot;
|
---|
41 | char *delimSecondLast = NULL;
|
---|
42 | char *delimLast = NULL;
|
---|
43 |
|
---|
44 | LogFlowFunc(("%s -> %s\n", pszFullPath, s));
|
---|
45 |
|
---|
46 | for (;;)
|
---|
47 | {
|
---|
48 | cp = RTStrGetCp(s);
|
---|
49 |
|
---|
50 | if (cp == RTUNICP_INVALID || cp == 0)
|
---|
51 | {
|
---|
52 | break;
|
---|
53 | }
|
---|
54 |
|
---|
55 | if (cp == RTPATH_DELIMITER)
|
---|
56 | {
|
---|
57 | if (delimLast != NULL)
|
---|
58 | {
|
---|
59 | delimSecondLast = delimLast;
|
---|
60 | }
|
---|
61 |
|
---|
62 | delimLast = s;
|
---|
63 | }
|
---|
64 |
|
---|
65 | s = RTStrNextCp (s);
|
---|
66 | }
|
---|
67 |
|
---|
68 | if (cp == 0)
|
---|
69 | {
|
---|
70 | if (delimLast + 1 == s)
|
---|
71 | {
|
---|
72 | if (delimSecondLast)
|
---|
73 | {
|
---|
74 | *delimSecondLast = 0;
|
---|
75 | }
|
---|
76 | else if (delimLast)
|
---|
77 | {
|
---|
78 | *delimLast = 0;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | else
|
---|
82 | {
|
---|
83 | if (delimLast)
|
---|
84 | {
|
---|
85 | *delimLast = 0;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | LogFlowFunc(("%s, %s, %s\n", pszFullPath, delimLast, delimSecondLast));
|
---|
91 | }
|
---|
92 |
|
---|
93 | static int vbsfCorrectCasing(char *pszFullPath, char *pszStartComponent)
|
---|
94 | {
|
---|
95 | PRTDIRENTRYEX pDirEntry = NULL;
|
---|
96 | uint32_t cbDirEntry, cbComponent;
|
---|
97 | int rc = VERR_FILE_NOT_FOUND;
|
---|
98 | PRTDIR hSearch = 0;
|
---|
99 | char szWildCard[4];
|
---|
100 |
|
---|
101 | Log2(("vbsfCorrectCasing: %s %s\n", pszFullPath, pszStartComponent));
|
---|
102 |
|
---|
103 | cbComponent = strlen(pszStartComponent);
|
---|
104 |
|
---|
105 | cbDirEntry = 4096;
|
---|
106 | pDirEntry = (PRTDIRENTRYEX)RTMemAlloc(cbDirEntry);
|
---|
107 | if (pDirEntry == 0)
|
---|
108 | {
|
---|
109 | AssertFailed();
|
---|
110 | return VERR_NO_MEMORY;
|
---|
111 | }
|
---|
112 |
|
---|
113 | /** @todo this is quite inefficient, especially for directories with many files */
|
---|
114 | Assert(pszFullPath < pszStartComponent-1);
|
---|
115 | Assert(*(pszStartComponent-1) == RTPATH_DELIMITER);
|
---|
116 | *(pszStartComponent-1) = 0;
|
---|
117 | strcpy(pDirEntry->szName, pszFullPath);
|
---|
118 | szWildCard[0] = RTPATH_DELIMITER;
|
---|
119 | szWildCard[1] = '*';
|
---|
120 | szWildCard[2] = 0;
|
---|
121 | strcat(pDirEntry->szName, szWildCard);
|
---|
122 |
|
---|
123 | rc = RTDirOpenFiltered (&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT);
|
---|
124 | *(pszStartComponent-1) = RTPATH_DELIMITER;
|
---|
125 | if (VBOX_FAILURE(rc))
|
---|
126 | goto end;
|
---|
127 |
|
---|
128 | for(;;)
|
---|
129 | {
|
---|
130 | uint32_t cbDirEntrySize = cbDirEntry;
|
---|
131 |
|
---|
132 | rc = RTDirReadEx(hSearch, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING);
|
---|
133 | if (rc == VERR_NO_MORE_FILES)
|
---|
134 | break;
|
---|
135 |
|
---|
136 | if (VINF_SUCCESS != rc && rc != VWRN_NO_DIRENT_INFO)
|
---|
137 | {
|
---|
138 | AssertFailed();
|
---|
139 | if (rc != VERR_NO_TRANSLATION)
|
---|
140 | break;
|
---|
141 | else
|
---|
142 | continue;
|
---|
143 | }
|
---|
144 |
|
---|
145 | Log2(("vbsfCorrectCasing: found %s\n", &pDirEntry->szName[0]));
|
---|
146 | if ( pDirEntry->cbName == cbComponent
|
---|
147 | && !RTStrICmp(pszStartComponent, &pDirEntry->szName[0]))
|
---|
148 | {
|
---|
149 | Log(("Found original name %s (%s)\n", &pDirEntry->szName[0], pszStartComponent));
|
---|
150 | strcpy(pszStartComponent, &pDirEntry->szName[0]);
|
---|
151 | rc = VINF_SUCCESS;
|
---|
152 | break;
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | end:
|
---|
157 | if (VBOX_FAILURE(rc))
|
---|
158 | Log(("vbsfCorrectCasing %s failed with %d\n", pszStartComponent, rc));
|
---|
159 |
|
---|
160 | if (pDirEntry)
|
---|
161 | RTMemFree(pDirEntry);
|
---|
162 |
|
---|
163 | if (hSearch)
|
---|
164 | RTDirClose(hSearch);
|
---|
165 | return rc;
|
---|
166 | }
|
---|
167 |
|
---|
168 | static int vbsfBuildFullPath (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath,
|
---|
169 | uint32_t cbPath, char **ppszFullPath, uint32_t *pcbFullPathRoot, bool fWildCard = false)
|
---|
170 | {
|
---|
171 | int rc = VINF_SUCCESS;
|
---|
172 |
|
---|
173 | char *pszFullPath = NULL;
|
---|
174 |
|
---|
175 | /* Query UCS2 root prefix for the path, cbRoot is the length in bytes including trailing (RTUTF16)0. */
|
---|
176 | uint32_t cbRoot = 0;
|
---|
177 | PCRTUTF16 pwszRoot = vbsfMappingsQueryHostRoot (root, &cbRoot);
|
---|
178 |
|
---|
179 | if (!pwszRoot || cbRoot == 0)
|
---|
180 | {
|
---|
181 | Log(("vbsfBuildFullPath: invalid root!\n"));
|
---|
182 | return VERR_INVALID_PARAMETER;
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8))
|
---|
186 | {
|
---|
187 | int rc;
|
---|
188 | char *utf8Root;
|
---|
189 |
|
---|
190 | rc = RTUtf16ToUtf8 (pwszRoot, &utf8Root);
|
---|
191 | if (VBOX_SUCCESS (rc))
|
---|
192 | {
|
---|
193 | size_t cbUtf8Root, cbUtf8FullPath;
|
---|
194 | char *utf8FullPath;
|
---|
195 |
|
---|
196 | cbUtf8Root = strlen (utf8Root);
|
---|
197 | cbUtf8FullPath = cbUtf8Root + 1 + pPath->u16Length + 1;
|
---|
198 | utf8FullPath = (char *) RTMemAllocZ (cbUtf8FullPath);
|
---|
199 |
|
---|
200 | if (!utf8FullPath)
|
---|
201 | {
|
---|
202 | rc = VERR_NO_MEMORY;
|
---|
203 | *ppszFullPath = NULL;
|
---|
204 | Log(("RTMemAllocZ %x failed!!\n", cbUtf8FullPath));
|
---|
205 | }
|
---|
206 | else
|
---|
207 | {
|
---|
208 | memcpy (utf8FullPath, utf8Root, cbUtf8Root);
|
---|
209 | memcpy (utf8FullPath + cbUtf8Root + 1,
|
---|
210 | &pPath->String.utf8[0],
|
---|
211 | pPath->u16Length);
|
---|
212 |
|
---|
213 | utf8FullPath[cbUtf8Root] = '/';
|
---|
214 | utf8FullPath[cbUtf8FullPath - 1] = 0;
|
---|
215 | pszFullPath = utf8FullPath;
|
---|
216 |
|
---|
217 | if (pcbFullPathRoot)
|
---|
218 | *pcbFullPathRoot = cbUtf8Root; /* Must index the path delimiter. */
|
---|
219 | }
|
---|
220 |
|
---|
221 | RTStrFree (utf8Root);
|
---|
222 | }
|
---|
223 | else
|
---|
224 | {
|
---|
225 | Log (("vbsfBuildFullPath: RTUtf16ToUtf8 failed with %Vrc\n", rc));
|
---|
226 | }
|
---|
227 | }
|
---|
228 | else
|
---|
229 | {
|
---|
230 | /* Client sends us UCS2, so convert it to UTF8. */
|
---|
231 | Log(("Root %ls path %.*ls\n", pwszRoot, pPath->u16Length/sizeof(pPath->String.ucs2[0]), pPath->String.ucs2));
|
---|
232 |
|
---|
233 | /* Allocate buffer that will be able to contain
|
---|
234 | * the root prefix and the pPath converted to UTF8.
|
---|
235 | * Expect a 2 bytes UCS2 to be converted to 8 bytes UTF8
|
---|
236 | * in worst case.
|
---|
237 | */
|
---|
238 | uint32_t cbFullPath = (cbRoot/sizeof (RTUTF16) + ShflStringLength (pPath)) * 4;
|
---|
239 |
|
---|
240 | pszFullPath = (char *)RTMemAllocZ (cbFullPath);
|
---|
241 |
|
---|
242 | if (!pszFullPath)
|
---|
243 | {
|
---|
244 | rc = VERR_NO_MEMORY;
|
---|
245 | }
|
---|
246 | else
|
---|
247 | {
|
---|
248 | uint32_t cb = cbFullPath;
|
---|
249 |
|
---|
250 | rc = RTUtf16ToUtf8Ex (pwszRoot, RTSTR_MAX, &pszFullPath, cb, NULL);
|
---|
251 | if (VBOX_FAILURE(rc))
|
---|
252 | {
|
---|
253 | AssertFailed();
|
---|
254 | return rc;
|
---|
255 | }
|
---|
256 |
|
---|
257 | char *dst = pszFullPath;
|
---|
258 |
|
---|
259 | cbRoot = strlen(dst);
|
---|
260 | if (dst[cbRoot - 1] != RTPATH_DELIMITER)
|
---|
261 | {
|
---|
262 | dst[cbRoot] = RTPATH_DELIMITER;
|
---|
263 | cbRoot++;
|
---|
264 | }
|
---|
265 |
|
---|
266 | if (pcbFullPathRoot)
|
---|
267 | *pcbFullPathRoot = cbRoot - 1; /* Must index the path delimiter. */
|
---|
268 |
|
---|
269 | dst += cbRoot;
|
---|
270 | cb -= cbRoot;
|
---|
271 |
|
---|
272 | if (pPath->u16Length)
|
---|
273 | {
|
---|
274 | /* Convert and copy components. */
|
---|
275 | PRTUTF16 src = &pPath->String.ucs2[0];
|
---|
276 |
|
---|
277 | /* Correct path delimiters */
|
---|
278 | if (pClient->PathDelimiter != RTPATH_DELIMITER)
|
---|
279 | {
|
---|
280 | LogFlow(("Correct path delimiter in %ls\n", src));
|
---|
281 | while (*src)
|
---|
282 | {
|
---|
283 | if (*src == pClient->PathDelimiter)
|
---|
284 | *src = RTPATH_DELIMITER;
|
---|
285 | src++;
|
---|
286 | }
|
---|
287 | src = &pPath->String.ucs2[0];
|
---|
288 | LogFlow(("Corrected string %ls\n", src));
|
---|
289 | }
|
---|
290 | if (*src == RTPATH_DELIMITER)
|
---|
291 | src++; /* we already appended a delimiter to the first part */
|
---|
292 |
|
---|
293 | rc = RTUtf16ToUtf8Ex (src, RTSTR_MAX, &dst, cb, NULL);
|
---|
294 | if (VBOX_FAILURE(rc))
|
---|
295 | {
|
---|
296 | AssertFailed();
|
---|
297 | return rc;
|
---|
298 | }
|
---|
299 |
|
---|
300 | uint32_t l = strlen (dst);
|
---|
301 |
|
---|
302 | cb -= l;
|
---|
303 | dst += l;
|
---|
304 |
|
---|
305 | Assert(cb > 0);
|
---|
306 | }
|
---|
307 |
|
---|
308 | /* Nul terminate the string */
|
---|
309 | *dst = 0;
|
---|
310 | }
|
---|
311 | }
|
---|
312 |
|
---|
313 | if (VBOX_SUCCESS (rc))
|
---|
314 | {
|
---|
315 | /* When the host file system is case sensitive and the guest expects a case insensitive fs, then problems can occur */
|
---|
316 | if ( vbsfIsHostMappingCaseSensitive (root)
|
---|
317 | && !vbsfIsGuestMappingCaseSensitive(root))
|
---|
318 | {
|
---|
319 | RTFSOBJINFO info;
|
---|
320 | char *pszWildCardComponent = NULL;
|
---|
321 |
|
---|
322 | if (fWildCard)
|
---|
323 | {
|
---|
324 | /* strip off the last path component, that contains the wildcard(s) */
|
---|
325 | uint32_t len = strlen(pszFullPath);
|
---|
326 | char *src = pszFullPath + len - 1;
|
---|
327 |
|
---|
328 | while(src > pszFullPath)
|
---|
329 | {
|
---|
330 | if (*src == RTPATH_DELIMITER)
|
---|
331 | break;
|
---|
332 | src--;
|
---|
333 | }
|
---|
334 | if (*src == RTPATH_DELIMITER)
|
---|
335 | {
|
---|
336 | bool fHaveWildcards = false;
|
---|
337 | char *temp = src;
|
---|
338 |
|
---|
339 | while(*temp)
|
---|
340 | {
|
---|
341 | char uc = *temp;
|
---|
342 | if (uc == '*' || uc == '?' || uc == '>' || uc == '<' || uc == '"')
|
---|
343 | {
|
---|
344 | fHaveWildcards = true;
|
---|
345 | break;
|
---|
346 | }
|
---|
347 | temp++;
|
---|
348 | }
|
---|
349 |
|
---|
350 | if (fHaveWildcards)
|
---|
351 | {
|
---|
352 | pszWildCardComponent = src;
|
---|
353 | *pszWildCardComponent = 0;
|
---|
354 | }
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | /** @todo don't check when creating files or directories; waste of time */
|
---|
359 | rc = RTPathQueryInfo(pszFullPath, &info, RTFSOBJATTRADD_NOTHING);
|
---|
360 | if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND)
|
---|
361 | {
|
---|
362 | uint32_t len = strlen(pszFullPath);
|
---|
363 | char *src = pszFullPath + len - 1;
|
---|
364 |
|
---|
365 | Log(("Handle case insenstive guest fs on top of host case sensitive fs for %s\n", pszFullPath));
|
---|
366 |
|
---|
367 | /* Find partial path that's valid */
|
---|
368 | while(src > pszFullPath)
|
---|
369 | {
|
---|
370 | if (*src == RTPATH_DELIMITER)
|
---|
371 | {
|
---|
372 | *src = 0;
|
---|
373 | rc = RTPathQueryInfo (pszFullPath, &info, RTFSOBJATTRADD_NOTHING);
|
---|
374 | *src = RTPATH_DELIMITER;
|
---|
375 | if (rc == VINF_SUCCESS)
|
---|
376 | {
|
---|
377 | #ifdef DEBUG
|
---|
378 | *src = 0;
|
---|
379 | Log(("Found valid partial path %s\n", pszFullPath));
|
---|
380 | *src = RTPATH_DELIMITER;
|
---|
381 | #endif
|
---|
382 | break;
|
---|
383 | }
|
---|
384 | }
|
---|
385 |
|
---|
386 | src--;
|
---|
387 | }
|
---|
388 | Assert(*src == RTPATH_DELIMITER && VBOX_SUCCESS(rc));
|
---|
389 | if ( *src == RTPATH_DELIMITER
|
---|
390 | && VBOX_SUCCESS(rc))
|
---|
391 | {
|
---|
392 | src++;
|
---|
393 | for(;;)
|
---|
394 | {
|
---|
395 | char *end = src;
|
---|
396 | bool fEndOfString = true;
|
---|
397 |
|
---|
398 | while(*end)
|
---|
399 | {
|
---|
400 | if (*end == RTPATH_DELIMITER)
|
---|
401 | break;
|
---|
402 | end++;
|
---|
403 | }
|
---|
404 |
|
---|
405 | if (*end == RTPATH_DELIMITER)
|
---|
406 | {
|
---|
407 | fEndOfString = false;
|
---|
408 | *end = 0;
|
---|
409 | rc = RTPathQueryInfo(src, &info, RTFSOBJATTRADD_NOTHING);
|
---|
410 | Assert(rc == VINF_SUCCESS || rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND);
|
---|
411 | }
|
---|
412 | else
|
---|
413 | if (end == src)
|
---|
414 | rc = VINF_SUCCESS; /* trailing delimiter */
|
---|
415 | else
|
---|
416 | rc = VERR_FILE_NOT_FOUND;
|
---|
417 |
|
---|
418 | if (rc == VERR_FILE_NOT_FOUND || rc == VERR_PATH_NOT_FOUND)
|
---|
419 | {
|
---|
420 | /* path component is invalid; try to correct the casing */
|
---|
421 | rc = vbsfCorrectCasing(pszFullPath, src);
|
---|
422 | if (VBOX_FAILURE(rc))
|
---|
423 | {
|
---|
424 | if (!fEndOfString)
|
---|
425 | *end = RTPATH_DELIMITER; /* restore the original full path */
|
---|
426 | break;
|
---|
427 | }
|
---|
428 | }
|
---|
429 |
|
---|
430 | if (fEndOfString)
|
---|
431 | break;
|
---|
432 |
|
---|
433 | *end = RTPATH_DELIMITER;
|
---|
434 | src = end + 1;
|
---|
435 | }
|
---|
436 | if (VBOX_FAILURE(rc))
|
---|
437 | Log(("Unable to find suitable component rc=%d\n", rc));
|
---|
438 | }
|
---|
439 | else
|
---|
440 | rc = VERR_FILE_NOT_FOUND;
|
---|
441 |
|
---|
442 | }
|
---|
443 | if (pszWildCardComponent)
|
---|
444 | *pszWildCardComponent = RTPATH_DELIMITER;
|
---|
445 |
|
---|
446 | /* might be a new file so don't fail here! */
|
---|
447 | rc = VINF_SUCCESS;
|
---|
448 | }
|
---|
449 | *ppszFullPath = pszFullPath;
|
---|
450 |
|
---|
451 | LogFlow(("vbsfBuildFullPath: %s rc=%Vrc\n", pszFullPath, rc));
|
---|
452 | }
|
---|
453 |
|
---|
454 | return rc;
|
---|
455 | }
|
---|
456 |
|
---|
457 | static void vbsfFreeFullPath (char *pszFullPath)
|
---|
458 | {
|
---|
459 | RTMemFree (pszFullPath);
|
---|
460 | }
|
---|
461 |
|
---|
462 | /**
|
---|
463 | * Convert shared folder create flags (see include/iprt/shflsvc.h) into iprt create flags.
|
---|
464 | *
|
---|
465 | * @returns iprt status code
|
---|
466 | * @param fShflFlags shared folder create flags
|
---|
467 | * @retval pfOpen iprt create flags
|
---|
468 | */
|
---|
469 | static int vbsfConvertFileOpenFlags(unsigned fShflFlags, unsigned *pfOpen)
|
---|
470 | {
|
---|
471 | unsigned fOpen = 0;
|
---|
472 | int rc = VINF_SUCCESS;
|
---|
473 |
|
---|
474 | switch (BIT_FLAG(fShflFlags, SHFL_CF_ACCESS_MASK_RW))
|
---|
475 | {
|
---|
476 | default:
|
---|
477 | case SHFL_CF_ACCESS_NONE:
|
---|
478 | {
|
---|
479 | /** @todo treat this as read access, but theoretically this could be a no access request. */
|
---|
480 | fOpen |= RTFILE_O_READ;
|
---|
481 | Log(("FLAG: SHFL_CF_ACCESS_NONE\n"));
|
---|
482 | break;
|
---|
483 | }
|
---|
484 |
|
---|
485 | case SHFL_CF_ACCESS_READ:
|
---|
486 | {
|
---|
487 | fOpen |= RTFILE_O_READ;
|
---|
488 | Log(("FLAG: SHFL_CF_ACCESS_READ\n"));
|
---|
489 | break;
|
---|
490 | }
|
---|
491 |
|
---|
492 | case SHFL_CF_ACCESS_WRITE:
|
---|
493 | {
|
---|
494 | fOpen |= RTFILE_O_WRITE;
|
---|
495 | Log(("FLAG: SHFL_CF_ACCESS_WRITE\n"));
|
---|
496 | break;
|
---|
497 | }
|
---|
498 |
|
---|
499 | case SHFL_CF_ACCESS_READWRITE:
|
---|
500 | {
|
---|
501 | fOpen |= RTFILE_O_READWRITE;
|
---|
502 | Log(("FLAG: SHFL_CF_ACCESS_READWRITE\n"));
|
---|
503 | break;
|
---|
504 | }
|
---|
505 | }
|
---|
506 |
|
---|
507 | /* Sharing mask */
|
---|
508 | switch (BIT_FLAG(fShflFlags, SHFL_CF_ACCESS_MASK_DENY))
|
---|
509 | {
|
---|
510 | default:
|
---|
511 | case SHFL_CF_ACCESS_DENYNONE:
|
---|
512 | fOpen |= RTFILE_O_DENY_NONE;
|
---|
513 | Log(("FLAG: SHFL_CF_ACCESS_DENYNONE\n"));
|
---|
514 | break;
|
---|
515 |
|
---|
516 | case SHFL_CF_ACCESS_DENYREAD:
|
---|
517 | fOpen |= RTFILE_O_DENY_READ;
|
---|
518 | Log(("FLAG: SHFL_CF_ACCESS_DENYREAD\n"));
|
---|
519 | break;
|
---|
520 |
|
---|
521 | case SHFL_CF_ACCESS_DENYWRITE:
|
---|
522 | fOpen |= RTFILE_O_DENY_WRITE;
|
---|
523 | Log(("FLAG: SHFL_CF_ACCESS_DENYWRITE\n"));
|
---|
524 | break;
|
---|
525 |
|
---|
526 | case SHFL_CF_ACCESS_DENYALL:
|
---|
527 | fOpen |= RTFILE_O_DENY_ALL;
|
---|
528 | Log(("FLAG: SHFL_CF_ACCESS_DENYALL\n"));
|
---|
529 | break;
|
---|
530 | }
|
---|
531 |
|
---|
532 | /* Open/Create action mask */
|
---|
533 | switch (BIT_FLAG(fShflFlags, SHFL_CF_ACT_MASK_IF_EXISTS))
|
---|
534 | {
|
---|
535 | case SHFL_CF_ACT_OPEN_IF_EXISTS:
|
---|
536 | if (SHFL_CF_ACT_CREATE_IF_NEW == BIT_FLAG(fShflFlags, SHFL_CF_ACT_MASK_IF_NEW))
|
---|
537 | {
|
---|
538 | fOpen |= RTFILE_O_OPEN_CREATE;
|
---|
539 | Log(("FLAGS: SHFL_CF_ACT_OPEN_IF_EXISTS and SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
540 | }
|
---|
541 | else if (SHFL_CF_ACT_FAIL_IF_NEW == BIT_FLAG(fShflFlags, SHFL_CF_ACT_MASK_IF_NEW))
|
---|
542 | {
|
---|
543 | fOpen |= RTFILE_O_OPEN;
|
---|
544 | Log(("FLAGS: SHFL_CF_ACT_OPEN_IF_EXISTS and SHFL_CF_ACT_FAIL_IF_NEW\n"));
|
---|
545 | }
|
---|
546 | else
|
---|
547 | {
|
---|
548 | Log(("FLAGS: invalid open/create action combination\n"));
|
---|
549 | rc = VERR_INVALID_PARAMETER;
|
---|
550 | }
|
---|
551 | break;
|
---|
552 | case SHFL_CF_ACT_FAIL_IF_EXISTS:
|
---|
553 | if (SHFL_CF_ACT_CREATE_IF_NEW == BIT_FLAG(fShflFlags, SHFL_CF_ACT_MASK_IF_NEW))
|
---|
554 | {
|
---|
555 | fOpen |= RTFILE_O_CREATE;
|
---|
556 | Log(("FLAGS: SHFL_CF_ACT_FAIL_IF_EXISTS and SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
557 | }
|
---|
558 | else
|
---|
559 | {
|
---|
560 | Log(("FLAGS: invalid open/create action combination\n"));
|
---|
561 | rc = VERR_INVALID_PARAMETER;
|
---|
562 | }
|
---|
563 | break;
|
---|
564 | case SHFL_CF_ACT_REPLACE_IF_EXISTS:
|
---|
565 | if (SHFL_CF_ACT_CREATE_IF_NEW == BIT_FLAG(fShflFlags, SHFL_CF_ACT_MASK_IF_NEW))
|
---|
566 | {
|
---|
567 | fOpen |= RTFILE_O_CREATE_REPLACE;
|
---|
568 | Log(("FLAGS: SHFL_CF_ACT_REPLACE_IF_EXISTS and SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
569 | }
|
---|
570 | else if (SHFL_CF_ACT_FAIL_IF_NEW == BIT_FLAG(fShflFlags, SHFL_CF_ACT_MASK_IF_NEW))
|
---|
571 | {
|
---|
572 | fOpen |= RTFILE_O_OPEN | RTFILE_O_TRUNCATE;
|
---|
573 | Log(("FLAGS: SHFL_CF_ACT_REPLACE_IF_EXISTS and SHFL_CF_ACT_FAIL_IF_NEW\n"));
|
---|
574 | }
|
---|
575 | else
|
---|
576 | {
|
---|
577 | Log(("FLAGS: invalid open/create action combination\n"));
|
---|
578 | rc = VERR_INVALID_PARAMETER;
|
---|
579 | }
|
---|
580 | break;
|
---|
581 | case SHFL_CF_ACT_OVERWRITE_IF_EXISTS:
|
---|
582 | if (SHFL_CF_ACT_CREATE_IF_NEW == BIT_FLAG(fShflFlags, SHFL_CF_ACT_MASK_IF_NEW))
|
---|
583 | {
|
---|
584 | fOpen |= RTFILE_O_CREATE_REPLACE;
|
---|
585 | Log(("FLAGS: SHFL_CF_ACT_OVERWRITE_IF_EXISTS and SHFL_CF_ACT_CREATE_IF_NEW\n"));
|
---|
586 | }
|
---|
587 | else if (SHFL_CF_ACT_FAIL_IF_NEW == BIT_FLAG(fShflFlags, SHFL_CF_ACT_MASK_IF_NEW))
|
---|
588 | {
|
---|
589 | fOpen |= RTFILE_O_OPEN | RTFILE_O_TRUNCATE;
|
---|
590 | Log(("FLAGS: SHFL_CF_ACT_OVERWRITE_IF_EXISTS and SHFL_CF_ACT_FAIL_IF_NEW\n"));
|
---|
591 | }
|
---|
592 | else
|
---|
593 | {
|
---|
594 | Log(("FLAGS: invalid open/create action combination\n"));
|
---|
595 | rc = VERR_INVALID_PARAMETER;
|
---|
596 | }
|
---|
597 | break;
|
---|
598 | default:
|
---|
599 | rc = VERR_INVALID_PARAMETER;
|
---|
600 | Log(("FLAG: SHFL_CF_ACT_MASK_IF_EXISTS - invalid parameter\n"));
|
---|
601 | }
|
---|
602 |
|
---|
603 | if (RT_SUCCESS(rc))
|
---|
604 | {
|
---|
605 | *pfOpen = fOpen;
|
---|
606 | }
|
---|
607 | return rc;
|
---|
608 | }
|
---|
609 |
|
---|
610 | /**
|
---|
611 | * Open a file or create and open a new one.
|
---|
612 | *
|
---|
613 | * @returns IPRT status code
|
---|
614 | * @param pszPath Path to the file or folder on the host.
|
---|
615 | * @param pParms->CreateFlags Creation or open parameters, see include/VBox/shflsvc.h
|
---|
616 | * @param pParms->Info When a new file is created this specifies the initial parameters.
|
---|
617 | * When a file is created or overwritten, it also specifies the
|
---|
618 | * initial size.
|
---|
619 | * @retval pParms->Result Shared folder status code, see include/VBox/shflsvc.h
|
---|
620 | * @retval pParms->Handle On success the (shared folder) handle of the file opened or
|
---|
621 | * created
|
---|
622 | * @retval pParms->Info On success the parameters of the file opened or created
|
---|
623 | */
|
---|
624 | static int vbsfOpenFile (const char *pszPath, SHFLCREATEPARMS *pParms)
|
---|
625 | {
|
---|
626 | LogFlow(("vbsfOpenFile: pszPath = %s, pParms = %p\n", pszPath, pParms));
|
---|
627 | Log(("SHFL create flags %08x\n", pParms->CreateFlags));
|
---|
628 |
|
---|
629 | SHFLHANDLE handle = SHFL_HANDLE_NIL;
|
---|
630 | SHFLFILEHANDLE *pHandle = 0;
|
---|
631 | /* Open or create a file. */
|
---|
632 | unsigned fOpen = 0;
|
---|
633 | bool fNoError = false;
|
---|
634 |
|
---|
635 | int rc = vbsfConvertFileOpenFlags(pParms->CreateFlags, &fOpen);
|
---|
636 | if (RT_SUCCESS(rc))
|
---|
637 | {
|
---|
638 | handle = vbsfAllocFileHandle();
|
---|
639 | }
|
---|
640 | if (SHFL_HANDLE_NIL != handle)
|
---|
641 | {
|
---|
642 | rc = VERR_NO_MEMORY; /* If this fails - rewritten immediately on success. */
|
---|
643 | pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(handle, SHFL_HF_TYPE_FILE);
|
---|
644 | }
|
---|
645 | if (0 != pHandle)
|
---|
646 | {
|
---|
647 | rc = RTFileOpen(&pHandle->file.Handle, pszPath, fOpen);
|
---|
648 | }
|
---|
649 | if (RT_FAILURE (rc))
|
---|
650 | {
|
---|
651 | switch (rc)
|
---|
652 | {
|
---|
653 | case VERR_FILE_NOT_FOUND:
|
---|
654 | pParms->Result = SHFL_FILE_NOT_FOUND;
|
---|
655 |
|
---|
656 | /* This actually isn't an error, so correct the rc before return later,
|
---|
657 | because the driver (VBoxSF.sys) expects rc = VINF_SUCCESS and checks the result code. */
|
---|
658 | fNoError = true;
|
---|
659 | break;
|
---|
660 | case VERR_PATH_NOT_FOUND:
|
---|
661 | pParms->Result = SHFL_PATH_NOT_FOUND;
|
---|
662 |
|
---|
663 | /* This actually isn't an error, so correct the rc before return later,
|
---|
664 | because the driver (VBoxSF.sys) expects rc = VINF_SUCCESS and checks the result code. */
|
---|
665 | fNoError = true;
|
---|
666 | break;
|
---|
667 | case VERR_ALREADY_EXISTS:
|
---|
668 | RTFSOBJINFO info;
|
---|
669 |
|
---|
670 | /** @todo Possible race left here. */
|
---|
671 | if (RT_SUCCESS(RTPathQueryInfo (pszPath, &info, RTFSOBJATTRADD_NOTHING)))
|
---|
672 | {
|
---|
673 | pParms->Info = info;
|
---|
674 | }
|
---|
675 | pParms->Result = SHFL_FILE_EXISTS;
|
---|
676 |
|
---|
677 | /* This actually isn't an error, so correct the rc before return later,
|
---|
678 | because the driver (VBoxSF.sys) expects rc = VINF_SUCCESS and checks the result code. */
|
---|
679 | fNoError = true;
|
---|
680 | break;
|
---|
681 | default:
|
---|
682 | pParms->Result = SHFL_NO_RESULT;
|
---|
683 | }
|
---|
684 | }
|
---|
685 |
|
---|
686 | if (RT_SUCCESS(rc))
|
---|
687 | {
|
---|
688 | /** @note The shared folder status code is very approximate, as the runtime
|
---|
689 | * does not really provide this information. */
|
---|
690 | pParms->Result = SHFL_FILE_EXISTS; /* We lost the information as to whether it was
|
---|
691 | created when we eliminated the race. */
|
---|
692 | if ( ( SHFL_CF_ACT_REPLACE_IF_EXISTS
|
---|
693 | == BIT_FLAG(pParms->CreateFlags, SHFL_CF_ACT_MASK_IF_EXISTS))
|
---|
694 | || ( SHFL_CF_ACT_OVERWRITE_IF_EXISTS
|
---|
695 | == BIT_FLAG(pParms->CreateFlags, SHFL_CF_ACT_MASK_IF_EXISTS)))
|
---|
696 | {
|
---|
697 | /* For now, we do not treat a failure here as fatal. */
|
---|
698 | /* @todo Also set the size for SHFL_CF_ACT_CREATE_IF_NEW if
|
---|
699 | SHFL_CF_ACT_FAIL_IF_EXISTS is set. */
|
---|
700 | RTFileSetSize(pHandle->file.Handle, pParms->Info.cbObject);
|
---|
701 | pParms->Result = SHFL_FILE_REPLACED;
|
---|
702 | }
|
---|
703 | if ( ( SHFL_CF_ACT_FAIL_IF_EXISTS
|
---|
704 | == BIT_FLAG(pParms->CreateFlags, SHFL_CF_ACT_MASK_IF_EXISTS))
|
---|
705 | || ( SHFL_CF_ACT_CREATE_IF_NEW
|
---|
706 | == BIT_FLAG(pParms->CreateFlags, SHFL_CF_ACT_MASK_IF_NEW)))
|
---|
707 | {
|
---|
708 | pParms->Result = SHFL_FILE_CREATED;
|
---|
709 | }
|
---|
710 | #if 0
|
---|
711 | /* @todo */
|
---|
712 | /* Set new attributes. */
|
---|
713 | if ( ( SHFL_CF_ACT_REPLACE_IF_EXISTS
|
---|
714 | == BIT_FLAG(pParms->CreateFlags, SHFL_CF_ACT_MASK_IF_EXISTS))
|
---|
715 | || ( SHFL_CF_ACT_CREATE_IF_NEW
|
---|
716 | == BIT_FLAG(pParms->CreateFlags, SHFL_CF_ACT_MASK_IF_NEW)))
|
---|
717 | {
|
---|
718 | RTFileSetTimes(pHandle->file.Handle,
|
---|
719 | &pParms->Info.AccessTime,
|
---|
720 | &pParms->Info.ModificationTime,
|
---|
721 | &pParms->Info.ChangeTime,
|
---|
722 | &pParms->Info.BirthTime
|
---|
723 | );
|
---|
724 |
|
---|
725 | RTFileSetMode (pHandle->file.Handle, pParms->Info.Attr.fMode);
|
---|
726 | }
|
---|
727 | #endif
|
---|
728 | RTFSOBJINFO info;
|
---|
729 |
|
---|
730 | /* Get file information */
|
---|
731 | rc = RTFileQueryInfo (pHandle->file.Handle, &info, RTFSOBJATTRADD_NOTHING);
|
---|
732 | if (RT_SUCCESS(rc))
|
---|
733 | {
|
---|
734 | pParms->Info = info;
|
---|
735 | }
|
---|
736 | }
|
---|
737 | if (RT_FAILURE(rc))
|
---|
738 | {
|
---|
739 | if ( (0 != pHandle)
|
---|
740 | && (NIL_RTFILE != pHandle->file.Handle)
|
---|
741 | && (0 != pHandle->file.Handle))
|
---|
742 | {
|
---|
743 | RTFileClose(pHandle->file.Handle);
|
---|
744 | pHandle->file.Handle = NIL_RTFILE;
|
---|
745 | }
|
---|
746 | if (SHFL_HANDLE_NIL != handle)
|
---|
747 | {
|
---|
748 | vbsfFreeFileHandle (handle);
|
---|
749 | }
|
---|
750 | }
|
---|
751 | else
|
---|
752 | {
|
---|
753 | pParms->Handle = handle;
|
---|
754 | }
|
---|
755 |
|
---|
756 | /* Report the driver that all is okay, we're done here */
|
---|
757 | if (fNoError)
|
---|
758 | rc = VINF_SUCCESS;
|
---|
759 |
|
---|
760 | LogFlow(("vbsfOpenFile: rc = %Vrc\n", rc));
|
---|
761 | return rc;
|
---|
762 | }
|
---|
763 |
|
---|
764 | /**
|
---|
765 | * Open a folder or create and open a new one.
|
---|
766 | *
|
---|
767 | * @returns IPRT status code
|
---|
768 | * @param pszPath Path to the file or folder on the host.
|
---|
769 | * @param pParms->CreateFlags Creation or open parameters, see include/VBox/shflsvc.h
|
---|
770 | * @retval pParms->Result Shared folder status code, see include/VBox/shflsvc.h
|
---|
771 | * @retval pParms->Handle On success the (shared folder) handle of the folder opened or
|
---|
772 | * created
|
---|
773 | * @retval pParms->Info On success the parameters of the folder opened or created
|
---|
774 | *
|
---|
775 | * @note folders are created with fMode = 0777
|
---|
776 | */
|
---|
777 | static int vbsfOpenDir (const char *pszPath, SHFLCREATEPARMS *pParms)
|
---|
778 | {
|
---|
779 | LogFlow(("vbsfOpenDir: pszPath = %s, pParms = %p\n", pszPath, pParms));
|
---|
780 | Log(("SHFL create flags %08x\n", pParms->CreateFlags));
|
---|
781 |
|
---|
782 | int rc = VERR_NO_MEMORY;
|
---|
783 | SHFLHANDLE handle = vbsfAllocDirHandle();
|
---|
784 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(handle, SHFL_HF_TYPE_DIR);
|
---|
785 | if (0 != pHandle)
|
---|
786 | {
|
---|
787 | rc = VINF_SUCCESS;
|
---|
788 | pParms->Result = SHFL_FILE_EXISTS; /* May be overwritten with SHFL_FILE_CREATED. */
|
---|
789 | /** @todo Can anyone think of a sensible, race-less way to do this? Although
|
---|
790 | I suspect that the race is inherent, due to the API available... */
|
---|
791 | /* Try to create the folder first if "create if new" is specified. If this
|
---|
792 | fails, and "open if exists" is specified, then we ignore the failure and try
|
---|
793 | to open the folder anyway. */
|
---|
794 | if ( SHFL_CF_ACT_CREATE_IF_NEW
|
---|
795 | == BIT_FLAG(pParms->CreateFlags, SHFL_CF_ACT_MASK_IF_NEW))
|
---|
796 | {
|
---|
797 | /** @todo render supplied attributes.
|
---|
798 | * bird: The guest should specify this. For windows guests RTFS_DOS_DIRECTORY should suffice. */
|
---|
799 | RTFMODE fMode = 0777;
|
---|
800 |
|
---|
801 | pParms->Result = SHFL_FILE_CREATED;
|
---|
802 | rc = RTDirCreate(pszPath, fMode);
|
---|
803 | if (RT_FAILURE (rc))
|
---|
804 | {
|
---|
805 | switch (rc)
|
---|
806 | {
|
---|
807 | case VERR_ALREADY_EXISTS:
|
---|
808 | pParms->Result = SHFL_FILE_EXISTS;
|
---|
809 | break;
|
---|
810 | case VERR_PATH_NOT_FOUND:
|
---|
811 | pParms->Result = SHFL_PATH_NOT_FOUND;
|
---|
812 | break;
|
---|
813 | default:
|
---|
814 | pParms->Result = SHFL_NO_RESULT;
|
---|
815 | }
|
---|
816 | }
|
---|
817 | }
|
---|
818 | if ( RT_SUCCESS(rc)
|
---|
819 | || (SHFL_CF_ACT_OPEN_IF_EXISTS == BIT_FLAG(pParms->CreateFlags, SHFL_CF_ACT_MASK_IF_EXISTS)))
|
---|
820 | {
|
---|
821 | /* Open the directory now */
|
---|
822 | rc = RTDirOpen (&pHandle->dir.Handle, pszPath);
|
---|
823 | if (RT_SUCCESS(rc))
|
---|
824 | {
|
---|
825 | RTFSOBJINFO info;
|
---|
826 |
|
---|
827 | rc = RTDirQueryInfo (pHandle->dir.Handle, &info, RTFSOBJATTRADD_NOTHING);
|
---|
828 | if (RT_SUCCESS(rc))
|
---|
829 | {
|
---|
830 | pParms->Info = info;
|
---|
831 | }
|
---|
832 | }
|
---|
833 | else
|
---|
834 | {
|
---|
835 | switch (rc)
|
---|
836 | {
|
---|
837 | case VERR_FILE_NOT_FOUND: /* Does this make sense? */
|
---|
838 | pParms->Result = SHFL_FILE_NOT_FOUND;
|
---|
839 | break;
|
---|
840 | case VERR_PATH_NOT_FOUND:
|
---|
841 | pParms->Result = SHFL_PATH_NOT_FOUND;
|
---|
842 | break;
|
---|
843 | case VERR_ACCESS_DENIED:
|
---|
844 | pParms->Result = SHFL_FILE_EXISTS;
|
---|
845 | break;
|
---|
846 | default:
|
---|
847 | pParms->Result = SHFL_NO_RESULT;
|
---|
848 | }
|
---|
849 | }
|
---|
850 | }
|
---|
851 | }
|
---|
852 | if (RT_FAILURE(rc))
|
---|
853 | {
|
---|
854 | if ( (0 != pHandle)
|
---|
855 | && (0 != pHandle->dir.Handle))
|
---|
856 | {
|
---|
857 | RTDirClose(pHandle->dir.Handle);
|
---|
858 | pHandle->dir.Handle = 0;
|
---|
859 | }
|
---|
860 | if (SHFL_HANDLE_NIL != handle)
|
---|
861 | {
|
---|
862 | vbsfFreeFileHandle (handle);
|
---|
863 | }
|
---|
864 | }
|
---|
865 | else
|
---|
866 | {
|
---|
867 | pParms->Handle = handle;
|
---|
868 | }
|
---|
869 | LogFlow(("vbsfOpenDir: rc = %Vrc\n", rc));
|
---|
870 | return rc;
|
---|
871 | }
|
---|
872 |
|
---|
873 | static int vbsfCloseDir (SHFLFILEHANDLE *pHandle)
|
---|
874 | {
|
---|
875 | int rc = VINF_SUCCESS;
|
---|
876 |
|
---|
877 | LogFlow(("vbsfCloseDir: Handle = %08X Search Handle = %08X\n",
|
---|
878 | pHandle->dir.Handle, pHandle->dir.SearchHandle));
|
---|
879 |
|
---|
880 | RTDirClose (pHandle->dir.Handle);
|
---|
881 |
|
---|
882 | if (pHandle->dir.SearchHandle)
|
---|
883 | RTDirClose(pHandle->dir.SearchHandle);
|
---|
884 |
|
---|
885 | if (pHandle->dir.pLastValidEntry)
|
---|
886 | {
|
---|
887 | RTMemFree(pHandle->dir.pLastValidEntry);
|
---|
888 | pHandle->dir.pLastValidEntry = NULL;
|
---|
889 | }
|
---|
890 |
|
---|
891 | LogFlow(("vbsfCloseDir: rc = %d\n", rc));
|
---|
892 |
|
---|
893 | return rc;
|
---|
894 | }
|
---|
895 |
|
---|
896 |
|
---|
897 | static int vbsfCloseFile (SHFLFILEHANDLE *pHandle)
|
---|
898 | {
|
---|
899 | int rc = VINF_SUCCESS;
|
---|
900 |
|
---|
901 | LogFlow(("vbsfCloseFile: Handle = %08X\n",
|
---|
902 | pHandle->file.Handle));
|
---|
903 |
|
---|
904 | rc = RTFileClose (pHandle->file.Handle);
|
---|
905 |
|
---|
906 | LogFlow(("vbsfCloseFile: rc = %d\n", rc));
|
---|
907 |
|
---|
908 | return rc;
|
---|
909 | }
|
---|
910 |
|
---|
911 | /**
|
---|
912 | * Look up file or folder information by host path.
|
---|
913 | *
|
---|
914 | * @returns iprt status code (currently VINF_SUCCESS)
|
---|
915 | * @param pszFullPath The path of the file to be looked up
|
---|
916 | * @retval pParms->Result Status of the operation (success or error)
|
---|
917 | * @retval pParms->Info On success, information returned about the file
|
---|
918 | */
|
---|
919 | static int vbsfLookupFile(char *pszPath, SHFLCREATEPARMS *pParms)
|
---|
920 | {
|
---|
921 | RTFSOBJINFO info;
|
---|
922 | int rc;
|
---|
923 |
|
---|
924 | rc = RTPathQueryInfo (pszPath, &info, RTFSOBJATTRADD_NOTHING);
|
---|
925 | LogFlow(("SHFL_CF_LOOKUP\n"));
|
---|
926 | /* Client just wants to know if the object exists. */
|
---|
927 | switch (rc)
|
---|
928 | {
|
---|
929 | case VINF_SUCCESS:
|
---|
930 | {
|
---|
931 | pParms->Info = info;
|
---|
932 | pParms->Result = SHFL_FILE_EXISTS;
|
---|
933 | break;
|
---|
934 | }
|
---|
935 |
|
---|
936 | case VERR_FILE_NOT_FOUND:
|
---|
937 | {
|
---|
938 | pParms->Result = SHFL_FILE_NOT_FOUND;
|
---|
939 | rc = VINF_SUCCESS;
|
---|
940 | break;
|
---|
941 | }
|
---|
942 |
|
---|
943 | case VERR_PATH_NOT_FOUND:
|
---|
944 | {
|
---|
945 | pParms->Result = SHFL_PATH_NOT_FOUND;
|
---|
946 | rc = VINF_SUCCESS;
|
---|
947 | break;
|
---|
948 | }
|
---|
949 | }
|
---|
950 | return rc;
|
---|
951 | }
|
---|
952 |
|
---|
953 | /**
|
---|
954 | * Create or open a file or folder. Perform character set and case
|
---|
955 | * conversion on the file name if necessary.
|
---|
956 | *
|
---|
957 | * @returns IPRT status code, but see note below
|
---|
958 | * @param pClient Data structure describing the client accessing the shared
|
---|
959 | * folder
|
---|
960 | * @param root The index of the shared folder in the table of mappings.
|
---|
961 | * The host path of the shared folder is found using this.
|
---|
962 | * @param pPath The path of the file or folder relative to the host path
|
---|
963 | * indexed by root.
|
---|
964 | * @param cbPath Presumably the length of the path in pPath. Actually
|
---|
965 | * ignored, as pPath contains a length parameter.
|
---|
966 | * @param pParms->Info If a new file is created or an old one overwritten, set
|
---|
967 | * these attributes
|
---|
968 | * @retval pParms->Result Shared folder result code, see include/VBox/shflsvc.h
|
---|
969 | * @retval pParms->Handle Shared folder handle to the newly opened file
|
---|
970 | * @retval pParms->Info Attributes of the file or folder opened
|
---|
971 | *
|
---|
972 | * @note This function returns success if a "non-exceptional" error occurred,
|
---|
973 | * such as "no such file". In this case, the caller should check the
|
---|
974 | * pParms->Result return value and whether pParms->Handle is valid.
|
---|
975 | */
|
---|
976 | int vbsfCreate (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, SHFLCREATEPARMS *pParms)
|
---|
977 | {
|
---|
978 | int rc = VINF_SUCCESS;
|
---|
979 |
|
---|
980 | LogFlow(("vbsfCreate: pClient = %p, pPath = %p, cbPath = %d, pParms = %p CreateFlags=%x\n",
|
---|
981 | pClient, pPath, cbPath, pParms, pParms->CreateFlags));
|
---|
982 |
|
---|
983 | /* Check the client access rights to the root. */
|
---|
984 | /** @todo */
|
---|
985 |
|
---|
986 | /* Build a host full path for the given path, handle file name case issues (if the guest
|
---|
987 | * expects case-insensitive paths but the host is case-sensitive) and convert ucs2 to utf8 if
|
---|
988 | * necessary.
|
---|
989 | */
|
---|
990 | char *pszFullPath = NULL;
|
---|
991 | uint32_t cbFullPathRoot = 0;
|
---|
992 |
|
---|
993 | rc = vbsfBuildFullPath (pClient, root, pPath, cbPath, &pszFullPath, &cbFullPathRoot);
|
---|
994 |
|
---|
995 | if (VBOX_SUCCESS (rc))
|
---|
996 | {
|
---|
997 | /* Reset return values in case client forgot to do so. */
|
---|
998 | pParms->Result = SHFL_NO_RESULT;
|
---|
999 | pParms->Handle = SHFL_HANDLE_NIL;
|
---|
1000 |
|
---|
1001 | if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_LOOKUP))
|
---|
1002 | {
|
---|
1003 | rc = vbsfLookupFile(pszFullPath, pParms);
|
---|
1004 | }
|
---|
1005 | else
|
---|
1006 | {
|
---|
1007 | /* Query path information. */
|
---|
1008 | RTFSOBJINFO info;
|
---|
1009 |
|
---|
1010 | rc = RTPathQueryInfo (pszFullPath, &info, RTFSOBJATTRADD_NOTHING);
|
---|
1011 | LogFlow(("RTPathQueryInfo returned %Vrc\n", rc));
|
---|
1012 |
|
---|
1013 | if (RT_SUCCESS(rc))
|
---|
1014 | {
|
---|
1015 | /* Mark it as a directory in case the caller didn't. */
|
---|
1016 | /**
|
---|
1017 | * @todo I left this in in order not to change the behaviour of the
|
---|
1018 | * function too much. Is it really needed, and should it really be
|
---|
1019 | * here?
|
---|
1020 | */
|
---|
1021 | if (BIT_FLAG(info.Attr.fMode, RTFS_DOS_DIRECTORY))
|
---|
1022 | {
|
---|
1023 | pParms->CreateFlags |= SHFL_CF_DIRECTORY;
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | /**
|
---|
1027 | * @todo This should be in the Windows Guest Additions, as no-one else
|
---|
1028 | * needs it.
|
---|
1029 | */
|
---|
1030 | if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_OPEN_TARGET_DIRECTORY))
|
---|
1031 | {
|
---|
1032 | vbsfStripLastComponent (pszFullPath, cbFullPathRoot);
|
---|
1033 | pParms->CreateFlags &= ~SHFL_CF_ACT_MASK_IF_EXISTS;
|
---|
1034 | pParms->CreateFlags &= ~SHFL_CF_ACT_MASK_IF_NEW;
|
---|
1035 | pParms->CreateFlags |= SHFL_CF_DIRECTORY;
|
---|
1036 | pParms->CreateFlags |= SHFL_CF_ACT_OPEN_IF_EXISTS;
|
---|
1037 | pParms->CreateFlags |= SHFL_CF_ACT_FAIL_IF_NEW;
|
---|
1038 | }
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | rc = VINF_SUCCESS;
|
---|
1042 |
|
---|
1043 | /* write access requested? */
|
---|
1044 | if (pParms->CreateFlags & ( SHFL_CF_ACT_REPLACE_IF_EXISTS
|
---|
1045 | | SHFL_CF_ACT_OVERWRITE_IF_EXISTS
|
---|
1046 | | SHFL_CF_ACT_CREATE_IF_NEW
|
---|
1047 | | SHFL_CF_ACCESS_WRITE))
|
---|
1048 | {
|
---|
1049 | /* is the guest allowed to write to this share? */
|
---|
1050 | bool fWritable;
|
---|
1051 | rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
|
---|
1052 | if (RT_FAILURE(rc) || !fWritable)
|
---|
1053 | rc = VERR_WRITE_PROTECT;
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 | if (RT_SUCCESS(rc))
|
---|
1057 | {
|
---|
1058 | if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_DIRECTORY))
|
---|
1059 | {
|
---|
1060 | rc = vbsfOpenDir (pszFullPath, pParms);
|
---|
1061 | }
|
---|
1062 | else
|
---|
1063 | {
|
---|
1064 | rc = vbsfOpenFile (pszFullPath, pParms);
|
---|
1065 | }
|
---|
1066 | }
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | /* free the path string */
|
---|
1070 | vbsfFreeFullPath(pszFullPath);
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | Log(("vbsfCreate: handle = %RX64 rc = %Vrc result=%x\n", (uint64_t)pParms->Handle, rc, pParms->Result));
|
---|
1074 |
|
---|
1075 | return rc;
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | int vbsfClose (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle)
|
---|
1079 | {
|
---|
1080 | int rc = VINF_SUCCESS;
|
---|
1081 |
|
---|
1082 | LogFlow(("vbsfClose: pClient = %p, Handle = %RX64\n",
|
---|
1083 | pClient, Handle));
|
---|
1084 |
|
---|
1085 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE);
|
---|
1086 | Assert(pHandle);
|
---|
1087 | if (!pHandle)
|
---|
1088 | return VERR_INVALID_HANDLE;
|
---|
1089 |
|
---|
1090 | switch (ShflHandleType (&pHandle->Header))
|
---|
1091 | {
|
---|
1092 | case SHFL_HF_TYPE_DIR:
|
---|
1093 | {
|
---|
1094 | rc = vbsfCloseDir (pHandle);
|
---|
1095 | break;
|
---|
1096 | }
|
---|
1097 | case SHFL_HF_TYPE_FILE:
|
---|
1098 | {
|
---|
1099 | rc = vbsfCloseFile (pHandle);
|
---|
1100 | break;
|
---|
1101 | }
|
---|
1102 | default:
|
---|
1103 | AssertFailed();
|
---|
1104 | break;
|
---|
1105 | }
|
---|
1106 | vbsfFreeFileHandle(Handle);
|
---|
1107 |
|
---|
1108 | Log(("vbsfClose: rc = %Rrc\n", rc));
|
---|
1109 |
|
---|
1110 | return rc;
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | int vbsfRead (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
|
---|
1114 | {
|
---|
1115 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_FILE);
|
---|
1116 | size_t count = 0;
|
---|
1117 | int rc;
|
---|
1118 |
|
---|
1119 | if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0)
|
---|
1120 | {
|
---|
1121 | AssertFailed();
|
---|
1122 | return VERR_INVALID_PARAMETER;
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | Log(("vbsfRead %RX64 offset %RX64 bytes %x\n", Handle, offset, *pcbBuffer));
|
---|
1126 |
|
---|
1127 | if (*pcbBuffer == 0)
|
---|
1128 | return VINF_SUCCESS; /* @todo correct? */
|
---|
1129 |
|
---|
1130 |
|
---|
1131 | rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL);
|
---|
1132 | if (rc != VINF_SUCCESS)
|
---|
1133 | {
|
---|
1134 | AssertRC(rc);
|
---|
1135 | return rc;
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | rc = RTFileRead(pHandle->file.Handle, pBuffer, *pcbBuffer, &count);
|
---|
1139 | *pcbBuffer = (uint32_t)count;
|
---|
1140 | Log(("RTFileRead returned %Vrc bytes read %x\n", rc, count));
|
---|
1141 | return rc;
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | int vbsfWrite (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
|
---|
1145 | {
|
---|
1146 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_FILE);
|
---|
1147 | size_t count = 0;
|
---|
1148 | int rc;
|
---|
1149 |
|
---|
1150 | if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0)
|
---|
1151 | {
|
---|
1152 | AssertFailed();
|
---|
1153 | return VERR_INVALID_PARAMETER;
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | Log(("vbsfWrite %RX64 offset %RX64 bytes %x\n", Handle, offset, *pcbBuffer));
|
---|
1157 |
|
---|
1158 | /* Is the guest allowed to write to this share?
|
---|
1159 | * XXX Actually this check was still done in vbsfCreate() -- RTFILE_O_WRITE cannot be set if vbsfMappingsQueryWritable() failed. */
|
---|
1160 | bool fWritable;
|
---|
1161 | rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
|
---|
1162 | if (RT_FAILURE(rc) || !fWritable)
|
---|
1163 | return VERR_WRITE_PROTECT;
|
---|
1164 |
|
---|
1165 | if (*pcbBuffer == 0)
|
---|
1166 | return VINF_SUCCESS; /** @todo correct? */
|
---|
1167 |
|
---|
1168 | rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL);
|
---|
1169 | if (rc != VINF_SUCCESS)
|
---|
1170 | {
|
---|
1171 | AssertRC(rc);
|
---|
1172 | return rc;
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | rc = RTFileWrite(pHandle->file.Handle, pBuffer, *pcbBuffer, &count);
|
---|
1176 | *pcbBuffer = (uint32_t)count;
|
---|
1177 | Log(("RTFileWrite returned %Vrc bytes written %x\n", rc, count));
|
---|
1178 | return rc;
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 |
|
---|
1182 | int vbsfFlush(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle)
|
---|
1183 | {
|
---|
1184 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_FILE);
|
---|
1185 | int rc = VINF_SUCCESS;
|
---|
1186 |
|
---|
1187 | if (pHandle == 0)
|
---|
1188 | {
|
---|
1189 | AssertFailed();
|
---|
1190 | return VERR_INVALID_HANDLE;
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | Log(("vbsfFlush %RX64\n", Handle));
|
---|
1194 | rc = RTFileFlush(pHandle->file.Handle);
|
---|
1195 | AssertRC(rc);
|
---|
1196 | return rc;
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | int vbsfDirList(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, SHFLSTRING *pPath, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer,
|
---|
1200 | uint32_t *pIndex, uint32_t *pcFiles)
|
---|
1201 | {
|
---|
1202 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR);
|
---|
1203 | PRTDIRENTRYEX pDirEntry = 0, pDirEntryOrg;
|
---|
1204 | uint32_t cbDirEntry, cbBufferOrg;
|
---|
1205 | int rc = VINF_SUCCESS;
|
---|
1206 | PSHFLDIRINFO pSFDEntry;
|
---|
1207 | PRTUTF16 pwszString;
|
---|
1208 | PRTDIR DirHandle;
|
---|
1209 | bool fUtf8;
|
---|
1210 |
|
---|
1211 | fUtf8 = BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8) != 0;
|
---|
1212 |
|
---|
1213 | if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0)
|
---|
1214 | {
|
---|
1215 | AssertFailed();
|
---|
1216 | return VERR_INVALID_PARAMETER;
|
---|
1217 | }
|
---|
1218 | Assert(pIndex && *pIndex == 0);
|
---|
1219 | DirHandle = pHandle->dir.Handle;
|
---|
1220 |
|
---|
1221 | cbDirEntry = 4096;
|
---|
1222 | pDirEntryOrg = pDirEntry = (PRTDIRENTRYEX)RTMemAlloc(cbDirEntry);
|
---|
1223 | if (pDirEntry == 0)
|
---|
1224 | {
|
---|
1225 | AssertFailed();
|
---|
1226 | return VERR_NO_MEMORY;
|
---|
1227 | }
|
---|
1228 |
|
---|
1229 | cbBufferOrg = *pcbBuffer;
|
---|
1230 | *pcbBuffer = 0;
|
---|
1231 | pSFDEntry = (PSHFLDIRINFO)pBuffer;
|
---|
1232 |
|
---|
1233 | *pIndex = 1; /* not yet complete */
|
---|
1234 | *pcFiles = 0;
|
---|
1235 |
|
---|
1236 | if (pPath)
|
---|
1237 | {
|
---|
1238 | if (pHandle->dir.SearchHandle == 0)
|
---|
1239 | {
|
---|
1240 | /* Build a host full path for the given path
|
---|
1241 | * and convert ucs2 to utf8 if necessary.
|
---|
1242 | */
|
---|
1243 | char *pszFullPath = NULL;
|
---|
1244 |
|
---|
1245 | Assert(pHandle->dir.pLastValidEntry == 0);
|
---|
1246 |
|
---|
1247 | rc = vbsfBuildFullPath (pClient, root, pPath, pPath->u16Size, &pszFullPath, NULL, true);
|
---|
1248 |
|
---|
1249 | if (VBOX_SUCCESS (rc))
|
---|
1250 | {
|
---|
1251 | rc = RTDirOpenFiltered (&pHandle->dir.SearchHandle, pszFullPath, RTDIRFILTER_WINNT);
|
---|
1252 |
|
---|
1253 | /* free the path string */
|
---|
1254 | vbsfFreeFullPath(pszFullPath);
|
---|
1255 |
|
---|
1256 | if (VBOX_FAILURE (rc))
|
---|
1257 | goto end;
|
---|
1258 | }
|
---|
1259 | else
|
---|
1260 | goto end;
|
---|
1261 | }
|
---|
1262 | Assert(pHandle->dir.SearchHandle);
|
---|
1263 | DirHandle = pHandle->dir.SearchHandle;
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | while(cbBufferOrg)
|
---|
1267 | {
|
---|
1268 | uint32_t cbDirEntrySize = cbDirEntry;
|
---|
1269 | uint32_t cbNeeded;
|
---|
1270 |
|
---|
1271 | /* Do we still have a valid last entry for the active search? If so, then return it here */
|
---|
1272 | if (pHandle->dir.pLastValidEntry)
|
---|
1273 | {
|
---|
1274 | pDirEntry = pHandle->dir.pLastValidEntry;
|
---|
1275 | }
|
---|
1276 | else
|
---|
1277 | {
|
---|
1278 | pDirEntry = pDirEntryOrg;
|
---|
1279 |
|
---|
1280 | rc = RTDirReadEx(DirHandle, pDirEntry, &cbDirEntrySize, RTFSOBJATTRADD_NOTHING);
|
---|
1281 | if (rc == VERR_NO_MORE_FILES)
|
---|
1282 | {
|
---|
1283 | *pIndex = 0; /* listing completed */
|
---|
1284 | break;
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | if (VINF_SUCCESS != rc && rc != VWRN_NO_DIRENT_INFO)
|
---|
1288 | {
|
---|
1289 | AssertFailed();
|
---|
1290 | if (rc != VERR_NO_TRANSLATION)
|
---|
1291 | break;
|
---|
1292 | else
|
---|
1293 | continue;
|
---|
1294 | }
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | cbNeeded = RT_OFFSETOF (SHFLDIRINFO, name.String);
|
---|
1298 | if (fUtf8)
|
---|
1299 | cbNeeded += pDirEntry->cbName + 1;
|
---|
1300 | else
|
---|
1301 | /* Overestimating, but that's ok */
|
---|
1302 | cbNeeded += (pDirEntry->cbName + 1) * 2;
|
---|
1303 |
|
---|
1304 | if (cbBufferOrg < cbNeeded)
|
---|
1305 | {
|
---|
1306 | /* No room, so save this directory entry, or else it's lost forever */
|
---|
1307 | pHandle->dir.pLastValidEntry = pDirEntry;
|
---|
1308 |
|
---|
1309 | if (*pcFiles == 0)
|
---|
1310 | {
|
---|
1311 | AssertFailed();
|
---|
1312 | return VINF_BUFFER_OVERFLOW; /* Return directly and don't free pDirEntry */
|
---|
1313 | }
|
---|
1314 | return VINF_SUCCESS; /* Return directly and don't free pDirEntry */
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | pSFDEntry->Info = pDirEntry->Info;
|
---|
1318 | pSFDEntry->cucShortName = 0;
|
---|
1319 |
|
---|
1320 | if (fUtf8)
|
---|
1321 | {
|
---|
1322 | void *src, *dst;
|
---|
1323 |
|
---|
1324 | src = &pDirEntry->szName[0];
|
---|
1325 | dst = &pSFDEntry->name.String.utf8[0];
|
---|
1326 |
|
---|
1327 | memcpy (dst, src, pDirEntry->cbName + 1);
|
---|
1328 |
|
---|
1329 | pSFDEntry->name.u16Size = pDirEntry->cbName + 1;
|
---|
1330 | pSFDEntry->name.u16Length = pDirEntry->cbName;
|
---|
1331 | }
|
---|
1332 | else
|
---|
1333 | {
|
---|
1334 | pSFDEntry->name.String.ucs2[0] = 0;
|
---|
1335 | pwszString = pSFDEntry->name.String.ucs2;
|
---|
1336 | int rc2 = RTStrToUtf16Ex(pDirEntry->szName, RTSTR_MAX, &pwszString, pDirEntry->cbName+1, NULL);
|
---|
1337 | AssertRC(rc2);
|
---|
1338 |
|
---|
1339 | pSFDEntry->name.u16Length = RTUtf16Len (pSFDEntry->name.String.ucs2) * 2;
|
---|
1340 | pSFDEntry->name.u16Size = pSFDEntry->name.u16Length + 2;
|
---|
1341 |
|
---|
1342 | Log(("SHFL: File name size %d\n", pSFDEntry->name.u16Size));
|
---|
1343 | Log(("SHFL: File name %ls\n", &pSFDEntry->name.String.ucs2));
|
---|
1344 |
|
---|
1345 | // adjust cbNeeded (it was overestimated before)
|
---|
1346 | cbNeeded = RT_OFFSETOF (SHFLDIRINFO, name.String) + pSFDEntry->name.u16Size;
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | pSFDEntry = (PSHFLDIRINFO)((uintptr_t)pSFDEntry + cbNeeded);
|
---|
1350 | *pcbBuffer += cbNeeded;
|
---|
1351 | cbBufferOrg-= cbNeeded;
|
---|
1352 |
|
---|
1353 | *pcFiles += 1;
|
---|
1354 |
|
---|
1355 | /* Free the saved last entry, that we've just returned */
|
---|
1356 | if (pHandle->dir.pLastValidEntry)
|
---|
1357 | {
|
---|
1358 | RTMemFree(pHandle->dir.pLastValidEntry);
|
---|
1359 | pHandle->dir.pLastValidEntry = NULL;
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | if (flags & SHFL_LIST_RETURN_ONE)
|
---|
1363 | break; /* we're done */
|
---|
1364 | }
|
---|
1365 | Assert(rc != VINF_SUCCESS || *pcbBuffer > 0);
|
---|
1366 |
|
---|
1367 | end:
|
---|
1368 | if (pDirEntry)
|
---|
1369 | RTMemFree(pDirEntry);
|
---|
1370 |
|
---|
1371 | return rc;
|
---|
1372 | }
|
---|
1373 |
|
---|
1374 | int vbsfQueryFileInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
|
---|
1375 | {
|
---|
1376 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE);
|
---|
1377 | int rc = VINF_SUCCESS;
|
---|
1378 | RTFSOBJINFO *pObjInfo = (RTFSOBJINFO *)pBuffer;
|
---|
1379 |
|
---|
1380 |
|
---|
1381 | if (pHandle == 0 || pcbBuffer == 0 || pObjInfo == 0 || *pcbBuffer < sizeof(RTFSOBJINFO))
|
---|
1382 | {
|
---|
1383 | AssertFailed();
|
---|
1384 | return VERR_INVALID_PARAMETER;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | /* @todo other options */
|
---|
1388 | Assert(flags == (SHFL_INFO_GET|SHFL_INFO_FILE));
|
---|
1389 |
|
---|
1390 | *pcbBuffer = 0;
|
---|
1391 |
|
---|
1392 | if (pHandle->Header.u32Flags & SHFL_HF_TYPE_DIR)
|
---|
1393 | {
|
---|
1394 | rc = RTDirQueryInfo(pHandle->dir.Handle, pObjInfo, RTFSOBJATTRADD_NOTHING);
|
---|
1395 | }
|
---|
1396 | else
|
---|
1397 | {
|
---|
1398 | rc = RTFileQueryInfo(pHandle->file.Handle, pObjInfo, RTFSOBJATTRADD_NOTHING);
|
---|
1399 | }
|
---|
1400 | if (rc == VINF_SUCCESS)
|
---|
1401 | {
|
---|
1402 | *pcbBuffer = sizeof(RTFSOBJINFO);
|
---|
1403 | }
|
---|
1404 | else
|
---|
1405 | AssertFailed();
|
---|
1406 |
|
---|
1407 | return rc;
|
---|
1408 | }
|
---|
1409 |
|
---|
1410 | static int vbsfSetFileInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
|
---|
1411 | {
|
---|
1412 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE);
|
---|
1413 | int rc = VINF_SUCCESS;
|
---|
1414 | RTFSOBJINFO *pSFDEntry;
|
---|
1415 |
|
---|
1416 | if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0 || *pcbBuffer < sizeof(RTFSOBJINFO))
|
---|
1417 | {
|
---|
1418 | AssertFailed();
|
---|
1419 | return VERR_INVALID_PARAMETER;
|
---|
1420 | }
|
---|
1421 |
|
---|
1422 | *pcbBuffer = 0;
|
---|
1423 | pSFDEntry = (RTFSOBJINFO *)pBuffer;
|
---|
1424 |
|
---|
1425 | Assert(flags == (SHFL_INFO_SET | SHFL_INFO_FILE));
|
---|
1426 |
|
---|
1427 | /* Change only the time values that are not zero */
|
---|
1428 | if (pHandle->Header.u32Flags & SHFL_HF_TYPE_DIR)
|
---|
1429 | {
|
---|
1430 | rc = RTDirSetTimes(pHandle->dir.Handle,
|
---|
1431 | (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ? &pSFDEntry->AccessTime : NULL,
|
---|
1432 | (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL,
|
---|
1433 | (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ? &pSFDEntry->ChangeTime: NULL,
|
---|
1434 | (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ? &pSFDEntry->BirthTime: NULL
|
---|
1435 | );
|
---|
1436 | }
|
---|
1437 | else
|
---|
1438 | {
|
---|
1439 | rc = RTFileSetTimes(pHandle->file.Handle,
|
---|
1440 | (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ? &pSFDEntry->AccessTime : NULL,
|
---|
1441 | (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL,
|
---|
1442 | (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ? &pSFDEntry->ChangeTime: NULL,
|
---|
1443 | (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ? &pSFDEntry->BirthTime: NULL
|
---|
1444 | );
|
---|
1445 | }
|
---|
1446 | if (rc != VINF_SUCCESS)
|
---|
1447 | {
|
---|
1448 | Log(("RTFileSetTimes failed with %Vrc\n", rc));
|
---|
1449 | Log(("AccessTime %VX64\n", RTTimeSpecGetNano(&pSFDEntry->AccessTime)));
|
---|
1450 | Log(("ModificationTime %VX64\n", RTTimeSpecGetNano(&pSFDEntry->ModificationTime)));
|
---|
1451 | Log(("ChangeTime %VX64\n", RTTimeSpecGetNano(&pSFDEntry->ChangeTime)));
|
---|
1452 | Log(("BirthTime %VX64\n", RTTimeSpecGetNano(&pSFDEntry->AccessTime)));
|
---|
1453 | /* temporary hack */
|
---|
1454 | rc = VINF_SUCCESS;
|
---|
1455 | }
|
---|
1456 |
|
---|
1457 | if (pHandle->Header.u32Flags & SHFL_HF_TYPE_FILE)
|
---|
1458 | {
|
---|
1459 | /* Change file attributes if necessary */
|
---|
1460 | if (pSFDEntry->Attr.fMode)
|
---|
1461 | {
|
---|
1462 | rc = RTFileSetMode((RTFILE)pHandle->file.Handle, pSFDEntry->Attr.fMode);
|
---|
1463 | if (rc != VINF_SUCCESS)
|
---|
1464 | {
|
---|
1465 | Log(("RTFileSetMode %x failed with %Vrc\n", pSFDEntry->Attr.fMode, rc));
|
---|
1466 | /* silent failure, because this tends to fail with e.g. windows guest & linux host */
|
---|
1467 | rc = VINF_SUCCESS;
|
---|
1468 | }
|
---|
1469 | }
|
---|
1470 | }
|
---|
1471 |
|
---|
1472 | if (rc == VINF_SUCCESS)
|
---|
1473 | {
|
---|
1474 | uint32_t bufsize = sizeof(*pSFDEntry);
|
---|
1475 |
|
---|
1476 | rc = vbsfQueryFileInfo(pClient, root, Handle, SHFL_INFO_GET|SHFL_INFO_FILE, &bufsize, (uint8_t *)pSFDEntry);
|
---|
1477 | if (rc == VINF_SUCCESS)
|
---|
1478 | {
|
---|
1479 | *pcbBuffer = sizeof(RTFSOBJINFO);
|
---|
1480 | }
|
---|
1481 | else
|
---|
1482 | AssertFailed();
|
---|
1483 | }
|
---|
1484 |
|
---|
1485 | return rc;
|
---|
1486 | }
|
---|
1487 |
|
---|
1488 |
|
---|
1489 | static int vbsfSetEndOfFile(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
|
---|
1490 | {
|
---|
1491 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_FILE);
|
---|
1492 | int rc = VINF_SUCCESS;
|
---|
1493 | RTFSOBJINFO *pSFDEntry;
|
---|
1494 |
|
---|
1495 | if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0 || *pcbBuffer < sizeof(RTFSOBJINFO))
|
---|
1496 | {
|
---|
1497 | AssertFailed();
|
---|
1498 | return VERR_INVALID_PARAMETER;
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 | *pcbBuffer = 0;
|
---|
1502 | pSFDEntry = (RTFSOBJINFO *)pBuffer;
|
---|
1503 |
|
---|
1504 | if (flags & SHFL_INFO_SIZE)
|
---|
1505 | {
|
---|
1506 | rc = RTFileSetSize(pHandle->file.Handle, pSFDEntry->cbObject);
|
---|
1507 | if (rc != VINF_SUCCESS)
|
---|
1508 | AssertFailed();
|
---|
1509 | }
|
---|
1510 | else
|
---|
1511 | AssertFailed();
|
---|
1512 |
|
---|
1513 | if (rc == VINF_SUCCESS)
|
---|
1514 | {
|
---|
1515 | RTFSOBJINFO fileinfo;
|
---|
1516 |
|
---|
1517 | /* Query the new object info and return it */
|
---|
1518 | rc = RTFileQueryInfo(pHandle->file.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING);
|
---|
1519 | if (rc == VINF_SUCCESS)
|
---|
1520 | {
|
---|
1521 | *pSFDEntry = fileinfo;
|
---|
1522 | *pcbBuffer = sizeof(RTFSOBJINFO);
|
---|
1523 | }
|
---|
1524 | else
|
---|
1525 | AssertFailed();
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 | return rc;
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | int vbsfQueryVolumeInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
|
---|
1532 | {
|
---|
1533 | int rc = VINF_SUCCESS;
|
---|
1534 | SHFLVOLINFO *pSFDEntry;
|
---|
1535 | char *pszFullPath = NULL;
|
---|
1536 | SHFLSTRING dummy;
|
---|
1537 |
|
---|
1538 | if (pcbBuffer == 0 || pBuffer == 0 || *pcbBuffer < sizeof(SHFLVOLINFO))
|
---|
1539 | {
|
---|
1540 | AssertFailed();
|
---|
1541 | return VERR_INVALID_PARAMETER;
|
---|
1542 | }
|
---|
1543 |
|
---|
1544 | /* @todo other options */
|
---|
1545 | Assert(flags == (SHFL_INFO_GET|SHFL_INFO_VOLUME));
|
---|
1546 |
|
---|
1547 | *pcbBuffer = 0;
|
---|
1548 | pSFDEntry = (PSHFLVOLINFO)pBuffer;
|
---|
1549 |
|
---|
1550 | ShflStringInitBuffer(&dummy, sizeof(dummy));
|
---|
1551 | rc = vbsfBuildFullPath (pClient, root, &dummy, 0, &pszFullPath, NULL);
|
---|
1552 |
|
---|
1553 | if (VBOX_SUCCESS (rc))
|
---|
1554 | {
|
---|
1555 | rc = RTFsQuerySizes(pszFullPath, &pSFDEntry->ullTotalAllocationBytes, &pSFDEntry->ullAvailableAllocationBytes, &pSFDEntry->ulBytesPerAllocationUnit, &pSFDEntry->ulBytesPerSector);
|
---|
1556 | if (rc != VINF_SUCCESS)
|
---|
1557 | goto exit;
|
---|
1558 |
|
---|
1559 | rc = RTFsQuerySerial(pszFullPath, &pSFDEntry->ulSerial);
|
---|
1560 | if (rc != VINF_SUCCESS)
|
---|
1561 | goto exit;
|
---|
1562 |
|
---|
1563 | rc = RTFsQueryProperties(pszFullPath, &pSFDEntry->fsProperties);
|
---|
1564 | if (rc != VINF_SUCCESS)
|
---|
1565 | goto exit;
|
---|
1566 |
|
---|
1567 | *pcbBuffer = sizeof(SHFLVOLINFO);
|
---|
1568 | }
|
---|
1569 | else AssertFailed();
|
---|
1570 |
|
---|
1571 | exit:
|
---|
1572 | AssertMsg(rc == VINF_SUCCESS, ("failure: rc = %Vrc\n", rc));
|
---|
1573 | /* free the path string */
|
---|
1574 | vbsfFreeFullPath(pszFullPath);
|
---|
1575 | return rc;
|
---|
1576 | }
|
---|
1577 |
|
---|
1578 | int vbsfQueryFSInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
|
---|
1579 | {
|
---|
1580 | if (pcbBuffer == 0 || pBuffer == 0)
|
---|
1581 | {
|
---|
1582 | AssertFailed();
|
---|
1583 | return VERR_INVALID_PARAMETER;
|
---|
1584 | }
|
---|
1585 |
|
---|
1586 | if (flags & SHFL_INFO_FILE)
|
---|
1587 | return vbsfQueryFileInfo(pClient, root, Handle, flags, pcbBuffer, pBuffer);
|
---|
1588 |
|
---|
1589 | if (flags & SHFL_INFO_VOLUME)
|
---|
1590 | return vbsfQueryVolumeInfo(pClient, root, flags, pcbBuffer, pBuffer);
|
---|
1591 |
|
---|
1592 | AssertFailed();
|
---|
1593 | return VERR_INVALID_PARAMETER;
|
---|
1594 | }
|
---|
1595 |
|
---|
1596 | int vbsfSetFSInfo(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint32_t flags, uint32_t *pcbBuffer, uint8_t *pBuffer)
|
---|
1597 | {
|
---|
1598 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_DIR|SHFL_HF_TYPE_FILE|SHFL_HF_TYPE_VOLUME);
|
---|
1599 |
|
---|
1600 | if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0)
|
---|
1601 | {
|
---|
1602 | AssertFailed();
|
---|
1603 | return VERR_INVALID_PARAMETER;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 | /* is the guest allowed to write to this share? */
|
---|
1607 | bool fWritable;
|
---|
1608 | int rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
|
---|
1609 | if (RT_FAILURE(rc) || !fWritable)
|
---|
1610 | return VERR_WRITE_PROTECT;
|
---|
1611 |
|
---|
1612 | if (flags & SHFL_INFO_FILE)
|
---|
1613 | return vbsfSetFileInfo(pClient, root, Handle, flags, pcbBuffer, pBuffer);
|
---|
1614 |
|
---|
1615 | if (flags & SHFL_INFO_SIZE)
|
---|
1616 | return vbsfSetEndOfFile(pClient, root, Handle, flags, pcbBuffer, pBuffer);
|
---|
1617 |
|
---|
1618 | // if (flags & SHFL_INFO_VOLUME)
|
---|
1619 | // return vbsfVolumeInfo(pClient, root, Handle, flags, pcbBuffer, pBuffer);
|
---|
1620 | AssertFailed();
|
---|
1621 | return VERR_INVALID_PARAMETER;
|
---|
1622 | }
|
---|
1623 |
|
---|
1624 | int vbsfLock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags)
|
---|
1625 | {
|
---|
1626 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_FILE);
|
---|
1627 | uint32_t fRTLock = 0;
|
---|
1628 | int rc;
|
---|
1629 |
|
---|
1630 | Assert((flags & SHFL_LOCK_MODE_MASK) != SHFL_LOCK_CANCEL);
|
---|
1631 |
|
---|
1632 | if (pHandle == 0)
|
---|
1633 | {
|
---|
1634 | AssertFailed();
|
---|
1635 | return VERR_INVALID_HANDLE;
|
---|
1636 | }
|
---|
1637 | if ( ((flags & SHFL_LOCK_MODE_MASK) == SHFL_LOCK_CANCEL)
|
---|
1638 | || (flags & SHFL_LOCK_ENTIRE)
|
---|
1639 | )
|
---|
1640 | {
|
---|
1641 | AssertFailed();
|
---|
1642 | return VERR_INVALID_PARAMETER;
|
---|
1643 | }
|
---|
1644 |
|
---|
1645 | /* Lock type */
|
---|
1646 | switch(flags & SHFL_LOCK_MODE_MASK)
|
---|
1647 | {
|
---|
1648 | case SHFL_LOCK_SHARED:
|
---|
1649 | fRTLock = RTFILE_LOCK_READ;
|
---|
1650 | break;
|
---|
1651 |
|
---|
1652 | case SHFL_LOCK_EXCLUSIVE:
|
---|
1653 | fRTLock = RTFILE_LOCK_READ | RTFILE_LOCK_WRITE;
|
---|
1654 | break;
|
---|
1655 |
|
---|
1656 | default:
|
---|
1657 | AssertFailed();
|
---|
1658 | return VERR_INVALID_PARAMETER;
|
---|
1659 | }
|
---|
1660 |
|
---|
1661 | /* Lock wait type */
|
---|
1662 | if (flags & SHFL_LOCK_WAIT)
|
---|
1663 | fRTLock |= RTFILE_LOCK_WAIT;
|
---|
1664 | else
|
---|
1665 | fRTLock |= RTFILE_LOCK_IMMEDIATELY;
|
---|
1666 |
|
---|
1667 | #ifdef RT_OS_WINDOWS
|
---|
1668 | rc = RTFileLock(pHandle->file.Handle, fRTLock, offset, length);
|
---|
1669 | if (rc != VINF_SUCCESS)
|
---|
1670 | Log(("RTFileLock %RTfile %RX64 %RX64 failed with %Rrc\n", pHandle->file.Handle, offset, length, rc));
|
---|
1671 | #else
|
---|
1672 | Log(("vbsfLock: Pretend success handle=%x\n", Handle));
|
---|
1673 | rc = VINF_SUCCESS;
|
---|
1674 | #endif
|
---|
1675 | return rc;
|
---|
1676 | }
|
---|
1677 |
|
---|
1678 | int vbsfUnlock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags)
|
---|
1679 | {
|
---|
1680 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(Handle, SHFL_HF_TYPE_FILE);
|
---|
1681 | int rc;
|
---|
1682 |
|
---|
1683 | Assert((flags & SHFL_LOCK_MODE_MASK) == SHFL_LOCK_CANCEL);
|
---|
1684 |
|
---|
1685 | if (pHandle == 0)
|
---|
1686 | {
|
---|
1687 | return VERR_INVALID_HANDLE;
|
---|
1688 | }
|
---|
1689 | if ( ((flags & SHFL_LOCK_MODE_MASK) != SHFL_LOCK_CANCEL)
|
---|
1690 | || (flags & SHFL_LOCK_ENTIRE)
|
---|
1691 | )
|
---|
1692 | {
|
---|
1693 | return VERR_INVALID_PARAMETER;
|
---|
1694 | }
|
---|
1695 |
|
---|
1696 | #ifdef RT_OS_WINDOWS
|
---|
1697 | rc = RTFileUnlock(pHandle->file.Handle, offset, length);
|
---|
1698 | if (rc != VINF_SUCCESS)
|
---|
1699 | Log(("RTFileUnlock %RTfile %RX64 %RTX64 failed with %Rrc\n", pHandle->file.Handle, offset, length, rc));
|
---|
1700 | #else
|
---|
1701 | Log(("vbsfUnlock: Pretend success handle=%x\n", Handle));
|
---|
1702 | rc = VINF_SUCCESS;
|
---|
1703 | #endif
|
---|
1704 |
|
---|
1705 | return rc;
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 |
|
---|
1709 | int vbsfRemove(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, uint32_t flags)
|
---|
1710 | {
|
---|
1711 | int rc = VINF_SUCCESS;
|
---|
1712 |
|
---|
1713 | /* Validate input */
|
---|
1714 | if ( flags & ~(SHFL_REMOVE_FILE|SHFL_REMOVE_DIR)
|
---|
1715 | || cbPath == 0
|
---|
1716 | || pPath == 0)
|
---|
1717 | {
|
---|
1718 | AssertFailed();
|
---|
1719 | return VERR_INVALID_PARAMETER;
|
---|
1720 | }
|
---|
1721 |
|
---|
1722 | /* Build a host full path for the given path
|
---|
1723 | * and convert ucs2 to utf8 if necessary.
|
---|
1724 | */
|
---|
1725 | char *pszFullPath = NULL;
|
---|
1726 |
|
---|
1727 | rc = vbsfBuildFullPath (pClient, root, pPath, cbPath, &pszFullPath, NULL);
|
---|
1728 | if (VBOX_SUCCESS (rc))
|
---|
1729 | {
|
---|
1730 | /* is the guest allowed to write to this share? */
|
---|
1731 | bool fWritable;
|
---|
1732 | rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
|
---|
1733 | if (RT_FAILURE(rc) || !fWritable)
|
---|
1734 | rc = VERR_WRITE_PROTECT;
|
---|
1735 |
|
---|
1736 | if (VBOX_SUCCESS (rc))
|
---|
1737 | {
|
---|
1738 | if (flags & SHFL_REMOVE_FILE)
|
---|
1739 | rc = RTFileDelete(pszFullPath);
|
---|
1740 | else
|
---|
1741 | rc = RTDirRemove(pszFullPath);
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | #ifndef DEBUG_dmik
|
---|
1745 | // VERR_ACCESS_DENIED for example?
|
---|
1746 | // Assert(rc == VINF_SUCCESS || rc == VERR_DIR_NOT_EMPTY);
|
---|
1747 | #endif
|
---|
1748 | /* free the path string */
|
---|
1749 | vbsfFreeFullPath(pszFullPath);
|
---|
1750 | }
|
---|
1751 | return rc;
|
---|
1752 | }
|
---|
1753 |
|
---|
1754 |
|
---|
1755 | int vbsfRename(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pSrc, SHFLSTRING *pDest, uint32_t flags)
|
---|
1756 | {
|
---|
1757 | int rc = VINF_SUCCESS;
|
---|
1758 |
|
---|
1759 | /* Validate input */
|
---|
1760 | if ( flags & ~(SHFL_REMOVE_FILE|SHFL_REMOVE_DIR|SHFL_RENAME_REPLACE_IF_EXISTS)
|
---|
1761 | || pSrc == 0
|
---|
1762 | || pDest == 0)
|
---|
1763 | {
|
---|
1764 | AssertFailed();
|
---|
1765 | return VERR_INVALID_PARAMETER;
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | /* Build a host full path for the given path
|
---|
1769 | * and convert ucs2 to utf8 if necessary.
|
---|
1770 | */
|
---|
1771 | char *pszFullPathSrc = NULL;
|
---|
1772 | char *pszFullPathDest = NULL;
|
---|
1773 |
|
---|
1774 | rc = vbsfBuildFullPath (pClient, root, pSrc, pSrc->u16Size, &pszFullPathSrc, NULL);
|
---|
1775 | if (rc != VINF_SUCCESS)
|
---|
1776 | return rc;
|
---|
1777 |
|
---|
1778 | rc = vbsfBuildFullPath (pClient, root, pDest, pDest->u16Size, &pszFullPathDest, NULL);
|
---|
1779 | if (VBOX_SUCCESS (rc))
|
---|
1780 | {
|
---|
1781 | Log(("Rename %s to %s\n", pszFullPathSrc, pszFullPathDest));
|
---|
1782 |
|
---|
1783 | /* is the guest allowed to write to this share? */
|
---|
1784 | bool fWritable;
|
---|
1785 | rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
|
---|
1786 | if (RT_FAILURE(rc) || !fWritable)
|
---|
1787 | rc = VERR_WRITE_PROTECT;
|
---|
1788 |
|
---|
1789 | if (VBOX_SUCCESS (rc))
|
---|
1790 | {
|
---|
1791 | if (flags & SHFL_RENAME_FILE)
|
---|
1792 | {
|
---|
1793 | rc = RTFileMove(pszFullPathSrc, pszFullPathDest, (flags & SHFL_RENAME_REPLACE_IF_EXISTS) ? RTFILEMOVE_FLAGS_REPLACE : 0);
|
---|
1794 | }
|
---|
1795 | else
|
---|
1796 | {
|
---|
1797 | /* NT ignores the REPLACE flag and simply return and already exists error. */
|
---|
1798 | rc = RTDirRename(pszFullPathSrc, pszFullPathDest, (flags & SHFL_RENAME_REPLACE_IF_EXISTS) ? RTPATHRENAME_FLAGS_REPLACE : 0);
|
---|
1799 | }
|
---|
1800 | }
|
---|
1801 |
|
---|
1802 | #ifndef DEBUG_dmik
|
---|
1803 | AssertRC(rc);
|
---|
1804 | #endif
|
---|
1805 | /* free the path string */
|
---|
1806 | vbsfFreeFullPath(pszFullPathDest);
|
---|
1807 | }
|
---|
1808 | /* free the path string */
|
---|
1809 | vbsfFreeFullPath(pszFullPathSrc);
|
---|
1810 | return rc;
|
---|
1811 | }
|
---|
1812 |
|
---|
1813 | /*
|
---|
1814 | * Clean up our mess by freeing all handles that are still valid.
|
---|
1815 | *
|
---|
1816 | */
|
---|
1817 | int vbsfDisconnect(SHFLCLIENTDATA *pClient)
|
---|
1818 | {
|
---|
1819 | for (int i=0;i<SHFLHANDLE_MAX;i++)
|
---|
1820 | {
|
---|
1821 | SHFLFILEHANDLE *pHandle = (SHFLFILEHANDLE *)vbsfQueryHandle(i, SHFL_HF_TYPE_MASK);
|
---|
1822 |
|
---|
1823 | if (pHandle)
|
---|
1824 | {
|
---|
1825 | Log(("Open handle %08x\n", i));
|
---|
1826 | vbsfClose(pClient, SHFL_HANDLE_ROOT /* incorrect, but it's not important */, (SHFLHANDLE)i);
|
---|
1827 | }
|
---|
1828 | }
|
---|
1829 | return VINF_SUCCESS;
|
---|
1830 | }
|
---|