VirtualBox

Changeset 67207 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 1, 2017 1:16:02 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
115889
Message:

Storage/VDVfs.cpp: Faked up a working query function. Some adjustments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/VDVfs.cpp

    r66250 r67207  
    210210 * @interface_method_impl{RTVFSOBJOPS,pfnQueryInfo}
    211211 */
    212 static DECLCALLBACK(int) vdVfsFile_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo,
    213                                                RTFSOBJATTRADD enmAddAttr)
    214 {
    215     NOREF(pvThis);
    216     NOREF(pObjInfo);
    217     NOREF(enmAddAttr);
    218     return VERR_NOT_SUPPORTED;
     212static DECLCALLBACK(int) vdVfsFile_QueryInfo(void *pvThis, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAddAttr)
     213{
     214    PVDVFSFILE pThis = (PVDVFSFILE)pvThis;
     215    unsigned const cOpenImages = VDGetCount(pThis->pDisk);
     216
     217    pObjInfo->cbObject    = VDGetSize(pThis->pDisk, cOpenImages - 1);
     218    pObjInfo->cbAllocated = 0;
     219    for (unsigned iImage = 0; iImage < cOpenImages; iImage++)
     220        pObjInfo->cbAllocated += VDGetFileSize(pThis->pDisk, iImage);
     221
     222    /** @todo enumerate the disk images directly...   */
     223    RTTimeNow(&pObjInfo->AccessTime);
     224    pObjInfo->BirthTime        = pObjInfo->AccessTime;
     225    pObjInfo->ChangeTime       = pObjInfo->AccessTime;
     226    pObjInfo->ModificationTime = pObjInfo->AccessTime;
     227
     228    pObjInfo->Attr.fMode       = RTFS_DOS_NT_NORMAL | RTFS_TYPE_FILE | 0644;
     229    pObjInfo->Attr.enmAdditional = enmAddAttr;
     230    switch (enmAddAttr)
     231    {
     232        case RTFSOBJATTRADD_UNIX:
     233            pObjInfo->Attr.u.Unix.uid           = NIL_RTUID;
     234            pObjInfo->Attr.u.Unix.gid           = NIL_RTGID;
     235            pObjInfo->Attr.u.Unix.cHardlinks    = 1;
     236            pObjInfo->Attr.u.Unix.INodeIdDevice = 0;
     237            pObjInfo->Attr.u.Unix.INodeId       = 0;
     238            pObjInfo->Attr.u.Unix.fFlags        = 0;
     239            pObjInfo->Attr.u.Unix.GenerationId  = 0;
     240            pObjInfo->Attr.u.Unix.Device        = 0;
     241            break;
     242
     243        case RTFSOBJATTRADD_UNIX_OWNER:
     244            pObjInfo->Attr.u.UnixOwner.uid = NIL_RTUID;
     245            pObjInfo->Attr.u.UnixOwner.szName[0] = '\0';
     246            break;
     247        case RTFSOBJATTRADD_UNIX_GROUP:
     248            pObjInfo->Attr.u.UnixGroup.gid = NIL_RTGID;
     249            pObjInfo->Attr.u.UnixGroup.szName[0] = '\0';
     250            break;
     251        case RTFSOBJATTRADD_EASIZE:
     252            pObjInfo->Attr.u.EASize.cb = 0;
     253            break;
     254
     255        default:
     256            AssertFailedReturn(VERR_INVALID_PARAMETER);
     257    }
     258
     259    return VINF_SUCCESS;
    219260}
    220261
     
    226267{
    227268    PVDVFSFILE pThis = (PVDVFSFILE)pvThis;
    228     int rc = VINF_SUCCESS;
    229269
    230270    Assert(pSgBuf->cSegs == 1);
     
    235275     */
    236276    uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off;
    237     if (offUnsigned >= VDGetSize(pThis->pDisk, VD_LAST_IMAGE))
     277    uint64_t const cbImage = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
     278    if (offUnsigned >= cbImage)
    238279    {
    239280        if (pcbRead)
    240281        {
    241282            *pcbRead = 0;
    242             pThis->offCurPos = offUnsigned;
     283            pThis->offCurPos = cbImage;
    243284            return VINF_EOF;
    244285        }
     
    246287    }
    247288
    248     size_t cbLeftToRead;
    249     if (offUnsigned + pSgBuf->paSegs[0].cbSeg > VDGetSize(pThis->pDisk, VD_LAST_IMAGE))
     289    int rc = VINF_SUCCESS;
     290    size_t cbLeftToRead = pSgBuf->paSegs[0].cbSeg;
     291    if (offUnsigned + cbLeftToRead <= cbImage)
     292    {
     293        if (pcbRead)
     294            *pcbRead = cbLeftToRead;
     295    }
     296    else
    250297    {
    251298        if (!pcbRead)
    252299            return VERR_EOF;
    253         *pcbRead = cbLeftToRead = (size_t)(VDGetSize(pThis->pDisk, VD_LAST_IMAGE) - offUnsigned);
    254     }
    255     else
    256     {
    257         cbLeftToRead = pSgBuf->paSegs[0].cbSeg;
    258         if (pcbRead)
    259             *pcbRead = cbLeftToRead;
     300        *pcbRead = cbLeftToRead = (size_t)(cbImage - offUnsigned);
     301        rc = VINF_EOF;
    260302    }
    261303
     
    265307    if (cbLeftToRead > 0)
    266308    {
    267         rc = vdReadHelper(pThis->pDisk, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbLeftToRead);
    268         if (RT_SUCCESS(rc))
     309        int rc2 = vdReadHelper(pThis->pDisk, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToRead);
     310        if (RT_SUCCESS(rc2))
    269311            offUnsigned += cbLeftToRead;
     312        else
     313            rc = rc2;
    270314    }
    271315
     
    281325{
    282326    PVDVFSFILE pThis = (PVDVFSFILE)pvThis;
    283     int rc = VINF_SUCCESS;
    284327
    285328    Assert(pSgBuf->cSegs == 1);
     
    291334     */
    292335    uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off;
    293     if (offUnsigned >= VDGetSize(pThis->pDisk, VD_LAST_IMAGE))
     336    uint64_t const cbImage = VDGetSize(pThis->pDisk, VD_LAST_IMAGE);
     337    if (offUnsigned >= cbImage)
    294338    {
    295339        if (pcbWritten)
    296340        {
    297341            *pcbWritten = 0;
    298             pThis->offCurPos = offUnsigned;
    299         }
    300         return VERR_NOT_SUPPORTED;
     342            pThis->offCurPos = cbImage;
     343        }
     344        return VERR_EOF;
    301345    }
    302346
    303347    size_t cbLeftToWrite;
    304     if (offUnsigned + pSgBuf->paSegs[0].cbSeg > VDGetSize(pThis->pDisk, VD_LAST_IMAGE))
    305     {
    306         if (!pcbWritten)
    307             return VERR_EOF;
    308         *pcbWritten = cbLeftToWrite = (size_t)(VDGetSize(pThis->pDisk, VD_LAST_IMAGE) - offUnsigned);
    309     }
    310     else
     348    if (offUnsigned + pSgBuf->paSegs[0].cbSeg < cbImage)
    311349    {
    312350        cbLeftToWrite = pSgBuf->paSegs[0].cbSeg;
     
    314352            *pcbWritten = cbLeftToWrite;
    315353    }
     354    else
     355    {
     356        if (!pcbWritten)
     357            return VERR_EOF;
     358        *pcbWritten = cbLeftToWrite = (size_t)(cbImage - offUnsigned);
     359    }
    316360
    317361    /*
    318362     * Ok, we've got a valid stretch within the file.  Do the reading.
    319363     */
     364    int rc = VINF_SUCCESS;
    320365    if (cbLeftToWrite > 0)
    321366    {
    322         rc = vdWriteHelper(pThis->pDisk, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbLeftToWrite);
     367        rc = vdWriteHelper(pThis->pDisk, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToWrite);
    323368        if (RT_SUCCESS(rc))
    324369            offUnsigned += cbLeftToWrite;
     
    344389 */
    345390static DECLCALLBACK(int) vdVfsFile_PollOne(void *pvThis, uint32_t fEvents, RTMSINTERVAL cMillies, bool fIntr,
    346                                               uint32_t *pfRetEvents)
     391                                           uint32_t *pfRetEvents)
    347392{
    348393    NOREF(pvThis);
     
    439484
    440485    /*
    441      * Calc new position, take care to stay within bounds.
    442      *
    443      * @todo: Setting position beyond the end of the disk does not make sense.
     486     * Calc new position, take care to stay without bounds.
    444487     */
    445488    uint64_t offNew;
Note: See TracChangeset for help on using the changeset viewer.

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