xref: /onnv-gate/usr/src/uts/common/syscall/pathconf.c (revision 7088:87e6b40103da)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52051Sprabahar  * Common Development and Distribution License (the "License").
62051Sprabahar  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*7088Sraf 
220Sstevel@tonic-gate /*
23*7088Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
320Sstevel@tonic-gate  * under license from the Regents of the University of California.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #include <sys/param.h>
380Sstevel@tonic-gate #include <sys/isa_defs.h>
390Sstevel@tonic-gate #include <sys/types.h>
400Sstevel@tonic-gate #include <sys/sysmacros.h>
410Sstevel@tonic-gate #include <sys/cred.h>
420Sstevel@tonic-gate #include <sys/systm.h>
430Sstevel@tonic-gate #include <sys/errno.h>
440Sstevel@tonic-gate #include <sys/pathname.h>
450Sstevel@tonic-gate #include <sys/vnode.h>
460Sstevel@tonic-gate #include <sys/vfs.h>
470Sstevel@tonic-gate #include <sys/file.h>
480Sstevel@tonic-gate #include <sys/uio.h>
490Sstevel@tonic-gate #include <sys/debug.h>
502051Sprabahar #include <fs/fs_subr.h>
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * Common code for pathconf(), fpathconf() system calls
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate static long
cpathconf(register vnode_t * vp,int cmd,struct cred * cr)560Sstevel@tonic-gate cpathconf(register vnode_t *vp, int cmd, struct cred *cr)
570Sstevel@tonic-gate {
58*7088Sraf 	struct statvfs64 sb;
590Sstevel@tonic-gate 	int error;
600Sstevel@tonic-gate 	ulong_t val;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	switch (cmd) {
630Sstevel@tonic-gate 	case _PC_2_SYMLINKS:
645331Samw 		if (error = VOP_PATHCONF(vp, _PC_SYMLINK_MAX, &val, cr, NULL))
650Sstevel@tonic-gate 			return ((long)set_errno(error));
660Sstevel@tonic-gate 		return ((long)(val > 0));
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	case _PC_ALLOC_SIZE_MIN:
690Sstevel@tonic-gate 	case _PC_REC_INCR_XFER_SIZE:
700Sstevel@tonic-gate 	case _PC_REC_MAX_XFER_SIZE:
710Sstevel@tonic-gate 	case _PC_REC_MIN_XFER_SIZE:
720Sstevel@tonic-gate 	case _PC_REC_XFER_ALIGN:
73*7088Sraf 		if ((error = VFS_STATVFS(vp->v_vfsp, &sb)) != 0)
74*7088Sraf 			return ((long)set_errno(error));
75*7088Sraf 
76*7088Sraf 		/*
77*7088Sraf 		 * There is generally no harm in doing larger transfers, but
78*7088Sraf 		 * there's a point of diminishing returns.  With 1MB transfers,
79*7088Sraf 		 * even if they're random, you get very close to platter speed.
80*7088Sraf 		 * Se we return 1MB as the maximum transfer size.
81*7088Sraf 		 */
82*7088Sraf 		if (cmd == _PC_REC_MAX_XFER_SIZE)
83*7088Sraf 			return ((long)MAX(sb.f_bsize, 1UL << 20));
84*7088Sraf 
85*7088Sraf 		/*
86*7088Sraf 		 * By definition, f_frsize is the smallest filesystem block.
87*7088Sraf 		 * However, _PC_ALLOC_SIZE_MIN is intended to define the
88*7088Sraf 		 * threshold for direct I/O.  This implies two requirements:
89*7088Sraf 		 * the VM and I/O subsystems must be able to create mappings
90*7088Sraf 		 * for DMA, which requires at least page alignment; and the
91*7088Sraf 		 * filesystem must avoid read/modify/write, which generally
92*7088Sraf 		 * requires multiples of its 'preferred' blocksize, f_bsize.
93*7088Sraf 		 *
94*7088Sraf 		 * PAGESIZE alignment is sufficient for DMA and block copy.
95*7088Sraf 		 * Rounding up to the filesystem 'preferred' blocksize
96*7088Sraf 		 * works just as well.
97*7088Sraf 		 *
98*7088Sraf 		 * All together, this means that the remaining parameters
99*7088Sraf 		 * map into the same value.
100*7088Sraf 		 */
101*7088Sraf 		return ((long)MAX(sb.f_bsize, PAGESIZE));
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	case _PC_ASYNC_IO:
1040Sstevel@tonic-gate 		return (1l);
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	case _PC_PRIO_IO:
1070Sstevel@tonic-gate 		return ((long)set_errno(EINVAL));
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 	case _PC_SYNC_IO:
1105331Samw 		if (!(error = VOP_FSYNC(vp, FSYNC, cr, NULL)))
1110Sstevel@tonic-gate 			return (1l);
1120Sstevel@tonic-gate 		return ((long)set_errno(error));
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	case _PC_XATTR_ENABLED:
1150Sstevel@tonic-gate 		return ((vp->v_vfsp->vfs_flag & VFS_XATTR) ? 1 : 0);
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	default:
1185331Samw 		if (error = VOP_PATHCONF(vp, cmd, &val, cr, NULL))
1190Sstevel@tonic-gate 			return ((long)set_errno(error));
1200Sstevel@tonic-gate 		return (val);
1210Sstevel@tonic-gate 	}
1220Sstevel@tonic-gate 	/* NOTREACHED */
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate /* fpathconf/pathconf interfaces */
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate long
fpathconf(int fdes,int name)1280Sstevel@tonic-gate fpathconf(int fdes, int name)
1290Sstevel@tonic-gate {
1300Sstevel@tonic-gate 	file_t *fp;
1310Sstevel@tonic-gate 	long retval;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	if ((fp = getf(fdes)) == NULL)
1340Sstevel@tonic-gate 		return (set_errno(EBADF));
1350Sstevel@tonic-gate 	retval = cpathconf(fp->f_vnode, name, fp->f_cred);
1360Sstevel@tonic-gate 	releasef(fdes);
1370Sstevel@tonic-gate 	return (retval);
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate long
pathconf(char * fname,int name)1410Sstevel@tonic-gate pathconf(char *fname, int name)
1420Sstevel@tonic-gate {
1430Sstevel@tonic-gate 	vnode_t *vp;
1440Sstevel@tonic-gate 	long	retval;
1450Sstevel@tonic-gate 	int	error;
1462051Sprabahar 	int 	estale_retry = 0;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate lookup:
1490Sstevel@tonic-gate 	if (error = lookupname(fname, UIO_USERSPACE, FOLLOW, NULLVPP, &vp)) {
1502051Sprabahar 		if ((error == ESTALE) && fs_need_estale_retry(estale_retry++))
1510Sstevel@tonic-gate 			goto lookup;
1520Sstevel@tonic-gate 		return ((long)set_errno(error));
1530Sstevel@tonic-gate 	}
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	retval = cpathconf(vp, name, CRED());
1560Sstevel@tonic-gate 	VN_RELE(vp);
1570Sstevel@tonic-gate 	return (retval);
1580Sstevel@tonic-gate }
159