xref: /illumos-gate/usr/src/uts/common/sys/pathname.h (revision b4203d75)
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 /*
23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
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 #ifndef _SYS_PATHNAME_H
35 #define	_SYS_PATHNAME_H
36 
37 #include <sys/vnode.h>
38 #include <sys/cred.h>
39 #include <sys/uio.h>
40 #include <sys/dirent.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * Pathname structure.
48  * System calls that operate on path names gather the path name
49  * from the system call into this structure and reduce it by
50  * peeling off translated components.  If a symbolic link is
51  * encountered the new path name to be translated is also
52  * assembled in this structure.
53  *
54  * By convention pn_buf is not changed once it's been set to point
55  * to the underlying storage; routines which manipulate the pathname
56  * do so by changing pn_path and pn_pathlen.  pn_pathlen is redundant
57  * since the path name is null-terminated, but is provided to make
58  * some computations faster.
59  */
60 typedef struct pathname {
61 	char	*pn_buf;		/* underlying storage */
62 	char	*pn_path;		/* remaining pathname */
63 	size_t	pn_pathlen;		/* remaining length */
64 	size_t	pn_bufsize;		/* total size of pn_buf */
65 } pathname_t;
66 
67 #define	pn_pathleft(pnp)	((pnp)->pn_pathlen)
68 
69 extern void	pn_alloc(struct pathname *);
70 extern void	pn_alloc_sz(struct pathname *, size_t);
71 extern int	pn_get(char *, enum uio_seg, struct pathname *);
72 extern int	pn_get_buf(char *, enum uio_seg, struct pathname *,
73 			void *, size_t);
74 extern int	pn_set(struct pathname *, char *);
75 extern int	pn_insert(struct pathname *, struct pathname *, size_t);
76 extern int	pn_getsymlink(vnode_t *, struct pathname *, cred_t *);
77 extern int	pn_getcomponent(struct pathname *, char *);
78 extern void	pn_setlast(struct pathname *);
79 extern void	pn_skipslash(struct pathname *);
80 extern int	pn_fixslash(struct pathname *);
81 extern int	pn_addslash(struct pathname *);
82 extern void	pn_free(struct pathname *);
83 
84 extern int lookupname(char *, enum uio_seg, int follow,
85 		vnode_t **, vnode_t **);
86 extern int lookupnameat(char *, enum uio_seg, int follow,
87 		vnode_t **, vnode_t **, vnode_t *);
88 extern int lookupnameatcred(char *, enum uio_seg, int follow,
89 		vnode_t **, vnode_t **, vnode_t *, cred_t *);
90 extern int lookuppn(struct pathname *, struct pathname *, int follow,
91 		vnode_t **, vnode_t **);
92 extern int lookuppnat(struct pathname *, struct pathname *, int follow,
93 		vnode_t **, vnode_t **, vnode_t *);
94 extern int lookuppnatcred(struct pathname *, struct pathname *, int follow,
95 		vnode_t **, vnode_t **, vnode_t *, cred_t *);
96 
97 extern int lookuppnvp(struct pathname *, struct pathname *, int follow,
98 		vnode_t **, vnode_t **, vnode_t *, vnode_t *, cred_t *);
99 extern int traverse(vnode_t **);
100 
101 extern int vnodetopath(vnode_t *, vnode_t *, char *, size_t, cred_t *);
102 extern int dogetcwd(char *, size_t);
103 extern int dirfindvp(vnode_t *, vnode_t *, vnode_t *, cred_t *, char *,
104 		size_t, dirent64_t **);
105 
106 #ifdef	__cplusplus
107 }
108 #endif
109 
110 #endif	/* _SYS_PATHNAME_H */
111