- Timestamp:
- Jan 28, 2011 12:51:37 PM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/SharedFolderImpl.h
r35755 r35757 46 46 47 47 // public initializer/uninitializer for internal purposes only 48 HRESULT init(Machine *aMachine, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount );48 HRESULT init(Machine *aMachine, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount, bool fFailOnError); 49 49 HRESULT initCopy(Machine *aMachine, SharedFolder *aThat); 50 HRESULT init(Console *aConsole, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount );51 HRESULT init(VirtualBox *aVirtualBox, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount);50 HRESULT init(Console *aConsole, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount, bool fFailOnError); 51 // HRESULT init(VirtualBox *aVirtualBox, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount, bool fFailOnError); 52 52 void uninit(); 53 53 … … 89 89 protected: 90 90 91 HRESULT protectedInit(VirtualBoxBase *aParent, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount); 91 HRESULT protectedInit(VirtualBoxBase *aParent, 92 const Utf8Str &aName, 93 const Utf8Str &aHostPath, 94 bool aWritable, 95 bool aAutoMount, 96 bool fFailOnError); 92 97 private: 93 98 -
trunk/src/VBox/Main/src-all/SharedFolderImpl.cpp
r35755 r35757 81 81 * Initializes the shared folder object. 82 82 * 83 * This variant initializes a machine instance that lives in the server address space. 84 * 83 85 * @param aMachine parent Machine object 84 86 * @param aName logical name of the shared folder … … 86 88 * @param aWritable writable if true, readonly otherwise 87 89 * @param aAutoMount if auto mounted by guest true, false otherwise 90 * @param fFailOnError Whether to fail with an error if the shared folder path is bad. 88 91 * 89 92 * @return COM result indicator … … 93 96 const Utf8Str &aHostPath, 94 97 bool aWritable, 95 bool aAutoMount) 98 bool aAutoMount, 99 bool fFailOnError) 96 100 { 97 101 /* Enclose the state transition NotReady->InInit->Ready */ … … 101 105 unconst(mMachine) = aMachine; 102 106 103 HRESULT rc = protectedInit(aMachine, aName, aHostPath, aWritable, aAutoMount );107 HRESULT rc = protectedInit(aMachine, aName, aHostPath, aWritable, aAutoMount, fFailOnError); 104 108 105 109 /* Confirm a successful initialization when it's the case */ … … 134 138 aThat->m->strHostPath, 135 139 aThat->m->fWritable, 136 aThat->m->fAutoMount); 140 aThat->m->fAutoMount, 141 false /* fFailOnError */ ); 137 142 138 143 /* Confirm a successful initialization when it's the case */ … … 144 149 145 150 /** 146 * Initializes the shared folder object. This variant gets called when 147 * the shared folder lives in the Console address space. 151 * Initializes the shared folder object. 152 * 153 * This variant initializes an instance that lives in the console address space. 148 154 * 149 155 * @param aConsole Console parent object … … 151 157 * @param aHostPath full path to the shared folder on the host 152 158 * @param aWritable writable if true, readonly otherwise 159 * @param fFailOnError Whether to fail with an error if the shared folder path is bad. 153 160 * 154 161 * @return COM result indicator … … 158 165 const Utf8Str &aHostPath, 159 166 bool aWritable, 160 bool aAutoMount) 167 bool aAutoMount, 168 bool fFailOnError) 161 169 { 162 170 /* Enclose the state transition NotReady->InInit->Ready */ … … 166 174 unconst(mConsole) = aConsole; 167 175 168 HRESULT rc = protectedInit(aConsole, aName, aHostPath, aWritable, aAutoMount );176 HRESULT rc = protectedInit(aConsole, aName, aHostPath, aWritable, aAutoMount, fFailOnError); 169 177 170 178 /* Confirm a successful initialization when it's the case */ … … 175 183 } 176 184 177 /** 178 * Initializes the shared folder object. This variant gets called when 179 * the shared folder lives in the VirtualBox (server) address space. 185 #if 0 186 187 /** 188 * Initializes the shared folder object. 189 * 190 * This variant initializes a global instance that lives in the server address space. It is not presently used. 180 191 * 181 192 * @param aVirtualBox VirtualBox parent object … … 183 194 * @param aHostPath full path to the shared folder on the host 184 195 * @param aWritable writable if true, readonly otherwise 196 * @param fFailOnError Whether to fail with an error if the shared folder path is bad. 185 197 * 186 198 * @return COM result indicator … … 190 202 const Utf8Str &aHostPath, 191 203 bool aWritable, 192 bool aAutoMount) 204 bool aAutoMount, 205 bool fFailOnError) 193 206 { 194 207 /* Enclose the state transition NotReady->InInit->Ready */ … … 206 219 return rc; 207 220 } 221 222 #endif 208 223 209 224 /** … … 217 232 const Utf8Str &aHostPath, 218 233 bool aWritable, 219 bool aAutoMount) 234 bool aAutoMount, 235 bool fFailOnError) 220 236 { 221 237 LogFlowThisFunc(("aName={%s}, aHostPath={%s}, aWritable={%d}, aAutoMount={%d}\n", … … 245 261 hostPath.stripTrailingSlash(); 246 262 247 /* Check whether the path is full (absolute) */ 248 char hostPathFull[RTPATH_MAX]; 249 int vrc = RTPathAbsEx(NULL, 250 hostPath.c_str(), 251 hostPathFull, 252 sizeof (hostPathFull)); 253 if (RT_FAILURE(vrc)) 254 return setError(E_INVALIDARG, 255 tr("Invalid shared folder path: '%s' (%Rrc)"), 256 hostPath.c_str(), vrc); 257 258 if (RTPathCompare(hostPath.c_str(), hostPathFull) != 0) 259 return setError(E_INVALIDARG, 260 tr("Shared folder path '%s' is not absolute"), 261 hostPath.c_str()); 263 if (fFailOnError) 264 { 265 /* Check whether the path is full (absolute) */ 266 char hostPathFull[RTPATH_MAX]; 267 int vrc = RTPathAbsEx(NULL, 268 hostPath.c_str(), 269 hostPathFull, 270 sizeof (hostPathFull)); 271 if (RT_FAILURE(vrc)) 272 return setError(E_INVALIDARG, 273 tr("Invalid shared folder path: '%s' (%Rrc)"), 274 hostPath.c_str(), vrc); 275 276 if (RTPathCompare(hostPath.c_str(), hostPathFull) != 0) 277 return setError(E_INVALIDARG, 278 tr("Shared folder path '%s' is not absolute"), 279 hostPath.c_str()); 280 } 262 281 263 282 unconst(mParent) = aParent; -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r35755 r35757 1384 1384 strHostPath, 1385 1385 writable, 1386 autoMount); 1386 autoMount, 1387 false /* fFailOnError */); 1387 1388 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 1388 1389 … … 2851 2852 CheckComArgStrNotEmptyOrNull(aHostPath); 2852 2853 2854 LogFlowThisFunc(("Entering for '%ls' -> '%ls'\n", aName, aHostPath)); 2855 2853 2856 AutoCaller autoCaller(this); 2854 2857 if (FAILED(autoCaller.rc())) return autoCaller.rc(); … … 2877 2880 if (SUCCEEDED(rc)) 2878 2881 return setError(VBOX_E_FILE_ERROR, 2879 tr("Shared folder named '%s' already exists"),2880 strName.c_str());2882 tr("Shared folder named '%s' already exists"), 2883 strName.c_str()); 2881 2884 2882 2885 pSharedFolder.createObject(); 2883 rc = pSharedFolder->init(this, strName, strHostPath, aWritable, aAutoMount); 2886 rc = pSharedFolder->init(this, 2887 strName, 2888 strHostPath, 2889 aWritable, 2890 aAutoMount, 2891 true /* fFailOnError */); 2884 2892 if (FAILED(rc)) return rc; 2885 2893 … … 2914 2922 fireSharedFolderChangedEvent(mEventSource, Scope_Session); 2915 2923 2924 LogFlowThisFunc(("Leaving for '%ls' -> '%ls'\n", aName, aHostPath)); 2925 2916 2926 return rc; 2917 2927 } … … 2923 2933 AutoCaller autoCaller(this); 2924 2934 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2935 2936 LogFlowThisFunc(("Entering for '%ls'\n", aName)); 2925 2937 2926 2938 Utf8Str strName(aName); … … 2976 2988 /* notify console callbacks after the folder is removed to the list */ 2977 2989 fireSharedFolderChangedEvent(mEventSource, Scope_Session); 2990 2991 LogFlowThisFunc(("Leaving for '%ls'\n", aName)); 2978 2992 2979 2993 return rc; … … 6195 6209 isWriteLockOnCurrentThread(), E_FAIL); 6196 6210 6211 LogFlowThisFunc(("Entering\n")); 6212 6197 6213 /* protect mpVM (if not NULL) */ 6198 6214 AutoVMCallerQuietWeak autoVMCaller(this); … … 6205 6221 && m_pVMMDev->isShFlActive(); 6206 6222 6207 if (aGlobal) 6208 { 6209 /// @todo grab & process global folders when they are done 6210 } 6211 else 6212 { 6213 SharedFolderDataMap oldFolders; 6214 if (online) 6215 oldFolders = m_mapMachineSharedFolders; 6216 6217 m_mapMachineSharedFolders.clear(); 6218 6219 SafeIfaceArray<ISharedFolder> folders; 6220 rc = mMachine->COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)); 6221 AssertComRCReturnRC(rc); 6222 6223 for (size_t i = 0; i < folders.size(); ++i) 6224 { 6225 ComPtr<ISharedFolder> pSharedFolder = folders[i]; 6226 6227 Bstr bstrName; 6228 Bstr bstrHostPath; 6229 BOOL writable; 6230 BOOL autoMount; 6231 6232 rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam()); 6233 if (FAILED(rc)) break; 6234 Utf8Str strName(bstrName); 6235 6236 rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam()); 6237 if (FAILED(rc)) break; 6238 Utf8Str strHostPath(bstrHostPath); 6239 6240 rc = pSharedFolder->COMGETTER(Writable)(&writable); 6241 if (FAILED(rc)) break; 6242 6243 rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount); 6244 if (FAILED(rc)) break; 6245 6246 m_mapMachineSharedFolders.insert(std::make_pair(strName, 6247 SharedFolderData(strHostPath, writable, autoMount))); 6248 6249 /* send changes to HGCM if the VM is running */ 6250 /// @todo umoeller report errors as runtime warnings through VMSetError 6223 try 6224 { 6225 if (aGlobal) 6226 { 6227 /// @todo grab & process global folders when they are done 6228 } 6229 else 6230 { 6231 SharedFolderDataMap oldFolders; 6232 if (online) 6233 oldFolders = m_mapMachineSharedFolders; 6234 6235 m_mapMachineSharedFolders.clear(); 6236 6237 SafeIfaceArray<ISharedFolder> folders; 6238 rc = mMachine->COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)); 6239 if (FAILED(rc)) throw rc; 6240 6241 for (size_t i = 0; i < folders.size(); ++i) 6242 { 6243 ComPtr<ISharedFolder> pSharedFolder = folders[i]; 6244 6245 Bstr bstrName; 6246 Bstr bstrHostPath; 6247 BOOL writable; 6248 BOOL autoMount; 6249 6250 rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam()); 6251 if (FAILED(rc)) throw rc; 6252 Utf8Str strName(bstrName); 6253 6254 rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam()); 6255 if (FAILED(rc)) throw rc; 6256 Utf8Str strHostPath(bstrHostPath); 6257 6258 rc = pSharedFolder->COMGETTER(Writable)(&writable); 6259 if (FAILED(rc)) throw rc; 6260 6261 rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount); 6262 if (FAILED(rc)) throw rc; 6263 6264 m_mapMachineSharedFolders.insert(std::make_pair(strName, 6265 SharedFolderData(strHostPath, writable, autoMount))); 6266 6267 /* send changes to HGCM if the VM is running */ 6268 /// @todo umoeller report errors as runtime warnings through VMSetError 6269 if (online) 6270 { 6271 SharedFolderDataMap::iterator it = oldFolders.find(strName); 6272 if ( it == oldFolders.end() 6273 || it->second.m_strHostPath != strHostPath) 6274 { 6275 /* a new machine folder is added or 6276 * the existing machine folder is changed */ 6277 if (m_mapSharedFolders.find(strName) != m_mapSharedFolders.end()) 6278 ; /* the console folder exists, nothing to do */ 6279 else 6280 { 6281 /* remove the old machine folder (when changed) 6282 * or the global folder if any (when new) */ 6283 if ( it != oldFolders.end() 6284 || m_mapGlobalSharedFolders.find(strName) != m_mapGlobalSharedFolders.end() 6285 ) 6286 { 6287 rc = removeSharedFolder(strName); 6288 if (FAILED(rc)) throw rc; 6289 } 6290 6291 /* create the new machine folder */ 6292 rc = createSharedFolder(strName, 6293 SharedFolderData(strHostPath, 6294 writable, 6295 autoMount)); 6296 if (FAILED(rc)) throw rc; 6297 } 6298 } 6299 /* forget the processed (or identical) folder */ 6300 if (it != oldFolders.end()) 6301 oldFolders.erase(it); 6302 } 6303 } 6304 6305 /* process outdated (removed) folders */ 6251 6306 if (online) 6252 6307 { 6253 SharedFolderDataMap::iterator it = oldFolders.find(strName); 6254 if ( it == oldFolders.end() 6255 || it->second.m_strHostPath != strHostPath) 6308 for (SharedFolderDataMap::const_iterator it = oldFolders.begin(); 6309 it != oldFolders.end(); ++ it) 6256 6310 { 6257 /* a new machine folder is added or 6258 * the existing machine folder is changed */ 6259 if (m_mapSharedFolders.find(strName) != m_mapSharedFolders.end()) 6311 if (m_mapSharedFolders.find(it->first) != m_mapSharedFolders.end()) 6260 6312 ; /* the console folder exists, nothing to do */ 6261 6313 else 6262 6314 { 6263 /* remove the old machine folder (when changed) 6264 * or the global folder if any (when new) */ 6265 if ( it != oldFolders.end() 6266 || m_mapGlobalSharedFolders.find(strName) != m_mapGlobalSharedFolders.end() 6267 ) 6268 rc = removeSharedFolder(strName); 6269 /* create the new machine folder */ 6270 rc = createSharedFolder(strName, 6271 SharedFolderData(strHostPath, 6272 writable, 6273 autoMount)); 6315 /* remove the outdated machine folder */ 6316 rc = removeSharedFolder(it->first); 6317 if (FAILED(rc)) throw rc; 6318 6319 /* create the global folder if there is any */ 6320 SharedFolderDataMap::const_iterator git = 6321 m_mapGlobalSharedFolders.find(it->first); 6322 if (git != m_mapGlobalSharedFolders.end()) 6323 { 6324 rc = createSharedFolder(git->first, git->second); 6325 if (FAILED(rc)) throw rc; 6326 } 6274 6327 } 6275 6328 } 6276 /* forget the processed (or identical) folder */6277 if (it != oldFolders.end())6278 oldFolders.erase(it);6279 6280 rc = S_OK;6281 6329 } 6282 6330 } 6283 6284 AssertComRCReturnRC(rc); 6285 6286 /* process outdated (removed) folders */ 6287 /// @todo report errors as runtime warnings through VMSetError 6331 } 6332 catch (HRESULT rc2) 6333 { 6288 6334 if (online) 6289 { 6290 for (SharedFolderDataMap::const_iterator it = oldFolders.begin(); 6291 it != oldFolders.end(); ++ it) 6292 { 6293 if (m_mapSharedFolders.find(it->first) != m_mapSharedFolders.end()) 6294 ; /* the console folder exists, nothing to do */ 6295 else 6296 { 6297 /* remove the outdated machine folder */ 6298 rc = removeSharedFolder(it->first); 6299 /* create the global folder if there is any */ 6300 SharedFolderDataMap::const_iterator git = 6301 m_mapGlobalSharedFolders.find(it->first); 6302 if (git != m_mapGlobalSharedFolders.end()) 6303 rc = createSharedFolder(git->first, git->second); 6304 } 6305 } 6306 6307 rc = S_OK; 6308 } 6309 } 6335 setVMRuntimeErrorCallbackF(mpVM, this, 0, "BrokenSharedFolder", 6336 N_("Broken shared folder!")); 6337 } 6338 6339 LogFlowThisFunc(("Leaving\n")); 6310 6340 6311 6341 return rc; … … 6364 6394 6365 6395 Log(("Adding shared folder '%s' -> '%s'\n", strName.c_str(), aData.m_strHostPath.c_str())); 6396 6397 // check whether the path is valid and exists 6398 /* Check whether the path is full (absolute) */ 6399 char hostPathFull[RTPATH_MAX]; 6400 int vrc = RTPathAbsEx(NULL, 6401 aData.m_strHostPath.c_str(), 6402 hostPathFull, 6403 sizeof(hostPathFull)); 6404 if (RT_FAILURE(vrc)) 6405 return setError(E_INVALIDARG, 6406 tr("Invalid shared folder path: '%s' (%Rrc)"), 6407 aData.m_strHostPath.c_str(), vrc); 6408 6409 if (RTPathCompare(aData.m_strHostPath.c_str(), hostPathFull) != 0) 6410 return setError(E_INVALIDARG, 6411 tr("Shared folder path '%s' is not absolute"), 6412 aData.m_strHostPath.c_str()); 6413 if (!RTPathExists(hostPathFull)) 6414 return setError(E_INVALIDARG, 6415 tr("Shared folder path '%s' does not exist on the host"), 6416 aData.m_strHostPath.c_str()); 6417 6418 // now that we know the path is good, give it to HGCM 6366 6419 6367 6420 Bstr bstrName(strName); … … 6411 6464 parms[3].u.uint32 = aData.m_fAutoMount; 6412 6465 6413 intvrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders",6414 6415 6466 vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders", 6467 SHFL_FN_ADD_MAPPING, 6468 SHFL_CPARMS_ADD_MAPPING2, &parms[0]); 6416 6469 RTMemFree(pFolderName); 6417 6470 RTMemFree(pMapName); … … 7830 7883 { 7831 7884 const SharedFolderData &d = it->second; 7832 rc = pConsole->createSharedFolder(it->first, 7833 d); 7834 if (FAILED(rc)) break; 7885 rc = pConsole->createSharedFolder(it->first, d); 7886 if (FAILED(rc)) 7887 { 7888 ErrorInfoKeeper eik; 7889 setVMRuntimeErrorCallbackF(pVM, pConsole, 0, "BrokenSharedFolder", 7890 N_("The shared folder '%s' could not be set up: %ls.\n" 7891 "The shared folder setup will not be complete. It is recommended to power down the virtual machine and " 7892 "fix the shared folder settings while the machine is not running."), 7893 it->first.c_str(), eik.getText().raw()); 7894 break; 7895 } 7835 7896 } 7836 if (FAILED(rc)) break; 7897 if (FAILED(rc)) 7898 rc = S_OK; // do not fail with broken shared folders 7837 7899 7838 7900 /* enter the lock again */ -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r35755 r35757 4652 4652 if (FAILED(rc)) return rc; 4653 4653 4654 Utf8Str strName(aName); 4655 4654 4656 ComObjPtr<SharedFolder> sharedFolder; 4655 rc = findSharedFolder( aName, sharedFolder, false /* aSetError */);4657 rc = findSharedFolder(strName, sharedFolder, false /* aSetError */); 4656 4658 if (SUCCEEDED(rc)) 4657 4659 return setError(VBOX_E_OBJECT_IN_USE, 4658 tr("Shared folder named '% ls' already exists"),4659 aName);4660 tr("Shared folder named '%s' already exists"), 4661 strName.c_str()); 4660 4662 4661 4663 sharedFolder.createObject(); 4662 rc = sharedFolder->init(getMachine(), aName, aHostPath, aWritable, aAutoMount); 4664 rc = sharedFolder->init(getMachine(), 4665 strName, 4666 aHostPath, 4667 !!aWritable, 4668 !!aAutoMount, 4669 true /* fFailOnError */); 4663 4670 if (FAILED(rc)) return rc; 4664 4671
Note:
See TracChangeset
for help on using the changeset viewer.