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/fs/nwfs/nwfs_vnops.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, 2001 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 <sys/param.h>
   35 #include <sys/systm.h>
   36 #include <sys/namei.h>
   37 #include <sys/kernel.h>
   38 #include <sys/bio.h>
   39 #include <sys/buf.h>
   40 #include <sys/fcntl.h>
   41 #include <sys/mount.h>
   42 #include <sys/unistd.h>
   43 #include <sys/vnode.h>
   44 
   45 #include <vm/vm.h>
   46 #include <vm/vm_extern.h>
   47 
   48 #include <machine/mutex.h>
   49 
   50 #include <netncp/ncp.h>
   51 #include <netncp/ncp_conn.h>
   52 #include <netncp/ncp_subr.h>
   53 #include <netncp/nwerror.h>
   54 #include <netncp/ncp_nls.h>
   55 
   56 #include <fs/nwfs/nwfs.h>
   57 #include <fs/nwfs/nwfs_node.h>
   58 #include <fs/nwfs/nwfs_subr.h>
   59 
   60 /*
   61  * Prototypes for NWFS vnode operations
   62  */
   63 static vop_create_t     nwfs_create;
   64 static vop_mknod_t      nwfs_mknod;
   65 static vop_open_t       nwfs_open;
   66 static vop_close_t      nwfs_close;
   67 static vop_access_t     nwfs_access;
   68 static vop_getattr_t    nwfs_getattr;
   69 static vop_setattr_t    nwfs_setattr;
   70 static vop_read_t       nwfs_read;
   71 static vop_write_t      nwfs_write;
   72 static vop_fsync_t      nwfs_fsync;
   73 static vop_remove_t     nwfs_remove;
   74 static vop_link_t       nwfs_link;
   75 static vop_lookup_t     nwfs_lookup;
   76 static vop_rename_t     nwfs_rename;
   77 static vop_mkdir_t      nwfs_mkdir;
   78 static vop_rmdir_t      nwfs_rmdir;
   79 static vop_symlink_t    nwfs_symlink;
   80 static vop_readdir_t    nwfs_readdir;
   81 static vop_strategy_t   nwfs_strategy;
   82 static vop_print_t      nwfs_print;
   83 static vop_pathconf_t   nwfs_pathconf;
   84 
   85 /* Global vfs data structures for nwfs */
   86 struct vop_vector nwfs_vnodeops = {
   87         .vop_default =          &default_vnodeops,
   88 
   89         .vop_access =           nwfs_access,
   90         .vop_close =            nwfs_close,
   91         .vop_create =           nwfs_create,
   92         .vop_fsync =            nwfs_fsync,
   93         .vop_getattr =          nwfs_getattr,
   94         .vop_getpages =         nwfs_getpages,
   95         .vop_inactive =         nwfs_inactive,
   96         .vop_ioctl =            nwfs_ioctl,
   97         .vop_link =             nwfs_link,
   98         .vop_lookup =           nwfs_lookup,
   99         .vop_mkdir =            nwfs_mkdir,
  100         .vop_mknod =            nwfs_mknod,
  101         .vop_open =             nwfs_open,
  102         .vop_pathconf =         nwfs_pathconf,
  103         .vop_print =            nwfs_print,
  104         .vop_putpages =         nwfs_putpages,
  105         .vop_read =             nwfs_read,
  106         .vop_readdir =          nwfs_readdir,
  107         .vop_reclaim =          nwfs_reclaim,
  108         .vop_remove =           nwfs_remove,
  109         .vop_rename =           nwfs_rename,
  110         .vop_rmdir =            nwfs_rmdir,
  111         .vop_setattr =          nwfs_setattr,
  112         .vop_strategy =         nwfs_strategy,
  113         .vop_symlink =          nwfs_symlink,
  114         .vop_write =            nwfs_write,
  115 };
  116 
  117 /*
  118  * nwfs_access vnode op
  119  */
  120 static int
  121 nwfs_access(ap)
  122         struct vop_access_args /* {
  123                 struct vnode *a_vp;
  124                 int  a_mode;
  125                 struct ucred *a_cred;
  126                 struct thread *td;
  127         } */ *ap;
  128 {
  129         struct vnode *vp = ap->a_vp;
  130         mode_t mpmode;
  131         struct nwmount *nmp = VTONWFS(vp);
  132 
  133         NCPVNDEBUG("\n");
  134         if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
  135                 switch (vp->v_type) {
  136                     case VREG: case VDIR: case VLNK:
  137                         return (EROFS);
  138                     default:
  139                         break;
  140                 }
  141         }
  142         mpmode = vp->v_type == VREG ? nmp->m.file_mode :
  143             nmp->m.dir_mode;
  144         return (vaccess(vp->v_type, mpmode, nmp->m.uid,
  145             nmp->m.gid, ap->a_mode, ap->a_cred, NULL));
  146 }
  147 /*
  148  * nwfs_open vnode op
  149  */
  150 /* ARGSUSED */
  151 static int
  152 nwfs_open(ap)
  153         struct vop_open_args /* {
  154                 struct vnode *a_vp;
  155                 int  a_mode;
  156                 struct ucred *a_cred;
  157                 struct thread *td;
  158         } */ *ap;
  159 {
  160         struct vnode *vp = ap->a_vp;
  161         int mode = ap->a_mode;
  162         struct nwnode *np = VTONW(vp);
  163         struct ncp_open_info no;
  164         struct nwmount *nmp = VTONWFS(vp);
  165         struct vattr vattr;
  166         int error, nwm;
  167 
  168         NCPVNDEBUG("%s,%d\n", np->n_name, np->opened);
  169         if (vp->v_type != VREG && vp->v_type != VDIR) { 
  170                 NCPFATAL("open vtype = %d\n", vp->v_type);
  171                 return (EACCES);
  172         }
  173         if (vp->v_type == VDIR) return 0;       /* nothing to do now */
  174         if (np->n_flag & NMODIFIED) {
  175                 if ((error = nwfs_vinvalbuf(vp, ap->a_td)) == EINTR)
  176                         return (error);
  177                 np->n_atime = 0;
  178                 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
  179                 if (error) return (error);
  180                 np->n_mtime = vattr.va_mtime.tv_sec;
  181         } else {
  182                 error = VOP_GETATTR(vp, &vattr, ap->a_cred, ap->a_td);
  183                 if (error) return (error);
  184                 if (np->n_mtime != vattr.va_mtime.tv_sec) {
  185                         if ((error = nwfs_vinvalbuf(vp, ap->a_td)) == EINTR)
  186                                 return (error);
  187                         np->n_mtime = vattr.va_mtime.tv_sec;
  188                 }
  189         }
  190         if (np->opened) {
  191                 np->opened++;
  192                 return 0;
  193         }
  194         nwm = AR_READ;
  195         if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
  196                 nwm |= AR_WRITE;
  197         error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN,
  198                                                0, nwm, &no, ap->a_td, ap->a_cred);
  199         if (error) {
  200                 if (mode & FWRITE)
  201                         return EACCES;
  202                 nwm = AR_READ;
  203                 error = ncp_open_create_file_or_subdir(nmp, vp, 0, NULL, OC_MODE_OPEN, 0,
  204                                                    nwm, &no, ap->a_td, ap->a_cred);
  205         }
  206         if (!error) {
  207                 np->opened++;
  208                 np->n_fh = no.fh;
  209                 np->n_origfh = no.origfh;
  210         }
  211         np->n_atime = 0;
  212         return (error);
  213 }
  214 
  215 static int
  216 nwfs_close(ap)
  217         struct vop_close_args /* {
  218                 struct vnodeop_desc *a_desc;
  219                 struct vnode *a_vp;
  220                 int  a_fflag;
  221                 struct ucred *a_cred;
  222                 struct thread *td;
  223         } */ *ap;
  224 {
  225         struct vnode *vp = ap->a_vp;
  226         struct nwnode *np = VTONW(vp);
  227         int error;
  228 
  229         NCPVNDEBUG("name=%s,pid=%d,c=%d\n", np->n_name, ap->a_td->td_proc->p_pid,
  230                         np->opened);
  231 
  232         if (vp->v_type == VDIR) return 0;       /* nothing to do now */
  233         error = 0;
  234         mtx_lock(&vp->v_interlock);
  235         if (np->opened == 0) {
  236                 mtx_unlock(&vp->v_interlock);
  237                 return 0;
  238         }
  239         mtx_unlock(&vp->v_interlock);
  240         error = nwfs_vinvalbuf(vp, ap->a_td);
  241         mtx_lock(&vp->v_interlock);
  242         if (np->opened == 0) {
  243                 mtx_unlock(&vp->v_interlock);
  244                 return 0;
  245         }
  246         if (--np->opened == 0) {
  247                 mtx_unlock(&vp->v_interlock);
  248                 error = ncp_close_file(NWFSTOCONN(VTONWFS(vp)), &np->n_fh, 
  249                    ap->a_td, ap->a_cred);
  250         } else
  251                 mtx_unlock(&vp->v_interlock);
  252         np->n_atime = 0;
  253         return (error);
  254 }
  255 
  256 /*
  257  * nwfs_getattr call from vfs.
  258  */
  259 static int
  260 nwfs_getattr(ap)
  261         struct vop_getattr_args /* {
  262                 struct vnode *a_vp;
  263                 struct vattr *a_vap;
  264                 struct ucred *a_cred;
  265                 struct thread *td;
  266         } */ *ap;
  267 {
  268         struct vnode *vp = ap->a_vp;
  269         struct nwnode *np = VTONW(vp);
  270         struct vattr *va=ap->a_vap;
  271         struct nwmount *nmp = VTONWFS(vp);
  272         struct nw_entry_info fattr;
  273         int error;
  274         u_int32_t oldsize;
  275 
  276         NCPVNDEBUG("%lx:%d: '%s' %d\n", (long)vp, nmp->n_volume, np->n_name, (vp->v_vflag & VV_ROOT) != 0);
  277         error = nwfs_attr_cachelookup(vp, va);
  278         if (!error) return 0;
  279         NCPVNDEBUG("not in cache\n");
  280         oldsize = np->n_size;
  281         if (np->n_flag & NVOLUME) {
  282                 error = ncp_obtain_info(nmp, np->n_fid.f_id, 0, NULL, &fattr,
  283                     ap->a_td, ap->a_cred);
  284         } else {
  285                 error = ncp_obtain_info(nmp, np->n_fid.f_parent, np->n_nmlen, 
  286                     np->n_name, &fattr, ap->a_td, ap->a_cred);
  287         }
  288         if (error) {
  289                 NCPVNDEBUG("error %d\n", error);
  290                 return error;
  291         }
  292         nwfs_attr_cacheenter(vp, &fattr);
  293         *va = np->n_vattr;
  294         if (np->opened)
  295                 np->n_size = oldsize;
  296         return (0);
  297 }
  298 /*
  299  * nwfs_setattr call from vfs.
  300  */
  301 static int
  302 nwfs_setattr(ap)
  303         struct vop_setattr_args /* {
  304                 struct vnode *a_vp;
  305                 struct vattr *a_vap;
  306                 struct ucred *a_cred;
  307                 struct thread *td;
  308         } */ *ap;
  309 {
  310         struct vnode *vp = ap->a_vp;
  311         struct nwnode *np = VTONW(vp);
  312         struct vattr *vap = ap->a_vap;
  313         u_quad_t tsize=0;
  314         int error = 0;
  315 
  316         NCPVNDEBUG("\n");
  317         if (vap->va_flags != VNOVAL)
  318                 return (EOPNOTSUPP);
  319         /*
  320          * Disallow write attempts if the filesystem is mounted read-only.
  321          */
  322         if ((vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL || 
  323              vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
  324              vap->va_mode != (mode_t)VNOVAL) &&(vp->v_mount->mnt_flag & MNT_RDONLY))
  325                 return (EROFS);
  326         if (vap->va_size != VNOVAL) {
  327                 switch (vp->v_type) {
  328                 case VDIR:
  329                         return (EISDIR);
  330                 case VREG:
  331                         /*
  332                          * Disallow write attempts if the filesystem is
  333                          * mounted read-only.
  334                          */
  335                         if (vp->v_mount->mnt_flag & MNT_RDONLY)
  336                                 return (EROFS);
  337                         vnode_pager_setsize(vp, (u_long)vap->va_size);
  338                         tsize = np->n_size;
  339                         np->n_size = vap->va_size;
  340                         break;
  341                 default:
  342                         return EINVAL;
  343                 };
  344         }
  345         error = ncp_setattr(vp, vap, ap->a_cred, ap->a_td);
  346         if (error && vap->va_size != VNOVAL) {
  347                 np->n_size = tsize;
  348                 vnode_pager_setsize(vp, (u_long)tsize);
  349         }
  350         np->n_atime = 0;        /* invalidate cache */
  351         VOP_GETATTR(vp, vap, ap->a_cred, ap->a_td);
  352         np->n_mtime = vap->va_mtime.tv_sec;
  353         return (0);
  354 }
  355 /*
  356  * nwfs_read call.
  357  */
  358 static int
  359 nwfs_read(ap)
  360         struct vop_read_args /* {
  361                 struct vnode *a_vp;
  362                 struct uio *a_uio;
  363                 int  a_ioflag;
  364                 struct ucred *a_cred;
  365         } */ *ap;
  366 {
  367         struct vnode *vp = ap->a_vp;
  368         struct uio *uio=ap->a_uio;
  369         int error;
  370         NCPVNDEBUG("nwfs_read:\n");
  371 
  372         if (vp->v_type != VREG && vp->v_type != VDIR)
  373                 return (EPERM);
  374         error = nwfs_readvnode(vp, uio, ap->a_cred);
  375         return error;
  376 }
  377 
  378 static int
  379 nwfs_write(ap)
  380         struct vop_write_args /* {
  381                 struct vnode *a_vp;
  382                 struct uio *a_uio;
  383                 int  a_ioflag;
  384                 struct ucred *a_cred;
  385         } */ *ap;
  386 {
  387         struct vnode *vp = ap->a_vp;
  388         struct uio *uio = ap->a_uio;
  389         int error;
  390 
  391         NCPVNDEBUG("%d,ofs=%d,sz=%d\n", vp->v_type, (int)uio->uio_offset, uio->uio_resid);
  392 
  393         if (vp->v_type != VREG)
  394                 return (EPERM);
  395         error = nwfs_writevnode(vp, uio, ap->a_cred, ap->a_ioflag);
  396         return(error);
  397 }
  398 /*
  399  * nwfs_create call
  400  * Create a regular file. On entry the directory to contain the file being
  401  * created is locked.  We must release before we return. We must also free
  402  * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
  403  * only if the SAVESTART bit in cn_flags is clear on success.
  404  */
  405 static int
  406 nwfs_create(ap)
  407         struct vop_create_args /* {
  408                 struct vnode *a_dvp;
  409                 struct vnode **a_vpp;
  410                 struct componentname *a_cnp;
  411                 struct vattr *a_vap;
  412         } */ *ap;
  413 {
  414         struct vnode *dvp = ap->a_dvp;
  415         struct vattr *vap = ap->a_vap;
  416         struct vnode **vpp=ap->a_vpp;
  417         struct componentname *cnp = ap->a_cnp;
  418         struct vnode *vp = (struct vnode *)0;
  419         int error = 0, fmode;
  420         struct vattr vattr;
  421         struct nwnode *np;
  422         struct ncp_open_info no;
  423         struct nwmount *nmp=VTONWFS(dvp);
  424         ncpfid fid;
  425         
  426 
  427         NCPVNDEBUG("\n");
  428         *vpp = NULL;
  429         if (vap->va_type == VSOCK)
  430                 return (EOPNOTSUPP);
  431         if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
  432                 return (error);
  433         }
  434         fmode = AR_READ | AR_WRITE;
  435 /*      if (vap->va_vaflags & VA_EXCLUSIVE)
  436                 fmode |= AR_DENY_READ | AR_DENY_WRITE;*/
  437         
  438         error = ncp_open_create_file_or_subdir(nmp, dvp, cnp->cn_namelen, cnp->cn_nameptr, 
  439                            OC_MODE_CREATE | OC_MODE_OPEN | OC_MODE_REPLACE,
  440                            0, fmode, &no, cnp->cn_thread, cnp->cn_cred);
  441         if (!error) {
  442                 error = ncp_close_file(NWFSTOCONN(nmp), &no.fh, cnp->cn_thread, cnp->cn_cred);
  443                 fid.f_parent = VTONW(dvp)->n_fid.f_id;
  444                 fid.f_id = no.fattr.dirEntNum;
  445                 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &vp);
  446                 if (!error) {
  447                         np = VTONW(vp);
  448                         np->opened = 0;
  449                         *vpp = vp;
  450                 }
  451                 if (cnp->cn_flags & MAKEENTRY)
  452                         cache_enter(dvp, vp, cnp);
  453         }
  454         return (error);
  455 }
  456 
  457 /*
  458  * nwfs_remove call. It isn't possible to emulate UFS behaivour because
  459  * NetWare doesn't allow delete/rename operations on an opened file.
  460  */
  461 static int
  462 nwfs_remove(ap)
  463         struct vop_remove_args /* {
  464                 struct vnodeop_desc *a_desc;
  465                 struct vnode * a_dvp;
  466                 struct vnode * a_vp;
  467                 struct componentname * a_cnp;
  468         } */ *ap;
  469 {
  470         struct vnode *vp = ap->a_vp;
  471         struct vnode *dvp = ap->a_dvp;
  472         struct componentname *cnp = ap->a_cnp;
  473         struct nwnode *np = VTONW(vp);
  474         struct nwmount *nmp = VTONWFS(vp);
  475         int error;
  476 
  477         if (vp->v_type == VDIR || np->opened || vrefcnt(vp) != 1)
  478                 return EPERM;
  479         cache_purge(vp);
  480         error = ncp_DeleteNSEntry(nmp, VTONW(dvp)->n_fid.f_id,
  481             cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
  482         if (error == 0)
  483                 np->n_flag |= NSHOULDFREE;
  484         else if (error == 0x899c)
  485                 error = EACCES;
  486         return (error);
  487 }
  488 
  489 /*
  490  * nwfs_file rename call
  491  */
  492 static int
  493 nwfs_rename(ap)
  494         struct vop_rename_args  /* {
  495                 struct vnode *a_fdvp;
  496                 struct vnode *a_fvp;
  497                 struct componentname *a_fcnp;
  498                 struct vnode *a_tdvp;
  499                 struct vnode *a_tvp;
  500                 struct componentname *a_tcnp;
  501         } */ *ap;
  502 {
  503         struct vnode *fvp = ap->a_fvp;
  504         struct vnode *tvp = ap->a_tvp;
  505         struct vnode *fdvp = ap->a_fdvp;
  506         struct vnode *tdvp = ap->a_tdvp;
  507         struct componentname *tcnp = ap->a_tcnp;
  508         struct componentname *fcnp = ap->a_fcnp;
  509         struct nwmount *nmp=VTONWFS(fvp);
  510         u_int16_t oldtype = 6;
  511         int error=0;
  512 
  513         /* Check for cross-device rename */
  514         if ((fvp->v_mount != tdvp->v_mount) ||
  515             (tvp && (fvp->v_mount != tvp->v_mount))) {
  516                 error = EXDEV;
  517                 goto out;
  518         }
  519 
  520         if (tvp && vrefcnt(tvp) > 1) {
  521                 error = EBUSY;
  522                 goto out;
  523         }
  524         if (fvp->v_type == VDIR) {
  525                 oldtype |= NW_TYPE_SUBDIR;
  526         } else if (fvp->v_type == VREG) {
  527                 oldtype |= NW_TYPE_FILE;
  528         } else {
  529                 error = EINVAL;
  530                 goto out;
  531         }
  532         if (tvp && tvp != fvp) {
  533                 error = ncp_DeleteNSEntry(nmp, VTONW(tdvp)->n_fid.f_id,
  534                     tcnp->cn_namelen, tcnp->cn_nameptr, 
  535                     tcnp->cn_thread, tcnp->cn_cred);
  536                 if (error == 0x899c) error = EACCES;
  537                 if (error)
  538                         goto out_cacherem;
  539         }
  540         error = ncp_nsrename(NWFSTOCONN(nmp), nmp->n_volume, nmp->name_space, 
  541                 oldtype, &nmp->m.nls,
  542                 VTONW(fdvp)->n_fid.f_id, fcnp->cn_nameptr, fcnp->cn_namelen,
  543                 VTONW(tdvp)->n_fid.f_id, tcnp->cn_nameptr, tcnp->cn_namelen,
  544                 tcnp->cn_thread, tcnp->cn_cred);
  545 
  546         if (error == 0x8992)
  547                 error = EEXIST;
  548         if (fvp->v_type == VDIR) {
  549                 if (tvp != NULL && tvp->v_type == VDIR)
  550                         cache_purge(tdvp);
  551                 cache_purge(fdvp);
  552         }
  553 out_cacherem:
  554         nwfs_attr_cacheremove(fdvp);
  555         nwfs_attr_cacheremove(tdvp);
  556         nwfs_attr_cacheremove(fvp);
  557 out:
  558         if (tdvp == tvp)
  559                 vrele(tdvp);
  560         else
  561                 vput(tdvp);
  562         if (tvp)
  563                 vput(tvp);
  564         vrele(fdvp);
  565         vrele(fvp);
  566         if (tvp)
  567                 nwfs_attr_cacheremove(tvp);
  568         /*
  569          * Kludge: Map ENOENT => 0 assuming that it is a reply to a retry.
  570          */
  571         if (error == ENOENT)
  572                 error = 0;
  573         return (error);
  574 }
  575 
  576 /*
  577  * nwfs hard link create call
  578  * Netware filesystems don't know what links are.
  579  */
  580 static int
  581 nwfs_link(ap)
  582         struct vop_link_args /* {
  583                 struct vnode *a_tdvp;
  584                 struct vnode *a_vp;
  585                 struct componentname *a_cnp;
  586         } */ *ap;
  587 {
  588         return EOPNOTSUPP;
  589 }
  590 
  591 /*
  592  * nwfs_symlink link create call
  593  * Netware filesystems don't know what symlinks are.
  594  */
  595 static int
  596 nwfs_symlink(ap)
  597         struct vop_symlink_args /* {
  598                 struct vnode *a_dvp;
  599                 struct vnode **a_vpp;
  600                 struct componentname *a_cnp;
  601                 struct vattr *a_vap;
  602                 char *a_target;
  603         } */ *ap;
  604 {
  605         return (EOPNOTSUPP);
  606 }
  607 
  608 static int nwfs_mknod(ap) 
  609         struct vop_mknod_args /* {
  610         } */ *ap;
  611 {
  612         return (EOPNOTSUPP);
  613 }
  614 
  615 /*
  616  * nwfs_mkdir call
  617  */
  618 static int
  619 nwfs_mkdir(ap)
  620         struct vop_mkdir_args /* {
  621                 struct vnode *a_dvp;
  622                 struct vnode **a_vpp;
  623                 struct componentname *a_cnp;
  624                 struct vattr *a_vap;
  625         } */ *ap;
  626 {
  627         struct vnode *dvp = ap->a_dvp;
  628 /*      struct vattr *vap = ap->a_vap;*/
  629         struct componentname *cnp = ap->a_cnp;
  630         int len=cnp->cn_namelen;
  631         struct ncp_open_info no;
  632         struct nwnode *np;
  633         struct vnode *newvp = (struct vnode *)0;
  634         ncpfid fid;
  635         int error = 0;
  636         struct vattr vattr;
  637         char *name=cnp->cn_nameptr;
  638 
  639         if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred, cnp->cn_thread))) {
  640                 return (error);
  641         }       
  642         if ((name[0] == '.') && ((len == 1) || ((len == 2) && (name[1] == '.')))) {
  643                 return EEXIST;
  644         }
  645         if (ncp_open_create_file_or_subdir(VTONWFS(dvp), dvp, cnp->cn_namelen,
  646                         cnp->cn_nameptr, OC_MODE_CREATE, aDIR, 0xffff,
  647                         &no, cnp->cn_thread, cnp->cn_cred) != 0) {
  648                 error = EACCES;
  649         } else {
  650                 error = 0;
  651         }
  652         if (!error) {
  653                 fid.f_parent = VTONW(dvp)->n_fid.f_id;
  654                 fid.f_id = no.fattr.dirEntNum;
  655                 error = nwfs_nget(VTOVFS(dvp), fid, &no.fattr, dvp, &newvp);
  656                 if (!error) {
  657                         np = VTONW(newvp);
  658                         newvp->v_type = VDIR;
  659                         *ap->a_vpp = newvp;
  660                 }
  661         }
  662         return (error);
  663 }
  664 
  665 /*
  666  * nwfs_remove directory call
  667  */
  668 static int
  669 nwfs_rmdir(ap)
  670         struct vop_rmdir_args /* {
  671                 struct vnode *a_dvp;
  672                 struct vnode *a_vp;
  673                 struct componentname *a_cnp;
  674         } */ *ap;
  675 {
  676         struct vnode *vp = ap->a_vp;
  677         struct vnode *dvp = ap->a_dvp;
  678         struct componentname *cnp = ap->a_cnp;
  679         struct nwnode *np = VTONW(vp);
  680         struct nwmount *nmp = VTONWFS(vp);
  681         struct nwnode *dnp = VTONW(dvp);
  682         int error = EIO;
  683 
  684         if (dvp == vp)
  685                 return EINVAL;
  686 
  687         error = ncp_DeleteNSEntry(nmp, dnp->n_fid.f_id, 
  688                 cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_thread, cnp->cn_cred);
  689         if (error == 0)
  690                 np->n_flag |= NSHOULDFREE;
  691         else if (error == NWE_DIR_NOT_EMPTY)
  692                 error = ENOTEMPTY;
  693         dnp->n_flag |= NMODIFIED;
  694         nwfs_attr_cacheremove(dvp);
  695         cache_purge(dvp);
  696         cache_purge(vp);
  697         return (error);
  698 }
  699 
  700 /*
  701  * nwfs_readdir call
  702  */
  703 static int
  704 nwfs_readdir(ap)
  705         struct vop_readdir_args /* {
  706                 struct vnode *a_vp;
  707                 struct uio *a_uio;
  708                 struct ucred *a_cred;
  709                 int *a_eofflag;
  710                 u_long *a_cookies;
  711                 int a_ncookies;
  712         } */ *ap;
  713 {
  714         struct vnode *vp = ap->a_vp;
  715         struct uio *uio = ap->a_uio;
  716         int error;
  717 
  718         if (vp->v_type != VDIR)
  719                 return (EPERM);
  720         if (ap->a_ncookies) {
  721                 printf("nwfs_readdir: no support for cookies now...");
  722                 return (EOPNOTSUPP);
  723         }
  724 
  725         error = nwfs_readvnode(vp, uio, ap->a_cred);
  726         return error;
  727 }
  728 /* ARGSUSED */
  729 static int
  730 nwfs_fsync(ap)
  731         struct vop_fsync_args /* {
  732                 struct vnodeop_desc *a_desc;
  733                 struct vnode * a_vp;
  734                 struct ucred * a_cred;
  735                 int  a_waitfor;
  736                 struct thread *a_td;
  737         } */ *ap;
  738 {
  739 /*      return (nfs_flush(ap->a_vp, ap->a_cred, ap->a_waitfor, ap->a_td, 1));*/
  740     return (0);
  741 }
  742 
  743 /* ARGSUSED */
  744 static 
  745 int nwfs_print (ap) 
  746         struct vop_print_args /* {
  747                 struct vnode *a_vp;
  748         } */ *ap;
  749 {
  750         struct vnode *vp = ap->a_vp;
  751         struct nwnode *np = VTONW(vp);
  752 
  753         printf("\tnwfs node: name = '%s', fid = %d, pfid = %d\n",
  754             np->n_name, np->n_fid.f_id, np->n_fid.f_parent);
  755         return (0);
  756 }
  757 
  758 static int nwfs_pathconf (ap)
  759         struct vop_pathconf_args  /* {
  760         struct vnode *vp;
  761         int name;
  762         register_t *retval;
  763         } */ *ap;
  764 {
  765         int name=ap->a_name, error=0;
  766         register_t *retval=ap->a_retval;
  767         
  768         switch(name){
  769                 case _PC_LINK_MAX:
  770                         *retval=0;
  771                         break;
  772                 case _PC_NAME_MAX:
  773                         *retval=NCP_MAX_FILENAME; /* XXX from nwfsnode */
  774                         break;
  775                 case _PC_PATH_MAX:
  776                         *retval=NCP_MAXPATHLEN; /* XXX from nwfsnode */
  777                         break;
  778                 default:
  779                         error=EINVAL;
  780         }
  781         return(error);
  782 }
  783 
  784 static int nwfs_strategy (ap) 
  785         struct vop_strategy_args /* {
  786         struct buf *a_bp
  787         } */ *ap;
  788 {
  789         struct buf *bp=ap->a_bp;
  790         struct ucred *cr;
  791         struct thread *td;
  792         int error = 0;
  793 
  794         NCPVNDEBUG("\n");
  795         if (bp->b_flags & B_ASYNC)
  796                 td = (struct thread *)0;
  797         else
  798                 td = curthread; /* XXX */
  799         if (bp->b_iocmd == BIO_READ)
  800                 cr = bp->b_rcred;
  801         else
  802                 cr = bp->b_wcred;
  803         /*
  804          * If the op is asynchronous and an i/o daemon is waiting
  805          * queue the request, wake it up and wait for completion
  806          * otherwise just do it ourselves.
  807          */
  808         if ((bp->b_flags & B_ASYNC) == 0 )
  809                 error = nwfs_doio(ap->a_vp, bp, cr, td);
  810         return (error);
  811 }
  812 
  813 
  814 /*
  815  * How to keep the brain busy ...
  816  * Currently lookup routine can make two lookup for vnode. This can be
  817  * avoided by reorg the code.
  818  */
  819 int
  820 nwfs_lookup(ap)
  821         struct vop_lookup_args /* {
  822                 struct vnodeop_desc *a_desc;
  823                 struct vnode *a_dvp;
  824                 struct vnode **a_vpp;
  825                 struct componentname *a_cnp;
  826         } */ *ap;
  827 {
  828         struct componentname *cnp = ap->a_cnp;
  829         struct vnode *dvp = ap->a_dvp;
  830         struct vnode **vpp = ap->a_vpp;
  831         int flags = cnp->cn_flags;
  832         struct vnode *vp;
  833         struct nwmount *nmp;
  834         struct mount *mp = dvp->v_mount;
  835         struct nwnode *dnp, *npp;
  836         struct nw_entry_info fattr, *fap;
  837         ncpfid fid;
  838         int nameiop=cnp->cn_nameiop, islastcn;
  839         int error = 0, notfound;
  840         struct thread *td = cnp->cn_thread;
  841         char _name[cnp->cn_namelen+1];
  842         bcopy(cnp->cn_nameptr, _name, cnp->cn_namelen);
  843         _name[cnp->cn_namelen]=0;
  844         
  845         if (dvp->v_type != VDIR)
  846                 return (ENOTDIR);
  847         if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT)) {
  848                 printf("nwfs_lookup: invalid '..'\n");
  849                 return EIO;
  850         }
  851 
  852         NCPVNDEBUG("%d '%s' in '%s' id=d\n", nameiop, _name, 
  853                 VTONW(dvp)->n_name/*, VTONW(dvp)->n_name*/);
  854 
  855         islastcn = flags & ISLASTCN;
  856         if (islastcn && (mp->mnt_flag & MNT_RDONLY) && (nameiop != LOOKUP))
  857                 return (EROFS);
  858         if ((error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td)))
  859                 return (error);
  860         nmp = VFSTONWFS(mp);
  861         dnp = VTONW(dvp);
  862 /*
  863 printf("dvp %d:%d:%d\n", (int)mp, (int)dvp->v_vflag & VV_ROOT, (int)flags & ISDOTDOT);
  864 */
  865         error = ncp_pathcheck(cnp->cn_nameptr, cnp->cn_namelen, &nmp->m.nls, 
  866             (nameiop == CREATE || nameiop == RENAME) && (nmp->m.nls.opt & NWHP_NOSTRICT) == 0);
  867         if (error) 
  868             return ENOENT;
  869 
  870         error = cache_lookup(dvp, vpp, cnp);
  871         NCPVNDEBUG("cache_lookup returned %d\n", error);
  872         if (error > 0)
  873                 return error;
  874         if (error) {            /* name was found */
  875                 struct vattr vattr;
  876 
  877                 vp = *vpp;
  878                 if (VOP_GETATTR(vp, &vattr, cnp->cn_cred, td) == 0 &&
  879                     vattr.va_ctime.tv_sec == VTONW(vp)->n_ctime) {
  880                         if (nameiop != LOOKUP && islastcn)
  881                                 cnp->cn_flags |= SAVENAME;
  882                         NCPVNDEBUG("use cached vnode");
  883                         return (0);
  884                 }
  885                 cache_purge(vp);
  886                 if (vp != dvp)
  887                         vput(vp);
  888                 else
  889                         vrele(vp);
  890                 *vpp = NULLVP;
  891         }
  892         /* not in cache, so ...  */
  893         error = 0;
  894         *vpp = NULLVP;
  895         fap = NULL;
  896         if (flags & ISDOTDOT) {
  897                 if (NWCMPF(&dnp->n_parent, &nmp->n_rootent)) {
  898                         fid = nmp->n_rootent;
  899                         fap = NULL;
  900                         notfound = 0;
  901                 } else {
  902                         error = nwfs_lookupnp(nmp, dnp->n_parent, td, &npp);
  903                         if (error) {
  904                                 return error;
  905                         }
  906                         fid = dnp->n_parent;
  907                         fap = &fattr;
  908                         /*np = *npp;*/
  909                         notfound = ncp_obtain_info(nmp, npp->n_dosfid,
  910                             0, NULL, fap, td, cnp->cn_cred);
  911                 }
  912         } else {
  913                 fap = &fattr;
  914                 notfound = ncp_lookup(dvp, cnp->cn_namelen, cnp->cn_nameptr,
  915                         fap, td, cnp->cn_cred);
  916                 fid.f_id = fap->dirEntNum;
  917                 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
  918                         fid.f_parent = dnp->n_fid.f_parent;
  919                 } else
  920                         fid.f_parent = dnp->n_fid.f_id;
  921                 NCPVNDEBUG("call to ncp_lookup returned=%d\n", notfound);
  922         }
  923         if (notfound && notfound < 0x80 )
  924                 return (notfound);      /* hard error */
  925         if (notfound) { /* entry not found */
  926                 /* Handle RENAME or CREATE case... */
  927                 if ((nameiop == CREATE || nameiop == RENAME) && islastcn) {
  928                         cnp->cn_flags |= SAVENAME;
  929                         return (EJUSTRETURN);
  930                 }
  931                 return ENOENT;
  932         }/* else {
  933                 NCPVNDEBUG("Found entry %s with id=%d\n", fap->entryName, fap->dirEntNum);
  934         }*/
  935         /* handle DELETE case ... */
  936         if (nameiop == DELETE && islastcn) {    /* delete last component */
  937                 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
  938                 if (error) return (error);
  939                 if (NWCMPF(&dnp->n_fid, &fid)) {        /* we found ourselfs */
  940                         VREF(dvp);
  941                         *vpp = dvp;
  942                         return 0;
  943                 }
  944                 error = nwfs_nget(mp, fid, fap, dvp, &vp);
  945                 if (error) return (error);
  946                 *vpp = vp;
  947                 cnp->cn_flags |= SAVENAME;      /* I free it later */
  948                 return (0);
  949         }
  950         if (nameiop == RENAME && islastcn) {
  951                 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, cnp->cn_thread);
  952                 if (error) return (error);
  953                 if (NWCMPF(&dnp->n_fid, &fid)) return EISDIR;
  954                 error = nwfs_nget(mp, fid, fap, dvp, &vp);
  955                 if (error) return (error);
  956                 *vpp = vp;
  957                 cnp->cn_flags |= SAVENAME;
  958                 return (0);
  959         }
  960         if (flags & ISDOTDOT) {
  961                 VOP_UNLOCK(dvp, 0, td);         /* race to get the inode */
  962                 error = nwfs_nget(mp, fid, NULL, NULL, &vp);
  963                 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
  964                 if (error)
  965                         return (error);
  966                 *vpp = vp;
  967         } else if (NWCMPF(&dnp->n_fid, &fid)) {
  968                 vref(dvp);
  969                 *vpp = dvp;
  970         } else {
  971                 error = nwfs_nget(mp, fid, fap, dvp, &vp);
  972                 if (error) return (error);
  973                 *vpp = vp;
  974                 NCPVNDEBUG("lookup: getnewvp!\n");
  975         }
  976         if ((cnp->cn_flags & MAKEENTRY)/* && !islastcn*/) {
  977                 VTONW(*vpp)->n_ctime = VTONW(*vpp)->n_vattr.va_ctime.tv_sec;
  978                 cache_enter(dvp, *vpp, cnp);
  979         }
  980         return (0);
  981 }

Cache object: 99aba6e041c097bb0e9c846c05732425


[ 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.