Changeset 48849 in vbox
- Timestamp:
- Oct 3, 2013 7:52:53 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/vd-ifs.h
r47349 r48849 621 621 */ 622 622 VBOXDDU_DECL(int) VDIfCreateVfsStream(PVDINTERFACEIO pVDIfsIo, void *pvStorage, uint32_t fFlags, PRTVFSIOSTREAM phVfsIos); 623 624 /** 625 * Create a VFS file handle around a VD I/O interface. 626 * 627 * The I/O interface will not be closed or free by the VFS file, the caller will 628 * do so after it is done with the VFS file and has released the instances of 629 * the VFS object returned by this API. 630 * 631 * @return VBox status code. 632 * @param pVDIfsIo Pointer to the VD I/O interface. 633 * @param pvStorage The storage argument to pass to the interface 634 * methods. 635 * @param fFlags RTFILE_O_XXX, access mask requied. 636 * @param phVfsFile Where to return the VFS file handle on success. 637 */ 638 VBOXDDU_DECL(int) VDIfCreateVfsFile(PVDINTERFACEIO pVDIfsIo, void *pvStorage, uint32_t fFlags, PRTVFSFILE phVfsFile); 623 639 624 640 -
trunk/src/VBox/Storage/VDIfVfs.cpp
r48176 r48849 37 37 38 38 /** 39 * The internal data of a DVM volume I/O stream.40 */ 41 typedef struct VDIFVFSIOS 39 * The internal data of an VD I/O to VFS file or I/O stream wrapper. 40 */ 41 typedef struct VDIFVFSIOSFILE 42 42 { 43 43 /** The VD I/O interface we wrap. */ … … 45 45 /** User pointer to pass to the VD I/O interface methods. */ 46 46 void *pvStorage; 47 /** The current stream position relative to the VDIfCreateVfsStream call. */48 uint64_toffCurPos;49 } VDIFVFSIOS ;47 /** The current stream position. */ 48 RTFOFF offCurPos; 49 } VDIFVFSIOSFILE; 50 50 /** Pointer to a the internal data of a DVM volume file. */ 51 typedef VDIFVFSIOS *PVDIFVFSIOS;51 typedef VDIFVFSIOSFILE *PVDIFVFSIOSFILE; 52 52 53 53 … … 80 80 static DECLCALLBACK(int) vdIfVfsIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 81 81 { 82 PVDIFVFSIOS pThis = (PVDIFVFSIOS)pvThis;82 PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis; 83 83 Assert(pSgBuf->cSegs == 1); NOREF(fBlocking); 84 Assert(off >= -1); 84 85 85 86 /* … … 91 92 if (RT_SUCCESS(rc)) 92 93 { 93 size_t cbAdvance = (pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg);94 size_t cbAdvance = pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg; 94 95 pThis->offCurPos = off + cbAdvance; 95 96 if (pcbRead && !cbAdvance) … … 105 106 static DECLCALLBACK(int) vdIfVfsIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 106 107 { 107 PVDIFVFSIOS pThis = (PVDIFVFSIOS)pvThis;108 PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis; 108 109 Assert(pSgBuf->cSegs == 1); NOREF(fBlocking); 110 Assert(off >= -1); 109 111 110 112 /* … … 125 127 static DECLCALLBACK(int) vdIfVfsIos_Flush(void *pvThis) 126 128 { 127 PVDIFVFSIOS pThis = (PVDIFVFSIOS)pvThis;129 PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis; 128 130 return vdIfIoFileFlushSync(pThis->pVDIfsIo, pThis->pvStorage); 129 131 } … … 134 136 */ 135 137 static DECLCALLBACK(int) vdIfVfsIos_PollOne(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr, 136 138 uint32_t *pfRetEvents) 137 139 { 138 140 NOREF(pvThis); … … 154 156 static DECLCALLBACK(int) vdIfVfsIos_Tell(void *pvThis, PRTFOFF poffActual) 155 157 { 156 PVDIFVFSIOS pThis = (PVDIFVFSIOS)pvThis;158 PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis; 157 159 *poffActual = pThis->offCurPos; 158 160 return VINF_SUCCESS; 159 161 } 160 162 161 /** 162 * Standard file operations. 163 */ 164 DECL_HIDDEN_CONST(const RTVFSIOSTREAMOPS) g_vdIfVfsStdIosOps = 163 164 /** 165 * VFS I/O stream operations for a VD file or stream. 166 */ 167 DECL_HIDDEN_CONST(const RTVFSIOSTREAMOPS) g_vdIfVfsIosOps = 165 168 { 166 169 { /* Obj */ … … 194 197 */ 195 198 RTVFSIOSTREAM hVfsIos; 196 PVDIFVFSIOS pThis;197 int rc = RTVfsNewIoStream(&g_vdIfVfs StdIosOps, sizeof(*pThis), fFlags,199 PVDIFVFSIOSFILE pThis; 200 int rc = RTVfsNewIoStream(&g_vdIfVfsIosOps, sizeof(*pThis), fFlags, 198 201 NIL_RTVFS, NIL_RTVFSLOCK, &hVfsIos, (void **)&pThis); 199 202 if (RT_SUCCESS(rc)) … … 210 213 } 211 214 215 216 217 /** 218 * @interface_method_impl{RTVFSOBJSETOPS,pfnMode} 219 */ 220 static DECLCALLBACK(int) vdIfVfsFile_SetMode(void *pvThis, RTFMODE fMode, RTFMODE fMask) 221 { 222 NOREF(pvThis); 223 NOREF(fMode); 224 NOREF(fMask); 225 return VERR_NOT_SUPPORTED; 226 } 227 228 229 /** 230 * @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes} 231 */ 232 static DECLCALLBACK(int) vdIfVfsFile_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime, 233 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime) 234 { 235 NOREF(pvThis); 236 NOREF(pAccessTime); 237 NOREF(pModificationTime); 238 NOREF(pChangeTime); 239 NOREF(pBirthTime); 240 return VERR_NOT_SUPPORTED; 241 } 242 243 244 /** 245 * @interface_method_impl{RTVFSOBJSETOPS,pfnSetOwner} 246 */ 247 static DECLCALLBACK(int) vdIfVfsFile_SetOwner(void *pvThis, RTUID uid, RTGID gid) 248 { 249 NOREF(pvThis); 250 NOREF(uid); 251 NOREF(gid); 252 return VERR_NOT_SUPPORTED; 253 } 254 255 256 /** 257 * @interface_method_impl{RTVFSFILEOPS,pfnSeek} 258 */ 259 static DECLCALLBACK(int) vdIfVfsFile_Seek(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual) 260 { 261 PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis; 262 263 uint64_t cbFile; 264 int rc = vdIfIoFileGetSize(pThis->pVDIfsIo, pThis->pvStorage, &cbFile); 265 if (RT_FAILURE(rc)) 266 return rc; 267 if (cbFile >= (uint64_t)RTFOFF_MAX) 268 cbFile = RTFOFF_MAX; 269 270 /* Recalculate the request to RTFILE_SEEK_BEGIN. */ 271 switch (uMethod) 272 { 273 case RTFILE_SEEK_BEGIN: 274 break; 275 case RTFILE_SEEK_CURRENT: 276 offSeek += pThis->offCurPos; 277 break; 278 case RTFILE_SEEK_END: 279 offSeek = cbFile + offSeek; 280 break; 281 default: 282 AssertFailedReturn(VERR_INVALID_PARAMETER); 283 } 284 285 /* Do limit checks. */ 286 if (offSeek < 0) 287 offSeek = 0; 288 else if (offSeek > (RTFOFF)cbFile) 289 offSeek = cbFile; 290 291 /* Apply and return. */ 292 pThis->offCurPos = offSeek; 293 if (poffActual) 294 *poffActual = offSeek; 295 296 return VINF_SUCCESS; 297 } 298 299 300 /** 301 * @interface_method_impl{RTVFSFILEOPS,pfnQuerySize} 302 */ 303 static DECLCALLBACK(int) vdIfVfsFile_QuerySize(void *pvThis, uint64_t *pcbFile) 304 { 305 PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis; 306 return vdIfIoFileGetSize(pThis->pVDIfsIo, pThis->pvStorage, pcbFile); 307 } 308 309 310 311 /** 312 * VFS file operations for a VD file. 313 */ 314 DECL_HIDDEN_CONST(const RTVFSFILEOPS) g_vdIfVfsFileOps = 315 { 316 { /* I/O stream */ 317 { /* Obj */ 318 RTVFSOBJOPS_VERSION, 319 RTVFSOBJTYPE_FILE, 320 "VDIfFile", 321 vdIfVfsIos_Close, 322 vdIfVfsIos_QueryInfo, 323 RTVFSOBJOPS_VERSION 324 }, 325 RTVFSIOSTREAMOPS_VERSION, 326 RTVFSIOSTREAMOPS_FEAT_NO_SG, 327 vdIfVfsIos_Read, 328 vdIfVfsIos_Write, 329 vdIfVfsIos_Flush, 330 vdIfVfsIos_PollOne, 331 vdIfVfsIos_Tell, 332 NULL /*Skip*/, 333 NULL /*ZeroFill*/, 334 RTVFSIOSTREAMOPS_VERSION, 335 }, 336 RTVFSFILEOPS_VERSION, 337 0, 338 { /* ObjSet */ 339 RTVFSOBJSETOPS_VERSION, 340 RT_OFFSETOF(RTVFSFILEOPS, Stream.Obj) - RT_OFFSETOF(RTVFSFILEOPS, ObjSet), 341 vdIfVfsFile_SetMode, 342 vdIfVfsFile_SetTimes, 343 vdIfVfsFile_SetOwner, 344 RTVFSOBJSETOPS_VERSION 345 }, 346 vdIfVfsFile_Seek, 347 vdIfVfsFile_QuerySize, 348 RTVFSFILEOPS_VERSION, 349 }; 350 351 352 VBOXDDU_DECL(int) VDIfCreateVfsFile(PVDINTERFACEIO pVDIfsIo, void *pvStorage, uint32_t fFlags, PRTVFSFILE phVfsFile) 353 { 354 AssertPtrReturn(pVDIfsIo, VERR_INVALID_HANDLE); 355 AssertPtrReturn(phVfsFile, VERR_INVALID_POINTER); 356 357 /* 358 * Create the volume file. 359 */ 360 RTVFSFILE hVfsFile; 361 PVDIFVFSIOSFILE pThis; 362 int rc = RTVfsNewFile(&g_vdIfVfsFileOps, sizeof(*pThis), fFlags, 363 NIL_RTVFS, NIL_RTVFSLOCK, &hVfsFile, (void **)&pThis); 364 if (RT_SUCCESS(rc)) 365 { 366 pThis->pVDIfsIo = pVDIfsIo; 367 pThis->pvStorage = pvStorage; 368 pThis->offCurPos = 0; 369 370 *phVfsFile = hVfsFile; 371 return VINF_SUCCESS; 372 } 373 374 return rc; 375 } 376 377
Note:
See TracChangeset
for help on using the changeset viewer.