stat.c revision 36b60d359f30acb8837a2d801b582ee5aa2c24f1
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* Get file attribute information through a file name or a file descriptor.
*/
#include <sys/isa_defs.h>
#include <sys/sysmacros.h>
#include <sys/pathname.h>
/*
* =========================================================
* "ROUND_TO_USEC" workaround for missing syscall interface.
* =========================================================
*
* Solaris does not provide interface to set the timestamp of a file in
* nanosecond granularity. POSIX.1-2008 specifies such syscall interface:
* futimens(), utimensat(). The modern filesystems like ZFS support
* nanosecond granular timestamps.
*
* Before the workaround was implemented:
*
* The timestamps were read with the nanosecond granularity but written
* only with the microsecond granularity. If the timestamp was copied by
* reading it with nanosecond granularity and by writing with the microsecond
* granularity, the nanosecond part of the timestamp was zero.
*
* Example: such copying of the timestamp is done by touch(1) if the '-r'
* option is used. 'touch -r' is used by build procuderes based on make(1S).
* The missing nanosecond part was breaking build procuderes and resulted in
* hard to diagnose build failures.
*
* After the workaround is implemented:
*
* The timestamps are in the kernel still stored with the nanosecond
* granularity. However, all the 'stat' syscalls now clear the nanosecond part
* in the timestamp values returned by these syscalls.
*
* The "ROUND_TO_USEC" workaround should be removed when the new syscall
* interface is available.
*/
int stat_force_usec_granularity = 1;
#define ROUND_TO_USEC(tms) \
{ \
}
/*
* Get the vp to be stated and the cred to be used for the call
* to VOP_GETATTR
*/
/*
* nmflag has the following values
*
* 1 - Always do lookup. i.e. stat, lstat.
* 2 - Name is optional i.e. fstatat
* 0 - Don't lookup name, vp is in file_p. i.e. fstat
*
*/
static int
{
int error;
int estale_retry = 0;
/*
* Only return EFAULT for fstatat when fd == AT_FDCWD && name == NULL
*/
} else
return (EFAULT);
} else {
char startchar;
return (EFAULT);
} else {
startchar = '\0';
}
return (EBADF);
}
} else {
}
}
if (audit_active)
goto lookup;
return (error);
}
} else {
}
return (0);
}
/*
* Native syscall interfaces:
*
* N-bit kernel, N-bit applications, N-bit file offsets
*/
int
{
}
int
{
}
/*
* fstat can and should be fast, do an inline implementation here.
*/
{ \
int error; \
\
if (audit_active) \
audit_setfsat_path(1); \
if (error) \
return (0); \
}
int
{
}
int
{
}
#if defined(__i386) || defined(__i386_COMPAT)
/*
* Handle all the "extended" stat operations in the same way;
* validate the version, then call the real handler.
*/
#endif /* __i386 || __i386_COMPAT */
#if defined(__i386)
/*
* Syscalls for i386 applications that issue {,l,f}xstat() directly
*/
int
{
}
int
{
}
int
{
}
#endif /* __i386 */
/*
* Common code for stat(), lstat(), and fstat().
* (32-bit kernel, 32-bit applications, 32-bit files)
* (64-bit kernel, 64-bit applications, 64-bit files)
*/
static int
{
int error;
return (error);
/* Workaround - see beginning of the file for the details */
if (stat_force_usec_granularity) {
}
#ifdef _ILP32
/*
* (32-bit kernel, 32-bit applications, 32-bit files)
* NOTE: 32-bit kernel maintains a 64-bit unsigend va_size.
*
* st_size of devices (VBLK and VCHR special files) is a special case.
* POSIX does not define size behavior for special files, so the
* following Solaris specific behavior is not a violation. Solaris
* returns the size of the device.
*
* For compatibility with 32-bit programs which happen to do stat() on
* a (mknod) bigger than 2GB we suppress the large file EOVERFLOW and
* instead we return the value MAXOFF32_T (LONG_MAX).
*
* 32-bit applications that care about the size of devices should be
* built 64-bit or use a large file interface (lfcompile(5) or lf64(5)).
*/
/* OVERFLOW | UNKNOWN_SIZE */
}
#endif /* _ILP32 */
return (EOVERFLOW);
}
return (EFAULT);
return (0);
}
static int
{
int error;
int link_follow;
int estale_retry = 0;
out:
if (error != 0) {
goto lookup;
}
return (0);
}
#if defined(_SYSCALL32_IMPL)
/*
* 64-bit kernel, 32-bit applications, 32-bit file offsets
*/
int
{
}
int
{
}
int
{
}
int
{
}
#if defined(__i386_COMPAT)
/*
* Syscalls for i386 applications that issue {,l,f}xstat() directly
*/
int
{
}
int
{
}
int
{
}
#endif /* __i386_COMPAT */
static int
{
int error;
return (error);
/* Workaround - see beginning of the file for the details */
if (stat_force_usec_granularity) {
}
/* devices are a special case, see comments in cstat */
/* OVERFLOW | UNKNOWN_SIZE */
}
/* check for large values */
return (EOVERFLOW);
}
return (EFAULT);
return (0);
}
static int
{
int error;
int link_follow;
int estale_retry = 0;
out:
if (error != 0) {
goto lookup;
}
return (0);
}
#endif /* _SYSCALL32_IMPL */
#if defined(_ILP32)
/*
* 32-bit kernel, 32-bit applications, 64-bit file offsets.
*
* These routines are implemented differently on 64-bit kernels.
*/
int
{
}
int
{
}
int
{
}
int
{
}
static int
{
int error;
return (error);
/* Workaround - see beginning of the file for the details */
if (stat_force_usec_granularity) {
}
}
return (EFAULT);
return (0);
}
static int
{
int error;
int link_follow;
int estale_retry = 0;
out:
if (error != 0) {
goto lookup;
}
return (0);
}
#endif /* _ILP32 */
#if defined(_SYSCALL32_IMPL)
/*
* 64-bit kernel, 32-bit applications, 64-bit file offsets.
*
* We'd really like to call the "native" stat calls for these ones,
* but the problem is that the 64-bit ABI defines the 'stat64' structure
* differently from the way the 32-bit ABI defines it.
*/
static int cstatat64_32(int, char *, int, struct stat64_32 *, int, int);
int
{
}
int
{
}
int
{
}
int
{
}
static int
{
int error;
return (error);
/* Workaround - see beginning of the file for the details */
if (stat_force_usec_granularity) {
}
return (EOVERFLOW);
}
return (EFAULT);
return (0);
}
static int
{
int error;
int link_follow;
int estale_retry = 0;
out:
if (error != 0) {
goto lookup;
}
return (0);
}
#endif /* _SYSCALL32_IMPL */