xref: /illumos-gate/usr/src/lib/smbsrv/libfksmbsrv/common/reparse.c (revision 2a1fd0ffe121888d44fdec321c25b53dcfaa9118)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22 /*	  All Rights Reserved  	*/
23 
24 
25 /*
26  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
27  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
28  */
29 
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/errno.h>
33 #include <sys/vnode.h>
34 #include <sys/nvpair.h>
35 #include <sys/uio.h>
36 #include <sys/kmem.h>
37 #include <fs/fs_subr.h>
38 #include <fs/fs_reparse.h>
39 
40 
41 /*
42  * support functions for reparse point
43  * copied from uts/common/fs/fs_subr.c
44  */
45 
46 /*
47  * reparse_vnode_parse
48  *
49  * Read the symlink data of a reparse point specified by the vnode
50  * and return the reparse data as name-value pair in the nvlist.
51  */
52 int
53 reparse_vnode_parse(vnode_t *vp, nvlist_t *nvl)
54 {
55 	int err;
56 	char *lkdata;
57 	struct uio uio;
58 	struct iovec iov;
59 
60 	if (vp == NULL || nvl == NULL)
61 		return (EINVAL);
62 
63 	lkdata = kmem_alloc(MAXREPARSELEN, KM_SLEEP);
64 
65 	/*
66 	 * Set up io vector to read sym link data
67 	 */
68 	iov.iov_base = lkdata;
69 	iov.iov_len = MAXREPARSELEN;
70 	uio.uio_iov = &iov;
71 	uio.uio_iovcnt = 1;
72 	uio.uio_segflg = UIO_SYSSPACE;
73 	uio.uio_extflg = UIO_COPY_CACHED;
74 	uio.uio_loffset = (offset_t)0;
75 	uio.uio_resid = MAXREPARSELEN;
76 
77 	if ((err = VOP_READLINK(vp, &uio, zone_kcred(), NULL)) == 0) {
78 		*(lkdata + MAXREPARSELEN - uio.uio_resid) = '\0';
79 		err = reparse_parse(lkdata, nvl);
80 	}
81 	kmem_free(lkdata, MAXREPARSELEN);	/* done with lkdata */
82 
83 	return (err);
84 }
85