diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
---|---|---|
committer | <> | 2014-05-08 15:03:54 +0000 |
commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Runtime/r3/win/dir-win.cpp | |
parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
download | VirtualBox-master.tar.gz |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Runtime/r3/win/dir-win.cpp')
-rw-r--r-- | src/VBox/Runtime/r3/win/dir-win.cpp | 342 |
1 files changed, 3 insertions, 339 deletions
diff --git a/src/VBox/Runtime/r3/win/dir-win.cpp b/src/VBox/Runtime/r3/win/dir-win.cpp index 2494b8b4..5c57315f 100644 --- a/src/VBox/Runtime/r3/win/dir-win.cpp +++ b/src/VBox/Runtime/r3/win/dir-win.cpp @@ -1,10 +1,10 @@ /* $Id: dir-win.cpp $ */ /** @file - * IPRT - Directory, win32. + * IPRT - Directory, Windows. */ /* - * Copyright (C) 2006-2007 Oracle Corporation + * Copyright (C) 2006-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -30,20 +30,17 @@ *******************************************************************************/ #define LOG_GROUP RTLOGGROUP_DIR #include <Windows.h> -#include <io.h> #include <iprt/dir.h> #include <iprt/path.h> -#include <iprt/alloc.h> +#include <iprt/mem.h> #include <iprt/string.h> #include <iprt/assert.h> -#include <iprt/param.h> #include <iprt/err.h> #include <iprt/file.h> #include <iprt/log.h> #include "internal/fs.h" #include "internal/path.h" -#include "internal/dir.h" @@ -129,339 +126,6 @@ RTDECL(int) RTDirFlush(const char *pszPath) } -int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf) -{ - /* - * Setup the search expression. - * - * pszPathBuf is pointing to the return 4K return buffer for the RTPathReal() - * call in rtDirOpenCommon(), so all we gota do is check that we don't overflow - * it when adding the wildcard expression. - */ - size_t cchExpr; - const char *pszExpr; - if (pDir->enmFilter == RTDIRFILTER_WINNT) - { - pszExpr = pDir->pszFilter; - cchExpr = pDir->cchFilter + 1; - } - else - { - pszExpr = "*"; - cchExpr = sizeof("*"); - } - if (pDir->cchPath + cchExpr > RTPATH_MAX) - return VERR_FILENAME_TOO_LONG; - memcpy(pszPathBuf + pDir->cchPath, pszExpr, cchExpr); - - - /* - * Attempt opening the search. - */ - int rc = VINF_SUCCESS; - PRTUTF16 pwszName; - rc = RTStrToUtf16(pszPathBuf, &pwszName); - if (RT_SUCCESS(rc)) - { - pDir->hDir = FindFirstFileW((LPCWSTR)pwszName, &pDir->Data); - if (pDir->hDir != INVALID_HANDLE_VALUE) - pDir->fDataUnread = true; - /* theoretical case of an empty directory. */ - else if (GetLastError() == ERROR_NO_MORE_FILES) - pDir->fDataUnread = false; - else - rc = RTErrConvertFromWin32(GetLastError()); - RTUtf16Free(pwszName); - } - - return rc; -} - - -RTDECL(int) RTDirClose(PRTDIR pDir) -{ - /* - * Validate input. - */ - if (!pDir) - return VERR_INVALID_PARAMETER; - if (pDir->u32Magic != RTDIR_MAGIC) - { - AssertMsgFailed(("Invalid pDir=%p\n", pDir)); - return VERR_INVALID_PARAMETER; - } - - /* - * Close the handle. - */ - pDir->u32Magic++; - if (pDir->hDir != INVALID_HANDLE_VALUE) - { - BOOL fRc = FindClose(pDir->hDir); - Assert(fRc); - pDir->hDir = INVALID_HANDLE_VALUE; - } - RTStrFree(pDir->pszName); - pDir->pszName = NULL; - RTMemFree(pDir); - - return VINF_SUCCESS; -} - - -RTDECL(int) RTDirRead(PRTDIR pDir, PRTDIRENTRY pDirEntry, size_t *pcbDirEntry) -{ - /* - * Validate input. - */ - if (!pDir || pDir->u32Magic != RTDIR_MAGIC) - { - AssertMsgFailed(("Invalid pDir=%p\n", pDir)); - return VERR_INVALID_PARAMETER; - } - if (!pDirEntry) - { - AssertMsgFailed(("Invalid pDirEntry=%p\n", pDirEntry)); - return VERR_INVALID_PARAMETER; - } - size_t cbDirEntry = sizeof(*pDirEntry); - if (pcbDirEntry) - { - cbDirEntry = *pcbDirEntry; - if (cbDirEntry < RT_UOFFSETOF(RTDIRENTRY, szName[2])) - { - AssertMsgFailed(("Invalid *pcbDirEntry=%d (min %d)\n", *pcbDirEntry, RT_OFFSETOF(RTDIRENTRY, szName[2]))); - return VERR_INVALID_PARAMETER; - } - } - - /* - * Fetch data? - */ - if (!pDir->fDataUnread) - { - RTStrFree(pDir->pszName); - pDir->pszName = NULL; - - BOOL fRc = FindNextFileW(pDir->hDir, &pDir->Data); - if (!fRc) - { - int iErr = GetLastError(); - if (pDir->hDir == INVALID_HANDLE_VALUE || iErr == ERROR_NO_MORE_FILES) - return VERR_NO_MORE_FILES; - return RTErrConvertFromWin32(iErr); - } - } - - /* - * Convert the filename to UTF-8. - */ - if (!pDir->pszName) - { - int rc = RTUtf16ToUtf8((PCRTUTF16)pDir->Data.cFileName, &pDir->pszName); - if (RT_FAILURE(rc)) - { - pDir->pszName = NULL; - return rc; - } - pDir->cchName = strlen(pDir->pszName); - } - - /* - * Check if we've got enough space to return the data. - */ - const char *pszName = pDir->pszName; - const size_t cchName = pDir->cchName; - const size_t cbRequired = RT_OFFSETOF(RTDIRENTRY, szName[1]) + cchName; - if (pcbDirEntry) - *pcbDirEntry = cbRequired; - if (cbRequired > cbDirEntry) - return VERR_BUFFER_OVERFLOW; - - /* - * Setup the returned data. - */ - pDir->fDataUnread = false; - pDirEntry->INodeId = 0; /** @todo we can use the fileid here if we must (see GetFileInformationByHandle). */ - pDirEntry->enmType = pDir->Data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY - ? RTDIRENTRYTYPE_DIRECTORY : RTDIRENTRYTYPE_FILE; - pDirEntry->cbName = (uint16_t)cchName; - Assert(pDirEntry->cbName == cchName); - memcpy(pDirEntry->szName, pszName, cchName + 1); - - return VINF_SUCCESS; -} - - -RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags) -{ - /** @todo Symlinks: Find[First|Next]FileW will return info about - the link, so RTPATH_F_FOLLOW_LINK is not handled correctly. */ - /* - * Validate input. - */ - if (!pDir || pDir->u32Magic != RTDIR_MAGIC) - { - AssertMsgFailed(("Invalid pDir=%p\n", pDir)); - return VERR_INVALID_PARAMETER; - } - if (!pDirEntry) - { - AssertMsgFailed(("Invalid pDirEntry=%p\n", pDirEntry)); - return VERR_INVALID_PARAMETER; - } - if ( enmAdditionalAttribs < RTFSOBJATTRADD_NOTHING - || enmAdditionalAttribs > RTFSOBJATTRADD_LAST) - { - AssertMsgFailed(("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs)); - return VERR_INVALID_PARAMETER; - } - AssertMsgReturn(RTPATH_F_IS_VALID(fFlags, 0), ("%#x\n", fFlags), VERR_INVALID_PARAMETER); - size_t cbDirEntry = sizeof(*pDirEntry); - if (pcbDirEntry) - { - cbDirEntry = *pcbDirEntry; - if (cbDirEntry < RT_UOFFSETOF(RTDIRENTRYEX, szName[2])) - { - AssertMsgFailed(("Invalid *pcbDirEntry=%d (min %d)\n", *pcbDirEntry, RT_OFFSETOF(RTDIRENTRYEX, szName[2]))); - return VERR_INVALID_PARAMETER; - } - } - - /* - * Fetch data? - */ - if (!pDir->fDataUnread) - { - RTStrFree(pDir->pszName); - pDir->pszName = NULL; - - BOOL fRc = FindNextFileW(pDir->hDir, &pDir->Data); - if (!fRc) - { - int iErr = GetLastError(); - if (pDir->hDir == INVALID_HANDLE_VALUE || iErr == ERROR_NO_MORE_FILES) - return VERR_NO_MORE_FILES; - return RTErrConvertFromWin32(iErr); - } - } - - /* - * Convert the filename to UTF-8. - */ - if (!pDir->pszName) - { - int rc = RTUtf16ToUtf8((PCRTUTF16)pDir->Data.cFileName, &pDir->pszName); - if (RT_FAILURE(rc)) - { - pDir->pszName = NULL; - return rc; - } - pDir->cchName = strlen(pDir->pszName); - } - - /* - * Check if we've got enough space to return the data. - */ - const char *pszName = pDir->pszName; - const size_t cchName = pDir->cchName; - const size_t cbRequired = RT_OFFSETOF(RTDIRENTRYEX, szName[1]) + cchName; - if (pcbDirEntry) - *pcbDirEntry = cbRequired; - if (cbRequired > cbDirEntry) - return VERR_BUFFER_OVERFLOW; - - /* - * Setup the returned data. - */ - pDir->fDataUnread = false; - pDirEntry->cbName = (uint16_t)cchName; - Assert(pDirEntry->cbName == cchName); - memcpy(pDirEntry->szName, pszName, cchName + 1); - if (pDir->Data.cAlternateFileName[0]) - { - /* copy and calc length */ - PCRTUTF16 pwszSrc = (PCRTUTF16)pDir->Data.cAlternateFileName; - PRTUTF16 pwszDst = pDirEntry->wszShortName; - uint32_t off = 0; - while (pwszSrc[off] && off < RT_ELEMENTS(pDirEntry->wszShortName) - 1U) - { - pwszDst[off] = pwszSrc[off]; - off++; - } - pDirEntry->cwcShortName = (uint16_t)off; - - /* zero the rest */ - do - pwszDst[off++] = '\0'; - while (off < RT_ELEMENTS(pDirEntry->wszShortName)); - } - else - { - memset(pDirEntry->wszShortName, 0, sizeof(pDirEntry->wszShortName)); - pDirEntry->cwcShortName = 0; - } - - pDirEntry->Info.cbObject = ((uint64_t)pDir->Data.nFileSizeHigh << 32) - | (uint64_t)pDir->Data.nFileSizeLow; - pDirEntry->Info.cbAllocated = pDirEntry->Info.cbObject; - - Assert(sizeof(uint64_t) == sizeof(pDir->Data.ftCreationTime)); - RTTimeSpecSetNtTime(&pDirEntry->Info.BirthTime, *(uint64_t *)&pDir->Data.ftCreationTime); - RTTimeSpecSetNtTime(&pDirEntry->Info.AccessTime, *(uint64_t *)&pDir->Data.ftLastAccessTime); - RTTimeSpecSetNtTime(&pDirEntry->Info.ModificationTime, *(uint64_t *)&pDir->Data.ftLastWriteTime); - pDirEntry->Info.ChangeTime = pDirEntry->Info.ModificationTime; - - pDirEntry->Info.Attr.fMode = rtFsModeFromDos((pDir->Data.dwFileAttributes << RTFS_DOS_SHIFT) & RTFS_DOS_MASK_NT, - pszName, cchName); - - /* - * Requested attributes (we cannot provide anything actually). - */ - switch (enmAdditionalAttribs) - { - case RTFSOBJATTRADD_EASIZE: - pDirEntry->Info.Attr.enmAdditional = RTFSOBJATTRADD_EASIZE; - pDirEntry->Info.Attr.u.EASize.cb = 0; - break; - - case RTFSOBJATTRADD_UNIX: - pDirEntry->Info.Attr.enmAdditional = RTFSOBJATTRADD_UNIX; - pDirEntry->Info.Attr.u.Unix.uid = ~0U; - pDirEntry->Info.Attr.u.Unix.gid = ~0U; - pDirEntry->Info.Attr.u.Unix.cHardlinks = 1; - pDirEntry->Info.Attr.u.Unix.INodeIdDevice = 0; /** @todo Use the volume serial number (see GetFileInformationByHandle). */ - pDirEntry->Info.Attr.u.Unix.INodeId = 0; /** @todo Use the fileid (see GetFileInformationByHandle). */ - pDirEntry->Info.Attr.u.Unix.fFlags = 0; - pDirEntry->Info.Attr.u.Unix.GenerationId = 0; - pDirEntry->Info.Attr.u.Unix.Device = 0; - break; - - case RTFSOBJATTRADD_NOTHING: - pDirEntry->Info.Attr.enmAdditional = RTFSOBJATTRADD_NOTHING; - break; - - case RTFSOBJATTRADD_UNIX_OWNER: - pDirEntry->Info.Attr.enmAdditional = RTFSOBJATTRADD_UNIX_OWNER; - pDirEntry->Info.Attr.u.UnixOwner.uid = ~0U; - pDirEntry->Info.Attr.u.UnixOwner.szName[0] = '\0'; /** @todo return something sensible here. */ - break; - - case RTFSOBJATTRADD_UNIX_GROUP: - pDirEntry->Info.Attr.enmAdditional = RTFSOBJATTRADD_UNIX_GROUP; - pDirEntry->Info.Attr.u.UnixGroup.gid = ~0U; - pDirEntry->Info.Attr.u.UnixGroup.szName[0] = '\0'; - break; - - default: - AssertMsgFailed(("Impossible!\n")); - return VERR_INTERNAL_ERROR; - } - - return VINF_SUCCESS; -} - - RTDECL(int) RTDirRename(const char *pszSrc, const char *pszDst, unsigned fRename) { /* |