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  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *      This product includes software developed by the University of
   21  *      California, Berkeley and its contributors.
   22  * 4. Neither the name of the University nor the names of its contributors
   23  *    may be used to endorse or promote products derived from this software
   24  *    without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   36  * SUCH DAMAGE.
   37  *
   38  * $FreeBSD: releng/5.1/sys/fs/ntfs/ntfs_vnops.c 111841 2003-03-03 19:15:40Z njl $
   39  *
   40  */
   41 
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/kernel.h>
   45 #include <sys/time.h>
   46 #include <sys/types.h>
   47 #include <sys/stat.h>
   48 #include <sys/vnode.h>
   49 #include <sys/mount.h>
   50 #include <sys/namei.h>
   51 #include <sys/malloc.h>
   52 #include <sys/bio.h>
   53 #include <sys/buf.h>
   54 #include <sys/dirent.h>
   55 
   56 #include <vm/vm.h>
   57 #include <vm/vm_param.h>
   58 #include <vm/vm_page.h>
   59 #include <vm/vm_object.h>
   60 #include <vm/vm_pager.h>
   61 #include <vm/vnode_pager.h>
   62 #include <vm/vm_extern.h>
   63 
   64 #include <sys/sysctl.h>
   65 
   66 /*#define NTFS_DEBUG 1*/
   67 #include <fs/ntfs/ntfs.h>
   68 #include <fs/ntfs/ntfs_inode.h>
   69 #include <fs/ntfs/ntfs_subr.h>
   70 
   71 #include <sys/unistd.h> /* for pathconf(2) constants */
   72 
   73 static int      ntfs_read(struct vop_read_args *);
   74 static int      ntfs_write(struct vop_write_args *ap);
   75 static int      ntfs_getattr(struct vop_getattr_args *ap);
   76 static int      ntfs_inactive(struct vop_inactive_args *ap);
   77 static int      ntfs_reclaim(struct vop_reclaim_args *ap);
   78 static int      ntfs_bmap(struct vop_bmap_args *ap);
   79 static int      ntfs_strategy(struct vop_strategy_args *ap);
   80 static int      ntfs_access(struct vop_access_args *ap);
   81 static int      ntfs_open(struct vop_open_args *ap);
   82 static int      ntfs_close(struct vop_close_args *ap);
   83 static int      ntfs_readdir(struct vop_readdir_args *ap);
   84 static int      ntfs_lookup(struct vop_lookup_args *ap);
   85 static int      ntfs_fsync(struct vop_fsync_args *ap);
   86 static int      ntfs_pathconf(void *);
   87 
   88 int     ntfs_prtactive = 1;     /* 1 => print out reclaim of active vnodes */
   89 
   90 /*
   91  * This is a noop, simply returning what one has been given.
   92  */
   93 int
   94 ntfs_bmap(ap)
   95         struct vop_bmap_args /* {
   96                 struct vnode *a_vp;
   97                 daddr_t  a_bn;
   98                 struct vnode **a_vpp;
   99                 daddr_t *a_bnp;
  100                 int *a_runp;
  101                 int *a_runb;
  102         } */ *ap;
  103 {
  104         dprintf(("ntfs_bmap: vn: %p, blk: %d\n", ap->a_vp,(u_int32_t)ap->a_bn));
  105         if (ap->a_vpp != NULL)
  106                 *ap->a_vpp = ap->a_vp;
  107         if (ap->a_bnp != NULL)
  108                 *ap->a_bnp = ap->a_bn;
  109         if (ap->a_runp != NULL)
  110                 *ap->a_runp = 0;
  111         if (ap->a_runb != NULL)
  112                 *ap->a_runb = 0;
  113         return (0);
  114 }
  115 
  116 static int
  117 ntfs_read(ap)
  118         struct vop_read_args /* {
  119                 struct vnode *a_vp;
  120                 struct uio *a_uio;
  121                 int a_ioflag;
  122                 struct ucred *a_cred;
  123         } */ *ap;
  124 {
  125         register struct vnode *vp = ap->a_vp;
  126         register struct fnode *fp = VTOF(vp);
  127         register struct ntnode *ip = FTONT(fp);
  128         struct uio *uio = ap->a_uio;
  129         struct ntfsmount *ntmp = ip->i_mp;
  130         struct buf *bp;
  131         daddr_t cn;
  132         int resid, off, toread;
  133         int error;
  134 
  135         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));
  136 
  137         dprintf(("ntfs_read: filesize: %d",(u_int32_t)fp->f_size));
  138 
  139         /* don't allow reading after end of file */
  140         if (uio->uio_offset > fp->f_size)
  141                 return (0);
  142 
  143         resid = min(uio->uio_resid, fp->f_size - uio->uio_offset);
  144 
  145         dprintf((", resid: %d\n", resid));
  146 
  147         error = 0;
  148         while (resid) {
  149                 cn = ntfs_btocn(uio->uio_offset);
  150                 off = ntfs_btocnoff(uio->uio_offset);
  151 
  152                 toread = min(off + resid, ntfs_cntob(1));
  153 
  154                 error = bread(vp, cn, ntfs_cntob(1), NOCRED, &bp);
  155                 if (error) {
  156                         brelse(bp);
  157                         break;
  158                 }
  159 
  160                 error = uiomove(bp->b_data + off, toread - off, uio);
  161                 if(error) {
  162                         brelse(bp);
  163                         break;
  164                 }
  165                 brelse(bp);
  166 
  167                 resid -= toread - off;
  168         }
  169 
  170         return (error);
  171 }
  172 
  173 static int
  174 ntfs_getattr(ap)
  175         struct vop_getattr_args /* {
  176                 struct vnode *a_vp;
  177                 struct vattr *a_vap;
  178                 struct ucred *a_cred;
  179                 struct thread *a_td;
  180         } */ *ap;
  181 {
  182         register struct vnode *vp = ap->a_vp;
  183         register struct fnode *fp = VTOF(vp);
  184         register struct ntnode *ip = FTONT(fp);
  185         register struct vattr *vap = ap->a_vap;
  186 
  187         dprintf(("ntfs_getattr: %d, flags: %d\n",ip->i_number,ip->i_flag));
  188 
  189         vap->va_fsid = dev2udev(ip->i_dev);
  190         vap->va_fileid = ip->i_number;
  191         vap->va_mode = ip->i_mp->ntm_mode;
  192         vap->va_nlink = ip->i_nlink;
  193         vap->va_uid = ip->i_mp->ntm_uid;
  194         vap->va_gid = ip->i_mp->ntm_gid;
  195         vap->va_rdev = 0;                               /* XXX UNODEV ? */
  196         vap->va_size = fp->f_size;
  197         vap->va_bytes = fp->f_allocated;
  198         vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
  199         vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
  200         vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
  201         vap->va_flags = ip->i_flag;
  202         vap->va_gen = 0;
  203         vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
  204         vap->va_type = vp->v_type;
  205         vap->va_filerev = 0;
  206         return (0);
  207 }
  208 
  209 /*
  210  * Last reference to an ntnode.  If necessary, write or delete it.
  211  */
  212 int
  213 ntfs_inactive(ap)
  214         struct vop_inactive_args /* {
  215                 struct vnode *a_vp;
  216         } */ *ap;
  217 {
  218         register struct vnode *vp = ap->a_vp;
  219 #ifdef NTFS_DEBUG
  220         register struct ntnode *ip = VTONT(vp);
  221 #endif
  222 
  223         dprintf(("ntfs_inactive: vnode: %p, ntnode: %d\n", vp, ip->i_number));
  224 
  225         if (ntfs_prtactive && vrefcnt(vp) != 0)
  226                 vprint("ntfs_inactive: pushing active", vp);
  227 
  228         VOP_UNLOCK(vp, 0, ap->a_td);
  229 
  230         /* XXX since we don't support any filesystem changes
  231          * right now, nothing more needs to be done
  232          */
  233         return (0);
  234 }
  235 
  236 /*
  237  * Reclaim an fnode/ntnode so that it can be used for other purposes.
  238  */
  239 int
  240 ntfs_reclaim(ap)
  241         struct vop_reclaim_args /* {
  242                 struct vnode *a_vp;
  243         } */ *ap;
  244 {
  245         register struct vnode *vp = ap->a_vp;
  246         register struct fnode *fp = VTOF(vp);
  247         register struct ntnode *ip = FTONT(fp);
  248         int error;
  249 
  250         dprintf(("ntfs_reclaim: vnode: %p, ntnode: %d\n", vp, ip->i_number));
  251 
  252         if (ntfs_prtactive && vrefcnt(vp) != 0)
  253                 vprint("ntfs_reclaim: pushing active", vp);
  254 
  255         if ((error = ntfs_ntget(ip)) != 0)
  256                 return (error);
  257         
  258         /* Purge old data structures associated with the inode. */
  259         cache_purge(vp);
  260 
  261         ntfs_frele(fp);
  262         ntfs_ntput(ip);
  263         vp->v_data = NULL;
  264 
  265         return (0);
  266 }
  267 
  268 /*
  269  * Calculate the logical to physical mapping if not done already,
  270  * then call the device strategy routine.
  271  */
  272 int
  273 ntfs_strategy(ap)
  274         struct vop_strategy_args /* {
  275                 struct buf *a_bp;
  276         } */ *ap;
  277 {
  278         register struct buf *bp = ap->a_bp;
  279         register struct vnode *vp = bp->b_vp;
  280         register struct fnode *fp = VTOF(vp);
  281         register struct ntnode *ip = FTONT(fp);
  282         struct ntfsmount *ntmp = ip->i_mp;
  283         int error;
  284 
  285         dprintf(("ntfs_strategy: offset: %d, blkno: %d, lblkno: %d\n",
  286                 (u_int32_t)bp->b_offset,(u_int32_t)bp->b_blkno,
  287                 (u_int32_t)bp->b_lblkno));
  288 
  289         dprintf(("strategy: bcount: %d flags: 0x%lx\n", 
  290                 (u_int32_t)bp->b_bcount,bp->b_flags));
  291 
  292         if (bp->b_iocmd == BIO_READ) {
  293                 u_int32_t toread;
  294 
  295                 if (ntfs_cntob(bp->b_blkno) >= fp->f_size) {
  296                         clrbuf(bp);
  297                         error = 0;
  298                 } else {
  299                         toread = min(bp->b_bcount,
  300                                  fp->f_size-ntfs_cntob(bp->b_blkno));
  301                         dprintf(("ntfs_strategy: toread: %d, fsize: %d\n",
  302                                 toread,(u_int32_t)fp->f_size));
  303 
  304                         error = ntfs_readattr(ntmp, ip, fp->f_attrtype,
  305                                 fp->f_attrname, ntfs_cntob(bp->b_blkno),
  306                                 toread, bp->b_data, NULL);
  307 
  308                         if (error) {
  309                                 printf("ntfs_strategy: ntfs_readattr failed\n");
  310                                 bp->b_error = error;
  311                                 bp->b_ioflags |= BIO_ERROR;
  312                         }
  313 
  314                         bzero(bp->b_data + toread, bp->b_bcount - toread);
  315                 }
  316         } else {
  317                 size_t tmp;
  318                 u_int32_t towrite;
  319 
  320                 if (ntfs_cntob(bp->b_blkno) + bp->b_bcount >= fp->f_size) {
  321                         printf("ntfs_strategy: CAN'T EXTEND FILE\n");
  322                         bp->b_error = error = EFBIG;
  323                         bp->b_ioflags |= BIO_ERROR;
  324                 } else {
  325                         towrite = min(bp->b_bcount,
  326                                 fp->f_size-ntfs_cntob(bp->b_blkno));
  327                         dprintf(("ntfs_strategy: towrite: %d, fsize: %d\n",
  328                                 towrite,(u_int32_t)fp->f_size));
  329 
  330                         error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,  
  331                                 fp->f_attrname, ntfs_cntob(bp->b_blkno),towrite,
  332                                 bp->b_data, &tmp, NULL);
  333 
  334                         if (error) {
  335                                 printf("ntfs_strategy: ntfs_writeattr fail\n");
  336                                 bp->b_error = error;
  337                                 bp->b_ioflags |= BIO_ERROR;
  338                         }
  339                 }
  340         }
  341         bufdone(bp);
  342         return (error);
  343 }
  344 
  345 static int
  346 ntfs_write(ap)
  347         struct vop_write_args /* {
  348                 struct vnode *a_vp;
  349                 struct uio *a_uio;
  350                 int  a_ioflag;
  351                 struct ucred *a_cred;
  352         } */ *ap;
  353 {
  354         register struct vnode *vp = ap->a_vp;
  355         register struct fnode *fp = VTOF(vp);
  356         register struct ntnode *ip = FTONT(fp);
  357         struct uio *uio = ap->a_uio;
  358         struct ntfsmount *ntmp = ip->i_mp;
  359         u_int64_t towrite;
  360         size_t written;
  361         int error;
  362 
  363         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));
  364         dprintf(("ntfs_write: filesize: %d",(u_int32_t)fp->f_size));
  365 
  366         if (uio->uio_resid + uio->uio_offset > fp->f_size) {
  367                 printf("ntfs_write: CAN'T WRITE BEYOND END OF FILE\n");
  368                 return (EFBIG);
  369         }
  370 
  371         towrite = min(uio->uio_resid, fp->f_size - uio->uio_offset);
  372 
  373         dprintf((", towrite: %d\n",(u_int32_t)towrite));
  374 
  375         error = ntfs_writeattr_plain(ntmp, ip, fp->f_attrtype,
  376                 fp->f_attrname, uio->uio_offset, towrite, NULL, &written, uio);
  377 #ifdef NTFS_DEBUG
  378         if (error)
  379                 printf("ntfs_write: ntfs_writeattr failed: %d\n", error);
  380 #endif
  381 
  382         return (error);
  383 }
  384 
  385 int
  386 ntfs_access(ap)
  387         struct vop_access_args /* {
  388                 struct vnode *a_vp;
  389                 int  a_mode;
  390                 struct ucred *a_cred;
  391                 struct thread *a_td;
  392         } */ *ap;
  393 {
  394         struct vnode *vp = ap->a_vp;
  395         struct ntnode *ip = VTONT(vp);
  396         mode_t mode = ap->a_mode;
  397 #ifdef QUOTA
  398         int error;
  399 #endif
  400 
  401         dprintf(("ntfs_access: %d\n",ip->i_number));
  402 
  403         /*
  404          * Disallow write attempts on read-only filesystems;
  405          * unless the file is a socket, fifo, or a block or
  406          * character device resident on the filesystem.
  407          */
  408         if (mode & VWRITE) {
  409                 switch ((int)vp->v_type) {
  410                 case VDIR:
  411                 case VLNK:
  412                 case VREG:
  413                         if (vp->v_mount->mnt_flag & MNT_RDONLY)
  414                                 return (EROFS);
  415 #ifdef QUOTA
  416                         if (error = getinoquota(ip))
  417                                 return (error);
  418 #endif
  419                         break;
  420                 }
  421         }
  422 
  423         return (vaccess(vp->v_type, ip->i_mp->ntm_mode, ip->i_mp->ntm_uid,
  424             ip->i_mp->ntm_gid, ap->a_mode, ap->a_cred, NULL));
  425 } 
  426 
  427 /*
  428  * Open called.
  429  *
  430  * Nothing to do.
  431  */
  432 /* ARGSUSED */
  433 static int
  434 ntfs_open(ap)
  435         struct vop_open_args /* {
  436                 struct vnode *a_vp;
  437                 int  a_mode;
  438                 struct ucred *a_cred;
  439                 struct thread *a_td;
  440         } */ *ap;
  441 {
  442 #if NTFS_DEBUG
  443         register struct vnode *vp = ap->a_vp;
  444         register struct ntnode *ip = VTONT(vp);
  445 
  446         printf("ntfs_open: %d\n",ip->i_number);
  447 #endif
  448 
  449         /*
  450          * Files marked append-only must be opened for appending.
  451          */
  452 
  453         return (0);
  454 }
  455 
  456 /*
  457  * Close called.
  458  *
  459  * Update the times on the inode.
  460  */
  461 /* ARGSUSED */
  462 static int
  463 ntfs_close(ap)
  464         struct vop_close_args /* {
  465                 struct vnode *a_vp;
  466                 int  a_fflag;
  467                 struct ucred *a_cred;
  468                 struct thread *a_td;
  469         } */ *ap;
  470 {
  471 #if NTFS_DEBUG
  472         register struct vnode *vp = ap->a_vp;
  473         register struct ntnode *ip = VTONT(vp);
  474 
  475         printf("ntfs_close: %d\n",ip->i_number);
  476 #endif
  477 
  478         return (0);
  479 }
  480 
  481 int
  482 ntfs_readdir(ap)
  483         struct vop_readdir_args /* {
  484                 struct vnode *a_vp;
  485                 struct uio *a_uio;
  486                 struct ucred *a_cred;
  487                 int *a_ncookies;
  488                 u_int **cookies;
  489         } */ *ap;
  490 {
  491         register struct vnode *vp = ap->a_vp;
  492         register struct fnode *fp = VTOF(vp);
  493         register struct ntnode *ip = FTONT(fp);
  494         struct uio *uio = ap->a_uio;
  495         struct ntfsmount *ntmp = ip->i_mp;
  496         int i, error = 0;
  497         u_int32_t faked = 0, num;
  498         int ncookies = 0;
  499         struct dirent cde;
  500         off_t off;
  501 
  502         dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
  503 
  504         off = uio->uio_offset;
  505 
  506         /* Simulate . in every dir except ROOT */
  507         if( ip->i_number != NTFS_ROOTINO ) {
  508                 struct dirent dot = { NTFS_ROOTINO,
  509                                 sizeof(struct dirent), DT_DIR, 1, "." };
  510 
  511                 if( uio->uio_offset < sizeof(struct dirent) ) {
  512                         dot.d_fileno = ip->i_number;
  513                         error = uiomove((char *)&dot,sizeof(struct dirent),uio);
  514                         if(error)
  515                                 return (error);
  516 
  517                         ncookies ++;
  518                 }
  519         }
  520 
  521         /* Simulate .. in every dir including ROOT */
  522         if( uio->uio_offset < 2 * sizeof(struct dirent) ) {
  523                 struct dirent dotdot = { NTFS_ROOTINO,
  524                                 sizeof(struct dirent), DT_DIR, 2, ".." };
  525 
  526                 error = uiomove((char *)&dotdot,sizeof(struct dirent),uio);
  527                 if(error)
  528                         return (error);
  529 
  530                 ncookies ++;
  531         }
  532 
  533         faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
  534         num = uio->uio_offset / sizeof(struct dirent) - faked;
  535 
  536         while( uio->uio_resid >= sizeof(struct dirent) ) {
  537                 struct attr_indexentry *iep;
  538 
  539                 error = ntfs_ntreaddir(ntmp, fp, num, &iep);
  540 
  541                 if(error)
  542                         return (error);
  543 
  544                 if( NULL == iep )
  545                         break;
  546 
  547                 for(; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (uio->uio_resid >= sizeof(struct dirent));
  548                         iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
  549                 {
  550                         if(!ntfs_isnamepermitted(ntmp,iep))
  551                                 continue;
  552 
  553                         for(i=0; i<iep->ie_fnamelen; i++) {
  554                                 cde.d_name[i] = NTFS_U28(iep->ie_fname[i]);
  555                         }
  556                         cde.d_name[i] = '\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 = iep->ie_fnamelen;
  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: 50c05822f80a56859f11bcdb50002f4a


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