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_vfsops.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_vfsops.c,v 1.23 1999/11/15 19:38:14 jdolecek Exp $        */
    2 
    3 /*-
    4  * Copyright (c) 1998, 1999 Semen Ustimenko
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  *
   28  * $FreeBSD$
   29  */
   30 
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/namei.h>
   35 #include <sys/conf.h>
   36 #include <sys/proc.h>
   37 #include <sys/kernel.h>
   38 #include <sys/vnode.h>
   39 #include <sys/mount.h>
   40 #include <sys/bio.h>
   41 #include <sys/buf.h>
   42 #include <sys/fcntl.h>
   43 #include <sys/malloc.h>
   44 #include <sys/systm.h>
   45 
   46 #include <geom/geom.h>
   47 #include <geom/geom_vfs.h>
   48 
   49 #include <vm/vm.h>
   50 #include <vm/vm_param.h>
   51 #include <vm/vm_page.h>
   52 #include <vm/vm_object.h>
   53 #include <vm/vm_extern.h>
   54 
   55 /*#define NTFS_DEBUG 1*/
   56 #include <fs/ntfs/ntfs.h>
   57 #include <fs/ntfs/ntfs_inode.h>
   58 #include <fs/ntfs/ntfs_subr.h>
   59 #include <fs/ntfs/ntfs_vfsops.h>
   60 #include <fs/ntfs/ntfs_ihash.h>
   61 #include <fs/ntfs/ntfsmount.h>
   62 
   63 static MALLOC_DEFINE(M_NTFSMNT, "ntfs_mount", "NTFS mount structure");
   64 MALLOC_DEFINE(M_NTFSNTNODE,"ntfs_ntnode",  "NTFS ntnode information");
   65 MALLOC_DEFINE(M_NTFSFNODE,"ntfs_fnode",  "NTFS fnode information");
   66 MALLOC_DEFINE(M_NTFSDIR,"ntfs_dir",  "NTFS dir buffer");
   67 
   68 struct sockaddr;
   69 
   70 static int      ntfs_mountfs(register struct vnode *, struct mount *, 
   71                                   struct thread *);
   72 static int      ntfs_calccfree(struct ntfsmount *ntmp, cn_t *cfreep);
   73 
   74 static vfs_init_t       ntfs_init;
   75 static vfs_uninit_t     ntfs_uninit;
   76 static vfs_vget_t       ntfs_vget;
   77 static vfs_fhtovp_t     ntfs_fhtovp;
   78 static vfs_cmount_t     ntfs_cmount;
   79 static vfs_mount_t      ntfs_mount;
   80 static vfs_root_t       ntfs_root;
   81 static vfs_statfs_t     ntfs_statfs;
   82 static vfs_unmount_t    ntfs_unmount;
   83 
   84 static b_strategy_t     ntfs_bufstrategy;
   85 
   86 /* 
   87  * Buffer operations for NTFS vnodes.
   88  * We punt on VOP_BMAP, so we need to do
   89  * strategy on the file's vnode rather
   90  * than the underlying device's
   91  */
   92 static struct buf_ops ntfs_vnbufops = {
   93         .bop_name     = "NTFS",
   94         .bop_strategy = ntfs_bufstrategy,
   95 };
   96 
   97 static int
   98 ntfs_init (
   99         struct vfsconf *vcp )
  100 {
  101         ntfs_nthashinit();
  102         ntfs_toupper_init();
  103         return 0;
  104 }
  105 
  106 static int
  107 ntfs_uninit (
  108         struct vfsconf *vcp )
  109 {
  110         ntfs_toupper_destroy();
  111         ntfs_nthashdestroy();
  112         return 0;
  113 }
  114 
  115 static int
  116 ntfs_cmount ( 
  117         struct mntarg *ma,
  118         void *data,
  119         int flags,
  120         struct thread *td )
  121 {
  122         int error;
  123         struct ntfs_args args;
  124 
  125         error = copyin(data, (caddr_t)&args, sizeof args);
  126         if (error)
  127                 return (error);
  128         ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
  129         ma = mount_arg(ma, "export", &args.export, sizeof args.export);
  130         ma = mount_argf(ma, "uid", "%d", args.uid);
  131         ma = mount_argf(ma, "gid", "%d", args.gid);
  132         ma = mount_argf(ma, "mode", "%d", args.mode);
  133         ma = mount_argb(ma, args.flag & NTFS_MFLAG_CASEINS, "nocaseins");
  134         ma = mount_argb(ma, args.flag & NTFS_MFLAG_ALLNAMES, "noallnames");
  135         if (args.flag & NTFS_MFLAG_KICONV) {
  136                 ma = mount_argsu(ma, "cs_ntfs", args.cs_ntfs, 64);
  137                 ma = mount_argsu(ma, "cs_local", args.cs_local, 64);
  138         }
  139 
  140         error = kernel_mount(ma, flags);
  141 
  142         return (error);
  143 }
  144 
  145 static const char *ntfs_opts[] = {
  146         "from", "export", "uid", "gid", "mode", "caseins", "allnames",
  147         "kiconv", "cs_ntfs", "cs_local", NULL
  148 };
  149 
  150 static int
  151 ntfs_mount ( 
  152         struct mount *mp,
  153         struct thread *td )
  154 {
  155         int             err = 0, error;
  156         struct vnode    *devvp;
  157         struct nameidata ndp;
  158         char *from;
  159 
  160         if (vfs_filteropt(mp->mnt_optnew, ntfs_opts))
  161                 return (EINVAL);
  162 
  163         from = vfs_getopts(mp->mnt_optnew, "from", &error);
  164         if (error)      
  165                 return (error);
  166 
  167         /*
  168          * If updating, check whether changing from read-only to
  169          * read/write.
  170          */
  171         if (mp->mnt_flag & MNT_UPDATE) {
  172                 if (vfs_flagopt(mp->mnt_optnew, "export", NULL, 0)) {
  173                         /* Process export requests in vfs_mount.c */
  174                         goto success;
  175                 } else {
  176                         printf("ntfs_mount(): MNT_UPDATE not supported\n");
  177                         err = EINVAL;
  178                         goto error_1;
  179                 }
  180         }
  181 
  182         /*
  183          * Not an update, or updating the name: look up the name
  184          * and verify that it refers to a sensible block device.
  185          */
  186         NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, from, td);
  187         err = namei(&ndp);
  188         if (err) {
  189                 /* can't get devvp!*/
  190                 goto error_1;
  191         }
  192         NDFREE(&ndp, NDF_ONLY_PNBUF);
  193         devvp = ndp.ni_vp;
  194 
  195         if (!vn_isdisk(devvp, &err))  {
  196                 vput(devvp);
  197                 return (err);
  198         }
  199 
  200         if (mp->mnt_flag & MNT_UPDATE) {
  201 #if 0
  202                 /*
  203                  ********************
  204                  * UPDATE
  205                  ********************
  206                  */
  207 
  208                 if (devvp != ntmp->um_devvp)
  209                         err = EINVAL;   /* needs translation */
  210                 vput(devvp);
  211                 if (err)
  212                         return (err);
  213 #endif
  214         } else {
  215                 /*
  216                  ********************
  217                  * NEW MOUNT
  218                  ********************
  219                  */
  220 
  221                 /*
  222                  * Since this is a new mount, we want the names for
  223                  * the device and the mount point copied in.  If an
  224                  * error occurs, the mountpoint is discarded by the
  225                  * upper level code.  Note that vfs_mount() handles
  226                  * copying the mountpoint f_mntonname for us, so we
  227                  * don't have to do it here unless we want to set it
  228                  * to something other than "path" for some rason.
  229                  */
  230                 /* Save "mounted from" info for mount point (NULL pad)*/
  231                 vfs_mountedfrom(mp, from);
  232 
  233                 err = ntfs_mountfs(devvp, mp, td);
  234         }
  235         if (err) {
  236                 vrele(devvp);
  237                 return (err);
  238         }
  239 
  240         goto success;
  241 
  242 error_1:        /* no state to back out*/
  243         /* XXX: missing NDFREE(&ndp, ...) */
  244 
  245 success:
  246         return(err);
  247 }
  248 
  249 /*
  250  * Common code for mount and mountroot
  251  */
  252 int
  253 ntfs_mountfs(devvp, mp, td)
  254         register struct vnode *devvp;
  255         struct mount *mp;
  256         struct thread *td;
  257 {
  258         struct buf *bp;
  259         struct ntfsmount *ntmp;
  260         struct cdev *dev = devvp->v_rdev;
  261         int error, ronly, i, v;
  262         struct vnode *vp;
  263         struct g_consumer *cp;
  264         struct g_provider *pp;
  265         char *cs_ntfs, *cs_local;
  266 
  267         ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
  268         DROP_GIANT();
  269         g_topology_lock();
  270 
  271         /*
  272          * XXX: Do not allow more than one consumer to open a device
  273          *      associated with a particular GEOM provider.
  274          *      This disables multiple read-only mounts of a device,
  275          *      but it gets rid of panics in vget() when you try to
  276          *      mount the same device more than once.
  277          */
  278         pp = g_dev_getprovider(devvp->v_rdev);
  279         if ((pp != NULL) && ((pp->acr | pp->acw | pp->ace ) != 0)) 
  280                 error = EPERM;
  281         else 
  282                 error = g_vfs_open(devvp, &cp, "ntfs", ronly ? 0 : 1);
  283 
  284         g_topology_unlock();
  285         PICKUP_GIANT();
  286         VOP_UNLOCK(devvp, 0, td);
  287         if (error)
  288                 return (error);
  289 
  290         bp = NULL;
  291 
  292         error = bread(devvp, BBLOCK, BBSIZE, NOCRED, &bp);
  293         if (error)
  294                 goto out;
  295         ntmp = malloc( sizeof *ntmp, M_NTFSMNT, M_WAITOK | M_ZERO);
  296         bcopy( bp->b_data, &ntmp->ntm_bootfile, sizeof(struct bootfile) );
  297         /*
  298          * We must not cache the boot block if its size is not exactly
  299          * one cluster in order to avoid confusing the buffer cache when
  300          * the boot file is read later by ntfs_readntvattr_plain(), which
  301          * reads a cluster at a time.
  302          */
  303         if (ntfs_cntob(1) != BBSIZE)
  304                 bp->b_flags |= B_NOCACHE;
  305         brelse( bp );
  306         bp = NULL;
  307 
  308         if (strncmp((const char *)ntmp->ntm_bootfile.bf_sysid, NTFS_BBID, NTFS_BBIDLEN)) {
  309                 error = EINVAL;
  310                 dprintf(("ntfs_mountfs: invalid boot block\n"));
  311                 goto out;
  312         }
  313 
  314         {
  315                 int8_t cpr = ntmp->ntm_mftrecsz;
  316                 if( cpr > 0 )
  317                         ntmp->ntm_bpmftrec = ntmp->ntm_spc * cpr;
  318                 else
  319                         ntmp->ntm_bpmftrec = (1 << (-cpr)) / ntmp->ntm_bps;
  320         }
  321         dprintf(("ntfs_mountfs(): bps: %d, spc: %d, media: %x, mftrecsz: %d (%d sects)\n",
  322                 ntmp->ntm_bps,ntmp->ntm_spc,ntmp->ntm_bootfile.bf_media,
  323                 ntmp->ntm_mftrecsz,ntmp->ntm_bpmftrec));
  324         dprintf(("ntfs_mountfs(): mftcn: 0x%x|0x%x\n",
  325                 (u_int32_t)ntmp->ntm_mftcn,(u_int32_t)ntmp->ntm_mftmirrcn));
  326 
  327         ntmp->ntm_mountp = mp;
  328         ntmp->ntm_devvp = devvp;
  329         if (1 == vfs_scanopt(mp->mnt_optnew, "uid", "%d", &v))
  330                 ntmp->ntm_uid = v;
  331         if (1 == vfs_scanopt(mp->mnt_optnew, "gid", "%d", &v))
  332                 ntmp->ntm_gid = v;
  333         if (1 == vfs_scanopt(mp->mnt_optnew, "mode", "%d", &v))
  334                 ntmp->ntm_mode = v;
  335         vfs_flagopt(mp->mnt_optnew,
  336             "caseins", &ntmp->ntm_flag, NTFS_MFLAG_CASEINS);
  337         vfs_flagopt(mp->mnt_optnew,
  338             "allnames", &ntmp->ntm_flag, NTFS_MFLAG_ALLNAMES);
  339         ntmp->ntm_cp = cp;
  340         ntmp->ntm_bo = &devvp->v_bufobj;
  341 
  342         cs_local = vfs_getopts(mp->mnt_optnew, "cs_local", &error);
  343         if (error && error != ENOENT)
  344                 goto out;
  345         cs_ntfs = vfs_getopts(mp->mnt_optnew, "cs_ntfs", &error);
  346         if (error && error != ENOENT)
  347                 goto out;
  348         /* Copy in the 8-bit to Unicode conversion table */
  349         /* Initialize Unicode to 8-bit table from 8toU table */
  350         ntfs_82u_init(ntmp, cs_local, cs_ntfs);
  351         if (cs_local != NULL && cs_ntfs != NULL)
  352                 ntfs_u28_init(ntmp, NULL, cs_local, cs_ntfs);
  353         else
  354                 ntfs_u28_init(ntmp, ntmp->ntm_82u, cs_local, cs_ntfs);
  355 
  356         mp->mnt_data = (qaddr_t)ntmp;
  357 
  358         dprintf(("ntfs_mountfs(): case-%s,%s uid: %d, gid: %d, mode: %o\n",
  359                 (ntmp->ntm_flag & NTFS_MFLAG_CASEINS)?"insens.":"sens.",
  360                 (ntmp->ntm_flag & NTFS_MFLAG_ALLNAMES)?" allnames,":"",
  361                 ntmp->ntm_uid, ntmp->ntm_gid, ntmp->ntm_mode));
  362 
  363         /*
  364          * We read in some system nodes to do not allow 
  365          * reclaim them and to have everytime access to them.
  366          */ 
  367         {
  368                 int pi[3] = { NTFS_MFTINO, NTFS_ROOTINO, NTFS_BITMAPINO };
  369                 for (i=0; i<3; i++) {
  370                         error = VFS_VGET(mp, pi[i], LK_EXCLUSIVE,
  371                                          &(ntmp->ntm_sysvn[pi[i]]));
  372                         if(error)
  373                                 goto out1;
  374                         ntmp->ntm_sysvn[pi[i]]->v_vflag |= VV_SYSTEM;
  375                         VREF(ntmp->ntm_sysvn[pi[i]]);
  376                         vput(ntmp->ntm_sysvn[pi[i]]);
  377                 }
  378         }
  379 
  380         /* read the Unicode lowercase --> uppercase translation table,
  381          * if necessary */
  382         if ((error = ntfs_toupper_use(mp, ntmp)))
  383                 goto out1;
  384 
  385         /*
  386          * Scan $BitMap and count free clusters
  387          */
  388         error = ntfs_calccfree(ntmp, &ntmp->ntm_cfree);
  389         if(error)
  390                 goto out1;
  391 
  392         /*
  393          * Read and translate to internal format attribute
  394          * definition file. 
  395          */
  396         {
  397                 int num,j;
  398                 struct attrdef ad;
  399 
  400                 /* Open $AttrDef */
  401                 error = VFS_VGET(mp, NTFS_ATTRDEFINO, LK_EXCLUSIVE, &vp );
  402                 if(error) 
  403                         goto out1;
  404 
  405                 /* Count valid entries */
  406                 for(num=0;;num++) {
  407                         error = ntfs_readattr(ntmp, VTONT(vp),
  408                                         NTFS_A_DATA, NULL,
  409                                         num * sizeof(ad), sizeof(ad),
  410                                         &ad, NULL);
  411                         if (error)
  412                                 goto out1;
  413                         if (ad.ad_name[0] == 0)
  414                                 break;
  415                 }
  416 
  417                 /* Alloc memory for attribute definitions */
  418                 MALLOC(ntmp->ntm_ad, struct ntvattrdef *,
  419                         num * sizeof(struct ntvattrdef),
  420                         M_NTFSMNT, M_WAITOK);
  421 
  422                 ntmp->ntm_adnum = num;
  423 
  424                 /* Read them and translate */
  425                 for(i=0;i<num;i++){
  426                         error = ntfs_readattr(ntmp, VTONT(vp),
  427                                         NTFS_A_DATA, NULL,
  428                                         i * sizeof(ad), sizeof(ad),
  429                                         &ad, NULL);
  430                         if (error)
  431                                 goto out1;
  432                         j = 0;
  433                         do {
  434                                 ntmp->ntm_ad[i].ad_name[j] = ad.ad_name[j];
  435                         } while(ad.ad_name[j++]);
  436                         ntmp->ntm_ad[i].ad_namelen = j - 1;
  437                         ntmp->ntm_ad[i].ad_type = ad.ad_type;
  438                 }
  439 
  440                 vput(vp);
  441         }
  442 
  443         mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
  444         mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
  445         mp->mnt_maxsymlinklen = 0;
  446         MNT_ILOCK(mp);
  447         mp->mnt_flag |= MNT_LOCAL;
  448         MNT_IUNLOCK(mp);
  449         return (0);
  450 
  451 out1:
  452         for(i=0;i<NTFS_SYSNODESNUM;i++)
  453                 if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
  454 
  455         if (vflush(mp, 0, 0, td))
  456                 dprintf(("ntfs_mountfs: vflush failed\n"));
  457 
  458 out:
  459         if (bp)
  460                 brelse(bp);
  461 
  462         DROP_GIANT();
  463         g_topology_lock();
  464         g_vfs_close(cp, td);
  465         g_topology_unlock();
  466         PICKUP_GIANT();
  467         
  468         return (error);
  469 }
  470 
  471 static int
  472 ntfs_unmount( 
  473         struct mount *mp,
  474         int mntflags,
  475         struct thread *td)
  476 {
  477         struct ntfsmount *ntmp;
  478         int error, flags, i;
  479 
  480         dprintf(("ntfs_unmount: unmounting...\n"));
  481         ntmp = VFSTONTFS(mp);
  482 
  483         flags = 0;
  484         if(mntflags & MNT_FORCE)
  485                 flags |= FORCECLOSE;
  486 
  487         dprintf(("ntfs_unmount: vflushing...\n"));
  488         error = vflush(mp, 0, flags | SKIPSYSTEM, td);
  489         if (error) {
  490                 printf("ntfs_unmount: vflush failed: %d\n",error);
  491                 return (error);
  492         }
  493 
  494         /* Check if only system vnodes are rest */
  495         for(i=0;i<NTFS_SYSNODESNUM;i++)
  496                  if((ntmp->ntm_sysvn[i]) && 
  497                     (vrefcnt(ntmp->ntm_sysvn[i]) > 1)) return (EBUSY);
  498 
  499         /* Dereference all system vnodes */
  500         for(i=0;i<NTFS_SYSNODESNUM;i++)
  501                  if(ntmp->ntm_sysvn[i]) vrele(ntmp->ntm_sysvn[i]);
  502 
  503         /* vflush system vnodes */
  504         error = vflush(mp, 0, flags, td);
  505         if (error)
  506                 printf("ntfs_unmount: vflush failed(sysnodes): %d\n",error);
  507 
  508         vinvalbuf(ntmp->ntm_devvp, V_SAVE, td, 0, 0);
  509 
  510         DROP_GIANT();
  511         g_topology_lock();
  512         g_vfs_close(ntmp->ntm_cp, td);
  513         g_topology_unlock();
  514         PICKUP_GIANT();
  515 
  516         vrele(ntmp->ntm_devvp);
  517 
  518         /* free the toupper table, if this has been last mounted ntfs volume */
  519         ntfs_toupper_unuse();
  520 
  521         dprintf(("ntfs_umount: freeing memory...\n"));
  522         ntfs_u28_uninit(ntmp);
  523         ntfs_82u_uninit(ntmp);
  524         mp->mnt_data = (qaddr_t)0;
  525         MNT_ILOCK(mp);
  526         mp->mnt_flag &= ~MNT_LOCAL;
  527         MNT_IUNLOCK(mp);
  528         FREE(ntmp->ntm_ad, M_NTFSMNT);
  529         FREE(ntmp, M_NTFSMNT);
  530         return (error);
  531 }
  532 
  533 static int
  534 ntfs_root(
  535         struct mount *mp,
  536         int flags,
  537         struct vnode **vpp,
  538         struct thread *td )
  539 {
  540         struct vnode *nvp;
  541         int error = 0;
  542 
  543         dprintf(("ntfs_root(): sysvn: %p\n",
  544                 VFSTONTFS(mp)->ntm_sysvn[NTFS_ROOTINO]));
  545         error = VFS_VGET(mp, (ino_t)NTFS_ROOTINO, LK_EXCLUSIVE, &nvp);
  546         if(error) {
  547                 printf("ntfs_root: VFS_VGET failed: %d\n",error);
  548                 return (error);
  549         }
  550 
  551         *vpp = nvp;
  552         return (0);
  553 }
  554 
  555 static int
  556 ntfs_calccfree(
  557         struct ntfsmount *ntmp,
  558         cn_t *cfreep)
  559 {
  560         struct vnode *vp;
  561         u_int8_t *tmp;
  562         int j, error;
  563         long cfree = 0;
  564         size_t bmsize, i;
  565 
  566         vp = ntmp->ntm_sysvn[NTFS_BITMAPINO];
  567 
  568         bmsize = VTOF(vp)->f_size;
  569 
  570         MALLOC(tmp, u_int8_t *, bmsize, M_TEMP, M_WAITOK);
  571 
  572         error = ntfs_readattr(ntmp, VTONT(vp), NTFS_A_DATA, NULL,
  573                                0, bmsize, tmp, NULL);
  574         if (error)
  575                 goto out;
  576 
  577         for(i=0;i<bmsize;i++)
  578                 for(j=0;j<8;j++)
  579                         if(~tmp[i] & (1 << j)) cfree++;
  580         *cfreep = cfree;
  581 
  582     out:
  583         FREE(tmp, M_TEMP);
  584         return(error);
  585 }
  586 
  587 static int
  588 ntfs_statfs(
  589         struct mount *mp,
  590         struct statfs *sbp,
  591         struct thread *td)
  592 {
  593         struct ntfsmount *ntmp = VFSTONTFS(mp);
  594         u_int64_t mftsize,mftallocated;
  595 
  596         dprintf(("ntfs_statfs():\n"));
  597 
  598         mftsize = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_size;
  599         mftallocated = VTOF(ntmp->ntm_sysvn[NTFS_MFTINO])->f_allocated;
  600 
  601         sbp->f_type = mp->mnt_vfc->vfc_typenum;
  602         sbp->f_bsize = ntmp->ntm_bps;
  603         sbp->f_iosize = ntmp->ntm_bps * ntmp->ntm_spc;
  604         sbp->f_blocks = ntmp->ntm_bootfile.bf_spv;
  605         sbp->f_bfree = sbp->f_bavail = ntfs_cntobn(ntmp->ntm_cfree);
  606         sbp->f_ffree = sbp->f_bfree / ntmp->ntm_bpmftrec;
  607         sbp->f_files = mftallocated / ntfs_bntob(ntmp->ntm_bpmftrec) +
  608                        sbp->f_ffree;
  609         sbp->f_flags = mp->mnt_flag;
  610 
  611         return (0);
  612 }
  613 
  614 /*ARGSUSED*/
  615 static int
  616 ntfs_fhtovp(
  617         struct mount *mp,
  618         struct fid *fhp,
  619         struct vnode **vpp)
  620 {
  621         struct vnode *nvp;
  622         struct ntfid *ntfhp = (struct ntfid *)fhp;
  623         int error;
  624 
  625         ddprintf(("ntfs_fhtovp(): %d\n", ntfhp->ntfid_ino));
  626 
  627         if ((error = VFS_VGET(mp, ntfhp->ntfid_ino, LK_EXCLUSIVE, &nvp)) != 0) {
  628                 *vpp = NULLVP;
  629                 return (error);
  630         }
  631         /* XXX as unlink/rmdir/mkdir/creat are not currently possible
  632          * with NTFS, we don't need to check anything else for now */
  633         *vpp = nvp;
  634         vnode_create_vobject(nvp, VTOF(nvp)->f_size, curthread);
  635         return (0);
  636 }
  637 
  638 int
  639 ntfs_vgetex(
  640         struct mount *mp,
  641         ino_t ino,
  642         u_int32_t attrtype,
  643         char *attrname,
  644         u_long lkflags,
  645         u_long flags,
  646         struct thread *td,
  647         struct vnode **vpp) 
  648 {
  649         int error;
  650         register struct ntfsmount *ntmp;
  651         struct ntnode *ip;
  652         struct fnode *fp;
  653         struct vnode *vp;
  654         enum vtype f_type;
  655 
  656         dprintf(("ntfs_vgetex: ino: %d, attr: 0x%x:%s, lkf: 0x%lx, f: 0x%lx\n",
  657                 ino, attrtype, attrname?attrname:"", (u_long)lkflags,
  658                 (u_long)flags));
  659 
  660         ntmp = VFSTONTFS(mp);
  661         *vpp = NULL;
  662 
  663         /* Get ntnode */
  664         error = ntfs_ntlookup(ntmp, ino, &ip);
  665         if (error) {
  666                 printf("ntfs_vget: ntfs_ntget failed\n");
  667                 return (error);
  668         }
  669 
  670         /* It may be not initialized fully, so force load it */
  671         if (!(flags & VG_DONTLOADIN) && !(ip->i_flag & IN_LOADED)) {
  672                 error = ntfs_loadntnode(ntmp, ip);
  673                 if(error) {
  674                         printf("ntfs_vget: CAN'T LOAD ATTRIBUTES FOR INO: %d\n",
  675                                ip->i_number);
  676                         ntfs_ntput(ip);
  677                         return (error);
  678                 }
  679         }
  680 
  681         error = ntfs_fget(ntmp, ip, attrtype, attrname, &fp);
  682         if (error) {
  683                 printf("ntfs_vget: ntfs_fget failed\n");
  684                 ntfs_ntput(ip);
  685                 return (error);
  686         }
  687 
  688         f_type = VNON;
  689         if (!(flags & VG_DONTVALIDFN) && !(fp->f_flag & FN_VALID)) {
  690                 if ((ip->i_frflag & NTFS_FRFLAG_DIR) &&
  691                     (fp->f_attrtype == NTFS_A_DATA && fp->f_attrname == NULL)) {
  692                         f_type = VDIR;
  693                 } else if (flags & VG_EXT) {
  694                         f_type = VNON;
  695                         fp->f_size = fp->f_allocated = 0;
  696                 } else {
  697                         f_type = VREG;  
  698 
  699                         error = ntfs_filesize(ntmp, fp, 
  700                                               &fp->f_size, &fp->f_allocated);
  701                         if (error) {
  702                                 ntfs_ntput(ip);
  703                                 return (error);
  704                         }
  705                 }
  706 
  707                 fp->f_flag |= FN_VALID;
  708         }
  709 
  710         if (FTOV(fp)) {
  711                 vget(FTOV(fp), lkflags, td);
  712                 *vpp = FTOV(fp);
  713                 ntfs_ntput(ip);
  714                 return (0);
  715         }
  716 
  717         error = getnewvnode("ntfs", ntmp->ntm_mountp, &ntfs_vnodeops, &vp);
  718         if(error) {
  719                 ntfs_frele(fp);
  720                 ntfs_ntput(ip);
  721                 return (error);
  722         }
  723         /* XXX: Too early for mpsafe fs, lacks vnode lock */
  724         error = insmntque(vp, ntmp->ntm_mountp);
  725         if (error) {
  726                 ntfs_frele(fp);
  727                 ntfs_ntput(ip);
  728                 return (error);
  729         }
  730         dprintf(("ntfs_vget: vnode: %p for ntnode: %d\n", vp,ino));
  731 
  732         fp->f_vp = vp;
  733         vp->v_data = fp;
  734         vp->v_type = f_type;
  735 
  736         vp->v_bufobj.bo_ops = &ntfs_vnbufops;
  737         vp->v_bufobj.bo_private = vp;
  738 
  739         if (ino == NTFS_ROOTINO)
  740                 vp->v_vflag |= VV_ROOT;
  741 
  742         ntfs_ntput(ip);
  743 
  744         if (lkflags & LK_TYPE_MASK) {
  745                 error = vn_lock(vp, lkflags, td);
  746                 if (error) {
  747                         vput(vp);
  748                         return (error);
  749                 }
  750         }
  751 
  752         *vpp = vp;
  753         return (0);
  754         
  755 }
  756 
  757 static int
  758 ntfs_vget(
  759         struct mount *mp,
  760         ino_t ino,
  761         int lkflags,
  762         struct vnode **vpp) 
  763 {
  764         return ntfs_vgetex(mp, ino, NTFS_A_DATA, NULL, lkflags, 0,
  765             curthread, vpp);
  766 }
  767 
  768 static void
  769 ntfs_bufstrategy(struct bufobj *bo, struct buf *bp)
  770 {
  771         struct vnode *vp;
  772         int rc;
  773 
  774         vp = bo->bo_private;
  775         KASSERT(bo == &vp->v_bufobj, ("BO/VP mismatch: vp %p bo %p != %p",
  776             vp, &vp->v_bufobj, bo));
  777         rc = VOP_STRATEGY(vp, bp);
  778         KASSERT(rc == 0, ("NTFS VOP_STRATEGY failed: bp=%p, "
  779                 "vp=%p, rc=%d", bp, vp, rc));
  780 }
  781 
  782 static struct vfsops ntfs_vfsops = {
  783         .vfs_fhtovp =   ntfs_fhtovp,
  784         .vfs_init =     ntfs_init,
  785         .vfs_cmount =   ntfs_cmount,
  786         .vfs_mount =    ntfs_mount,
  787         .vfs_root =     ntfs_root,
  788         .vfs_statfs =   ntfs_statfs,
  789         .vfs_uninit =   ntfs_uninit,
  790         .vfs_unmount =  ntfs_unmount,
  791         .vfs_vget =     ntfs_vget,
  792 };
  793 VFS_SET(ntfs_vfsops, ntfs, 0);
  794 MODULE_VERSION(ntfs, 1);

Cache object: 48faaf90e8f82f507ae83ca07a891f8e


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