pathint-nt.cpp revision 304e26e9a9c1422dbc299ed139eceacca271a9dd
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * IPRT - Native NT, Internal Path stuff.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * Copyright (C) 2006-2013 Oracle Corporation
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * available from http://www.virtualbox.org. This file is free software;
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * General Public License (GPL) as published by the Free Software
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * The contents of this file may alternatively be used under the terms
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * of the Common Development and Distribution License Version 1.0
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * VirtualBox OSE distribution, in which case the provisions of the
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * CDDL are applicable instead of those of the GPL.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * You may elect to license modified versions of this file under the
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * terms and conditions of either the GPL or the CDDL or both.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync/*******************************************************************************
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync* Header Files *
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync*******************************************************************************/
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * Handles the pass thru case.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * @returns IPRT status code.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @param pNtName Where to return the NT name.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @param phRootDir Where to return the root handle, if applicable.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * @param pszPath The UTF-8 path.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsyncstatic int rtNtPathToNativePassThruWin(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath)
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync int rc = RTStrToUtf16Ex(pszPath + 1, RTSTR_MAX, &pwszPath, 0, &cwcLen);
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync pNtName->MaximumLength = pNtName->Length = (uint16_t)(cwcLen * 2);
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * Converts the path to UTF-16 and sets all the return values.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * @returns IPRT status code.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * @param pNtName Where to return the NT name.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @param phRootDir Where to return the root handle, if applicable.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @param pszPath The UTF-8 path.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsyncstatic int rtNtPathToNativeToUtf16(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath)
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync int rc = RTStrToUtf16Ex(pszPath, RTSTR_MAX, &pwszPath, 0, &cwcLen);
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync pNtName->MaximumLength = pNtName->Length = (uint16_t)(cwcLen * 2);
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * Converts a path to NT format and encoding.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @returns IPRT status code.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * @param pNtName Where to return the NT name.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * @param phRootDir Where to return the root handle, if applicable.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * @param pszPath The UTF-8 path.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsyncstatic int rtNtPathToNative(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath)
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * Very simple conversion of a win32-like path into an NT path.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync return rtNtPathToNativePassThruWin(pNtName, phRootDir, pszPath);
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync /* Special hack: The path starts with "\\\\!\\", we will skip past the bang and pass it thru. */
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync return rtNtPathToNativeToUtf16(pNtName, phRootDir, pszPath + 3);
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * Device path.
a4ba1fc5788b1fb4c078587d5f55936e1b83098dvboxsync * Note! I suspect \\.\stuff\..\otherstuff may be handled differently by windows.
return rc;
RTDECL(int) RTNtPathOpen(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs, ULONG fShareAccess,
&ObjAttr,
&Ios,
if (puAction)
return rc;
RTDECL(int) RTNtPathOpenDir(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fShareAccess, ULONG fCreateOptions,
&ObjAttr,
&Ios,
if (pfObjDir)
*pfObjDir = false;
#ifdef IPRT_WITH_NT_PATH_PASSTHRU
else if ( pfObjDir
if ( (fDesiredAccess & (FILE_LIST_DIRECTORY | FILE_GENERIC_READ | GENERIC_READ | STANDARD_RIGHTS_READ))
|| !fObjDesiredAccess)
*pfObjDir = true;
return rc;
return VINF_SUCCESS;