fileio-posix.cpp revision a4e2866230f32cdd3fd786cc8a4fa8c471bd133b
/* $Id$ */
/** @file
* IPRT - File I/O, POSIX.
*/
/*
* 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_FILE
#include <errno.h>
#include <fcntl.h>
#ifdef _MSC_VER
# include <io.h>
# include <stdio.h>
#else
# include <unistd.h>
#endif
# include <io.h>
#endif
#ifdef RT_OS_L4
/* This is currently ifdef'ed out in the relevant L4 header file */
/* Same as `utimes', but takes an open file descriptor instead of a name. */
#endif
#ifdef RT_OS_SOLARIS
#endif
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** @def RT_DONT_CONVERT_FILENAMES
* Define this to pass UTF-8 unconverted to the kernel. */
#ifdef __DOXYGEN__
#define RT_DONT_CONVERT_FILENAMES 1
#endif
/** Default file permissions for newly created files. */
#else
# define RT_FILE_PERMISSION (00600)
#endif
{
/*
* Validate input.
*/
{
return VERR_INVALID_PARAMETER;
}
*pFile = NIL_RTFILE;
if (!VALID_PTR(pszFilename))
{
return VERR_INVALID_PARAMETER;
}
/*
* Merge forced open flags and validate them.
*/
if (RT_FAILURE(rc))
return rc;
#ifndef O_NONBLOCK
if (fOpen & RTFILE_O_NON_BLOCK)
{
return VERR_INVALID_PARAMETER;
}
#endif
/*
* Calculate open mode flags.
*/
int fOpenMode = 0;
#ifdef O_BINARY
#endif
#ifdef O_LARGEFILE
#endif
#ifdef O_NOINHERIT
if (!(fOpen & RTFILE_O_INHERIT))
fOpenMode |= O_NOINHERIT;
#endif
#ifdef O_NONBLOCK
if (fOpen & RTFILE_O_NON_BLOCK)
fOpenMode |= O_NONBLOCK;
#endif
#ifdef O_SYNC
if (fOpen & RTFILE_O_WRITE_THROUGH)
#endif
switch (fOpen & RTFILE_O_ACTION_MASK)
{
case RTFILE_O_OPEN: break;
case RTFILE_O_CREATE_REPLACE: fOpenMode |= O_CREAT | O_TRUNC; break; /** @todo replacing needs fixing, this is *not* a 1:1 mapping! */
}
if (fOpen & RTFILE_O_TRUNCATE)
switch (fOpen & RTFILE_O_ACCESS_MASK)
{
default:
return VERR_INVALID_PARAMETER;
}
/** @todo sharing! */
/*
*/
#ifdef RT_DONT_CONVERT_FILENAMES
#else
char *pszNativeFilename;
if (RT_FAILURE(rc))
return (rc);
#endif
if (fh >= 0)
{
/*
* Mark the file handle close on exec, unless inherit is specified.
*/
if ( !(fOpen & RTFILE_O_INHERIT)
#ifdef O_NOINHERIT
#endif
{
LogFlow(("RTFileOpen(%p:{%RTfile}, %p:{%s}, %#x): returns %Rrc\n",
return VINF_SUCCESS;
}
}
return RTErrConvertFromErrno(iErr);
}
{
return VINF_SUCCESS;
return RTErrConvertFromErrno(errno);
}
{
if ( uNative < 0
{
*pFile = NIL_RTFILE;
return VERR_INVALID_HANDLE;
}
return VINF_SUCCESS;
}
{
return (RTHCINTPTR)File;
}
{
char *pszNativeFilename;
if (RT_SUCCESS(rc))
{
if (unlink(pszNativeFilename) != 0)
}
return rc;
}
{
static const unsigned aSeekRecode[] =
{
};
/*
* Validate input.
*/
if (uMethod > RTFILE_SEEK_END)
{
return VERR_INVALID_PARAMETER;
}
/* check that within off_t range. */
{
AssertMsgFailed(("64-bit search not supported\n"));
return VERR_NOT_SUPPORTED;
}
if (offCurrent != ~0)
{
if (poffActual)
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
{
if (cbToRead <= 0)
return VINF_SUCCESS;
/*
* Attempt read.
*/
if (cbRead >= 0)
{
if (pcbRead)
/* caller can handle partial read. */
else
{
/* Caller expects all to be read. */
{
if (cbReadPart <= 0)
{
if (cbReadPart == 0)
return VERR_EOF;
return RTErrConvertFromErrno(errno);
}
cbRead += cbReadPart;
}
}
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
{
if (cbToWrite <= 0)
return VINF_SUCCESS;
/*
* Attempt write.
*/
if (cbWritten >= 0)
{
if (pcbWritten)
/* caller can handle partial write. */
*pcbWritten = cbWritten;
else
{
/* Caller expects all to be write. */
{
if (cbWrittenPart <= 0)
return RTErrConvertFromErrno(errno);
}
}
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
{
/*
* Validate offset.
*/
&& (cbSize >> 32) != 0)
{
return VERR_NOT_SUPPORTED;
}
#if defined(_MSC_VER) || (defined(RT_OS_OS2) && (!defined(__INNOTEK_LIBC__) || __INNOTEK_LIBC__ < 0x006))
#else
/* This relies on a non-standard feature of FreeBSD, Linux, and OS/2
* LIBC v0.6 and higher. (SuS doesn't define ftruncate() and size bigger
* than the file.)
*/
#endif
return VINF_SUCCESS;
return RTErrConvertFromErrno(errno);
}
{
{
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
/**
* Determine the maximum file size.
*
* @returns IPRT status code.
* @param File Handle to the file.
* @param pcbMax Where to store the max file size.
* @see RTFileGetMaxSize.
*/
{
/*
* Save the current location
*/
if (RT_FAILURE(rc))
return rc;
/*
* Perform a binary search for the max file size.
*/
/** @todo Unfortunately this does not work for certain file system types,
* for instance cifs mounts. Even worse, statvfs.f_fsid returns 0 for such
* file systems. */
//uint64_t offHigh = INT64_MAX;
for (;;)
{
if (cbInterval == 0)
{
if (pcbMax)
}
if (RT_FAILURE(rc))
else
}
}
{
if (File != NIL_RTFILE)
{
if (fFlags >= 0)
return true;
}
return false;
}
{
return RTErrConvertFromErrno(errno);
return VINF_SUCCESS;
}
{
if (piRet)
}
RTR3DECL(int) RTFileQueryInfo(RTFILE File, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
{
/*
* Validate input.
*/
if (File == NIL_RTFILE)
{
return VERR_INVALID_PARAMETER;
}
if (!pObjInfo)
{
return VERR_INVALID_PARAMETER;
}
{
return VERR_INVALID_PARAMETER;
}
/*
* Query file info.
*/
{
return rc;
}
/*
* Setup the returned data.
*/
/*
* Requested attributes (we cannot provide anything actually).
*/
switch (enmAdditionalAttribs)
{
case RTFSOBJATTRADD_EASIZE:
break;
case RTFSOBJATTRADD_NOTHING:
case RTFSOBJATTRADD_UNIX:
/* done */
break;
default:
AssertMsgFailed(("Impossible!\n"));
return VERR_INTERNAL_ERROR;
}
return VINF_SUCCESS;
}
{
/*
* We can only set AccessTime and ModificationTime, so if neither
* are specified we can return immediately.
*/
if (!pAccessTime && !pModificationTime)
return VINF_SUCCESS;
/*
* Convert the input to timeval, getting the missing one if necessary,
* and call the API which does the change.
*/
if (pAccessTime && pModificationTime)
{
}
else
{
if (RT_FAILURE(rc))
return rc;
RTTimeSpecGetTimeval(pModificationTime ? pModificationTime : &ObjInfo.ModificationTime, &aTimevals[1]);
}
{
return rc;
}
return VINF_SUCCESS;
}
{
/*
* Normalize the mode and call the API.
*/
if (!rtFsModeIsValid(fMode))
return VERR_INVALID_PARAMETER;
{
return rc;
}
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
AssertMsgReturn(!(fRename & ~RTPATHRENAME_FLAGS_REPLACE), ("%#x\n", fRename), VERR_INVALID_PARAMETER);
/*
* Take common cause with RTPathRename.
*/
LogFlow(("RTDirRename(%p:{%s}, %p:{%s}, %#x): returns %Rrc\n",
return rc;
}