fs.cpp revision 36004000e897ff86c5e7a4d5f549d40eb028cc92
/* $Id$ */
/** @file
* IPRT - File System.
*/
/*
* 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 *
*******************************************************************************/
#ifndef RT_OS_WINDOWS
# define RTTIME_INCL_TIMESPEC
#endif
/**
* Converts dos-style attributes to Unix attributes.
*
* @returns
* @param fMode The mode mask containing dos-style attibutes only.
* @param pszName The filename which this applies to (exe check).
* @param cbName The length of that filename. (optional, set 0)
*/
{
/* everything is readable. */
if (fMode & RTFS_DOS_DIRECTORY)
/* directories are executable. */
else
{
fMode |= RTFS_TYPE_FILE;
{
/* check for executable extension. */
char szExt[4];
)
}
}
/* writable? */
if (!(fMode & RTFS_DOS_READONLY))
return fMode;
}
/**
* Converts Unix attributes to Dos-style attributes.
*
* @returns File mode mask.
* @param fMode The mode mask containing dos-style attibutes only.
* @param pszName The filename which this applies to (hidden check).
* @param cbName The length of that filename. (optional, set 0)
*/
{
fMode &= RTFS_UNIX_MASK;
if (RTFS_IS_DIRECTORY(fMode))
if (!(fMode & RTFS_DOS_MASK))
{
fMode |= RTFS_DOS_HIDDEN;
}
return fMode;
}
/**
* Normalizes the give mode mask.
*
* It will create the missing unix or dos mask from the other (one
* of them is required by all APIs), and guess the file type if that's
* missing.
*
* @returns Normalized file mode.
* @param fMode The mode mask that may contain a partial/incomplete mask.
* @param pszName The filename which this applies to (exe check).
* @param cbName The length of that filename. (optional, set 0)
*/
{
if (!(fMode & RTFS_UNIX_MASK))
else if (!(fMode & RTFS_DOS_MASK))
else if (!(fMode & RTFS_TYPE_MASK))
else if (RTFS_IS_DIRECTORY(fMode))
return fMode;
}
/**
* Checks if the file mode is valid or not.
*
* @return true if valid.
* @return false if invalid, done bitching.
* @param fMode The file mode.
*/
{
("%RTfmode\n", fMode), false);
("%RTfmode\n", fMode), false);
/** @todo more checks! */
return true;
}
/**
* Checks if the file mode is valid as a permission mask or not.
*
* @return true if valid.
* @return false if invalid, done bitching.
* @param fMode The file mode.
*/
{
("%RTfmode\n", fMode), false);
/** @todo more checks! */
return true;
}
#ifndef RT_OS_WINDOWS
/**
* Internal worker function which setups RTFSOBJINFO based on a UNIX stat struct.
*
* @param pObjInfo The file system object info structure to setup.
* @param pStat The stat structure to use.
* @param cbName The length of that filename. (optional, set 0)
*/
void rtFsConvertStatToObjInfo(PRTFSOBJINFO pObjInfo, const struct stat *pStat, const char *pszName, unsigned cbName)
{
#ifdef HAVE_STAT_NSEC
RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->AccessTime, pStat->st_atime), pStat->st_atimensec);
RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->ModificationTime, pStat->st_mtime), pStat->st_mtimensec);
RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->ChangeTime, pStat->st_ctime), pStat->st_ctimensec);
#ifdef HAVE_STAT_BIRTHTIME
RTTimeSpecAddNano(RTTimeSpecSetSeconds(&pObjInfo->BirthTime, pStat->st_birthtime), pStat->st_birthtimensec);
#endif
#elif defined(HAVE_STAT_TIMESPEC_BRIEF)
# ifdef HAVE_STAT_BIRTHTIME
# endif
#elif defined(HAVE_STAT_TIMESPEC)
# ifdef HAVE_STAT_BIRTHTIME
# endif
#else /* just the normal stuff */
# ifdef HAVE_STAT_BIRTHTIME
# endif
#endif
#ifndef HAVE_STAT_BIRTHTIME
#endif
/* the file mode */
#ifdef S_ISTXT
#else
#error "S_ISVTX / S_ISTXT isn't defined"
#endif
#ifdef S_IFWHT
#endif
/* additional unix attribs */
#ifdef HAVE_STAT_FLAGS
#else
#endif
#ifdef HAVE_STAT_GEN
#else
#endif
}
#endif /* !RT_OS_WINDOWS */