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/ntfs/ntfs_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 /*      $NetBSD: ntfs_vnops.c,v 1.23 1999/10/31 19:45:27 jdolecek Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 1992, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * This code is derived from software contributed to Berkeley by
    8  * John Heidemann of the UCLA Ficus project.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 4. Neither the name of the University nor the names of its contributors
   19  *    may be used to endorse or promote products derived from this software
   20  *    without specific prior written permission.
   21  *
   22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   32  * SUCH DAMAGE.
   33  *
   34  * $FreeBSD$
   35  *
   36  */
   37 
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/kernel.h>
   41 #include <sys/time.h>
   42 #include <sys/types.h>
   43 #include <sys/stat.h>
   44 #include <sys/vnode.h>
   45 #include <sys/mount.h>
   46 #include <sys/namei.h>
   47 #include <sys/malloc.h>
   48 #include <sys/bio.h>
   49 #include <sys/buf.h>
   50 #include <sys/dirent.h>
   51 
   52 #include <vm/vm.h>
   53 #include <vm/vm_param.h>
   54 #include <vm/vm_page.h>
   55 #include <vm/vm_object.h>
   56 #include <vm/vm_pager.h>
   57 #include <vm/vnode_pager.h>
   58 #include <vm/vm_extern.h>
   59 
   60 #include <sys/sysctl.h>
   61 
   62 /*#define NTFS_DEBUG 1*/
   63 #include <fs/ntfs/ntfs.h>
   64 #include <fs/ntfs/ntfs_inode.h>
   65 #include <fs/ntfs/ntfs_subr.h>
   66 
   67 #include <sys/unistd.h> /* for pathconf(2) constants */
   68 
   69 static int      ntfs_read(struct vop_read_args *);
   70 static int      ntfs_write(struct vop_write_args *ap);
   71 static int      ntfs_getattr(struct vop_getattr_args *ap);
   72 static int      ntfs_inactive(struct vop_inactive_args *ap);
   73 static int      ntfs_reclaim(struct vop_reclaim_args *ap);
   74 static int      ntfs_bmap(struct vop_bmap_args *ap);
   75 static int      ntfs_strategy(struct vop_strategy_args *ap);
   76 static int      ntfs_access(struct vop_access_args *ap);
   77 static int      ntfs_open(struct vop_open_args *ap);
   78 static int      ntfs_close(struct vop_close_args *ap);
   79 static int      ntfs_readdir(struct vop_readdir_args *ap);
   80 static int      ntfs_lookup(struct vop_lookup_args *ap);
   81 static int      ntfs_fsync(struct vop_fsync_args *ap);
   82 static int      ntfs_pathconf(void *);
   83 
   84 int     ntfs_prtactive = 1;     /* 1 => print out reclaim of active vnodes */
   85 
   86 /*
   87  * This is a noop, simply returning what one has been given.
   88  */
   89 int
   90 ntfs_bmap(ap)
   91         struct vop_bmap_args /* {
   92                 struct vnode *a_vp;
   93                 daddr_t  a_bn;
   94                 struct vnode **a_vpp;
   95                 daddr_t *a_bnp;
   96                 int *a_runp;
   97                 int *a_runb;
   98         } */ *ap;
   99 {
  100         dprintf(("ntfs_bmap: vn: %p, blk: %d\n", ap->a_vp,(u_int32_t)ap->a_bn));
  101         if (ap->a_vpp != NULL)
  102                 *ap->a_vpp = ap->a_vp;
  103         if (ap->a_bnp != NULL)
  104                 *ap->a_bnp = ap->a_bn;
  105         if (ap->a_runp != NULL)
  106                 *ap->a_runp = 0;
  107         if (ap->a_runb != NULL)
  108                 *ap->a_runb = 0;
  109         return (0);
  110 }
  111 
  112 static int
  113 ntfs_read(ap)
  114         struct vop_read_args /* {
  115                 struct vnode *a_vp;
  116                 struct uio *a_uio;
  117                 int a_ioflag;
  118                 struct ucred *a_cred;
  119         } */ *ap;
  120 {
  121         register struct vnode *vp = ap->a_vp;
  122         register struct fnode *fp = VTOF(vp);
  123         register struct ntnode *ip = FTONT(fp);
  124         struct uio *uio = ap->a_uio;
  125         struct ntfsmount *ntmp = ip->i_mp;
  126         struct buf *bp;
  127         daddr_t cn;
  128         int resid, off, toread;
  129         int error;
  130 
  131         dprintf(("ntfs_read: ino: %d, off: %d resid: %d, segflg: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
  132 
  133         dprintf(("ntfs_read: filesize: %d",(u_int32_t)fp->f_size));
  134 
  135         /* don't allow reading after end of file */
  136         if (uio->uio_offset > fp->f_size)
  137                 return (0);
  138 
  139         resid = min(uio->uio_resid, fp->f_size - uio->uio_offset);
  140 
  141         dprintf((", resid: %d\n", resid));
  142 
  143         error = 0;
  144         while (resid) {
  145                 cn = ntfs_btocn(uio->uio_offset);
  146                 off = ntfs_btocnoff(uio->uio_offset);
  147 
  148                 toread = min(off + resid, ntfs_cntob(1));
  149 
  150                 error = bread(vp, cn, ntfs_cntob(1), NOCRED, &bp);
  151                 if (error) {
  152                         brelse(bp);
  153                         break;
  154                 }
  155 
  156                 error = uiomove(bp->b_data + off, toread - off, uio);
  157                 if(error) {
  158                         brelse(bp);
  159                         break;
  160                 }
  161                 brelse(bp);
  162 
  163                 resid -= toread - off;
  164         }
  165 
  166         return (error);
  167 }
  168 
  169 static int
  170 ntfs_getattr(ap)
  171         struct vop_getattr_args /* {
  172                 struct vnode *a_vp;
  173                 struct vattr *a_vap;
  174                 struct ucred *a_cred;
  175                 struct thread *a_td;
  176         } */ *ap;
  177 {
  178         register struct vnode *vp = ap->a_vp;
  179         register struct fnode *fp = VTOF(vp);
  180         register struct ntnode *ip = FTONT(fp);
  181         register struct vattr *vap = ap->a_vap;
  182 
  183         dprintf(("ntfs_getattr: %d, flags: %d\n",ip->i_number,ip->i_flag));
  184 
  185         vap->va_fsid = dev2udev(ip->i_dev);
  186         vap->va_fileid = ip->i_number;
  187         vap->va_mode = ip->i_mp->ntm_mode;
  188         vap->va_nlink = ip->i_nlink;
  189         vap->va_uid = ip->i_mp->ntm_uid;
  190         vap->va_gid = ip->i_mp->ntm_gid;
  191         vap->va_rdev = 0;                               /* XXX UNODEV ? */
  192         vap->va_size = fp->f_size;
  193         vap->va_bytes = fp->f_allocated;
  194         vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
  195         vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
  196         vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
  197         vap->va_flags = ip->i_flag;
  198         vap->va_gen = 0;
  199         vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
  200         vap->va_type = vp->v_type;
  201         vap->va_filerev = 0;
  202         return (0);
  203 }
  204 
  205 /*
  206  * Last reference to an ntnode.  If necessary, write or delete it.
  207  */
  208 int
  209 ntfs_inactive(ap)
  210         struct vop_inactive_args /* {
  211                 struct vnode *a_vp;
  212         } */ *ap;
  213 {
  214         register struct vnode *vp = ap->a_vp;
  215 #ifdef NTFS_DEBUG
  216         register struct ntnode *ip = VTONT(vp);
  217 #endif
  218 
  219         dprintf(("ntfs_inactive: vnode: %p, ntnode: %d\n", vp, ip->i_number));
  220 
  221         if (ntfs_prtactive && vrefcnt(vp) != 0)
  222                 vprint("ntfs_inactive: pushing active", vp);
  223 
  224         VOP_UNLOCK(vp, 0, ap->a_td);
  225 
  226         /* XXX since we don't support any filesystem changes
  227          * right now, nothing more needs to be done
  228          */
  229         return (0);
  230 }
  231 
  232 /*
  233  * Reclaim an fnode/ntnode so that it can be used for other purposes.
  234  */
  235 int
  236 ntfs_reclaim(ap)
  237         struct vop_reclaim_args /* {
  238                 struct vnode *a_vp;
  239         } */ *ap;
  240 {
  241         register struct vnode *vp = ap->a_vp;
  242         register struct fnode *fp = VTOF(vp);
  243         register struct ntnode *ip = FTONT(fp);
  244         int error;
  245 
  246         dprintf(("ntfs_reclaim: vnode: %p, ntnode: %d\n", vp, ip->i_number));
  247 
  248         if (ntfs_prtactive && vrefcnt(vp) != 0)
  249                 vprint("ntfs_reclaim: pushing active", vp);
  250 
  251         if ((error = ntfs_ntget(ip)) != 0)
  252                 return (error);
  253         
  254         /* Purge old data structures associated with the inode. */
  255         ntfs_frele(fp);
  256         ntfs_ntput(ip);
  257         vp->v_data = NULL;
  258 
  259         return (0);
  260 }
  261 
  262 /*
  263  * Calculate the logical to physical mapping if not done already,
  264  * then call the device strategy routine.
  265  */
  266 int
  267 ntfs_strategy(ap)
  268         struct vop_strategy_args /* {
  269                 struct buf *a_bp;
  270         } */ *ap;
  271 {
  272         register struct buf *bp = ap->a_bp;
  273         register struct vnode *vp = bp->b_vp;
  274         register struct fnode *fp = VTOF(vp);
  275         register struct ntnode *ip = FTONT(fp);
  276         struct ntfsmount *ntmp = ip->i_mp;
  277         int error;
  278 
  279         KASSERT(ap->a_vp == ap->a_bp->b_vp, ("%s(%p != %p)",
  280             __func__, ap->a_vp, ap->a_bp->b_vp));
  281         dprintf(("ntfs_strategy: offset: %d, blkno: %d, lblkno: %d\n",
  282                 (u_int32_t)bp->b_offset,(u_int32_t)bp->b_blkno,
  283                 (u_int32_t)bp->b_lblkno));
  284 
  285         dprintf(("strategy: bcount: %d flags: 0x%lx\n", 
  286                 (u_int32_t)bp->b_bcount,bp->b_flags));
  287 
  288         if (bp->b_iocmd == BIO_READ) {
  289                 u_int32_t toread;
  290 
  291                 if (ntfs_cntob(bp->b_blkno) >= fp->f_size) {
  292                         clrbuf(bp);
  293                         error = 0;
  294                 } else {
  295                         toread = min(bp->b_bcount,
  296                                  fp->f_size-ntfs_cntob(bp->b_blkno));
  297                         dprintf(("ntfs_strategy: toread: %d, fsize: %d\n",
  298                                 toread,(u_int32_t)fp->f_size));
  299 
  300                         error = ntfs_readattr(ntmp, ip, fp->f_attrtype,
  301                                 fp->f_attrname, ntfs_cntob(bp->b_blkno),
  302                                 toread, bp->b_data, NULL);
  303 
  304                         if (error) {
  305                                 printf("ntfs_strategy: ntfs_readattr failed\n");
  306                                 bp->b_error = error;
  307                                 bp->b_ioflags |= BIO_ERROR;
  308                         }
  309 
  310                         bzero(bp->b_data + toread, bp->b_bcount - toread);
  311                 }
  312         } else {
  313                 size_t tmp;
  314                 u_int32_t towrite;
  315 
  316                 if (ntfs_cntob(bp->b_blkno) + bp->b_bcount >= fp->f_size) {
  317                         printf("ntfs_strategy: CAN'T EXTEND FILE\n");
  318                         bp->b_error = error = EFBIG;
  319                         bp->b_ioflags |= BIO_ERROR;
  320                 } else {
  321                         towrite = min(bp->b_bcount,
  322                                 fp->f_size-ntfs_cntob(bp->b_blkno));
  323                         dprintf(("ntfs_strategy: towrite: %d, fsize: %d\n",
  324                                 towrite,(u_int32_t)fp->f_size));
  325 
  326                         error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,  
  327                                 fp->f_attrname, ntfs_cntob(bp->b_blkno),towrite,
  328                                 bp->b_data, &tmp, NULL);
  329 
  330                         if (error) {
  331                                 printf("ntfs_strategy: ntfs_writeattr fail\n");
  332                                 bp->b_error = error;
  333                                 bp->b_ioflags |= BIO_ERROR;
  334                         }
  335                 }
  336         }
  337         bufdone(bp);
  338         return (error);
  339 }
  340 
  341 static int
  342 ntfs_write(ap)
  343         struct vop_write_args /* {
  344                 struct vnode *a_vp;
  345                 struct uio *a_uio;
  346                 int  a_ioflag;
  347                 struct ucred *a_cred;
  348         } */ *ap;
  349 {
  350         register struct vnode *vp = ap->a_vp;
  351         register struct fnode *fp = VTOF(vp);
  352         register struct ntnode *ip = FTONT(fp);
  353         struct uio *uio = ap->a_uio;
  354         struct ntfsmount *ntmp = ip->i_mp;
  355         u_int64_t towrite;
  356         size_t written;
  357         int error;
  358 
  359         dprintf(("ntfs_write: ino: %d, off: %d resid: %d, segflg: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid,uio->uio_segflg));
  360         dprintf(("ntfs_write: filesize: %d",(u_int32_t)fp->f_size));
  361 
  362         if (uio->uio_resid + uio->uio_offset > fp->f_size) {
  363                 printf("ntfs_write: CAN'T WRITE BEYOND END OF FILE\n");
  364                 return (EFBIG);
  365         }
  366 
  367         towrite = min(uio->uio_resid, fp->f_size - uio->uio_offset);
  368 
  369         dprintf((", towrite: %d\n",(u_int32_t)towrite));
  370 
  371         error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
  372                 fp->f_attrname, uio->uio_offset, towrite, NULL, &written, uio);
  373 #ifdef NTFS_DEBUG
  374         if (error)
  375                 printf("ntfs_write: ntfs_writeattr failed: %d\n", error);
  376 #endif
  377 
  378         return (error);
  379 }
  380 
  381 int
  382 ntfs_access(ap)
  383         struct vop_access_args /* {
  384                 struct vnode *a_vp;
  385                 int  a_mode;
  386                 struct ucred *a_cred;
  387                 struct thread *a_td;
  388         } */ *ap;
  389 {
  390         struct vnode *vp = ap->a_vp;
  391         struct ntnode *ip = VTONT(vp);
  392         mode_t mode = ap->a_mode;
  393 #ifdef QUOTA
  394         int error;
  395 #endif
  396 
  397         dprintf(("ntfs_access: %d\n",ip->i_number));
  398 
  399         /*
  400          * Disallow write attempts on read-only filesystems;
  401          * unless the file is a socket, fifo, or a block or
  402          * character device resident on the filesystem.
  403          */
  404         if (mode & VWRITE) {
  405                 switch ((int)vp->v_type) {
  406                 case VDIR:
  407                 case VLNK:
  408                 case VREG:
  409                         if (vp->v_mount->mnt_flag & MNT_RDONLY)
  410                                 return (EROFS);
  411 #ifdef QUOTA
  412                         if (error = getinoquota(ip))
  413                                 return (error);
  414 #endif
  415                         break;
  416                 }
  417         }
  418 
  419         return (vaccess(vp->v_type, ip->i_mp->ntm_mode, ip->i_mp->ntm_uid,
  420             ip->i_mp->ntm_gid, ap->a_mode, ap->a_cred, NULL));
  421 } 
  422 
  423 /*
  424  * Open called.
  425  *
  426  * Nothing to do.
  427  */
  428 /* ARGSUSED */
  429 static int
  430 ntfs_open(ap)
  431         struct vop_open_args /* {
  432                 struct vnode *a_vp;
  433                 int  a_mode;
  434                 struct ucred *a_cred;
  435                 struct thread *a_td;
  436         } */ *ap;
  437 {
  438 #if NTFS_DEBUG
  439         register struct vnode *vp = ap->a_vp;
  440         register struct ntnode *ip = VTONT(vp);
  441 
  442         printf("ntfs_open: %d\n",ip->i_number);
  443 #endif
  444 
  445         /*
  446          * Files marked append-only must be opened for appending.
  447          */
  448 
  449         return (0);
  450 }
  451 
  452 /*
  453  * Close called.
  454  *
  455  * Update the times on the inode.
  456  */
  457 /* ARGSUSED */
  458 static int
  459 ntfs_close(ap)
  460         struct vop_close_args /* {
  461                 struct vnode *a_vp;
  462                 int  a_fflag;
  463                 struct ucred *a_cred;
  464                 struct thread *a_td;
  465         } */ *ap;
  466 {
  467 #if NTFS_DEBUG
  468         register struct vnode *vp = ap->a_vp;
  469         register struct ntnode *ip = VTONT(vp);
  470 
  471         printf("ntfs_close: %d\n",ip->i_number);
  472 #endif
  473 
  474         return (0);
  475 }
  476 
  477 int
  478 ntfs_readdir(ap)
  479         struct vop_readdir_args /* {
  480                 struct vnode *a_vp;
  481                 struct uio *a_uio;
  482                 struct ucred *a_cred;
  483                 int *a_ncookies;
  484                 u_int **cookies;
  485         } */ *ap;
  486 {
  487         register struct vnode *vp = ap->a_vp;
  488         register struct fnode *fp = VTOF(vp);
  489         register struct ntnode *ip = FTONT(fp);
  490         struct uio *uio = ap->a_uio;
  491         struct ntfsmount *ntmp = ip->i_mp;
  492         int i, j, error = 0;
  493         wchar c;
  494         u_int32_t faked = 0, num;
  495         int ncookies = 0;
  496         struct dirent cde;
  497         off_t off;
  498 
  499         dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
  500 
  501         off = uio->uio_offset;
  502 
  503         /* Simulate . in every dir except ROOT */
  504         if( ip->i_number != NTFS_ROOTINO ) {
  505                 struct dirent dot = { NTFS_ROOTINO,
  506                                 sizeof(struct dirent), DT_DIR, 1, "." };
  507 
  508                 if( uio->uio_offset < sizeof(struct dirent) ) {
  509                         dot.d_fileno = ip->i_number;
  510                         error = uiomove((char *)&dot,sizeof(struct dirent),uio);
  511                         if(error)
  512                                 return (error);
  513 
  514                         ncookies ++;
  515                 }
  516         }
  517 
  518         /* Simulate .. in every dir including ROOT */
  519         if( uio->uio_offset < 2 * sizeof(struct dirent) ) {
  520                 struct dirent dotdot = { NTFS_ROOTINO,
  521                                 sizeof(struct dirent), DT_DIR, 2, ".." };
  522 
  523                 error = uiomove((char *)&dotdot,sizeof(struct dirent),uio);
  524                 if(error)
  525                         return (error);
  526 
  527                 ncookies ++;
  528         }
  529 
  530         faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
  531         num = uio->uio_offset / sizeof(struct dirent) - faked;
  532 
  533         while( uio->uio_resid >= sizeof(struct dirent) ) {
  534                 struct attr_indexentry *iep;
  535 
  536                 error = ntfs_ntreaddir(ntmp, fp, num, &iep);
  537 
  538                 if(error)
  539                         return (error);
  540 
  541                 if( NULL == iep )
  542                         break;
  543 
  544                 for(; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (uio->uio_resid >= sizeof(struct dirent));
  545                         iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
  546                 {
  547                         if(!ntfs_isnamepermitted(ntmp,iep))
  548                                 continue;
  549 
  550                         for(i=0, j=0; i<iep->ie_fnamelen; i++, j++) {
  551                                 c = NTFS_U28(iep->ie_fname[i]);
  552                                 if (c&0xFF00)
  553                                         cde.d_name[j++] = (char)(c>>8);
  554                                 cde.d_name[j] = (char)c&0xFF;
  555                         }
  556                         cde.d_name[j] = '\0';
  557                         dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
  558                                 num, cde.d_name, iep->ie_fnametype,
  559                                 iep->ie_flag));
  560                         cde.d_namlen = j;
  561                         cde.d_fileno = iep->ie_number;
  562                         cde.d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
  563                         cde.d_reclen = sizeof(struct dirent);
  564                         dprintf(("%s\n", (cde.d_type == DT_DIR) ? "dir":"reg"));
  565 
  566                         error = uiomove((char *)&cde, sizeof(struct dirent), uio);
  567                         if(error)
  568                                 return (error);
  569 
  570                         ncookies++;
  571                         num++;
  572                 }
  573         }
  574 
  575         dprintf(("ntfs_readdir: %d entries (%d bytes) read\n",
  576                 ncookies,(u_int)(uio->uio_offset - off)));
  577         dprintf(("ntfs_readdir: off: %d resid: %d\n",
  578                 (u_int32_t)uio->uio_offset,uio->uio_resid));
  579 
  580         if (!error && ap->a_ncookies != NULL) {
  581                 struct dirent* dpStart;
  582                 struct dirent* dp;
  583                 u_long *cookies;
  584                 u_long *cookiep;
  585 
  586                 ddprintf(("ntfs_readdir: %d cookies\n",ncookies));
  587                 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
  588                         panic("ntfs_readdir: unexpected uio from NFS server");
  589                 dpStart = (struct dirent *)
  590                      ((caddr_t)uio->uio_iov->iov_base -
  591                          (uio->uio_offset - off));
  592                 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
  593                        M_TEMP, M_WAITOK);
  594                 for (dp = dpStart, cookiep = cookies, i=0;
  595                      i < ncookies;
  596                      dp = (struct dirent *)((caddr_t) dp + dp->d_reclen), i++) {
  597                         off += dp->d_reclen;
  598                         *cookiep++ = (u_int) off;
  599                 }
  600                 *ap->a_ncookies = ncookies;
  601                 *ap->a_cookies = cookies;
  602         }
  603 /*
  604         if (ap->a_eofflag)
  605             *ap->a_eofflag = VTONT(ap->a_vp)->i_size <= uio->uio_offset;
  606 */
  607         return (error);
  608 }
  609 
  610 int
  611 ntfs_lookup(ap)
  612         struct vop_lookup_args /* {
  613                 struct vnode *a_dvp;
  614                 struct vnode **a_vpp;
  615                 struct componentname *a_cnp;
  616         } */ *ap;
  617 {
  618         register struct vnode *dvp = ap->a_dvp;
  619         register struct ntnode *dip = VTONT(dvp);
  620         struct ntfsmount *ntmp = dip->i_mp;
  621         struct componentname *cnp = ap->a_cnp;
  622         struct ucred *cred = cnp->cn_cred;
  623         int error;
  624         int lockparent = cnp->cn_flags & LOCKPARENT;
  625 #if NTFS_DEBUG
  626         int wantparent = cnp->cn_flags & (LOCKPARENT|WANTPARENT);
  627 #endif
  628         dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d, lp: %d, wp: %d \n",
  629                 (int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen,
  630                 dip->i_number, lockparent, wantparent));
  631 
  632         error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_thread);
  633         if(error)
  634                 return (error);
  635 
  636         if ((cnp->cn_flags & ISLASTCN) &&
  637             (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
  638             (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
  639                 return (EROFS);
  640 
  641         if(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
  642                 dprintf(("ntfs_lookup: faking . directory in %d\n",
  643                         dip->i_number));
  644 
  645                 VREF(dvp);
  646                 *ap->a_vpp = dvp;
  647                 error = 0;
  648         } else if (cnp->cn_flags & ISDOTDOT) {
  649                 struct ntvattr *vap;
  650 
  651                 dprintf(("ntfs_lookup: faking .. directory in %d\n",
  652                          dip->i_number));
  653 
  654                 error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
  655                 if(error)
  656                         return (error);
  657 
  658                 VOP_UNLOCK(dvp,0,cnp->cn_thread);
  659                 cnp->cn_flags |= PDIRUNLOCK;
  660 
  661                 dprintf(("ntfs_lookup: parentdir: %d\n",
  662                          vap->va_a_name->n_pnumber));
  663                 error = VFS_VGET(ntmp->ntm_mountp, vap->va_a_name->n_pnumber,
  664                                  LK_EXCLUSIVE, ap->a_vpp); 
  665                 ntfs_ntvattrrele(vap);
  666                 if (error) {
  667                         if (vn_lock(dvp,LK_EXCLUSIVE|LK_RETRY,cnp->cn_thread)==0)
  668                                 cnp->cn_flags &= ~PDIRUNLOCK;
  669                         return (error);
  670                 }
  671 
  672                 if (lockparent && (cnp->cn_flags & ISLASTCN)) {
  673                         error = vn_lock(dvp, LK_EXCLUSIVE, cnp->cn_thread);
  674                         if (error) {
  675                                 vput( *(ap->a_vpp) );
  676                                 return (error);
  677                         }
  678                         cnp->cn_flags &= ~PDIRUNLOCK;
  679                 }
  680         } else {
  681                 error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp);
  682                 if (error) {
  683                         dprintf(("ntfs_ntlookupfile: returned %d\n", error));
  684                         return (error);
  685                 }
  686 
  687                 dprintf(("ntfs_lookup: found ino: %d\n", 
  688                         VTONT(*ap->a_vpp)->i_number));
  689 
  690                 if(!lockparent || !(cnp->cn_flags & ISLASTCN))
  691                         VOP_UNLOCK(dvp, 0, cnp->cn_thread);
  692         }
  693 
  694         if (cnp->cn_flags & MAKEENTRY)
  695                 cache_enter(dvp, *ap->a_vpp, cnp);
  696 
  697         return (error);
  698 }
  699 
  700 /*
  701  * Flush the blocks of a file to disk.
  702  *
  703  * This function is worthless for vnodes that represent directories. Maybe we
  704  * could just do a sync if they try an fsync on a directory file.
  705  */
  706 static int
  707 ntfs_fsync(ap)
  708         struct vop_fsync_args /* {
  709                 struct vnode *a_vp;
  710                 struct ucred *a_cred;
  711                 int a_waitfor;
  712                 struct thread *a_td;
  713         } */ *ap;
  714 {
  715         return (0);
  716 }
  717 
  718 /*
  719  * Return POSIX pathconf information applicable to NTFS filesystem
  720  */
  721 int
  722 ntfs_pathconf(v)
  723         void *v;
  724 {
  725         struct vop_pathconf_args /* {
  726                 struct vnode *a_vp;
  727                 int a_name;
  728                 register_t *a_retval;
  729         } */ *ap = v;
  730 
  731         switch (ap->a_name) {
  732         case _PC_LINK_MAX:
  733                 *ap->a_retval = 1;
  734                 return (0);
  735         case _PC_NAME_MAX:
  736                 *ap->a_retval = NTFS_MAXFILENAME;
  737                 return (0);
  738         case _PC_PATH_MAX:
  739                 *ap->a_retval = PATH_MAX;
  740                 return (0);
  741         case _PC_CHOWN_RESTRICTED:
  742                 *ap->a_retval = 1;
  743                 return (0);
  744         case _PC_NO_TRUNC:
  745                 *ap->a_retval = 0;
  746                 return (0);
  747         default:
  748                 return (EINVAL);
  749         }
  750         /* NOTREACHED */
  751 }
  752 
  753 /*
  754  * Global vfs data structures
  755  */
  756 vop_t **ntfs_vnodeop_p;
  757 static
  758 struct vnodeopv_entry_desc ntfs_vnodeop_entries[] = {
  759         { &vop_default_desc, (vop_t *)vop_defaultop },
  760 
  761         { &vop_getattr_desc, (vop_t *)ntfs_getattr },
  762         { &vop_inactive_desc, (vop_t *)ntfs_inactive },
  763         { &vop_reclaim_desc, (vop_t *)ntfs_reclaim },
  764         { &vop_pathconf_desc, ntfs_pathconf },
  765 
  766         { &vop_cachedlookup_desc, (vop_t *)ntfs_lookup },
  767         { &vop_lookup_desc, (vop_t *)vfs_cache_lookup },
  768 
  769         { &vop_access_desc, (vop_t *)ntfs_access },
  770         { &vop_close_desc, (vop_t *)ntfs_close },
  771         { &vop_open_desc, (vop_t *)ntfs_open },
  772         { &vop_readdir_desc, (vop_t *)ntfs_readdir },
  773         { &vop_fsync_desc, (vop_t *)ntfs_fsync },
  774 
  775         { &vop_bmap_desc, (vop_t *)ntfs_bmap },
  776         { &vop_strategy_desc, (vop_t *)ntfs_strategy },
  777         { &vop_read_desc, (vop_t *)ntfs_read },
  778         { &vop_write_desc, (vop_t *)ntfs_write },
  779 
  780         { NULL, NULL }
  781 };
  782 
  783 static
  784 struct vnodeopv_desc ntfs_vnodeop_opv_desc =
  785         { &ntfs_vnodeop_p, ntfs_vnodeop_entries };
  786 
  787 VNODEOP_SET(ntfs_vnodeop_opv_desc);

Cache object: f30f78ae9a6fde2665e4aa1597438f65


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