c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * IPRT - File I/O, POSIX, Part 2.
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync * Copyright (C) 2006-2012 Oracle Corporation
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * available from http://www.virtualbox.org. This file is free software;
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * General Public License (GPL) as published by the Free Software
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * The contents of this file may alternatively be used under the terms
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * of the Common Development and Distribution License Version 1.0
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * VirtualBox OSE distribution, in which case the provisions of the
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * CDDL are applicable instead of those of the GPL.
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * You may elect to license modified versions of this file under the
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * terms and conditions of either the GPL or the CDDL or both.
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync/*******************************************************************************
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync* Header Files *
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync*******************************************************************************/
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync#if defined(RT_OS_OS2) && (!defined(__INNOTEK_LIBC__) || __INNOTEK_LIBC__ < 0x006)
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync# define futimes(filedes, timeval) futimesat(filedes, NULL, timeval)
dc0a54940789f994c84390cb4a9f03da0b492285vboxsyncRTR3DECL(int) RTFileQueryInfo(RTFILE hFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * Validate input.
dc0a54940789f994c84390cb4a9f03da0b492285vboxsync AssertReturn(hFile != NIL_RTFILE, VERR_INVALID_PARAMETER);
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync AssertMsgFailed(("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs));
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * Query file info.
dc0a54940789f994c84390cb4a9f03da0b492285vboxsync Log(("RTFileQueryInfo(%RTfile,,%d): returns %Rrc\n", hFile, enmAdditionalAttribs, rc));
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * Setup the returned data.
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync rtFsConvertStatToObjInfo(pObjInfo, &Stat, NULL, 0);
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * Requested attributes (we cannot provide anything actually).
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync rtFsObjInfoAttrSetUnixOwner(pObjInfo, Stat.st_uid);
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync rtFsObjInfoAttrSetUnixGroup(pObjInfo, Stat.st_gid);
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_EASIZE;
dc0a54940789f994c84390cb4a9f03da0b492285vboxsync LogFlow(("RTFileQueryInfo(%RTfile,,%d): returns VINF_SUCCESS\n", hFile, enmAdditionalAttribs));
dc0a54940789f994c84390cb4a9f03da0b492285vboxsyncRTR3DECL(int) RTFileSetTimes(RTFILE hFile, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * We can only set AccessTime and ModificationTime, so if neither
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * are specified we can return immediately.
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync memcpy(&aTimespecs[0], pAccessTime, sizeof(struct timespec));
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync memcpy(&aTimespecs[1], pModificationTime, sizeof(struct timespec));
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync int rc = RTFileQueryInfo(hFile, &ObjInfo, RTFSOBJATTRADD_UNIX);
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync memcpy(&aTimespecs[0], pAccessTime ? pAccessTime : &ObjInfo.AccessTime, sizeof(struct timespec));
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync memcpy(&aTimespecs[1], pModificationTime ? pModificationTime : &ObjInfo.ModificationTime, sizeof(struct timespec));
9fc464631dc4a68fbb5eb6419d61fbe91b6b16bdvboxsync Log(("RTFileSetTimes(%RTfile,%p,%p,,): returns %Rrc\n", hFile, pAccessTime, pModificationTime, rc));
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * Convert the input to timeval, getting the missing one if necessary,
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync * and call the API which does the change.
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync RTTimeSpecGetTimeval(pModificationTime, &aTimevals[1]);
dc0a54940789f994c84390cb4a9f03da0b492285vboxsync int rc = RTFileQueryInfo(hFile, &ObjInfo, RTFSOBJATTRADD_UNIX);
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync RTTimeSpecGetTimeval(pAccessTime ? pAccessTime : &ObjInfo.AccessTime, &aTimevals[0]);
c1bf14b7bd52ba68e91e056d3f054c053f944164vboxsync RTTimeSpecGetTimeval(pModificationTime ? pModificationTime : &ObjInfo.ModificationTime, &aTimevals[1]);
7f559fbdfc27f13c8448645ace787c4c1ddefd13vboxsync /* XXX this falls back to utimes("/proc/self/fd/...",...) for older kernels/glibcs and this
7f559fbdfc27f13c8448645ace787c4c1ddefd13vboxsync * will not work for hardened builds where this directory is owned by root.root and mode 0500 */
dc0a54940789f994c84390cb4a9f03da0b492285vboxsync Log(("RTFileSetTimes(%RTfile,%p,%p,,): returns %Rrc\n", hFile, pAccessTime, pModificationTime, rc));