Changeset 31111 in vbox
- Timestamp:
- Jul 26, 2010 12:23:16 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/VBoxGuestLib.h
r31052 r31111 526 526 VBGLR3DECL(int) VbglR3SharedFolderConnect(uint32_t *pu32ClientId); 527 527 VBGLR3DECL(int) VbglR3SharedFolderDisconnect(uint32_t u32ClientId); 528 VBGLR3DECL(bool) VbglR3SharedFolderExists(uint32_t u32ClientId, char *pszShareName); 528 529 VBGLR3DECL(int) VbglR3SharedFolderGetMappings(uint32_t u32ClientId, bool fAutoMountOnly, 529 530 PVBGLR3SHAREDFOLDERMAPPING *ppaMappings, uint32_t *pcMappings); -
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSharedFolders.cpp
r31052 r31111 25 25 int VBoxSharedFoldersAutoMount(void) 26 26 { 27 #if 028 27 uint32_t u32ClientId; 29 28 int rc = VbglR3SharedFolderConnect(&u32ClientId); … … 32 31 else 33 32 { 34 uint32_t cMappings = 64; /* See shflsvc.h for define; should be used later. */ 35 uint32_t cbMappings = cMappings * sizeof(VBGLR3SHAREDFOLDERMAPPING); 36 VBGLR3SHAREDFOLDERMAPPING *paMappings = (PVBGLR3SHAREDFOLDERMAPPING)RTMemAlloc(cbMappings); 37 38 if (paMappings) 33 uint32_t cMappings; 34 VBGLR3SHAREDFOLDERMAPPING *paMappings; 35 36 rc = VbglR3SharedFolderGetMappings(u32ClientId, true /* Only process auto-mounted folders */, 37 &paMappings, &cMappings); 38 if (RT_SUCCESS(rc)) 39 39 { 40 rc = VbglR3SharedFolderGetMappings(u32ClientId, true /* Only process auto-mounted folders */, 41 paMappings, cbMappings, 42 &cMappings); 43 if (RT_SUCCESS(rc)) 40 #if 0 41 /* Check for a fixed/virtual auto-mount share. */ 42 if (VbglR3SharedFolderExists(u32ClientId, "vbsfAutoMount")) 44 43 { 45 RT_CLAMP(cMappings, 0, 64); /* Maximum mappings, see shflsvc.h */ 46 for (uint32_t i = 0; i < cMappings; i++) 44 Log(("VBoxTray: Hosts supports auto-mount root\n")); 45 } 46 else 47 { 48 #endif 49 Log(("VBoxTray: Got %u shared folder mappings\n", cMappings)); 50 for (uint32_t i = 0; i < cMappings && RT_SUCCESS(rc); i++) 47 51 { 48 52 char *pszName = NULL; … … 51 55 && *pszName) 52 56 { 57 Log(("VBoxTray: Connecting share %u (%s) ...\n", i+1, pszName)); 58 53 59 char *pszShareName = NULL; 54 RTStrAPrintf(&pszShareName, "\\\\vboxsrv\\%s", pszName);55 if (pszShareName)60 if ( RTStrAPrintf(&pszShareName, "\\\\vboxsrv\\%s", pszName) > 0 61 && pszShareName) 56 62 { 57 NETRESOURCE resource; 58 RT_ZERO(resource); 59 resource.dwType = RESOURCETYPE_ANY; 60 resource.lpLocalName = TEXT("f:"); 61 resource.lpRemoteName = TEXT(pszShareName); 62 63 /** @todo Figure out how to map the drives in a block (F,G,H, ...). 64 Save the mapping for later use. */ 65 DWORD dwErr = WNetAddConnection2A(&resource, NULL, NULL, 0); 66 if (dwErr == NO_ERROR) 63 char cDrive = 'D'; /* Start probing whether drive D: is free to use. */ 64 do 67 65 { 68 LogRel(("VBoxTray: Shared folder \"%s\" was mounted to share \"%s\"\n", pszName, dwErr)); 66 char szCurDrive[3]; 67 RTStrPrintf(szCurDrive, sizeof(szCurDrive), "%c:", cDrive++); 68 69 NETRESOURCE resource; 70 RT_ZERO(resource); 71 resource.dwType = RESOURCETYPE_ANY; 72 resource.lpLocalName = TEXT(szCurDrive); 73 resource.lpRemoteName = TEXT(pszShareName); 74 /* Go straight to our network provider in order to get maximum lookup speed. */ 75 resource.lpProvider = TEXT("VirtualBox Shared Folders"); 76 77 /** @todo Figure out how to map the drives in a block (F,G,H, ...). 78 Save the mapping for later use. */ 79 DWORD dwErr = WNetAddConnection2A(&resource, NULL, NULL, 0); 80 if (dwErr == NO_ERROR) 81 { 82 LogRel(("VBoxTray: Shared folder \"%s\" was mounted to drive \"%s\"\n", pszName, szCurDrive)); 83 break; 84 } 85 else 86 { 87 LogRel(("VBoxTray: Mounting \"%s\" to \"%s\" resulted in dwErr = %ld\n", pszName, szCurDrive, dwErr)); 88 89 switch (dwErr) 90 { 91 /* 92 * The local device specified by the lpLocalName member is already 93 * connected to a network resource. Try next drive ... 94 */ 95 case ERROR_ALREADY_ASSIGNED: 96 break; 97 98 default: 99 LogRel(("VBoxTray: Error while mounting shared folder \"%s\" to \"%s\", error = %ld\n", 100 pszName, szCurDrive, dwErr)); 101 break; 102 } 103 } 104 } while(cDrive <= 'Z'); 105 106 if (cDrive > 'Z') 107 { 108 LogRel(("VBoxTray: No free driver letter found to assign shared folder \"%s\", aborting.\n", pszName)); 109 break; 69 110 } 70 else 71 { 72 switch (dwErr) 73 { 74 case ERROR_ALREADY_ASSIGNED: 75 break; 76 77 default: 78 LogRel(("VBoxTray: Error while mounting shared folder \"%s\", error = %ld\n", 79 pszName, dwErr)); 80 } 81 } 111 82 112 RTStrFree(pszShareName); 83 113 } 114 else 115 rc = VERR_NO_MEMORY; 84 116 RTStrFree(pszName); 85 117 } … … 88 120 paMappings[i].u32Root, rc)); 89 121 } 122 #if 0 90 123 } 91 else 92 Log(("VBoxTray: Error while getting the shared folder mappings, rc = %Rrc\n", rc)); 124 #endif 93 125 RTMemFree(paMappings); 94 126 } 95 127 else 96 rc = VERR_NO_MEMORY;128 Log(("VBoxTray: Error while getting the shared folder mappings, rc = %Rrc\n", rc)); 97 129 VbglR3SharedFolderDisconnect(u32ClientId); 98 130 } 99 131 return rc; 100 #endif101 return 0;102 132 } 103 133 104 134 int VBoxSharedFoldersAutoUnmount(void) 105 135 { 106 //WNetCancelConnection2(name, 0, 1 /* Force disconnect */); 107 return 0; 136 uint32_t u32ClientId; 137 int rc = VbglR3SharedFolderConnect(&u32ClientId); 138 if (!RT_SUCCESS(rc)) 139 Log(("VBoxTray: Failed to connect to the shared folder service, error %Rrc\n", rc)); 140 else 141 { 142 uint32_t cMappings; 143 VBGLR3SHAREDFOLDERMAPPING *paMappings; 144 145 rc = VbglR3SharedFolderGetMappings(u32ClientId, true /* Only process auto-mounted folders */, 146 &paMappings, &cMappings); 147 if (RT_SUCCESS(rc)) 148 { 149 for (uint32_t i = 0; i < cMappings && RT_SUCCESS(rc); i++) 150 { 151 char *pszName = NULL; 152 rc = VbglR3SharedFolderGetName(u32ClientId, paMappings[i].u32Root, &pszName); 153 if ( RT_SUCCESS(rc) 154 && *pszName) 155 { 156 Log(("VBoxTray: Disconnecting share %u (%s) ...\n", i+1, pszName)); 157 158 char *pszShareName = NULL; 159 if ( RTStrAPrintf(&pszShareName, "\\\\vboxsrv\\%s", pszName) > 0 160 && pszShareName) 161 { 162 DWORD dwErr = WNetCancelConnection2(pszShareName, 0, FALSE /* Force disconnect */); 163 if (dwErr == NO_ERROR) 164 { 165 LogRel(("VBoxTray: Share \"%s\" was disconnected\n", pszShareName)); 166 break; 167 } 168 else 169 { 170 LogRel(("VBoxTray: Disconnecting \"%s\" failed, dwErr = %ld\n", pszShareName, dwErr)); 171 172 switch (dwErr) 173 { 174 case ERROR_NOT_CONNECTED: 175 break; 176 177 default: 178 LogRel(("VBoxTray: Error while disconnecting shared folder \"%s\", error = %ld\n", 179 pszShareName, dwErr)); 180 break; 181 } 182 } 183 184 RTStrFree(pszShareName); 185 } 186 else 187 rc = VERR_NO_MEMORY; 188 RTStrFree(pszName); 189 } 190 else 191 Log(("VBoxTray: Error while getting the shared folder name for root node = %u, rc = %Rrc\n", 192 paMappings[i].u32Root, rc)); 193 } 194 RTMemFree(paMappings); 195 } 196 else 197 Log(("VBoxTray: Error while getting the shared folder mappings, rc = %Rrc\n", rc)); 198 VbglR3SharedFolderDisconnect(u32ClientId); 199 } 200 return rc; 108 201 } 202 -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibSharedFolders.cpp
r31052 r31111 83 83 rc = Info.result; 84 84 return rc; 85 } 86 87 88 /** 89 * Checks whether a shared folder share exists or not. 90 * 91 * @returns True if shared folder exists, false if not. 92 * @param u32ClientId The client id returned by VbglR3InfoSvcConnect(). 93 * @param pszShareName Shared folder name to check. 94 */ 95 VBGLR3DECL(bool) VbglR3SharedFolderExists(uint32_t u32ClientId, char *pszShareName) 96 { 97 AssertPtr(pszShareName); 98 99 uint32_t cMappings; 100 VBGLR3SHAREDFOLDERMAPPING *paMappings; 101 102 /** @todo Use some caching here? */ 103 bool fFound = false; 104 int rc = VbglR3SharedFolderGetMappings(u32ClientId, true /* Only process auto-mounted folders */, 105 &paMappings, &cMappings); 106 if (RT_SUCCESS(rc)) 107 { 108 for (uint32_t i = 0; i < cMappings && !fFound; i++) 109 { 110 char *pszName = NULL; 111 rc = VbglR3SharedFolderGetName(u32ClientId, paMappings[i].u32Root, &pszName); 112 if ( RT_SUCCESS(rc) 113 && *pszName) 114 { 115 if (RTStrICmp(pszName, pszShareName) == 0) 116 fFound = true; 117 RTStrFree(pszName); 118 } 119 } 120 RTMemFree(paMappings); 121 } 122 return fFound; 85 123 } 86 124
Note:
See TracChangeset
for help on using the changeset viewer.