Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/dist/smbfs Implement smbfs kernel operations (ioctl etc.) th...
details: https://anonhg.NetBSD.org/src/rev/c413286d3898
branches: trunk
changeset: 747228:c413286d3898
user: pooka <pooka%NetBSD.org@localhost>
date: Sun Sep 06 18:38:17 2009 +0000
description:
Implement smbfs kernel operations (ioctl etc.) through a vector of
function pointers instead of direct linkage so that rump syscalls
are possible.
diffstat:
dist/smbfs/include/smb_kernelops.h | 52 +++++++++++++++++++++++++++++++++++++
dist/smbfs/lib/smb/ctx.c | 24 +++++++++-------
dist/smbfs/lib/smb/file.c | 8 +++--
dist/smbfs/lib/smb/nbns_rq.c | 21 ++++++++------
dist/smbfs/lib/smb/rq.c | 7 ++--
dist/smbfs/lib/smb/smb_kernelops.c | 53 ++++++++++++++++++++++++++++++++++++++
6 files changed, 139 insertions(+), 26 deletions(-)
diffs (truncated from 382 to 300 lines):
diff -r ccbb835facfb -r c413286d3898 dist/smbfs/include/smb_kernelops.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dist/smbfs/include/smb_kernelops.h Sun Sep 06 18:38:17 2009 +0000
@@ -0,0 +1,52 @@
+/* $NetBSD: smb_kernelops.h,v 1.1 2009/09/06 18:38:17 pooka Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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 _SMBFS_KERNEL_OPS_H_
+#define _SMBFS_KERNEL_OPS_H_
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <fcntl.h>
+
+struct smb_kernelops {
+ int (*ko_open)(const char *, int, mode_t);
+ int (*ko_ioctl)(int, unsigned long, void *);
+ int (*ko_close)(int);
+
+ int (*ko_socket)(int, int, int);
+ int (*ko_setsockopt)(int, int, int, const void *, socklen_t);
+ int (*ko_bind)(int, const struct sockaddr *, socklen_t);
+ ssize_t (*ko_sendto)(int, const void *, size_t, int,
+ const struct sockaddr *, socklen_t);
+ ssize_t (*ko_recvfrom)(int, void *, size_t, int,
+ struct sockaddr *, socklen_t *);
+};
+extern const struct smb_kernelops smb_kops;
+
+#endif /* _SMBFS_KERNEL_OPS_H_ */
diff -r ccbb835facfb -r c413286d3898 dist/smbfs/lib/smb/ctx.c
--- a/dist/smbfs/lib/smb/ctx.c Sun Sep 06 18:06:24 2009 +0000
+++ b/dist/smbfs/lib/smb/ctx.c Sun Sep 06 18:38:17 2009 +0000
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: ctx.c,v 1.13 2009/06/26 22:41:26 njoly Exp $");
+__RCSID("$NetBSD: ctx.c,v 1.14 2009/09/06 18:38:17 pooka Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
@@ -59,6 +59,8 @@
#include <netsmb/smb_conn.h>
#include <cflib.h>
+#include "smb_kernelops.h"
+
/*
* Prescan command line for [-U user] argument
* and fill context with defaults
@@ -601,7 +603,7 @@
/*
* First, try to open as cloned device
*/
- fd = open("/dev/"NSMB_NAME, O_RDWR);
+ fd = smb_kops.ko_open("/dev/"NSMB_NAME, O_RDWR, 0);
if (fd >= 0) {
ctx->ct_fd = fd;
return 0;
@@ -613,7 +615,7 @@
*/
for (i = 0; i < 1024; i++) {
snprintf(buf, sizeof(buf), "/dev/"NSMB_NAME"%d", i);
- fd = open(buf, O_RDWR);
+ fd = smb_kops.ko_open(buf, O_RDWR, 0);
if (fd >= 0) {
ctx->ct_fd = fd;
return 0;
@@ -652,7 +654,7 @@
return EINVAL;
}
if (ctx->ct_fd != -1) {
- close(ctx->ct_fd);
+ smb_kops.ko_close(ctx->ct_fd);
ctx->ct_fd = -1;
}
error = smb_ctx_gethandle(ctx);
@@ -665,10 +667,10 @@
bcopy(&ctx->ct_sh, &rq.ioc_sh, sizeof(struct smbioc_oshare));
rq.ioc_flags = flags;
rq.ioc_level = level;
- if (ioctl(ctx->ct_fd, SMBIOC_LOOKUP, &rq) == -1) {
+ if (smb_kops.ko_ioctl(ctx->ct_fd, SMBIOC_LOOKUP, &rq) == -1) {
error = errno;
- close(ctx->ct_fd);
+ smb_kops.ko_close(ctx->ct_fd);
ctx->ct_fd = -1;
/*
@@ -689,7 +691,7 @@
bcopy(&ctx->ct_ssn, &rq.ioc_ssn, sizeof(struct smbioc_ossn));
- if (ioctl(ctx->ct_fd, SMBIOC_LOOKUP, &rq) != -1)
+ if (smb_kops.ko_ioctl(ctx->ct_fd, SMBIOC_LOOKUP, &rq) != -1)
goto success;
error = errno;
@@ -715,7 +717,7 @@
return EINVAL;
}
if (ctx->ct_fd != -1) {
- close(ctx->ct_fd);
+ smb_kops.ko_close(ctx->ct_fd);
ctx->ct_fd = -1;
}
error = smb_ctx_gethandle(ctx);
@@ -723,14 +725,14 @@
smb_error("can't get handle to requester", 0);
return EINVAL;
}
- if (ioctl(ctx->ct_fd, SMBIOC_OPENSESSION, ssn) == -1) {
+ if (smb_kops.ko_ioctl(ctx->ct_fd, SMBIOC_OPENSESSION, ssn) == -1) {
error = errno;
smb_error("can't open session to server %s", error, ssn->ioc_srvname);
return error;
}
if (sh->ioc_share[0] == 0)
return 0;
- if (ioctl(ctx->ct_fd, SMBIOC_OPENSHARE, sh) == -1) {
+ if (smb_kops.ko_ioctl(ctx->ct_fd, SMBIOC_OPENSHARE, sh) == -1) {
error = errno;
smb_error("can't connect to share //%s/%s", error,
ssn->ioc_srvname, sh->ioc_share);
@@ -749,7 +751,7 @@
fl.ioc_level = level;
fl.ioc_mask = mask;
fl.ioc_flags = flags;
- if (ioctl(ctx->ct_fd, SMBIOC_SETFLAGS, &fl) == -1)
+ if (smb_kops.ko_ioctl(ctx->ct_fd, SMBIOC_SETFLAGS, &fl) == -1)
return errno;
return 0;
}
diff -r ccbb835facfb -r c413286d3898 dist/smbfs/lib/smb/file.c
--- a/dist/smbfs/lib/smb/file.c Sun Sep 06 18:06:24 2009 +0000
+++ b/dist/smbfs/lib/smb/file.c Sun Sep 06 18:38:17 2009 +0000
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: file.c,v 1.3 2006/05/10 06:24:02 skrll Exp $");
+__RCSID("$NetBSD: file.c,v 1.4 2009/09/06 18:38:17 pooka Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
@@ -54,6 +54,8 @@
#include <netsmb/smb_conn.h>
#include <cflib.h>
+#include "smb_kernelops.h"
+
int
smb_read(struct smb_ctx *ctx, smbfh fh, off_t offset, size_t count, char *dst)
{
@@ -63,7 +65,7 @@
rwrq.ioc_base = dst;
rwrq.ioc_cnt = count;
rwrq.ioc_offset = offset;
- if (ioctl(ctx->ct_fd, SMBIOC_READ, &rwrq) == -1)
+ if (smb_kops.ko_ioctl(ctx->ct_fd, SMBIOC_READ, &rwrq) == -1)
return -1;
return rwrq.ioc_cnt;
}
@@ -78,7 +80,7 @@
rwrq.ioc_base = __UNCONST(src);
rwrq.ioc_cnt = count;
rwrq.ioc_offset = offset;
- if (ioctl(ctx->ct_fd, SMBIOC_WRITE, &rwrq) == -1)
+ if (smb_kops.ko_ioctl(ctx->ct_fd, SMBIOC_WRITE, &rwrq) == -1)
return -1;
return rwrq.ioc_cnt;
}
diff -r ccbb835facfb -r c413286d3898 dist/smbfs/lib/smb/nbns_rq.c
--- a/dist/smbfs/lib/smb/nbns_rq.c Sun Sep 06 18:06:24 2009 +0000
+++ b/dist/smbfs/lib/smb/nbns_rq.c Sun Sep 06 18:38:17 2009 +0000
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: nbns_rq.c,v 1.6 2009/09/06 17:02:36 pooka Exp $");
+__RCSID("$NetBSD: nbns_rq.c,v 1.7 2009/09/06 18:38:17 pooka Exp $");
#include <sys/param.h>
#include <sys/socket.h>
@@ -53,6 +53,7 @@
#include <netsmb/smb_lib.h>
#include <netsmb/nb_lib.h>
+#include "smb_kernelops.h"
static int nbns_rq_create(int opcode, struct nb_ctx *ctx, struct nbns_rq **rqpp);
static void nbns_rq_done(struct nbns_rq *rqp);
@@ -173,7 +174,7 @@
if (rqp == NULL)
return;
if (rqp->nr_fd >= 0)
- close(rqp->nr_fd);
+ smb_kops.ko_close(rqp->nr_fd);
mb_done(&rqp->nr_rq);
mb_done(&rqp->nr_rp);
free(rqp);
@@ -264,7 +265,7 @@
int n, len;
len = sizeof(sender);
- n = recvfrom(s, rpdata, mbp->mb_top->m_maxlen, 0,
+ n = smb_kops.ko_recvfrom(s, rpdata, mbp->mb_top->m_maxlen, 0,
(struct sockaddr*)&sender, &len);
if (n < 0) {
if (errno == EAGAIN)
@@ -283,16 +284,18 @@
struct timeval tv;
int opt, s;
- s = rqp->nr_fd = socket(AF_INET, SOCK_DGRAM, 0);
+ s = rqp->nr_fd = smb_kops.ko_socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
return errno;
if (rqp->nr_flags & NBRQF_BROADCAST) {
opt = 1;
- if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt)) < 0)
+ if (smb_kops.ko_setsockopt(s, SOL_SOCKET, SO_BROADCAST,
+ &opt, sizeof(opt)) < 0)
return errno;
tv.tv_sec = rqp->nr_nbd->nb_timo;
tv.tv_usec = 0;
- if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
+ if (smb_kops.ko_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO,
+ &tv, sizeof(tv)) < 0)
return errno;
if (rqp->nr_if == NULL)
return NBERROR(NBERR_NOBCASTIFS);
@@ -301,7 +304,7 @@
locaddr.sin_len = sizeof(locaddr);
locaddr.sin_addr = rqp->nr_if->id_addr;
rqp->nr_dest.sin_addr.s_addr = rqp->nr_if->id_addr.s_addr | ~rqp->nr_if->id_mask.s_addr;
- if (bind(s, (struct sockaddr*)&locaddr, sizeof(locaddr)) < 0)
+ if (smb_kops.ko_bind(s, (struct sockaddr*)&locaddr, sizeof(locaddr)) < 0)
return errno;
}
return 0;
@@ -313,7 +316,7 @@
struct mbdata *mbp = &rqp->nr_rq;
int s = rqp->nr_fd;
- if (sendto(s, mtod(mbp->mb_top, char *), mbp->mb_count, 0,
+ if (smb_kops.ko_sendto(s, mtod(mbp->mb_top, char *), mbp->mb_count, 0,
(struct sockaddr*)&rqp->nr_dest, sizeof(rqp->nr_dest)) < 0)
return errno;
return 0;
@@ -344,7 +347,7 @@
rqp->nr_if != NULL &&
rqp->nr_if->id_next != NULL) {
rqp->nr_if = rqp->nr_if->id_next;
- close(rqp->nr_fd);
+ smb_kops.ko_close(rqp->nr_fd);
goto again;
} else
return error;
diff -r ccbb835facfb -r c413286d3898 dist/smbfs/lib/smb/rq.c
--- a/dist/smbfs/lib/smb/rq.c Sun Sep 06 18:06:24 2009 +0000
+++ b/dist/smbfs/lib/smb/rq.c Sun Sep 06 18:38:17 2009 +0000
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: rq.c,v 1.4 2006/05/10 06:24:02 skrll Exp $");
+__RCSID("$NetBSD: rq.c,v 1.5 2009/09/06 18:38:17 pooka Exp $");
#include <sys/param.h>
#include <sys/ioctl.h>
@@ -51,6 +51,7 @@
Home |
Main Index |
Thread Index |
Old Index