VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/dvm/dvmvfs.cpp@ 69818

Last change on this file since 69818 was 69818, checked in by vboxsync, 7 years ago

IPRT/VFS: Got rid of the pfnTraversalOpen method.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 35.9 KB
Line 
1/* $Id: dvmvfs.cpp 69818 2017-11-23 19:44:07Z vboxsync $ */
2/** @file
3 * IPRT Disk Volume Management API (DVM) - VFS glue.
4 */
5
6/*
7 * Copyright (C) 2012-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#define LOG_GROUP RTLOGGROUP_FS /** @todo fix log group */
32#include <iprt/types.h>
33#include <iprt/assert.h>
34#include <iprt/mem.h>
35#include <iprt/dvm.h>
36#include <iprt/err.h>
37#include <iprt/asm.h>
38#include <iprt/string.h>
39#include <iprt/file.h>
40#include <iprt/sg.h>
41#include <iprt/vfslowlevel.h>
42#include <iprt/poll.h>
43#include <iprt/log.h>
44#include "internal/dvm.h"
45
46
47/*********************************************************************************************************************************
48* Structures and Typedefs *
49*********************************************************************************************************************************/
50/**
51 * A volume manager VFS for use in chains (thing pseudo/devfs).
52 */
53typedef struct RTDVMVFSVOL
54{
55 /** The volume manager. */
56 RTDVM hVolMgr;
57 /** Whether to close it on success. */
58 bool fCloseDvm;
59 /** Whether the access is read-only. */
60 bool fReadOnly;
61 /** Number of volumes. */
62 uint32_t cVolumes;
63 /** Self reference. */
64 RTVFS hVfsSelf;
65} RTDVMVFSVOL;
66/** Poitner to a volume manager VFS. */
67typedef RTDVMVFSVOL *PRTDVMVFSVOL;
68
69/**
70 * The volume manager VFS (root) dir data.
71 */
72typedef struct RTDVMVFSDIR
73{
74 /** Pointer to the VFS volume. */
75 PRTDVMVFSVOL pVfsVol;
76 /** The current directory offset. */
77 uint32_t offDir;
78 /** Set if we need to try return hCurVolume again because of buffer overflow. */
79 bool fReturnCurrent;
80 /** The current DVM volume. */
81 RTDVMVOLUME hCurVolume;
82} RTDVMVFSDIR;
83/** Poitner to a volume manager VFS (root) dir. */
84typedef RTDVMVFSDIR *PRTDVMVFSDIR;
85
86/**
87 * The internal data of a DVM volume I/O stream.
88 */
89typedef struct RTVFSDVMFILE
90{
91 /** The volume the VFS file belongs to. */
92 RTDVMVOLUME hVol;
93 /** Pointer to the VFS volume. Can be NULL. */
94 PRTDVMVFSVOL pVfsVol;
95 /** Current position. */
96 uint64_t offCurPos;
97 /** Set if readable. */
98 bool fCanRead;
99 /** Set if writable. */
100 bool fCanWrite;
101} RTVFSDVMFILE;
102/** Pointer to a the internal data of a DVM volume file. */
103typedef RTVFSDVMFILE *PRTVFSDVMFILE;
104
105
106/**
107 * @interface_method_impl{RTVFSOBJOPS,pfnClose}
108 */
109static DECLCALLBACK(int) rtDvmVfsFile_Close(void *pvThis)
110{
111 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
112
113 RTDvmVolumeRelease(pThis->hVol);
114 return VINF_SUCCESS;
115}
116
117
118/**
119 * Worker for rtDvmVfsFile_QueryInfo, rtDvmVfsDir_QueryEntryInfo, and
120 * rtDvmVfsDir_ReadDir.
121 */
122static int rtDvmVfsFile_QueryInfoWorker(RTDVMVOLUME hVolume, RTDVM hVolMgr, bool fReadOnly,
123 PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
124{
125
126 pObjInfo->cbObject = RTDvmVolumeGetSize(hVolume);
127 pObjInfo->cbAllocated = pObjInfo->cbObject;
128 RTTimeSpecSetNano(&pObjInfo->AccessTime, 0);
129 RTTimeSpecSetNano(&pObjInfo->ModificationTime, 0);
130 RTTimeSpecSetNano(&pObjInfo->ChangeTime, 0);
131 RTTimeSpecSetNano(&pObjInfo->BirthTime, 0);
132 pObjInfo->Attr.fMode = RTFS_TYPE_FILE | RTFS_DOS_NT_NORMAL;
133 if (fReadOnly)
134 pObjInfo->Attr.fMode |= RTFS_DOS_READONLY | 0444;
135 else
136 pObjInfo->Attr.fMode |= 0666;
137
138 switch (enmAddAttr)
139 {
140 case RTFSOBJATTRADD_NOTHING:
141 case RTFSOBJATTRADD_UNIX:
142 pObjInfo->Attr.u.Unix.uid = (RTUID)RTDvmVolumeGetType(hVolume);
143 pObjInfo->Attr.u.Unix.gid = hVolMgr != NIL_RTDVM ? (RTGID)RTDvmMapGetFormatType(hVolMgr) : NIL_RTGID;
144 pObjInfo->Attr.u.Unix.cHardlinks = 1;
145 pObjInfo->Attr.u.Unix.INodeIdDevice = 0;
146 pObjInfo->Attr.u.Unix.INodeId = 0;
147 pObjInfo->Attr.u.Unix.fFlags = 0;
148 pObjInfo->Attr.u.Unix.GenerationId = 0;
149 pObjInfo->Attr.u.Unix.Device = 0;
150 break;
151
152 case RTFSOBJATTRADD_UNIX_OWNER:
153 {
154 RTDVMVOLTYPE enmType = RTDvmVolumeGetType(hVolume);
155 pObjInfo->Attr.u.UnixOwner.uid = (RTUID)enmType;
156 RTStrCopy(pObjInfo->Attr.u.UnixOwner.szName, sizeof(pObjInfo->Attr.u.UnixOwner.szName),
157 RTDvmVolumeTypeGetDescr(enmType));
158 break;
159 }
160
161 case RTFSOBJATTRADD_UNIX_GROUP:
162 if (hVolMgr != NIL_RTDVM)
163 {
164 pObjInfo->Attr.u.UnixGroup.gid = (RTGID)RTDvmMapGetFormatType(hVolMgr);
165 RTStrCopy(pObjInfo->Attr.u.UnixGroup.szName, sizeof(pObjInfo->Attr.u.UnixGroup.szName),
166 RTDvmMapGetFormatName(hVolMgr));
167 }
168 else
169 {
170 pObjInfo->Attr.u.UnixGroup.gid = NIL_RTGID;
171 pObjInfo->Attr.u.UnixGroup.szName[0] = '\0';
172 }
173 break;
174
175 case RTFSOBJATTRADD_EASIZE:
176 pObjInfo->Attr.u.EASize.cb = 0;
177 break;
178
179 default:
180 return VERR_INVALID_PARAMETER;
181 }
182 return VINF_SUCCESS;
183}
184
185
186/**
187 * @interface_method_impl{RTVFSOBJOPS,pfnQueryInfo}
188 */
189static DECLCALLBACK(int) rtDvmVfsFile_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
190{
191 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
192 return rtDvmVfsFile_QueryInfoWorker(pThis->hVol,
193 pThis->pVfsVol ? pThis->pVfsVol->hVolMgr : NIL_RTDVM,
194 pThis->pVfsVol ? pThis->pVfsVol->fReadOnly : !pThis->fCanWrite,
195 pObjInfo, enmAddAttr);
196}
197
198
199/**
200 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
201 */
202static DECLCALLBACK(int) rtDvmVfsFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
203{
204 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
205 int rc = VINF_SUCCESS;
206
207 Assert(pSgBuf->cSegs == 1);
208 NOREF(fBlocking);
209
210 /*
211 * Find the current position and check if it's within the volume.
212 */
213 uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off;
214 if (offUnsigned >= RTDvmVolumeGetSize(pThis->hVol))
215 {
216 if (pcbRead)
217 {
218 *pcbRead = 0;
219 pThis->offCurPos = offUnsigned;
220 return VINF_EOF;
221 }
222 return VERR_EOF;
223 }
224
225 size_t cbLeftToRead;
226 if (offUnsigned + pSgBuf->paSegs[0].cbSeg > RTDvmVolumeGetSize(pThis->hVol))
227 {
228 if (!pcbRead)
229 return VERR_EOF;
230 *pcbRead = cbLeftToRead = (size_t)(RTDvmVolumeGetSize(pThis->hVol) - offUnsigned);
231 }
232 else
233 {
234 cbLeftToRead = pSgBuf->paSegs[0].cbSeg;
235 if (pcbRead)
236 *pcbRead = cbLeftToRead;
237 }
238
239 /*
240 * Ok, we've got a valid stretch within the file. Do the reading.
241 */
242 if (cbLeftToRead > 0)
243 {
244 rc = RTDvmVolumeRead(pThis->hVol, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbLeftToRead);
245 if (RT_SUCCESS(rc))
246 offUnsigned += cbLeftToRead;
247 }
248
249 pThis->offCurPos = offUnsigned;
250 return rc;
251}
252
253
254/**
255 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
256 */
257static DECLCALLBACK(int) rtDvmVfsFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
258{
259 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
260 int rc = VINF_SUCCESS;
261
262 Assert(pSgBuf->cSegs == 1);
263 NOREF(fBlocking);
264
265 /*
266 * Find the current position and check if it's within the volume.
267 * Writing beyond the end of a volume is not supported.
268 */
269 uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off;
270 if (offUnsigned >= RTDvmVolumeGetSize(pThis->hVol))
271 {
272 if (pcbWritten)
273 {
274 *pcbWritten = 0;
275 pThis->offCurPos = offUnsigned;
276 }
277 return VERR_NOT_SUPPORTED;
278 }
279
280 size_t cbLeftToWrite;
281 if (offUnsigned + pSgBuf->paSegs[0].cbSeg > RTDvmVolumeGetSize(pThis->hVol))
282 {
283 if (!pcbWritten)
284 return VERR_EOF;
285 *pcbWritten = cbLeftToWrite = (size_t)(RTDvmVolumeGetSize(pThis->hVol) - offUnsigned);
286 }
287 else
288 {
289 cbLeftToWrite = pSgBuf->paSegs[0].cbSeg;
290 if (pcbWritten)
291 *pcbWritten = cbLeftToWrite;
292 }
293
294 /*
295 * Ok, we've got a valid stretch within the file. Do the reading.
296 */
297 if (cbLeftToWrite > 0)
298 {
299 rc = RTDvmVolumeWrite(pThis->hVol, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbLeftToWrite);
300 if (RT_SUCCESS(rc))
301 offUnsigned += cbLeftToWrite;
302 }
303
304 pThis->offCurPos = offUnsigned;
305 return rc;
306}
307
308
309/**
310 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnFlush}
311 */
312static DECLCALLBACK(int) rtDvmVfsFile_Flush(void *pvThis)
313{
314 NOREF(pvThis);
315 return VINF_SUCCESS; /** @todo Implement missing DVM API. */
316}
317
318
319/**
320 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnPollOne}
321 */
322static DECLCALLBACK(int) rtDvmVfsFile_PollOne(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
323 uint32_t *pfRetEvents)
324{
325 NOREF(pvThis);
326 int rc;
327 if (fEvents != RTPOLL_EVT_ERROR)
328 {
329 *pfRetEvents = fEvents & ~RTPOLL_EVT_ERROR;
330 rc = VINF_SUCCESS;
331 }
332 else
333 rc = RTVfsUtilDummyPollOne(fEvents, cMillies, fIntr, pfRetEvents);
334 return rc;
335}
336
337
338/**
339 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnTell}
340 */
341static DECLCALLBACK(int) rtDvmVfsFile_Tell(void *pvThis, PRTFOFF poffActual)
342{
343 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
344 *poffActual = pThis->offCurPos;
345 return VINF_SUCCESS;
346}
347
348
349/**
350 * @interface_method_impl{RTVFSOBJSETOPS,pfnMode}
351 */
352static DECLCALLBACK(int) rtDvmVfsFile_SetMode(void *pvThis, RTFMODE fMode, RTFMODE fMask)
353{
354 NOREF(pvThis);
355 NOREF(fMode);
356 NOREF(fMask);
357 return VERR_NOT_SUPPORTED;
358}
359
360
361/**
362 * @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes}
363 */
364static DECLCALLBACK(int) rtDvmVfsFile_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
365 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
366{
367 NOREF(pvThis);
368 NOREF(pAccessTime);
369 NOREF(pModificationTime);
370 NOREF(pChangeTime);
371 NOREF(pBirthTime);
372 return VERR_NOT_SUPPORTED;
373}
374
375
376/**
377 * @interface_method_impl{RTVFSOBJSETOPS,pfnSetOwner}
378 */
379static DECLCALLBACK(int) rtDvmVfsFile_SetOwner(void *pvThis, RTUID uid, RTGID gid)
380{
381 NOREF(pvThis);
382 NOREF(uid);
383 NOREF(gid);
384 return VERR_NOT_SUPPORTED;
385}
386
387
388/**
389 * @interface_method_impl{RTVFSFILEOPS,pfnSeek}
390 */
391static DECLCALLBACK(int) rtDvmVfsFile_Seek(void *pvThis, RTFOFF offSeek, unsigned uMethod, PRTFOFF poffActual)
392{
393 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
394
395 /*
396 * Seek relative to which position.
397 */
398 uint64_t offWrt;
399 switch (uMethod)
400 {
401 case RTFILE_SEEK_BEGIN:
402 offWrt = 0;
403 break;
404
405 case RTFILE_SEEK_CURRENT:
406 offWrt = pThis->offCurPos;
407 break;
408
409 case RTFILE_SEEK_END:
410 offWrt = RTDvmVolumeGetSize(pThis->hVol);
411 break;
412
413 default:
414 return VERR_INTERNAL_ERROR_5;
415 }
416
417 /*
418 * Calc new position, take care to stay within bounds.
419 *
420 * @todo: Setting position beyond the end of the volume does not make sense.
421 */
422 uint64_t offNew;
423 if (offSeek == 0)
424 offNew = offWrt;
425 else if (offSeek > 0)
426 {
427 offNew = offWrt + offSeek;
428 if ( offNew < offWrt
429 || offNew > RTFOFF_MAX)
430 offNew = RTFOFF_MAX;
431 }
432 else if ((uint64_t)-offSeek < offWrt)
433 offNew = offWrt + offSeek;
434 else
435 offNew = 0;
436
437 /*
438 * Update the state and set return value.
439 */
440 pThis->offCurPos = offNew;
441
442 *poffActual = offNew;
443 return VINF_SUCCESS;
444}
445
446
447/**
448 * @interface_method_impl{RTVFSFILEOPS,pfnQuerySize}
449 */
450static DECLCALLBACK(int) rtDvmVfsFile_QuerySize(void *pvThis, uint64_t *pcbFile)
451{
452 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
453 *pcbFile = RTDvmVolumeGetSize(pThis->hVol);
454 return VINF_SUCCESS;
455}
456
457
458/**
459 * Standard file operations.
460 */
461DECL_HIDDEN_CONST(const RTVFSFILEOPS) g_rtDvmVfsStdFileOps =
462{
463 { /* Stream */
464 { /* Obj */
465 RTVFSOBJOPS_VERSION,
466 RTVFSOBJTYPE_FILE,
467 "DvmFile",
468 rtDvmVfsFile_Close,
469 rtDvmVfsFile_QueryInfo,
470 RTVFSOBJOPS_VERSION
471 },
472 RTVFSIOSTREAMOPS_VERSION,
473 RTVFSIOSTREAMOPS_FEAT_NO_SG,
474 rtDvmVfsFile_Read,
475 rtDvmVfsFile_Write,
476 rtDvmVfsFile_Flush,
477 rtDvmVfsFile_PollOne,
478 rtDvmVfsFile_Tell,
479 NULL /*Skip*/,
480 NULL /*ZeroFill*/,
481 RTVFSIOSTREAMOPS_VERSION,
482 },
483 RTVFSFILEOPS_VERSION,
484 /*RTVFSIOFILEOPS_FEAT_NO_AT_OFFSET*/ 0,
485 { /* ObjSet */
486 RTVFSOBJSETOPS_VERSION,
487 RT_OFFSETOF(RTVFSFILEOPS, Stream.Obj) - RT_OFFSETOF(RTVFSFILEOPS, ObjSet),
488 rtDvmVfsFile_SetMode,
489 rtDvmVfsFile_SetTimes,
490 rtDvmVfsFile_SetOwner,
491 RTVFSOBJSETOPS_VERSION
492 },
493 rtDvmVfsFile_Seek,
494 rtDvmVfsFile_QuerySize,
495 RTVFSFILEOPS_VERSION
496};
497
498
499/**
500 * Internal worker for RTDvmVolumeCreateVfsFile and rtDvmVfsDir_OpenFile.
501 *
502 * @returns IPRT status code.
503 * @param pVfsVol The VFS volume, optional.
504 * @param hVol The volume handle. (Reference not consumed.)
505 * @param fOpen RTFILE_O_XXX (valid).
506 * @param phVfsFileOut Where to return the handle to the file.
507 */
508static int rtDvmVfsCreateFileForVolume(PRTDVMVFSVOL pVfsVol, RTDVMVOLUME hVol, uint64_t fOpen, PRTVFSFILE phVfsFileOut)
509{
510 uint32_t cRefs = RTDvmVolumeRetain(hVol);
511 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE);
512
513 /*
514 * Create the volume file.
515 */
516 RTVFSFILE hVfsFile;
517 PRTVFSDVMFILE pThis;
518 int rc = RTVfsNewFile(&g_rtDvmVfsStdFileOps, sizeof(*pThis), fOpen, NIL_RTVFS, NIL_RTVFSLOCK, &hVfsFile, (void **)&pThis);
519 if (RT_SUCCESS(rc))
520 {
521 pThis->offCurPos = 0;
522 pThis->hVol = hVol;
523 pThis->fCanRead = RT_BOOL(fOpen & RTFILE_O_READ);
524 pThis->fCanWrite = RT_BOOL(fOpen & RTFILE_O_WRITE);
525 pThis->pVfsVol = pVfsVol;
526
527 *phVfsFileOut = hVfsFile;
528 return VINF_SUCCESS;
529 }
530
531 RTDvmVolumeRelease(hVol);
532 return rc;
533}
534
535
536RTDECL(int) RTDvmVolumeCreateVfsFile(RTDVMVOLUME hVol, uint64_t fOpen, PRTVFSFILE phVfsFileOut)
537{
538 AssertPtrReturn(hVol, VERR_INVALID_HANDLE);
539 AssertPtrReturn(phVfsFileOut, VERR_INVALID_POINTER);
540 AssertReturn(fOpen & RTFILE_O_ACCESS_MASK, VERR_INVALID_FLAGS);
541 AssertReturn(!(fOpen & ~RTFILE_O_VALID_MASK), VERR_INVALID_FLAGS);
542 return rtDvmVfsCreateFileForVolume(NULL, hVol, fOpen, phVfsFileOut);
543}
544
545
546/**
547 * @interface_method_impl{RTVFSOBJOPS,pfnClose}
548 */
549static DECLCALLBACK(int) rtDvmVfsDir_Close(void *pvThis)
550{
551 PRTDVMVFSDIR pThis = (PRTDVMVFSDIR)pvThis;
552
553 if (pThis->hCurVolume != NIL_RTDVMVOLUME)
554 {
555 RTDvmVolumeRelease(pThis->hCurVolume);
556 pThis->hCurVolume = NIL_RTDVMVOLUME;
557 }
558
559 pThis->pVfsVol = NULL;
560
561 return VINF_SUCCESS;
562}
563
564
565/**
566 * @interface_method_impl{RTVFSOBJOPS,pfnQueryInfo}
567 */
568static DECLCALLBACK(int) rtDvmVfsDir_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
569{
570 PRTDVMVFSDIR pThis = (PRTDVMVFSDIR)pvThis;
571 pObjInfo->cbObject = pThis->pVfsVol->cVolumes;
572 pObjInfo->cbAllocated = pThis->pVfsVol->cVolumes;
573 RTTimeSpecSetNano(&pObjInfo->AccessTime, 0);
574 RTTimeSpecSetNano(&pObjInfo->ModificationTime, 0);
575 RTTimeSpecSetNano(&pObjInfo->ChangeTime, 0);
576 RTTimeSpecSetNano(&pObjInfo->BirthTime, 0);
577 pObjInfo->Attr.fMode = RTFS_TYPE_DIRECTORY | RTFS_DOS_DIRECTORY;
578 if (pThis->pVfsVol->fReadOnly)
579 pObjInfo->Attr.fMode |= RTFS_DOS_READONLY | 0555;
580 else
581 pObjInfo->Attr.fMode |= 0777;
582
583 switch (enmAddAttr)
584 {
585 case RTFSOBJATTRADD_NOTHING:
586 case RTFSOBJATTRADD_UNIX:
587 pObjInfo->Attr.u.Unix.uid = NIL_RTUID;
588 pObjInfo->Attr.u.Unix.gid = (RTGID)RTDvmMapGetFormatType(pThis->pVfsVol->hVolMgr);
589 pObjInfo->Attr.u.Unix.cHardlinks = pThis->pVfsVol->cVolumes;
590 pObjInfo->Attr.u.Unix.INodeIdDevice = 0;
591 pObjInfo->Attr.u.Unix.INodeId = 0;
592 pObjInfo->Attr.u.Unix.fFlags = 0;
593 pObjInfo->Attr.u.Unix.GenerationId = 0;
594 pObjInfo->Attr.u.Unix.Device = 0;
595 break;
596
597 case RTFSOBJATTRADD_UNIX_OWNER:
598 pObjInfo->Attr.u.UnixOwner.uid = NIL_RTUID;
599 pObjInfo->Attr.u.UnixOwner.szName[0] = '\0';
600 break;
601
602 case RTFSOBJATTRADD_UNIX_GROUP:
603 pObjInfo->Attr.u.UnixGroup.gid = (RTGID)RTDvmMapGetFormatType(pThis->pVfsVol->hVolMgr);
604 RTStrCopy(pObjInfo->Attr.u.UnixGroup.szName, sizeof(pObjInfo->Attr.u.UnixGroup.szName),
605 RTDvmMapGetFormatName(pThis->pVfsVol->hVolMgr));
606 break;
607
608 case RTFSOBJATTRADD_EASIZE:
609 pObjInfo->Attr.u.EASize.cb = 0;
610 break;
611
612 default:
613 return VERR_INVALID_PARAMETER;
614 }
615 return VINF_SUCCESS;
616}
617
618
619/**
620 * @interface_method_impl{RTVFSOBJSETOPS,pfnMode}
621 */
622static DECLCALLBACK(int) rtDvmVfsDir_SetMode(void *pvThis, RTFMODE fMode, RTFMODE fMask)
623{
624 NOREF(pvThis); NOREF(fMode); NOREF(fMask);
625 return VERR_NOT_SUPPORTED;
626}
627
628
629/**
630 * @interface_method_impl{RTVFSOBJSETOPS,pfnSetTimes}
631 */
632static DECLCALLBACK(int) rtDvmVfsDir_SetTimes(void *pvThis, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
633 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
634{
635 NOREF(pvThis); NOREF(pAccessTime); NOREF(pModificationTime); NOREF(pChangeTime); NOREF(pBirthTime);
636 return VERR_NOT_SUPPORTED;
637}
638
639
640/**
641 * @interface_method_impl{RTVFSOBJSETOPS,pfnSetOwner}
642 */
643static DECLCALLBACK(int) rtDvmVfsDir_SetOwner(void *pvThis, RTUID uid, RTGID gid)
644{
645 RT_NOREF(pvThis, uid, gid);
646 return VERR_NOT_SUPPORTED;
647}
648
649
650static int rtDvmVfsDir_FindEntry(PRTDVMVFSDIR pThis, const char *pszEntry, PRTDVMVOLUME phVolume)
651{
652 /*
653 * Enumerate the volumes and try match the volume name.
654 */
655 int rc;
656 PRTDVMVFSVOL pVfsVol = pThis->pVfsVol;
657 if (pVfsVol->cVolumes > 0)
658 {
659 /* The first volume. */
660 uint32_t iVol = 0;
661 RTDVMVOLUME hVol;
662 rc = RTDvmMapQueryFirstVolume(pThis->pVfsVol->hVolMgr, &hVol);
663 while (RT_SUCCESS(rc))
664 {
665 /* Match the name. */
666 bool fMatch;
667 char *pszVolName;
668 rc = RTDvmVolumeQueryName(hVol, &pszVolName);
669 if (RT_SUCCESS(rc))
670 {
671 fMatch = RTStrCmp(pszEntry, pszVolName) == 0 && *pszVolName != '\0';
672 RTStrFree(pszVolName);
673 }
674 else if (rc == VERR_NOT_SUPPORTED)
675 fMatch = false;
676 else
677 {
678 RTDvmVolumeRelease(hVol);
679 break;
680 }
681
682 /* Match the sequential volume number. */
683 if (!fMatch)
684 {
685 char szTmp[16];
686 RTStrPrintf(szTmp, sizeof(szTmp), "vol%u", iVol);
687 fMatch = RTStrCmp(pszEntry, szTmp) == 0;
688 }
689
690 if (fMatch)
691 {
692 *phVolume = hVol;
693 return VINF_SUCCESS;
694 }
695
696 /* More volumes? */
697 iVol++;
698 if (iVol >= pVfsVol->cVolumes)
699 {
700 RTDvmVolumeRelease(hVol);
701 rc = VERR_FILE_NOT_FOUND;
702 break;
703 }
704
705 /* Get the next volume. */
706 RTDVMVOLUME hVolNext;
707 rc = RTDvmMapQueryNextVolume(pThis->pVfsVol->hVolMgr, hVol, &hVolNext);
708 RTDvmVolumeRelease(hVol);
709 hVol = hVolNext;
710 }
711 }
712 else
713 rc = VERR_FILE_NOT_FOUND;
714 return rc;
715}
716
717
718/**
719 * @interface_method_impl{RTVFSDIROPS,pfnOpen}
720 */
721static DECLCALLBACK(int) rtDvmVfsDir_Open(void *pvThis, const char *pszEntry, uint64_t fOpen, uint32_t fFlags, PRTVFSOBJ phVfsObj)
722{
723 PRTDVMVFSDIR pThis = (PRTDVMVFSDIR)pvThis;
724 RTDVMVOLUME hVolume;
725 int rc = rtDvmVfsDir_FindEntry(pThis, pszEntry, &hVolume);
726 if (RT_SUCCESS(rc))
727 {
728 if ( (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN
729 || (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_OPEN_CREATE
730 || (fOpen & RTFILE_O_ACTION_MASK) == RTFILE_O_CREATE_REPLACE)
731 {
732 if (fFlags & (RTVFSOBJ_F_OPEN_FILE | RTVFSOBJ_F_OPEN_DEV_BLOCK))
733 {
734 if ( !(fOpen & RTFILE_O_WRITE)
735 || !pThis->pVfsVol->fReadOnly)
736 {
737 RTVFSFILE hVfsFile;
738 rc = rtDvmVfsCreateFileForVolume(pThis->pVfsVol, hVolume, fOpen, &hVfsFile);
739 if (RT_SUCCESS(rc))
740 {
741 *phVfsObj = RTVfsObjFromFile(hVfsFile);
742 RTVfsFileRelease(hVfsFile);
743 AssertStmt(*phVfsObj != NIL_RTVFSOBJ, rc = VERR_INTERNAL_ERROR_3);
744 }
745 }
746 else
747 rc = VERR_WRITE_PROTECT;
748 }
749 else
750 rc = VERR_IS_A_FILE;
751 }
752 else
753 rc = VERR_ALREADY_EXISTS;
754 RTDvmVolumeRelease(hVolume);
755 }
756 return rc;
757}
758
759
760/**
761 * @interface_method_impl{RTVFSDIROPS,pfnOpenFile}
762 */
763static DECLCALLBACK(int) rtDvmVfsDir_OpenFile(void *pvThis, const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile)
764{
765 RTVFSOBJ hVfsObj;
766 int rc = rtDvmVfsDir_Open(pvThis, pszFilename, fOpen, RTVFSOBJ_F_OPEN_FILE, &hVfsObj);
767 if (RT_SUCCESS(rc))
768 {
769 *phVfsFile = RTVfsObjToFile(hVfsObj);
770 RTVfsObjRelease(hVfsObj);
771 }
772 return rc;
773}
774
775
776/**
777 * @interface_method_impl{RTVFSDIROPS,pfnOpenDir}
778 */
779static DECLCALLBACK(int) rtDvmVfsDir_OpenDir(void *pvThis, const char *pszSubDir, uint32_t fFlags, PRTVFSDIR phVfsDir)
780{
781 NOREF(pvThis); NOREF(pszSubDir); NOREF(fFlags); NOREF(phVfsDir);
782 return VERR_FILE_NOT_FOUND;
783}
784
785
786/**
787 * @interface_method_impl{RTVFSDIROPS,pfnCreateDir}
788 */
789static DECLCALLBACK(int) rtDvmVfsDir_CreateDir(void *pvThis, const char *pszSubDir, RTFMODE fMode, PRTVFSDIR phVfsDir)
790{
791 RT_NOREF(pvThis, pszSubDir, fMode, phVfsDir);
792 return VERR_NOT_SUPPORTED;
793}
794
795
796/**
797 * @interface_method_impl{RTVFSDIROPS,pfnOpenSymlink}
798 */
799static DECLCALLBACK(int) rtDvmVfsDir_OpenSymlink(void *pvThis, const char *pszSymlink, PRTVFSSYMLINK phVfsSymlink)
800{
801 RT_NOREF(pvThis, pszSymlink, phVfsSymlink);
802 return VERR_NOT_SUPPORTED;
803}
804
805
806/**
807 * @interface_method_impl{RTVFSDIROPS,pfnCreateSymlink}
808 */
809static DECLCALLBACK(int) rtDvmVfsDir_CreateSymlink(void *pvThis, const char *pszSymlink, const char *pszTarget,
810 RTSYMLINKTYPE enmType, PRTVFSSYMLINK phVfsSymlink)
811{
812 RT_NOREF(pvThis, pszSymlink, pszTarget, enmType, phVfsSymlink);
813 return VERR_NOT_SUPPORTED;
814}
815
816
817/**
818 * @interface_method_impl{RTVFSDIROPS,pfnQueryEntryInfo}
819 */
820static DECLCALLBACK(int) rtDvmVfsDir_QueryEntryInfo(void *pvThis, const char *pszEntry,
821 PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
822{
823 PRTDVMVFSDIR pThis = (PRTDVMVFSDIR)pvThis;
824 RTDVMVOLUME hVolume;
825 int rc = rtDvmVfsDir_FindEntry(pThis, pszEntry, &hVolume);
826 if (RT_SUCCESS(rc))
827 {
828 rc = rtDvmVfsFile_QueryInfoWorker(hVolume, pThis->pVfsVol->hVolMgr, pThis->pVfsVol->fReadOnly, pObjInfo, enmAddAttr);
829 RTDvmVolumeRelease(hVolume);
830 }
831 return rc;
832}
833
834
835/**
836 * @interface_method_impl{RTVFSDIROPS,pfnUnlinkEntry}
837 */
838static DECLCALLBACK(int) rtDvmVfsDir_UnlinkEntry(void *pvThis, const char *pszEntry, RTFMODE fType)
839{
840 RT_NOREF(pvThis, pszEntry, fType);
841 return VERR_NOT_IMPLEMENTED;
842}
843
844
845/**
846 * @interface_method_impl{RTVFSDIROPS,pfnRenameEntry}
847 */
848static DECLCALLBACK(int) rtDvmVfsDir_RenameEntry(void *pvThis, const char *pszEntry, RTFMODE fType, const char *pszNewName)
849{
850 RT_NOREF(pvThis, pszEntry, fType, pszNewName);
851 return VERR_NOT_IMPLEMENTED;
852}
853
854
855/**
856 * @interface_method_impl{RTVFSDIROPS,pfnRewindDir}
857 */
858static DECLCALLBACK(int) rtDvmVfsDir_RewindDir(void *pvThis)
859{
860 PRTDVMVFSDIR pThis = (PRTDVMVFSDIR)pvThis;
861
862 if (pThis->hCurVolume != NIL_RTDVMVOLUME)
863 {
864 RTDvmVolumeRelease(pThis->hCurVolume);
865 pThis->hCurVolume = NIL_RTDVMVOLUME;
866 }
867 pThis->fReturnCurrent = false;
868 pThis->offDir = 0;
869
870 return VINF_SUCCESS;
871}
872
873
874/**
875 * @interface_method_impl{RTVFSDIROPS,pfnReadDir}
876 */
877static DECLCALLBACK(int) rtDvmVfsDir_ReadDir(void *pvThis, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry,
878 RTFSOBJATTRADD enmAddAttr)
879{
880 PRTDVMVFSDIR pThis = (PRTDVMVFSDIR)pvThis;
881 PRTDVMVFSVOL pVfsVol = pThis->pVfsVol;
882 int rc;
883
884 /*
885 * Get the volume to return info about.
886 */
887 if (!pThis->fReturnCurrent)
888 {
889 if (pThis->offDir < pVfsVol->cVolumes)
890 {
891 RTDVMVOLUME hNextVolume;
892 if (pThis->offDir == 0)
893 rc = RTDvmMapQueryFirstVolume(pVfsVol->hVolMgr, &hNextVolume);
894 else
895 rc = RTDvmMapQueryNextVolume(pVfsVol->hVolMgr, pThis->hCurVolume, &hNextVolume);
896 if (RT_FAILURE(rc))
897 return rc;
898 RTDvmVolumeRelease(pThis->hCurVolume);
899 pThis->hCurVolume = hNextVolume;
900 }
901 else
902 {
903 RTDvmVolumeRelease(pThis->hCurVolume);
904 pThis->hCurVolume = NIL_RTDVMVOLUME;
905 return VERR_NO_MORE_FILES;
906 }
907 }
908
909 /*
910 * Figure out the name length.
911 */
912 char szVolNo[16];
913 RTStrPrintf(szVolNo, sizeof(szVolNo), "vol%u", pThis->offDir);
914
915 char *pszVolName;
916 rc = RTDvmVolumeQueryName(pThis->hCurVolume, &pszVolName);
917 if ( RT_SUCCESS(rc)
918 || rc == VERR_NOT_SUPPORTED)
919 {
920 if (rc == VERR_NOT_SUPPORTED)
921 pszVolName = szVolNo;
922 else if (*pszVolName == '\0')
923 {
924 RTStrFree(pszVolName);
925 pszVolName = szVolNo;
926 }
927
928 size_t cchVolName = strlen(pszVolName);
929 size_t cbNeeded = RT_OFFSETOF(RTDIRENTRYEX, szName[cchVolName + 1]);
930 if (cbNeeded <= *pcbDirEntry)
931 {
932 *pcbDirEntry = cbNeeded;
933
934 /* Do the names. */
935 pDirEntry->cbName = (uint16_t)cchVolName;
936 memcpy(pDirEntry->szName, pszVolName, cchVolName + 1);
937 if (pszVolName != szVolNo)
938 {
939 RTStrFree(pszVolName);
940
941 PRTUTF16 pwszShortName = pDirEntry->wszShortName;
942 size_t cwcShortName = 0;
943 rc = RTStrToUtf16Ex(szVolNo, RTSTR_MAX, &pwszShortName, RT_ELEMENTS(pDirEntry->wszShortName), &cwcShortName);
944 AssertRC(rc);
945 pDirEntry->cwcShortName = (uint16_t)cwcShortName;
946 }
947 else
948 {
949 pDirEntry->cwcShortName = 0;
950 pDirEntry->wszShortName[0] = '\0';
951 }
952
953 /* Do the rest. */
954 rc = rtDvmVfsFile_QueryInfoWorker(pThis->hCurVolume, pVfsVol->hVolMgr, pVfsVol->fReadOnly,
955 &pDirEntry->Info, enmAddAttr);
956 pThis->fReturnCurrent = !RT_SUCCESS(rc);
957 pThis->offDir += RT_SUCCESS(rc);
958 return rc;
959 }
960
961 *pcbDirEntry = cbNeeded;
962 rc = VERR_BUFFER_OVERFLOW;
963
964 if (pszVolName != szVolNo)
965 RTStrFree(pszVolName);
966 }
967
968 pThis->fReturnCurrent = true;
969 return rc;
970}
971
972
973/**
974 * DVM (root) directory operations.
975 */
976static const RTVFSDIROPS g_rtDvmVfsDirOps =
977{
978 { /* Obj */
979 RTVFSOBJOPS_VERSION,
980 RTVFSOBJTYPE_DIR,
981 "DvmDir",
982 rtDvmVfsDir_Close,
983 rtDvmVfsDir_QueryInfo,
984 RTVFSOBJOPS_VERSION
985 },
986 RTVFSDIROPS_VERSION,
987 0,
988 { /* ObjSet */
989 RTVFSOBJSETOPS_VERSION,
990 RT_OFFSETOF(RTVFSDIROPS, Obj) - RT_OFFSETOF(RTVFSDIROPS, ObjSet),
991 rtDvmVfsDir_SetMode,
992 rtDvmVfsDir_SetTimes,
993 rtDvmVfsDir_SetOwner,
994 RTVFSOBJSETOPS_VERSION
995 },
996 rtDvmVfsDir_Open,
997 rtDvmVfsDir_OpenFile,
998 rtDvmVfsDir_OpenDir,
999 rtDvmVfsDir_CreateDir,
1000 rtDvmVfsDir_OpenSymlink,
1001 rtDvmVfsDir_CreateSymlink,
1002 rtDvmVfsDir_QueryEntryInfo,
1003 rtDvmVfsDir_UnlinkEntry,
1004 rtDvmVfsDir_RenameEntry,
1005 rtDvmVfsDir_RewindDir,
1006 rtDvmVfsDir_ReadDir,
1007 RTVFSDIROPS_VERSION,
1008};
1009
1010
1011
1012/**
1013 * @interface_method_impl{RTVFSOBJOPS::Obj,pfnClose}
1014 */
1015static DECLCALLBACK(int) rtDvmVfsVol_Close(void *pvThis)
1016{
1017 PRTDVMVFSVOL pThis = (PRTDVMVFSVOL)pvThis;
1018 LogFlow(("rtDvmVfsVol_Close(%p)\n", pThis));
1019
1020 if ( pThis->fCloseDvm
1021 && pThis->hVolMgr != NIL_RTDVM )
1022 RTDvmRelease(pThis->hVolMgr);
1023 pThis->hVolMgr = NIL_RTDVM;
1024
1025 return VINF_SUCCESS;
1026}
1027
1028
1029/**
1030 * @interface_method_impl{RTVFSOBJOPS::Obj,pfnQueryInfo}
1031 */
1032static DECLCALLBACK(int) rtDvmVfsVol_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
1033{
1034 RT_NOREF(pvThis, pObjInfo, enmAddAttr);
1035 return VERR_WRONG_TYPE;
1036}
1037
1038
1039/**
1040 * @interface_method_impl{RTVFSOPS,pfnOpenRoot}
1041 */
1042static DECLCALLBACK(int) rtDvmVfsVol_OpenRoot(void *pvThis, PRTVFSDIR phVfsDir)
1043{
1044 PRTDVMVFSVOL pThis = (PRTDVMVFSVOL)pvThis;
1045
1046 PRTDVMVFSDIR pNewDir;
1047 int rc = RTVfsNewDir(&g_rtDvmVfsDirOps, sizeof(*pNewDir), 0 /*fFlags*/, pThis->hVfsSelf,
1048 NIL_RTVFSLOCK /*use volume lock*/, phVfsDir, (void **)&pNewDir);
1049 if (RT_SUCCESS(rc))
1050 {
1051 pNewDir->offDir = 0;
1052 pNewDir->pVfsVol = pThis;
1053 pNewDir->fReturnCurrent = false;
1054 pNewDir->hCurVolume = NIL_RTDVMVOLUME;
1055 }
1056 return rc;
1057}
1058
1059
1060/**
1061 * @interface_method_impl{RTVFSOPS,pfnIsRangeInUse}
1062 */
1063static DECLCALLBACK(int) rtDvmVfsVol_IsRangeInUse(void *pvThis, RTFOFF off, size_t cb, bool *pfUsed)
1064{
1065 RT_NOREF(pvThis, off, cb, pfUsed);
1066 return VERR_NOT_IMPLEMENTED;
1067}
1068
1069
1070DECL_HIDDEN_CONST(const RTVFSOPS) g_rtDvmVfsVolOps =
1071{
1072 { /* Obj */
1073 RTVFSOBJOPS_VERSION,
1074 RTVFSOBJTYPE_VFS,
1075 "DvmVol",
1076 rtDvmVfsVol_Close,
1077 rtDvmVfsVol_QueryInfo,
1078 RTVFSOBJOPS_VERSION
1079 },
1080 RTVFSOPS_VERSION,
1081 0 /* fFeatures */,
1082 rtDvmVfsVol_OpenRoot,
1083 rtDvmVfsVol_IsRangeInUse,
1084 RTVFSOPS_VERSION
1085};
1086
1087
1088
1089/**
1090 * @interface_method_impl{RTVFSCHAINELEMENTREG,pfnValidate}
1091 */
1092static DECLCALLBACK(int) rtDvmVfsChain_Validate(PCRTVFSCHAINELEMENTREG pProviderReg, PRTVFSCHAINSPEC pSpec,
1093 PRTVFSCHAINELEMSPEC pElement, uint32_t *poffError, PRTERRINFO pErrInfo)
1094{
1095 RT_NOREF(pProviderReg, pSpec);
1096
1097 /*
1098 * Basic checks.
1099 */
1100 if (pElement->enmTypeIn != RTVFSOBJTYPE_FILE)
1101 return pElement->enmTypeIn == RTVFSOBJTYPE_INVALID ? VERR_VFS_CHAIN_CANNOT_BE_FIRST_ELEMENT : VERR_VFS_CHAIN_TAKES_FILE;
1102 if (pElement->enmType != RTVFSOBJTYPE_VFS)
1103 return VERR_VFS_CHAIN_ONLY_VFS;
1104
1105 if (pElement->cArgs > 1)
1106 return VERR_VFS_CHAIN_AT_MOST_ONE_ARG;
1107
1108 /*
1109 * Parse the flag if present, save in pElement->uProvider.
1110 */
1111 /** @todo allow specifying sector size */
1112 bool fReadOnly = (pSpec->fOpenFile & RTFILE_O_ACCESS_MASK) == RTFILE_O_READ;
1113 if (pElement->cArgs > 0)
1114 {
1115 const char *psz = pElement->paArgs[0].psz;
1116 if (*psz)
1117 {
1118 if ( !strcmp(psz, "ro")
1119 || !strcmp(psz, "r"))
1120 fReadOnly = true;
1121 else if (!strcmp(psz, "rw"))
1122 fReadOnly = false;
1123 else
1124 {
1125 *poffError = pElement->paArgs[0].offSpec;
1126 return RTErrInfoSet(pErrInfo, VERR_VFS_CHAIN_INVALID_ARGUMENT, "Expected 'ro' or 'rw' as argument");
1127 }
1128 }
1129 }
1130
1131 pElement->uProvider = fReadOnly;
1132 return VINF_SUCCESS;
1133}
1134
1135
1136/**
1137 * @interface_method_impl{RTVFSCHAINELEMENTREG,pfnInstantiate}
1138 */
1139static DECLCALLBACK(int) rtDvmVfsChain_Instantiate(PCRTVFSCHAINELEMENTREG pProviderReg, PCRTVFSCHAINSPEC pSpec,
1140 PCRTVFSCHAINELEMSPEC pElement, RTVFSOBJ hPrevVfsObj,
1141 PRTVFSOBJ phVfsObj, uint32_t *poffError, PRTERRINFO pErrInfo)
1142{
1143 RT_NOREF(pProviderReg, pSpec, poffError, pErrInfo);
1144 AssertReturn(hPrevVfsObj != NIL_RTVFSOBJ, VERR_VFS_CHAIN_IPE);
1145
1146 /*
1147 * Instantiate the volume manager and open the map stuff.
1148 */
1149 RTVFSFILE hPrevVfsFile = RTVfsObjToFile(hPrevVfsObj);
1150 AssertReturn(hPrevVfsFile != NIL_RTVFSFILE, VERR_VFS_CHAIN_CAST_FAILED);
1151
1152 RTDVM hVolMgr;
1153 int rc = RTDvmCreate(&hVolMgr, hPrevVfsFile, 512, 0 /*fFlags*/);
1154 RTVfsFileRelease(hPrevVfsFile);
1155 if (RT_SUCCESS(rc))
1156 {
1157 rc = RTDvmMapOpen(hVolMgr);
1158 if (RT_SUCCESS(rc))
1159 {
1160 /*
1161 * Create a VFS instance for the volume manager.
1162 */
1163 RTVFS hVfs = NIL_RTVFS;
1164 PRTDVMVFSVOL pThis = NULL;
1165 rc = RTVfsNew(&g_rtDvmVfsVolOps, sizeof(RTDVMVFSVOL), NIL_RTVFS, RTVFSLOCK_CREATE_RW, &hVfs, (void **)&pThis);
1166 if (RT_SUCCESS(rc))
1167 {
1168 pThis->hVolMgr = hVolMgr;
1169 pThis->fCloseDvm = true;
1170 pThis->fReadOnly = pElement->uProvider == (uint64_t)true;
1171 pThis->cVolumes = RTDvmMapGetValidVolumes(hVolMgr);
1172 pThis->hVfsSelf = hVfs;
1173
1174 *phVfsObj = RTVfsObjFromVfs(hVfs);
1175 RTVfsRelease(hVfs);
1176 return *phVfsObj != NIL_RTVFSOBJ ? VINF_SUCCESS : VERR_VFS_CHAIN_CAST_FAILED;
1177 }
1178 }
1179 else
1180 rc = RTErrInfoSetF(pErrInfo, rc, "RTDvmMapOpen failed: %Rrc", rc);
1181 RTDvmRelease(hVolMgr);
1182 }
1183 else
1184 rc = RTErrInfoSetF(pErrInfo, rc, "RTDvmCreate failed: %Rrc", rc);
1185 return rc;
1186}
1187
1188
1189/**
1190 * @interface_method_impl{RTVFSCHAINELEMENTREG,pfnCanReuseElement}
1191 */
1192static DECLCALLBACK(bool) rtDvmVfsChain_CanReuseElement(PCRTVFSCHAINELEMENTREG pProviderReg,
1193 PCRTVFSCHAINSPEC pSpec, PCRTVFSCHAINELEMSPEC pElement,
1194 PCRTVFSCHAINSPEC pReuseSpec, PCRTVFSCHAINELEMSPEC pReuseElement)
1195{
1196 RT_NOREF(pProviderReg, pSpec, pElement, pReuseSpec, pReuseElement);
1197 return false;
1198}
1199
1200
1201/** VFS chain element 'file'. */
1202static RTVFSCHAINELEMENTREG g_rtVfsChainIsoFsVolReg =
1203{
1204 /* uVersion = */ RTVFSCHAINELEMENTREG_VERSION,
1205 /* fReserved = */ 0,
1206 /* pszName = */ "dvm",
1207 /* ListEntry = */ { NULL, NULL },
1208 /* pszHelp = */ "Opens a container image using the VD API.\n"
1209 "Optionally takes one parameter 'ro' (read only) or 'rw' (read write).\n",
1210 /* pfnValidate = */ rtDvmVfsChain_Validate,
1211 /* pfnInstantiate = */ rtDvmVfsChain_Instantiate,
1212 /* pfnCanReuseElement = */ rtDvmVfsChain_CanReuseElement,
1213 /* uEndMarker = */ RTVFSCHAINELEMENTREG_VERSION
1214};
1215
1216RTVFSCHAIN_AUTO_REGISTER_ELEMENT_PROVIDER(&g_rtVfsChainIsoFsVolReg, rtVfsChainIsoFsVolReg);
1217
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette