Changeset 67207 in vbox for trunk/src/VBox
- Timestamp:
- Jun 1, 2017 1:16:02 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 115889
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/VDVfs.cpp
r66250 r67207 210 210 * @interface_method_impl{RTVFSOBJOPS,pfnQueryInfo} 211 211 */ 212 static DECLCALLBACK(int) vdVfsFile_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, 213 RTFSOBJATTRADD enmAddAttr) 214 { 215 NOREF(pvThis); 216 NOREF(pObjInfo); 217 NOREF(enmAddAttr); 218 return VERR_NOT_SUPPORTED; 212 static DECLCALLBACK(int) vdVfsFile_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr) 213 { 214 PVDVFSFILE pThis = (PVDVFSFILE)pvThis; 215 unsigned const cOpenImages = VDGetCount(pThis->pDisk); 216 217 pObjInfo->cbObject = VDGetSize(pThis->pDisk, cOpenImages - 1); 218 pObjInfo->cbAllocated = 0; 219 for (unsigned iImage = 0; iImage < cOpenImages; iImage++) 220 pObjInfo->cbAllocated += VDGetFileSize(pThis->pDisk, iImage); 221 222 /** @todo enumerate the disk images directly... */ 223 RTTimeNow(&pObjInfo->AccessTime); 224 pObjInfo->BirthTime = pObjInfo->AccessTime; 225 pObjInfo->ChangeTime = pObjInfo->AccessTime; 226 pObjInfo->ModificationTime = pObjInfo->AccessTime; 227 228 pObjInfo->Attr.fMode = RTFS_DOS_NT_NORMAL | RTFS_TYPE_FILE | 0644; 229 pObjInfo->Attr.enmAdditional = enmAddAttr; 230 switch (enmAddAttr) 231 { 232 case RTFSOBJATTRADD_UNIX: 233 pObjInfo->Attr.u.Unix.uid = NIL_RTUID; 234 pObjInfo->Attr.u.Unix.gid = NIL_RTGID; 235 pObjInfo->Attr.u.Unix.cHardlinks = 1; 236 pObjInfo->Attr.u.Unix.INodeIdDevice = 0; 237 pObjInfo->Attr.u.Unix.INodeId = 0; 238 pObjInfo->Attr.u.Unix.fFlags = 0; 239 pObjInfo->Attr.u.Unix.GenerationId = 0; 240 pObjInfo->Attr.u.Unix.Device = 0; 241 break; 242 243 case RTFSOBJATTRADD_UNIX_OWNER: 244 pObjInfo->Attr.u.UnixOwner.uid = NIL_RTUID; 245 pObjInfo->Attr.u.UnixOwner.szName[0] = '\0'; 246 break; 247 case RTFSOBJATTRADD_UNIX_GROUP: 248 pObjInfo->Attr.u.UnixGroup.gid = NIL_RTGID; 249 pObjInfo->Attr.u.UnixGroup.szName[0] = '\0'; 250 break; 251 case RTFSOBJATTRADD_EASIZE: 252 pObjInfo->Attr.u.EASize.cb = 0; 253 break; 254 255 default: 256 AssertFailedReturn(VERR_INVALID_PARAMETER); 257 } 258 259 return VINF_SUCCESS; 219 260 } 220 261 … … 226 267 { 227 268 PVDVFSFILE pThis = (PVDVFSFILE)pvThis; 228 int rc = VINF_SUCCESS;229 269 230 270 Assert(pSgBuf->cSegs == 1); … … 235 275 */ 236 276 uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off; 237 if (offUnsigned >= VDGetSize(pThis->pDisk, VD_LAST_IMAGE)) 277 uint64_t const cbImage = VDGetSize(pThis->pDisk, VD_LAST_IMAGE); 278 if (offUnsigned >= cbImage) 238 279 { 239 280 if (pcbRead) 240 281 { 241 282 *pcbRead = 0; 242 pThis->offCurPos = offUnsigned;283 pThis->offCurPos = cbImage; 243 284 return VINF_EOF; 244 285 } … … 246 287 } 247 288 248 size_t cbLeftToRead; 249 if (offUnsigned + pSgBuf->paSegs[0].cbSeg > VDGetSize(pThis->pDisk, VD_LAST_IMAGE)) 289 int rc = VINF_SUCCESS; 290 size_t cbLeftToRead = pSgBuf->paSegs[0].cbSeg; 291 if (offUnsigned + cbLeftToRead <= cbImage) 292 { 293 if (pcbRead) 294 *pcbRead = cbLeftToRead; 295 } 296 else 250 297 { 251 298 if (!pcbRead) 252 299 return VERR_EOF; 253 *pcbRead = cbLeftToRead = (size_t)(VDGetSize(pThis->pDisk, VD_LAST_IMAGE) - offUnsigned); 254 } 255 else 256 { 257 cbLeftToRead = pSgBuf->paSegs[0].cbSeg; 258 if (pcbRead) 259 *pcbRead = cbLeftToRead; 300 *pcbRead = cbLeftToRead = (size_t)(cbImage - offUnsigned); 301 rc = VINF_EOF; 260 302 } 261 303 … … 265 307 if (cbLeftToRead > 0) 266 308 { 267 rc = vdReadHelper(pThis->pDisk, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbLeftToRead);268 if (RT_SUCCESS(rc ))309 int rc2 = vdReadHelper(pThis->pDisk, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToRead); 310 if (RT_SUCCESS(rc2)) 269 311 offUnsigned += cbLeftToRead; 312 else 313 rc = rc2; 270 314 } 271 315 … … 281 325 { 282 326 PVDVFSFILE pThis = (PVDVFSFILE)pvThis; 283 int rc = VINF_SUCCESS;284 327 285 328 Assert(pSgBuf->cSegs == 1); … … 291 334 */ 292 335 uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off; 293 if (offUnsigned >= VDGetSize(pThis->pDisk, VD_LAST_IMAGE)) 336 uint64_t const cbImage = VDGetSize(pThis->pDisk, VD_LAST_IMAGE); 337 if (offUnsigned >= cbImage) 294 338 { 295 339 if (pcbWritten) 296 340 { 297 341 *pcbWritten = 0; 298 pThis->offCurPos = offUnsigned;299 } 300 return VERR_ NOT_SUPPORTED;342 pThis->offCurPos = cbImage; 343 } 344 return VERR_EOF; 301 345 } 302 346 303 347 size_t cbLeftToWrite; 304 if (offUnsigned + pSgBuf->paSegs[0].cbSeg > VDGetSize(pThis->pDisk, VD_LAST_IMAGE)) 305 { 306 if (!pcbWritten) 307 return VERR_EOF; 308 *pcbWritten = cbLeftToWrite = (size_t)(VDGetSize(pThis->pDisk, VD_LAST_IMAGE) - offUnsigned); 309 } 310 else 348 if (offUnsigned + pSgBuf->paSegs[0].cbSeg < cbImage) 311 349 { 312 350 cbLeftToWrite = pSgBuf->paSegs[0].cbSeg; … … 314 352 *pcbWritten = cbLeftToWrite; 315 353 } 354 else 355 { 356 if (!pcbWritten) 357 return VERR_EOF; 358 *pcbWritten = cbLeftToWrite = (size_t)(cbImage - offUnsigned); 359 } 316 360 317 361 /* 318 362 * Ok, we've got a valid stretch within the file. Do the reading. 319 363 */ 364 int rc = VINF_SUCCESS; 320 365 if (cbLeftToWrite > 0) 321 366 { 322 rc = vdWriteHelper(pThis->pDisk, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbLeftToWrite);367 rc = vdWriteHelper(pThis->pDisk, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToWrite); 323 368 if (RT_SUCCESS(rc)) 324 369 offUnsigned += cbLeftToWrite; … … 344 389 */ 345 390 static DECLCALLBACK(int) vdVfsFile_PollOne(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, 346 391 uint32_t *pfRetEvents) 347 392 { 348 393 NOREF(pvThis); … … 439 484 440 485 /* 441 * Calc new position, take care to stay within bounds. 442 * 443 * @todo: Setting position beyond the end of the disk does not make sense. 486 * Calc new position, take care to stay without bounds. 444 487 */ 445 488 uint64_t offNew;
Note:
See TracChangeset
for help on using the changeset viewer.