Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/smbfs initial stab at smbfs (CIFS). originally for free...



details:   https://anonhg.NetBSD.org/src/rev/8adba3c8a35e
branches:  trunk
changeset: 500162:8adba3c8a35e
user:      deberg <deberg%NetBSD.org@localhost>
date:      Thu Dec 07 03:33:46 2000 +0000

description:
initial stab at smbfs (CIFS).  originally for freebsd by boris popov,
first ported to 1.4 branch by Christian Limpach <chris%nice.ch@localhost>.

diffstat:

 sys/smbfs/Makefile       |     8 +
 sys/smbfs/smbfs.h        |   105 +++
 sys/smbfs/smbfs_io.c     |   677 ++++++++++++++++++++++
 sys/smbfs/smbfs_ioctl.c  |    63 ++
 sys/smbfs/smbfs_node.c   |   352 +++++++++++
 sys/smbfs/smbfs_node.h   |   102 +++
 sys/smbfs/smbfs_smb.c    |  1235 ++++++++++++++++++++++++++++++++++++++++
 sys/smbfs/smbfs_subr.c   |   337 +++++++++++
 sys/smbfs/smbfs_subr.h   |   184 ++++++
 sys/smbfs/smbfs_vfsops.c |   575 ++++++++++++++++++
 sys/smbfs/smbfs_vnops.c  |  1405 ++++++++++++++++++++++++++++++++++++++++++++++
 11 files changed, 5043 insertions(+), 0 deletions(-)

diffs (truncated from 5087 to 300 lines):

diff -r cc4b475e0ac5 -r 8adba3c8a35e sys/smbfs/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/smbfs/Makefile        Thu Dec 07 03:33:46 2000 +0000
@@ -0,0 +1,8 @@
+#      $NetBSD: Makefile,v 1.1 2000/12/07 03:33:46 deberg Exp $
+
+KDIR=  /sys/smbfs
+INCSDIR= /usr/include/smbfs
+
+INCS=  smbfs.h smbfs_node.h smbfs_subr.h
+
+.include <bsd.kinc.mk>
diff -r cc4b475e0ac5 -r 8adba3c8a35e sys/smbfs/smbfs.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/smbfs/smbfs.h Thu Dec 07 03:33:46 2000 +0000
@@ -0,0 +1,105 @@
+/*     $NetBSD: smbfs.h,v 1.1 2000/12/07 03:33:46 deberg Exp $ */
+
+/*
+ * Copyright (c) 2000, Boris Popov
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Boris Popov.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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_SMBFS_H_
+#define _SMBFS_SMBFS_H_
+
+#define VT_SMBFS       24
+
+#define SMBFS_VERMAJ   1
+#define SMBFS_VERMIN   1012
+#define SMBFS_VERSION  (SMBFS_VERMAJ*100000 + SMBFS_VERMIN)
+#define        SMBFS_VFSNAME   "smbfs"
+
+/* Values for flags */
+#define SMBFS_MOUNT_SOFT       0x0001
+#define SMBFS_MOUNT_INTR       0x0002
+#define SMBFS_MOUNT_STRONG     0x0004
+#define        SMBFS_MOUNT_HAVE_NLS    0x0008
+#define        SMBFS_MOUNT_NO_LONG     0x0010
+
+#define        SMBFS_MAXPATHCOMP       256     /* maximum number of path components */
+
+
+/* Layout of the mount control block for a netware file system. */
+struct smbfs_args {
+       int             version;
+       int             dev;
+       u_int           flags;
+       char            mount_point[MAXPATHLEN];
+       u_char          root_path[512+1];
+       uid_t           uid;
+       gid_t           gid;
+       mode_t          file_mode;
+       mode_t          dir_mode;
+       int             caseopt;
+};
+
+#ifdef _KERNEL
+
+#ifdef MALLOC_DECLARE
+MALLOC_DECLARE(M_SMBFSMNT);
+#endif
+
+struct smbnode;
+struct smb_share;
+struct u_cred;
+struct vop_ioctl_args;
+struct buf;
+
+struct smbmount {
+       struct smbfs_args       sm_args;
+       struct mount *          sm_mp;
+       struct smbnode *        sm_root;
+       struct ucred *          sm_owner;
+       int                     sm_flags;
+       long                    sm_nextino;
+       struct smb_share *      sm_share;
+       struct simplelock       sm_npslock;
+       struct smbnode *        sm_npstack[SMBFS_MAXPATHCOMP];
+       int                     sm_caseopt;
+};
+
+#define VFSTOSMBFS(mp)         ((struct smbmount *)((mp)->mnt_data))
+#define SMBFSTOVFS(smp)                ((struct mount *)((smp)->sm_mp))
+#define VTOVFS(vp)             ((vp)->v_mount)
+#define        VTOSMBFS(vp)            (VFSTOSMBFS(VTOVFS(vp)))
+
+int smbfs_ioctl(struct vop_ioctl_args *ap);
+int smbfs_doio(struct buf *bp, struct ucred *cr, struct proc *p);
+int smbfs_vinvalbuf(struct vnode *vp, int flags, struct ucred *cred, 
+       struct proc *p, int intrflg);
+#endif /* KERNEL */
+
+#endif /* _SMBFS_SMBFS_H_ */
diff -r cc4b475e0ac5 -r 8adba3c8a35e sys/smbfs/smbfs_io.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/smbfs/smbfs_io.c      Thu Dec 07 03:33:46 2000 +0000
@@ -0,0 +1,677 @@
+/*     $NetBSD: smbfs_io.c,v 1.1 2000/12/07 03:33:46 deberg Exp $      */
+
+/*
+ * Copyright (c) 2000, Boris Popov
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *    This product includes software developed by Boris Popov.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/resourcevar.h>   /* defines plimit structure in proc struct */
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/fcntl.h>
+#include <sys/mount.h>
+#include <sys/namei.h>
+#include <sys/vnode.h>
+#include <sys/dirent.h>
+#include <sys/signalvar.h>
+#include <uvm/uvm_extern.h>
+#include <sys/sysctl.h>
+
+#ifndef NetBSD
+#if __FreeBSD_version < 400000
+#include <vm/vm_prot.h>
+#endif
+#endif
+#include <uvm/uvm_page.h>
+#include <uvm/uvm_object.h>
+#include <uvm/uvm_pager.h>
+#ifndef NetBSD
+#include <vm/vnode_pager.h>
+#endif
+/*
+#include <sys/ioccom.h>
+*/
+#include <netsmb/smb.h>
+#include <netsmb/smb_conn.h>
+#include <netsmb/smb_subr.h>
+#include <netsmb/smb_lock.h>
+
+#include <smbfs/smbfs.h>
+#include <smbfs/smbfs_node.h>
+#include <smbfs/smbfs_subr.h>
+
+#ifdef FB_CURRENT
+#include <sys/bio.h>
+#else
+#define        bufdone biodone
+#endif
+#include <sys/buf.h>
+
+/*#define SMBFS_RWGENERIC*/
+
+extern int smbfs_pbuf_freecnt;
+
+static int smbfs_fastlookup = 1;
+
+extern struct linker_set sysctl_vfs_smbfs;
+
+#ifdef SYSCTL_DECL
+SYSCTL_DECL(_vfs_smbfs);
+#endif
+#ifndef NetBSD
+SYSCTL_INT(_vfs_smbfs, OID_AUTO, fastlookup, CTLFLAG_RW, &smbfs_fastlookup, 0, "");
+#endif
+
+
+#define DE_SIZE        (sizeof(struct dirent))
+
+static int
+smbfs_readvdir(struct vnode *vp, struct uio *uio, struct ucred *cred)
+{
+       struct dirent de;
+       struct componentname cn;
+       struct smb_cred scred;
+       struct smbfs_fctx *ctx;
+       struct vnode *newvp;
+       struct smbnode *np = VTOSMB(vp);
+       int error/*, *eofflag = ap->a_eofflag*/;
+       long offset, limit;
+       const unsigned char *hcp;
+       int i;
+
+       np = VTOSMB(vp);
+       SMBVDEBUG("dirname='%s'\n", np->n_name);
+       if (uio->uio_resid < DE_SIZE || uio->uio_offset < 0)
+               return EINVAL;
+       smb_makescred(&scred, uio->uio_procp, cred);
+       offset = uio->uio_offset / DE_SIZE;     /* offset in the directory */
+       limit = uio->uio_resid / DE_SIZE;
+       while (limit && offset < 2) {
+               limit--;
+               bzero((caddr_t)&de, DE_SIZE);
+               de.d_reclen = DE_SIZE;
+               de.d_fileno = (offset == 0) ? np->n_ino :
+                   (np->n_parent ? np->n_parent->n_ino : 2);
+               if (de.d_fileno == 0)
+                       de.d_fileno = 0x7ffffffd + offset;
+               de.d_namlen = offset + 1;
+               de.d_name[0] = '.';
+               de.d_name[1] = '.';
+               de.d_name[offset + 1] = '\0';
+               de.d_type = DT_DIR;
+               error = uiomove((caddr_t)&de, DE_SIZE, uio);
+               if (error)
+                       return error;
+               offset++;
+               uio->uio_offset += DE_SIZE;
+       }
+       if (limit == 0)
+               return 0;
+       if (offset != np->n_dirofs || np->n_dirseq == NULL) {
+               SMBVDEBUG("Reopening search %ld:%ld\n", offset, np->n_dirofs);
+               if (np->n_dirseq) {
+                       smbfs_findclose(np->n_dirseq, &scred);
+                       np->n_dirseq = NULL;
+               }
+               np->n_dirofs = 2;
+               error = smbfs_findopen(np, "*", 1,
+                   SMB_FA_SYSTEM | SMB_FA_HIDDEN | SMB_FA_DIR,
+                   &scred, &ctx);
+               if (error) {
+                       SMBVDEBUG("can not open search, error = %d", error);
+                       return error;
+               }
+               np->n_dirseq = ctx;
+       } else
+               ctx = np->n_dirseq;
+       while (np->n_dirofs < offset) {
+               error = smbfs_findnext(ctx, offset - np->n_dirofs++, &scred);
+               if (error) {
+                       smbfs_findclose(np->n_dirseq, &scred);
+                       np->n_dirseq = NULL;
+                       return error == ENOENT ? 0 : error;
+               }
+       }
+       error = 0;
+       for (; limit; limit--, offset++) {
+               bzero((caddr_t)&de, DE_SIZE);
+               de.d_reclen = DE_SIZE;
+               error = smbfs_findnext(ctx, limit, &scred);
+               if (error)
+                       break;
+               np->n_dirofs++;
+               de.d_fileno = ctx->f_attr.fa_ino;
+               de.d_type = (ctx->f_attr.fa_attr & SMB_FA_DIR) ? DT_DIR : DT_REG;
+               de.d_namlen = ctx->f_nmlen;



Home | Main Index | Thread Index | Old Index