VirtualBox

Changeset 70195 in vbox for trunk/src/VBox/Runtime/r3/nt


Ignore:
Timestamp:
Dec 18, 2017 1:40:26 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119769
Message:

IPRT/R3: Made the core work on NT 3.51 (still experimental).

Location:
trunk/src/VBox/Runtime/r3/nt
Files:
2 edited

Legend:

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

    r69705 r70195  
    4646    (   (a_UniStr)->Length == sizeof(a_wszType) - sizeof(RTUTF16) \
    4747     && memcmp((a_UniStr)->Buffer, a_wszType, sizeof(a_wszType) - sizeof(RTUTF16)) == 0)
     48
     49
     50/*********************************************************************************************************************************
     51*   Global Variables                                                                                                             *
     52*********************************************************************************************************************************/
     53extern decltype(NtQueryFullAttributesFile) *g_pfnNtQueryFullAttributesFile; /* init-win.cpp */
    4854
    4955
     
    378384     */
    379385    int rc = VINF_TRY_AGAIN;
    380     if (enmAddAttr != RTFSOBJATTRADD_UNIX)
     386    if (   enmAddAttr != RTFSOBJATTRADD_UNIX
     387        && g_pfnNtQueryFullAttributesFile)
    381388    {
    382389        InitializeObjectAttributes(&ObjAttr, pNtName, OBJ_CASE_INSENSITIVE, hRootDir, NULL);
    383         rcNt = NtQueryFullAttributesFile(&ObjAttr, &uBuf.NetOpenInfo);
     390        rcNt = g_pfnNtQueryFullAttributesFile(&ObjAttr, &uBuf.NetOpenInfo);
    384391        if (NT_SUCCESS(rcNt))
    385392        {
  • trunk/src/VBox/Runtime/r3/nt/pathint-nt.cpp

    r69705 r70195  
    3838#include <iprt/assert.h>
    3939
     40#include "../win/internal-r3-win.h"
     41
    4042
    4143/*********************************************************************************************************************************
    4244*   Global Variables                                                                                                             *
    4345*********************************************************************************************************************************/
    44 static char const g_szPrefixUnc[] = "\\??\\UNC\\";
    45 static char const g_szPrefix[]    = "\\??\\";
     46static char const g_szPrefixUnc[]      = "\\??\\UNC\\";
     47static char const g_szPrefix[]         = "\\??\\";
     48static char const g_szPrefixNt3xUnc[]  = "\\DosDevices\\UNC\\";
     49static char const g_szPrefixNt3x[]     = "\\DosDevices\\";
    4650
    4751
     
    6468        if (cwcLen < _32K - 1)
    6569        {
    66             pwszPath[0] = '\\';
    67             pwszPath[1] = '?';
    68             pwszPath[2] = '?';
    69             pwszPath[3] = '\\';
    70 
     70            *phRootDir = NULL;
     71            if (   g_enmWinVer >=  kRTWinOSType_NT4
     72                || g_enmWinVer == kRTWinOSType_UNKNOWN)
     73            {
     74                pwszPath[0] = '\\';
     75                pwszPath[1] = '?';
     76                pwszPath[2] = '?';
     77                pwszPath[3] = '\\';
     78
     79                pNtName->Buffer = pwszPath;
     80                pNtName->Length = (uint16_t)(cwcLen * sizeof(RTUTF16));
     81                pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
     82                return VINF_SUCCESS;
     83            }
     84
     85            rc = RTUtf16Realloc(&pwszPath, cwcLen + sizeof(g_szPrefixNt3x));
     86            if (RT_SUCCESS(rc))
     87            {
     88                memmove(&pwszPath[sizeof(g_szPrefixNt3x) - 1], &pwszPath[4], (cwcLen - 4 + 1) * sizeof(RTUTF16));
     89                for (uint32_t i = 0; i < sizeof(g_szPrefixNt3x) - 1; i++)
     90                    pwszPath[i] = g_szPrefixNt3x[i];
     91
     92                pNtName->Buffer = pwszPath;
     93                pNtName->Length = (uint16_t)((cwcLen - 4 + sizeof(g_szPrefixNt3x) - 1) * sizeof(RTUTF16));
     94                pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
     95                return VINF_SUCCESS;
     96            }
     97        }
     98
     99        RTUtf16Free(pwszPath);
     100        rc = VERR_FILENAME_TOO_LONG;
     101    }
     102    return rc;
     103}
     104
     105
     106/**
     107 * Handles the pass thru case for UTF-16 input.
     108 * Win32 path uses "\\?\" prefix which is converted to "\??\" NT prefix.
     109 *
     110 * @returns IPRT status code.
     111 * @param   pNtName             Where to return the NT name.
     112 * @param   phRootDir           Stores NULL here, as we don't use it.
     113 * @param   pwszWinPath         The UTF-16 windows-style path.
     114 * @param   cwcWinPath          The length of the windows-style input path.
     115 */
     116static int rtNtPathFromWinUtf16PassThru(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir,
     117                                        PCRTUTF16 pwszWinPath, size_t cwcWinPath)
     118{
     119    /* Check length and allocate memory for it. */
     120    int rc;
     121    if (cwcWinPath < _32K - 1)
     122    {
     123        size_t const cwcExtraPrefix =  g_enmWinVer >=  kRTWinOSType_NT4 || g_enmWinVer == kRTWinOSType_UNKNOWN
     124                                    ? 0 : sizeof(g_szPrefixNt3x) - 1 - 4;
     125        PRTUTF16 pwszNtPath = (PRTUTF16)RTUtf16Alloc((cwcExtraPrefix + cwcWinPath + 1) * sizeof(RTUTF16));
     126        if (pwszNtPath)
     127        {
     128            /* Intialize the path. */
     129            if (!cwcExtraPrefix)
     130            {
     131                pwszNtPath[0] = '\\';
     132                pwszNtPath[1] = '?';
     133                pwszNtPath[2] = '?';
     134                pwszNtPath[3] = '\\';
     135            }
     136            else
     137                for (uint32_t i = 0; i < sizeof(g_szPrefixNt3x) - 1; i++)
     138                    pwszNtPath[i] = g_szPrefixNt3x[i];
     139            memcpy(pwszNtPath + cwcExtraPrefix + 4, pwszWinPath + 4, (cwcWinPath - 4) * sizeof(RTUTF16));
     140            pwszNtPath[cwcExtraPrefix + cwcWinPath] = '\0';
     141
     142            /* Initialize the return values. */
     143            pNtName->Buffer = pwszNtPath;
     144            pNtName->Length = (uint16_t)(cwcExtraPrefix + cwcWinPath * sizeof(RTUTF16));
     145            pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
     146            *phRootDir = NULL;
     147
     148            rc = VINF_SUCCESS;
     149        }
     150        else
     151            rc = VERR_NO_UTF16_MEMORY;
     152    }
     153    else
     154        rc = VERR_FILENAME_TOO_LONG;
     155    return rc;
     156}
     157
     158
     159
     160
     161
     162/**
     163 * Converts the path to UTF-16 and sets all the return values.
     164 *
     165 * @returns IPRT status code.
     166 * @param   pNtName             Where to return the NT name.
     167 * @param   phRootDir           Where to return the root handle, if applicable.
     168 * @param   pszPath             The UTF-8 path.
     169 */
     170static int rtNtPathUtf8ToUniStr(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath)
     171{
     172    PRTUTF16 pwszPath = NULL;
     173    size_t   cwcLen;
     174    int rc = RTStrToUtf16Ex(pszPath, RTSTR_MAX, &pwszPath, 0, &cwcLen);
     175    if (RT_SUCCESS(rc))
     176    {
     177        if (cwcLen < _32K - 1)
     178        {
    71179            pNtName->Buffer = pwszPath;
    72180            pNtName->Length = (uint16_t)(cwcLen * sizeof(RTUTF16));
     
    84192
    85193/**
    86  * Handles the pass thru case for UTF-16 input.
    87  * Win32 path uses "\\?\" prefix which is converted to "\??\" NT prefix.
    88  *
    89  * @returns IPRT status code.
    90  * @param   pNtName             Where to return the NT name.
    91  * @param   phRootDir           Stores NULL here, as we don't use it.
    92  * @param   pwszWinPath         The UTF-16 windows-style path.
    93  * @param   cwcWinPath          The length of the windows-style input path.
    94  */
    95 static int rtNtPathFromWinUtf16PassThru(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir,
    96                                         PCRTUTF16 pwszWinPath, size_t cwcWinPath)
    97 {
    98     /* Check length and allocate memory for it. */
    99     int rc;
    100     if (cwcWinPath < _32K - 1)
    101     {
    102         PRTUTF16 pwszNtPath = (PRTUTF16)RTUtf16Alloc((cwcWinPath + 1) * sizeof(RTUTF16));
    103         if (pwszNtPath)
    104         {
    105             /* Intialize the path. */
    106             pwszNtPath[0] = '\\';
    107             pwszNtPath[1] = '?';
    108             pwszNtPath[2] = '?';
    109             pwszNtPath[3] = '\\';
    110             memcpy(pwszNtPath + 4, pwszWinPath + 4, (cwcWinPath - 4) * sizeof(RTUTF16));
    111             pwszNtPath[cwcWinPath] = '\0';
    112 
    113             /* Initialize the return values. */
    114             pNtName->Buffer = pwszNtPath;
    115             pNtName->Length = (uint16_t)(cwcWinPath * sizeof(RTUTF16));
    116             pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
    117             *phRootDir = NULL;
    118 
    119             rc = VINF_SUCCESS;
    120         }
    121         else
    122             rc = VERR_NO_UTF16_MEMORY;
    123     }
    124     else
    125         rc = VERR_FILENAME_TOO_LONG;
    126     return rc;
    127 }
    128 
    129 
    130 
    131 
    132 
    133 /**
    134  * Converts the path to UTF-16 and sets all the return values.
    135  *
    136  * @returns IPRT status code.
    137  * @param   pNtName             Where to return the NT name.
    138  * @param   phRootDir           Where to return the root handle, if applicable.
    139  * @param   pszPath             The UTF-8 path.
    140  */
    141 static int rtNtPathUtf8ToUniStr(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath)
    142 {
    143     PRTUTF16 pwszPath = NULL;
    144     size_t   cwcLen;
    145     int rc = RTStrToUtf16Ex(pszPath, RTSTR_MAX, &pwszPath, 0, &cwcLen);
    146     if (RT_SUCCESS(rc))
    147     {
    148         if (cwcLen < _32K - 1)
    149         {
    150             pNtName->Buffer = pwszPath;
    151             pNtName->Length = (uint16_t)(cwcLen * sizeof(RTUTF16));
    152             pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
    153             *phRootDir = NULL;
    154             return VINF_SUCCESS;
    155         }
    156 
    157         RTUtf16Free(pwszPath);
    158         rc = VERR_FILENAME_TOO_LONG;
    159     }
    160     return rc;
    161 }
    162 
    163 
    164 /**
    165194 * Converts a windows-style path to NT format and encoding.
    166195 *
     
    179208     * Very simple conversion of a win32-like path into an NT path.
    180209     */
    181     const char *pszPrefix = g_szPrefix;
    182     size_t      cchPrefix = sizeof(g_szPrefix) - 1;
     210    const char *pszPrefix;
     211    size_t      cchPrefix;
     212    if (   g_enmWinVer >=  kRTWinOSType_NT4
     213        || g_enmWinVer == kRTWinOSType_UNKNOWN)
     214    {
     215        pszPrefix = g_szPrefix;
     216        cchPrefix = sizeof(g_szPrefix) - 1;
     217    }
     218    else
     219    {
     220        pszPrefix = g_szPrefixNt3x;
     221        cchPrefix = sizeof(g_szPrefixNt3x) - 1;
     222    }
     223
    183224    size_t      cchSkip   = 0;
    184 
    185225    if (   RTPATH_IS_SLASH(pszPath[0])
    186226        && RTPATH_IS_SLASH(pszPath[1])
     
    211251        {
    212252            /* UNC */
    213             pszPrefix = g_szPrefixUnc;
    214             cchPrefix = sizeof(g_szPrefixUnc) - 1;
     253            if (   g_enmWinVer >=  kRTWinOSType_NT4
     254                || g_enmWinVer == kRTWinOSType_UNKNOWN)
     255            {
     256                pszPrefix = g_szPrefixUnc;
     257                cchPrefix = sizeof(g_szPrefixUnc) - 1;
     258            }
     259            else
     260            {
     261                pszPrefix = g_szPrefixNt3xUnc;
     262                cchPrefix = sizeof(g_szPrefixNt3xUnc) - 1;
     263            }
    215264            cchSkip   = 2;
    216265        }
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