The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/nwfs/nwfs_vfsops.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1999, 2000 Boris Popov
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    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.
   19  *
   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
   30  * SUCH DAMAGE.
   31  *
   32  * $FreeBSD$
   33  */
   34 #include "opt_ncp.h"
   35 #ifndef NCP
   36 #error "NWFS requires NCP protocol"
   37 #endif
   38 
   39 #include <sys/param.h>
   40 #include <sys/systm.h>
   41 #include <sys/proc.h>
   42 #include <sys/kernel.h>
   43 #include <sys/sysctl.h>
   44 #include <sys/vnode.h>
   45 #include <sys/mount.h>
   46 #include <sys/stat.h>
   47 #include <sys/malloc.h>
   48 #include <sys/buf.h>
   49 
   50 #include <netncp/ncp.h>
   51 #include <netncp/ncp_conn.h>
   52 #include <netncp/ncp_subr.h>
   53 #include <netncp/ncp_ncp.h>
   54 #include <netncp/ncp_nls.h>
   55 
   56 #include <nwfs/nwfs.h>
   57 #include <nwfs/nwfs_node.h>
   58 #include <nwfs/nwfs_subr.h>
   59 
   60 int nwfs_debuglevel = 0;
   61 
   62 static int nwfs_version = NWFS_VERSION;
   63 
   64 SYSCTL_DECL(_vfs_nwfs);
   65 SYSCTL_NODE(_vfs, OID_AUTO, nwfs, CTLFLAG_RW, 0, "Netware file system");
   66 SYSCTL_INT(_vfs_nwfs, OID_AUTO, version, CTLFLAG_RD, &nwfs_version, 0, "");
   67 SYSCTL_INT(_vfs_nwfs, OID_AUTO, debuglevel, CTLFLAG_RW, &nwfs_debuglevel, 0, "");
   68 
   69 static int nwfs_mount(struct mount *, char *, caddr_t,
   70                         struct nameidata *, struct proc *);
   71 static int nwfs_quotactl(struct mount *, int, uid_t, caddr_t, struct proc *);
   72 static int nwfs_root(struct mount *, struct vnode **);
   73 static int nwfs_start(struct mount *, int, struct proc *);
   74 static int nwfs_statfs(struct mount *, struct statfs *, struct proc *);
   75 static int nwfs_sync(struct mount *, int, struct ucred *, struct proc *);
   76 static int nwfs_unmount(struct mount *, int, struct proc *);
   77 static int nwfs_init(struct vfsconf *vfsp);
   78 static int nwfs_uninit(struct vfsconf *vfsp);
   79 
   80 static struct vfsops nwfs_vfsops = {
   81         nwfs_mount,
   82         nwfs_start,
   83         nwfs_unmount,
   84         nwfs_root,
   85         nwfs_quotactl,
   86         nwfs_statfs,
   87         nwfs_sync,
   88         vfs_stdvget,
   89         vfs_stdfhtovp,          /* shouldn't happen */
   90         vfs_stdcheckexp,
   91         vfs_stdvptofh,          /* shouldn't happen */
   92         nwfs_init,
   93         nwfs_uninit,
   94         vfs_stdextattrctl,
   95 };
   96 
   97 
   98 VFS_SET(nwfs_vfsops, nwfs, VFCF_NETWORK);
   99 
  100 int nwfs_pbuf_freecnt = -1;     /* start out unlimited */
  101 static int nwfsid = 1;
  102 
  103 static int
  104 nwfs_initnls(struct nwmount *nmp) {
  105         char    *pc, *pe;
  106         int     error = 0;
  107 #define COPY_TABLE(t,d) { \
  108                 if (t) { \
  109                         error = copyin((t), pc, 256); \
  110                         if (error) break; \
  111                 } else \
  112                         bcopy(d, pc, 256); \
  113                 (t) = pc; pc += 256; \
  114         }
  115 
  116         nmp->m.nls.opt |= NWHP_NLS | NWHP_DOS;
  117         if ((nmp->m.flags & NWFS_MOUNT_HAVE_NLS) == 0) {
  118                 nmp->m.nls.to_lower = ncp_defnls.to_lower;
  119                 nmp->m.nls.to_upper = ncp_defnls.to_upper;
  120                 nmp->m.nls.n2u = ncp_defnls.n2u;
  121                 nmp->m.nls.u2n = ncp_defnls.u2n;
  122                 return 0;
  123         }
  124         MALLOC(pe, char *, 256 * 4, M_NWFSDATA, M_WAITOK);
  125         pc = pe;
  126         do {
  127                 COPY_TABLE(nmp->m.nls.to_lower, ncp_defnls.to_lower);
  128                 COPY_TABLE(nmp->m.nls.to_upper, ncp_defnls.to_upper);
  129                 COPY_TABLE(nmp->m.nls.n2u, ncp_defnls.n2u);
  130                 COPY_TABLE(nmp->m.nls.u2n, ncp_defnls.u2n);
  131         } while(0);
  132         if (error) {
  133                 free(pe, M_NWFSDATA);
  134                 return error;
  135         }
  136         return 0;
  137 }
  138 /*
  139  * mp - path - addr in user space of mount point (ie /usr or whatever)
  140  * data - addr in user space of mount params 
  141  */
  142 static int nwfs_mount(struct mount *mp, char *path, caddr_t data, 
  143                       struct nameidata *ndp, struct proc *p)
  144 {
  145         struct nwfs_args args;    /* will hold data from mount request */
  146         size_t size;
  147         int error;
  148         struct nwmount *nmp = NULL;
  149         struct ncp_conn *conn = NULL;
  150         struct ncp_handle *handle = NULL;
  151         struct vnode *vp;
  152         char *pc,*pe;
  153 
  154         if (data == NULL) {
  155                 nwfs_printf("missing data argument\n");
  156                 return 1;
  157         }
  158         if (mp->mnt_flag & MNT_UPDATE) {
  159                 nwfs_printf("MNT_UPDATE not implemented");
  160                 return (EOPNOTSUPP);
  161         }
  162         error = copyin(data, (caddr_t)&args, sizeof(struct nwfs_args));
  163         if (error)
  164                 return (error);
  165         if (args.version != NWFS_VERSION) {
  166                 nwfs_printf("mount version mismatch: kernel=%d, mount=%d\n",NWFS_VERSION,args.version);
  167                 return (1);
  168         }
  169         error = ncp_conn_getbyref(args.connRef,p,p->p_ucred,NCPM_EXECUTE,&conn);
  170         if (error) {
  171                 nwfs_printf("invalid connection refernce %d\n",args.connRef);
  172                 return (error);
  173         }
  174         error = ncp_conn_gethandle(conn, NULL, &handle);
  175         if (error) {
  176                 nwfs_printf("can't get connection handle\n");
  177                 return (error);
  178         }
  179         ncp_conn_unlock(conn,p);        /* we keep the ref */
  180         mp->mnt_stat.f_iosize = conn->buffer_size;
  181         /* We must malloc our own mount info */
  182         MALLOC(nmp,struct nwmount *,sizeof(struct nwmount),M_NWFSDATA,M_USE_RESERVE | M_ZERO);
  183         if (nmp == NULL) {
  184                 nwfs_printf("could not alloc nwmount\n");
  185                 error = ENOMEM;
  186                 goto bad;
  187         }
  188         mp->mnt_data = (qaddr_t)nmp;
  189         nmp->connh = handle;
  190         nmp->n_root = NULL;
  191         nmp->n_id = nwfsid++;
  192         nmp->m = args;
  193         nmp->m.file_mode = (nmp->m.file_mode &
  194                             (S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFREG;
  195         nmp->m.dir_mode  = (nmp->m.dir_mode &
  196                             (S_IRWXU|S_IRWXG|S_IRWXO)) | S_IFDIR;
  197         if ((error = nwfs_initnls(nmp)) != 0) goto bad;
  198         (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
  199         bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
  200         pc = mp->mnt_stat.f_mntfromname;
  201         pe = pc+sizeof(mp->mnt_stat.f_mntfromname);
  202         bzero(pc, MNAMELEN);
  203         *(pc++) = '/';
  204         pc = index(strncpy(pc, conn->li.server, pe-pc-2),0);
  205         if (pc < pe-1) {
  206                 *(pc++) = ':';
  207                 pc=index(strncpy(pc, conn->li.user, pe-pc-2),0);
  208                 if (pc < pe-1) {
  209                         *(pc++) = '/';
  210                         strncpy(pc, nmp->m.mounted_vol, pe-pc-2);
  211                 }
  212         }
  213         /* protect against invalid mount points */
  214         nmp->m.mount_point[sizeof(nmp->m.mount_point)-1] = '\0';
  215         vfs_getnewfsid(mp);
  216         error = nwfs_root(mp, &vp);
  217         if (error)
  218                 goto bad;
  219         /*
  220          * Lose the lock but keep the ref.
  221          */
  222         VOP_UNLOCK(vp, 0, curproc);
  223         NCPVODEBUG("rootvp.vrefcnt=%d\n",vp->v_usecount);
  224         return error;
  225 bad:
  226         if (nmp)
  227                 free(nmp, M_NWFSDATA);
  228         if (handle)
  229                 ncp_conn_puthandle(handle, NULL, 0);
  230         return error;
  231 }
  232 
  233 /* Unmount the filesystem described by mp. */
  234 static int
  235 nwfs_unmount(struct mount *mp, int mntflags, struct proc *p)
  236 {
  237         struct nwmount *nmp = VFSTONWFS(mp);
  238         struct ncp_conn *conn;
  239         int error, flags;
  240 
  241         NCPVODEBUG("nwfs_unmount: flags=%04x\n",mntflags);
  242         flags = 0;
  243         if (mntflags & MNT_FORCE)
  244                 flags |= FORCECLOSE;
  245         /* There is 1 extra root vnode reference from nwfs_mount(). */
  246         error = vflush(mp, 1, flags);
  247         if (error)
  248                 return (error);
  249         conn = NWFSTOCONN(nmp);
  250         ncp_conn_puthandle(nmp->connh,NULL,0);
  251         if (ncp_conn_lock(conn,p,p->p_ucred,NCPM_WRITE | NCPM_EXECUTE) == 0) {
  252                 if(ncp_disconnect(conn))
  253                         ncp_conn_unlock(conn,p);
  254         }
  255         mp->mnt_data = (qaddr_t)0;
  256         if (nmp->m.flags & NWFS_MOUNT_HAVE_NLS)
  257                 free(nmp->m.nls.to_lower, M_NWFSDATA);
  258         free(nmp, M_NWFSDATA);
  259         mp->mnt_flag &= ~MNT_LOCAL;
  260         return (error);
  261 }
  262 
  263 /*  Return locked vnode to root of a filesystem */
  264 static int
  265 nwfs_root(struct mount *mp, struct vnode **vpp) {
  266         struct vnode *vp;
  267         struct nwmount *nmp;
  268         struct nwnode *np;
  269         struct ncp_conn *conn;
  270         struct nw_entry_info fattr;
  271         struct proc *p = curproc;
  272         struct ucred *cred = p->p_ucred;
  273         int error, nsf, opt;
  274         u_char vol;
  275 
  276         nmp = VFSTONWFS(mp);
  277         conn = NWFSTOCONN(nmp);
  278         if (nmp->n_root) {
  279                 *vpp = NWTOV(nmp->n_root);
  280                 while (vget(*vpp, LK_EXCLUSIVE, curproc) != 0)
  281                         ;
  282                 return 0;
  283         }
  284         error = ncp_lookup_volume(conn, nmp->m.mounted_vol, &vol, 
  285                 &nmp->n_rootent.f_id, p, cred);
  286         if (error)
  287                 return ENOENT;
  288         nmp->n_volume = vol;
  289         error = ncp_get_namespaces(conn, vol, &nsf, p, cred);
  290         if (error)
  291                 return ENOENT;
  292         if (nsf & NW_NSB_OS2) {
  293                 NCPVODEBUG("volume %s has os2 namespace\n",nmp->m.mounted_vol);
  294                 if ((nmp->m.flags & NWFS_MOUNT_NO_OS2) == 0) {
  295                         nmp->name_space = NW_NS_OS2;
  296                         nmp->m.nls.opt &= ~NWHP_DOS;
  297                 }
  298         }
  299         opt = nmp->m.nls.opt;
  300         nsf = opt & (NWHP_UPPER | NWHP_LOWER);
  301         if (opt & NWHP_DOS) {
  302                 if (nsf == (NWHP_UPPER | NWHP_LOWER)) {
  303                         nmp->m.nls.opt &= ~(NWHP_LOWER | NWHP_UPPER);
  304                 } else if (nsf == 0) {
  305                         nmp->m.nls.opt |= NWHP_LOWER;
  306                 }
  307         } else {
  308                 if (nsf == (NWHP_UPPER | NWHP_LOWER)) {
  309                         nmp->m.nls.opt &= ~(NWHP_LOWER | NWHP_UPPER);
  310                 }
  311         }
  312         if (nmp->m.root_path[0]) {
  313                 nmp->m.root_path[0]--;
  314                 error = ncp_obtain_info(nmp, nmp->n_rootent.f_id,
  315                     -nmp->m.root_path[0], nmp->m.root_path, &fattr, p, cred);
  316                 if (error) {
  317                         NCPFATAL("Invalid root path specified\n");
  318                         return ENOENT;
  319                 }
  320                 nmp->n_rootent.f_parent = fattr.dirEntNum;
  321                 nmp->m.root_path[0]++;
  322                 error = ncp_obtain_info(nmp, nmp->n_rootent.f_id,
  323                     -nmp->m.root_path[0], nmp->m.root_path, &fattr, p, cred);
  324                 if (error) {
  325                         NCPFATAL("Invalid root path specified\n");
  326                         return ENOENT;
  327                 }
  328                 nmp->n_rootent.f_id = fattr.dirEntNum;
  329         } else {
  330                 error = ncp_obtain_info(nmp, nmp->n_rootent.f_id,
  331                     0, NULL, &fattr, p, cred);
  332                 if (error) {
  333                         NCPFATAL("Can't obtain volume info\n");
  334                         return ENOENT;
  335                 }
  336                 fattr.nameLen = strlen(strcpy(fattr.entryName, NWFS_ROOTVOL));
  337                 nmp->n_rootent.f_parent = nmp->n_rootent.f_id;
  338         }
  339         error = nwfs_nget(mp, nmp->n_rootent, &fattr, NULL, &vp);
  340         if (error)
  341                 return (error);
  342         vp->v_flag |= VROOT;
  343         np = VTONW(vp);
  344         if (nmp->m.root_path[0] == 0)
  345                 np->n_flag |= NVOLUME;
  346         nmp->n_root = np;
  347 /*      error = VOP_GETATTR(vp, &vattr, cred, p);
  348         if (error) {
  349                 vput(vp);
  350                 NCPFATAL("Can't get root directory entry\n");
  351                 return error;
  352         }*/
  353         *vpp = vp;
  354         return (0);
  355 }
  356 
  357 /*
  358  * Vfs start routine, a no-op.
  359  */
  360 /* ARGSUSED */
  361 static int
  362 nwfs_start(mp, flags, p)
  363         struct mount *mp;
  364         int flags;
  365         struct proc *p;
  366 {
  367         NCPVODEBUG("flags=%04x\n",flags);
  368         return (0);
  369 }
  370 
  371 /*
  372  * Do operations associated with quotas, not supported
  373  */
  374 /* ARGSUSED */
  375 static int
  376 nwfs_quotactl(mp, cmd, uid, arg, p)
  377         struct mount *mp;
  378         int cmd;
  379         uid_t uid;
  380         caddr_t arg;
  381         struct proc *p;
  382 {
  383         NCPVODEBUG("return EOPNOTSUPP\n");
  384         return (EOPNOTSUPP);
  385 }
  386 
  387 /*ARGSUSED*/
  388 int
  389 nwfs_init(struct vfsconf *vfsp)
  390 {
  391 #ifndef SMP
  392         size_t olen, plen;
  393         int name[2];
  394         int ncpu, error;
  395 
  396         name[0] = CTL_HW;
  397         name[1] = HW_NCPU;
  398         olen = sizeof(ncpu);
  399         error = kernel_sysctl(curproc, name, 2, &ncpu, &olen, NULL, 0, &plen);
  400         if (error == 0 && ncpu > 1)
  401                 printf("warning: nwfs module compiled without SMP support.");
  402 #endif
  403         nwfs_hash_init();
  404         nwfs_pbuf_freecnt = nswbuf / 2 + 1;
  405         NCPVODEBUG("always happy to load!\n");
  406         return (0);
  407 }
  408 
  409 /*ARGSUSED*/
  410 int
  411 nwfs_uninit(struct vfsconf *vfsp)
  412 {
  413 
  414         nwfs_hash_free();
  415         NCPVODEBUG("unloaded\n");
  416         return (0);
  417 }
  418 
  419 /*
  420  * nwfs_statfs call
  421  */
  422 int
  423 nwfs_statfs(mp, sbp, p)
  424         struct mount *mp;
  425         struct statfs *sbp;
  426         struct proc *p;
  427 {
  428         struct nwmount *nmp = VFSTONWFS(mp);
  429         int error = 0, secsize;
  430         struct nwnode *np = nmp->n_root;
  431         struct ncp_volume_info vi;
  432 
  433         if (np == NULL) return EINVAL;
  434         error = ncp_get_volume_info_with_number(NWFSTOCONN(nmp), nmp->n_volume, &vi,p,p->p_ucred);
  435         if (error) return error;
  436         secsize = 512;                  /* XXX how to get real value ??? */
  437         sbp->f_spare2=0;                /* placeholder */
  438         /* fundamental file system block size */
  439         sbp->f_bsize = vi.sectors_per_block*secsize;
  440         /* optimal transfer block size */
  441         sbp->f_iosize = NWFSTOCONN(nmp)->buffer_size;
  442         /* total data blocks in file system */
  443         sbp->f_blocks= vi.total_blocks;
  444         /* free blocks in fs */
  445         sbp->f_bfree = vi.free_blocks + vi.purgeable_blocks;
  446         /* free blocks avail to non-superuser */
  447         sbp->f_bavail= vi.free_blocks+vi.purgeable_blocks;
  448         /* total file nodes in file system */
  449         sbp->f_files = vi.total_dir_entries;
  450         /* free file nodes in fs */
  451         sbp->f_ffree = vi.available_dir_entries;
  452         sbp->f_flags = 0;               /* copy of mount exported flags */
  453         if (sbp != &mp->mnt_stat) {
  454                 sbp->f_fsid = mp->mnt_stat.f_fsid;      /* file system id */
  455                 sbp->f_owner = mp->mnt_stat.f_owner;    /* user that mounted the filesystem */
  456                 sbp->f_type = mp->mnt_vfc->vfc_typenum; /* type of filesystem */
  457                 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
  458                 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
  459         }
  460         strncpy(sbp->f_fstypename, mp->mnt_vfc->vfc_name, MFSNAMELEN);
  461         return 0;
  462 }
  463 
  464 /*
  465  * Flush out the buffer cache
  466  */
  467 /* ARGSUSED */
  468 static int
  469 nwfs_sync(mp, waitfor, cred, p)
  470         struct mount *mp;
  471         int waitfor;
  472         struct ucred *cred;
  473         struct proc *p;
  474 {
  475         struct vnode *vp;
  476         int error, allerror = 0;
  477         /*
  478          * Force stale buffer cache information to be flushed.
  479          */
  480 loop:
  481         for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist);
  482              vp != NULL;
  483              vp = TAILQ_NEXT(vp, v_nmntvnodes)) {
  484                 /*
  485                  * If the vnode that we are about to sync is no longer
  486                  * associated with this mount point, start over.
  487                  */
  488                 if (vp->v_mount != mp)
  489                         goto loop;
  490                 if (VOP_ISLOCKED(vp, NULL) || TAILQ_EMPTY(&vp->v_dirtyblkhd) ||
  491                     waitfor == MNT_LAZY)
  492                         continue;
  493                 if (vget(vp, LK_EXCLUSIVE, p))
  494                         goto loop;
  495                 error = VOP_FSYNC(vp, cred, waitfor, p);
  496                 if (error)
  497                         allerror = error;
  498                 vput(vp);
  499         }
  500         return (allerror);
  501 }

Cache object: d7981585fb4d1b8bc1f23e06c2f85cce


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.