Changeset 69611 in vbox for trunk/src/VBox/Storage
- Timestamp:
- Nov 7, 2017 7:02:47 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/vbox-img.cpp
r69609 r69611 1334 1334 1335 1335 1336 static DECLCALLBACK(int) vboximgDvmRead(void *pvUser, uint64_t off, void *pvBuf, size_t cbRead)1337 {1338 int rc = VINF_SUCCESS;1339 PVDISK pDisk = (PVDISK)pvUser;1340 1341 /* Take shortcut if possible. */1342 if ( off % 512 == 01343 && cbRead % 512 == 0)1344 rc = VDRead(pDisk, off, pvBuf, cbRead);1345 else1346 {1347 uint8_t *pbBuf = (uint8_t *)pvBuf;1348 uint8_t abBuf[512];1349 1350 /* Unaligned access, make it aligned. */1351 if (off % 512 != 0)1352 {1353 uint64_t offAligned = off & ~(uint64_t)(512 - 1);1354 size_t cbToCopy = 512 - (off - offAligned);1355 rc = VDRead(pDisk, offAligned, abBuf, 512);1356 if (RT_SUCCESS(rc))1357 {1358 memcpy(pbBuf, &abBuf[off - offAligned], cbToCopy);1359 pbBuf += cbToCopy;1360 off += cbToCopy;1361 cbRead -= cbToCopy;1362 }1363 }1364 1365 if ( RT_SUCCESS(rc)1366 && (cbRead & ~(uint64_t)(512 - 1)))1367 {1368 size_t cbReadAligned = cbRead & ~(uint64_t)(512 - 1);1369 1370 Assert(!(off % 512));1371 rc = VDRead(pDisk, off, pbBuf, cbReadAligned);1372 if (RT_SUCCESS(rc))1373 {1374 pbBuf += cbReadAligned;1375 off += cbReadAligned;1376 cbRead -= cbReadAligned;1377 }1378 }1379 1380 if ( RT_SUCCESS(rc)1381 && cbRead)1382 {1383 Assert(cbRead < 512);1384 Assert(!(off % 512));1385 1386 rc = VDRead(pDisk, off, abBuf, 512);1387 if (RT_SUCCESS(rc))1388 memcpy(pbBuf, abBuf, cbRead);1389 }1390 }1391 1392 return rc;1393 }1394 1395 1396 static DECLCALLBACK(int) vboximgDvmWrite(void *pvUser, uint64_t off, const void *pvBuf, size_t cbWrite)1397 {1398 PVDISK pDisk = (PVDISK)pvUser;1399 return VDWrite(pDisk, off, pvBuf, cbWrite);1400 }1401 1402 1403 1336 static DECLCALLBACK(int) vboximgQueryBlockStatus(void *pvUser, uint64_t off, 1404 1337 uint64_t cb, bool *pfAllocated)
Note:
See TracChangeset
for help on using the changeset viewer.