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/msdosfs/msdosfs_denode.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: msdosfs_denode.c,v 1.17.2.1 2007/09/29 11:33:35 xtraeme Exp $  */
    2 
    3 /*-
    4  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
    5  * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
    6  * All rights reserved.
    7  * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 3. All advertising materials mentioning features or use of this software
   18  *    must display the following acknowledgement:
   19  *      This product includes software developed by TooLs GmbH.
   20  * 4. The name of TooLs GmbH may not be used to endorse or promote products
   21  *    derived from this software without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
   24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   26  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
   29  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   31  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   32  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   33  */
   34 /*
   35  * Written by Paul Popelka (paulp@uts.amdahl.com)
   36  *
   37  * You can do anything you want with this software, just don't say you wrote
   38  * it, and don't remove this notice.
   39  *
   40  * This software is provided "as is".
   41  *
   42  * The author supplies this software to be publicly redistributed on the
   43  * understanding that the author is not responsible for the correct
   44  * functioning of this software in any circumstances and is not liable for
   45  * any damages caused by this software.
   46  *
   47  * October 1992
   48  */
   49 
   50 #include <sys/cdefs.h>
   51 __KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.17.2.1 2007/09/29 11:33:35 xtraeme Exp $");
   52 
   53 #include <sys/param.h>
   54 #include <sys/systm.h>
   55 #include <sys/mount.h>
   56 #include <sys/malloc.h>
   57 #include <sys/pool.h>
   58 #include <sys/proc.h>
   59 #include <sys/buf.h>
   60 #include <sys/vnode.h>
   61 #include <sys/kernel.h>         /* defines "time" */
   62 #include <sys/dirent.h>
   63 #include <sys/namei.h>
   64 #include <sys/kauth.h>
   65 
   66 #include <uvm/uvm_extern.h>
   67 
   68 #include <fs/msdosfs/bpb.h>
   69 #include <fs/msdosfs/msdosfsmount.h>
   70 #include <fs/msdosfs/direntry.h>
   71 #include <fs/msdosfs/denode.h>
   72 #include <fs/msdosfs/fat.h>
   73 
   74 LIST_HEAD(ihashhead, denode) *dehashtbl;
   75 u_long dehash;                  /* size of hash table - 1 */
   76 #define DEHASH(dev, dcl, doff) \
   77     (((dev) + (dcl) + (doff) / sizeof(struct direntry)) & dehash)
   78 
   79 struct simplelock msdosfs_ihash_slock;
   80 
   81 POOL_INIT(msdosfs_denode_pool, sizeof(struct denode), 0, 0, 0, "msdosnopl",
   82     &pool_allocator_nointr);
   83 
   84 extern int prtactive;
   85 
   86 static const struct genfs_ops msdosfs_genfsops = {
   87         .gop_size = genfs_size,
   88         .gop_alloc = msdosfs_gop_alloc,
   89         .gop_write = genfs_gop_write,
   90         .gop_markupdate = msdosfs_gop_markupdate,
   91 };
   92 
   93 static struct denode *msdosfs_hashget(dev_t, u_long, u_long);
   94 static void msdosfs_hashins(struct denode *);
   95 static void msdosfs_hashrem(struct denode *);
   96 
   97 #ifdef _LKM
   98 MALLOC_DECLARE(M_MSDOSFSFAT);
   99 #endif
  100 
  101 void
  102 msdosfs_init()
  103 {
  104 #ifdef _LKM
  105         malloc_type_attach(M_MSDOSFSMNT);
  106         malloc_type_attach(M_MSDOSFSFAT);
  107         pool_init(&msdosfs_denode_pool, sizeof(struct denode), 0, 0, 0,
  108             "msdosnopl", &pool_allocator_nointr);
  109 #endif
  110         dehashtbl = hashinit(desiredvnodes / 2, HASH_LIST, M_MSDOSFSMNT,
  111             M_WAITOK, &dehash);
  112         simple_lock_init(&msdosfs_ihash_slock);
  113 }
  114 
  115 /*
  116  * Reinitialize inode hash table.
  117  */
  118 
  119 void
  120 msdosfs_reinit()
  121 {
  122         struct denode *dep;
  123         struct ihashhead *oldhash, *hash;
  124         u_long oldmask, mask, val;
  125         int i;
  126 
  127         hash = hashinit(desiredvnodes / 2, HASH_LIST, M_MSDOSFSMNT, M_WAITOK,
  128             &mask);
  129 
  130         simple_lock(&msdosfs_ihash_slock);
  131         oldhash = dehashtbl;
  132         oldmask = dehash;
  133         dehashtbl = hash;
  134         dehash = mask;
  135         for (i = 0; i <= oldmask; i++) {
  136                 while ((dep = LIST_FIRST(&oldhash[i])) != NULL) {
  137                         LIST_REMOVE(dep, de_hash);
  138                         val = DEHASH(dep->de_dev, dep->de_dirclust,
  139                             dep->de_diroffset);
  140                         LIST_INSERT_HEAD(&hash[val], dep, de_hash);
  141                 }
  142         }
  143         simple_unlock(&msdosfs_ihash_slock);
  144         hashdone(oldhash, M_MSDOSFSMNT);
  145 }
  146 
  147 void
  148 msdosfs_done()
  149 {
  150         hashdone(dehashtbl, M_MSDOSFSMNT);
  151 #ifdef _LKM
  152         pool_destroy(&msdosfs_denode_pool);
  153         malloc_type_detach(M_MSDOSFSFAT);
  154         malloc_type_detach(M_MSDOSFSMNT);
  155 #endif
  156 }
  157 
  158 static struct denode *
  159 msdosfs_hashget(dev, dirclust, diroff)
  160         dev_t dev;
  161         u_long dirclust;
  162         u_long diroff;
  163 {
  164         struct denode *dep;
  165         struct vnode *vp;
  166 
  167 loop:
  168         simple_lock(&msdosfs_ihash_slock);
  169         LIST_FOREACH(dep, &dehashtbl[DEHASH(dev, dirclust, diroff)], de_hash) {
  170                 if (dirclust == dep->de_dirclust &&
  171                     diroff == dep->de_diroffset &&
  172                     dev == dep->de_dev &&
  173                     dep->de_refcnt != 0) {
  174                         vp = DETOV(dep);
  175                         simple_lock(&vp->v_interlock);
  176                         simple_unlock(&msdosfs_ihash_slock);
  177                         if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK))
  178                                 goto loop;
  179                         return (dep);
  180                 }
  181         }
  182         simple_unlock(&msdosfs_ihash_slock);
  183         return (NULL);
  184 }
  185 
  186 static void
  187 msdosfs_hashins(dep)
  188         struct denode *dep;
  189 {
  190         struct ihashhead *depp;
  191         int val;
  192 
  193         simple_lock(&msdosfs_ihash_slock);
  194         val = DEHASH(dep->de_dev, dep->de_dirclust, dep->de_diroffset);
  195         depp = &dehashtbl[val];
  196         LIST_INSERT_HEAD(depp, dep, de_hash);
  197         simple_unlock(&msdosfs_ihash_slock);
  198 }
  199 
  200 static void
  201 msdosfs_hashrem(dep)
  202         struct denode *dep;
  203 {
  204         simple_lock(&msdosfs_ihash_slock);
  205         LIST_REMOVE(dep, de_hash);
  206         simple_unlock(&msdosfs_ihash_slock);
  207 }
  208 
  209 /*
  210  * If deget() succeeds it returns with the gotten denode locked().
  211  *
  212  * pmp       - address of msdosfsmount structure of the filesystem containing
  213  *             the denode of interest.  The pm_dev field and the address of
  214  *             the msdosfsmount structure are used.
  215  * dirclust  - which cluster bp contains, if dirclust is 0 (root directory)
  216  *             diroffset is relative to the beginning of the root directory,
  217  *             otherwise it is cluster relative.
  218  * diroffset - offset past begin of cluster of denode we want
  219  * depp      - returns the address of the gotten denode.
  220  */
  221 int
  222 deget(pmp, dirclust, diroffset, depp)
  223         struct msdosfsmount *pmp;       /* so we know the maj/min number */
  224         u_long dirclust;                /* cluster this dir entry came from */
  225         u_long diroffset;               /* index of entry within the cluster */
  226         struct denode **depp;           /* returns the addr of the gotten denode */
  227 {
  228         int error;
  229         extern int (**msdosfs_vnodeop_p)(void *);
  230         struct direntry *direntptr;
  231         struct denode *ldep;
  232         struct vnode *nvp;
  233         struct buf *bp;
  234 
  235 #ifdef MSDOSFS_DEBUG
  236         printf("deget(pmp %p, dirclust %lu, diroffset %lx, depp %p)\n",
  237             pmp, dirclust, diroffset, depp);
  238 #endif
  239 
  240         /*
  241          * On FAT32 filesystems, root is a (more or less) normal
  242          * directory
  243          */
  244         if (FAT32(pmp) && dirclust == MSDOSFSROOT)
  245                 dirclust = pmp->pm_rootdirblk;
  246 
  247         /*
  248          * See if the denode is in the denode cache. Use the location of
  249          * the directory entry to compute the hash value. For subdir use
  250          * address of "." entry. For root dir (if not FAT32) use cluster
  251          * MSDOSFSROOT, offset MSDOSFSROOT_OFS
  252          *
  253          * NOTE: The check for de_refcnt > 0 below insures the denode being
  254          * examined does not represent an unlinked but still open file.
  255          * These files are not to be accessible even when the directory
  256          * entry that represented the file happens to be reused while the
  257          * deleted file is still open.
  258          */
  259         ldep = msdosfs_hashget(pmp->pm_dev, dirclust, diroffset);
  260         if (ldep) {
  261                 *depp = ldep;
  262                 return (0);
  263         }
  264 
  265         /*
  266          * Directory entry was not in cache, have to create a vnode and
  267          * copy it from the passed disk buffer.
  268          */
  269         /* getnewvnode() does a VREF() on the vnode */
  270         error = getnewvnode(VT_MSDOSFS, pmp->pm_mountp,
  271                             msdosfs_vnodeop_p, &nvp);
  272         if (error) {
  273                 *depp = 0;
  274                 return (error);
  275         }
  276         ldep = pool_get(&msdosfs_denode_pool, PR_WAITOK);
  277         memset(ldep, 0, sizeof *ldep);
  278         nvp->v_data = ldep;
  279         ldep->de_vnode = nvp;
  280         ldep->de_flag = 0;
  281         ldep->de_devvp = 0;
  282         ldep->de_lockf = 0;
  283         ldep->de_dev = pmp->pm_dev;
  284         ldep->de_dirclust = dirclust;
  285         ldep->de_diroffset = diroffset;
  286         fc_purge(ldep, 0);      /* init the fat cache for this denode */
  287 
  288         /*
  289          * Insert the denode into the hash queue and lock the denode so it
  290          * can't be accessed until we've read it in and have done what we
  291          * need to it.
  292          */
  293         vn_lock(nvp, LK_EXCLUSIVE | LK_RETRY);
  294         genfs_node_init(nvp, &msdosfs_genfsops);
  295         msdosfs_hashins(ldep);
  296 
  297         ldep->de_pmp = pmp;
  298         ldep->de_devvp = pmp->pm_devvp;
  299         ldep->de_refcnt = 1;
  300         /*
  301          * Copy the directory entry into the denode area of the vnode.
  302          */
  303         if ((dirclust == MSDOSFSROOT
  304              || (FAT32(pmp) && dirclust == pmp->pm_rootdirblk))
  305             && diroffset == MSDOSFSROOT_OFS) {
  306                 /*
  307                  * Directory entry for the root directory. There isn't one,
  308                  * so we manufacture one. We should probably rummage
  309                  * through the root directory and find a label entry (if it
  310                  * exists), and then use the time and date from that entry
  311                  * as the time and date for the root denode.
  312                  */
  313                 nvp->v_flag |= VROOT; /* should be further down         XXX */
  314 
  315                 ldep->de_Attributes = ATTR_DIRECTORY;
  316                 if (FAT32(pmp))
  317                         ldep->de_StartCluster = pmp->pm_rootdirblk;
  318                         /* de_FileSize will be filled in further down */
  319                 else {
  320                         ldep->de_StartCluster = MSDOSFSROOT;
  321                         ldep->de_FileSize = pmp->pm_rootdirsize * pmp->pm_BytesPerSec;
  322                 }
  323                 /*
  324                  * fill in time and date so that dos2unixtime() doesn't
  325                  * spit up when called from msdosfs_getattr() with root
  326                  * denode
  327                  */
  328                 ldep->de_CHun = 0;
  329                 ldep->de_CTime = 0x0000;        /* 00:00:00      */
  330                 ldep->de_CDate = (0 << DD_YEAR_SHIFT) | (1 << DD_MONTH_SHIFT)
  331                     | (1 << DD_DAY_SHIFT);
  332                 /* Jan 1, 1980   */
  333                 ldep->de_ADate = ldep->de_CDate;
  334                 ldep->de_MTime = ldep->de_CTime;
  335                 ldep->de_MDate = ldep->de_CDate;
  336                 /* leave the other fields as garbage */
  337         } else {
  338                 error = readep(pmp, dirclust, diroffset, &bp, &direntptr);
  339                 if (error) {
  340                         ldep->de_devvp = NULL;
  341                         ldep->de_Name[0] = SLOT_DELETED;
  342                         vput(nvp);
  343                         return (error);
  344                 }
  345                 DE_INTERNALIZE(ldep, direntptr);
  346                 brelse(bp);
  347         }
  348 
  349         /*
  350          * Fill in a few fields of the vnode and finish filling in the
  351          * denode.  Then return the address of the found denode.
  352          */
  353         if (ldep->de_Attributes & ATTR_DIRECTORY) {
  354                 /*
  355                  * Since DOS directory entries that describe directories
  356                  * have 0 in the filesize field, we take this opportunity
  357                  * to find out the length of the directory and plug it into
  358                  * the denode structure.
  359                  */
  360                 u_long size;
  361 
  362                 nvp->v_type = VDIR;
  363                 if (ldep->de_StartCluster != MSDOSFSROOT) {
  364                         error = pcbmap(ldep, CLUST_END, 0, &size, 0);
  365                         if (error == E2BIG) {
  366                                 ldep->de_FileSize = de_cn2off(pmp, size);
  367                                 error = 0;
  368                         } else
  369                                 printf("deget(): pcbmap returned %d\n", error);
  370                 }
  371         } else
  372                 nvp->v_type = VREG;
  373         VREF(ldep->de_devvp);
  374         *depp = ldep;
  375         nvp->v_size = ldep->de_FileSize;
  376         return (0);
  377 }
  378 
  379 int
  380 deupdat(dep, waitfor)
  381         struct denode *dep;
  382         int waitfor;
  383 {
  384 
  385         return (msdosfs_update(DETOV(dep), NULL, NULL,
  386             waitfor ? UPDATE_WAIT : 0));
  387 }
  388 
  389 /*
  390  * Truncate the file described by dep to the length specified by length.
  391  */
  392 int
  393 detrunc(struct denode *dep, u_long length, int flags, kauth_cred_t cred,
  394     struct lwp *l)
  395 {
  396         int error;
  397         int allerror;
  398         u_long eofentry;
  399         u_long chaintofree = 0;
  400         daddr_t bn, lastblock;
  401         int boff;
  402         int isadir = dep->de_Attributes & ATTR_DIRECTORY;
  403         struct buf *bp;
  404         struct msdosfsmount *pmp = dep->de_pmp;
  405 
  406 #ifdef MSDOSFS_DEBUG
  407         printf("detrunc(): file %s, length %lu, flags %x\n", dep->de_Name, length, flags);
  408 #endif
  409 
  410         /*
  411          * Disallow attempts to truncate the root directory since it is of
  412          * fixed size.  That's just the way dos filesystems are.  We use
  413          * the VROOT bit in the vnode because checking for the directory
  414          * bit and a startcluster of 0 in the denode is not adequate to
  415          * recognize the root directory at this point in a file or
  416          * directory's life.
  417          */
  418         if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp)) {
  419                 printf("detrunc(): can't truncate root directory, clust %ld, offset %ld\n",
  420                     dep->de_dirclust, dep->de_diroffset);
  421                 return (EINVAL);
  422         }
  423 
  424         uvm_vnp_setsize(DETOV(dep), length);
  425 
  426         if (dep->de_FileSize < length)
  427                 return (deextend(dep, length, cred));
  428         lastblock = de_clcount(pmp, length) - 1;
  429 
  430         /*
  431          * If the desired length is 0 then remember the starting cluster of
  432          * the file and set the StartCluster field in the directory entry
  433          * to 0.  If the desired length is not zero, then get the number of
  434          * the last cluster in the shortened file.  Then get the number of
  435          * the first cluster in the part of the file that is to be freed.
  436          * Then set the next cluster pointer in the last cluster of the
  437          * file to CLUST_EOFE.
  438          */
  439         if (length == 0) {
  440                 chaintofree = dep->de_StartCluster;
  441                 dep->de_StartCluster = 0;
  442                 eofentry = ~0;
  443         } else {
  444                 error = pcbmap(dep, lastblock, 0, &eofentry, 0);
  445                 if (error) {
  446 #ifdef MSDOSFS_DEBUG
  447                         printf("detrunc(): pcbmap fails %d\n", error);
  448 #endif
  449                         return (error);
  450                 }
  451         }
  452 
  453         fc_purge(dep, lastblock + 1);
  454 
  455         /*
  456          * If the new length is not a multiple of the cluster size then we
  457          * must zero the tail end of the new last cluster in case it
  458          * becomes part of the file again because of a seek.
  459          */
  460         if ((boff = length & pmp->pm_crbomask) != 0) {
  461                 if (isadir) {
  462                         bn = cntobn(pmp, eofentry);
  463                         error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn),
  464                             pmp->pm_bpcluster, NOCRED, &bp);
  465                         if (error) {
  466                                 brelse(bp);
  467 #ifdef MSDOSFS_DEBUG
  468                                 printf("detrunc(): bread fails %d\n", error);
  469 #endif
  470                                 return (error);
  471                         }
  472                         memset(bp->b_data + boff, 0, pmp->pm_bpcluster - boff);
  473                         if (flags & IO_SYNC)
  474                                 bwrite(bp);
  475                         else
  476                                 bdwrite(bp);
  477                 } else {
  478                         uvm_vnp_zerorange(DETOV(dep), length,
  479                                           pmp->pm_bpcluster - boff);
  480                 }
  481         }
  482 
  483         /*
  484          * Write out the updated directory entry.  Even if the update fails
  485          * we free the trailing clusters.
  486          */
  487         dep->de_FileSize = length;
  488         if (!isadir)
  489                 dep->de_flag |= DE_UPDATE|DE_MODIFIED;
  490         vtruncbuf(DETOV(dep), lastblock + 1, 0, 0);
  491         allerror = deupdat(dep, 1);
  492 #ifdef MSDOSFS_DEBUG
  493         printf("detrunc(): allerror %d, eofentry %lu\n",
  494                allerror, eofentry);
  495 #endif
  496 
  497         /*
  498          * If we need to break the cluster chain for the file then do it
  499          * now.
  500          */
  501         if (eofentry != ~0) {
  502                 error = fatentry(FAT_GET_AND_SET, pmp, eofentry,
  503                                  &chaintofree, CLUST_EOFE);
  504                 if (error) {
  505 #ifdef MSDOSFS_DEBUG
  506                         printf("detrunc(): fatentry errors %d\n", error);
  507 #endif
  508                         return (error);
  509                 }
  510                 fc_setcache(dep, FC_LASTFC, de_cluster(pmp, length - 1),
  511                             eofentry);
  512         }
  513 
  514         /*
  515          * Now free the clusters removed from the file because of the
  516          * truncation.
  517          */
  518         if (chaintofree != 0 && !MSDOSFSEOF(chaintofree, pmp->pm_fatmask))
  519                 freeclusterchain(pmp, chaintofree);
  520 
  521         return (allerror);
  522 }
  523 
  524 /*
  525  * Extend the file described by dep to length specified by length.
  526  */
  527 int
  528 deextend(dep, length, cred)
  529         struct denode *dep;
  530         u_long length;
  531         kauth_cred_t cred;
  532 {
  533         struct msdosfsmount *pmp = dep->de_pmp;
  534         u_long count, osize;
  535         int error;
  536 
  537         /*
  538          * The root of a DOS filesystem cannot be extended.
  539          */
  540         if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp))
  541                 return (EINVAL);
  542 
  543         /*
  544          * Directories cannot be extended.
  545          */
  546         if (dep->de_Attributes & ATTR_DIRECTORY)
  547                 return (EISDIR);
  548 
  549         if (length <= dep->de_FileSize)
  550                 panic("deextend: file too large");
  551 
  552         /*
  553          * Compute the number of clusters to allocate.
  554          */
  555         count = de_clcount(pmp, length) - de_clcount(pmp, dep->de_FileSize);
  556         if (count > 0) {
  557                 if (count > pmp->pm_freeclustercount)
  558                         return (ENOSPC);
  559                 error = extendfile(dep, count, NULL, NULL, DE_CLEAR);
  560                 if (error) {
  561                         /* truncate the added clusters away again */
  562                         (void) detrunc(dep, dep->de_FileSize, 0, cred, NULL);
  563                         return (error);
  564                 }
  565         }
  566 
  567         osize = dep->de_FileSize;
  568         dep->de_FileSize = length;
  569         uvm_vnp_setsize(DETOV(dep), (voff_t)dep->de_FileSize);
  570         dep->de_flag |= DE_UPDATE|DE_MODIFIED;
  571         uvm_vnp_zerorange(DETOV(dep), (off_t)osize,
  572             (size_t)(dep->de_FileSize - osize));
  573         return (deupdat(dep, 1));
  574 }
  575 
  576 /*
  577  * Move a denode to its correct hash queue after the file it represents has
  578  * been moved to a new directory.
  579  */
  580 void
  581 reinsert(dep)
  582         struct denode *dep;
  583 {
  584         /*
  585          * Fix up the denode cache.  If the denode is for a directory,
  586          * there is nothing to do since the hash is based on the starting
  587          * cluster of the directory file and that hasn't changed.  If for a
  588          * file the hash is based on the location of the directory entry,
  589          * so we must remove it from the cache and re-enter it with the
  590          * hash based on the new location of the directory entry.
  591          */
  592         if (dep->de_Attributes & ATTR_DIRECTORY)
  593                 return;
  594         msdosfs_hashrem(dep);
  595         msdosfs_hashins(dep);
  596 }
  597 
  598 int
  599 msdosfs_reclaim(v)
  600         void *v;
  601 {
  602         struct vop_reclaim_args /* {
  603                 struct vnode *a_vp;
  604         } */ *ap = v;
  605         struct vnode *vp = ap->a_vp;
  606         struct denode *dep = VTODE(vp);
  607 
  608 #ifdef MSDOSFS_DEBUG
  609         printf("msdosfs_reclaim(): dep %p, file %s, refcnt %ld\n",
  610             dep, dep->de_Name, dep->de_refcnt);
  611 #endif
  612 
  613         if (prtactive && vp->v_usecount != 0)
  614                 vprint("msdosfs_reclaim(): pushing active", vp);
  615         /*
  616          * Remove the denode from its hash chain.
  617          */
  618         msdosfs_hashrem(dep);
  619         /*
  620          * Purge old data structures associated with the denode.
  621          */
  622         cache_purge(vp);
  623         if (dep->de_devvp) {
  624                 vrele(dep->de_devvp);
  625                 dep->de_devvp = 0;
  626         }
  627 #if 0 /* XXX */
  628         dep->de_flag = 0;
  629 #endif
  630         pool_put(&msdosfs_denode_pool, dep);
  631         vp->v_data = NULL;
  632         return (0);
  633 }
  634 
  635 int
  636 msdosfs_inactive(v)
  637         void *v;
  638 {
  639         struct vop_inactive_args /* {
  640                 struct vnode *a_vp;
  641                 struct lwp *a_l;
  642         } */ *ap = v;
  643         struct lwp *l = ap->a_l;
  644         struct vnode *vp = ap->a_vp;
  645         struct denode *dep = VTODE(vp);
  646         int error = 0;
  647 
  648 #ifdef MSDOSFS_DEBUG
  649         printf("msdosfs_inactive(): dep %p, de_Name[0] %x\n", dep, dep->de_Name[0]);
  650 #endif
  651 
  652         if (prtactive && vp->v_usecount != 0)
  653                 vprint("msdosfs_inactive(): pushing active", vp);
  654 
  655         /*
  656          * Get rid of denodes related to stale file handles.
  657          */
  658         if (dep->de_Name[0] == SLOT_DELETED)
  659                 goto out;
  660 
  661         /*
  662          * If the file has been deleted and it is on a read/write
  663          * filesystem, then truncate the file, and mark the directory slot
  664          * as empty.  (This may not be necessary for the dos filesystem.)
  665          */
  666 #ifdef MSDOSFS_DEBUG
  667         printf("msdosfs_inactive(): dep %p, refcnt %ld, mntflag %x %s\n",
  668                dep, dep->de_refcnt, vp->v_mount->mnt_flag,
  669                 (vp->v_mount->mnt_flag & MNT_RDONLY) ? "MNT_RDONLY" : "");
  670 #endif
  671         if (dep->de_refcnt <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
  672                 if (dep->de_FileSize != 0) {
  673                         error = detrunc(dep, (u_long)0, 0, NOCRED, NULL);
  674                 }
  675                 dep->de_Name[0] = SLOT_DELETED;
  676         }
  677         deupdat(dep, 0);
  678 out:
  679         VOP_UNLOCK(vp, 0);
  680         /*
  681          * If we are done with the denode, reclaim it
  682          * so that it can be reused immediately.
  683          */
  684 #ifdef MSDOSFS_DEBUG
  685         printf("msdosfs_inactive(): v_usecount %d, de_Name[0] %x\n",
  686                 vp->v_usecount, dep->de_Name[0]);
  687 #endif
  688         if (dep->de_Name[0] == SLOT_DELETED)
  689                 vrecycle(vp, (struct simplelock *)0, l);
  690         return (error);
  691 }
  692 
  693 int
  694 msdosfs_gop_alloc(struct vnode *vp, off_t off,
  695     off_t len, int flags, kauth_cred_t cred)
  696 {
  697         return 0;
  698 }
  699 
  700 void
  701 msdosfs_gop_markupdate(struct vnode *vp, int flags)
  702 {
  703         u_long mask = 0;
  704 
  705         if ((flags & GOP_UPDATE_ACCESSED) != 0) {
  706                 mask = DE_ACCESS;
  707         }
  708         if ((flags & GOP_UPDATE_MODIFIED) != 0) {
  709                 mask |= DE_UPDATE;
  710         }
  711         if (mask) {
  712                 struct denode *dep = VTODE(vp);
  713 
  714                 dep->de_flag |= mask;
  715         }
  716 }

Cache object: b7c985a189602642f8d2f98756b34b05


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