xref: /illumos-gate/usr/src/uts/common/syscall/stat.c (revision b9238976)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 /*
30  * Portions of this source code were derived from Berkeley 4.3 BSD
31  * under license from the Regents of the University of California.
32  */
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 /*
37  * Get file attribute information through a file name or a file descriptor.
38  */
39 
40 #include <sys/param.h>
41 #include <sys/isa_defs.h>
42 #include <sys/types.h>
43 #include <sys/sysmacros.h>
44 #include <sys/cred.h>
45 #include <sys/systm.h>
46 #include <sys/errno.h>
47 #include <sys/fcntl.h>
48 #include <sys/pathname.h>
49 #include <sys/stat.h>
50 #include <sys/vfs.h>
51 #include <sys/vnode.h>
52 #include <sys/mode.h>
53 #include <sys/file.h>
54 #include <sys/proc.h>
55 #include <sys/uio.h>
56 #include <sys/debug.h>
57 #include <sys/cmn_err.h>
58 #include <c2/audit.h>
59 #include <fs/fs_subr.h>
60 
61 /*
62  * Get the vp to be stated and the cred to be used for the call
63  * to VOP_GETATTR
64  */
65 
66 /*
67  * nmflag has the following values
68  *
69  * 1 - Always do lookup.  i.e. stat, lstat.
70  * 2 - Name is optional i.e. fstatat
71  * 0 - Don't lookup name, vp is in file_p. i.e. fstat
72  *
73  */
74 static int
75 cstatat_getvp(int fd, char *name, int nmflag,
76     int follow, vnode_t **vp, cred_t **cred)
77 {
78 	vnode_t *startvp;
79 	file_t *fp;
80 	int error;
81 	cred_t *cr;
82 	int estale_retry = 0;
83 
84 	*vp = NULL;
85 
86 	/*
87 	 * Only return EFAULT for fstatat when fd == AT_FDCWD && name == NULL
88 	 */
89 
90 	if (fd == AT_FDCWD) {
91 		if (name != NULL || nmflag != 2) {
92 			startvp = NULL;
93 			cr = CRED();
94 			crhold(cr);
95 		} else
96 			return (EFAULT);
97 	} else {
98 		char startchar;
99 
100 		if (nmflag == 1 || (nmflag == 2 && name != NULL)) {
101 			if (copyin(name, &startchar, sizeof (char)))
102 				return (EFAULT);
103 		} else {
104 			startchar = '\0';
105 		}
106 		if (startchar != '/' || nmflag == 0) {
107 			if ((fp = getf(fd)) == NULL) {
108 				return (EBADF);
109 			}
110 			startvp = fp->f_vnode;
111 			cr = fp->f_cred;
112 			crhold(cr);
113 			VN_HOLD(startvp);
114 			releasef(fd);
115 		} else {
116 			startvp = NULL;
117 			cr = CRED();
118 			crhold(cr);
119 		}
120 	}
121 	*cred = cr;
122 
123 #ifdef C2_AUDIT
124 	if (audit_active)
125 		audit_setfsat_path(1);
126 #endif /* C2_AUDIT */
127 
128 
129 	if (nmflag == 1 || (nmflag == 2 && name != NULL)) {
130 lookup:
131 		if (error = lookupnameat(name, UIO_USERSPACE, follow, NULLVPP,
132 		    vp, startvp)) {
133 			if ((error == ESTALE) &&
134 			    fs_need_estale_retry(estale_retry++))
135 				goto lookup;
136 			if (startvp != NULL)
137 				VN_RELE(startvp);
138 			crfree(cr);
139 			return (error);
140 		}
141 		if (startvp != NULL)
142 			VN_RELE(startvp);
143 	} else {
144 		*vp = startvp;
145 	}
146 
147 	return (0);
148 }
149 
150 /*
151  * Native syscall interfaces:
152  *
153  * N-bit kernel, N-bit applications, N-bit file offsets
154  */
155 
156 static int cstatat(int, char *, int, struct stat *, int, int);
157 static int cstat(vnode_t *vp, struct stat *, int, cred_t *);
158 
159 int
160 stat(char *fname, struct stat *sb)
161 {
162 	return (cstatat(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
163 }
164 
165 int
166 lstat(char *fname, struct stat *sb)
167 {
168 	return (cstatat(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
169 }
170 
171 /*
172  * fstat can and should be fast, do an inline implementation here.
173  */
174 #define	FSTAT_BODY(fd, sb, statfn)				\
175 	{							\
176 		file_t *fp;					\
177 		int error;					\
178 								\
179 		if ((fp = getf(fd)) == NULL)			\
180 			return (set_errno(EBADF));		\
181 		if (audit_active)				\
182 			audit_setfsat_path(1);			\
183 		error = statfn(fp->f_vnode, sb, 0, fp->f_cred);	\
184 		releasef(fd);					\
185 		if (error)					\
186 			return (set_errno(error));		\
187 		return (0);					\
188 	}
189 
190 int
191 fstat(int fd, struct stat *sb)
192 {
193 	FSTAT_BODY(fd, sb, cstat)
194 }
195 
196 int
197 fstatat(int fd, char *name, struct stat *sb, int flags)
198 {
199 	return (cstatat(fd, name, 2, sb,
200 	    flags & AT_SYMLINK_NOFOLLOW ? AT_SYMLINK_NOFOLLOW : 0,
201 	    flags & _AT_TRIGGER ? ATTR_TRIGGER : 0));
202 }
203 
204 #if defined(__i386) || defined(__i386_COMPAT)
205 
206 /*
207  * Handle all the "extended" stat operations in the same way;
208  * validate the version, then call the real handler.
209  */
210 
211 #define	XSTAT_BODY(ver, f, s, fn)			\
212 	return (ver != _STAT_VER ? set_errno(EINVAL) : fn(f, s));
213 
214 #endif	/* __i386 || __i386_COMPAT */
215 
216 #if defined(__i386)
217 
218 /*
219  * Syscalls for i386 applications that issue {,l,f}xstat() directly
220  */
221 int
222 xstat(int version, char *fname, struct stat *sb)
223 {
224 	XSTAT_BODY(version, fname, sb, stat)
225 }
226 
227 int
228 lxstat(int version, char *fname, struct stat *sb)
229 {
230 	XSTAT_BODY(version, fname, sb, lstat)
231 }
232 
233 int
234 fxstat(int version, int fd, struct stat *sb)
235 {
236 	XSTAT_BODY(version, fd, sb, fstat)
237 }
238 
239 #endif	/* __i386 */
240 
241 /*
242  * Common code for stat(), lstat(), and fstat().
243  * (32-bit kernel, 32-bit applications, 32-bit files)
244  * (64-bit kernel, 64-bit applications, 64-bit files)
245  */
246 static int
247 cstat(vnode_t *vp, struct stat *ubp, int flag, cred_t *cr)
248 {
249 	struct vfssw *vswp;
250 	struct stat sb;
251 	vattr_t vattr;
252 	int error;
253 
254 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
255 	if ((error = VOP_GETATTR(vp, &vattr, flag, cr)) != 0)
256 		return (error);
257 #ifdef	_ILP32
258 	/*
259 	 * (32-bit kernel, 32-bit applications, 32-bit files)
260 	 * NOTE: 32-bit kernel maintains a 64-bit unsigend va_size.
261 	 *
262 	 * st_size of devices (VBLK and VCHR special files) is a special case.
263 	 * POSIX does not define size behavior for special files, so the
264 	 * following Solaris specific behavior is not a violation. Solaris
265 	 * returns the size of the device.
266 	 *
267 	 * For compatibility with 32-bit programs which happen to do stat() on
268 	 * a (mknod) bigger than 2GB we suppress the large file EOVERFLOW and
269 	 * instead we return the value MAXOFF32_T (LONG_MAX).
270 	 *
271 	 * 32-bit applications that care about the size of devices should be
272 	 * built 64-bit or use a large file interface (lfcompile(5) or lf64(5)).
273 	 */
274 	if ((vattr.va_size > MAXOFF32_T) &&
275 	    ((vp->v_type == VBLK) || (vp->v_type == VCHR))) {
276 		/* OVERFLOW | UNKNOWN_SIZE */
277 		vattr.va_size = MAXOFF32_T;
278 	}
279 #endif	/* _ILP32 */
280 	if (vattr.va_size > MAXOFF_T || vattr.va_nblocks > LONG_MAX ||
281 	    vattr.va_nodeid > ULONG_MAX)
282 		return (EOVERFLOW);
283 
284 	bzero(&sb, sizeof (sb));
285 	sb.st_dev = vattr.va_fsid;
286 	sb.st_ino = (ino_t)vattr.va_nodeid;
287 	sb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
288 	sb.st_nlink = vattr.va_nlink;
289 	sb.st_uid = vattr.va_uid;
290 	sb.st_gid = vattr.va_gid;
291 	sb.st_rdev = vattr.va_rdev;
292 	sb.st_size = (off_t)vattr.va_size;
293 	sb.st_atim = vattr.va_atime;
294 	sb.st_mtim = vattr.va_mtime;
295 	sb.st_ctim = vattr.va_ctime;
296 	sb.st_blksize = vattr.va_blksize;
297 	sb.st_blocks = (blkcnt_t)vattr.va_nblocks;
298 	if (vp->v_vfsp != NULL) {
299 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
300 		if (vswp->vsw_name && *vswp->vsw_name)
301 			(void) strcpy(sb.st_fstype, vswp->vsw_name);
302 	}
303 	if (copyout(&sb, ubp, sizeof (sb)))
304 		return (EFAULT);
305 	return (0);
306 }
307 
308 static int
309 cstatat(int fd, char *name, int nmflag, struct stat *sb, int follow, int flags)
310 {
311 	vnode_t *vp;
312 	int error;
313 	cred_t *cred;
314 	int link_follow;
315 	int estale_retry = 0;
316 
317 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
318 lookup:
319 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
320 		return (set_errno(error));
321 	error = cstat(vp, sb, flags, cred);
322 	crfree(cred);
323 	VN_RELE(vp);
324 out:
325 	if (error != 0) {
326 		if (error == ESTALE &&
327 		    fs_need_estale_retry(estale_retry++) &&
328 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
329 			goto lookup;
330 		return (set_errno(error));
331 	}
332 	return (0);
333 }
334 
335 #if defined(_SYSCALL32_IMPL)
336 
337 /*
338  * 64-bit kernel, 32-bit applications, 32-bit file offsets
339  */
340 static int cstatat32(int, char *, int, struct stat32 *, int, int);
341 static int cstat32(vnode_t *, struct stat32 *, int, cred_t *);
342 
343 int
344 stat32(char *fname, struct stat32 *sb)
345 {
346 	return (cstatat32(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
347 }
348 
349 int
350 lstat32(char *fname, struct stat32 *sb)
351 {
352 	return (cstatat32(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
353 }
354 
355 int
356 fstat32(int fd, struct stat32 *sb)
357 {
358 	FSTAT_BODY(fd, sb, cstat32)
359 }
360 
361 int
362 fstatat32(int fd, char *name, struct stat32 *sb, int flags)
363 {
364 	return (cstatat32(fd, name, 2, sb,
365 	    flags & AT_SYMLINK_NOFOLLOW ? AT_SYMLINK_NOFOLLOW : 0,
366 	    flags & _AT_TRIGGER ? ATTR_TRIGGER : 0));
367 }
368 
369 #if defined(__i386_COMPAT)
370 
371 /*
372  * Syscalls for i386 applications that issue {,l,f}xstat() directly
373  */
374 int
375 xstat32(int version, char *fname, struct stat32 *sb)
376 {
377 	XSTAT_BODY(version, fname, sb, stat32)
378 }
379 
380 int
381 lxstat32(int version, char *fname, struct stat32 *sb)
382 {
383 	XSTAT_BODY(version, fname, sb, lstat32)
384 }
385 
386 int
387 fxstat32(int version, int fd, struct stat32 *sb)
388 {
389 	XSTAT_BODY(version, fd, sb, fstat32)
390 }
391 
392 #endif	/* __i386_COMPAT */
393 
394 static int
395 cstat32(vnode_t *vp, struct stat32 *ubp, int flag, struct cred *cr)
396 {
397 	struct vfssw *vswp;
398 	struct stat32 sb;
399 	vattr_t vattr;
400 	int error;
401 	dev32_t st_dev, st_rdev;
402 
403 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
404 	if (error = VOP_GETATTR(vp, &vattr, flag, cr))
405 		return (error);
406 
407 	/* devices are a special case, see comments in cstat */
408 	if ((vattr.va_size > MAXOFF32_T) &&
409 	    ((vp->v_type == VBLK) || (vp->v_type == VCHR))) {
410 		/* OVERFLOW | UNKNOWN_SIZE */
411 		vattr.va_size = MAXOFF32_T;
412 	}
413 
414 	/* check for large values */
415 	if (!cmpldev(&st_dev, vattr.va_fsid) ||
416 	    !cmpldev(&st_rdev, vattr.va_rdev) ||
417 	    vattr.va_size > MAXOFF32_T ||
418 	    vattr.va_nblocks > INT32_MAX ||
419 	    vattr.va_nodeid > UINT32_MAX ||
420 	    TIMESPEC_OVERFLOW(&(vattr.va_atime)) ||
421 	    TIMESPEC_OVERFLOW(&(vattr.va_mtime)) ||
422 	    TIMESPEC_OVERFLOW(&(vattr.va_ctime)))
423 		return (EOVERFLOW);
424 
425 	bzero(&sb, sizeof (sb));
426 	sb.st_dev = st_dev;
427 	sb.st_ino = (ino32_t)vattr.va_nodeid;
428 	sb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
429 	sb.st_nlink = vattr.va_nlink;
430 	sb.st_uid = vattr.va_uid;
431 	sb.st_gid = vattr.va_gid;
432 	sb.st_rdev = st_rdev;
433 	sb.st_size = (off32_t)vattr.va_size;
434 	TIMESPEC_TO_TIMESPEC32(&(sb.st_atim), &(vattr.va_atime));
435 	TIMESPEC_TO_TIMESPEC32(&(sb.st_mtim), &(vattr.va_mtime));
436 	TIMESPEC_TO_TIMESPEC32(&(sb.st_ctim), &(vattr.va_ctime));
437 	sb.st_blksize = vattr.va_blksize;
438 	sb.st_blocks = (blkcnt32_t)vattr.va_nblocks;
439 	if (vp->v_vfsp != NULL) {
440 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
441 		if (vswp->vsw_name && *vswp->vsw_name)
442 			(void) strcpy(sb.st_fstype, vswp->vsw_name);
443 	}
444 	if (copyout(&sb, ubp, sizeof (sb)))
445 		return (EFAULT);
446 	return (0);
447 }
448 
449 static int
450 cstatat32(int fd, char *name, int nmflag, struct stat32 *sb,
451     int follow, int flags)
452 {
453 	vnode_t *vp;
454 	int error;
455 	cred_t *cred;
456 	int link_follow;
457 	int estale_retry = 0;
458 
459 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
460 lookup:
461 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
462 		return (set_errno(error));
463 	error = cstat32(vp, sb, flags, cred);
464 	crfree(cred);
465 	VN_RELE(vp);
466 out:
467 	if (error != 0) {
468 		if (error == ESTALE &&
469 		    fs_need_estale_retry(estale_retry++) &&
470 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
471 			goto lookup;
472 		return (set_errno(error));
473 	}
474 	return (0);
475 }
476 
477 #endif	/* _SYSCALL32_IMPL */
478 
479 #if defined(_ILP32)
480 
481 /*
482  * 32-bit kernel, 32-bit applications, 64-bit file offsets.
483  *
484  * These routines are implemented differently on 64-bit kernels.
485  */
486 static int cstatat64(int, char *, int, struct stat64 *, int, int);
487 static int cstat64(vnode_t *, struct stat64 *, int, cred_t *);
488 
489 int
490 stat64(char *fname, struct stat64 *sb)
491 {
492 	return (cstatat64(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
493 }
494 
495 int
496 lstat64(char *fname, struct stat64 *sb)
497 {
498 	return (cstatat64(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
499 }
500 
501 int
502 fstat64(int fd, struct stat64 *sb)
503 {
504 	FSTAT_BODY(fd, sb, cstat64)
505 }
506 
507 int
508 fstatat64(int fd, char *name, struct stat64 *sb, int flags)
509 {
510 	return (cstatat64(fd, name, 2, sb,
511 	    flags & AT_SYMLINK_NOFOLLOW ? AT_SYMLINK_NOFOLLOW : 0,
512 	    flags & _AT_TRIGGER ? ATTR_TRIGGER : 0));
513 }
514 
515 static int
516 cstat64(vnode_t *vp, struct stat64 *ubp, int flag, cred_t *cr)
517 {
518 	struct vfssw *vswp;
519 	struct stat64 lsb;
520 	vattr_t vattr;
521 	int error;
522 
523 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
524 	if (error = VOP_GETATTR(vp, &vattr, flag, cr))
525 		return (error);
526 
527 	bzero(&lsb, sizeof (lsb));
528 	lsb.st_dev = vattr.va_fsid;
529 	lsb.st_ino = vattr.va_nodeid;
530 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
531 	lsb.st_nlink = vattr.va_nlink;
532 	lsb.st_uid = vattr.va_uid;
533 	lsb.st_gid = vattr.va_gid;
534 	lsb.st_rdev = vattr.va_rdev;
535 	lsb.st_size = vattr.va_size;
536 	lsb.st_atim = vattr.va_atime;
537 	lsb.st_mtim = vattr.va_mtime;
538 	lsb.st_ctim = vattr.va_ctime;
539 	lsb.st_blksize = vattr.va_blksize;
540 	lsb.st_blocks = vattr.va_nblocks;
541 	if (vp->v_vfsp != NULL) {
542 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
543 		if (vswp->vsw_name && *vswp->vsw_name)
544 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
545 	}
546 	if (copyout(&lsb, ubp, sizeof (lsb)))
547 		return (EFAULT);
548 	return (0);
549 }
550 
551 static int
552 cstatat64(int fd, char *name, int nmflag, struct stat64 *sb,
553     int follow, int flags)
554 {
555 	vnode_t *vp;
556 	int error;
557 	cred_t *cred;
558 	int link_follow;
559 	int estale_retry = 0;
560 
561 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
562 lookup:
563 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
564 		return (set_errno(error));
565 	error = cstat64(vp, sb, flags, cred);
566 	crfree(cred);
567 	VN_RELE(vp);
568 out:
569 	if (error != 0) {
570 		if (error == ESTALE &&
571 		    fs_need_estale_retry(estale_retry++) &&
572 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
573 			goto lookup;
574 		return (set_errno(error));
575 	}
576 	return (0);
577 }
578 
579 #endif	/* _ILP32 */
580 
581 #if defined(_SYSCALL32_IMPL)
582 
583 /*
584  * 64-bit kernel, 32-bit applications, 64-bit file offsets.
585  *
586  * We'd really like to call the "native" stat calls for these ones,
587  * but the problem is that the 64-bit ABI defines the 'stat64' structure
588  * differently from the way the 32-bit ABI defines it.
589  */
590 
591 static int cstatat64_32(int, char *, int, struct stat64_32 *, int, int);
592 static int cstat64_32(vnode_t *, struct stat64_32 *, int, cred_t *);
593 
594 int
595 stat64_32(char *fname, struct stat64_32 *sb)
596 {
597 	return (cstatat64_32(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
598 }
599 
600 int
601 lstat64_32(char *fname, struct stat64_32 *sb)
602 {
603 	return (cstatat64_32(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
604 }
605 
606 int
607 fstat64_32(int fd, struct stat64_32 *sb)
608 {
609 	FSTAT_BODY(fd, sb, cstat64_32)
610 }
611 
612 int
613 fstatat64_32(int fd, char *name, struct stat64_32 *sb, int flags)
614 {
615 	return (cstatat64_32(fd, name, 2, sb,
616 	    flags & AT_SYMLINK_NOFOLLOW ? AT_SYMLINK_NOFOLLOW : 0,
617 	    flags & _AT_TRIGGER ? ATTR_TRIGGER : 0));
618 }
619 
620 static int
621 cstat64_32(vnode_t *vp, struct stat64_32 *ubp, int flag, cred_t *cr)
622 {
623 	struct vfssw *vswp;
624 	struct stat64_32 lsb;
625 	vattr_t vattr;
626 	int error;
627 	dev32_t st_dev, st_rdev;
628 
629 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
630 	if (error = VOP_GETATTR(vp, &vattr, flag, cr))
631 		return (error);
632 
633 	if (!cmpldev(&st_dev, vattr.va_fsid) ||
634 	    !cmpldev(&st_rdev, vattr.va_rdev) ||
635 	    TIMESPEC_OVERFLOW(&(vattr.va_atime)) ||
636 	    TIMESPEC_OVERFLOW(&(vattr.va_mtime)) ||
637 	    TIMESPEC_OVERFLOW(&(vattr.va_ctime)))
638 		return (EOVERFLOW);
639 
640 	bzero(&lsb, sizeof (lsb));
641 	lsb.st_dev = st_dev;
642 	lsb.st_ino = vattr.va_nodeid;
643 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
644 	lsb.st_nlink = vattr.va_nlink;
645 	lsb.st_uid = vattr.va_uid;
646 	lsb.st_gid = vattr.va_gid;
647 	lsb.st_rdev = st_rdev;
648 	lsb.st_size = vattr.va_size;
649 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_atim), &(vattr.va_atime));
650 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_mtim), &(vattr.va_mtime));
651 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_ctim), &(vattr.va_ctime));
652 	lsb.st_blksize = vattr.va_blksize;
653 	lsb.st_blocks = vattr.va_nblocks;
654 	if (vp->v_vfsp != NULL) {
655 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
656 		if (vswp->vsw_name && *vswp->vsw_name)
657 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
658 	}
659 	if (copyout(&lsb, ubp, sizeof (lsb)))
660 		return (EFAULT);
661 	return (0);
662 }
663 
664 static int
665 cstatat64_32(int fd, char *name, int nmflag, struct stat64_32 *sb,
666     int follow, int flags)
667 {
668 	vnode_t  *vp;
669 	int error;
670 	cred_t *cred;
671 	int link_follow;
672 	int estale_retry = 0;
673 
674 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
675 lookup:
676 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
677 		return (set_errno(error));
678 	error = cstat64_32(vp, sb, flags, cred);
679 	crfree(cred);
680 	VN_RELE(vp);
681 out:
682 	if (error != 0) {
683 		if (error == ESTALE &&
684 		    fs_need_estale_retry(estale_retry++) &&
685 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
686 			goto lookup;
687 		return (set_errno(error));
688 	}
689 	return (0);
690 }
691 
692 #endif /* _SYSCALL32_IMPL */
693