xref: /titanic_50/usr/src/uts/common/syscall/stat.c (revision 8fd04b8338ed5093ec2d1e668fa620b7de44c177)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5dd29fa4aSprabahar  * Common Development and Distribution License (the "License").
6dd29fa4aSprabahar  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*8fd04b83SRoger A. Faulkner 
227c478bd9Sstevel@tonic-gate /*
23*8fd04b83SRoger A. Faulkner  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
327c478bd9Sstevel@tonic-gate  * under license from the Regents of the University of California.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Get file attribute information through a file name or a file descriptor.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/param.h>
407c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
417c478bd9Sstevel@tonic-gate #include <sys/types.h>
427c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
437c478bd9Sstevel@tonic-gate #include <sys/cred.h>
447c478bd9Sstevel@tonic-gate #include <sys/systm.h>
457c478bd9Sstevel@tonic-gate #include <sys/errno.h>
467c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
477c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
487c478bd9Sstevel@tonic-gate #include <sys/stat.h>
497c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
507c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
517c478bd9Sstevel@tonic-gate #include <sys/mode.h>
527c478bd9Sstevel@tonic-gate #include <sys/file.h>
537c478bd9Sstevel@tonic-gate #include <sys/proc.h>
547c478bd9Sstevel@tonic-gate #include <sys/uio.h>
557c478bd9Sstevel@tonic-gate #include <sys/debug.h>
567c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
577c478bd9Sstevel@tonic-gate #include <c2/audit.h>
58dd29fa4aSprabahar #include <fs/fs_subr.h>
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * Get the vp to be stated and the cred to be used for the call
627c478bd9Sstevel@tonic-gate  * to VOP_GETATTR
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate static int
66*8fd04b83SRoger A. Faulkner cstatat_getvp(int fd, char *name, int follow, vnode_t **vp, cred_t **cred)
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate 	vnode_t *startvp;
697c478bd9Sstevel@tonic-gate 	file_t *fp;
707c478bd9Sstevel@tonic-gate 	int error;
717c478bd9Sstevel@tonic-gate 	cred_t *cr;
72dd29fa4aSprabahar 	int estale_retry = 0;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	*vp = NULL;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	/*
777c478bd9Sstevel@tonic-gate 	 * Only return EFAULT for fstatat when fd == AT_FDCWD && name == NULL
787c478bd9Sstevel@tonic-gate 	 */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	if (fd == AT_FDCWD) {
817c478bd9Sstevel@tonic-gate 		startvp = NULL;
827c478bd9Sstevel@tonic-gate 		cr = CRED();
837c478bd9Sstevel@tonic-gate 		crhold(cr);
847c478bd9Sstevel@tonic-gate 	} else {
857c478bd9Sstevel@tonic-gate 		char startchar;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 		if (copyin(name, &startchar, sizeof (char)))
887c478bd9Sstevel@tonic-gate 			return (EFAULT);
89*8fd04b83SRoger A. Faulkner 		if (startchar != '/') {
907c478bd9Sstevel@tonic-gate 			if ((fp = getf(fd)) == NULL) {
917c478bd9Sstevel@tonic-gate 				return (EBADF);
927c478bd9Sstevel@tonic-gate 			}
937c478bd9Sstevel@tonic-gate 			startvp = fp->f_vnode;
947c478bd9Sstevel@tonic-gate 			cr = fp->f_cred;
957c478bd9Sstevel@tonic-gate 			crhold(cr);
967c478bd9Sstevel@tonic-gate 			VN_HOLD(startvp);
977c478bd9Sstevel@tonic-gate 			releasef(fd);
987c478bd9Sstevel@tonic-gate 		} else {
997c478bd9Sstevel@tonic-gate 			startvp = NULL;
1007c478bd9Sstevel@tonic-gate 			cr = CRED();
1017c478bd9Sstevel@tonic-gate 			crhold(cr);
1027c478bd9Sstevel@tonic-gate 		}
1037c478bd9Sstevel@tonic-gate 	}
1047c478bd9Sstevel@tonic-gate 	*cred = cr;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	if (audit_active)
1077c478bd9Sstevel@tonic-gate 		audit_setfsat_path(1);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate lookup:
1107c478bd9Sstevel@tonic-gate 	if (error = lookupnameat(name, UIO_USERSPACE, follow, NULLVPP,
1117c478bd9Sstevel@tonic-gate 	    vp, startvp)) {
112dd29fa4aSprabahar 		if ((error == ESTALE) &&
113dd29fa4aSprabahar 		    fs_need_estale_retry(estale_retry++))
1147c478bd9Sstevel@tonic-gate 			goto lookup;
1157c478bd9Sstevel@tonic-gate 		if (startvp != NULL)
1167c478bd9Sstevel@tonic-gate 			VN_RELE(startvp);
1177c478bd9Sstevel@tonic-gate 		crfree(cr);
1187c478bd9Sstevel@tonic-gate 		return (error);
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate 	if (startvp != NULL)
1217c478bd9Sstevel@tonic-gate 		VN_RELE(startvp);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	return (0);
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * Native syscall interfaces:
1287c478bd9Sstevel@tonic-gate  *
1297c478bd9Sstevel@tonic-gate  * N-bit kernel, N-bit applications, N-bit file offsets
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate 
132*8fd04b83SRoger A. Faulkner static int cstatat(int, char *, struct stat *, int, int);
1337c478bd9Sstevel@tonic-gate static int cstat(vnode_t *vp, struct stat *, int, cred_t *);
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  * fstat can and should be fast, do an inline implementation here.
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate #define	FSTAT_BODY(fd, sb, statfn)				\
1397c478bd9Sstevel@tonic-gate 	{							\
1407c478bd9Sstevel@tonic-gate 		file_t *fp;					\
1417c478bd9Sstevel@tonic-gate 		int error;					\
1427c478bd9Sstevel@tonic-gate 								\
143*8fd04b83SRoger A. Faulkner 		if (fd == AT_FDCWD)				\
144*8fd04b83SRoger A. Faulkner 			return (set_errno(EFAULT));		\
1457c478bd9Sstevel@tonic-gate 		if ((fp = getf(fd)) == NULL)			\
1467c478bd9Sstevel@tonic-gate 			return (set_errno(EBADF));		\
1477c478bd9Sstevel@tonic-gate 		if (audit_active)				\
1487c478bd9Sstevel@tonic-gate 			audit_setfsat_path(1);			\
1497c478bd9Sstevel@tonic-gate 		error = statfn(fp->f_vnode, sb, 0, fp->f_cred);	\
1507c478bd9Sstevel@tonic-gate 		releasef(fd);					\
1517c478bd9Sstevel@tonic-gate 		if (error)					\
1527c478bd9Sstevel@tonic-gate 			return (set_errno(error));		\
1537c478bd9Sstevel@tonic-gate 		return (0);					\
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate int
1577c478bd9Sstevel@tonic-gate fstat(int fd, struct stat *sb)
1587c478bd9Sstevel@tonic-gate {
1597c478bd9Sstevel@tonic-gate 	FSTAT_BODY(fd, sb, cstat)
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate int
1637c478bd9Sstevel@tonic-gate fstatat(int fd, char *name, struct stat *sb, int flags)
1647c478bd9Sstevel@tonic-gate {
165*8fd04b83SRoger A. Faulkner 	int followflag;
166*8fd04b83SRoger A. Faulkner 	int csflags;
1677c478bd9Sstevel@tonic-gate 
168*8fd04b83SRoger A. Faulkner 	if (name == NULL)
169*8fd04b83SRoger A. Faulkner 		return (fstat(fd, sb));
1707c478bd9Sstevel@tonic-gate 
171*8fd04b83SRoger A. Faulkner 	followflag = (flags & AT_SYMLINK_NOFOLLOW);
172*8fd04b83SRoger A. Faulkner 	csflags = (flags & _AT_TRIGGER ? ATTR_TRIGGER : 0);
173*8fd04b83SRoger A. Faulkner 	if (followflag == 0)
174*8fd04b83SRoger A. Faulkner 		csflags |= ATTR_REAL;	/* flag for procfs lookups */
1757c478bd9Sstevel@tonic-gate 
176*8fd04b83SRoger A. Faulkner 	return (cstatat(fd, name, sb, followflag, csflags));
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate int
180*8fd04b83SRoger A. Faulkner stat(char *name, struct stat *sb)
1817c478bd9Sstevel@tonic-gate {
182*8fd04b83SRoger A. Faulkner 	return (fstatat(AT_FDCWD, name, sb, 0));
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate int
186*8fd04b83SRoger A. Faulkner lstat(char *name, struct stat *sb)
1877c478bd9Sstevel@tonic-gate {
188*8fd04b83SRoger A. Faulkner 	return (fstatat(AT_FDCWD, name, sb, AT_SYMLINK_NOFOLLOW));
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate  * Common code for stat(), lstat(), and fstat().
1937c478bd9Sstevel@tonic-gate  * (32-bit kernel, 32-bit applications, 32-bit files)
1947c478bd9Sstevel@tonic-gate  * (64-bit kernel, 64-bit applications, 64-bit files)
1957c478bd9Sstevel@tonic-gate  */
1967c478bd9Sstevel@tonic-gate static int
1977c478bd9Sstevel@tonic-gate cstat(vnode_t *vp, struct stat *ubp, int flag, cred_t *cr)
1987c478bd9Sstevel@tonic-gate {
1997c478bd9Sstevel@tonic-gate 	struct vfssw *vswp;
2007c478bd9Sstevel@tonic-gate 	struct stat sb;
2017c478bd9Sstevel@tonic-gate 	vattr_t vattr;
2027c478bd9Sstevel@tonic-gate 	int error;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
205da6c28aaSamw 	if ((error = VOP_GETATTR(vp, &vattr, flag, cr, NULL)) != 0)
2067c478bd9Sstevel@tonic-gate 		return (error);
2077c478bd9Sstevel@tonic-gate #ifdef	_ILP32
2087c478bd9Sstevel@tonic-gate 	/*
2097c478bd9Sstevel@tonic-gate 	 * (32-bit kernel, 32-bit applications, 32-bit files)
2107c478bd9Sstevel@tonic-gate 	 * NOTE: 32-bit kernel maintains a 64-bit unsigend va_size.
2117c478bd9Sstevel@tonic-gate 	 *
2127c478bd9Sstevel@tonic-gate 	 * st_size of devices (VBLK and VCHR special files) is a special case.
2137c478bd9Sstevel@tonic-gate 	 * POSIX does not define size behavior for special files, so the
2147c478bd9Sstevel@tonic-gate 	 * following Solaris specific behavior is not a violation. Solaris
2157c478bd9Sstevel@tonic-gate 	 * returns the size of the device.
2167c478bd9Sstevel@tonic-gate 	 *
2177c478bd9Sstevel@tonic-gate 	 * For compatibility with 32-bit programs which happen to do stat() on
2187c478bd9Sstevel@tonic-gate 	 * a (mknod) bigger than 2GB we suppress the large file EOVERFLOW and
2197c478bd9Sstevel@tonic-gate 	 * instead we return the value MAXOFF32_T (LONG_MAX).
2207c478bd9Sstevel@tonic-gate 	 *
2217c478bd9Sstevel@tonic-gate 	 * 32-bit applications that care about the size of devices should be
2227c478bd9Sstevel@tonic-gate 	 * built 64-bit or use a large file interface (lfcompile(5) or lf64(5)).
2237c478bd9Sstevel@tonic-gate 	 */
2247c478bd9Sstevel@tonic-gate 	if ((vattr.va_size > MAXOFF32_T) &&
2257c478bd9Sstevel@tonic-gate 	    ((vp->v_type == VBLK) || (vp->v_type == VCHR))) {
2267c478bd9Sstevel@tonic-gate 		/* OVERFLOW | UNKNOWN_SIZE */
2277c478bd9Sstevel@tonic-gate 		vattr.va_size = MAXOFF32_T;
2287c478bd9Sstevel@tonic-gate 	}
2297c478bd9Sstevel@tonic-gate #endif	/* _ILP32 */
2307c478bd9Sstevel@tonic-gate 	if (vattr.va_size > MAXOFF_T || vattr.va_nblocks > LONG_MAX ||
2317c478bd9Sstevel@tonic-gate 	    vattr.va_nodeid > ULONG_MAX)
2327c478bd9Sstevel@tonic-gate 		return (EOVERFLOW);
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	bzero(&sb, sizeof (sb));
2357c478bd9Sstevel@tonic-gate 	sb.st_dev = vattr.va_fsid;
2367c478bd9Sstevel@tonic-gate 	sb.st_ino = (ino_t)vattr.va_nodeid;
2377c478bd9Sstevel@tonic-gate 	sb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
2387c478bd9Sstevel@tonic-gate 	sb.st_nlink = vattr.va_nlink;
2397c478bd9Sstevel@tonic-gate 	sb.st_uid = vattr.va_uid;
2407c478bd9Sstevel@tonic-gate 	sb.st_gid = vattr.va_gid;
2417c478bd9Sstevel@tonic-gate 	sb.st_rdev = vattr.va_rdev;
2427c478bd9Sstevel@tonic-gate 	sb.st_size = (off_t)vattr.va_size;
2437c478bd9Sstevel@tonic-gate 	sb.st_atim = vattr.va_atime;
2447c478bd9Sstevel@tonic-gate 	sb.st_mtim = vattr.va_mtime;
2457c478bd9Sstevel@tonic-gate 	sb.st_ctim = vattr.va_ctime;
2467c478bd9Sstevel@tonic-gate 	sb.st_blksize = vattr.va_blksize;
2477c478bd9Sstevel@tonic-gate 	sb.st_blocks = (blkcnt_t)vattr.va_nblocks;
2487c478bd9Sstevel@tonic-gate 	if (vp->v_vfsp != NULL) {
2497c478bd9Sstevel@tonic-gate 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
2507c478bd9Sstevel@tonic-gate 		if (vswp->vsw_name && *vswp->vsw_name)
2517c478bd9Sstevel@tonic-gate 			(void) strcpy(sb.st_fstype, vswp->vsw_name);
2527c478bd9Sstevel@tonic-gate 	}
2537c478bd9Sstevel@tonic-gate 	if (copyout(&sb, ubp, sizeof (sb)))
2547c478bd9Sstevel@tonic-gate 		return (EFAULT);
2557c478bd9Sstevel@tonic-gate 	return (0);
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate static int
259*8fd04b83SRoger A. Faulkner cstatat(int fd, char *name, struct stat *sb, int follow, int flags)
2607c478bd9Sstevel@tonic-gate {
2617c478bd9Sstevel@tonic-gate 	vnode_t *vp;
2627c478bd9Sstevel@tonic-gate 	int error;
2637c478bd9Sstevel@tonic-gate 	cred_t *cred;
2647c478bd9Sstevel@tonic-gate 	int link_follow;
265dd29fa4aSprabahar 	int estale_retry = 0;
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
2687c478bd9Sstevel@tonic-gate lookup:
269*8fd04b83SRoger A. Faulkner 	if (error = cstatat_getvp(fd, name, link_follow, &vp, &cred))
2707c478bd9Sstevel@tonic-gate 		return (set_errno(error));
2717c478bd9Sstevel@tonic-gate 	error = cstat(vp, sb, flags, cred);
2727c478bd9Sstevel@tonic-gate 	crfree(cred);
2737c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
2747c478bd9Sstevel@tonic-gate 	if (error != 0) {
2757c478bd9Sstevel@tonic-gate 		if (error == ESTALE &&
276*8fd04b83SRoger A. Faulkner 		    fs_need_estale_retry(estale_retry++))
2777c478bd9Sstevel@tonic-gate 			goto lookup;
2787c478bd9Sstevel@tonic-gate 		return (set_errno(error));
2797c478bd9Sstevel@tonic-gate 	}
2807c478bd9Sstevel@tonic-gate 	return (0);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate  * 64-bit kernel, 32-bit applications, 32-bit file offsets
2877c478bd9Sstevel@tonic-gate  */
288*8fd04b83SRoger A. Faulkner static int cstatat32(int, char *, struct stat32 *, int, int);
2897c478bd9Sstevel@tonic-gate static int cstat32(vnode_t *, struct stat32 *, int, cred_t *);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate int
2927c478bd9Sstevel@tonic-gate fstat32(int fd, struct stat32 *sb)
2937c478bd9Sstevel@tonic-gate {
2947c478bd9Sstevel@tonic-gate 	FSTAT_BODY(fd, sb, cstat32)
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate int
298b9238976Sth199096 fstatat32(int fd, char *name, struct stat32 *sb, int flags)
2997c478bd9Sstevel@tonic-gate {
300*8fd04b83SRoger A. Faulkner 	int followflag;
301*8fd04b83SRoger A. Faulkner 	int csflags;
3027c478bd9Sstevel@tonic-gate 
303*8fd04b83SRoger A. Faulkner 	if (name == NULL)
304*8fd04b83SRoger A. Faulkner 		return (fstat32(fd, sb));
3057c478bd9Sstevel@tonic-gate 
306*8fd04b83SRoger A. Faulkner 	followflag = (flags & AT_SYMLINK_NOFOLLOW);
307*8fd04b83SRoger A. Faulkner 	csflags = (flags & _AT_TRIGGER ? ATTR_TRIGGER : 0);
308*8fd04b83SRoger A. Faulkner 	if (followflag == 0)
309*8fd04b83SRoger A. Faulkner 		csflags |= ATTR_REAL;	/* flag for procfs lookups */
310*8fd04b83SRoger A. Faulkner 
311*8fd04b83SRoger A. Faulkner 	return (cstatat32(fd, name, sb, followflag, csflags));
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate int
315*8fd04b83SRoger A. Faulkner stat32(char *name, struct stat32 *sb)
3167c478bd9Sstevel@tonic-gate {
317*8fd04b83SRoger A. Faulkner 	return (fstatat32(AT_FDCWD, name, sb, 0));
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate int
321*8fd04b83SRoger A. Faulkner lstat32(char *name, struct stat32 *sb)
3227c478bd9Sstevel@tonic-gate {
323*8fd04b83SRoger A. Faulkner 	return (fstatat32(AT_FDCWD, name, sb, AT_SYMLINK_NOFOLLOW));
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate static int
3277c478bd9Sstevel@tonic-gate cstat32(vnode_t *vp, struct stat32 *ubp, int flag, struct cred *cr)
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate 	struct vfssw *vswp;
3307c478bd9Sstevel@tonic-gate 	struct stat32 sb;
3317c478bd9Sstevel@tonic-gate 	vattr_t vattr;
3327c478bd9Sstevel@tonic-gate 	int error;
3337c478bd9Sstevel@tonic-gate 	dev32_t st_dev, st_rdev;
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
336da6c28aaSamw 	if (error = VOP_GETATTR(vp, &vattr, flag, cr, NULL))
3377c478bd9Sstevel@tonic-gate 		return (error);
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	/* devices are a special case, see comments in cstat */
3407c478bd9Sstevel@tonic-gate 	if ((vattr.va_size > MAXOFF32_T) &&
3417c478bd9Sstevel@tonic-gate 	    ((vp->v_type == VBLK) || (vp->v_type == VCHR))) {
3427c478bd9Sstevel@tonic-gate 		/* OVERFLOW | UNKNOWN_SIZE */
3437c478bd9Sstevel@tonic-gate 		vattr.va_size = MAXOFF32_T;
3447c478bd9Sstevel@tonic-gate 	}
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 	/* check for large values */
3477c478bd9Sstevel@tonic-gate 	if (!cmpldev(&st_dev, vattr.va_fsid) ||
3487c478bd9Sstevel@tonic-gate 	    !cmpldev(&st_rdev, vattr.va_rdev) ||
3497c478bd9Sstevel@tonic-gate 	    vattr.va_size > MAXOFF32_T ||
3507c478bd9Sstevel@tonic-gate 	    vattr.va_nblocks > INT32_MAX ||
3517c478bd9Sstevel@tonic-gate 	    vattr.va_nodeid > UINT32_MAX ||
3527c478bd9Sstevel@tonic-gate 	    TIMESPEC_OVERFLOW(&(vattr.va_atime)) ||
3537c478bd9Sstevel@tonic-gate 	    TIMESPEC_OVERFLOW(&(vattr.va_mtime)) ||
3547c478bd9Sstevel@tonic-gate 	    TIMESPEC_OVERFLOW(&(vattr.va_ctime)))
3557c478bd9Sstevel@tonic-gate 		return (EOVERFLOW);
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	bzero(&sb, sizeof (sb));
3587c478bd9Sstevel@tonic-gate 	sb.st_dev = st_dev;
3597c478bd9Sstevel@tonic-gate 	sb.st_ino = (ino32_t)vattr.va_nodeid;
3607c478bd9Sstevel@tonic-gate 	sb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
3617c478bd9Sstevel@tonic-gate 	sb.st_nlink = vattr.va_nlink;
3627c478bd9Sstevel@tonic-gate 	sb.st_uid = vattr.va_uid;
3637c478bd9Sstevel@tonic-gate 	sb.st_gid = vattr.va_gid;
3647c478bd9Sstevel@tonic-gate 	sb.st_rdev = st_rdev;
3657c478bd9Sstevel@tonic-gate 	sb.st_size = (off32_t)vattr.va_size;
3667c478bd9Sstevel@tonic-gate 	TIMESPEC_TO_TIMESPEC32(&(sb.st_atim), &(vattr.va_atime));
3677c478bd9Sstevel@tonic-gate 	TIMESPEC_TO_TIMESPEC32(&(sb.st_mtim), &(vattr.va_mtime));
3687c478bd9Sstevel@tonic-gate 	TIMESPEC_TO_TIMESPEC32(&(sb.st_ctim), &(vattr.va_ctime));
3697c478bd9Sstevel@tonic-gate 	sb.st_blksize = vattr.va_blksize;
3707c478bd9Sstevel@tonic-gate 	sb.st_blocks = (blkcnt32_t)vattr.va_nblocks;
3717c478bd9Sstevel@tonic-gate 	if (vp->v_vfsp != NULL) {
3727c478bd9Sstevel@tonic-gate 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
3737c478bd9Sstevel@tonic-gate 		if (vswp->vsw_name && *vswp->vsw_name)
3747c478bd9Sstevel@tonic-gate 			(void) strcpy(sb.st_fstype, vswp->vsw_name);
3757c478bd9Sstevel@tonic-gate 	}
3767c478bd9Sstevel@tonic-gate 	if (copyout(&sb, ubp, sizeof (sb)))
3777c478bd9Sstevel@tonic-gate 		return (EFAULT);
3787c478bd9Sstevel@tonic-gate 	return (0);
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate static int
382*8fd04b83SRoger A. Faulkner cstatat32(int fd, char *name, struct stat32 *sb, int follow, int flags)
3837c478bd9Sstevel@tonic-gate {
3847c478bd9Sstevel@tonic-gate 	vnode_t *vp;
3857c478bd9Sstevel@tonic-gate 	int error;
3867c478bd9Sstevel@tonic-gate 	cred_t *cred;
3877c478bd9Sstevel@tonic-gate 	int link_follow;
388dd29fa4aSprabahar 	int estale_retry = 0;
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
3917c478bd9Sstevel@tonic-gate lookup:
392*8fd04b83SRoger A. Faulkner 	if (error = cstatat_getvp(fd, name, link_follow, &vp, &cred))
3937c478bd9Sstevel@tonic-gate 		return (set_errno(error));
3947c478bd9Sstevel@tonic-gate 	error = cstat32(vp, sb, flags, cred);
3957c478bd9Sstevel@tonic-gate 	crfree(cred);
3967c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
3977c478bd9Sstevel@tonic-gate 	if (error != 0) {
3987c478bd9Sstevel@tonic-gate 		if (error == ESTALE &&
399*8fd04b83SRoger A. Faulkner 		    fs_need_estale_retry(estale_retry++))
4007c478bd9Sstevel@tonic-gate 			goto lookup;
4017c478bd9Sstevel@tonic-gate 		return (set_errno(error));
4027c478bd9Sstevel@tonic-gate 	}
4037c478bd9Sstevel@tonic-gate 	return (0);
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32_IMPL */
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate #if defined(_ILP32)
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /*
4117c478bd9Sstevel@tonic-gate  * 32-bit kernel, 32-bit applications, 64-bit file offsets.
4127c478bd9Sstevel@tonic-gate  *
4137c478bd9Sstevel@tonic-gate  * These routines are implemented differently on 64-bit kernels.
4147c478bd9Sstevel@tonic-gate  */
415*8fd04b83SRoger A. Faulkner static int cstatat64(int, char *, struct stat64 *, int, int);
4167c478bd9Sstevel@tonic-gate static int cstat64(vnode_t *, struct stat64 *, int, cred_t *);
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate int
4197c478bd9Sstevel@tonic-gate fstat64(int fd, struct stat64 *sb)
4207c478bd9Sstevel@tonic-gate {
4217c478bd9Sstevel@tonic-gate 	FSTAT_BODY(fd, sb, cstat64)
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate int
4257c478bd9Sstevel@tonic-gate fstatat64(int fd, char *name, struct stat64 *sb, int flags)
4267c478bd9Sstevel@tonic-gate {
427*8fd04b83SRoger A. Faulkner 	int followflag;
428*8fd04b83SRoger A. Faulkner 	int csflags;
429*8fd04b83SRoger A. Faulkner 
430*8fd04b83SRoger A. Faulkner 	if (name == NULL)
431*8fd04b83SRoger A. Faulkner 		return (fstat64(fd, sb));
432*8fd04b83SRoger A. Faulkner 
433*8fd04b83SRoger A. Faulkner 	followflag = (flags & AT_SYMLINK_NOFOLLOW);
434*8fd04b83SRoger A. Faulkner 	csflags = (flags & _AT_TRIGGER ? ATTR_TRIGGER : 0);
435*8fd04b83SRoger A. Faulkner 	if (followflag == 0)
436*8fd04b83SRoger A. Faulkner 		csflags |= ATTR_REAL;	/* flag for procfs lookups */
437*8fd04b83SRoger A. Faulkner 
438*8fd04b83SRoger A. Faulkner 	return (cstatat64(fd, name, sb, followflag, csflags));
439*8fd04b83SRoger A. Faulkner }
440*8fd04b83SRoger A. Faulkner 
441*8fd04b83SRoger A. Faulkner int
442*8fd04b83SRoger A. Faulkner stat64(char *name, struct stat64 *sb)
443*8fd04b83SRoger A. Faulkner {
444*8fd04b83SRoger A. Faulkner 	return (fstatat64(AT_FDCWD, name, sb, 0));
445*8fd04b83SRoger A. Faulkner }
446*8fd04b83SRoger A. Faulkner 
447*8fd04b83SRoger A. Faulkner int
448*8fd04b83SRoger A. Faulkner lstat64(char *name, struct stat64 *sb)
449*8fd04b83SRoger A. Faulkner {
450*8fd04b83SRoger A. Faulkner 	return (fstatat64(AT_FDCWD, name, sb, AT_SYMLINK_NOFOLLOW));
4517c478bd9Sstevel@tonic-gate }
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate static int
4547c478bd9Sstevel@tonic-gate cstat64(vnode_t *vp, struct stat64 *ubp, int flag, cred_t *cr)
4557c478bd9Sstevel@tonic-gate {
4567c478bd9Sstevel@tonic-gate 	struct vfssw *vswp;
4577c478bd9Sstevel@tonic-gate 	struct stat64 lsb;
4587c478bd9Sstevel@tonic-gate 	vattr_t vattr;
4597c478bd9Sstevel@tonic-gate 	int error;
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
462da6c28aaSamw 	if (error = VOP_GETATTR(vp, &vattr, flag, cr, NULL))
4637c478bd9Sstevel@tonic-gate 		return (error);
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	bzero(&lsb, sizeof (lsb));
4667c478bd9Sstevel@tonic-gate 	lsb.st_dev = vattr.va_fsid;
4677c478bd9Sstevel@tonic-gate 	lsb.st_ino = vattr.va_nodeid;
4687c478bd9Sstevel@tonic-gate 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
4697c478bd9Sstevel@tonic-gate 	lsb.st_nlink = vattr.va_nlink;
4707c478bd9Sstevel@tonic-gate 	lsb.st_uid = vattr.va_uid;
4717c478bd9Sstevel@tonic-gate 	lsb.st_gid = vattr.va_gid;
4727c478bd9Sstevel@tonic-gate 	lsb.st_rdev = vattr.va_rdev;
4737c478bd9Sstevel@tonic-gate 	lsb.st_size = vattr.va_size;
4747c478bd9Sstevel@tonic-gate 	lsb.st_atim = vattr.va_atime;
4757c478bd9Sstevel@tonic-gate 	lsb.st_mtim = vattr.va_mtime;
4767c478bd9Sstevel@tonic-gate 	lsb.st_ctim = vattr.va_ctime;
4777c478bd9Sstevel@tonic-gate 	lsb.st_blksize = vattr.va_blksize;
4787c478bd9Sstevel@tonic-gate 	lsb.st_blocks = vattr.va_nblocks;
4797c478bd9Sstevel@tonic-gate 	if (vp->v_vfsp != NULL) {
4807c478bd9Sstevel@tonic-gate 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
4817c478bd9Sstevel@tonic-gate 		if (vswp->vsw_name && *vswp->vsw_name)
4827c478bd9Sstevel@tonic-gate 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
4837c478bd9Sstevel@tonic-gate 	}
4847c478bd9Sstevel@tonic-gate 	if (copyout(&lsb, ubp, sizeof (lsb)))
4857c478bd9Sstevel@tonic-gate 		return (EFAULT);
4867c478bd9Sstevel@tonic-gate 	return (0);
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate static int
490*8fd04b83SRoger A. Faulkner cstatat64(int fd, char *name, struct stat64 *sb, int follow, int flags)
4917c478bd9Sstevel@tonic-gate {
4927c478bd9Sstevel@tonic-gate 	vnode_t *vp;
4937c478bd9Sstevel@tonic-gate 	int error;
4947c478bd9Sstevel@tonic-gate 	cred_t *cred;
4957c478bd9Sstevel@tonic-gate 	int link_follow;
496dd29fa4aSprabahar 	int estale_retry = 0;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
4997c478bd9Sstevel@tonic-gate lookup:
500*8fd04b83SRoger A. Faulkner 	if (error = cstatat_getvp(fd, name, link_follow, &vp, &cred))
5017c478bd9Sstevel@tonic-gate 		return (set_errno(error));
5027c478bd9Sstevel@tonic-gate 	error = cstat64(vp, sb, flags, cred);
5037c478bd9Sstevel@tonic-gate 	crfree(cred);
5047c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
5057c478bd9Sstevel@tonic-gate 	if (error != 0) {
5067c478bd9Sstevel@tonic-gate 		if (error == ESTALE &&
507*8fd04b83SRoger A. Faulkner 		    fs_need_estale_retry(estale_retry++))
5087c478bd9Sstevel@tonic-gate 			goto lookup;
5097c478bd9Sstevel@tonic-gate 		return (set_errno(error));
5107c478bd9Sstevel@tonic-gate 	}
5117c478bd9Sstevel@tonic-gate 	return (0);
5127c478bd9Sstevel@tonic-gate }
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate #endif	/* _ILP32 */
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32_IMPL)
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate /*
5197c478bd9Sstevel@tonic-gate  * 64-bit kernel, 32-bit applications, 64-bit file offsets.
5207c478bd9Sstevel@tonic-gate  *
5217c478bd9Sstevel@tonic-gate  * We'd really like to call the "native" stat calls for these ones,
5227c478bd9Sstevel@tonic-gate  * but the problem is that the 64-bit ABI defines the 'stat64' structure
5237c478bd9Sstevel@tonic-gate  * differently from the way the 32-bit ABI defines it.
5247c478bd9Sstevel@tonic-gate  */
5257c478bd9Sstevel@tonic-gate 
526*8fd04b83SRoger A. Faulkner static int cstatat64_32(int, char *, struct stat64_32 *, int, int);
5277c478bd9Sstevel@tonic-gate static int cstat64_32(vnode_t *, struct stat64_32 *, int, cred_t *);
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate int
5307c478bd9Sstevel@tonic-gate fstat64_32(int fd, struct stat64_32 *sb)
5317c478bd9Sstevel@tonic-gate {
5327c478bd9Sstevel@tonic-gate 	FSTAT_BODY(fd, sb, cstat64_32)
5337c478bd9Sstevel@tonic-gate }
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate int
536b9238976Sth199096 fstatat64_32(int fd, char *name, struct stat64_32 *sb, int flags)
5377c478bd9Sstevel@tonic-gate {
538*8fd04b83SRoger A. Faulkner 	int followflag;
539*8fd04b83SRoger A. Faulkner 	int csflags;
540*8fd04b83SRoger A. Faulkner 
541*8fd04b83SRoger A. Faulkner 	if (name == NULL)
542*8fd04b83SRoger A. Faulkner 		return (fstat64_32(fd, sb));
543*8fd04b83SRoger A. Faulkner 
544*8fd04b83SRoger A. Faulkner 	followflag = (flags & AT_SYMLINK_NOFOLLOW);
545*8fd04b83SRoger A. Faulkner 	csflags = (flags & _AT_TRIGGER ? ATTR_TRIGGER : 0);
546*8fd04b83SRoger A. Faulkner 	if (followflag == 0)
547*8fd04b83SRoger A. Faulkner 		csflags |= ATTR_REAL;	/* flag for procfs lookups */
548*8fd04b83SRoger A. Faulkner 
549*8fd04b83SRoger A. Faulkner 	return (cstatat64_32(fd, name, sb, followflag, csflags));
550*8fd04b83SRoger A. Faulkner }
551*8fd04b83SRoger A. Faulkner 
552*8fd04b83SRoger A. Faulkner int
553*8fd04b83SRoger A. Faulkner stat64_32(char *name, struct stat64_32 *sb)
554*8fd04b83SRoger A. Faulkner {
555*8fd04b83SRoger A. Faulkner 	return (fstatat64_32(AT_FDCWD, name, sb, 0));
556*8fd04b83SRoger A. Faulkner }
557*8fd04b83SRoger A. Faulkner 
558*8fd04b83SRoger A. Faulkner int
559*8fd04b83SRoger A. Faulkner lstat64_32(char *name, struct stat64_32 *sb)
560*8fd04b83SRoger A. Faulkner {
561*8fd04b83SRoger A. Faulkner 	return (fstatat64_32(AT_FDCWD, name, sb, AT_SYMLINK_NOFOLLOW));
5627c478bd9Sstevel@tonic-gate }
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate static int
5657c478bd9Sstevel@tonic-gate cstat64_32(vnode_t *vp, struct stat64_32 *ubp, int flag, cred_t *cr)
5667c478bd9Sstevel@tonic-gate {
5677c478bd9Sstevel@tonic-gate 	struct vfssw *vswp;
5687c478bd9Sstevel@tonic-gate 	struct stat64_32 lsb;
5697c478bd9Sstevel@tonic-gate 	vattr_t vattr;
5707c478bd9Sstevel@tonic-gate 	int error;
5717c478bd9Sstevel@tonic-gate 	dev32_t st_dev, st_rdev;
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
574da6c28aaSamw 	if (error = VOP_GETATTR(vp, &vattr, flag, cr, NULL))
5757c478bd9Sstevel@tonic-gate 		return (error);
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	if (!cmpldev(&st_dev, vattr.va_fsid) ||
5787c478bd9Sstevel@tonic-gate 	    !cmpldev(&st_rdev, vattr.va_rdev) ||
5797c478bd9Sstevel@tonic-gate 	    TIMESPEC_OVERFLOW(&(vattr.va_atime)) ||
5807c478bd9Sstevel@tonic-gate 	    TIMESPEC_OVERFLOW(&(vattr.va_mtime)) ||
5817c478bd9Sstevel@tonic-gate 	    TIMESPEC_OVERFLOW(&(vattr.va_ctime)))
5827c478bd9Sstevel@tonic-gate 		return (EOVERFLOW);
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	bzero(&lsb, sizeof (lsb));
5857c478bd9Sstevel@tonic-gate 	lsb.st_dev = st_dev;
5867c478bd9Sstevel@tonic-gate 	lsb.st_ino = vattr.va_nodeid;
5877c478bd9Sstevel@tonic-gate 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
5887c478bd9Sstevel@tonic-gate 	lsb.st_nlink = vattr.va_nlink;
5897c478bd9Sstevel@tonic-gate 	lsb.st_uid = vattr.va_uid;
5907c478bd9Sstevel@tonic-gate 	lsb.st_gid = vattr.va_gid;
5917c478bd9Sstevel@tonic-gate 	lsb.st_rdev = st_rdev;
5927c478bd9Sstevel@tonic-gate 	lsb.st_size = vattr.va_size;
5937c478bd9Sstevel@tonic-gate 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_atim), &(vattr.va_atime));
5947c478bd9Sstevel@tonic-gate 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_mtim), &(vattr.va_mtime));
5957c478bd9Sstevel@tonic-gate 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_ctim), &(vattr.va_ctime));
5967c478bd9Sstevel@tonic-gate 	lsb.st_blksize = vattr.va_blksize;
5977c478bd9Sstevel@tonic-gate 	lsb.st_blocks = vattr.va_nblocks;
5987c478bd9Sstevel@tonic-gate 	if (vp->v_vfsp != NULL) {
5997c478bd9Sstevel@tonic-gate 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
6007c478bd9Sstevel@tonic-gate 		if (vswp->vsw_name && *vswp->vsw_name)
6017c478bd9Sstevel@tonic-gate 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
6027c478bd9Sstevel@tonic-gate 	}
6037c478bd9Sstevel@tonic-gate 	if (copyout(&lsb, ubp, sizeof (lsb)))
6047c478bd9Sstevel@tonic-gate 		return (EFAULT);
6057c478bd9Sstevel@tonic-gate 	return (0);
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate static int
609*8fd04b83SRoger A. Faulkner cstatat64_32(int fd, char *name, struct stat64_32 *sb, int follow, int flags)
6107c478bd9Sstevel@tonic-gate {
6117c478bd9Sstevel@tonic-gate 	vnode_t  *vp;
6127c478bd9Sstevel@tonic-gate 	int error;
6137c478bd9Sstevel@tonic-gate 	cred_t *cred;
6147c478bd9Sstevel@tonic-gate 	int link_follow;
615dd29fa4aSprabahar 	int estale_retry = 0;
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
6187c478bd9Sstevel@tonic-gate lookup:
619*8fd04b83SRoger A. Faulkner 	if (error = cstatat_getvp(fd, name, link_follow, &vp, &cred))
6207c478bd9Sstevel@tonic-gate 		return (set_errno(error));
6217c478bd9Sstevel@tonic-gate 	error = cstat64_32(vp, sb, flags, cred);
6227c478bd9Sstevel@tonic-gate 	crfree(cred);
6237c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
6247c478bd9Sstevel@tonic-gate 	if (error != 0) {
6257c478bd9Sstevel@tonic-gate 		if (error == ESTALE &&
626*8fd04b83SRoger A. Faulkner 		    fs_need_estale_retry(estale_retry++))
6277c478bd9Sstevel@tonic-gate 			goto lookup;
6287c478bd9Sstevel@tonic-gate 		return (set_errno(error));
6297c478bd9Sstevel@tonic-gate 	}
6307c478bd9Sstevel@tonic-gate 	return (0);
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32_IMPL */
634