kernel - VM PAGER part 2/2 - Expand vinitvmio() and vnode_pager_alloc()
[dragonfly.git] / sys / vfs / msdosfs / msdosfs_denode.c
blob74e0cc629c39e59007447c0fea39a4ee266b0be0
1 /* $FreeBSD: src/sys/msdosfs/msdosfs_denode.c,v 1.47.2.3 2002/08/22 16:20:15 trhodes Exp $ */
2 /* $DragonFly: src/sys/vfs/msdosfs/msdosfs_denode.c,v 1.35 2008/06/08 07:56:06 nth Exp $ */
3 /* $NetBSD: msdosfs_denode.c,v 1.28 1998/02/10 14:10:00 mrg Exp $ */
5 /*-
6 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
7 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
8 * All rights reserved.
9 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by TooLs GmbH.
22 * 4. The name of TooLs GmbH may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Written by Paul Popelka (paulp@uts.amdahl.com)
39 * You can do anything you want with this software, just don't say you wrote
40 * it, and don't remove this notice.
42 * This software is provided "as is".
44 * The author supplies this software to be publicly redistributed on the
45 * understanding that the author is not responsible for the correct
46 * functioning of this software in any circumstances and is not liable for
47 * any damages caused by this software.
49 * October 1992
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/kernel.h>
55 #include <sys/mount.h>
56 #include <sys/malloc.h>
57 #include <sys/proc.h>
58 #include <sys/buf.h>
59 #include <sys/vnode.h>
61 #include <vm/vm.h>
62 #include <vm/vm_extern.h>
64 #include "bpb.h"
65 #include "msdosfsmount.h"
66 #include "direntry.h"
67 #include "denode.h"
68 #include "fat.h"
70 static int msdosfs_hashins (struct denode *dep);
71 static void msdosfs_hashrem (struct denode *dep);
73 static MALLOC_DEFINE(M_MSDOSFSNODE, "MSDOSFS node", "MSDOSFS vnode private part");
76 * Hash table caching denode instances.
78 * denodes are keyed by the disk location (cluster num, entry offset) of the
79 * directory entry of the file they represent.
81 * denodes representing deleted but still opened files are left in this cache
82 * until reclaimed. Deleted directory entries can be reused when files are
83 * renamed or new files created. As a consequence, several denodes associated
84 * with the same entry may coexist in this cache as long as a single one of
85 * them map to an existing file (de_refcnt > 0).
87 * R/w access to this cache is protected by dehash_token.
89 static struct denode **dehashtbl;
90 static u_long dehash; /* size of hash table - 1 */
91 #define DEHASH(dev, dcl, doff) (dehashtbl[(minor(dev) + (dcl) + (doff) / \
92 sizeof(struct direntry)) & dehash])
93 static struct lwkt_token dehash_token;
95 union _qcvt {
96 quad_t qcvt;
97 long val[2];
99 #define SETHIGH(q, h) { \
100 union _qcvt tmp; \
101 tmp.qcvt = (q); \
102 tmp.val[_QUAD_HIGHWORD] = (h); \
103 (q) = tmp.qcvt; \
105 #define SETLOW(q, l) { \
106 union _qcvt tmp; \
107 tmp.qcvt = (q); \
108 tmp.val[_QUAD_LOWWORD] = (l); \
109 (q) = tmp.qcvt; \
112 static struct denode *
113 msdosfs_hashget (cdev_t dev, u_long dirclust, u_long diroff);
115 /*ARGSUSED*/
116 int
117 msdosfs_init(struct vfsconf *vfsp)
119 dehash = 16;
120 while (dehash < desiredvnodes)
121 dehash <<= 1;
122 dehashtbl = kmalloc(sizeof(void *) * dehash, M_MSDOSFSMNT,
123 M_WAITOK|M_ZERO);
124 --dehash;
125 lwkt_token_init(&dehash_token);
126 return (0);
129 int
130 msdosfs_uninit(struct vfsconf *vfsp)
133 if (dehashtbl)
134 kfree(dehashtbl, M_MSDOSFSMNT);
135 return (0);
138 static struct denode *
139 msdosfs_hashget(cdev_t dev, u_long dirclust, u_long diroff)
141 struct denode *dep;
142 lwkt_tokref ilock;
143 struct vnode *vp;
145 lwkt_gettoken(&ilock, &dehash_token);
146 loop:
147 for (dep = DEHASH(dev, dirclust, diroff); dep; dep = dep->de_next) {
148 if (dirclust != dep->de_dirclust
149 || diroff != dep->de_diroffset
150 || dev != dep->de_dev
151 || dep->de_refcnt <= 0) {
152 continue;
154 vp = DETOV(dep);
155 if (vget(vp, LK_EXCLUSIVE))
156 goto loop;
159 * We must check to see if the inode has been ripped
160 * out from under us after blocking.
162 for (dep = DEHASH(dev, dirclust, diroff); dep; dep = dep->de_next) {
163 if (dirclust == dep->de_dirclust
164 && diroff == dep->de_diroffset
165 && dev == dep->de_dev
166 && dep->de_refcnt > 0) {
167 break;
170 if (dep == NULL || DETOV(dep) != vp) {
171 vput(vp);
172 goto loop;
174 lwkt_reltoken(&ilock);
175 return (dep);
177 lwkt_reltoken(&ilock);
178 return (NULL);
182 * Try to insert specified denode into the hash table. Return 0 on success
183 * and EBUSY if there is already a denode with the same key.
185 static
187 msdosfs_hashins(struct denode *dep)
189 struct denode **depp, *deq;
190 lwkt_tokref ilock;
192 lwkt_gettoken(&ilock, &dehash_token);
193 depp = &DEHASH(dep->de_dev, dep->de_dirclust, dep->de_diroffset);
194 while ((deq = *depp) != NULL) {
195 if (deq->de_dev == dep->de_dev &&
196 deq->de_dirclust == dep->de_dirclust &&
197 deq->de_diroffset == dep->de_diroffset &&
198 deq->de_refcnt > 0) {
199 lwkt_reltoken(&ilock);
200 return(EBUSY);
202 depp = &deq->de_next;
204 dep->de_next = NULL;
205 *depp = dep;
206 lwkt_reltoken(&ilock);
207 return(0);
210 static
211 void
212 msdosfs_hashrem(struct denode *dep)
214 struct denode **depp, *deq;
215 lwkt_tokref ilock;
217 lwkt_gettoken(&ilock, &dehash_token);
218 depp = &DEHASH(dep->de_dev, dep->de_dirclust, dep->de_diroffset);
219 while ((deq = *depp) != NULL) {
220 if (dep == deq)
221 break;
222 depp = &deq->de_next;
224 KKASSERT(dep == deq);
225 *depp = dep->de_next;
226 dep->de_next = NULL;
227 lwkt_reltoken(&ilock);
230 void
231 msdosfs_reinsert(struct denode *ip, u_long new_dirclust, u_long new_diroffset)
233 lwkt_tokref ilock;
234 int error;
236 lwkt_gettoken(&ilock, &dehash_token);
237 msdosfs_hashrem(ip);
238 ip->de_dirclust = new_dirclust;
239 ip->de_diroffset = new_diroffset;
240 error = msdosfs_hashins(ip);
241 KASSERT(!error, ("msdosfs_reinsert: insertion failed %d", error));
242 lwkt_reltoken(&ilock);
246 * If deget() succeeds it returns with the gotten denode locked().
248 * pmp - address of msdosfsmount structure of the filesystem containing
249 * the denode of interest. The pm_dev field and the address of
250 * the msdosfsmount structure are used.
251 * dirclust - which cluster bp contains, if dirclust is 0 (root directory)
252 * diroffset is relative to the beginning of the root directory,
253 * otherwise it is cluster relative.
254 * diroffset - offset past begin of cluster of denode we want
255 * depp - returns the address of the gotten denode.
258 deget(struct msdosfsmount *pmp, /* so we know the maj/min number */
259 u_long dirclust, /* cluster this dir entry came from */
260 u_long diroffset, /* index of entry within the cluster */
261 struct denode **depp) /* returns the addr of the gotten denode */
263 int error;
264 cdev_t dev = pmp->pm_dev;
265 struct mount *mntp = pmp->pm_mountp;
266 struct direntry *direntptr;
267 struct denode *ldep;
268 struct vnode *nvp;
269 struct buf *bp;
270 struct timeval tv;
272 #ifdef MSDOSFS_DEBUG
273 kprintf("deget(pmp %p, dirclust %lu, diroffset %lx, depp %p)\n",
274 pmp, dirclust, diroffset, depp);
275 #endif
278 * On FAT32 filesystems, root is a (more or less) normal
279 * directory
281 if (FAT32(pmp) && dirclust == MSDOSFSROOT)
282 dirclust = pmp->pm_rootdirblk;
284 again:
286 * See if the denode is in the denode cache. Use the location of
287 * the directory entry to compute the hash value. For subdir use
288 * address of "." entry. For root dir (if not FAT32) use cluster
289 * MSDOSFSROOT, offset MSDOSFSROOT_OFS
291 * NOTE: The check for de_refcnt > 0 below insures the denode being
292 * examined does not represent an unlinked but still open file.
293 * These files are not to be accessible even when the directory
294 * entry that represented the file happens to be reused while the
295 * deleted file is still open.
297 ldep = msdosfs_hashget(dev, dirclust, diroffset);
298 if (ldep) {
299 *depp = ldep;
300 return (0);
304 * Do the MALLOC before the getnewvnode since doing so afterward
305 * might cause a bogus v_data pointer to get dereferenced
306 * elsewhere if MALLOC should block.
308 MALLOC(ldep, struct denode *, sizeof(struct denode), M_MSDOSFSNODE,
309 M_WAITOK | M_ZERO);
312 * Directory entry was not in cache, have to create a vnode and
313 * copy it from the passed disk buffer.
316 /* getnewvnode() does a vref() on the vnode */
317 error = getnewvnode(VT_MSDOSFS, mntp, &nvp, VLKTIMEOUT, 0);
318 if (error) {
319 *depp = NULL;
320 FREE(ldep, M_MSDOSFSNODE);
321 return error;
324 ldep->de_vnode = nvp;
325 ldep->de_flag = 0;
326 ldep->de_devvp = 0;
327 ldep->de_dev = dev;
328 ldep->de_dirclust = dirclust;
329 ldep->de_diroffset = diroffset;
330 fc_purge(ldep, 0); /* init the fat cache for this denode */
333 * Insert the denode into the hash queue. If a collision occurs
334 * throw away the vnode and try again.
336 error = msdosfs_hashins(ldep);
337 if (error == EBUSY) {
338 nvp->v_type = VBAD;
339 vx_put(nvp);
340 kfree(ldep, M_MSDOSFSNODE);
341 goto again;
342 } else if (error) {
343 nvp->v_type = VBAD;
344 vx_put(nvp);
345 kfree(ldep, M_MSDOSFSNODE);
346 *depp = NULL;
347 return (EINVAL);
349 nvp->v_data = ldep;
350 ldep->de_pmp = pmp;
351 ldep->de_refcnt = 1;
353 * Copy the directory entry into the denode area of the vnode.
355 if ((dirclust == MSDOSFSROOT
356 || (FAT32(pmp) && dirclust == pmp->pm_rootdirblk))
357 && diroffset == MSDOSFSROOT_OFS) {
359 * Directory entry for the root directory. There isn't one,
360 * so we manufacture one. We should probably rummage
361 * through the root directory and find a label entry (if it
362 * exists), and then use the time and date from that entry
363 * as the time and date for the root denode.
365 vsetflags(nvp, VROOT); /* should be further down XXX */
367 ldep->de_Attributes = ATTR_DIRECTORY;
368 ldep->de_LowerCase = 0;
369 if (FAT32(pmp))
370 ldep->de_StartCluster = pmp->pm_rootdirblk;
371 /* de_FileSize will be filled in further down */
372 else {
373 ldep->de_StartCluster = MSDOSFSROOT;
374 ldep->de_FileSize = pmp->pm_rootdirsize * DEV_BSIZE;
377 * fill in time and date so that dos2unixtime() doesn't
378 * spit up when called from msdosfs_getattr() with root
379 * denode
381 ldep->de_CHun = 0;
382 ldep->de_CTime = 0x0000; /* 00:00:00 */
383 ldep->de_CDate = (0 << DD_YEAR_SHIFT) | (1 << DD_MONTH_SHIFT)
384 | (1 << DD_DAY_SHIFT);
385 /* Jan 1, 1980 */
386 ldep->de_ADate = ldep->de_CDate;
387 ldep->de_MTime = ldep->de_CTime;
388 ldep->de_MDate = ldep->de_CDate;
389 /* leave the other fields as garbage */
390 } else {
391 error = readep(pmp, dirclust, diroffset, &bp, &direntptr);
392 if (error) {
394 * The denode does not contain anything useful, so
395 * it would be wrong to leave it on its hash chain.
396 * Arrange for vput() to just forget about it.
398 ldep->de_Name[0] = SLOT_DELETED;
399 nvp->v_type = VBAD;
401 vx_put(nvp);
402 *depp = NULL;
403 return (error);
405 DE_INTERNALIZE(ldep, direntptr);
406 brelse(bp);
410 * Fill in a few fields of the vnode and finish filling in the
411 * denode. Then return the address of the found denode.
413 if (ldep->de_Attributes & ATTR_DIRECTORY) {
415 * Since DOS directory entries that describe directories
416 * have 0 in the filesize field, we take this opportunity
417 * to find out the length of the directory and plug it into
418 * the denode structure.
420 u_long size;
423 * XXX Sometimes, these arrives that . entry have cluster
424 * number 0, when it shouldn't. Use real cluster number
425 * instead of what is written in directory entry.
427 if ((diroffset == 0) && (ldep->de_StartCluster != dirclust)) {
428 kprintf("deget(): . entry at clust %ld != %ld\n",
429 dirclust, ldep->de_StartCluster);
430 ldep->de_StartCluster = dirclust;
433 nvp->v_type = VDIR;
434 if (ldep->de_StartCluster != MSDOSFSROOT) {
435 error = pcbmap(ldep, 0xffff, NULL, &size, NULL);
436 if (error == E2BIG) {
437 ldep->de_FileSize = de_cn2off(pmp, size);
438 error = 0;
439 } else
440 kprintf("deget(): pcbmap returned %d\n", error);
442 } else {
443 nvp->v_type = VREG;
445 getmicrouptime(&tv);
446 SETHIGH(ldep->de_modrev, tv.tv_sec);
447 SETLOW(ldep->de_modrev, tv.tv_usec * 4294);
448 ldep->de_devvp = pmp->pm_devvp;
449 vref(ldep->de_devvp);
450 vinitvmio(nvp, ldep->de_FileSize, PAGE_SIZE, -1);
452 * Leave nvp locked and refd so the returned inode is effectively
453 * locked and refd.
455 *depp = ldep;
456 return (0);
460 deupdat(struct denode *dep, int waitfor)
462 int error;
463 struct buf *bp;
464 struct direntry *dirp;
465 struct timespec ts;
467 if (DETOV(dep)->v_mount->mnt_flag & MNT_RDONLY)
468 return (0);
469 getnanotime(&ts);
470 DETIMES(dep, &ts, &ts, &ts);
471 if ((dep->de_flag & DE_MODIFIED) == 0)
472 return (0);
473 dep->de_flag &= ~DE_MODIFIED;
474 if (dep->de_Attributes & ATTR_DIRECTORY)
475 return (0);
476 if (dep->de_refcnt <= 0)
477 return (0);
478 error = readde(dep, &bp, &dirp);
479 if (error)
480 return (error);
481 DE_EXTERNALIZE(dirp, dep);
482 if (waitfor)
483 return (bwrite(bp));
484 else {
485 bdwrite(bp);
486 return (0);
491 * Truncate the file described by dep to the length specified by length.
494 detrunc(struct denode *dep, u_long length, int flags)
496 int error;
497 int allerror;
498 u_long eofentry;
499 u_long chaintofree;
500 daddr_t bn, cn;
501 int boff;
502 int isadir = dep->de_Attributes & ATTR_DIRECTORY;
503 struct buf *bp;
504 struct msdosfsmount *pmp = dep->de_pmp;
506 #ifdef MSDOSFS_DEBUG
507 kprintf("detrunc(): file %s, length %lu, flags %x\n", dep->de_Name, length, flags);
508 #endif
511 * Disallow attempts to truncate the root directory since it is of
512 * fixed size. That's just the way dos filesystems are. We use
513 * the VROOT bit in the vnode because checking for the directory
514 * bit and a startcluster of 0 in the denode is not adequate to
515 * recognize the root directory at this point in a file or
516 * directory's life.
518 if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp)) {
519 kprintf("detrunc(): can't truncate root directory, clust %ld, offset %ld\n",
520 dep->de_dirclust, dep->de_diroffset);
521 return (EINVAL);
525 if (dep->de_FileSize < length) {
526 vnode_pager_setsize(DETOV(dep), length);
527 return deextend(dep, length);
531 * If the desired length is 0 then remember the starting cluster of
532 * the file and set the StartCluster field in the directory entry
533 * to 0. If the desired length is not zero, then get the number of
534 * the last cluster in the shortened file. Then get the number of
535 * the first cluster in the part of the file that is to be freed.
536 * Then set the next cluster pointer in the last cluster of the
537 * file to CLUST_EOFE.
539 if (length == 0) {
540 chaintofree = dep->de_StartCluster;
541 dep->de_StartCluster = 0;
542 eofentry = ~0;
543 } else {
544 error = pcbmap(dep, de_clcount(pmp, length) - 1,
545 NULL, &eofentry, NULL);
546 if (error) {
547 #ifdef MSDOSFS_DEBUG
548 kprintf("detrunc(): pcbmap fails %d\n", error);
549 #endif
550 return (error);
554 fc_purge(dep, de_clcount(pmp, length));
557 * If the new length is not a multiple of the cluster size then we
558 * must zero the tail end of the new last cluster in case it
559 * becomes part of the file again because of a seek.
561 if ((boff = length & pmp->pm_crbomask) != 0) {
562 if (isadir) {
563 bn = xcntobn(pmp, eofentry);
564 error = bread(pmp->pm_devvp, de_bntodoff(pmp, bn), pmp->pm_bpcluster, &bp);
565 } else {
566 cn = de_cluster(pmp, length);
567 error = bread(DETOV(dep), de_cn2doff(pmp, cn), pmp->pm_bpcluster, &bp);
569 if (error) {
570 brelse(bp);
571 #ifdef MSDOSFS_DEBUG
572 kprintf("detrunc(): bread fails %d\n", error);
573 #endif
574 return (error);
577 * is this the right place for it?
579 bzero(bp->b_data + boff, pmp->pm_bpcluster - boff);
580 if (flags & IO_SYNC)
581 bwrite(bp);
582 else
583 bdwrite(bp);
587 * Write out the updated directory entry. Even if the update fails
588 * we free the trailing clusters.
590 dep->de_FileSize = length;
591 if (!isadir)
592 dep->de_flag |= DE_UPDATE|DE_MODIFIED;
593 allerror = vtruncbuf(DETOV(dep), length, pmp->pm_bpcluster);
594 #ifdef MSDOSFS_DEBUG
595 if (allerror)
596 kprintf("detrunc(): vtruncbuf error %d\n", allerror);
597 #endif
598 error = deupdat(dep, 1);
599 if (error && (allerror == 0))
600 allerror = error;
601 #ifdef MSDOSFS_DEBUG
602 kprintf("detrunc(): allerror %d, eofentry %lu\n",
603 allerror, eofentry);
604 #endif
607 * If we need to break the cluster chain for the file then do it
608 * now.
610 if (eofentry != ~0) {
611 error = fatentry(FAT_GET_AND_SET, pmp, eofentry,
612 &chaintofree, CLUST_EOFE);
613 if (error) {
614 #ifdef MSDOSFS_DEBUG
615 kprintf("detrunc(): fatentry errors %d\n", error);
616 #endif
617 return (error);
619 fc_setcache(dep, FC_LASTFC, de_cluster(pmp, length - 1),
620 eofentry);
624 * Now free the clusters removed from the file because of the
625 * truncation.
627 if (chaintofree != 0 && !MSDOSFSEOF(pmp, chaintofree))
628 freeclusterchain(pmp, chaintofree);
630 return (allerror);
634 * Extend the file described by dep to length specified by length.
637 deextend(struct denode *dep, u_long length)
639 struct msdosfsmount *pmp = dep->de_pmp;
640 u_long count;
641 int error;
644 * The root of a DOS filesystem cannot be extended.
646 if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp))
647 return (EINVAL);
650 * Directories cannot be extended.
652 if (dep->de_Attributes & ATTR_DIRECTORY)
653 return (EISDIR);
655 if (length <= dep->de_FileSize)
656 panic("deextend: file too large");
659 * Compute the number of clusters to allocate.
661 count = de_clcount(pmp, length) - de_clcount(pmp, dep->de_FileSize);
662 if (count > 0) {
663 if (count > pmp->pm_freeclustercount)
664 return (ENOSPC);
665 error = extendfile(dep, count, NULL, NULL, DE_CLEAR);
666 if (error) {
667 /* truncate the added clusters away again */
668 detrunc(dep, dep->de_FileSize, 0);
669 return (error);
672 dep->de_FileSize = length;
673 dep->de_flag |= DE_UPDATE|DE_MODIFIED;
674 return (deupdat(dep, 1));
678 * msdosfs_reclaim(struct vnode *a_vp)
681 msdosfs_reclaim(struct vop_reclaim_args *ap)
683 struct vnode *vp = ap->a_vp;
684 struct denode *dep = VTODE(vp);
686 #ifdef MSDOSFS_DEBUG
687 kprintf("msdosfs_reclaim(): dep %p, file %s, refcnt %ld\n",
688 dep, dep ? (char *)dep->de_Name : "?", dep ? dep->de_refcnt : -1);
689 #endif
691 if (prtactive && vp->v_sysref.refcnt > 1)
692 vprint("msdosfs_reclaim(): pushing active", vp);
694 * Remove the denode from its hash chain.
696 vp->v_data = NULL;
697 if (dep) {
698 msdosfs_hashrem(dep);
699 if (dep->de_devvp) {
700 vrele(dep->de_devvp);
701 dep->de_devvp = 0;
703 kfree(dep, M_MSDOSFSNODE);
705 return (0);
709 * msdosfs_inactive(struct vnode *a_vp)
712 msdosfs_inactive(struct vop_inactive_args *ap)
714 struct vnode *vp = ap->a_vp;
715 struct denode *dep = VTODE(vp);
716 int error = 0;
718 #ifdef MSDOSFS_DEBUG
719 kprintf("msdosfs_inactive(): dep %p, de_Name[0] %x\n",
720 dep, (dep ? dep->de_Name[0] : 0));
721 #endif
723 if (prtactive && vp->v_sysref.refcnt > 1)
724 vprint("msdosfs_inactive(): pushing active", vp);
727 * Ignore denodes related to stale file handles.
729 if (dep == NULL || dep->de_Name[0] == SLOT_DELETED)
730 goto out;
733 * If the file has been deleted and it is on a read/write
734 * filesystem, then truncate the file, and mark the directory slot
735 * as empty. (This may not be necessary for the dos filesystem.)
737 #ifdef MSDOSFS_DEBUG
738 kprintf("msdosfs_inactive(): dep %p, refcnt %ld, mntflag %x, MNT_RDONLY %x\n",
739 dep, dep->de_refcnt, vp->v_mount->mnt_flag, MNT_RDONLY);
740 #endif
741 if (dep->de_refcnt <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
742 error = detrunc(dep, (u_long) 0, 0);
743 dep->de_flag |= DE_UPDATE;
744 dep->de_Name[0] = SLOT_DELETED;
746 deupdat(dep, 0);
748 out:
750 * If we are done with the denode, reclaim it
751 * so that it can be reused immediately.
753 #ifdef MSDOSFS_DEBUG
754 kprintf("msdosfs_inactive(): v_sysrefs %d, de_Name[0] %x\n",
755 vp->v_sysref.refcnt, (dep ? dep->de_Name[0] : 0));
756 #endif
757 if (dep == NULL || dep->de_Name[0] == SLOT_DELETED)
758 vrecycle(vp);
759 return (error);