xref: /titanic_52/usr/src/uts/common/syscall/pathconf.c (revision 67e3a03ed4a2813074d36330f062ed6e593a4937)
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 #include <sys/param.h>
37 #include <sys/isa_defs.h>
38 #include <sys/types.h>
39 #include <sys/sysmacros.h>
40 #include <sys/cred.h>
41 #include <sys/systm.h>
42 #include <sys/errno.h>
43 #include <sys/pathname.h>
44 #include <sys/vnode.h>
45 #include <sys/vfs.h>
46 #include <sys/file.h>
47 #include <sys/uio.h>
48 #include <sys/debug.h>
49 #include <fs/fs_subr.h>
50 
51 /*
52  * Common code for pathconf(), fpathconf() system calls
53  */
54 static long
55 cpathconf(register vnode_t *vp, int cmd, struct cred *cr)
56 {
57 	int error;
58 	ulong_t val;
59 
60 	switch (cmd) {
61 	case _PC_2_SYMLINKS:
62 		if (error = VOP_PATHCONF(vp, _PC_SYMLINK_MAX, &val, cr, NULL))
63 			return ((long)set_errno(error));
64 		return ((long)(val > 0));
65 
66 	case _PC_ALLOC_SIZE_MIN:
67 	case _PC_REC_INCR_XFER_SIZE:
68 	case _PC_REC_MAX_XFER_SIZE:
69 	case _PC_REC_MIN_XFER_SIZE:
70 	case _PC_REC_XFER_ALIGN:
71 		return ((long)set_errno(EINVAL));
72 
73 	case _PC_ASYNC_IO:
74 		return (1l);
75 
76 	case _PC_PRIO_IO:
77 		return ((long)set_errno(EINVAL));
78 
79 	case _PC_SYNC_IO:
80 		if (!(error = VOP_FSYNC(vp, FSYNC, cr, NULL)))
81 			return (1l);
82 		return ((long)set_errno(error));
83 
84 	case _PC_XATTR_ENABLED:
85 		return ((vp->v_vfsp->vfs_flag & VFS_XATTR) ? 1 : 0);
86 
87 	default:
88 		if (error = VOP_PATHCONF(vp, cmd, &val, cr, NULL))
89 			return ((long)set_errno(error));
90 		return (val);
91 	}
92 	/* NOTREACHED */
93 }
94 
95 /* fpathconf/pathconf interfaces */
96 
97 long
98 fpathconf(int fdes, int name)
99 {
100 	file_t *fp;
101 	long retval;
102 
103 	if ((fp = getf(fdes)) == NULL)
104 		return (set_errno(EBADF));
105 	retval = cpathconf(fp->f_vnode, name, fp->f_cred);
106 	releasef(fdes);
107 	return (retval);
108 }
109 
110 long
111 pathconf(char *fname, int name)
112 {
113 	vnode_t *vp;
114 	long	retval;
115 	int	error;
116 	int 	estale_retry = 0;
117 
118 lookup:
119 	if (error = lookupname(fname, UIO_USERSPACE, FOLLOW, NULLVPP, &vp)) {
120 		if ((error == ESTALE) && fs_need_estale_retry(estale_retry++))
121 			goto lookup;
122 		return ((long)set_errno(error));
123 	}
124 
125 	retval = cpathconf(vp, name, CRED());
126 	VN_RELE(vp);
127 	return (retval);
128 }
129