vbox的更動 65288 路徑 trunk/src/VBox/HostServices
- 時間撮記:
- 2017-1-13 下午03:51:16 (8 年 以前)
- 位置:
- trunk/src/VBox/HostServices/SharedFolders
- 檔案:
-
- 修改 2 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/HostServices/SharedFolders/shflhandle.h
r62489 r65288 44 44 { 45 45 SHFLHANDLEHDR Header; 46 SHFLROOT root; /* Where the handle has been opened. */ 46 47 union 47 48 { -
trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp
r65279 r65288 141 141 { 142 142 vbsfFreeHostPath(pszFullPath); 143 } 144 145 typedef enum VBSFCHECKACCESS 146 { 147 VBSF_CHECK_ACCESS_READ = 0, 148 VBSF_CHECK_ACCESS_WRITE = 1 149 } VBSFCHECKACCESS; 150 151 /** 152 * Check if the handle data is valid and the operation is allowed on the shared folder. 153 * 154 * @returns IPRT status code 155 * @param pClient Data structure describing the client accessing the shared folder 156 * @param root The index of the shared folder in the table of mappings. 157 * @param pHandle Information about the file or directory object. 158 * @param enmCheckAccess Whether the operation needs read only or write access. 159 */ 160 static int vbsfCheckHandleAccess(SHFLCLIENTDATA *pClient, SHFLROOT root, 161 SHFLFILEHANDLE *pHandle, VBSFCHECKACCESS enmCheckAccess) 162 { 163 /* Handle from the same 'root' index? */ 164 if (RT_LIKELY(RT_VALID_PTR(pHandle) && root == pHandle->root)) 165 { /* likely */ } 166 else 167 return VERR_INVALID_HANDLE; 168 169 /* Check if the guest is still allowed to access this share. 170 * vbsfMappingsQueryWritable returns error if the shared folder has been removed from the VM settings. 171 */ 172 bool fWritable; 173 int rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 174 if (RT_SUCCESS(rc)) 175 { /* likely */ } 176 else 177 return VERR_ACCESS_DENIED; 178 179 if (enmCheckAccess == VBSF_CHECK_ACCESS_WRITE) 180 { 181 /* Operation requires write access. Check if the shared folder is writable too. */ 182 if (RT_LIKELY(fWritable)) 183 { /* likely */ } 184 else 185 return VERR_WRITE_PROTECT; 186 } 187 188 return VINF_SUCCESS; 143 189 } 144 190 … … 421 467 if (pHandle) 422 468 { 469 pHandle->root = root; 423 470 rc = RTFileOpen(&pHandle->file.Handle, pszPath, fOpen); 424 471 } … … 564 611 * @returns IPRT status code 565 612 * @param pClient Data structure describing the client accessing the shared folder 613 * @param root The index of the shared folder in the table of mappings. 566 614 * @param pszPath Path to the file or folder on the host. 567 615 * @param pParms @a CreateFlags Creation or open parameters, see include/VBox/shflsvc.h … … 573 621 * @note folders are created with fMode = 0777 574 622 */ 575 static int vbsfOpenDir(SHFLCLIENTDATA *pClient, const char *pszPath,623 static int vbsfOpenDir(SHFLCLIENTDATA *pClient, SHFLROOT root, const char *pszPath, 576 624 SHFLCREATEPARMS *pParms) 577 625 { … … 584 632 if (0 != pHandle) 585 633 { 634 pHandle->root = root; 586 635 rc = VINF_SUCCESS; 587 636 pParms->Result = SHFL_FILE_EXISTS; /* May be overwritten with SHFL_FILE_CREATED. */ … … 885 934 if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_DIRECTORY)) 886 935 { 887 rc = vbsfOpenDir(pClient, pszFullPath, pParms);936 rc = vbsfOpenDir(pClient, root, pszFullPath, pParms); 888 937 } 889 938 else … … 920 969 int vbsfClose(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle) 921 970 { 922 RT_NOREF1(root); 923 int rc = VINF_SUCCESS; 924 925 LogFlow(("vbsfClose: pClient = %p, Handle = %RX64\n", 926 pClient, Handle)); 927 971 LogFunc(("pClient = %p, root 0x%RX32, Handle = 0x%RX64\n", 972 pClient, root, Handle)); 973 974 int rc = VERR_INVALID_HANDLE; 928 975 uint32_t type = vbsfQueryHandleType(pClient, Handle); 929 976 Assert((type & ~(SHFL_HF_TYPE_DIR | SHFL_HF_TYPE_FILE)) == 0); 930 931 977 switch (type & (SHFL_HF_TYPE_DIR | SHFL_HF_TYPE_FILE)) 932 978 { 933 979 case SHFL_HF_TYPE_DIR: 934 980 { 935 rc = vbsfCloseDir(vbsfQueryDirHandle(pClient, Handle)); 981 SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle); 982 if (RT_LIKELY(pHandle && root == pHandle->root)) 983 { 984 rc = vbsfCloseDir(pHandle); 985 vbsfFreeFileHandle(pClient, Handle); 986 } 936 987 break; 937 988 } 938 989 case SHFL_HF_TYPE_FILE: 939 990 { 940 rc = vbsfCloseFile(vbsfQueryFileHandle(pClient, Handle)); 991 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 992 if (RT_LIKELY(pHandle && root == pHandle->root)) 993 { 994 rc = vbsfCloseFile(pHandle); 995 vbsfFreeFileHandle(pClient, Handle); 996 } 941 997 break; 942 998 } 943 999 default: 944 return VERR_INVALID_HANDLE; 945 } 946 vbsfFreeFileHandle(pClient, Handle); 947 948 Log(("vbsfClose: rc = %Rrc\n", rc)); 949 1000 break; 1001 } 1002 1003 LogFunc(("rc = %Rrc\n", rc)); 950 1004 return rc; 951 1005 } … … 963 1017 } 964 1018 #endif 965 int vbsfRead (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer) 966 { 1019 int vbsfRead(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer) 1020 { 1021 LogFunc(("pClient %p, root 0x%RX32, Handle 0x%RX64, offset 0x%RX64, bytes 0x%RX32\n", 1022 pClient, root, Handle, offset, pcbBuffer? *pcbBuffer: 0)); 1023 1024 AssertPtrReturn(pClient, VERR_INVALID_PARAMETER); 1025 967 1026 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 968 size_t count = 0; 969 int rc; 970 971 if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0) 972 { 973 AssertFailed(); 974 return VERR_INVALID_PARAMETER; 975 } 976 977 Log(("vbsfRead %RX64 offset %RX64 bytes %x\n", Handle, offset, *pcbBuffer)); 978 979 /* Is the guest allowed to access this share? 980 * Checked here because the shared folder can be removed from the VM settings. */ 981 bool fWritable; 982 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 983 if (RT_FAILURE(rc)) 984 return VERR_ACCESS_DENIED; 985 986 if (*pcbBuffer == 0) 987 return VINF_SUCCESS; /** @todo correct? */ 988 989 990 rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL); 991 if (rc != VINF_SUCCESS) 992 { 993 AssertRC(rc); 1027 int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ); 1028 if (RT_SUCCESS(rc)) 1029 { /* likely */ } 1030 else 994 1031 return rc; 995 } 996 997 rc = RTFileRead(pHandle->file.Handle, pBuffer, *pcbBuffer, &count); 998 *pcbBuffer = (uint32_t)count; 999 Log(("RTFileRead returned %Rrc bytes read %x\n", rc, count)); 1032 1033 if (RT_LIKELY(*pcbBuffer != 0)) 1034 { 1035 rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL); 1036 if (RT_SUCCESS(rc)) 1037 { 1038 size_t count = 0; 1039 rc = RTFileRead(pHandle->file.Handle, pBuffer, *pcbBuffer, &count); 1040 *pcbBuffer = (uint32_t)count; 1041 } 1042 else 1043 AssertRC(rc); 1044 } 1045 else 1046 { 1047 /* Reading zero bytes always succeeds. */ 1048 rc = VINF_SUCCESS; 1049 } 1050 1051 LogFunc(("%Rrc bytes read 0x%RX32\n", rc, *pcbBuffer)); 1000 1052 return rc; 1001 1053 } … … 1015 1067 int vbsfWrite(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer) 1016 1068 { 1069 LogFunc(("pClient %p, root 0x%RX32, Handle 0x%RX64, offset 0x%RX64, bytes 0x%RX32\n", 1070 pClient, root, Handle, offset, pcbBuffer? *pcbBuffer: 0)); 1071 1072 AssertPtrReturn(pClient, VERR_INVALID_PARAMETER); 1073 1017 1074 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1018 size_t count = 0; 1019 int rc; 1020 1021 if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0) 1022 { 1023 AssertFailed(); 1024 return VERR_INVALID_PARAMETER; 1025 } 1026 1027 Log(("vbsfWrite %RX64 offset %RX64 bytes %x\n", Handle, offset, *pcbBuffer)); 1028 1029 /* Is the guest allowed to write to this share? 1030 * Checked here because the shared folder can be removed from the VM settings. */ 1031 bool fWritable; 1032 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 1033 if (RT_FAILURE(rc) || !fWritable) 1034 return VERR_WRITE_PROTECT; 1035 1036 if (*pcbBuffer == 0) 1037 return VINF_SUCCESS; /** @todo correct? */ 1038 1039 rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL); 1040 if (rc != VINF_SUCCESS) 1041 { 1042 AssertRC(rc); 1075 int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1076 if (RT_SUCCESS(rc)) 1077 { /* likely */ } 1078 else 1043 1079 return rc; 1044 } 1045 1046 rc = RTFileWrite(pHandle->file.Handle, pBuffer, *pcbBuffer, &count); 1047 *pcbBuffer = (uint32_t)count; 1048 Log(("RTFileWrite returned %Rrc bytes written %x\n", rc, count)); 1080 1081 if (RT_LIKELY(*pcbBuffer != 0)) 1082 { 1083 rc = RTFileSeek(pHandle->file.Handle, offset, RTFILE_SEEK_BEGIN, NULL); 1084 if (RT_SUCCESS(rc)) 1085 { 1086 size_t count = 0; 1087 rc = RTFileWrite(pHandle->file.Handle, pBuffer, *pcbBuffer, &count); 1088 *pcbBuffer = (uint32_t)count; 1089 } 1090 else 1091 AssertRC(rc); 1092 } 1093 else 1094 { 1095 /** @todo: What writing zero bytes should do? */ 1096 rc = VINF_SUCCESS; 1097 } 1098 1099 LogFunc(("%Rrc bytes written 0x%RX32\n", rc, *pcbBuffer)); 1049 1100 return rc; 1050 1101 } … … 1066 1117 int vbsfFlush(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle) 1067 1118 { 1068 RT_NOREF1(root); 1119 LogFunc(("pClient %p, root 0x%RX32, Handle 0x%RX64\n", 1120 pClient, root, Handle)); 1121 1122 AssertPtrReturn(pClient, VERR_INVALID_PARAMETER); 1123 1069 1124 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1070 int rc = VINF_SUCCESS; 1071 1072 if (pHandle == 0) 1073 { 1074 AssertFailed(); 1075 return VERR_INVALID_HANDLE; 1076 } 1077 1078 Log(("vbsfFlush %RX64\n", Handle)); 1125 int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1126 if (RT_SUCCESS(rc)) 1127 { /* likely */ } 1128 else 1129 return rc; 1130 1079 1131 rc = RTFileFlush(pHandle->file.Handle); 1080 AssertRC(rc); 1132 1133 LogFunc(("%Rrc\n", rc)); 1081 1134 return rc; 1082 1135 } … … 1097 1150 uint32_t *pcbBuffer, uint8_t *pBuffer, uint32_t *pIndex, uint32_t *pcFiles) 1098 1151 { 1099 SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle);1100 1152 PRTDIRENTRYEX pDirEntry = 0, pDirEntryOrg; 1101 1153 uint32_t cbDirEntry, cbBufferOrg; 1102 int rc = VINF_SUCCESS;1103 1154 PSHFLDIRINFO pSFDEntry; 1104 1155 PRTUTF16 pwszString; 1105 1156 PRTDIR DirHandle; 1106 bool fUtf8; 1107 1108 fUtf8 = BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8) != 0; 1109 1110 if (pHandle == 0 || pcbBuffer == 0 || pBuffer == 0) 1111 { 1112 AssertFailed(); 1113 return VERR_INVALID_PARAMETER; 1114 } 1115 1116 /* Is the guest allowed to access this share? 1117 * Checked here because the shared folder can be removed from the VM settings. */ 1118 bool fWritable; 1119 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 1120 if (RT_FAILURE(rc)) 1121 return VERR_ACCESS_DENIED; 1122 1123 Assert(pIndex && *pIndex == 0); 1157 const bool fUtf8 = BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8) != 0; 1158 1159 AssertPtrReturn(pClient, VERR_INVALID_PARAMETER); 1160 1161 SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle); 1162 int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ); 1163 if (RT_SUCCESS(rc)) 1164 { /* likely */ } 1165 else 1166 return rc; 1167 1168 Assert(*pIndex == 0); 1124 1169 DirHandle = pHandle->dir.Handle; 1125 1170 … … 1360 1405 uint32_t *pcbBuffer, uint8_t *pBuffer) 1361 1406 { 1362 RT_NOREF 2(root,flags);1407 RT_NOREF1(flags); 1363 1408 uint32_t type = vbsfQueryHandleType(pClient, Handle); 1364 1409 int rc = VINF_SUCCESS; … … 1384 1429 { 1385 1430 SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle); 1386 rc = RTDirQueryInfo(pHandle->dir.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING); 1431 rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ); 1432 if (RT_SUCCESS(rc)) 1433 rc = RTDirQueryInfo(pHandle->dir.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING); 1387 1434 } 1388 1435 else 1389 1436 { 1390 1437 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1391 rc = RTFileQueryInfo(pHandle->file.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING); 1438 rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ); 1439 if (RT_SUCCESS(rc)) 1440 rc = RTFileQueryInfo(pHandle->file.Handle, &fileinfo, RTFSOBJATTRADD_NOTHING); 1392 1441 #ifdef RT_OS_WINDOWS 1393 1442 if (RT_SUCCESS(rc) && RTFS_IS_FILE(pObjInfo->Attr.fMode)) … … 1409 1458 uint32_t *pcbBuffer, uint8_t *pBuffer) 1410 1459 { 1411 RT_NOREF 2(root,flags);1460 RT_NOREF1(flags); 1412 1461 uint32_t type = vbsfQueryHandleType(pClient, Handle); 1413 1462 int rc = VINF_SUCCESS; … … 1432 1481 { 1433 1482 SHFLFILEHANDLE *pHandle = vbsfQueryDirHandle(pClient, Handle); 1434 rc = RTDirSetTimes(pHandle->dir.Handle, 1435 (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ? &pSFDEntry->AccessTime : NULL, 1436 (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL, 1437 (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ? &pSFDEntry->ChangeTime: NULL, 1438 (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ? &pSFDEntry->BirthTime: NULL 1439 ); 1483 rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1484 if (RT_SUCCESS(rc)) 1485 rc = RTDirSetTimes(pHandle->dir.Handle, 1486 (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ? &pSFDEntry->AccessTime : NULL, 1487 (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL, 1488 (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ? &pSFDEntry->ChangeTime: NULL, 1489 (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ? &pSFDEntry->BirthTime: NULL 1490 ); 1440 1491 } 1441 1492 else 1442 1493 { 1443 1494 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1444 rc = RTFileSetTimes(pHandle->file.Handle, 1445 (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ? &pSFDEntry->AccessTime : NULL, 1446 (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL, 1447 (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ? &pSFDEntry->ChangeTime: NULL, 1448 (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ? &pSFDEntry->BirthTime: NULL 1449 ); 1495 rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1496 if (RT_SUCCESS(rc)) 1497 rc = RTFileSetTimes(pHandle->file.Handle, 1498 (RTTimeSpecGetNano(&pSFDEntry->AccessTime)) ? &pSFDEntry->AccessTime : NULL, 1499 (RTTimeSpecGetNano(&pSFDEntry->ModificationTime)) ? &pSFDEntry->ModificationTime: NULL, 1500 (RTTimeSpecGetNano(&pSFDEntry->ChangeTime)) ? &pSFDEntry->ChangeTime: NULL, 1501 (RTTimeSpecGetNano(&pSFDEntry->BirthTime)) ? &pSFDEntry->BirthTime: NULL 1502 ); 1450 1503 } 1451 1504 if (rc != VINF_SUCCESS) … … 1463 1516 { 1464 1517 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1465 /* Change file attributes if necessary */ 1466 if (pSFDEntry->Attr.fMode) 1467 { 1468 RTFMODE fMode = pSFDEntry->Attr.fMode; 1518 rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1519 if (RT_SUCCESS(rc)) 1520 { 1521 /* Change file attributes if necessary */ 1522 if (pSFDEntry->Attr.fMode) 1523 { 1524 RTFMODE fMode = pSFDEntry->Attr.fMode; 1469 1525 1470 1526 #ifndef RT_OS_WINDOWS 1471 /* Don't allow the guest to clear the own bit, otherwise the guest wouldn't be 1472 * able to access this file anymore. Only for guests, which set the UNIX mode. */ 1473 if (fMode & RTFS_UNIX_MASK) 1474 fMode |= RTFS_UNIX_IRUSR; 1475 #endif 1476 1477 rc = RTFileSetMode(pHandle->file.Handle, fMode); 1478 if (rc != VINF_SUCCESS) 1479 { 1480 Log(("RTFileSetMode %x failed with %Rrc\n", fMode, rc)); 1481 /* silent failure, because this tends to fail with e.g. windows guest & linux host */ 1482 rc = VINF_SUCCESS; 1527 /* Don't allow the guest to clear the own bit, otherwise the guest wouldn't be 1528 * able to access this file anymore. Only for guests, which set the UNIX mode. */ 1529 if (fMode & RTFS_UNIX_MASK) 1530 fMode |= RTFS_UNIX_IRUSR; 1531 #endif 1532 1533 rc = RTFileSetMode(pHandle->file.Handle, fMode); 1534 if (rc != VINF_SUCCESS) 1535 { 1536 Log(("RTFileSetMode %x failed with %Rrc\n", fMode, rc)); 1537 /* silent failure, because this tends to fail with e.g. windows guest & linux host */ 1538 rc = VINF_SUCCESS; 1539 } 1483 1540 } 1484 1541 } … … 1506 1563 uint32_t *pcbBuffer, uint8_t *pBuffer) 1507 1564 { 1508 RT_NOREF 2(root,flags);1565 RT_NOREF1(flags); 1509 1566 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1510 int rc = VINF_SUCCESS;1511 1567 SHFLFSOBJINFO *pSFDEntry; 1512 1568 … … 1516 1572 return VERR_INVALID_PARAMETER; 1517 1573 } 1574 1575 int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_WRITE); 1576 if (RT_SUCCESS(rc)) 1577 { /* likely */ } 1578 else 1579 return rc; 1518 1580 1519 1581 *pcbBuffer = 0; … … 1648 1710 } 1649 1711 1650 /* is the guest allowed to write to this share? */1651 bool fWritable;1652 int rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);1653 if (RT_FAILURE(rc) || !fWritable)1654 return VERR_WRITE_PROTECT;1655 1656 1712 if (flags & SHFL_INFO_FILE) 1657 1713 return vbsfSetFileInfo(pClient, root, Handle, flags, pcbBuffer, pBuffer); … … 1681 1737 int vbsfLock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags) 1682 1738 { 1683 RT_NOREF1(root);1684 1739 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1685 1740 uint32_t fRTLock = 0; 1686 int rc;1687 1741 1688 1742 Assert((flags & SHFL_LOCK_MODE_MASK) != SHFL_LOCK_CANCEL); 1689 1743 1690 if (pHandle == 0) 1691 { 1692 AssertFailed(); 1693 return VERR_INVALID_HANDLE; 1694 } 1744 int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ); 1745 if (RT_SUCCESS(rc)) 1746 { /* likely */ } 1747 else 1748 return rc; 1749 1695 1750 if ( ((flags & SHFL_LOCK_MODE_MASK) == SHFL_LOCK_CANCEL) 1696 1751 || (flags & SHFL_LOCK_ENTIRE) … … 1737 1792 int vbsfUnlock(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint64_t length, uint32_t flags) 1738 1793 { 1739 RT_NOREF1(root);1740 1794 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); 1741 int rc;1742 1795 1743 1796 Assert((flags & SHFL_LOCK_MODE_MASK) == SHFL_LOCK_CANCEL); 1744 1797 1745 if (pHandle == 0) 1746 { 1747 return VERR_INVALID_HANDLE; 1748 } 1798 int rc = vbsfCheckHandleAccess(pClient, root, pHandle, VBSF_CHECK_ACCESS_READ); 1799 if (RT_SUCCESS(rc)) 1800 { /* likely */ } 1801 else 1802 return rc; 1803 1749 1804 if ( ((flags & SHFL_LOCK_MODE_MASK) != SHFL_LOCK_CANCEL) 1750 1805 || (flags & SHFL_LOCK_ENTIRE) … … 1956 2011 int vbsfDisconnect(SHFLCLIENTDATA *pClient) 1957 2012 { 1958 for (int i=0; i<SHFLHANDLE_MAX; i++) 1959 { 2013 for (int i = 0; i < SHFLHANDLE_MAX; ++i) 2014 { 2015 SHFLFILEHANDLE *pHandle = NULL; 1960 2016 SHFLHANDLE Handle = (SHFLHANDLE)i; 1961 if (vbsfQueryHandleType(pClient, Handle)) 1962 { 1963 Log(("Open handle %08x\n", i)); 1964 vbsfClose(pClient, SHFL_HANDLE_ROOT /* incorrect, but it's not important */, (SHFLHANDLE)i); 2017 2018 uint32_t type = vbsfQueryHandleType(pClient, Handle); 2019 switch (type & (SHFL_HF_TYPE_DIR | SHFL_HF_TYPE_FILE)) 2020 { 2021 case SHFL_HF_TYPE_DIR: 2022 { 2023 pHandle = vbsfQueryDirHandle(pClient, Handle); 2024 break; 2025 } 2026 case SHFL_HF_TYPE_FILE: 2027 { 2028 pHandle = vbsfQueryFileHandle(pClient, Handle); 2029 break; 2030 } 2031 default: 2032 break; 2033 } 2034 2035 if (pHandle) 2036 { 2037 LogFunc(("Opened handle 0x%08x\n", i)); 2038 vbsfClose(pClient, pHandle->root, Handle); 1965 2039 } 1966 2040 }
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器