dir-win.cpp revision c4d14c17e737e0456e9db8d937a9a6475fffd0a3
/* $Id$ */
/** @file
* IPRT - Directory, win32.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_DIR
#include <Windows.h>
#include <io.h>
{
/*
* Validate the file mode.
*/
int rc;
{
/*
* Convert to UTF-16.
*/
if (RT_SUCCESS(rc))
{
/*
* Create the directory.
*/
rc = VINF_SUCCESS;
else
/*
* Turn off indexing of directory through Windows Indexing Service
*/
if (RT_SUCCESS(rc))
{
rc = VINF_SUCCESS;
else
}
}
}
else
{
}
return rc;
}
{
/*
* Convert to UTF-16.
*/
if (RT_SUCCESS(rc))
{
/*
* Remove the directory.
*/
rc = VINF_SUCCESS;
else
}
return rc;
}
{
/*
* 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.
*/
const char *pszExpr;
{
}
else
{
pszExpr = "*";
cchExpr = sizeof("*");
}
return VERR_FILENAME_TOO_LONG;
/*
* Attempt opening the search.
*/
int rc = VINF_SUCCESS;
#ifndef RT_DONT_CONVERT_FILENAMES
if (RT_SUCCESS(rc))
{
#else
#endif
pDir->fDataUnread = true;
/* theoretical case of an empty directory. */
else if (GetLastError() == ERROR_NO_MORE_FILES)
pDir->fDataUnread = false;
else
#ifndef RT_DONT_CONVERT_FILENAMES
}
#endif
return rc;
}
{
/*
* Validate input.
*/
if (!pDir)
return VERR_INVALID_PARAMETER;
{
return VERR_INVALID_PARAMETER;
}
/*
* Close the handle.
*/
{
}
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
{
return VERR_INVALID_PARAMETER;
}
if (!pDirEntry)
{
return VERR_INVALID_PARAMETER;
}
if (pcbDirEntry)
{
{
AssertMsgFailed(("Invalid *pcbDirEntry=%d (min %d)\n", *pcbDirEntry, RT_OFFSETOF(RTDIRENTRY, szName[2])));
return VERR_INVALID_PARAMETER;
}
}
/*
* Fetch data?
*/
if (!pDir->fDataUnread)
{
#ifdef RT_DONT_CONVERT_FILENAMES
#else
#endif
if (!fRc)
{
int iErr = GetLastError();
return VERR_NO_MORE_FILES;
return RTErrConvertFromWin32(iErr);
}
}
#ifndef RT_DONT_CONVERT_FILENAMES
/*
* Convert the filename to UTF-8.
*/
{
if (RT_FAILURE(rc))
{
return rc;
}
}
#endif
/*
* Check if we've got enough space to return the data.
*/
#ifdef RT_DONT_CONVERT_FILENAMES
#else
#endif
if (pcbDirEntry)
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). */
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.
*/
{
return VERR_INVALID_PARAMETER;
}
if (!pDirEntry)
{
return VERR_INVALID_PARAMETER;
}
{
return VERR_INVALID_PARAMETER;
}
if (pcbDirEntry)
{
{
AssertMsgFailed(("Invalid *pcbDirEntry=%d (min %d)\n", *pcbDirEntry, RT_OFFSETOF(RTDIRENTRYEX, szName[2])));
return VERR_INVALID_PARAMETER;
}
}
/*
* Fetch data?
*/
if (!pDir->fDataUnread)
{
#ifdef RT_DONT_CONVERT_FILENAMES
#else
#endif
if (!fRc)
{
int iErr = GetLastError();
return VERR_NO_MORE_FILES;
return RTErrConvertFromWin32(iErr);
}
}
#ifndef RT_DONT_CONVERT_FILENAMES
/*
* Convert the filename to UTF-8.
*/
{
if (RT_FAILURE(rc))
{
return rc;
}
}
#endif
/*
* Check if we've got enough space to return the data.
*/
#ifdef RT_DONT_CONVERT_FILENAMES
#else
#endif
if (pcbDirEntry)
if (cbRequired > cbDirEntry)
return VERR_BUFFER_OVERFLOW;
/*
* Setup the returned data.
*/
pDir->fDataUnread = false;
#ifndef RT_DONT_CONVERT_FILENAMES /* this ain't nice since the whole point of this define is not to drag in conversion... */
{
/* copy and calc length */
while (*pwszSrc)
/* zero the rest */
*pwszDst++ = '\0';
}
else
#endif
{
pDirEntry->cwcShortName = 0;
}
pDirEntry->Info.Attr.fMode = rtFsModeFromDos((pDir->Data.dwFileAttributes << RTFS_DOS_SHIFT) & RTFS_DOS_MASK_NT,
/*
* Requested attributes (we cannot provide anything actually).
*/
switch (enmAdditionalAttribs)
{
case RTFSOBJATTRADD_EASIZE:
break;
case RTFSOBJATTRADD_UNIX:
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). */
break;
case RTFSOBJATTRADD_NOTHING:
break;
default:
AssertMsgFailed(("Impossible!\n"));
return VERR_INTERNAL_ERROR;
}
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
AssertMsgReturn(!(fRename & ~RTPATHRENAME_FLAGS_REPLACE), ("%#x\n", fRename), VERR_INVALID_PARAMETER);
/*
* Call the worker.
*/
LogFlow(("RTDirRename(%p:{%s}, %p:{%s}, %#x): returns %Rrc\n", pszSrc, pszSrc, pszDst, pszDst, fRename, rc));
return rc;
}