Module Name:    src
Committed By:   nakayama
Date:           Sat Nov 15 18:49:05 UTC 2014

Modified Files:
        src/sys/netsmb: iconv.c
        src/sys/rump/dev/lib/libnetsmb: Makefile
Added Files:
        src/sys/rump/dev/lib/libnetsmb: netsmb_iconv.c netsmb_user.c
            netsmb_user.h

Log Message:
Make rump_smbfs(8) uses host iconv(3) to convert filenames
character set.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/netsmb/iconv.c
cvs rdiff -u -r1.4 -r1.5 src/sys/rump/dev/lib/libnetsmb/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c \
    src/sys/rump/dev/lib/libnetsmb/netsmb_user.c \
    src/sys/rump/dev/lib/libnetsmb/netsmb_user.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netsmb/iconv.c
diff -u src/sys/netsmb/iconv.c:1.13 src/sys/netsmb/iconv.c:1.14
--- src/sys/netsmb/iconv.c:1.13	Thu Feb 20 11:08:57 2014
+++ src/sys/netsmb/iconv.c	Sat Nov 15 18:49:04 2014
@@ -1,41 +1,48 @@
-/*	$NetBSD: iconv.c,v 1.13 2014/02/20 11:08:57 joerg Exp $	*/
+/*	$NetBSD: iconv.c,v 1.14 2014/11/15 18:49:04 nakayama Exp $	*/
 
 /* Public domain */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.13 2014/02/20 11:08:57 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.14 2014/11/15 18:49:04 nakayama Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/systm.h>
 #include <sys/errno.h>
-#include <sys/malloc.h>
 
 #include <netsmb/iconv.h>
 
+/* stubs for iconv functions */
+int iconv_open_stub(const char *, const char *, void **);
+int iconv_close_stub(void *);
+int iconv_conv_stub(void *, const char **, size_t *, char **, size_t *);
+__weak_alias(iconv_open, iconv_open_stub);
+__weak_alias(iconv_close, iconv_close_stub);
+__weak_alias(iconv_conv, iconv_conv_stub);
+
 int
-iconv_open(const char *to, const char *from,
+iconv_open_stub(const char *to, const char *from,
     void **handle)
 {
 	return 0;
 }
 
 int
-iconv_close(void *handle)
+iconv_close_stub(void *handle)
 {
 	return 0;
 }
 
 int
-iconv_conv(void *handle, const char **inbuf,
+iconv_conv_stub(void *handle, const char **inbuf,
     size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
 {
-	if (*inbytesleft > *outbytesleft)
-		return(E2BIG);
-
 	if (inbuf == NULL)
 		return(0); /* initial shift state */
 
+	if (*inbytesleft > *outbytesleft)
+		return(E2BIG);
+
 	(void)memcpy(*outbuf, *inbuf, *inbytesleft);
 
 	*outbytesleft -= *inbytesleft;
@@ -59,7 +66,11 @@ iconv_convstr(void *handle, char *dst, c
 		strlcpy(dst, src, l);
 		return dst;
 	}
-	inlen = outlen = strlen(src);
+	inlen = strlen(src);
+	outlen = l - 1;
+	error = iconv_conv(handle, NULL, NULL, &p, &outlen);
+	if (error)
+		return NULL;
 	error = iconv_conv(handle, &src, &inlen, &p, &outlen);
 	if (error)
 		return NULL;
@@ -82,6 +93,9 @@ iconv_convmem(void *handle, void *dst, c
 		return dst;
 	}
 	inlen = outlen = size;
+	error = iconv_conv(handle, NULL, NULL, &d, &outlen);
+	if (error)
+		return NULL;
 	error = iconv_conv(handle, &s, &inlen, &d, &outlen);
 	if (error)
 		return NULL;

Index: src/sys/rump/dev/lib/libnetsmb/Makefile
diff -u src/sys/rump/dev/lib/libnetsmb/Makefile:1.4 src/sys/rump/dev/lib/libnetsmb/Makefile:1.5
--- src/sys/rump/dev/lib/libnetsmb/Makefile:1.4	Thu Mar 13 01:57:29 2014
+++ src/sys/rump/dev/lib/libnetsmb/Makefile	Sat Nov 15 18:49:04 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.4 2014/03/13 01:57:29 pooka Exp $
+#	$NetBSD: Makefile,v 1.5 2014/11/15 18:49:04 nakayama Exp $
 #
 
 .PATH:	${.CURDIR}/../../../../netsmb
@@ -13,5 +13,8 @@ SRCS+=	netsmb_component.c
 CPPFLAGS+=	-I${RUMPTOP}/librump/rumpvfs
 #CPPFLAGS+=	-DSMB_SOCKET_DEBUG -DSMB_IOD_DEBUG
 
+SRCS+=	netsmb_iconv.c
+RUMPCOMP_USER_SRCS=	netsmb_user.c
+
 .include <bsd.lib.mk>
 .include <bsd.klinks.mk>

Added files:

Index: src/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c
diff -u /dev/null src/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c:1.1
--- /dev/null	Sat Nov 15 18:49:05 2014
+++ src/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c	Sat Nov 15 18:49:04 2014
@@ -0,0 +1,79 @@
+/*	$NetBSD: netsmb_iconv.c,v 1.1 2014/11/15 18:49:04 nakayama Exp $	*/
+
+/*
+ * Copyright (c) 2014 Takeshi Nakayama.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: netsmb_iconv.c,v 1.1 2014/11/15 18:49:04 nakayama Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+
+#include <netsmb/iconv.h>
+
+#include "netsmb_user.h"
+
+int
+iconv_open(const char *to, const char *from, void **handle)
+{
+	if (strcmp(to, "tolower") && strcmp(to, "toupper"))
+		return rumpcomp_netsmb_iconv_open(to, from, handle);
+	return 0;
+}
+
+int
+iconv_close(void *handle)
+{
+	if (handle != NULL)
+		return rumpcomp_netsmb_iconv_close(handle);
+	return 0;
+}
+
+int
+iconv_conv(void *handle, const char **inbuf, size_t *inbytesleft,
+    char **outbuf, size_t *outbytesleft)
+{
+	size_t len;
+
+	if (handle != NULL)
+		return rumpcomp_netsmb_iconv_conv(handle, inbuf, inbytesleft,
+		    outbuf, outbytesleft);
+
+	if (inbuf == NULL)
+		return 0;
+
+	if (*inbytesleft > *outbytesleft)
+		return E2BIG;
+
+	len = *inbytesleft;
+	memcpy(*outbuf, *inbuf, len);
+	*inbuf += len;
+	*inbytesleft = 0;
+	*outbuf += len;
+	*outbytesleft -= len;
+	return 0;
+}
Index: src/sys/rump/dev/lib/libnetsmb/netsmb_user.c
diff -u /dev/null src/sys/rump/dev/lib/libnetsmb/netsmb_user.c:1.1
--- /dev/null	Sat Nov 15 18:49:05 2014
+++ src/sys/rump/dev/lib/libnetsmb/netsmb_user.c	Sat Nov 15 18:49:04 2014
@@ -0,0 +1,81 @@
+/*	$NetBSD: netsmb_user.c,v 1.1 2014/11/15 18:49:04 nakayama Exp $	*/
+
+/*
+ * Copyright (c) 2014 Takeshi Nakayama.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _KERNEL
+#include <stddef.h>
+#include <iconv.h>
+#include <errno.h>
+
+#include <rump/rumpuser_component.h>
+
+#include "netsmb_user.h"
+
+int
+rumpcomp_netsmb_iconv_open(const char *to, const char *from, void **handle)
+{
+	iconv_t cd;
+	int rv;
+
+	cd = iconv_open(to, from);
+	if (cd == (iconv_t)-1)
+		rv = errno;
+	else {
+		if (handle != NULL)
+			*handle = (void *)cd;
+		rv = 0;
+	}
+
+	return rumpuser_component_errtrans(rv);
+}
+
+int
+rumpcomp_netsmb_iconv_close(void *handle)
+{
+	int rv;
+
+	if (iconv_close((iconv_t)handle) == -1)
+		rv = errno;
+	else
+		rv = 0;
+
+	return rumpuser_component_errtrans(rv);
+}
+
+int
+rumpcomp_netsmb_iconv_conv(void *handle, const char **inbuf,
+    size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
+{
+	int rv;
+
+	if (iconv((iconv_t)handle, inbuf, inbytesleft, outbuf, outbytesleft)
+	    == (size_t)-1)
+		rv = errno;
+	else
+		rv = 0;
+
+	return rumpuser_component_errtrans(rv);
+}
+#endif
Index: src/sys/rump/dev/lib/libnetsmb/netsmb_user.h
diff -u /dev/null src/sys/rump/dev/lib/libnetsmb/netsmb_user.h:1.1
--- /dev/null	Sat Nov 15 18:49:05 2014
+++ src/sys/rump/dev/lib/libnetsmb/netsmb_user.h	Sat Nov 15 18:49:04 2014
@@ -0,0 +1,31 @@
+/*	$NetBSD: netsmb_user.h,v 1.1 2014/11/15 18:49:04 nakayama Exp $	*/
+
+/*
+ * Copyright (c) 2014 Takeshi Nakayama.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+int rumpcomp_netsmb_iconv_open(const char *, const char *, void **);
+int rumpcomp_netsmb_iconv_close(void *);
+int rumpcomp_netsmb_iconv_conv(void *, const char **, size_t *, char **,
+    size_t *);

Reply via email to