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-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
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.2/sys/fs/ntfs/ntfs_vnops.c 120775 2003-10-05 02:43:30Z jeff $
   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         ntfs_frele(fp);
  260         ntfs_ntput(ip);
  261         vp->v_data = NULL;
  262 
  263         return (0);
  264 }
  265 
  266 /*
  267  * Calculate the logical to physical mapping if not done already,
  268  * then call the device strategy routine.
  269  */
  270 int
  271 ntfs_strategy(ap)
  272         struct vop_strategy_args /* {
  273                 struct buf *a_bp;
  274         } */ *ap;
  275 {
  276         register struct buf *bp = ap->a_bp;
  277         register struct vnode *vp = bp->b_vp;
  278         register struct fnode *fp = VTOF(vp);
  279         register struct ntnode *ip = FTONT(fp);
  280         struct ntfsmount *ntmp = ip->i_mp;
  281         int error;
  282 
  283         KASSERT(ap->a_vp == ap->a_bp->b_vp, ("%s(%p != %p)",
  284             __func__, ap->a_vp, ap->a_bp->b_vp));
  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, j, error = 0;
  497         wchar c;
  498         u_int32_t faked = 0, num;
  499         int ncookies = 0;
  500         struct dirent cde;
  501         off_t off;
  502 
  503         dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
  504 
  505         off = uio->uio_offset;
  506 
  507         /* Simulate . in every dir except ROOT */
  508         if( ip->i_number != NTFS_ROOTINO ) {
  509                 struct dirent dot = { NTFS_ROOTINO,
  510                                 sizeof(struct dirent), DT_DIR, 1, "." };
  511 
  512                 if( uio->uio_offset < sizeof(struct dirent) ) {
  513                         dot.d_fileno = ip->i_number;
  514                         error = uiomove((char *)&dot,sizeof(struct dirent),uio);
  515                         if(error)
  516                                 return (error);
  517 
  518                         ncookies ++;
  519                 }
  520         }
  521 
  522         /* Simulate .. in every dir including ROOT */
  523         if( uio->uio_offset < 2 * sizeof(struct dirent) ) {
  524                 struct dirent dotdot = { NTFS_ROOTINO,
  525                                 sizeof(struct dirent), DT_DIR, 2, ".." };
  526 
  527                 error = uiomove((char *)&dotdot,sizeof(struct dirent),uio);
  528                 if(error)
  529                         return (error);
  530 
  531                 ncookies ++;
  532         }
  533 
  534         faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
  535         num = uio->uio_offset / sizeof(struct dirent) - faked;
  536 
  537         while( uio->uio_resid >= sizeof(struct dirent) ) {
  538                 struct attr_indexentry *iep;
  539 
  540                 error = ntfs_ntreaddir(ntmp, fp, num, &iep);
  541 
  542                 if(error)
  543                         return (error);
  544 
  545                 if( NULL == iep )
  546                         break;
  547 
  548                 for(; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (uio->uio_resid >= sizeof(struct dirent));
  549                         iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
  550                 {
  551                         if(!ntfs_isnamepermitted(ntmp,iep))
  552                                 continue;
  553 
  554                         for(i=0, j=0; i<iep->ie_fnamelen; i++, j++) {
  555                                 c = NTFS_U28(iep->ie_fname[i]);
  556                                 if (c&0xFF00)
  557                                         cde.d_name[j++] = (char)(c>>8);
  558                                 cde.d_name[j] = (char)c&0xFF;
  559                         }
  560                         cde.d_name[j] = '\0';
  561                         dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
  562                                 num, cde.d_name, iep->ie_fnametype,
  563                                 iep->ie_flag));
  564                         cde.d_namlen = j;
  565                         cde.d_fileno = iep->ie_number;
  566                         cde.d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
  567                         cde.d_reclen = sizeof(struct dirent);
  568                         dprintf(("%s\n", (cde.d_type == DT_DIR) ? "dir":"reg"));
  569 
  570                         error = uiomove((char *)&cde, sizeof(struct dirent), uio);
  571                         if(error)
  572                                 return (error);
  573 
  574                         ncookies++;
  575                         num++;
  576                 }
  577         }
  578 
  579         dprintf(("ntfs_readdir: %d entries (%d bytes) read\n",
  580                 ncookies,(u_int)(uio->uio_offset - off)));
  581         dprintf(("ntfs_readdir: off: %d resid: %d\n",
  582                 (u_int32_t)uio->uio_offset,uio->uio_resid));
  583 
  584         if (!error && ap->a_ncookies != NULL) {
  585                 struct dirent* dpStart;
  586                 struct dirent* dp;
  587                 u_long *cookies;
  588                 u_long *cookiep;
  589 
  590                 ddprintf(("ntfs_readdir: %d cookies\n",ncookies));
  591                 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
  592                         panic("ntfs_readdir: unexpected uio from NFS server");
  593                 dpStart = (struct dirent *)
  594                      ((caddr_t)uio->uio_iov->iov_base -
  595                          (uio->uio_offset - off));
  596                 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
  597                        M_TEMP, M_WAITOK);
  598                 for (dp = dpStart, cookiep = cookies, i=0;
  599                      i < ncookies;
  600                      dp = (struct dirent *)((caddr_t) dp + dp->d_reclen), i++) {
  601                         off += dp->d_reclen;
  602                         *cookiep++ = (u_int) off;
  603                 }
  604                 *ap->a_ncookies = ncookies;
  605                 *ap->a_cookies = cookies;
  606         }
  607 /*
  608         if (ap->a_eofflag)
  609             *ap->a_eofflag = VTONT(ap->a_vp)->i_size <= uio->uio_offset;
  610 */
  611         return (error);
  612 }
  613 
  614 int
  615 ntfs_lookup(ap)
  616         struct vop_lookup_args /* {
  617                 struct vnode *a_dvp;
  618                 struct vnode **a_vpp;
  619                 struct componentname *a_cnp;
  620         } */ *ap;
  621 {
  622         register struct vnode *dvp = ap->a_dvp;
  623         register struct ntnode *dip = VTONT(dvp);
  624         struct ntfsmount *ntmp = dip->i_mp;
  625         struct componentname *cnp = ap->a_cnp;
  626         struct ucred *cred = cnp->cn_cred;
  627         int error;
  628         int lockparent = cnp->cn_flags & LOCKPARENT;
  629 #if NTFS_DEBUG
  630         int wantparent = cnp->cn_flags & (LOCKPARENT|WANTPARENT);
  631 #endif
  632         dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d, lp: %d, wp: %d \n",
  633                 (int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen,
  634                 dip->i_number, lockparent, wantparent));
  635 
  636         error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_thread);
  637         if(error)
  638                 return (error);
  639 
  640         if ((cnp->cn_flags & ISLASTCN) &&
  641             (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
  642             (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
  643                 return (EROFS);
  644 
  645         if(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
  646                 dprintf(("ntfs_lookup: faking . directory in %d\n",
  647                         dip->i_number));
  648 
  649                 VREF(dvp);
  650                 *ap->a_vpp = dvp;
  651                 error = 0;
  652         } else if (cnp->cn_flags & ISDOTDOT) {
  653                 struct ntvattr *vap;
  654 
  655                 dprintf(("ntfs_lookup: faking .. directory in %d\n",
  656                          dip->i_number));
  657 
  658                 error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
  659                 if(error)
  660                         return (error);
  661 
  662                 VOP_UNLOCK(dvp,0,cnp->cn_thread);
  663                 cnp->cn_flags |= PDIRUNLOCK;
  664 
  665                 dprintf(("ntfs_lookup: parentdir: %d\n",
  666                          vap->va_a_name->n_pnumber));
  667                 error = VFS_VGET(ntmp->ntm_mountp, vap->va_a_name->n_pnumber,
  668                                  LK_EXCLUSIVE, ap->a_vpp); 
  669                 ntfs_ntvattrrele(vap);
  670                 if (error) {
  671                         if (vn_lock(dvp,LK_EXCLUSIVE|LK_RETRY,cnp->cn_thread)==0)
  672                                 cnp->cn_flags &= ~PDIRUNLOCK;
  673                         return (error);
  674                 }
  675 
  676                 if (lockparent && (cnp->cn_flags & ISLASTCN)) {
  677                         error = vn_lock(dvp, LK_EXCLUSIVE, cnp->cn_thread);
  678                         if (error) {
  679                                 vput( *(ap->a_vpp) );
  680                                 return (error);
  681                         }
  682                         cnp->cn_flags &= ~PDIRUNLOCK;
  683                 }
  684         } else {
  685                 error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp);
  686                 if (error) {
  687                         dprintf(("ntfs_ntlookupfile: returned %d\n", error));
  688                         return (error);
  689                 }
  690 
  691                 dprintf(("ntfs_lookup: found ino: %d\n", 
  692                         VTONT(*ap->a_vpp)->i_number));
  693 
  694                 if(!lockparent || !(cnp->cn_flags & ISLASTCN))
  695                         VOP_UNLOCK(dvp, 0, cnp->cn_thread);
  696         }
  697 
  698         if (cnp->cn_flags & MAKEENTRY)
  699                 cache_enter(dvp, *ap->a_vpp, cnp);
  700 
  701         return (error);
  702 }
  703 
  704 /*
  705  * Flush the blocks of a file to disk.
  706  *
  707  * This function is worthless for vnodes that represent directories. Maybe we
  708  * could just do a sync if they try an fsync on a directory file.
  709  */
  710 static int
  711 ntfs_fsync(ap)
  712         struct vop_fsync_args /* {
  713                 struct vnode *a_vp;
  714                 struct ucred *a_cred;
  715                 int a_waitfor;
  716                 struct thread *a_td;
  717         } */ *ap;
  718 {
  719         return (0);
  720 }
  721 
  722 /*
  723  * Return POSIX pathconf information applicable to NTFS filesystem
  724  */
  725 int
  726 ntfs_pathconf(v)
  727         void *v;
  728 {
  729         struct vop_pathconf_args /* {
  730                 struct vnode *a_vp;
  731                 int a_name;
  732                 register_t *a_retval;
  733         } */ *ap = v;
  734 
  735         switch (ap->a_name) {
  736         case _PC_LINK_MAX:
  737                 *ap->a_retval = 1;
  738                 return (0);
  739         case _PC_NAME_MAX:
  740                 *ap->a_retval = NTFS_MAXFILENAME;
  741                 return (0);
  742         case _PC_PATH_MAX:
  743                 *ap->a_retval = PATH_MAX;
  744                 return (0);
  745         case _PC_CHOWN_RESTRICTED:
  746                 *ap->a_retval = 1;
  747                 return (0);
  748         case _PC_NO_TRUNC:
  749                 *ap->a_retval = 0;
  750                 return (0);
  751         default:
  752                 return (EINVAL);
  753         }
  754         /* NOTREACHED */
  755 }
  756 
  757 /*
  758  * Global vfs data structures
  759  */
  760 vop_t **ntfs_vnodeop_p;
  761 static
  762 struct vnodeopv_entry_desc ntfs_vnodeop_entries[] = {
  763         { &vop_default_desc, (vop_t *)vop_defaultop },
  764 
  765         { &vop_getattr_desc, (vop_t *)ntfs_getattr },
  766         { &vop_inactive_desc, (vop_t *)ntfs_inactive },
  767         { &vop_reclaim_desc, (vop_t *)ntfs_reclaim },
  768         { &vop_pathconf_desc, ntfs_pathconf },
  769 
  770         { &vop_cachedlookup_desc, (vop_t *)ntfs_lookup },
  771         { &vop_lookup_desc, (vop_t *)vfs_cache_lookup },
  772 
  773         { &vop_access_desc, (vop_t *)ntfs_access },
  774         { &vop_close_desc, (vop_t *)ntfs_close },
  775         { &vop_open_desc, (vop_t *)ntfs_open },
  776         { &vop_readdir_desc, (vop_t *)ntfs_readdir },
  777         { &vop_fsync_desc, (vop_t *)ntfs_fsync },
  778 
  779         { &vop_bmap_desc, (vop_t *)ntfs_bmap },
  780         { &vop_strategy_desc, (vop_t *)ntfs_strategy },
  781         { &vop_read_desc, (vop_t *)ntfs_read },
  782         { &vop_write_desc, (vop_t *)ntfs_write },
  783 
  784         { NULL, NULL }
  785 };
  786 
  787 static
  788 struct vnodeopv_desc ntfs_vnodeop_opv_desc =
  789         { &ntfs_vnodeop_p, ntfs_vnodeop_entries };
  790 
  791 VNODEOP_SET(ntfs_vnodeop_opv_desc);

Cache object: 76bc726fbf74a113739abf5788f0d4a9


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