Changeset 23589 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Oct 6, 2009 9:33:17 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 53255
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/SSM.cpp
r23542 r23589 353 353 } SSMSTATE; 354 354 355 355 356 /** Pointer to a SSM stream buffer. */ 356 357 typedef struct SSMSTRMBUF *PSSMSTRMBUF; … … 381 382 typedef struct SSMSTRM 382 383 { 383 /** The file handle. */ 384 RTFILE hFile; 384 /** The stream method table. */ 385 PCSSMSTRMOPS pOps; 386 /** The user argument for the stream methods. 387 * For file based streams, this is the file handle and not a pointer. */ 388 void *pvUser; 385 389 386 390 /** Write (set) or read (clear) stream. */ … … 1627 1631 1628 1632 /** 1633 * @copydoc SSMSTRMOPS::pfnWrite 1634 */ 1635 static DECLCALLBACK(int) ssmR3FileWrite(void *pvUser, uint64_t offStream, const void *pvBuf, size_t cbToWrite) 1636 { 1637 Assert(RTFileTell((RTFILE)(uintptr_t)pvUser) == offStream); NOREF(offStream); 1638 return RTFileWriteAt((RTFILE)(uintptr_t)pvUser, offStream, pvBuf, cbToWrite, NULL); /** @todo use RTFileWrite */ 1639 } 1640 1641 1642 /** 1643 * @copydoc SSMSTRMOPS::pfnRead 1644 */ 1645 static DECLCALLBACK(int) ssmR3FileRead(void *pvUser, uint64_t offStream, void *pvBuf, size_t cbToRead, size_t *pcbRead) 1646 { 1647 Assert(RTFileTell((RTFILE)(uintptr_t)pvUser) == offStream); NOREF(offStream); 1648 return RTFileRead((RTFILE)(uintptr_t)pvUser, pvBuf, cbToRead, pcbRead); 1649 } 1650 1651 1652 /** 1653 * @copydoc SSMSTRMOPS::pfnSeek 1654 */ 1655 static DECLCALLBACK(int) ssmR3FileSeek(void *pvUser, int64_t offSeek, unsigned uMethod, uint64_t *poffActual) 1656 { 1657 return RTFileSeek((RTFILE)(uintptr_t)pvUser, offSeek, uMethod, poffActual); 1658 } 1659 1660 1661 /** 1662 * @copydoc SSMSTRMOPS::pfnTell 1663 */ 1664 static DECLCALLBACK(uint64_t) ssmR3FileTell(void *pvUser) 1665 { 1666 return RTFileTell((RTFILE)(uintptr_t)pvUser); 1667 } 1668 1669 1670 /** 1671 * @copydoc SSMSTRMOPS::pfnSize 1672 */ 1673 static DECLCALLBACK(int) ssmR3FileSize(void *pvUser, uint64_t *pcb) 1674 { 1675 return RTFileGetSize((RTFILE)(uintptr_t)pvUser, pcb); 1676 } 1677 1678 1679 /** 1680 * @copydoc SSMSTRMOPS::pfnClose 1681 */ 1682 static DECLCALLBACK(int) ssmR3FileClose(void *pvUser) 1683 { 1684 return RTFileClose((RTFILE)(uintptr_t)pvUser); 1685 } 1686 1687 1688 /** 1689 * Method table for a file based stream. 1690 */ 1691 static SSMSTRMOPS const g_ssmR3FileOps = 1692 { 1693 SSMSTRMOPS_VERSION, 1694 ssmR3FileWrite, 1695 ssmR3FileRead, 1696 ssmR3FileSeek, 1697 ssmR3FileTell, 1698 ssmR3FileSize, 1699 ssmR3FileClose, 1700 SSMSTRMOPS_VERSION 1701 }; 1702 1703 1704 /** 1629 1705 * Opens a file stream. 1630 1706 * … … 1645 1721 ? RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_WRITE 1646 1722 : RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE; 1647 rc = RTFileOpen(&pStrm->hFile, pszFilename, fFlags); 1723 RTFILE hFile; 1724 rc = RTFileOpen(&hFile, pszFilename, fFlags); 1648 1725 if (RT_SUCCESS(rc)) 1649 1726 { 1727 pStrm->pOps = &g_ssmR3FileOps; 1728 pStrm->pvUser = (void *)(uintptr_t)hFile; 1650 1729 pStrm->fWrite = fWrite; 1651 1730 return VINF_SUCCESS; … … 1918 1997 1919 1998 /* flush */ 1920 int rc = RTFileWriteAt(pStrm->hFile, pCur->offStream, &pCur->abData[0], pCur->cb, NULL);1999 int rc = pStrm->pOps->pfnWrite(pStrm->pvUser, pCur->offStream, &pCur->abData[0], pCur->cb); 1921 2000 if ( RT_FAILURE(rc) 1922 2001 && ssmR3StrmSetError(pStrm, rc)) … … 1963 2042 } 1964 2043 1965 int rc = RTFileClose(pStrm->hFile);2044 int rc = pStrm->pOps->pfnClose(pStrm->pvUser); 1966 2045 if (RT_FAILURE(rc)) 1967 2046 ssmR3StrmSetError(pStrm, rc); 1968 pStrm->hFile = NIL_RTFILE; 2047 pStrm->pOps = NULL; 2048 pStrm->pvUser = NULL; 1969 2049 1970 2050 rc = pStrm->rc; … … 2152 2232 if (pStrm->fNeedSeek) 2153 2233 { 2154 rc = RTFileSeek(pStrm->hFile, pStrm->offNeedSeekTo, RTFILE_SEEK_BEGIN, NULL);2234 rc = pStrm->pOps->pfnSeek(pStrm->pvUser, pStrm->offNeedSeekTo, RTFILE_SEEK_BEGIN, NULL); 2155 2235 if (RT_FAILURE(rc)) 2156 2236 { … … 2170 2250 return pStrm->rc; 2171 2251 2172 pBuf->offStream = RTFileTell(pStrm->hFile);2252 pBuf->offStream = pStrm->pOps->pfnTell(pStrm->pvUser); 2173 2253 size_t cbRead = sizeof(pBuf->abData); 2174 rc = RTFileRead(pStrm->hFile, &pBuf->abData[0], cbRead, &cbRead);2254 rc = pStrm->pOps->pfnRead(pStrm->pvUser, pBuf->offStream, &pBuf->abData[0], cbRead, &cbRead); 2175 2255 if ( RT_SUCCESS(rc) 2176 2256 && cbRead > 0) … … 2406 2486 2407 2487 uint64_t offStream; 2408 int rc = RTFileSeek(pStrm->hFile, off, uMethod, &offStream);2488 int rc = pStrm->pOps->pfnSeek(pStrm->pvUser, off, uMethod, &offStream); 2409 2489 if (RT_SUCCESS(rc)) 2410 2490 { … … 2466 2546 { 2467 2547 uint64_t cbFile; 2468 int rc = RTFileGetSize(pStrm->hFile, &cbFile);2548 int rc = pStrm->pOps->pfnSize(pStrm->pvUser, &cbFile); 2469 2549 AssertLogRelRCReturn(rc, UINT64_MAX); 2470 2550 return cbFile; … … 2480 2560 static bool ssmR3StrmIsFile(PSSMSTRM pStrm) 2481 2561 { 2482 return pStrm-> hFile != NIL_RTFILE;2562 return pStrm->pOps == &g_ssmR3FileOps; 2483 2563 } 2484 2564 … … 2501 2581 static int ssmR3StrmPeekAt(PSSMSTRM pStrm, RTFOFF off, void *pvBuf, size_t cbToRead, uint64_t *poff) 2502 2582 { 2503 AssertReturn(!pStrm->fWrite && pStrm->hFile != NIL_RTFILE, VERR_NOT_SUPPORTED);2583 AssertReturn(!pStrm->fWrite, VERR_NOT_SUPPORTED); 2504 2584 AssertReturn(pStrm->hIoThread == NIL_RTTHREAD, VERR_WRONG_ORDER); 2505 2585 … … 2509 2589 pStrm->offNeedSeekTo = pStrm->offCurStream + (pStrm->pCur ? pStrm->pCur->cb : 0); 2510 2590 } 2511 2512 int rc = RTFileSeek(pStrm->hFile, off, off >= 0 ? RTFILE_SEEK_BEGIN : RTFILE_SEEK_END, poff);2591 uint64_t offActual; 2592 int rc = pStrm->pOps->pfnSeek(pStrm->pvUser, off, off >= 0 ? RTFILE_SEEK_BEGIN : RTFILE_SEEK_END, &offActual); 2513 2593 if (RT_SUCCESS(rc)) 2514 rc = RTFileRead(pStrm->hFile, pvBuf, cbToRead, NULL); 2594 { 2595 if (poff) 2596 *poff = offActual; 2597 rc = pStrm->pOps->pfnRead(pStrm->pvUser, offActual, pvBuf, cbToRead, NULL); 2598 } 2515 2599 2516 2600 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.