2 * Copyright (c) 2000-2001, Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $Id: smbfs_subr.c,v 1.18 2005/02/02 00:22:23 lindak Exp $
36 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
37 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
38 * Use is subject to license terms.
41 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <sys/vnode.h>
45 #include <sys/sunddi.h>
47 #include <netsmb/smb_osdep.h>
49 #include <netsmb/smb.h>
50 #include <netsmb/smb_conn.h>
51 #include <netsmb/smb_subr.h>
52 #include <netsmb/smb_rq.h>
54 #include <smbfs/smbfs.h>
55 #include <smbfs/smbfs_node.h>
56 #include <smbfs/smbfs_subr.h>
59 * In the Darwin code, this function used to compute the full path
60 * by following the chain of n_parent pointers back to the root.
61 * In the Solaris port we found the n_parent pointers inconvenient
62 * because they hold parent nodes busy. We now keep the full path
63 * in every node, so this function need only marshall the directory
64 * path, and (if provided) the separator and last component name.
66 * Note that this logic must match that in smbfs_getino
69 smbfs_fullpath(struct mbchain
*mbp
, struct smb_vc
*vcp
, struct smbnode
*dnp
,
70 const char *name
, int nmlen
, u_int8_t sep
)
72 int caseopt
= SMB_CS_NONE
;
73 int unicode
= (SMB_UNICODE_STRINGS(vcp
)) ? 1 : 0;
76 if (SMB_DIALECT(vcp
) < SMB_DIALECT_LANMAN1_0
)
77 caseopt
|= SMB_CS_UPPER
;
80 error
= mb_put_padbyte(mbp
);
85 error
= smb_put_dmem(mbp
, vcp
,
86 dnp
->n_rpath
, dnp
->n_rplen
,
90 * Special case at share root:
91 * Don't put another slash.
93 if (dnp
->n_rplen
<= 1 && sep
== '\\')
96 * More special cases, now for XATTR:
97 * Our "faked up" XATTR directories use a
98 * full path name ending with ":" so as to
99 * avoid conflicts with any real paths.
100 * (It is not a valid CIFS path name.)
101 * Therefore, when we're composing a full
102 * path name from an XATTR directory, we
103 * need to _ommit_ the ":" separator and
104 * instead copy the one from the "fake"
105 * parent node's path name.
107 if (dnp
->n_flag
& N_XATTR
)
111 /* Put the separator */
113 error
= mb_put_uint16le(mbp
, sep
);
115 error
= mb_put_uint8(mbp
, sep
);
120 error
= smb_put_dmem(mbp
, vcp
,
121 name
, nmlen
, caseopt
, NULL
);
125 /* Put NULL termination. */
127 error
= mb_put_uint16le(mbp
, 0);
129 error
= mb_put_uint8(mbp
, 0);
135 * Convert a Unicode directory entry to UTF-8
138 smbfs_fname_tolocal(struct smbfs_fctx
*ctx
)
140 uchar_t tmpbuf
[SMB_MAXFNAMELEN
+1];
141 struct smb_vc
*vcp
= SSTOVC(ctx
->f_ssp
);
144 size_t inlen
, outlen
;
147 if (ctx
->f_nmlen
== 0)
150 if (!SMB_UNICODE_STRINGS(vcp
))
153 if (ctx
->f_namesz
< sizeof (tmpbuf
)) {
159 * In-place conversions are not supported,
160 * so convert into tmpbuf and copy.
163 outlen
= SMB_MAXFNAMELEN
;
165 src
= (const ushort_t
*)ctx
->f_name
;
166 inlen
= ctx
->f_nmlen
/ 2; /* number of UCS-2 characters */
167 flags
= UCONV_IN_LITTLE_ENDIAN
;
169 if (uconv_u16tou8(src
, &inlen
, dst
, &outlen
, flags
) != 0)
172 ASSERT(outlen
< sizeof (tmpbuf
));
173 tmpbuf
[outlen
] = '\0';
174 bcopy(tmpbuf
, ctx
->f_name
, outlen
+ 1);
175 ctx
->f_nmlen
= (int)outlen
;
180 * Conversion failed, but our caller does not
181 * deal with errors here, so just put a "?".
182 * Don't expect to ever see this.
184 (void) strlcpy(ctx
->f_name
, "?", ctx
->f_namesz
);