Changeset 71782 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 9, 2018 3:49:19 PM (7 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestFileImpl.h
r71406 r71782 56 56 int i_onRemove(void); 57 57 int i_openFile(uint32_t uTimeoutMS, int *pGuestRc); 58 int i_queryInfo(GuestFsObjData &objData, int *prcGuest); 58 59 int i_readData(uint32_t uSize, uint32_t uTimeoutMS, void* pvData, uint32_t cbData, uint32_t* pcbRead); 59 60 int i_readDataAt(uint64_t uOffset, uint32_t uSize, uint32_t uTimeoutMS, -
trunk/src/VBox/Main/src-client/GuestFileImpl.cpp
r71636 r71782 434 434 return VERR_INVALID_PARAMETER; 435 435 436 int rc = VINF_SUCCESS;437 438 436 int idx = 1; /* Current parameter index. */ 439 437 CALLBACKDATA_FILE_NOTIFY dataCb; … … 444 442 int rcGuest = (int)dataCb.rc; /* uint32_t vs. int. */ 445 443 446 LogFlowFunc(("uType=%RU32, rcGuest=%Rrc\n", 447 dataCb.uType, rcGuest)); 444 LogFlowThisFunc(("uType=%RU32, rcGuest=%Rrc\n", dataCb.uType, rcGuest)); 448 445 449 446 if (RT_FAILURE(rcGuest)) … … 457 454 } 458 455 456 AssertMsg(mObjectID == VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCbCtx->uContextID), 457 ("File ID %RU32 does not match object ID %RU32\n", mObjectID, 458 VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCbCtx->uContextID))); 459 460 int rc = VERR_NOT_SUPPORTED; /* Play safe by default. */ 461 459 462 switch (dataCb.uType) 460 463 { 461 464 case GUEST_FILE_NOTIFYTYPE_ERROR: 462 465 { 463 int rc2 = i_setFileStatus(FileStatus_Error, rcGuest); 464 AssertRC(rc2); 465 466 rc = i_setFileStatus(FileStatus_Error, rcGuest); 466 467 break; 467 468 } … … 471 472 if (pSvcCbData->mParms == 4) 472 473 { 473 pSvcCbData->mpaParms[idx++].getUInt32(&dataCb.u.open.uHandle); 474 475 AssertMsg(mObjectID == VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCbCtx->uContextID), 476 ("File ID %RU32 does not match object ID %RU32\n", mObjectID, 477 VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCbCtx->uContextID))); 474 rc = pSvcCbData->mpaParms[idx++].getUInt32(&dataCb.u.open.uHandle); 475 if (RT_FAILURE(rc)) 476 break; 478 477 479 478 /* Set the process status. */ 480 int rc2 = i_setFileStatus(FileStatus_Open, rcGuest); 481 AssertRC(rc2); 479 rc = i_setFileStatus(FileStatus_Open, rcGuest); 482 480 } 483 else484 rc = VERR_NOT_SUPPORTED;485 486 481 break; 487 482 } … … 489 484 case GUEST_FILE_NOTIFYTYPE_CLOSE: 490 485 { 491 int rc2 = i_setFileStatus(FileStatus_Closed, rcGuest); 492 AssertRC(rc2); 493 486 rc = i_setFileStatus(FileStatus_Closed, rcGuest); 494 487 break; 495 488 } … … 499 492 if (pSvcCbData->mParms == 4) 500 493 { 501 pSvcCbData->mpaParms[idx++].getPointer(&dataCb.u.read.pvData, 502 &dataCb.u.read.cbData); 503 uint32_t cbRead = dataCb.u.read.cbData; 494 rc = pSvcCbData->mpaParms[idx++].getPointer(&dataCb.u.read.pvData, &dataCb.u.read.cbData); 495 if (RT_FAILURE(rc)) 496 break; 497 498 const uint32_t cbRead = dataCb.u.read.cbData; 499 500 Log3ThisFunc(("cbRead=%RU32\n", cbRead)); 504 501 505 502 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); … … 515 512 cbRead, ComSafeArrayAsInParam(data)); 516 513 } 517 else518 rc = VERR_NOT_SUPPORTED;519 514 break; 520 515 } … … 524 519 if (pSvcCbData->mParms == 4) 525 520 { 526 pSvcCbData->mpaParms[idx++].getUInt32(&dataCb.u.write.cbWritten); 521 rc = pSvcCbData->mpaParms[idx++].getUInt32(&dataCb.u.write.cbWritten); 522 if (RT_FAILURE(rc)) 523 break; 524 525 Log3ThisFunc(("cbWritten=%RU32\n", dataCb.u.write.cbWritten)); 527 526 528 527 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 529 528 530 529 mData.mOffCurrent += dataCb.u.write.cbWritten; 531 uint64_t uOffCurrent = mData.mOffCurrent;532 530 533 531 alock.release(); 534 532 535 fireGuestFileWriteEvent(mEventSource, mSession, this, uOffCurrent,533 fireGuestFileWriteEvent(mEventSource, mSession, this, mData.mOffCurrent, 536 534 dataCb.u.write.cbWritten); 537 535 } 538 else539 rc = VERR_NOT_SUPPORTED;540 536 break; 541 537 } … … 545 541 if (pSvcCbData->mParms == 4) 546 542 { 547 pSvcCbData->mpaParms[idx++].getUInt64(&dataCb.u.seek.uOffActual); 543 rc = pSvcCbData->mpaParms[idx++].getUInt64(&dataCb.u.seek.uOffActual); 544 if (RT_FAILURE(rc)) 545 break; 546 547 Log3ThisFunc(("uOffActual=%RU64\n", dataCb.u.seek.uOffActual)); 548 548 549 549 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); … … 553 553 alock.release(); 554 554 555 fireGuestFileOffsetChangedEvent(mEventSource, mSession, this, 556 dataCb.u.seek.uOffActual, 0 /* Processed */); 555 fireGuestFileOffsetChangedEvent(mEventSource, mSession, this, mData.mOffCurrent, 0 /* Processed */); 557 556 } 558 else559 rc = VERR_NOT_SUPPORTED;560 557 break; 561 558 } … … 565 562 if (pSvcCbData->mParms == 4) 566 563 { 567 pSvcCbData->mpaParms[idx++].getUInt64(&dataCb.u.tell.uOffActual); 564 rc = pSvcCbData->mpaParms[idx++].getUInt64(&dataCb.u.tell.uOffActual); 565 if (RT_FAILURE(rc)) 566 break; 567 568 Log3ThisFunc(("uOffActual=%RU64\n", dataCb.u.tell.uOffActual)); 568 569 569 570 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); … … 573 574 alock.release(); 574 575 575 fireGuestFileOffsetChangedEvent(mEventSource, mSession, this, 576 dataCb.u.tell.uOffActual, 0 /* Processed */); 576 fireGuestFileOffsetChangedEvent(mEventSource, mSession, this, mData.mOffCurrent, 0 /* Processed */); 577 577 } 578 else579 rc = VERR_NOT_SUPPORTED;580 578 break; 581 579 } 582 580 583 581 default: 584 rc = VERR_NOT_SUPPORTED;585 582 break; 586 583 } … … 639 636 int GuestFile::i_openFile(uint32_t uTimeoutMS, int *prcGuest) 640 637 { 638 AssertReturn(mData.mOpenInfo.mFileName.isNotEmpty(), VERR_INVALID_PARAMETER); 639 641 640 LogFlowThisFuncEnter(); 642 641 643 642 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 644 643 645 LogFlowThisFunc(("strFile=%s, enmAccessMode=%d (%s) enmOpenAction=%d (%s) uCreationMode=%RU32, mfOpenEx=%RU32\n", 646 mData.mOpenInfo.mFileName.c_str(), mData.mOpenInfo.mAccessMode, mData.mOpenInfo.mpszAccessMode, 647 mData.mOpenInfo.mOpenAction, mData.mOpenInfo.mpszOpenAction, mData.mOpenInfo.mCreationMode, 648 mData.mOpenInfo.mfOpenEx)); 644 LogFlowThisFunc(("strFile=%s, enmAccessMode=0x%x, enmOpenAction=0x%x, uCreationMode=%RU32, mfOpenEx=%RU32\n", 645 mData.mOpenInfo.mFileName.c_str(), mData.mOpenInfo.mAccessMode, mData.mOpenInfo.mOpenAction, 646 mData.mOpenInfo.mCreationMode, mData.mOpenInfo.mfOpenEx)); 647 648 /* Validate and translate open action. */ 649 const char *pszOpenAction = NULL; 650 switch (mData.mOpenInfo.mOpenAction) 651 { 652 case (FileOpenAction_T)FileOpenAction_OpenExisting: pszOpenAction = "oe"; break; 653 case (FileOpenAction_T)FileOpenAction_OpenOrCreate: pszOpenAction = "oc"; break; 654 case (FileOpenAction_T)FileOpenAction_CreateNew: pszOpenAction = "ce"; break; 655 case (FileOpenAction_T)FileOpenAction_CreateOrReplace: pszOpenAction = "ca"; break; 656 case (FileOpenAction_T)FileOpenAction_OpenExistingTruncated: pszOpenAction = "ot"; break; 657 case (FileOpenAction_T)FileOpenAction_AppendOrCreate: 658 pszOpenAction = "oa"; /** @todo get rid of this one and implement AppendOnly/AppendRead. */ 659 break; 660 default: 661 return VERR_INVALID_PARAMETER; 662 } 663 664 /* Validate and translate access mode. */ 665 const char *pszAccessMode = NULL; 666 switch (mData.mOpenInfo.mAccessMode) 667 { 668 case (FileAccessMode_T)FileAccessMode_ReadOnly: pszAccessMode = "r"; break; 669 case (FileAccessMode_T)FileAccessMode_WriteOnly: pszAccessMode = "w"; break; 670 case (FileAccessMode_T)FileAccessMode_ReadWrite: pszAccessMode = "r+"; break; 671 case (FileAccessMode_T)FileAccessMode_AppendOnly: 672 RT_FALL_THRU(); 673 case (FileAccessMode_T)FileAccessMode_AppendRead: 674 return VERR_NOT_IMPLEMENTED; 675 default: 676 return VERR_INVALID_PARAMETER; 677 } 678 679 /* Validate and translate sharing mode. */ 680 const char *pszSharingMode = NULL; 681 switch (mData.mOpenInfo.mSharingMode) 682 { 683 case (FileSharingMode_T)FileSharingMode_All: pszSharingMode = ""; break; 684 case (FileSharingMode_T)FileSharingMode_Read: 685 RT_FALL_THRU(); 686 case (FileSharingMode_T)FileSharingMode_Write: 687 RT_FALL_THRU(); 688 case (FileSharingMode_T)FileSharingMode_ReadWrite: 689 RT_FALL_THRU(); 690 case (FileSharingMode_T)FileSharingMode_Delete: 691 RT_FALL_THRU(); 692 case (FileSharingMode_T)FileSharingMode_ReadDelete: 693 RT_FALL_THRU(); 694 case (FileSharingMode_T)FileSharingMode_WriteDelete: 695 return VERR_NOT_IMPLEMENTED; 696 default: 697 return VERR_INVALID_PARAMETER; 698 } 699 649 700 int vrc; 650 701 … … 671 722 paParms[i++].setPointer((void*)mData.mOpenInfo.mFileName.c_str(), 672 723 (ULONG)mData.mOpenInfo.mFileName.length() + 1); 673 paParms[i++].setString( mData.mOpenInfo.mpszAccessMode);674 paParms[i++].setString( mData.mOpenInfo.mpszOpenAction);675 paParms[i++].setString( ""); /** @todo sharing mode. */724 paParms[i++].setString(pszAccessMode); 725 paParms[i++].setString(pszOpenAction); 726 paParms[i++].setString(pszSharingMode); 676 727 paParms[i++].setUInt32(mData.mOpenInfo.mCreationMode); 677 paParms[i++].setUInt64( 0 /* initial offset */);728 paParms[i++].setUInt64(mData.mOpenInfo.muOffset); 678 729 /** @todo Next protocol version: add flags, replace strings, remove initial offset. */ 679 730 … … 688 739 LogFlowFuncLeaveRC(vrc); 689 740 return vrc; 741 } 742 743 int GuestFile::i_queryInfo(GuestFsObjData &objData, int *prcGuest) 744 { 745 AssertPtr(mSession); 746 return mSession->i_fsQueryInfo(mData.mOpenInfo.mFileName, FALSE /* fFollowSymlinks */, objData, prcGuest); 690 747 } 691 748 … … 956 1013 hr = pFileEvent->COMGETTER(Data)(ComSafeArrayAsOutParam(data)); 957 1014 ComAssertComRC(hr); 958 size_t cbRead = data.size(); 959 if ( cbRead 960 && cbRead <= cbData) 1015 const size_t cbRead = data.size(); 1016 if (cbRead) 961 1017 { 962 memcpy(pvData, data.raw(), data.size()); 1018 if (cbRead <= cbData) 1019 memcpy(pvData, data.raw(), cbRead); 1020 else 1021 vrc = VERR_BUFFER_OVERFLOW; 963 1022 } 964 1023 else 965 vrc = VERR_ BUFFER_OVERFLOW;1024 vrc = VERR_NO_DATA; 966 1025 } 967 1026 if (pcbRead) … … 1205 1264 HRESULT GuestFile::queryInfo(ComPtr<IFsObjInfo> &aObjInfo) 1206 1265 { 1207 RT_NOREF(aObjInfo); 1208 ReturnComNotImplemented(); 1266 AutoCaller autoCaller(this); 1267 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1268 1269 LogFlowThisFuncEnter(); 1270 1271 HRESULT hr = S_OK; 1272 1273 GuestFsObjData fsObjData; int rcGuest; 1274 int vrc = i_queryInfo(fsObjData, &rcGuest); 1275 if (RT_SUCCESS(vrc)) 1276 { 1277 ComObjPtr<GuestFsObjInfo> ptrFsObjInfo; 1278 hr = ptrFsObjInfo.createObject(); 1279 if (SUCCEEDED(hr)) 1280 { 1281 vrc = ptrFsObjInfo->init(fsObjData); 1282 if (RT_SUCCESS(vrc)) 1283 hr = ptrFsObjInfo.queryInterfaceTo(aObjInfo.asOutParam()); 1284 else 1285 hr = setErrorVrc(vrc); 1286 } 1287 } 1288 else 1289 { 1290 if (GuestProcess::i_isGuestError(vrc)) 1291 { 1292 hr = GuestProcess::i_setErrorExternal(this, rcGuest); 1293 } 1294 else 1295 hr = setErrorVrc(vrc, tr("Querying file information failed: %Rrc"), vrc); 1296 } 1297 1298 LogFlowFuncLeaveRC(vrc); 1299 return hr; 1209 1300 } 1210 1301 1211 1302 HRESULT GuestFile::querySize(LONG64 *aSize) 1212 1303 { 1213 RT_NOREF(aSize); 1214 ReturnComNotImplemented(); 1304 AutoCaller autoCaller(this); 1305 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1306 1307 LogFlowThisFuncEnter(); 1308 1309 HRESULT hr = S_OK; 1310 1311 GuestFsObjData fsObjData; int rcGuest; 1312 int vrc = i_queryInfo(fsObjData, &rcGuest); 1313 if (RT_SUCCESS(vrc)) 1314 { 1315 *aSize = fsObjData.mObjectSize; 1316 } 1317 else 1318 { 1319 if (GuestProcess::i_isGuestError(vrc)) 1320 { 1321 hr = GuestProcess::i_setErrorExternal(this, rcGuest); 1322 } 1323 else 1324 hr = setErrorVrc(vrc, tr("Querying file size failed: %Rrc"), vrc); 1325 } 1326 1327 LogFlowFuncLeaveRC(vrc); 1328 return hr; 1215 1329 } 1216 1330 … … 1255 1369 return hr; 1256 1370 } 1371 1257 1372 HRESULT GuestFile::readAt(LONG64 aOffset, ULONG aToRead, ULONG aTimeoutMS, std::vector<BYTE> &aData) 1258 1259 1373 { 1260 1374 AutoCaller autoCaller(this); … … 1387 1501 1388 1502 HRESULT GuestFile::writeAt(LONG64 aOffset, const std::vector<BYTE> &aData, ULONG aTimeoutMS, ULONG *aWritten) 1389 1390 1503 { 1391 1504 AutoCaller autoCaller(this);
Note:
See TracChangeset
for help on using the changeset viewer.