VirtualBox

Changeset 78339 in vbox for trunk/src


Ignore:
Timestamp:
Apr 28, 2019 11:38:32 AM (6 years ago)
Author:
vboxsync
Message:

winnt/vboxsf: Contiuing cleaning up VBoxMRxSetFileInfo; moving stuff to improve locality somewhat. bugref:9172

Location:
trunk/src/VBox/Additions/WINNT/SharedFolders/driver
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/file.cpp

    r78338 r78339  
    260260         ByteCount, ByteOffset, FileSize));
    261261
    262     /** @todo check if this is necessary. */
     262/** @todo r=bird: This check is incorrect as we must let the host do these
     263 * checks with up-to-date end-of-file data.  What we've got cached here is
     264 * potentially out of date.  (This code is here because someone saw it in some
     265 * sample, I suspect and didn't quite understand what it was all about.  The
     266 * thing is that when FCB_STATE_READCACHING_ENABLED is set, the caller
     267 * already checks and the sample probably wanted to cover its bases.  We,
     268 * don't want to do that as already explained earlier.) */
    263269#ifdef FCB_STATE_READCACHING_ENABLED    /* Correct spelling for Vista 6001 SDK. */
    264270    if (!FlagOn(capFcb->FcbState, FCB_STATE_READCACHING_ENABLED))
     
    267273#endif
    268274    {
    269 /** @todo r=bird: How is this file size accurate given that the file resides
    270  *        on the host and be grown/shrunk independently there?   Why is this
    271  *        only done when FCB_STATE_READCACHEING_ENABLED is clear? */
    272275        if (ByteOffset >= FileSize)
    273276        {
     
    313316    RxContext->InformationToReturn = ByteCount;
    314317
     318/** @todo if we read past the end-of-file as we know it, or if we reached
     319 * end-of-file earlier than we though, update the file size.  The
     320 * RxLowIoReadShellCompletion() routine does not seem to do this for is and
     321 * I (bird) couldn't find anyone else doing it either. */
     322
    315323    Log(("VBOXSF: vbsfReadInternal: Status = 0x%08X, ByteCount = 0x%X\n",
    316324         Status, ByteCount));
     
    554562}
    555563
    556 NTSTATUS vbsfNtSetEndOfFile(IN OUT struct _RX_CONTEXT * RxContext,
    557                             IN uint64_t cbNewFileSize)
    558 {
    559     NTSTATUS Status = STATUS_SUCCESS;
    560 
    561     RxCaptureFcb;
    562     RxCaptureFobx;
    563 
    564     PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
    565     PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
    566 
    567     PSHFLFSOBJINFO pObjInfo;
    568     uint32_t cbBuffer;
    569     int vrc;
    570 
    571     Log(("VBOXSF: vbsfNtSetEndOfFile: New size = %RX64\n",
    572          cbNewFileSize));
    573 
    574     Assert(pVBoxFobx && pNetRootExtension);
    575 
    576     cbBuffer = sizeof(SHFLFSOBJINFO);
    577     pObjInfo = (SHFLFSOBJINFO *)vbsfNtAllocNonPagedMem(cbBuffer);
    578     if (!pObjInfo)
    579     {
    580         AssertFailed();
    581         return STATUS_INSUFFICIENT_RESOURCES;
    582     }
    583 
    584     RtlZeroMemory(pObjInfo, cbBuffer);
    585     pObjInfo->cbObject = cbNewFileSize;
    586 
    587     vrc = VbglR0SfFsInfo(&g_SfClient, &pNetRootExtension->map, pVBoxFobx->hFile,
    588                          SHFL_INFO_SET | SHFL_INFO_SIZE, &cbBuffer, (PSHFLDIRINFO)pObjInfo);
    589 
    590     Log(("VBOXSF: vbsfNtSetEndOfFile: VbglR0SfFsInfo returned %Rrc\n", vrc));
    591 
    592     Status = vbsfNtVBoxStatusToNt(vrc);
    593     if (Status == STATUS_SUCCESS)
    594     {
    595         Log(("VBOXSF: vbsfNtSetEndOfFile: VbglR0SfFsInfo new allocation size = %RX64\n",
    596              pObjInfo->cbAllocated));
    597 
    598         /** @todo update the file stats! */
    599     }
    600 
    601     if (pObjInfo)
    602         vbsfNtFreeNonPagedMem(pObjInfo);
    603 
    604     Log(("VBOXSF: vbsfNtSetEndOfFile: Returned 0x%08X\n", Status));
    605     return Status;
    606 }
    607 
    608564/** See PMRX_EXTENDFILE_CALLDOWN in ddk/mrx.h
    609565 *
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/info.cpp

    r78338 r78339  
    12731273}
    12741274
     1275/**
     1276 * Worker for vbsfNtSetBasicInfo.
     1277 */
    12751278static NTSTATUS vbsfNtSetBasicInfo(PMRX_VBOX_FOBX pVBoxFobx, PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
    12761279                                   PFILE_BASIC_INFORMATION pBasicInfo)
     
    14071410}
    14081411
     1412/**
     1413 * Worker for vbsfNtSetBasicInfo.
     1414 */
     1415static NTSTATUS vbsfNtSetEndOfFile(IN OUT struct _RX_CONTEXT * RxContext, IN uint64_t cbNewFileSize)
     1416{
     1417    NTSTATUS Status = STATUS_SUCCESS;
     1418
     1419    RxCaptureFcb;
     1420    RxCaptureFobx;
     1421
     1422    PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
     1423    PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
     1424
     1425    PSHFLFSOBJINFO pObjInfo;
     1426    uint32_t cbBuffer;
     1427    int vrc;
     1428
     1429    Log(("VBOXSF: vbsfNtSetEndOfFile: New size = %RX64\n",
     1430         cbNewFileSize));
     1431
     1432    Assert(pVBoxFobx && pNetRootExtension);
     1433
     1434    cbBuffer = sizeof(SHFLFSOBJINFO);
     1435    pObjInfo = (SHFLFSOBJINFO *)vbsfNtAllocNonPagedMem(cbBuffer);
     1436    if (!pObjInfo)
     1437    {
     1438        AssertFailed();
     1439        return STATUS_INSUFFICIENT_RESOURCES;
     1440    }
     1441
     1442    RtlZeroMemory(pObjInfo, cbBuffer);
     1443    pObjInfo->cbObject = cbNewFileSize;
     1444
     1445    vrc = VbglR0SfFsInfo(&g_SfClient, &pNetRootExtension->map, pVBoxFobx->hFile,
     1446                         SHFL_INFO_SET | SHFL_INFO_SIZE, &cbBuffer, (PSHFLDIRINFO)pObjInfo);
     1447
     1448    Log(("VBOXSF: vbsfNtSetEndOfFile: VbglR0SfFsInfo returned %Rrc\n", vrc));
     1449
     1450    Status = vbsfNtVBoxStatusToNt(vrc);
     1451    if (Status == STATUS_SUCCESS)
     1452    {
     1453        Log(("VBOXSF: vbsfNtSetEndOfFile: VbglR0SfFsInfo new allocation size = %RX64\n",
     1454             pObjInfo->cbAllocated));
     1455
     1456        /** @todo update the file stats! */
     1457    }
     1458
     1459    if (pObjInfo)
     1460        vbsfNtFreeNonPagedMem(pObjInfo);
     1461
     1462    Log(("VBOXSF: vbsfNtSetEndOfFile: Returned 0x%08X\n", Status));
     1463    return Status;
     1464}
     1465
     1466/**
     1467 * Worker for vbsfNtSetBasicInfo.
     1468 */
     1469static NTSTATUS vbsfNtRename(IN PRX_CONTEXT RxContext,
     1470                             IN FILE_INFORMATION_CLASS FileInformationClass,
     1471                             IN PVOID pBuffer,
     1472                             IN ULONG BufferLength)
     1473{
     1474    NTSTATUS Status = STATUS_SUCCESS;
     1475
     1476    RxCaptureFcb;
     1477    RxCaptureFobx;
     1478
     1479    PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
     1480    PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
     1481    PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
     1482
     1483    PFILE_RENAME_INFORMATION RenameInformation = (PFILE_RENAME_INFORMATION)RxContext->Info.Buffer;
     1484    PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME(pSrvOpen, capFcb);
     1485
     1486    int vrc;
     1487    PSHFLSTRING SrcPath = 0, DestPath = 0;
     1488    ULONG flags;
     1489
     1490    RT_NOREF(FileInformationClass, pBuffer, BufferLength);
     1491
     1492    Assert(FileInformationClass == FileRenameInformation);
     1493
     1494    Log(("VBOXSF: vbsfNtRename: FileName = %.*ls\n",
     1495         RenameInformation->FileNameLength / sizeof(WCHAR), &RenameInformation->FileName[0]));
     1496
     1497    /* Must close the file before renaming it! */
     1498    if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
     1499        vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx);
     1500
     1501    /* Mark it as renamed, so we do nothing during close */
     1502    SetFlag(pSrvOpen->Flags, SRVOPEN_FLAG_FILE_RENAMED);
     1503
     1504    Log(("VBOXSF: vbsfNtRename: RenameInformation->FileNameLength = %d\n", RenameInformation->FileNameLength));
     1505    Status = vbsfNtShflStringFromUnicodeAlloc(&DestPath, RenameInformation->FileName, (uint16_t)RenameInformation->FileNameLength);
     1506    if (Status != STATUS_SUCCESS)
     1507        return Status;
     1508
     1509    Log(("VBOXSF: vbsfNtRename: Destination path = %.*ls\n",
     1510         DestPath->u16Length / sizeof(WCHAR), &DestPath->String.ucs2[0]));
     1511
     1512    Log(("VBOXSF: vbsfNtRename: RemainingName->Length = %d\n", RemainingName->Length));
     1513    Status = vbsfNtShflStringFromUnicodeAlloc(&SrcPath, RemainingName->Buffer, RemainingName->Length);
     1514    if (Status != STATUS_SUCCESS)
     1515    {
     1516        vbsfNtFreeNonPagedMem(DestPath);
     1517        return Status;
     1518    }
     1519
     1520    Log(("VBOXSF: vbsfNtRename: Source path = %.*ls\n",
     1521         SrcPath->u16Length / sizeof(WCHAR), &SrcPath->String.ucs2[0]));
     1522
     1523    /* Call host. */
     1524    flags = pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? SHFL_RENAME_DIR : SHFL_RENAME_FILE;
     1525    if (RenameInformation->ReplaceIfExists)
     1526        flags |= SHFL_RENAME_REPLACE_IF_EXISTS;
     1527
     1528    Log(("VBOXSF: vbsfNtRename: Calling VbglR0SfRename\n"));
     1529    vrc = VbglR0SfRename(&g_SfClient, &pNetRootExtension->map, SrcPath, DestPath, flags);
     1530
     1531    vbsfNtFreeNonPagedMem(SrcPath);
     1532    vbsfNtFreeNonPagedMem(DestPath);
     1533
     1534    Status = vbsfNtVBoxStatusToNt(vrc);
     1535    if (vrc != VINF_SUCCESS)
     1536        Log(("VBOXSF: vbsfNtRename: VbglR0SfRename failed with %Rrc\n", vrc));
     1537
     1538    Log(("VBOXSF: vbsfNtRename: Returned 0x%08X\n", Status));
     1539    return Status;
     1540}
     1541
     1542
    14091543NTSTATUS VBoxMRxSetFileInfo(IN PRX_CONTEXT RxContext)
    14101544{
     
    14651599        }
    14661600
     1601        /*
     1602         * Prior to calling us, RxSetEndOfFileInfo will have updated the FCB fields space.FileSize,
     1603         * Header.AllocationSize and (if old value was larger) Header.ValidDataLength.  On success
     1604         * it will inform the cache manager, while on failure the old values will be restored.
     1605         *
     1606         * Note! RxSetEndOfFileInfo assumes that the old Header.FileSize value is up to date and
     1607         *       will hide calls which does not change the size from us.  This is of course not
     1608         *       the case for non-local file systems, as the server is the only which up-to-date
     1609         *       information.  Don't see an easy way of working around it, so ignoring it for now.
     1610         */
    14671611        case FileEndOfFileInformation:
    14681612        {
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/path.cpp

    r78329 r78339  
    724724}
    725725
    726 /*
     726/**
    727727 * Closes an opened file handle of a MRX_VBOX_FOBX.
     728 *
    728729 * Updates file attributes if necessary.
     730 *
     731 * Used by VBoxMRxCloseSrvOpen, vbsfNtRemove and vbsfNtRename.
    729732 */
    730 static NTSTATUS vbsfCloseFileHandle(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
    731                                     PMRX_VBOX_FOBX pVBoxFobx)
     733NTSTATUS vbsfNtCloseFileHandle(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
     734                               PMRX_VBOX_FOBX pVBoxFobx)
    732735{
    733736    NTSTATUS Status = STATUS_SUCCESS;
     
    803806    /* Close file */
    804807    if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
    805         vbsfCloseFileHandle(pNetRootExtension, pVBoxFobx);
     808        vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx);
    806809
    807810    if (capFcb->FcbState & FCB_STATE_DELETE_ON_CLOSE)
     
    818821}
    819822
     823/**
     824 * Worker for vbsfNtSetBasicInfo and VBoxMRxCloseSrvOpen.
     825 */
    820826NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext)
    821827{
     
    838844    /* Close file first if not already done. */
    839845    if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
    840         vbsfCloseFileHandle(pNetRootExtension, pVBoxFobx);
     846        vbsfNtCloseFileHandle(pNetRootExtension, pVBoxFobx);
    841847
    842848    Log(("VBOXSF: vbsfNtRemove: RemainingName->Length %d\n", RemainingName->Length));
     
    864870}
    865871
    866 NTSTATUS vbsfNtRename(IN PRX_CONTEXT RxContext,
    867                       IN FILE_INFORMATION_CLASS FileInformationClass,
    868                       IN PVOID pBuffer,
    869                       IN ULONG BufferLength)
    870 {
    871     NTSTATUS Status = STATUS_SUCCESS;
    872 
    873     RxCaptureFcb;
    874     RxCaptureFobx;
    875 
    876     PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(capFcb->pNetRoot);
    877     PMRX_VBOX_FOBX pVBoxFobx = VBoxMRxGetFileObjectExtension(capFobx);
    878     PMRX_SRV_OPEN pSrvOpen = capFobx->pSrvOpen;
    879 
    880     PFILE_RENAME_INFORMATION RenameInformation = (PFILE_RENAME_INFORMATION)RxContext->Info.Buffer;
    881     PUNICODE_STRING RemainingName = GET_ALREADY_PREFIXED_NAME(pSrvOpen, capFcb);
    882 
    883     int vrc;
    884     PSHFLSTRING SrcPath = 0, DestPath = 0;
    885     ULONG flags;
    886 
    887     RT_NOREF(FileInformationClass, pBuffer, BufferLength);
    888 
    889     Assert(FileInformationClass == FileRenameInformation);
    890 
    891     Log(("VBOXSF: vbsfNtRename: FileName = %.*ls\n",
    892          RenameInformation->FileNameLength / sizeof(WCHAR), &RenameInformation->FileName[0]));
    893 
    894     /* Must close the file before renaming it! */
    895     if (pVBoxFobx->hFile != SHFL_HANDLE_NIL)
    896         vbsfCloseFileHandle(pNetRootExtension, pVBoxFobx);
    897 
    898     /* Mark it as renamed, so we do nothing during close */
    899     SetFlag(pSrvOpen->Flags, SRVOPEN_FLAG_FILE_RENAMED);
    900 
    901     Log(("VBOXSF: vbsfNtRename: RenameInformation->FileNameLength = %d\n", RenameInformation->FileNameLength));
    902     Status = vbsfNtShflStringFromUnicodeAlloc(&DestPath, RenameInformation->FileName, (uint16_t)RenameInformation->FileNameLength);
    903     if (Status != STATUS_SUCCESS)
    904         return Status;
    905 
    906     Log(("VBOXSF: vbsfNtRename: Destination path = %.*ls\n",
    907          DestPath->u16Length / sizeof(WCHAR), &DestPath->String.ucs2[0]));
    908 
    909     Log(("VBOXSF: vbsfNtRename: RemainingName->Length = %d\n", RemainingName->Length));
    910     Status = vbsfNtShflStringFromUnicodeAlloc(&SrcPath, RemainingName->Buffer, RemainingName->Length);
    911     if (Status != STATUS_SUCCESS)
    912     {
    913         vbsfNtFreeNonPagedMem(DestPath);
    914         return Status;
    915     }
    916 
    917     Log(("VBOXSF: vbsfNtRename: Source path = %.*ls\n",
    918          SrcPath->u16Length / sizeof(WCHAR), &SrcPath->String.ucs2[0]));
    919 
    920     /* Call host. */
    921     flags = pVBoxFobx->Info.Attr.fMode & RTFS_DOS_DIRECTORY ? SHFL_RENAME_DIR : SHFL_RENAME_FILE;
    922     if (RenameInformation->ReplaceIfExists)
    923         flags |= SHFL_RENAME_REPLACE_IF_EXISTS;
    924 
    925     Log(("VBOXSF: vbsfNtRename: Calling VbglR0SfRename\n"));
    926     vrc = VbglR0SfRename(&g_SfClient, &pNetRootExtension->map, SrcPath, DestPath, flags);
    927 
    928     vbsfNtFreeNonPagedMem(SrcPath);
    929     vbsfNtFreeNonPagedMem(DestPath);
    930 
    931     Status = vbsfNtVBoxStatusToNt(vrc);
    932     if (vrc != VINF_SUCCESS)
    933         Log(("VBOXSF: vbsfNtRename: VbglR0SfRename failed with %Rrc\n", vrc));
    934 
    935     Log(("VBOXSF: vbsfNtRename: Returned 0x%08X\n", Status));
    936     return Status;
    937 }
    938 
    939872NTSTATUS VBoxMRxShouldTryToCollapseThisOpen(IN PRX_CONTEXT RxContext)
    940873{
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/vbsf.h

    r78338 r78339  
    219219NTSTATUS vbsfNtCreateConnection(IN PRX_CONTEXT RxContext,
    220220                                OUT PBOOLEAN PostToFsp);
    221 
    222 NTSTATUS vbsfNtSetEndOfFile(IN OUT struct _RX_CONTEXT * RxContext,
    223                             IN uint64_t cbNewFileSize);
    224 NTSTATUS vbsfNtRename(IN PRX_CONTEXT RxContext,
    225                       IN FILE_INFORMATION_CLASS FileInformationClass,
    226                       IN PVOID pBuffer,
    227                       IN ULONG BufferLength);
     221NTSTATUS vbsfNtCloseFileHandle(PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension,
     222                               PMRX_VBOX_FOBX pVBoxFobx);
    228223NTSTATUS vbsfNtRemove(IN PRX_CONTEXT RxContext);
    229 
    230224void     vbsfNtCopyInfoToLegacy(PMRX_VBOX_FOBX pVBoxFobx, PCSHFLFSOBJINFO pInfo);
    231 
    232225NTSTATUS vbsfNtVBoxStatusToNt(int vrc);
    233226PVOID    vbsfNtAllocNonPagedMem(ULONG ulSize);
Note: See TracChangeset for help on using the changeset viewer.

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