Changeset 33822 in vbox
- Timestamp:
- Nov 7, 2010 8:25:30 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 67467
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/vfs.h
r33820 r33822 40 40 /** @defgroup grp_rt_fs RTVfs - Virtual Filesystem 41 41 * @ingroup grp_rt 42 * 43 * The virtual filesystem APIs are intended to make it possible to work on 44 * container files, file system sub-trees, file system overlays and other custom 45 * filesystem configurations. It also makes it possible to create filters, like 46 * automatically gunzipping a tar.gz file before feeding it to the RTTar API for 47 * unpacking - or wise versa. 48 * 49 * The virtual filesystem APIs are intended to mirror the RTDir, RTFile, RTPath 50 * and RTFs APIs pretty closely so that rewriting a piece of code to work with 51 * it should be easy. However there are some differences to the way the APIs 52 * works and the user should heed the documentation. The differences are 53 * usually motivated by simplification and in some case to make the VFS more 54 * flexible. 55 * 42 56 * @{ 43 57 */ … … 115 129 * @{ 116 130 */ 131 132 /** 133 * Retains a reference to the VFS I/O stream handle. 134 * 135 * @returns New reference count on success, UINT32_MAX on failure. 136 * @param hVfsIos The VFS I/O stream handle. 137 */ 117 138 RTDECL(uint32_t) RTVfsIoStrmRetain(RTVFSIOSTREAM hVfsIos); 139 140 /** 141 * Releases a reference to the VFS I/O stream handle. 142 * 143 * @returns New reference count on success (0 if closed), UINT32_MAX on failure. 144 * @param hVfsIos The VFS I/O stream handle. 145 */ 118 146 RTDECL(uint32_t) RTVfsIoStrmRelease(RTVFSIOSTREAM hVfsIos); 147 148 /** 149 * Convert the VFS I/O stream handle to a VFS file handle. 150 * 151 * @returns The VFS file handle on success, this must be released. 152 * NIL_RTVFSFILE if the I/O stream handle is invalid. 153 * @param hVfsIos The VFS I/O stream handle. 154 * @sa RTVfsFileToIoStream 155 */ 119 156 RTDECL(RTVFSFILE) RTVfsIoStrmToFile(RTVFSIOSTREAM hVfsIos); 157 158 /** 159 * Query information about the I/O stream. 160 * 161 * @returns IPRT status code. 162 * @param hVfsIos The VFS I/O stream handle. 163 * @param pObjInfo Where to return the info. 164 * @param enmAddAttr Which additional attributes should be retrieved. 165 * @sa RTFileQueryInfo 166 */ 120 167 RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr); 168 169 /** 170 * Read bytes from the I/O stream. 171 * 172 * @returns IPRT status code. 173 * @param hVfsIos The VFS I/O stream handle. 174 * @param pvBuf Where to store the read bytes. 175 * @param cbToRead The number of bytes to read. 176 * @param pcbRead Where to store the number of bytes actually read. 177 * If this is NULL, the call will block until @a 178 * cbToRead bytes are available. If this is non-NULL, 179 * the call will not block and return what is currently 180 * avaiable. 181 * @sa RTFileRead, RTPipeRead, RTPipeReadBlocking, RTSocketRead 182 */ 121 183 RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, size_t *pcbRead); 184 185 /** 186 * Write bytes to the I/O stream. 187 * 188 * @returns IPRT status code. 189 * @param hVfsIos The VFS I/O stream handle. 190 * @param pvBuf The bytes to write. 191 * @param cbToWrite The number of bytes to write. 192 * @param pcbWritten Where to store the number of bytes actually written. 193 * If this is NULL, the call will block until @a 194 * cbToWrite bytes are available. If this is non-NULL, 195 * the call will not block and return after writing 196 * what is possible. 197 * @sa RTFileWrite, RTPipeWrite, RTPipeWriteBlocking, RTSocketWrite 198 */ 122 199 RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten); 123 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, size_t *pcbRead); 124 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, size_t *pcbWritten); 200 201 /** 202 * Reads bytes from the I/O stream into a scatter buffer. 203 * 204 * @returns IPRT status code. 205 * @param hVfsIos The VFS I/O stream handle. 206 * @param pSgBuf Pointer to a scatter buffer descriptor. The number 207 * of bytes described by the segments is what will be 208 * attemted read. 209 * @param fBlocking Whether the call is blocking (@c true) or not. If 210 * not, the @a pcbRead parameter must not be NULL. 211 * @param pcbRead Where to store the number of bytes actually read. 212 * This can be NULL if @a fBlocking is true. 213 * @sa RTFileSgRead, RTSocketSgRead 214 */ 215 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead); 216 217 /** 218 * Write bytes to the I/O stream from a gather buffer. 219 * 220 * @returns IPRT status code. 221 * @param hVfsIos The VFS I/O stream handle. 222 * @param pSgBuf Pointer to a gather buffer descriptor. The number 223 * of bytes described by the segments is what will be 224 * attemted written. 225 * @param fBlocking Whether the call is blocking (@c true) or not. If 226 * not, the @a pcbWritten parameter must not be NULL. 227 * @param pcbRead Where to store the number of bytes actually written. 228 * This can be NULL if @a fBlocking is true. 229 * @sa RTFileSgWrite, RTSocketSgWrite 230 */ 231 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten); 232 233 /** 234 * Flush any buffered data to the I/O stream. 235 * 236 * @returns IPRT status code. 237 * @param hVfsIos The VFS I/O stream handle. 238 * @sa RTFileFlush, RTPipeFlush 239 */ 125 240 RTDECL(int) RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos); 241 242 /** 243 * Poll for events. 244 * 245 * @returns IPRT status code. 246 * @param hVfsIos The VFS I/O stream handle. 247 * @param fEvents The events to poll for (RTPOLL_EVT_XXX). 248 * @param cMillies How long to wait for event to eventuate. 249 * @param fIntr Whether the wait is interruptible and can return 250 * VERR_INTERRUPTED (@c true) or if this condition 251 * should be hidden from the caller (@c false). 252 * @param pfRetEvents Where to return the event mask. 253 * @sa RTPollSetAdd, RTPoll, RTPollNoResume. 254 */ 126 255 RTDECL(RTFOFF) RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, 127 256 uint32_t *pfRetEvents); 257 /** 258 * Tells the current I/O stream position. 259 * 260 * @returns Zero or higher - where to return the I/O stream offset. Values 261 * below zero are IPRT status codes (VERR_XXX). 262 * @param hVfsIos The VFS I/O stream handle. 263 * @sa RTFileTell 264 */ 128 265 RTDECL(RTFOFF) RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos); 129 266 /** @} */ … … 155 292 * NIL_RTVFSIOSTREAM if the file handle is invalid. 156 293 * @param hVfsFile The VFS file handle. 294 * @sa RTVfsIoStrmToFile 157 295 */ 158 296 RTDECL(RTVFSIOSTREAM) RTVfsFileToIoStream(RTVFSFILE hVfsFile); -
trunk/include/iprt/vfslowlevel.h
r33820 r33822 428 428 * @param pvThis The implementation specific file data. 429 429 * @param poffActual Where to return the actual offset. 430 * @sa RTFile Seek430 * @sa RTFileTell 431 431 */ 432 432 DECLCALLBACKMEMBER(int, pfnTell)(void *pvThis, PRTFOFF poffActual); -
trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp
r33820 r33822 184 184 185 185 186 RTDECL(uint32_t) RTVfsIoStrmRetain(RTVFSIOSTREAM hVfsIos) 187 { 188 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 189 AssertPtrReturn(pThis, UINT32_MAX); 190 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, UINT32_MAX); 191 return rtVfsRetain(&pThis->cRefs); 192 } 193 194 195 RTDECL(uint32_t) RTVfsIoStrmRelease(RTVFSIOSTREAM hVfsIos) 196 { 197 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 198 AssertPtrReturn(pThis, UINT32_MAX); 199 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, UINT32_MAX); 200 201 uint32_t cRefs = rtVfsRelease(&pThis->cRefs); 202 if (!cRefs) 203 { 204 /* 205 * That was the last reference, close the stream. 206 * 207 * This is a little bit more complicated than when releasing a file or 208 * directory handle because the I/O stream can be a sub-object and we 209 * need to get to the real one before handing it to RTMemFree. 210 */ 211 ASMAtomicWriteU32(&pThis->uMagic, RTVFSIOSTREAM_MAGIC_DEAD); 212 pThis->pOps->Obj.pfnClose(pThis->pvThis); 213 214 switch (pThis->pOps->Obj.enmType) 215 { 216 case RTVFSOBJTYPE_IOSTREAM: 217 RTMemFree(pThis); 218 break; 219 220 case RTVFSOBJTYPE_FILE: 221 { 222 RTVFSFILEINTERNAL *pThisFile = RT_FROM_MEMBER(pThis, RTVFSFILEINTERNAL, Stream); 223 ASMAtomicWriteU32(&pThisFile->uMagic, RTVFSIOSTREAM_MAGIC_DEAD); 224 RTMemFree(pThisFile); 225 break; 226 } 227 228 /* Add new I/O stream compatible handle types here. */ 229 230 default: 231 AssertMsgFailed(("%d\n", pThis->pOps->Obj.enmType)); 232 break; 233 } 234 } 235 236 return cRefs; 237 238 } 239 240 241 RTDECL(RTVFSFILE) RTVfsIoStrmToFile(RTVFSIOSTREAM hVfsIos) 242 { 243 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 244 AssertPtrReturn(pThis, NIL_RTVFSFILE); 245 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, NIL_RTVFSFILE); 246 247 if (pThis->pOps->Obj.enmType == RTVFSOBJTYPE_FILE) 248 { 249 rtVfsRetainVoid(&pThis->cRefs); 250 return RT_FROM_MEMBER(pThis, RTVFSFILEINTERNAL, Stream); 251 } 252 253 /* this is no crime, so don't assert. */ 254 return NIL_RTVFSFILE; 255 } 256 257 258 RTDECL(int) RTVfsIoStrmQueryInfo(RTVFSIOSTREAM hVfsIos, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr) 259 { 260 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 261 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 262 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 263 264 return pThis->pOps->Obj.pfnQueryInfo(pThis->pvThis, pObjInfo, enmAddAttr); 265 } 266 267 268 RTDECL(int) RTVfsIoStrmRead(RTVFSIOSTREAM hVfsIos, void *pvBuf, size_t cbToRead, size_t *pcbRead) 269 { 270 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 271 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 272 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 273 274 RTSGSEG Seg = { pvBuf, cbToRead }; 275 RTSGBUF SgBuf; 276 RTSgBufInit(&SgBuf, &Seg, 1); 277 return pThis->pOps->pfnRead(pThis->pvThis, -1 /*off*/, &SgBuf, pcbRead == NULL /*fBlocking*/, pcbRead); 278 } 279 280 281 RTDECL(int) RTVfsIoStrmWrite(RTVFSIOSTREAM hVfsIos, const void *pvBuf, size_t cbToWrite, size_t *pcbWritten) 282 { 283 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 284 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 285 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 286 287 RTSGSEG Seg = { (void *)pvBuf, cbToWrite }; 288 RTSGBUF SgBuf; 289 RTSgBufInit(&SgBuf, &Seg, 1); 290 return pThis->pOps->pfnWrite(pThis->pvThis, -1 /*off*/, &SgBuf, pcbWritten == NULL /*fBlocking*/, pcbWritten); 291 } 292 293 294 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 295 { 296 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 297 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 298 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 299 AssertPtr(pSgBuf); 300 AssertReturn(fBlocking || VALID_PTR(pcbRead), VERR_INVALID_PARAMETER); 301 302 return pThis->pOps->pfnRead(pThis->pvThis, -1 /*off*/, pSgBuf, fBlocking, pcbRead); 303 } 304 305 306 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 307 { 308 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 309 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 310 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 311 AssertPtr(pSgBuf); 312 AssertReturn(fBlocking || VALID_PTR(pcbWritten), VERR_INVALID_PARAMETER); 313 314 return pThis->pOps->pfnWrite(pThis->pvThis, -1 /*off*/, pSgBuf, fBlocking, pcbWritten); 315 } 316 317 318 RTDECL(int) RTVfsIoStrmFlush(RTVFSIOSTREAM hVfsIos) 319 { 320 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 321 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 322 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 323 324 return pThis->pOps->pfnFlush(pThis->pvThis); 325 } 326 327 328 RTDECL(RTFOFF) RTVfsIoStrmPoll(RTVFSIOSTREAM hVfsIos, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, 329 uint32_t *pfRetEvents) 330 { 331 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 332 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 333 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, VERR_INVALID_HANDLE); 334 335 return pThis->pOps->pfnPollOne(pThis->pvThis, fEvents, cMillies, fIntr, pfRetEvents); 336 } 337 338 339 RTDECL(RTFOFF) RTVfsIoStrmTell(RTVFSIOSTREAM hVfsIos) 340 { 341 RTVFSIOSTREAMINTERNAL *pThis = hVfsIos; 342 AssertPtrReturn(pThis, -1); 343 AssertReturn(pThis->uMagic == RTVFSIOSTREAM_MAGIC, -1); 344 345 RTFOFF off; 346 int rc = pThis->pOps->pfnTell(pThis->pvThis, &off); 347 if (RT_FAILURE(rc)) 348 off = rc; 349 return off; 350 } 351 352 353 186 354 RTDECL(int) RTVfsNewFile(PCRTVFSFILEOPS pFileOps, size_t cbInstance, uint32_t fOpen, RTVFS hVfs, 187 355 PRTVFSFILE phVfsFile, void **ppvInstance)
Note:
See TracChangeset
for help on using the changeset viewer.