1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
|
/* $Id: DnDTransferObject.cpp $ */
/** @file
* DnD - Transfer object implemenation for handling creation/reading/writing to files and directories on host or guest side.
*/
/*
* Copyright (C) 2014-2023 Oracle and/or its affiliates.
*
* This file is part of VirtualBox base platform packages, as
* available from https://www.virtualbox.org.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, in version 3 of the
* License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses>.
*
* SPDX-License-Identifier: GPL-3.0-only
*/
/*********************************************************************************************************************************
* Header Files *
*********************************************************************************************************************************/
#define LOG_GROUP LOG_GROUP_GUEST_DND
#include <VBox/GuestHost/DragAndDrop.h>
#include <iprt/dir.h>
#include <iprt/err.h>
#include <iprt/file.h>
#include <iprt/fs.h>
#include <iprt/path.h>
#include <iprt/string.h>
#include <iprt/uri.h>
#include <VBox/log.h>
/*********************************************************************************************************************************
* Prototypes *
*********************************************************************************************************************************/
static int dndTransferObjectCloseInternal(PDNDTRANSFEROBJECT pObj);
static int dndTransferObjectQueryInfoInternal(PDNDTRANSFEROBJECT pObj);
/**
* Initializes the object, internal version.
*
* @returns VBox status code.
* @param pObj DnD transfer object to initialize.
*/
static int dndTransferObjectInitInternal(PDNDTRANSFEROBJECT pObj)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
pObj->enmType = DNDTRANSFEROBJTYPE_UNKNOWN;
pObj->idxDst = 0;
pObj->pszPath = NULL;
RT_ZERO(pObj->u);
return VINF_SUCCESS;
}
/**
* Initializes the object.
*
* @returns VBox status code.
* @param pObj DnD transfer object to initialize.
*/
int DnDTransferObjectInit(PDNDTRANSFEROBJECT pObj)
{
return dndTransferObjectInitInternal(pObj);
}
/**
* Initializes the object with an expected object type and file path.
*
* @returns VBox status code.
* @param pObj DnD transfer object to initialize.
* @param enmType Type we expect this object to be.
* @param pcszPathSrcAbs Absolute source (local) path of file this object represents. Can be empty (e.g. for root stuff).
* @param pcszPathDst Relative path of file this object represents at the destination.
* Together with \a pcszPathSrcAbs this represents the complete absolute local path.
*/
int DnDTransferObjectInitEx(PDNDTRANSFEROBJECT pObj,
DNDTRANSFEROBJTYPE enmType, const char *pcszPathSrcAbs, const char *pcszPathDst)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
AssertReturn(pObj->enmType == DNDTRANSFEROBJTYPE_UNKNOWN, VERR_WRONG_ORDER); /* Already initialized? */
/* pcszPathSrcAbs can be empty. */
AssertPtrReturn(pcszPathDst, VERR_INVALID_POINTER);
int rc = dndTransferObjectInitInternal(pObj);
AssertRCReturn(rc, rc);
rc = DnDPathValidate(pcszPathDst, false /* Does not need to exist */);
AssertRCReturn(rc, rc);
char szPath[RTPATH_MAX + 1];
/* Save the index (in characters) where the first destination segment starts. */
if ( pcszPathSrcAbs
&& RTStrNLen(pcszPathSrcAbs, RTSTR_MAX))
{
rc = DnDPathValidate(pcszPathSrcAbs, false /* Does not need to exist */);
if (RT_FAILURE(rc))
return rc;
rc = RTStrCopy(szPath, sizeof(szPath), pcszPathSrcAbs);
if (RT_SUCCESS(rc))
rc = RTPathEnsureTrailingSeparator(szPath, sizeof(szPath)) == 0 ? VERR_BUFFER_OVERFLOW : VINF_SUCCESS;
/* Save the index (in characters) where the destination part starts. */
pObj->idxDst = (uint16_t)RTStrNLen(szPath, RTPATH_MAX);
AssertReturn(pObj->idxDst <= RTPATH_MAX, VERR_INVALID_PARAMETER);
}
else
{
szPath[0] = '\0'; /* Init empty string. */
pObj->idxDst = 0;
}
if (RT_FAILURE(rc))
return rc;
/* Append the destination part. */
rc = RTPathAppend(szPath, sizeof(szPath), pcszPathDst);
if ( RT_SUCCESS(rc)
&& enmType == DNDTRANSFEROBJTYPE_DIRECTORY)
rc = RTPathEnsureTrailingSeparator(szPath, sizeof(szPath)) == 0 ? VERR_BUFFER_OVERFLOW : VINF_SUCCESS;
if (RT_FAILURE(rc))
return rc;
pObj->pszPath = RTStrDup(szPath);
if (!pObj->pszPath)
return VERR_NO_MEMORY;
/* Convert paths into transport format. */
rc = DnDPathConvert(pObj->pszPath, strlen(pObj->pszPath), DNDPATHCONVERT_FLAGS_TRANSPORT);
if (RT_FAILURE(rc))
{
RTStrFree(pObj->pszPath);
pObj->pszPath = NULL;
return rc;
}
LogFlowFunc(("enmType=%RU32, pcszPathSrcAbs=%s, pcszPathDst=%s -> pszPath=%s\n",
enmType, pcszPathSrcAbs, pcszPathDst, pObj->pszPath));
pObj->enmType = enmType;
return VINF_SUCCESS;
}
/**
* Destroys a DnD transfer object.
*
* @param pObj DnD transfer object to destroy.
*/
void DnDTransferObjectDestroy(PDNDTRANSFEROBJECT pObj)
{
if (!pObj)
return;
DnDTransferObjectReset(pObj);
}
/**
* Closes the object's internal handles (to files / ...).
*
* @returns VBox status code.
* @param pObj DnD transfer object to close internally.
*/
static int dndTransferObjectCloseInternal(PDNDTRANSFEROBJECT pObj)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
int rc = VINF_SUCCESS;
if (pObj->pszPath)
LogRel2(("DnD: Closing '%s'\n", pObj->pszPath));
switch (pObj->enmType)
{
case DNDTRANSFEROBJTYPE_FILE:
{
if (RTFileIsValid(pObj->u.File.hFile))
{
rc = RTFileClose(pObj->u.File.hFile);
if (RT_SUCCESS(rc))
{
pObj->u.File.hFile = NIL_RTFILE;
RT_ZERO(pObj->u.File.objInfo);
}
else
LogRel(("DnD: Closing file '%s' failed with %Rrc\n", pObj->pszPath, rc));
}
break;
}
case DNDTRANSFEROBJTYPE_DIRECTORY:
{
if (RTDirIsValid(pObj->u.Dir.hDir))
{
rc = RTDirClose(pObj->u.Dir.hDir);
if (RT_SUCCESS(rc))
{
pObj->u.Dir.hDir = NIL_RTDIR;
RT_ZERO(pObj->u.Dir.objInfo);
}
else
LogRel(("DnD: Closing directory '%s' failed with %Rrc\n", pObj->pszPath, rc));
}
break;
}
default:
break;
}
return rc;
}
/**
* Closes the object.
* This also closes the internal handles associated with the object (to files / ...).
*
* @returns VBox status code.
* @param pObj DnD transfer object to close.
*/
int DnDTransferObjectClose(PDNDTRANSFEROBJECT pObj)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
return dndTransferObjectCloseInternal(pObj);
}
/**
* Returns the absolute source path of the object.
*
* @return Absolute source path of the object.
* @param pObj DnD transfer object to get source path for.
*/
const char *DnDTransferObjectGetSourcePath(PDNDTRANSFEROBJECT pObj)
{
AssertPtrReturn(pObj, NULL);
return pObj->pszPath;
}
/**
* Returns the (relative) destination path of the object, in transport style.
*
* @return Relative destination path of the object, or NULL if not set.
* @param pObj DnD transfer object to get destination path for.
*/
const char *DnDTransferObjectGetDestPath(PDNDTRANSFEROBJECT pObj)
{
AssertPtrReturn(pObj, NULL);
if (!pObj->pszPath)
return NULL;
AssertReturn(strlen(pObj->pszPath) >= pObj->idxDst, NULL);
return &pObj->pszPath[pObj->idxDst];
}
/**
* Returns the (relative) destination path of the object, extended version.
*
* @return VBox status code, or VERR_NOT_FOUND if not initialized yet.
* @param pObj DnD transfer object to get destination path for.
* @param enmStyle Which path style to return.
* @param pszBuf Where to store the path.
* @param cbBuf Size (in bytes) where to store the path.
*/
int DnDTransferObjectGetDestPathEx(PDNDTRANSFEROBJECT pObj, DNDTRANSFEROBJPATHSTYLE enmStyle, char *pszBuf, size_t cbBuf)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
AssertPtrReturn(pszBuf, VERR_INVALID_POINTER);
AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
if (!pObj->pszPath)
return VERR_NOT_FOUND;
AssertReturn(strlen(pObj->pszPath) >= pObj->idxDst, VERR_INTERNAL_ERROR);
int rc = RTStrCopy(pszBuf, cbBuf, &pObj->pszPath[pObj->idxDst]);
if ( RT_SUCCESS(rc)
&& enmStyle == DNDTRANSFEROBJPATHSTYLE_DOS)
rc = DnDPathConvert(pszBuf, cbBuf, DNDPATHCONVERT_FLAGS_TO_DOS);
return rc;
}
/**
* Returns the directory / file mode of the object.
*
* @return File / directory mode.
* @param pObj DnD transfer object to get directory / file mode for.
*/
RTFMODE DnDTransferObjectGetMode(PDNDTRANSFEROBJECT pObj)
{
AssertPtrReturn(pObj, 0);
switch (pObj->enmType)
{
case DNDTRANSFEROBJTYPE_FILE:
return pObj->u.File.objInfo.Attr.fMode;
case DNDTRANSFEROBJTYPE_DIRECTORY:
return pObj->u.Dir.objInfo.Attr.fMode;
default:
break;
}
return 0;
}
/**
* Returns the bytes already processed (read / written).
*
* Note: Only applies if the object is of type DnDTransferObjectType_File.
*
* @return Bytes already processed (read / written).
* @param pObj DnD transfer object to get processed bytes for.
*/
uint64_t DnDTransferObjectGetProcessed(PDNDTRANSFEROBJECT pObj)
{
if (pObj->enmType == DNDTRANSFEROBJTYPE_FILE)
return pObj->u.File.cbProcessed;
return 0;
}
/**
* Returns the file's logical size (in bytes).
*
* Note: Only applies if the object is of type DnDTransferObjectType_File.
*
* @return The file's logical size (in bytes).
* @param pObj DnD transfer object to get size for.
*/
uint64_t DnDTransferObjectGetSize(PDNDTRANSFEROBJECT pObj)
{
if (pObj->enmType == DNDTRANSFEROBJTYPE_FILE)
return pObj->u.File.cbToProcess;
return 0;
}
/**
* Returns the object's type.
*
* @return The object's type.
* @param pObj DnD transfer object to get type for.
*/
DNDTRANSFEROBJTYPE DnDTransferObjectGetType(PDNDTRANSFEROBJECT pObj)
{
return pObj->enmType;
}
/**
* Returns whether the processing of the object is complete or not.
* For file objects this means that all bytes have been processed.
*
* @return True if complete, False if not.
* @param pObj DnD transfer object to get completion status for.
*/
bool DnDTransferObjectIsComplete(PDNDTRANSFEROBJECT pObj)
{
bool fComplete;
switch (pObj->enmType)
{
case DNDTRANSFEROBJTYPE_FILE:
Assert(pObj->u.File.cbProcessed <= pObj->u.File.cbToProcess);
fComplete = pObj->u.File.cbProcessed == pObj->u.File.cbToProcess;
break;
case DNDTRANSFEROBJTYPE_DIRECTORY:
fComplete = true;
break;
default:
fComplete = true;
break;
}
return fComplete;
}
/**
* Returns whether the object is in an open state or not.
* @param pObj DnD transfer object to get open status for.
*/
bool DnDTransferObjectIsOpen(PDNDTRANSFEROBJECT pObj)
{
switch (pObj->enmType)
{
case DNDTRANSFEROBJTYPE_FILE: return RTFileIsValid(pObj->u.File.hFile);
case DNDTRANSFEROBJTYPE_DIRECTORY: return RTDirIsValid(pObj->u.Dir.hDir);
default: break;
}
return false;
}
/**
* Open the object with a specific file type, and, depending on the type, specifying additional parameters.
*
* @return IPRT status code.
* @param pObj DnD transfer object to open.
* @param fOpen Open mode to use; only valid for file objects.
* @param fMode File mode to set; only valid for file objects. Depends on fOpen and and can be 0.
* @param fFlags Additional DnD transfer object flags.
*/
int DnDTransferObjectOpen(PDNDTRANSFEROBJECT pObj, uint64_t fOpen, RTFMODE fMode, DNDTRANSFEROBJECTFLAGS fFlags)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
AssertReturn(fOpen, VERR_INVALID_FLAGS);
/* fMode is optional. */
AssertReturn(!(fFlags & ~DNDTRANSFEROBJECT_FLAGS_VALID_MASK), VERR_INVALID_FLAGS);
RT_NOREF1(fFlags);
int rc = VINF_SUCCESS;
LogFlowFunc(("pszPath=%s, fOpen=0x%x, fMode=0x%x, fFlags=0x%x\n", pObj->pszPath, fOpen, fMode, fFlags));
switch (pObj->enmType)
{
case DNDTRANSFEROBJTYPE_FILE:
{
LogRel2(("DnD: Opening file '%s'\n", pObj->pszPath));
/*
* Open files on the source with RTFILE_O_DENY_WRITE to prevent races
* where the OS writes to the file while the destination side transfers
* it over.
*/
rc = RTFileOpen(&pObj->u.File.hFile, pObj->pszPath, fOpen);
if (RT_SUCCESS(rc))
{
if ( (fOpen & RTFILE_O_WRITE) /* Only set the file mode on write. */
&& fMode /* Some file mode to set specified? */)
{
rc = RTFileSetMode(pObj->u.File.hFile, fMode);
if (RT_FAILURE(rc))
LogRel(("DnD: Setting mode %#x for file '%s' failed with %Rrc\n", fMode, pObj->pszPath, rc));
}
else if (fOpen & RTFILE_O_READ)
{
rc = dndTransferObjectQueryInfoInternal(pObj);
}
}
else
LogRel(("DnD: Opening file '%s' failed with %Rrc\n", pObj->pszPath, rc));
if (RT_SUCCESS(rc))
{
LogFlowFunc(("File cbObject=%RU64, fMode=0x%x\n",
pObj->u.File.objInfo.cbObject, pObj->u.File.objInfo.Attr.fMode));
pObj->u.File.cbToProcess = pObj->u.File.objInfo.cbObject;
pObj->u.File.cbProcessed = 0;
}
break;
}
case DNDTRANSFEROBJTYPE_DIRECTORY:
{
LogRel2(("DnD: Opening directory '%s'\n", pObj->pszPath));
rc = RTDirOpen(&pObj->u.Dir.hDir, pObj->pszPath);
if (RT_SUCCESS(rc))
{
rc = dndTransferObjectQueryInfoInternal(pObj);
}
else
LogRel(("DnD: Opening directory '%s' failed with %Rrc\n", pObj->pszPath, rc));
break;
}
default:
rc = VERR_NOT_IMPLEMENTED;
break;
}
LogFlowFuncLeaveRC(rc);
return rc;
}
/**
* Queries information about the object using a specific view, internal version.
*
* @return IPRT status code.
* @param pObj DnD transfer object to query info for.
*/
static int dndTransferObjectQueryInfoInternal(PDNDTRANSFEROBJECT pObj)
{
int rc;
switch (pObj->enmType)
{
case DNDTRANSFEROBJTYPE_FILE:
AssertMsgReturn(RTFileIsValid(pObj->u.File.hFile), ("Object has invalid file handle\n"), VERR_INVALID_STATE);
rc = RTFileQueryInfo(pObj->u.File.hFile, &pObj->u.File.objInfo, RTFSOBJATTRADD_NOTHING);
break;
case DNDTRANSFEROBJTYPE_DIRECTORY:
AssertMsgReturn(RTDirIsValid(pObj->u.Dir.hDir), ("Object has invalid directory handle\n"), VERR_INVALID_STATE);
rc = RTDirQueryInfo(pObj->u.Dir.hDir, &pObj->u.Dir.objInfo, RTFSOBJATTRADD_NOTHING);
break;
default:
rc = VERR_NOT_IMPLEMENTED;
break;
}
if (RT_FAILURE(rc))
LogRel(("DnD: Querying information for '%s' failed with %Rrc\n", pObj->pszPath, rc));
return rc;
}
/**
* Queries information about the object using a specific view.
*
* @return IPRT status code.
* @param pObj DnD transfer object to query info for.
*/
int DnDTransferObjectQueryInfo(PDNDTRANSFEROBJECT pObj)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
return dndTransferObjectQueryInfoInternal(pObj);
}
/**
* Reads data from the object. Only applies to files objects.
*
* @return IPRT status code.
* @param pObj DnD transfer object to read data from.
* @param pvBuf Buffer where to store the read data.
* @param cbBuf Size (in bytes) of the buffer.
* @param pcbRead Pointer where to store how many bytes were read. Optional.
*/
int DnDTransferObjectRead(PDNDTRANSFEROBJECT pObj, void *pvBuf, size_t cbBuf, uint32_t *pcbRead)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
/* pcbRead is optional. */
size_t cbRead = 0;
int rc;
switch (pObj->enmType)
{
case DNDTRANSFEROBJTYPE_FILE:
{
rc = RTFileRead(pObj->u.File.hFile, pvBuf, cbBuf, &cbRead);
if (RT_SUCCESS(rc))
{
pObj->u.File.cbProcessed += cbRead;
Assert(pObj->u.File.cbProcessed <= pObj->u.File.cbToProcess);
/* End of file reached or error occurred? */
if ( pObj->u.File.cbToProcess
&& pObj->u.File.cbProcessed == pObj->u.File.cbToProcess)
{
rc = VINF_EOF;
}
}
else
LogRel(("DnD: Reading from file '%s' failed with %Rrc\n", pObj->pszPath, rc));
break;
}
case DNDTRANSFEROBJTYPE_DIRECTORY:
{
rc = VINF_SUCCESS;
break;
}
default:
rc = VERR_NOT_IMPLEMENTED;
break;
}
if (RT_SUCCESS(rc))
{
if (pcbRead)
*pcbRead = (uint32_t)cbRead;
}
LogFlowFunc(("Returning cbRead=%zu, rc=%Rrc\n", cbRead, rc));
return rc;
}
/**
* Resets the object's state and closes all related handles.
*
* @param pObj DnD transfer object to reset.
*/
void DnDTransferObjectReset(PDNDTRANSFEROBJECT pObj)
{
AssertPtrReturnVoid(pObj);
LogFlowFuncEnter();
int vrc2 = dndTransferObjectCloseInternal(pObj);
AssertRCReturnVoid(vrc2);
pObj->enmType = DNDTRANSFEROBJTYPE_UNKNOWN;
pObj->idxDst = 0;
RTStrFree(pObj->pszPath);
pObj->pszPath = NULL;
RT_ZERO(pObj->u);
}
/**
* Sets the bytes to process by the object.
*
* Note: Only applies if the object is of type DnDTransferObjectType_File.
*
* @return IPRT return code.
* @param pObj DnD transfer object to set size for.
* @param cbSize Size (in bytes) to process.
*/
int DnDTransferObjectSetSize(PDNDTRANSFEROBJECT pObj, uint64_t cbSize)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
AssertReturn(pObj->enmType == DNDTRANSFEROBJTYPE_FILE, VERR_INVALID_PARAMETER);
/** @todo Implement sparse file support here. */
pObj->u.File.cbToProcess = cbSize;
return VINF_SUCCESS;
}
/**
* Writes data to an object. Only applies to file objects.
*
* @return IPRT status code.
* @param pObj DnD transfer object to write to.
* @param pvBuf Buffer of data to write.
* @param cbBuf Size (in bytes) of data to write.
* @param pcbWritten Pointer where to store how many bytes were written. Optional.
*/
int DnDTransferObjectWrite(PDNDTRANSFEROBJECT pObj, const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten)
{
AssertPtrReturn(pObj, VERR_INVALID_POINTER);
AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
/* pcbWritten is optional. */
size_t cbWritten = 0;
int rc;
switch (pObj->enmType)
{
case DNDTRANSFEROBJTYPE_FILE:
{
rc = RTFileWrite(pObj->u.File.hFile, pvBuf, cbBuf, &cbWritten);
if (RT_SUCCESS(rc))
{
pObj->u.File.cbProcessed += cbWritten;
}
else
LogRel(("DnD: Writing to file '%s' failed with %Rrc\n", pObj->pszPath, rc));
break;
}
case DNDTRANSFEROBJTYPE_DIRECTORY:
{
rc = VINF_SUCCESS;
break;
}
default:
rc = VERR_NOT_IMPLEMENTED;
break;
}
if (RT_SUCCESS(rc))
{
if (pcbWritten)
*pcbWritten = (uint32_t)cbWritten;
}
LogFlowFunc(("Returning cbWritten=%zu, rc=%Rrc\n", cbWritten, rc));
return rc;
}
|