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