Changeset 91685 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Oct 12, 2021 9:26:59 AM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 147413
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/UefiVariableStoreImpl.cpp
r91535 r91685 242 242 HRESULT UefiVariableStore::deleteVariable(const com::Utf8Str &aName, const com::Guid &aOwnerUuid) 243 243 { 244 RT_NOREF(aName, aOwnerUuid); 245 return E_NOTIMPL; 244 RT_NOREF(aOwnerUuid); 245 246 /* the machine needs to be mutable */ 247 AutoMutableStateDependency adep(m->pMachine); 248 if (FAILED(adep.rc())) return adep.rc(); 249 250 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 251 if (FAILED(hrc)) return hrc; 252 253 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 254 255 char szVarPath[_1K]; 256 ssize_t cch = RTStrPrintf2(szVarPath, sizeof(szVarPath), "/raw/%s", aName.c_str()); 257 if (cch > 0) 258 { 259 RTVFSDIR hVfsDirRoot = NIL_RTVFSDIR; 260 int vrc = RTVfsOpenRoot(m->hVfsUefiVarStore, &hVfsDirRoot); 261 if (RT_SUCCESS(vrc)) 262 { 263 vrc = RTVfsDirRemoveDir(hVfsDirRoot, szVarPath, 0 /*fFlags*/); 264 RTVfsDirRelease(hVfsDirRoot); 265 if (RT_FAILURE(vrc)) 266 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to remove variable '%s' (%Rrc)"), aName.c_str(), vrc); 267 } 268 else 269 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to open the variable store root (%Rrc)"), vrc); 270 } 271 else 272 hrc = setError(E_FAIL, tr("The variable name is too long")); 273 274 i_releaseUefiVariableStore(); 275 return hrc; 246 276 } 247 277 … … 249 279 HRESULT UefiVariableStore::changeVariable(const com::Utf8Str &aName, const std::vector<BYTE> &aData) 250 280 { 251 RT_NOREF(aName, aData); 252 return E_NOTIMPL; 281 /* the machine needs to be mutable */ 282 AutoMutableStateDependency adep(m->pMachine); 283 if (FAILED(adep.rc())) return adep.rc(); 284 285 HRESULT hrc = i_retainUefiVariableStore(false /*fReadonly*/); 286 if (FAILED(hrc)) return hrc; 287 288 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS); 289 290 RTVFSFILE hVfsFile = NIL_RTVFSFILE; 291 hrc = i_uefiVarStoreOpenVar(aName.c_str(), &hVfsFile); 292 if (SUCCEEDED(hrc)) 293 { 294 int vrc = RTVfsFileSetSize(hVfsFile, aData.size(), RTVFSFILE_SIZE_F_NORMAL); 295 if (RT_SUCCESS(vrc)) 296 { 297 vrc = RTVfsFileWriteAt(hVfsFile, 0 /*off*/, &aData.front(), aData.size(), NULL /*pcbWritten*/); 298 if (RT_FAILURE(vrc)) 299 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to data for variable '%s' (%Rrc)"), aName.c_str(), vrc); 300 } 301 else 302 hrc = setError(VBOX_E_IPRT_ERROR, tr("Failed to allocate space for the variable '%s' (%Rrc)"), aName.c_str(), vrc); 303 304 RTVfsFileRelease(hVfsFile); 305 } 306 307 i_releaseUefiVariableStore(); 308 return hrc; 253 309 } 254 310 … … 743 799 744 800 801 /** 802 * Tries to open the given variable from the variable store and returns a file handle. 803 * 804 * @returns IPRT status code. 805 * @param pszVar The variable name. 806 * @param phVfsFile Where to return the VFS file handle to the created variable on success. 807 */ 808 HRESULT UefiVariableStore::i_uefiVarStoreOpenVar(const char *pszVar, PRTVFSFILE phVfsFile) 809 { 810 char szVarPath[_1K]; 811 ssize_t cch = RTStrPrintf2(szVarPath, sizeof(szVarPath), "/by-name/%s", pszVar); 812 Assert(cch > 0); RT_NOREF(cch); 813 814 HRESULT hrc = S_OK; 815 int vrc = RTVfsFileOpen(m->hVfsUefiVarStore, szVarPath, 816 RTFILE_O_READWRITE | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, 817 phVfsFile); 818 if ( vrc == VERR_PATH_NOT_FOUND 819 || vrc == VERR_FILE_NOT_FOUND) 820 hrc = setError(VBOX_E_OBJECT_NOT_FOUND, tr("The variable '%s' could not be found"), pszVar); 821 else if (RT_FAILURE(vrc)) 822 hrc = setError(VBOX_E_IPRT_ERROR, tr("Couldn't open variable '%s' (%Rrc)"), pszVar, vrc); 823 824 return hrc; 825 } 826 827 745 828 HRESULT UefiVariableStore::i_uefiVarStoreSetVar(PCEFI_GUID pGuid, const char *pszVar, uint32_t fAttr, const void *pvData, size_t cbData) 746 829 {
Note:
See TracChangeset
for help on using the changeset viewer.