xref: /titanic_51/usr/src/uts/common/syscall/stat.c (revision f6485eec0b33b15e863ae352c5279913ed8e6d29)
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, NULL)) != 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 int
343 stat32(char *fname, struct stat32 *sb)
344 {
345 	return (cstatat32(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
346 }
347 
348 int
349 lstat32(char *fname, struct stat32 *sb)
350 {
351 	return (cstatat32(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
352 }
353 
354 int
355 fstat32(int fd, struct stat32 *sb)
356 {
357 	FSTAT_BODY(fd, sb, cstat32)
358 }
359 
360 int
361 fstatat32(int fd, char *name, struct stat32 *sb, int flags)
362 {
363 	return (cstatat32(fd, name, 2, sb,
364 	    flags & AT_SYMLINK_NOFOLLOW ? AT_SYMLINK_NOFOLLOW : 0,
365 	    flags & _AT_TRIGGER ? ATTR_TRIGGER : 0));
366 }
367 
368 #if defined(__i386_COMPAT)
369 
370 /*
371  * Syscalls for i386 applications that issue {,l,f}xstat() directly
372  */
373 int
374 xstat32(int version, char *fname, struct stat32 *sb)
375 {
376 	XSTAT_BODY(version, fname, sb, stat32)
377 }
378 
379 int
380 lxstat32(int version, char *fname, struct stat32 *sb)
381 {
382 	XSTAT_BODY(version, fname, sb, lstat32)
383 }
384 
385 int
386 fxstat32(int version, int fd, struct stat32 *sb)
387 {
388 	XSTAT_BODY(version, fd, sb, fstat32)
389 }
390 
391 #endif	/* __i386_COMPAT */
392 
393 static int
394 cstat32(vnode_t *vp, struct stat32 *ubp, int flag, struct cred *cr)
395 {
396 	struct vfssw *vswp;
397 	struct stat32 sb;
398 	vattr_t vattr;
399 	int error;
400 	dev32_t st_dev, st_rdev;
401 
402 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
403 	if (error = VOP_GETATTR(vp, &vattr, flag, cr, NULL))
404 		return (error);
405 
406 	/* devices are a special case, see comments in cstat */
407 	if ((vattr.va_size > MAXOFF32_T) &&
408 	    ((vp->v_type == VBLK) || (vp->v_type == VCHR))) {
409 		/* OVERFLOW | UNKNOWN_SIZE */
410 		vattr.va_size = MAXOFF32_T;
411 	}
412 
413 	/* check for large values */
414 	if (!cmpldev(&st_dev, vattr.va_fsid) ||
415 	    !cmpldev(&st_rdev, vattr.va_rdev) ||
416 	    vattr.va_size > MAXOFF32_T ||
417 	    vattr.va_nblocks > INT32_MAX ||
418 	    vattr.va_nodeid > UINT32_MAX ||
419 	    TIMESPEC_OVERFLOW(&(vattr.va_atime)) ||
420 	    TIMESPEC_OVERFLOW(&(vattr.va_mtime)) ||
421 	    TIMESPEC_OVERFLOW(&(vattr.va_ctime)))
422 		return (EOVERFLOW);
423 
424 	bzero(&sb, sizeof (sb));
425 	sb.st_dev = st_dev;
426 	sb.st_ino = (ino32_t)vattr.va_nodeid;
427 	sb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
428 	sb.st_nlink = vattr.va_nlink;
429 	sb.st_uid = vattr.va_uid;
430 	sb.st_gid = vattr.va_gid;
431 	sb.st_rdev = st_rdev;
432 	sb.st_size = (off32_t)vattr.va_size;
433 	TIMESPEC_TO_TIMESPEC32(&(sb.st_atim), &(vattr.va_atime));
434 	TIMESPEC_TO_TIMESPEC32(&(sb.st_mtim), &(vattr.va_mtime));
435 	TIMESPEC_TO_TIMESPEC32(&(sb.st_ctim), &(vattr.va_ctime));
436 	sb.st_blksize = vattr.va_blksize;
437 	sb.st_blocks = (blkcnt32_t)vattr.va_nblocks;
438 	if (vp->v_vfsp != NULL) {
439 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
440 		if (vswp->vsw_name && *vswp->vsw_name)
441 			(void) strcpy(sb.st_fstype, vswp->vsw_name);
442 	}
443 	if (copyout(&sb, ubp, sizeof (sb)))
444 		return (EFAULT);
445 	return (0);
446 }
447 
448 static int
449 cstatat32(int fd, char *name, int nmflag, struct stat32 *sb,
450     int follow, int flags)
451 {
452 	vnode_t *vp;
453 	int error;
454 	cred_t *cred;
455 	int link_follow;
456 	int estale_retry = 0;
457 
458 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
459 lookup:
460 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
461 		return (set_errno(error));
462 	error = cstat32(vp, sb, flags, cred);
463 	crfree(cred);
464 	VN_RELE(vp);
465 out:
466 	if (error != 0) {
467 		if (error == ESTALE &&
468 		    fs_need_estale_retry(estale_retry++) &&
469 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
470 			goto lookup;
471 		return (set_errno(error));
472 	}
473 	return (0);
474 }
475 
476 #endif	/* _SYSCALL32_IMPL */
477 
478 #if defined(_ILP32)
479 
480 /*
481  * 32-bit kernel, 32-bit applications, 64-bit file offsets.
482  *
483  * These routines are implemented differently on 64-bit kernels.
484  */
485 static int cstatat64(int, char *, int, struct stat64 *, int, int);
486 static int cstat64(vnode_t *, struct stat64 *, int, cred_t *);
487 
488 int
489 stat64(char *fname, struct stat64 *sb)
490 {
491 	return (cstatat64(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
492 }
493 
494 int
495 lstat64(char *fname, struct stat64 *sb)
496 {
497 	return (cstatat64(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
498 }
499 
500 int
501 fstat64(int fd, struct stat64 *sb)
502 {
503 	FSTAT_BODY(fd, sb, cstat64)
504 }
505 
506 int
507 fstatat64(int fd, char *name, struct stat64 *sb, int flags)
508 {
509 	return (cstatat64(fd, name, 2, sb,
510 	    flags & AT_SYMLINK_NOFOLLOW ? AT_SYMLINK_NOFOLLOW : 0,
511 	    flags & _AT_TRIGGER ? ATTR_TRIGGER : 0));
512 }
513 
514 static int
515 cstat64(vnode_t *vp, struct stat64 *ubp, int flag, cred_t *cr)
516 {
517 	struct vfssw *vswp;
518 	struct stat64 lsb;
519 	vattr_t vattr;
520 	int error;
521 
522 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
523 	if (error = VOP_GETATTR(vp, &vattr, flag, cr, NULL))
524 		return (error);
525 
526 	bzero(&lsb, sizeof (lsb));
527 	lsb.st_dev = vattr.va_fsid;
528 	lsb.st_ino = vattr.va_nodeid;
529 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
530 	lsb.st_nlink = vattr.va_nlink;
531 	lsb.st_uid = vattr.va_uid;
532 	lsb.st_gid = vattr.va_gid;
533 	lsb.st_rdev = vattr.va_rdev;
534 	lsb.st_size = vattr.va_size;
535 	lsb.st_atim = vattr.va_atime;
536 	lsb.st_mtim = vattr.va_mtime;
537 	lsb.st_ctim = vattr.va_ctime;
538 	lsb.st_blksize = vattr.va_blksize;
539 	lsb.st_blocks = vattr.va_nblocks;
540 	if (vp->v_vfsp != NULL) {
541 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
542 		if (vswp->vsw_name && *vswp->vsw_name)
543 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
544 	}
545 	if (copyout(&lsb, ubp, sizeof (lsb)))
546 		return (EFAULT);
547 	return (0);
548 }
549 
550 static int
551 cstatat64(int fd, char *name, int nmflag, struct stat64 *sb,
552     int follow, int flags)
553 {
554 	vnode_t *vp;
555 	int error;
556 	cred_t *cred;
557 	int link_follow;
558 	int estale_retry = 0;
559 
560 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
561 lookup:
562 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
563 		return (set_errno(error));
564 	error = cstat64(vp, sb, flags, cred);
565 	crfree(cred);
566 	VN_RELE(vp);
567 out:
568 	if (error != 0) {
569 		if (error == ESTALE &&
570 		    fs_need_estale_retry(estale_retry++) &&
571 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
572 			goto lookup;
573 		return (set_errno(error));
574 	}
575 	return (0);
576 }
577 
578 #endif	/* _ILP32 */
579 
580 #if defined(_SYSCALL32_IMPL)
581 
582 /*
583  * 64-bit kernel, 32-bit applications, 64-bit file offsets.
584  *
585  * We'd really like to call the "native" stat calls for these ones,
586  * but the problem is that the 64-bit ABI defines the 'stat64' structure
587  * differently from the way the 32-bit ABI defines it.
588  */
589 
590 static int cstatat64_32(int, char *, int, struct stat64_32 *, int, int);
591 static int cstat64_32(vnode_t *, struct stat64_32 *, int, cred_t *);
592 
593 int
594 stat64_32(char *fname, struct stat64_32 *sb)
595 {
596 	return (cstatat64_32(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
597 }
598 
599 int
600 lstat64_32(char *fname, struct stat64_32 *sb)
601 {
602 	return (cstatat64_32(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
603 }
604 
605 int
606 fstat64_32(int fd, struct stat64_32 *sb)
607 {
608 	FSTAT_BODY(fd, sb, cstat64_32)
609 }
610 
611 int
612 fstatat64_32(int fd, char *name, struct stat64_32 *sb, int flags)
613 {
614 	return (cstatat64_32(fd, name, 2, sb,
615 	    flags & AT_SYMLINK_NOFOLLOW ? AT_SYMLINK_NOFOLLOW : 0,
616 	    flags & _AT_TRIGGER ? ATTR_TRIGGER : 0));
617 }
618 
619 static int
620 cstat64_32(vnode_t *vp, struct stat64_32 *ubp, int flag, cred_t *cr)
621 {
622 	struct vfssw *vswp;
623 	struct stat64_32 lsb;
624 	vattr_t vattr;
625 	int error;
626 	dev32_t st_dev, st_rdev;
627 
628 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
629 	if (error = VOP_GETATTR(vp, &vattr, flag, cr, NULL))
630 		return (error);
631 
632 	if (!cmpldev(&st_dev, vattr.va_fsid) ||
633 	    !cmpldev(&st_rdev, vattr.va_rdev) ||
634 	    TIMESPEC_OVERFLOW(&(vattr.va_atime)) ||
635 	    TIMESPEC_OVERFLOW(&(vattr.va_mtime)) ||
636 	    TIMESPEC_OVERFLOW(&(vattr.va_ctime)))
637 		return (EOVERFLOW);
638 
639 	bzero(&lsb, sizeof (lsb));
640 	lsb.st_dev = st_dev;
641 	lsb.st_ino = vattr.va_nodeid;
642 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
643 	lsb.st_nlink = vattr.va_nlink;
644 	lsb.st_uid = vattr.va_uid;
645 	lsb.st_gid = vattr.va_gid;
646 	lsb.st_rdev = st_rdev;
647 	lsb.st_size = vattr.va_size;
648 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_atim), &(vattr.va_atime));
649 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_mtim), &(vattr.va_mtime));
650 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_ctim), &(vattr.va_ctime));
651 	lsb.st_blksize = vattr.va_blksize;
652 	lsb.st_blocks = vattr.va_nblocks;
653 	if (vp->v_vfsp != NULL) {
654 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
655 		if (vswp->vsw_name && *vswp->vsw_name)
656 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
657 	}
658 	if (copyout(&lsb, ubp, sizeof (lsb)))
659 		return (EFAULT);
660 	return (0);
661 }
662 
663 static int
664 cstatat64_32(int fd, char *name, int nmflag, struct stat64_32 *sb,
665     int follow, int flags)
666 {
667 	vnode_t  *vp;
668 	int error;
669 	cred_t *cred;
670 	int link_follow;
671 	int estale_retry = 0;
672 
673 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
674 lookup:
675 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
676 		return (set_errno(error));
677 	error = cstat64_32(vp, sb, flags, cred);
678 	crfree(cred);
679 	VN_RELE(vp);
680 out:
681 	if (error != 0) {
682 		if (error == ESTALE &&
683 		    fs_need_estale_retry(estale_retry++) &&
684 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
685 			goto lookup;
686 		return (set_errno(error));
687 	}
688 	return (0);
689 }
690 
691 #endif /* _SYSCALL32_IMPL */
692