VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/fileio2-posix.cpp@ 37596

Last change on this file since 37596 was 37596, checked in by vboxsync, 13 years ago

*: RTFILE becomes a pointer, RTFileOpen++ expands it's flags paramter from uint32_t to uint64_t.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1/* $Id: fileio2-posix.cpp 37596 2011-06-22 19:30:06Z vboxsync $ */
2/** @file
3 * IPRT - File I/O, POSIX, Part 2.
4 */
5
6/*
7 * Copyright (C) 2006-2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#define LOG_GROUP RTLOGGROUP_FILE
32
33#include <errno.h>
34#include <sys/stat.h>
35#include <sys/types.h>
36#ifdef _MSC_VER
37# include <io.h>
38# include <stdio.h>
39#else
40# include <unistd.h>
41# include <sys/time.h>
42#endif
43#ifdef RT_OS_LINUX
44# include <sys/file.h>
45#endif
46#if defined(RT_OS_OS2) && (!defined(__INNOTEK_LIBC__) || __INNOTEK_LIBC__ < 0x006)
47# include <io.h>
48#endif
49#ifdef RT_OS_L4
50/* This is currently ifdef'ed out in the relevant L4 header file */
51/* Same as `utimes', but takes an open file descriptor instead of a name. */
52extern int futimes(int __fd, __const struct timeval __tvp[2]) __THROW;
53#endif
54
55#ifdef RT_OS_SOLARIS
56# define futimes(filedes, timeval) futimesat(filedes, NULL, timeval)
57#endif
58
59#include <iprt/file.h>
60#include <iprt/path.h>
61#include <iprt/assert.h>
62#include <iprt/string.h>
63#include <iprt/err.h>
64#include <iprt/log.h>
65#include "internal/file.h"
66#include "internal/fs.h"
67#include "internal/path.h"
68
69
70
71RTR3DECL(int) RTFileQueryInfo(RTFILE hFile, PRTFSOBJINFO pObjInfo, RTFSOBJATTRADD enmAdditionalAttribs)
72{
73 /*
74 * Validate input.
75 */
76 AssertReturn(hFile != NIL_RTFILE, VERR_INVALID_PARAMETER);
77 AssertPtrReturn(pObjInfo, VERR_INVALID_PARAMETER);
78 if ( enmAdditionalAttribs < RTFSOBJATTRADD_NOTHING
79 || enmAdditionalAttribs > RTFSOBJATTRADD_LAST)
80 {
81 AssertMsgFailed(("Invalid enmAdditionalAttribs=%p\n", enmAdditionalAttribs));
82 return VERR_INVALID_PARAMETER;
83 }
84
85 /*
86 * Query file info.
87 */
88 struct stat Stat;
89 if (fstat(RTFileToNative(hFile), &Stat))
90 {
91 int rc = RTErrConvertFromErrno(errno);
92 Log(("RTFileQueryInfo(%RTfile,,%d): returns %Rrc\n", hFile, enmAdditionalAttribs, rc));
93 return rc;
94 }
95
96 /*
97 * Setup the returned data.
98 */
99 rtFsConvertStatToObjInfo(pObjInfo, &Stat, NULL, 0);
100
101 /*
102 * Requested attributes (we cannot provide anything actually).
103 */
104 switch (enmAdditionalAttribs)
105 {
106 case RTFSOBJATTRADD_NOTHING:
107 case RTFSOBJATTRADD_UNIX:
108 /* done */
109 break;
110
111 case RTFSOBJATTRADD_UNIX_OWNER:
112 rtFsObjInfoAttrSetUnixOwner(pObjInfo, Stat.st_uid);
113 break;
114
115 case RTFSOBJATTRADD_UNIX_GROUP:
116 rtFsObjInfoAttrSetUnixGroup(pObjInfo, Stat.st_gid);
117 break;
118
119 case RTFSOBJATTRADD_EASIZE:
120 pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_EASIZE;
121 pObjInfo->Attr.u.EASize.cb = 0;
122 break;
123
124 default:
125 AssertMsgFailed(("Impossible!\n"));
126 return VERR_INTERNAL_ERROR;
127 }
128
129 LogFlow(("RTFileQueryInfo(%RTfile,,%d): returns VINF_SUCCESS\n", hFile, enmAdditionalAttribs));
130 return VINF_SUCCESS;
131}
132
133
134RTR3DECL(int) RTFileSetTimes(RTFILE hFile, PCRTTIMESPEC pAccessTime, PCRTTIMESPEC pModificationTime,
135 PCRTTIMESPEC pChangeTime, PCRTTIMESPEC pBirthTime)
136{
137 /*
138 * We can only set AccessTime and ModificationTime, so if neither
139 * are specified we can return immediately.
140 */
141 if (!pAccessTime && !pModificationTime)
142 return VINF_SUCCESS;
143
144 /*
145 * Convert the input to timeval, getting the missing one if necessary,
146 * and call the API which does the change.
147 */
148 struct timeval aTimevals[2];
149 if (pAccessTime && pModificationTime)
150 {
151 RTTimeSpecGetTimeval(pAccessTime, &aTimevals[0]);
152 RTTimeSpecGetTimeval(pModificationTime, &aTimevals[1]);
153 }
154 else
155 {
156 RTFSOBJINFO ObjInfo;
157 int rc = RTFileQueryInfo(hFile, &ObjInfo, RTFSOBJATTRADD_UNIX);
158 if (RT_FAILURE(rc))
159 return rc;
160 RTTimeSpecGetTimeval(pAccessTime ? pAccessTime : &ObjInfo.AccessTime, &aTimevals[0]);
161 RTTimeSpecGetTimeval(pModificationTime ? pModificationTime : &ObjInfo.ModificationTime, &aTimevals[1]);
162 }
163
164 if (futimes(RTFileToNative(hFile), aTimevals))
165 {
166 int rc = RTErrConvertFromErrno(errno);
167 Log(("RTFileSetTimes(%RTfile,%p,%p,,): returns %Rrc\n", hFile, pAccessTime, pModificationTime, rc));
168 return rc;
169 }
170 return VINF_SUCCESS;
171}
172
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette