dir-posix.cpp revision 0a4172139798eb6d0b8bb15a585c190f94708cdb
/* $Id$ */
/** @file
* IPRT - Directory manipulation, POSIX.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_DIR
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#if !defined(RT_OS_SOLARIS)
# define HAVE_DIRENT_D_TYPE 1
#endif
{
bool fRc = false;
char const *pszNativePath;
if (RT_SUCCESS(rc))
{
struct stat s;
}
return fRc;
}
{
int rc;
{
char const *pszNativePath;
if (RT_SUCCESS(rc))
{
{
#ifdef RT_OS_SOLARIS
/*
* during the Nevada development cycle. We've observed:
* - Build 111b (2009.06) returns EACCES.
* - Build ca. 70-80 returns ENOSYS.
*/
{
}
#endif
}
}
}
else
{
}
return rc;
}
{
char const *pszNativePath;
if (RT_SUCCESS(rc))
{
if (rmdir(pszNativePath))
}
return rc;
}
{
/*
* Linux: The fsync() man page hints at this being required for ensuring
* consistency between directory and file in case of a crash.
*
* Solaris: No mentioned is made of directories on the fsync man page.
* While rename+fsync will do what we want on ZFS, the code needs more
* careful studying wrt whether the directory entry of a new file is
* implicitly synced when the file is synced (it's very likely for ZFS).
*
* FreeBSD: The FFS fsync code seems to flush the directory entry as well
* in some cases. Don't know exactly what's up with rename, but from the
* look of things fsync(dir) should work.
*/
int rc;
#ifdef O_DIRECTORY
#else
#endif
if (fd >= 0)
{
rc = VINF_SUCCESS;
else
}
else
return rc;
}
{
/*
* Convert to a native path and try opendir.
*/
char const *pszNativePath;
if (RT_SUCCESS(rc))
{
{
/*
* Init data.
*/
pDir->fDataUnread = false;
}
else
}
return rc;
}
{
/*
* Validate input.
*/
if (!pDir)
return VERR_INVALID_PARAMETER;
{
return VERR_INVALID_PARAMETER;
}
/*
* Close the handle.
*/
int rc = VINF_SUCCESS;
{
}
return rc;
}
/**
* Ensure that there is unread data in the buffer
* and that there is a converted filename hanging around.
*
* @returns IPRT status code.
* @param pDir the open directory. Fully validated.
*/
{
/** @todo try avoid the rematching on buffer overflow errors. */
for (;;)
{
/*
* Fetch data?
*/
if (!pDir->fDataUnread)
{
if (rc)
{
/** @todo Consider translating ENOENT (The current
* position of the directory stream is invalid)
* differently. */
return rc;
}
if (!pResult)
return VERR_NO_MORE_FILES;
}
/*
* Convert the filename to UTF-8.
*/
{
if (RT_FAILURE(rc))
{
return rc;
}
}
break;
pDir->fDataUnread = false;
}
pDir->fDataUnread = true;
return VINF_SUCCESS;
}
#ifdef HAVE_DIRENT_D_TYPE
/**
* Converts the d_type field to IPRT directory entry type.
*
* @returns IPRT directory entry type.
* @param Unix
*/
{
switch (iType)
{
case DT_UNKNOWN: return RTDIRENTRYTYPE_UNKNOWN;
case DT_FIFO: return RTDIRENTRYTYPE_FIFO;
case DT_CHR: return RTDIRENTRYTYPE_DEV_CHAR;
case DT_DIR: return RTDIRENTRYTYPE_DIRECTORY;
case DT_BLK: return RTDIRENTRYTYPE_DEV_BLOCK;
case DT_REG: return RTDIRENTRYTYPE_FILE;
case DT_LNK: return RTDIRENTRYTYPE_SYMLINK;
case DT_SOCK: return RTDIRENTRYTYPE_SOCKET;
case DT_WHT: return RTDIRENTRYTYPE_WHITEOUT;
default:
return RTDIRENTRYTYPE_UNKNOWN;
}
}
#endif /*HAVE_DIRENT_D_TYPE */
{
/*
* Validate and digest input.
*/
if (!rtDirValidHandle(pDir))
return VERR_INVALID_PARAMETER;
if (pcbDirEntry)
{
}
/*
*/
if (RT_SUCCESS(rc))
{
/*
* Check if we've got enough space to return the data.
*/
if (pcbDirEntry)
if (cbRequired <= cbDirEntry)
{
/*
* Setup the returned data.
*/
#ifdef HAVE_DIRENT_D_TYPE
#else
#endif
/* free cached data */
pDir->fDataUnread = false;
}
else
}
LogFlow(("RTDirRead(%p:{%s}, %p:{%s}, %p:{%u}): returns %Rrc\n",
return rc;
}
/**
* Fills dummy info into the info structure.
* This function is called if we cannot stat the file.
*
* @param pInfo The struct in question.
* @param
*/
{
pInfo->cbAllocated = 0;
switch (enmType)
{
default:
}
}
RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags)
{
/*
* Validate and digest input.
*/
if (!rtDirValidHandle(pDir))
return VERR_INVALID_PARAMETER;
("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs),
if (pcbDirEntry)
{
}
/*
*/
if (RT_SUCCESS(rc))
{
/*
* Check if we've got enough space to return the data.
*/
if (pcbDirEntry)
if (cbRequired <= cbDirEntry)
{
/*
* Setup the returned data.
*/
pDirEntry->cwcShortName = 0;
pDirEntry->wszShortName[0] = 0;
/* get the info data */
if (pszNamePath)
{
}
else
rc = VERR_NO_MEMORY;
if (RT_FAILURE(rc))
{
#ifdef HAVE_DIRENT_D_TYPE
#else
#endif
}
/* free cached data */
pDir->fDataUnread = false;
}
else
}
return rc;
}
{
/*
* Validate input.
*/
AssertMsgReturn(!(fRename & ~RTPATHRENAME_FLAGS_REPLACE), ("%#x\n", fRename), VERR_INVALID_PARAMETER);
/*
* Take common cause with RTPathRename.
*/
LogFlow(("RTDirRename(%p:{%s}, %p:{%s}): returns %Rrc\n",
return rc;
}