pathconf.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
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, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28/*	  All Rights Reserved  	*/
29
30/*
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
33 */
34
35#pragma ident	"%Z%%M%	%I%	%E% SMI"
36
37#include <sys/param.h>
38#include <sys/isa_defs.h>
39#include <sys/types.h>
40#include <sys/sysmacros.h>
41#include <sys/cred.h>
42#include <sys/systm.h>
43#include <sys/errno.h>
44#include <sys/pathname.h>
45#include <sys/vnode.h>
46#include <sys/vfs.h>
47#include <sys/file.h>
48#include <sys/uio.h>
49#include <sys/debug.h>
50
51/*
52 * Common code for pathconf(), fpathconf() system calls
53 */
54static long
55cpathconf(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))
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)))
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))
89			return ((long)set_errno(error));
90		return (val);
91	}
92	/* NOTREACHED */
93}
94
95/* fpathconf/pathconf interfaces */
96
97long
98fpathconf(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
110long
111pathconf(char *fname, int name)
112{
113	vnode_t *vp;
114	long	retval;
115	int	error;
116
117lookup:
118	if (error = lookupname(fname, UIO_USERSPACE, FOLLOW, NULLVPP, &vp)) {
119		if (error == ESTALE)
120			goto lookup;
121		return ((long)set_errno(error));
122	}
123
124	retval = cpathconf(vp, name, CRED());
125	VN_RELE(vp);
126	return (retval);
127}
128