Changeset 59620 in vbox for trunk/src/VBox/Runtime/common/vfs
- Timestamp:
- Feb 10, 2016 12:47:33 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105459
- Location:
- trunk/src/VBox/Runtime/common/vfs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp
r57358 r59620 2135 2135 2136 2136 2137 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)2137 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 2138 2138 { 2139 2139 AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER); … … 2150 2150 int rc; 2151 2151 if (!(pThis->pOps->fFeatures & RTVFSIOSTREAMOPS_FEAT_NO_SG)) 2152 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, pSgBuf, fBlocking, pcbRead);2152 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, off, pSgBuf, fBlocking, pcbRead); 2153 2153 else 2154 2154 { … … 2162 2162 2163 2163 size_t cbReadSeg = pcbRead ? 0 : pSgBuf->paSegs[iSeg].cbSeg; 2164 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbRead ? &cbReadSeg : NULL);2164 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbRead ? &cbReadSeg : NULL); 2165 2165 if (RT_FAILURE(rc)) 2166 2166 break; … … 2168 2168 if ((pcbRead && cbReadSeg != SgBuf.paSegs[0].cbSeg) || rc != VINF_SUCCESS) 2169 2169 break; 2170 if (off != -1) 2171 off += cbReadSeg; 2170 2172 } 2171 2173 … … 2178 2180 2179 2181 2180 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)2182 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 2181 2183 { 2182 2184 AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER); … … 2193 2195 int rc; 2194 2196 if (!(pThis->pOps->fFeatures & RTVFSIOSTREAMOPS_FEAT_NO_SG)) 2195 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, pSgBuf, fBlocking, pcbWritten);2197 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, pSgBuf, fBlocking, pcbWritten); 2196 2198 else 2197 2199 { … … 2205 2207 2206 2208 size_t cbWrittenSeg = 0; 2207 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten ? &cbWrittenSeg : NULL);2209 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbWritten ? &cbWrittenSeg : NULL); 2208 2210 if (RT_FAILURE(rc)) 2209 2211 break; … … 2213 2215 if (cbWrittenSeg != SgBuf.paSegs[0].cbSeg) 2214 2216 break; 2217 if (off != -1) 2218 off += cbWrittenSeg; 2215 2219 } 2220 else if (off != -1) 2221 off += pSgBuf->paSegs[iSeg].cbSeg; 2216 2222 } 2217 2223 -
trunk/src/VBox/Runtime/common/vfs/vfsiosmisc.cpp
r57358 r59620 33 33 34 34 #include <iprt/err.h> 35 #include <iprt/mem.h> 35 36 #include <iprt/string.h> 36 37 … … 124 125 } 125 126 127 128 /** Header size. */ 129 #define READ_ALL_HEADER_SIZE 0x20 130 /** The header magic. It's followed by the size (both size_t). */ 131 #define READ_ALL_HEADER_MAGIC UINT32_C(0x11223355) 132 133 RTDECL(int) RTVfsIoStrmReadAll(RTVFSIOSTREAM hVfsIos, void **ppvBuf, size_t *pcbBuf) 134 { 135 /* 136 * Try query the object information and in case the stream has a known 137 * size we could use for guidance. 138 */ 139 RTFSOBJINFO ObjInfo; 140 int rc = RTVfsIoStrmQueryInfo(hVfsIos, &ObjInfo, RTFSOBJATTRADD_NOTHING); 141 size_t cbAllocated = RT_SUCCESS(rc) && ObjInfo.cbObject > 0 && ObjInfo.cbObject < _1G 142 ? (size_t)ObjInfo.cbObject + 1 : _16K; 143 cbAllocated += READ_ALL_HEADER_SIZE; 144 void *pvBuf = RTMemAlloc(cbAllocated); 145 if (pvBuf) 146 { 147 memset(pvBuf, 0xfe, READ_ALL_HEADER_SIZE); 148 size_t off = 0; 149 for (;;) 150 { 151 /* 152 * Handle buffer growing and detecting the end of it all. 153 */ 154 size_t cbToRead = cbAllocated - off - READ_ALL_HEADER_SIZE - 1; 155 if (!cbToRead) 156 { 157 /* The end? */ 158 uint8_t bIgn; 159 size_t cbIgn; 160 rc = RTVfsIoStrmRead(hVfsIos, &bIgn, 0, true /*fBlocking*/, &cbIgn); 161 if (rc == VINF_EOF) 162 break; 163 164 /* Grow the buffer. */ 165 cbAllocated -= READ_ALL_HEADER_SIZE - 1; 166 cbAllocated = RT_MAX(RT_MIN(cbAllocated, _32M), _1K); 167 cbAllocated = RT_ALIGN_Z(cbAllocated, _4K); 168 cbAllocated += READ_ALL_HEADER_SIZE + 1; 169 170 void *pvNew = RTMemRealloc(pvBuf, cbAllocated); 171 AssertBreakStmt(pvNew, rc = VERR_NO_MEMORY); 172 173 cbToRead = cbAllocated - off - READ_ALL_HEADER_SIZE - 1; 174 } 175 Assert(cbToRead < cbAllocated); 176 177 /* 178 * Read. 179 */ 180 size_t cbActual; 181 rc = RTVfsIoStrmRead(hVfsIos, (uint8_t *)pvBuf + READ_ALL_HEADER_SIZE + off, cbToRead, 182 true /*fBlocking*/, &cbActual); 183 if (RT_FAILURE(rc)) 184 break; 185 Assert(cbActual > 0); 186 Assert(cbActual <= cbToRead); 187 off += cbActual; 188 if (rc == VINF_EOF) 189 break; 190 } 191 Assert(rc != VERR_EOF); 192 if (RT_SUCCESS(rc)) 193 { 194 ((size_t *)pvBuf)[0] = READ_ALL_HEADER_MAGIC; 195 ((size_t *)pvBuf)[1] = off; 196 ((uint8_t *)pvBuf)[READ_ALL_HEADER_SIZE + off] = 0; 197 198 *ppvBuf = (uint8_t *)pvBuf + READ_ALL_HEADER_SIZE; 199 *pcbBuf = off; 200 return VINF_SUCCESS; 201 } 202 203 RTMemFree(pvBuf); 204 } 205 else 206 rc = VERR_NO_MEMORY; 207 *ppvBuf = NULL; 208 *pcbBuf = 0; 209 return rc; 210 } 211 212 213 RTDECL(void) RTVfsIoStrmReadAllFree(void *pvBuf, size_t cbBuf) 214 { 215 AssertPtrReturnVoid(pvBuf); 216 217 /* Spool back to the start of the header. */ 218 pvBuf = (uint8_t *)pvBuf - READ_ALL_HEADER_SIZE; 219 220 /* Make sure the caller isn't messing with us. Hardcoded, but works. */ 221 Assert(((size_t *)pvBuf)[0] == READ_ALL_HEADER_MAGIC); 222 Assert(((size_t *)pvBuf)[1] == cbBuf); 223 224 /* Free it. */ 225 RTMemFree(pvBuf); 226 } 227 -
trunk/src/VBox/Runtime/common/vfs/vfsmemory.cpp
r59524 r59620 805 805 806 806 807 RTDECL(int) RTVfsFileFromBuffer( RTVFSIOSTREAM hVfsIos,uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile)807 RTDECL(int) RTVfsFileFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile) 808 808 { 809 809 /* … … 832 832 return VINF_SUCCESS; 833 833 } 834 RTVfsFileRelease(hVfsFile); 835 } 836 return rc; 837 } 838 839 840 RTDECL(int) RTVfsIoStrmFromBuffer(uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSIOSTREAM phVfsIos) 841 { 842 RTVFSFILE hVfsFile; 843 int rc = RTVfsFileFromBuffer(fFlags, pvBuf, cbBuf, &hVfsFile); 844 if (RT_SUCCESS(rc)) 845 { 846 *phVfsIos = RTVfsFileToIoStream(hVfsFile); 834 847 RTVfsFileRelease(hVfsFile); 835 848 } -
trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp
r57635 r59620 502 502 int rc = RTVfsFileOpenNormal(pszFilename, fOpen, &hVfsFile); 503 503 if (RT_SUCCESS(rc)) 504 { 504 505 *phVfsIos = RTVfsFileToIoStream(hVfsFile); 505 return rc; 506 } 507 506 RTVfsFileRelease(hVfsFile); 507 } 508 return rc; 509 } 510
Note:
See TracChangeset
for help on using the changeset viewer.