VirtualBox

Changeset 69795 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Nov 21, 2017 4:29:49 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119213
Message:

IPRT: file mode changing on NT + RTChMod command.

  • Reimplemented RTFileSetMode for NT.
  • Implemented RTPathSetMode for NT.
  • Reimplemented RTDirRelPathSetMode for NT.
  • Started on a testcase command: RTChMode
Location:
trunk/src/VBox/Runtime/r3
Files:
2 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/nt/dirrel-r3-nt.cpp

    r69753 r69795  
    414414    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    415415    AssertReturn(pThis->u32Magic == RTDIR_MAGIC, VERR_INVALID_HANDLE);
     416    fMode = rtFsModeNormalize(fMode, pszRelPath, 0);
     417    AssertReturn(rtFsModeIsValidPermissions(fMode), VERR_INVALID_FMODE);
    416418    AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_FLAGS);
    417419
    418     char szPath[RTPATH_MAX];
    419     int rc = rtDirRelBuildFullPath(pThis, szPath, sizeof(szPath), pszRelPath);
    420     if (RT_SUCCESS(rc))
    421     {
    422 RTAssertMsg2("DBG: RTDirRelPathSetMode(%s)...\n", szPath);
    423 #ifndef RT_OS_WINDOWS
    424         rc = RTPathSetMode(szPath, fMode); /** @todo fFlags is currently ignored. */
    425 #else
    426         rc = VERR_NOT_IMPLEMENTED; /** @todo implement RTPathSetMode on windows. */
    427         RT_NOREF(fMode);
    428 #endif
     420    /*
     421     * Convert and normalize the path.
     422     */
     423    UNICODE_STRING NtName;
     424    HANDLE hRoot = pThis->hDir;
     425    int rc = RTNtPathRelativeFromUtf8(&NtName, &hRoot, pszRelPath, RTDIRREL_NT_GET_ASCENT(pThis),
     426                                      pThis->enmInfoClass == FileMaximumInformation);
     427    if (RT_SUCCESS(rc))
     428    {
     429        HANDLE              hSubDir = RTNT_INVALID_HANDLE_VALUE;
     430        IO_STATUS_BLOCK     Ios     = RTNT_IO_STATUS_BLOCK_INITIALIZER;
     431        OBJECT_ATTRIBUTES   ObjAttr;
     432        InitializeObjectAttributes(&ObjAttr, &NtName, 0 /*fAttrib*/, hRoot, NULL);
     433
     434        ULONG fOpenOptions = FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT | FILE_OPEN_REPARSE_POINT;
     435        if (fFlags & RTPATH_F_ON_LINK)
     436            fOpenOptions |= FILE_OPEN_REPARSE_POINT;
     437        NTSTATUS rcNt = NtCreateFile(&hSubDir,
     438                                     FILE_WRITE_ATTRIBUTES | SYNCHRONIZE,
     439                                     &ObjAttr,
     440                                     &Ios,
     441                                     NULL /*AllocationSize*/,
     442                                     FILE_ATTRIBUTE_NORMAL,
     443                                     FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
     444                                     FILE_OPEN,
     445                                     fOpenOptions,
     446                                     NULL /*EaBuffer*/,
     447                                     0 /*EaLength*/);
     448        if (NT_SUCCESS(rcNt))
     449        {
     450            rc = rtNtFileSetModeWorker(hSubDir, fMode);
     451
     452            rcNt = NtClose(hSubDir);
     453            if (!NT_SUCCESS(rcNt) && RT_SUCCESS(rc))
     454                rc = RTErrConvertFromNtStatus(rcNt);
     455        }
     456        else
     457            rc = RTErrConvertFromNtStatus(rcNt);
     458
     459        RTNtPathFree(&NtName, NULL);
    429460    }
    430461    return rc;
  • trunk/src/VBox/Runtime/r3/nt/internal-r3-nt.h

    r69111 r69795  
    6969#endif
    7070
     71/**
     72 * Common worker for RTFileSetMode, RTPathSetMode and RTDirRelPathSetMode.
     73 *
     74 * @returns IPRT status code.
     75 * @param   hNativeFile The NT handle to the file system object.
     76 * @param   fMode       Valid and normalized file mode mask to set.
     77 */
     78DECLHIDDEN(int) rtNtFileSetModeWorker(HANDLE hNativeFile, RTFMODE fMode);
     79
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r69536 r69795  
    977977
    978978
     979#if 0 /* RTFileSetMode is implemented by RTFileSetMode-r3-nt.cpp */
    979980/* This comes from a source file with a different set of system headers (DDK)
    980981 * so it can't be declared in a common header, like internal/file.h.
     
    10031004    return VINF_SUCCESS;
    10041005}
     1006#endif
    10051007
    10061008
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