xref: /titanic_51/usr/src/uts/common/syscall/stat.c (revision 8a40a695ee676a322b094e9afe5375567bfb51e3)
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 2006 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, flags, 0));
200 }
201 
202 #if defined(__i386) || defined(__i386_COMPAT)
203 
204 /*
205  * Handle all the "extended" stat operations in the same way;
206  * validate the version, then call the real handler.
207  */
208 
209 #define	XSTAT_BODY(ver, f, s, fn)			\
210 	return (ver != _STAT_VER ? set_errno(EINVAL) : fn(f, s));
211 
212 #endif	/* __i386 || __i386_COMPAT */
213 
214 #if defined(__i386)
215 
216 /*
217  * Syscalls for i386 applications that issue {,l,f}xstat() directly
218  */
219 int
220 xstat(int version, char *fname, struct stat *sb)
221 {
222 	XSTAT_BODY(version, fname, sb, stat)
223 }
224 
225 int
226 lxstat(int version, char *fname, struct stat *sb)
227 {
228 	XSTAT_BODY(version, fname, sb, lstat)
229 }
230 
231 int
232 fxstat(int version, int fd, struct stat *sb)
233 {
234 	XSTAT_BODY(version, fd, sb, fstat)
235 }
236 
237 #endif	/* __i386 */
238 
239 /*
240  * Common code for stat(), lstat(), and fstat().
241  * (32-bit kernel, 32-bit applications, 32-bit files)
242  * (64-bit kernel, 64-bit applications, 64-bit files)
243  */
244 static int
245 cstat(vnode_t *vp, struct stat *ubp, int flag, cred_t *cr)
246 {
247 	struct vfssw *vswp;
248 	struct stat sb;
249 	vattr_t vattr;
250 	int error;
251 
252 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
253 	if ((error = VOP_GETATTR(vp, &vattr, flag, cr)) != 0)
254 		return (error);
255 #ifdef	_ILP32
256 	/*
257 	 * (32-bit kernel, 32-bit applications, 32-bit files)
258 	 * NOTE: 32-bit kernel maintains a 64-bit unsigend va_size.
259 	 *
260 	 * st_size of devices (VBLK and VCHR special files) is a special case.
261 	 * POSIX does not define size behavior for special files, so the
262 	 * following Solaris specific behavior is not a violation. Solaris
263 	 * returns the size of the device.
264 	 *
265 	 * For compatibility with 32-bit programs which happen to do stat() on
266 	 * a (mknod) bigger than 2GB we suppress the large file EOVERFLOW and
267 	 * instead we return the value MAXOFF32_T (LONG_MAX).
268 	 *
269 	 * 32-bit applications that care about the size of devices should be
270 	 * built 64-bit or use a large file interface (lfcompile(5) or lf64(5)).
271 	 */
272 	if ((vattr.va_size > MAXOFF32_T) &&
273 	    ((vp->v_type == VBLK) || (vp->v_type == VCHR))) {
274 		/* OVERFLOW | UNKNOWN_SIZE */
275 		vattr.va_size = MAXOFF32_T;
276 	}
277 #endif	/* _ILP32 */
278 	if (vattr.va_size > MAXOFF_T || vattr.va_nblocks > LONG_MAX ||
279 	    vattr.va_nodeid > ULONG_MAX)
280 		return (EOVERFLOW);
281 
282 	bzero(&sb, sizeof (sb));
283 	sb.st_dev = vattr.va_fsid;
284 	sb.st_ino = (ino_t)vattr.va_nodeid;
285 	sb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
286 	sb.st_nlink = vattr.va_nlink;
287 	sb.st_uid = vattr.va_uid;
288 	sb.st_gid = vattr.va_gid;
289 	sb.st_rdev = vattr.va_rdev;
290 	sb.st_size = (off_t)vattr.va_size;
291 	sb.st_atim = vattr.va_atime;
292 	sb.st_mtim = vattr.va_mtime;
293 	sb.st_ctim = vattr.va_ctime;
294 	sb.st_blksize = vattr.va_blksize;
295 	sb.st_blocks = (blkcnt_t)vattr.va_nblocks;
296 	if (vp->v_vfsp != NULL) {
297 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
298 		if (vswp->vsw_name && *vswp->vsw_name)
299 			(void) strcpy(sb.st_fstype, vswp->vsw_name);
300 	}
301 	if (copyout(&sb, ubp, sizeof (sb)))
302 		return (EFAULT);
303 	return (0);
304 }
305 
306 static int
307 cstatat(int fd, char *name, int nmflag, struct stat *sb, int follow, int flags)
308 {
309 	vnode_t *vp;
310 	int error;
311 	cred_t *cred;
312 	int link_follow;
313 	int estale_retry = 0;
314 
315 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
316 lookup:
317 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
318 		return (set_errno(error));
319 	error = cstat(vp, sb, flags, cred);
320 	crfree(cred);
321 	VN_RELE(vp);
322 out:
323 	if (error != 0) {
324 		if (error == ESTALE &&
325 		    fs_need_estale_retry(estale_retry++) &&
326 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
327 			goto lookup;
328 		return (set_errno(error));
329 	}
330 	return (0);
331 }
332 
333 #if defined(_SYSCALL32_IMPL)
334 
335 /*
336  * 64-bit kernel, 32-bit applications, 32-bit file offsets
337  */
338 static int cstatat32(int, char *, int, struct stat32 *, int, int);
339 static int cstat32(vnode_t *, struct stat32 *, int, cred_t *);
340 
341 int
342 stat32(char *fname, struct stat32 *sb)
343 {
344 	return (cstatat32(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
345 }
346 
347 int
348 lstat32(char *fname, struct stat32 *sb)
349 {
350 	return (cstatat32(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
351 }
352 
353 int
354 fstat32(int fd, struct stat32 *sb)
355 {
356 	FSTAT_BODY(fd, sb, cstat32)
357 }
358 
359 int
360 fstatat32(int fd, char *name, struct stat32 *sb, int flag)
361 {
362 	return (cstatat32(fd, name, 2, sb, flag, 0));
363 }
364 
365 #if defined(__i386_COMPAT)
366 
367 /*
368  * Syscalls for i386 applications that issue {,l,f}xstat() directly
369  */
370 int
371 xstat32(int version, char *fname, struct stat32 *sb)
372 {
373 	XSTAT_BODY(version, fname, sb, stat32)
374 }
375 
376 int
377 lxstat32(int version, char *fname, struct stat32 *sb)
378 {
379 	XSTAT_BODY(version, fname, sb, lstat32)
380 }
381 
382 int
383 fxstat32(int version, int fd, struct stat32 *sb)
384 {
385 	XSTAT_BODY(version, fd, sb, fstat32)
386 }
387 
388 #endif	/* __i386_COMPAT */
389 
390 static int
391 cstat32(vnode_t *vp, struct stat32 *ubp, int flag, struct cred *cr)
392 {
393 	struct vfssw *vswp;
394 	struct stat32 sb;
395 	vattr_t vattr;
396 	int error;
397 	dev32_t st_dev, st_rdev;
398 
399 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
400 	if (error = VOP_GETATTR(vp, &vattr, flag, cr))
401 		return (error);
402 
403 	/* devices are a special case, see comments in cstat */
404 	if ((vattr.va_size > MAXOFF32_T) &&
405 	    ((vp->v_type == VBLK) || (vp->v_type == VCHR))) {
406 		/* OVERFLOW | UNKNOWN_SIZE */
407 		vattr.va_size = MAXOFF32_T;
408 	}
409 
410 	/* check for large values */
411 	if (!cmpldev(&st_dev, vattr.va_fsid) ||
412 	    !cmpldev(&st_rdev, vattr.va_rdev) ||
413 	    vattr.va_size > MAXOFF32_T ||
414 	    vattr.va_nblocks > INT32_MAX ||
415 	    vattr.va_nodeid > UINT32_MAX ||
416 	    TIMESPEC_OVERFLOW(&(vattr.va_atime)) ||
417 	    TIMESPEC_OVERFLOW(&(vattr.va_mtime)) ||
418 	    TIMESPEC_OVERFLOW(&(vattr.va_ctime)))
419 		return (EOVERFLOW);
420 
421 	bzero(&sb, sizeof (sb));
422 	sb.st_dev = st_dev;
423 	sb.st_ino = (ino32_t)vattr.va_nodeid;
424 	sb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
425 	sb.st_nlink = vattr.va_nlink;
426 	sb.st_uid = vattr.va_uid;
427 	sb.st_gid = vattr.va_gid;
428 	sb.st_rdev = st_rdev;
429 	sb.st_size = (off32_t)vattr.va_size;
430 	TIMESPEC_TO_TIMESPEC32(&(sb.st_atim), &(vattr.va_atime));
431 	TIMESPEC_TO_TIMESPEC32(&(sb.st_mtim), &(vattr.va_mtime));
432 	TIMESPEC_TO_TIMESPEC32(&(sb.st_ctim), &(vattr.va_ctime));
433 	sb.st_blksize = vattr.va_blksize;
434 	sb.st_blocks = (blkcnt32_t)vattr.va_nblocks;
435 	if (vp->v_vfsp != NULL) {
436 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
437 		if (vswp->vsw_name && *vswp->vsw_name)
438 			(void) strcpy(sb.st_fstype, vswp->vsw_name);
439 	}
440 	if (copyout(&sb, ubp, sizeof (sb)))
441 		return (EFAULT);
442 	return (0);
443 }
444 
445 static int
446 cstatat32(int fd, char *name, int nmflag, struct stat32 *sb,
447     int follow, int flags)
448 {
449 	vnode_t *vp;
450 	int error;
451 	cred_t *cred;
452 	int link_follow;
453 	int estale_retry = 0;
454 
455 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
456 lookup:
457 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
458 		return (set_errno(error));
459 	error = cstat32(vp, sb, flags, cred);
460 	crfree(cred);
461 	VN_RELE(vp);
462 out:
463 	if (error != 0) {
464 		if (error == ESTALE &&
465 		    fs_need_estale_retry(estale_retry++) &&
466 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
467 			goto lookup;
468 		return (set_errno(error));
469 	}
470 	return (0);
471 }
472 
473 #endif	/* _SYSCALL32_IMPL */
474 
475 #if defined(_ILP32)
476 
477 /*
478  * 32-bit kernel, 32-bit applications, 64-bit file offsets.
479  *
480  * These routines are implemented differently on 64-bit kernels.
481  */
482 static int cstatat64(int, char *, int, struct stat64 *, int, int);
483 static int cstat64(vnode_t *, struct stat64 *, int, cred_t *);
484 
485 int
486 stat64(char *fname, struct stat64 *sb)
487 {
488 	return (cstatat64(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
489 }
490 
491 int
492 lstat64(char *fname, struct stat64 *sb)
493 {
494 	return (cstatat64(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
495 }
496 
497 int
498 fstat64(int fd, struct stat64 *sb)
499 {
500 	FSTAT_BODY(fd, sb, cstat64)
501 }
502 
503 int
504 fstatat64(int fd, char *name, struct stat64 *sb, int flags)
505 {
506 	return (cstatat64(fd, name, 2, sb, flags, 0));
507 }
508 
509 static int
510 cstat64(vnode_t *vp, struct stat64 *ubp, int flag, cred_t *cr)
511 {
512 	struct vfssw *vswp;
513 	struct stat64 lsb;
514 	vattr_t vattr;
515 	int error;
516 
517 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
518 	if (error = VOP_GETATTR(vp, &vattr, flag, cr))
519 		return (error);
520 
521 	bzero(&lsb, sizeof (lsb));
522 	lsb.st_dev = vattr.va_fsid;
523 	lsb.st_ino = vattr.va_nodeid;
524 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
525 	lsb.st_nlink = vattr.va_nlink;
526 	lsb.st_uid = vattr.va_uid;
527 	lsb.st_gid = vattr.va_gid;
528 	lsb.st_rdev = vattr.va_rdev;
529 	lsb.st_size = vattr.va_size;
530 	lsb.st_atim = vattr.va_atime;
531 	lsb.st_mtim = vattr.va_mtime;
532 	lsb.st_ctim = vattr.va_ctime;
533 	lsb.st_blksize = vattr.va_blksize;
534 	lsb.st_blocks = vattr.va_nblocks;
535 	if (vp->v_vfsp != NULL) {
536 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
537 		if (vswp->vsw_name && *vswp->vsw_name)
538 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
539 	}
540 	if (copyout(&lsb, ubp, sizeof (lsb)))
541 		return (EFAULT);
542 	return (0);
543 }
544 
545 static int
546 cstatat64(int fd, char *name, int nmflag, struct stat64 *sb,
547     int follow, int flags)
548 {
549 	vnode_t *vp;
550 	int error;
551 	cred_t *cred;
552 	int link_follow;
553 	int estale_retry = 0;
554 
555 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
556 lookup:
557 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
558 		return (set_errno(error));
559 	error = cstat64(vp, sb, flags, cred);
560 	crfree(cred);
561 	VN_RELE(vp);
562 out:
563 	if (error != 0) {
564 		if (error == ESTALE &&
565 		    fs_need_estale_retry(estale_retry++) &&
566 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
567 			goto lookup;
568 		return (set_errno(error));
569 	}
570 	return (0);
571 }
572 
573 #endif	/* _ILP32 */
574 
575 #if defined(_SYSCALL32_IMPL)
576 
577 /*
578  * 64-bit kernel, 32-bit applications, 64-bit file offsets.
579  *
580  * We'd really like to call the "native" stat calls for these ones,
581  * but the problem is that the 64-bit ABI defines the 'stat64' structure
582  * differently from the way the 32-bit ABI defines it.
583  */
584 
585 static int cstatat64_32(int, char *, int, struct stat64_32 *, int, int);
586 static int cstat64_32(vnode_t *, struct stat64_32 *, int, cred_t *);
587 
588 int
589 stat64_32(char *fname, struct stat64_32 *sb)
590 {
591 	return (cstatat64_32(AT_FDCWD, fname, 1, sb, 0, ATTR_REAL));
592 }
593 
594 int
595 lstat64_32(char *fname, struct stat64_32 *sb)
596 {
597 	return (cstatat64_32(AT_FDCWD, fname, 1, sb, AT_SYMLINK_NOFOLLOW, 0));
598 }
599 
600 int
601 fstat64_32(int fd, struct stat64_32 *sb)
602 {
603 	FSTAT_BODY(fd, sb, cstat64_32)
604 }
605 
606 int
607 fstatat64_32(int fd, char *name, struct stat64_32 *sb, int flag)
608 {
609 	return (cstatat64_32(fd, name, 2, sb, flag, 0));
610 }
611 
612 static int
613 cstat64_32(vnode_t *vp, struct stat64_32 *ubp, int flag, cred_t *cr)
614 {
615 	struct vfssw *vswp;
616 	struct stat64_32 lsb;
617 	vattr_t vattr;
618 	int error;
619 	dev32_t st_dev, st_rdev;
620 
621 	vattr.va_mask = AT_STAT | AT_NBLOCKS | AT_BLKSIZE | AT_SIZE;
622 	if (error = VOP_GETATTR(vp, &vattr, flag, cr))
623 		return (error);
624 
625 	if (!cmpldev(&st_dev, vattr.va_fsid) ||
626 	    !cmpldev(&st_rdev, vattr.va_rdev) ||
627 	    TIMESPEC_OVERFLOW(&(vattr.va_atime)) ||
628 	    TIMESPEC_OVERFLOW(&(vattr.va_mtime)) ||
629 	    TIMESPEC_OVERFLOW(&(vattr.va_ctime)))
630 		return (EOVERFLOW);
631 
632 	bzero(&lsb, sizeof (lsb));
633 	lsb.st_dev = st_dev;
634 	lsb.st_ino = vattr.va_nodeid;
635 	lsb.st_mode = VTTOIF(vattr.va_type) | vattr.va_mode;
636 	lsb.st_nlink = vattr.va_nlink;
637 	lsb.st_uid = vattr.va_uid;
638 	lsb.st_gid = vattr.va_gid;
639 	lsb.st_rdev = st_rdev;
640 	lsb.st_size = vattr.va_size;
641 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_atim), &(vattr.va_atime));
642 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_mtim), &(vattr.va_mtime));
643 	TIMESPEC_TO_TIMESPEC32(&(lsb.st_ctim), &(vattr.va_ctime));
644 	lsb.st_blksize = vattr.va_blksize;
645 	lsb.st_blocks = vattr.va_nblocks;
646 	if (vp->v_vfsp != NULL) {
647 		vswp = &vfssw[vp->v_vfsp->vfs_fstype];
648 		if (vswp->vsw_name && *vswp->vsw_name)
649 			(void) strcpy(lsb.st_fstype, vswp->vsw_name);
650 	}
651 	if (copyout(&lsb, ubp, sizeof (lsb)))
652 		return (EFAULT);
653 	return (0);
654 }
655 
656 static int
657 cstatat64_32(int fd, char *name, int nmflag, struct stat64_32 *sb,
658     int follow, int flags)
659 {
660 	vnode_t  *vp;
661 	int error;
662 	cred_t *cred;
663 	int link_follow;
664 	int estale_retry = 0;
665 
666 	link_follow = (follow == AT_SYMLINK_NOFOLLOW) ? NO_FOLLOW : FOLLOW;
667 lookup:
668 	if (error = cstatat_getvp(fd, name, nmflag, link_follow, &vp, &cred))
669 		return (set_errno(error));
670 	error = cstat64_32(vp, sb, flags, cred);
671 	crfree(cred);
672 	VN_RELE(vp);
673 out:
674 	if (error != 0) {
675 		if (error == ESTALE &&
676 		    fs_need_estale_retry(estale_retry++) &&
677 		    (nmflag == 1 || (nmflag == 2 && name != NULL)))
678 			goto lookup;
679 		return (set_errno(error));
680 	}
681 	return (0);
682 }
683 
684 #endif /* _SYSCALL32_IMPL */
685