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  * 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: releng/8.0/sys/fs/ntfs/ntfs_vnops.c 186194 2008-12-16 21:13:11Z trasz $
   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 vop_read_t       ntfs_read;
   70 static vop_write_t      ntfs_write;
   71 static vop_getattr_t    ntfs_getattr;
   72 static vop_inactive_t   ntfs_inactive;
   73 static vop_reclaim_t    ntfs_reclaim;
   74 static vop_bmap_t       ntfs_bmap;
   75 static vop_strategy_t   ntfs_strategy;
   76 static vop_access_t     ntfs_access;
   77 static vop_open_t       ntfs_open;
   78 static vop_close_t      ntfs_close;
   79 static vop_readdir_t    ntfs_readdir;
   80 static vop_cachedlookup_t       ntfs_lookup;
   81 static vop_fsync_t      ntfs_fsync;
   82 static vop_pathconf_t   ntfs_pathconf;
   83 static vop_vptofh_t     ntfs_vptofh;
   84 
   85 int     ntfs_prtactive = 1;     /* 1 => print out reclaim of active vnodes */
   86 
   87 /*
   88  * This is a noop, simply returning what one has been given.
   89  */
   90 int
   91 ntfs_bmap(ap)
   92         struct vop_bmap_args /* {
   93                 struct vnode *a_vp;
   94                 daddr_t  a_bn;
   95                 struct bufobj **a_bop;
   96                 daddr_t *a_bnp;
   97                 int *a_runp;
   98                 int *a_runb;
   99         } */ *ap;
  100 {
  101         struct vnode *vp = ap->a_vp;
  102 
  103         dprintf(("ntfs_bmap: vn: %p, blk: %d\n", ap->a_vp,(u_int32_t)ap->a_bn));
  104         if (ap->a_bop != NULL)
  105                 *ap->a_bop = &vp->v_bufobj;
  106         if (ap->a_bnp != NULL)
  107                 *ap->a_bnp = ap->a_bn;
  108         if (ap->a_runp != NULL)
  109                 *ap->a_runp = 0;
  110         if (ap->a_runb != NULL)
  111                 *ap->a_runb = 0;
  112         return (0);
  113 }
  114 
  115 static int
  116 ntfs_read(ap)
  117         struct vop_read_args /* {
  118                 struct vnode *a_vp;
  119                 struct uio *a_uio;
  120                 int a_ioflag;
  121                 struct ucred *a_cred;
  122         } */ *ap;
  123 {
  124         register struct vnode *vp = ap->a_vp;
  125         register struct fnode *fp = VTOF(vp);
  126         register struct ntnode *ip = FTONT(fp);
  127         struct uio *uio = ap->a_uio;
  128         struct ntfsmount *ntmp = ip->i_mp;
  129         struct buf *bp;
  130         daddr_t cn;
  131         int resid, off, toread;
  132         int error;
  133 
  134         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));
  135 
  136         dprintf(("ntfs_read: filesize: %d",(u_int32_t)fp->f_size));
  137 
  138         /* don't allow reading after end of file */
  139         if (uio->uio_offset > fp->f_size)
  140                 return (0);
  141 
  142         resid = MIN(uio->uio_resid, fp->f_size - uio->uio_offset);
  143 
  144         dprintf((", resid: %d\n", resid));
  145 
  146         error = 0;
  147         while (resid) {
  148                 cn = ntfs_btocn(uio->uio_offset);
  149                 off = ntfs_btocnoff(uio->uio_offset);
  150 
  151                 toread = MIN(off + resid, ntfs_cntob(1));
  152 
  153                 error = bread(vp, cn, ntfs_cntob(1), NOCRED, &bp);
  154                 if (error) {
  155                         brelse(bp);
  156                         break;
  157                 }
  158 
  159                 error = uiomove(bp->b_data + off, toread - off, uio);
  160                 if(error) {
  161                         brelse(bp);
  162                         break;
  163                 }
  164                 brelse(bp);
  165 
  166                 resid -= toread - off;
  167         }
  168 
  169         return (error);
  170 }
  171 
  172 static int
  173 ntfs_getattr(ap)
  174         struct vop_getattr_args /* {
  175                 struct vnode *a_vp;
  176                 struct vattr *a_vap;
  177                 struct ucred *a_cred;
  178                 struct thread *a_td;
  179         } */ *ap;
  180 {
  181         register struct vnode *vp = ap->a_vp;
  182         register struct fnode *fp = VTOF(vp);
  183         register struct ntnode *ip = FTONT(fp);
  184         register struct vattr *vap = ap->a_vap;
  185 
  186         dprintf(("ntfs_getattr: %d, flags: %d\n",ip->i_number,ip->i_flag));
  187 
  188         vap->va_fsid = dev2udev(ip->i_dev);
  189         vap->va_fileid = ip->i_number;
  190         vap->va_mode = ip->i_mp->ntm_mode;
  191         vap->va_nlink = (ip->i_nlink || ip->i_flag & IN_LOADED ? ip->i_nlink : 1);
  192         vap->va_uid = ip->i_mp->ntm_uid;
  193         vap->va_gid = ip->i_mp->ntm_gid;
  194         vap->va_rdev = NODEV;
  195         vap->va_size = fp->f_size;
  196         vap->va_bytes = fp->f_allocated;
  197         vap->va_atime = ntfs_nttimetounix(fp->f_times.t_access);
  198         vap->va_mtime = ntfs_nttimetounix(fp->f_times.t_write);
  199         vap->va_ctime = ntfs_nttimetounix(fp->f_times.t_create);
  200         vap->va_flags = ip->i_flag;
  201         vap->va_gen = 0;
  202         vap->va_blocksize = ip->i_mp->ntm_spc * ip->i_mp->ntm_bps;
  203         vap->va_type = vp->v_type;
  204         vap->va_filerev = 0;
  205         return (0);
  206 }
  207 
  208 /*
  209  * Last reference to an ntnode.  If necessary, write or delete it.
  210  */
  211 int
  212 ntfs_inactive(ap)
  213         struct vop_inactive_args /* {
  214                 struct vnode *a_vp;
  215         } */ *ap;
  216 {
  217         register struct vnode *vp = ap->a_vp;
  218 #ifdef NTFS_DEBUG
  219         register struct ntnode *ip = VTONT(vp);
  220 #endif
  221 
  222         dprintf(("ntfs_inactive: vnode: %p, ntnode: %d\n", vp, ip->i_number));
  223 
  224         if (ntfs_prtactive && vrefcnt(vp) != 0)
  225                 vprint("ntfs_inactive: pushing active", vp);
  226 
  227         /* XXX since we don't support any filesystem changes
  228          * right now, nothing more needs to be done
  229          */
  230         return (0);
  231 }
  232 
  233 /*
  234  * Reclaim an fnode/ntnode so that it can be used for other purposes.
  235  */
  236 int
  237 ntfs_reclaim(ap)
  238         struct vop_reclaim_args /* {
  239                 struct vnode *a_vp;
  240         } */ *ap;
  241 {
  242         register struct vnode *vp = ap->a_vp;
  243         register struct fnode *fp = VTOF(vp);
  244         register struct ntnode *ip = FTONT(fp);
  245         int error;
  246 
  247         dprintf(("ntfs_reclaim: vnode: %p, ntnode: %d\n", vp, ip->i_number));
  248 
  249         if (ntfs_prtactive && vrefcnt(vp) != 0)
  250                 vprint("ntfs_reclaim: pushing active", vp);
  251 
  252         /*
  253          * Destroy the vm object and flush associated pages.
  254          */
  255         vnode_destroy_vobject(vp);
  256 
  257         if ((error = ntfs_ntget(ip)) != 0)
  258                 return (error);
  259         
  260         /* Purge old data structures associated with the inode. */
  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 = ap->a_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%x\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 (0);
  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                 accmode_t a_accmode;
  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         accmode_t accmode = ap->a_accmode;
  397 
  398         dprintf(("ntfs_access: %d\n",ip->i_number));
  399 
  400         /*
  401          * Disallow write attempts on read-only filesystems;
  402          * unless the file is a socket, fifo, or a block or
  403          * character device resident on the filesystem.
  404          */
  405         if (accmode & VWRITE) {
  406                 switch ((int)vp->v_type) {
  407                 case VDIR:
  408                 case VLNK:
  409                 case VREG:
  410                         if (vp->v_mount->mnt_flag & MNT_RDONLY)
  411                                 return (EROFS);
  412                         break;
  413                 }
  414         }
  415 
  416         return (vaccess(vp->v_type, ip->i_mp->ntm_mode, ip->i_mp->ntm_uid,
  417             ip->i_mp->ntm_gid, ap->a_accmode, ap->a_cred, NULL));
  418 } 
  419 
  420 /*
  421  * Open called.
  422  *
  423  * Nothing to do.
  424  */
  425 /* ARGSUSED */
  426 static int
  427 ntfs_open(ap)
  428         struct vop_open_args /* {
  429                 struct vnode *a_vp;
  430                 int  a_mode;
  431                 struct ucred *a_cred;
  432                 struct thread *a_td;
  433         } */ *ap;
  434 {
  435 #ifdef NTFS_DEBUG
  436         register struct vnode *vp = ap->a_vp;
  437         register struct ntnode *ip = VTONT(vp);
  438 
  439         printf("ntfs_open: %d\n",ip->i_number);
  440 #endif
  441 
  442         vnode_create_vobject(ap->a_vp, VTOF(ap->a_vp)->f_size, ap->a_td);
  443 
  444         /*
  445          * Files marked append-only must be opened for appending.
  446          */
  447 
  448         return (0);
  449 }
  450 
  451 /*
  452  * Close called.
  453  *
  454  * Update the times on the inode.
  455  */
  456 /* ARGSUSED */
  457 static int
  458 ntfs_close(ap)
  459         struct vop_close_args /* {
  460                 struct vnode *a_vp;
  461                 int  a_fflag;
  462                 struct ucred *a_cred;
  463                 struct thread *a_td;
  464         } */ *ap;
  465 {
  466 #ifdef NTFS_DEBUG
  467         register struct vnode *vp = ap->a_vp;
  468         register struct ntnode *ip = VTONT(vp);
  469 
  470         printf("ntfs_close: %d\n",ip->i_number);
  471 #endif
  472 
  473         return (0);
  474 }
  475 
  476 int
  477 ntfs_readdir(ap)
  478         struct vop_readdir_args /* {
  479                 struct vnode *a_vp;
  480                 struct uio *a_uio;
  481                 struct ucred *a_cred;
  482                 int *a_ncookies;
  483                 u_int **cookies;
  484         } */ *ap;
  485 {
  486         register struct vnode *vp = ap->a_vp;
  487         register struct fnode *fp = VTOF(vp);
  488         register struct ntnode *ip = FTONT(fp);
  489         struct uio *uio = ap->a_uio;
  490         struct ntfsmount *ntmp = ip->i_mp;
  491         int i, j, error = 0;
  492         wchar c;
  493         u_int32_t faked = 0, num;
  494         int ncookies = 0;
  495         struct dirent cde;
  496         off_t off;
  497 
  498         dprintf(("ntfs_readdir %d off: %d resid: %d\n",ip->i_number,(u_int32_t)uio->uio_offset,uio->uio_resid));
  499 
  500         off = uio->uio_offset;
  501 
  502         /* Simulate . in every dir except ROOT */
  503         if( ip->i_number != NTFS_ROOTINO ) {
  504                 struct dirent dot = { NTFS_ROOTINO,
  505                                 sizeof(struct dirent), DT_DIR, 1, "." };
  506 
  507                 if( uio->uio_offset < sizeof(struct dirent) ) {
  508                         dot.d_fileno = ip->i_number;
  509                         error = uiomove((char *)&dot,sizeof(struct dirent),uio);
  510                         if(error)
  511                                 return (error);
  512 
  513                         ncookies ++;
  514                 }
  515         }
  516 
  517         /* Simulate .. in every dir including ROOT */
  518         if( uio->uio_offset < 2 * sizeof(struct dirent) ) {
  519                 struct dirent dotdot = { NTFS_ROOTINO,
  520                                 sizeof(struct dirent), DT_DIR, 2, ".." };
  521 
  522                 error = uiomove((char *)&dotdot,sizeof(struct dirent),uio);
  523                 if(error)
  524                         return (error);
  525 
  526                 ncookies ++;
  527         }
  528 
  529         faked = (ip->i_number == NTFS_ROOTINO) ? 1 : 2;
  530         num = uio->uio_offset / sizeof(struct dirent) - faked;
  531 
  532         while( uio->uio_resid >= sizeof(struct dirent) ) {
  533                 struct attr_indexentry *iep;
  534 
  535                 error = ntfs_ntreaddir(ntmp, fp, num, &iep);
  536 
  537                 if(error)
  538                         return (error);
  539 
  540                 if( NULL == iep )
  541                         break;
  542 
  543                 for(; !(iep->ie_flag & NTFS_IEFLAG_LAST) && (uio->uio_resid >= sizeof(struct dirent));
  544                         iep = NTFS_NEXTREC(iep, struct attr_indexentry *))
  545                 {
  546                         if(!ntfs_isnamepermitted(ntmp,iep))
  547                                 continue;
  548 
  549                         for(i=0, j=0; i<iep->ie_fnamelen; i++, j++) {
  550                                 c = NTFS_U28(iep->ie_fname[i]);
  551                                 if (c&0xFF00)
  552                                         cde.d_name[j++] = (char)(c>>8);
  553                                 cde.d_name[j] = (char)c&0xFF;
  554                         }
  555                         cde.d_name[j] = '\0';
  556                         dprintf(("ntfs_readdir: elem: %d, fname:[%s] type: %d, flag: %d, ",
  557                                 num, cde.d_name, iep->ie_fnametype,
  558                                 iep->ie_flag));
  559                         cde.d_namlen = j;
  560                         cde.d_fileno = iep->ie_number;
  561                         cde.d_type = (iep->ie_fflag & NTFS_FFLAG_DIR) ? DT_DIR : DT_REG;
  562                         cde.d_reclen = sizeof(struct dirent);
  563                         dprintf(("%s\n", (cde.d_type == DT_DIR) ? "dir":"reg"));
  564 
  565                         error = uiomove((char *)&cde, sizeof(struct dirent), uio);
  566                         if(error)
  567                                 return (error);
  568 
  569                         ncookies++;
  570                         num++;
  571                 }
  572         }
  573 
  574         dprintf(("ntfs_readdir: %d entries (%d bytes) read\n",
  575                 ncookies,(u_int)(uio->uio_offset - off)));
  576         dprintf(("ntfs_readdir: off: %d resid: %d\n",
  577                 (u_int32_t)uio->uio_offset,uio->uio_resid));
  578 
  579         if (!error && ap->a_ncookies != NULL) {
  580                 struct dirent* dpStart;
  581                 struct dirent* dp;
  582                 u_long *cookies;
  583                 u_long *cookiep;
  584 
  585                 ddprintf(("ntfs_readdir: %d cookies\n",ncookies));
  586                 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
  587                         panic("ntfs_readdir: unexpected uio from NFS server");
  588                 dpStart = (struct dirent *)
  589                      ((caddr_t)uio->uio_iov->iov_base -
  590                          (uio->uio_offset - off));
  591                 cookies = malloc(ncookies * sizeof(u_long),
  592                        M_TEMP, M_WAITOK);
  593                 for (dp = dpStart, cookiep = cookies, i=0;
  594                      i < ncookies;
  595                      dp = (struct dirent *)((caddr_t) dp + dp->d_reclen), i++) {
  596                         off += dp->d_reclen;
  597                         *cookiep++ = (u_int) off;
  598                 }
  599                 *ap->a_ncookies = ncookies;
  600                 *ap->a_cookies = cookies;
  601         }
  602 /*
  603         if (ap->a_eofflag)
  604             *ap->a_eofflag = VTONT(ap->a_vp)->i_size <= uio->uio_offset;
  605 */
  606         return (error);
  607 }
  608 
  609 int
  610 ntfs_lookup(ap)
  611         struct vop_cachedlookup_args /* {
  612                 struct vnode *a_dvp;
  613                 struct vnode **a_vpp;
  614                 struct componentname *a_cnp;
  615         } */ *ap;
  616 {
  617         register struct vnode *dvp = ap->a_dvp;
  618         register struct ntnode *dip = VTONT(dvp);
  619         struct ntfsmount *ntmp = dip->i_mp;
  620         struct componentname *cnp = ap->a_cnp;
  621         struct ucred *cred = cnp->cn_cred;
  622         int error;
  623         dprintf(("ntfs_lookup: \"%.*s\" (%ld bytes) in %d\n",
  624                 (int)cnp->cn_namelen, cnp->cn_nameptr, cnp->cn_namelen,
  625                 dip->i_number));
  626 
  627         error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_thread);
  628         if(error)
  629                 return (error);
  630 
  631         if ((cnp->cn_flags & ISLASTCN) &&
  632             (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
  633             (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
  634                 return (EROFS);
  635 
  636         if(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
  637                 dprintf(("ntfs_lookup: faking . directory in %d\n",
  638                         dip->i_number));
  639 
  640                 VREF(dvp);
  641                 *ap->a_vpp = dvp;
  642                 error = 0;
  643         } else if (cnp->cn_flags & ISDOTDOT) {
  644                 struct ntvattr *vap;
  645 
  646                 dprintf(("ntfs_lookup: faking .. directory in %d\n",
  647                          dip->i_number));
  648 
  649                 error = ntfs_ntvattrget(ntmp, dip, NTFS_A_NAME, NULL, 0, &vap);
  650                 if(error)
  651                         return (error);
  652 
  653                 VOP_UNLOCK(dvp,0);
  654                 dprintf(("ntfs_lookup: parentdir: %d\n",
  655                          vap->va_a_name->n_pnumber));
  656                 error = VFS_VGET(ntmp->ntm_mountp, vap->va_a_name->n_pnumber,
  657                                  LK_EXCLUSIVE, ap->a_vpp); 
  658                 ntfs_ntvattrrele(vap);
  659                 if (error) {
  660                         vn_lock(dvp,LK_EXCLUSIVE|LK_RETRY);
  661                         return (error);
  662                 }
  663         } else {
  664                 error = ntfs_ntlookupfile(ntmp, dvp, cnp, ap->a_vpp);
  665                 if (error) {
  666                         dprintf(("ntfs_ntlookupfile: returned %d\n", error));
  667                         return (error);
  668                 }
  669 
  670                 dprintf(("ntfs_lookup: found ino: %d\n", 
  671                         VTONT(*ap->a_vpp)->i_number));
  672         }
  673 
  674         if (cnp->cn_flags & MAKEENTRY)
  675                 cache_enter(dvp, *ap->a_vpp, cnp);
  676 
  677         return (error);
  678 }
  679 
  680 /*
  681  * Flush the blocks of a file to disk.
  682  *
  683  * This function is worthless for vnodes that represent directories. Maybe we
  684  * could just do a sync if they try an fsync on a directory file.
  685  */
  686 static int
  687 ntfs_fsync(ap)
  688         struct vop_fsync_args /* {
  689                 struct vnode *a_vp;
  690                 struct ucred *a_cred;
  691                 int a_waitfor;
  692                 struct thread *a_td;
  693         } */ *ap;
  694 {
  695         return (0);
  696 }
  697 
  698 /*
  699  * Return POSIX pathconf information applicable to NTFS filesystem
  700  */
  701 int
  702 ntfs_pathconf(ap)
  703         struct vop_pathconf_args *ap;
  704 {
  705 
  706         switch (ap->a_name) {
  707         case _PC_LINK_MAX:
  708                 *ap->a_retval = 1;
  709                 return (0);
  710         case _PC_NAME_MAX:
  711                 *ap->a_retval = NTFS_MAXFILENAME;
  712                 return (0);
  713         case _PC_PATH_MAX:
  714                 *ap->a_retval = PATH_MAX;
  715                 return (0);
  716         case _PC_CHOWN_RESTRICTED:
  717                 *ap->a_retval = 1;
  718                 return (0);
  719         case _PC_NO_TRUNC:
  720                 *ap->a_retval = 0;
  721                 return (0);
  722         default:
  723                 return (EINVAL);
  724         }
  725         /* NOTREACHED */
  726 }
  727 
  728 int
  729 ntfs_vptofh(ap)
  730         struct vop_vptofh_args /* {
  731                 struct vnode *a_vp;
  732                 struct fid *a_fhp;
  733         } */ *ap;
  734 {
  735         register struct ntnode *ntp;
  736         register struct ntfid *ntfhp;
  737 
  738         ddprintf(("ntfs_fhtovp(): %p\n", ap->a_vp));
  739 
  740         ntp = VTONT(ap->a_vp);
  741         ntfhp = (struct ntfid *)ap->a_fhp;
  742         ntfhp->ntfid_len = sizeof(struct ntfid);
  743         ntfhp->ntfid_ino = ntp->i_number;
  744         /* ntfhp->ntfid_gen = ntp->i_gen; */
  745         return (0);
  746 }
  747 
  748 /*
  749  * Global vfs data structures
  750  */
  751 struct vop_vector ntfs_vnodeops = {
  752         .vop_default =          &default_vnodeops,
  753 
  754         .vop_access =           ntfs_access,
  755         .vop_bmap =             ntfs_bmap,
  756         .vop_cachedlookup =     ntfs_lookup,
  757         .vop_close =            ntfs_close,
  758         .vop_fsync =            ntfs_fsync,
  759         .vop_getattr =          ntfs_getattr,
  760         .vop_inactive =         ntfs_inactive,
  761         .vop_lookup =           vfs_cache_lookup,
  762         .vop_open =             ntfs_open,
  763         .vop_pathconf =         ntfs_pathconf,
  764         .vop_read =             ntfs_read,
  765         .vop_readdir =          ntfs_readdir,
  766         .vop_reclaim =          ntfs_reclaim,
  767         .vop_strategy =         ntfs_strategy,
  768         .vop_write =            ntfs_write,
  769         .vop_vptofh =           ntfs_vptofh,
  770 };

Cache object: 1121577df5005a69158c9410c951ce60


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