xref: /netbsd-src/sys/fs/msdosfs/msdosfs_denode.c (revision 001c68bd94f75ce9270b69227c4199fbf34ee396)
1 /*	$NetBSD: msdosfs_denode.c,v 1.4 2003/06/29 22:31:09 fvdl 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.4 2003/06/29 22:31:09 fvdl 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 
65 #include <uvm/uvm_extern.h>
66 
67 #include <fs/msdosfs/bpb.h>
68 #include <fs/msdosfs/msdosfsmount.h>
69 #include <fs/msdosfs/direntry.h>
70 #include <fs/msdosfs/denode.h>
71 #include <fs/msdosfs/fat.h>
72 
73 LIST_HEAD(ihashhead, denode) *dehashtbl;
74 u_long dehash;			/* size of hash table - 1 */
75 #define	DEHASH(dev, dcl, doff) \
76     (((dev) + (dcl) + (doff) / sizeof(struct direntry)) & dehash)
77 
78 struct simplelock msdosfs_ihash_slock;
79 
80 struct pool msdosfs_denode_pool;
81 
82 extern int prtactive;
83 
84 struct genfs_ops msdosfs_genfsops = {
85 	genfs_size,
86 	msdosfs_gop_alloc,
87 	genfs_gop_write,
88 };
89 
90 static struct denode *msdosfs_hashget __P((dev_t, u_long, u_long));
91 static void msdosfs_hashins __P((struct denode *));
92 static void msdosfs_hashrem __P((struct denode *));
93 
94 void
95 msdosfs_init()
96 {
97 	dehashtbl = hashinit(desiredvnodes / 2, HASH_LIST, M_MSDOSFSMNT,
98 	    M_WAITOK, &dehash);
99 	simple_lock_init(&msdosfs_ihash_slock);
100 	pool_init(&msdosfs_denode_pool, sizeof(struct denode), 0, 0, 0,
101 	    "msdosnopl", &pool_allocator_nointr);
102 }
103 
104 /*
105  * Reinitialize inode hash table.
106  */
107 
108 void
109 msdosfs_reinit()
110 {
111 	struct denode *dep;
112 	struct ihashhead *oldhash, *hash;
113 	u_long oldmask, mask, val;
114 	int i;
115 
116 	hash = hashinit(desiredvnodes / 2, HASH_LIST, M_MSDOSFSMNT, M_WAITOK,
117 	    &mask);
118 
119 	simple_lock(&msdosfs_ihash_slock);
120 	oldhash = dehashtbl;
121 	oldmask = dehash;
122 	dehashtbl = hash;
123 	dehash = mask;
124 	for (i = 0; i <= oldmask; i++) {
125 		while ((dep = LIST_FIRST(&oldhash[i])) != NULL) {
126 			LIST_REMOVE(dep, de_hash);
127 			val = DEHASH(dep->de_dev, dep->de_dirclust,
128 			    dep->de_diroffset);
129 			LIST_INSERT_HEAD(&hash[val], dep, de_hash);
130 		}
131 	}
132 	simple_unlock(&msdosfs_ihash_slock);
133 	hashdone(oldhash, M_MSDOSFSMNT);
134 }
135 
136 void
137 msdosfs_done()
138 {
139 	hashdone(dehashtbl, M_MSDOSFSMNT);
140 	pool_destroy(&msdosfs_denode_pool);
141 }
142 
143 static struct denode *
144 msdosfs_hashget(dev, dirclust, diroff)
145 	dev_t dev;
146 	u_long dirclust;
147 	u_long diroff;
148 {
149 	struct denode *dep;
150 	struct vnode *vp;
151 
152 loop:
153 	simple_lock(&msdosfs_ihash_slock);
154 	LIST_FOREACH(dep, &dehashtbl[DEHASH(dev, dirclust, diroff)], de_hash) {
155 		if (dirclust == dep->de_dirclust &&
156 		    diroff == dep->de_diroffset &&
157 		    dev == dep->de_dev &&
158 		    dep->de_refcnt != 0) {
159 			vp = DETOV(dep);
160 			simple_lock(&vp->v_interlock);
161 			simple_unlock(&msdosfs_ihash_slock);
162 			if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK))
163 				goto loop;
164 			return (dep);
165 		}
166 	}
167 	simple_unlock(&msdosfs_ihash_slock);
168 	return (NULL);
169 }
170 
171 static void
172 msdosfs_hashins(dep)
173 	struct denode *dep;
174 {
175 	struct ihashhead *depp;
176 	int val;
177 
178 	simple_lock(&msdosfs_ihash_slock);
179 	val = DEHASH(dep->de_dev, dep->de_dirclust, dep->de_diroffset);
180 	depp = &dehashtbl[val];
181 	LIST_INSERT_HEAD(depp, dep, de_hash);
182 	simple_unlock(&msdosfs_ihash_slock);
183 }
184 
185 static void
186 msdosfs_hashrem(dep)
187 	struct denode *dep;
188 {
189 	simple_lock(&msdosfs_ihash_slock);
190 	LIST_REMOVE(dep, de_hash);
191 	simple_unlock(&msdosfs_ihash_slock);
192 }
193 
194 /*
195  * If deget() succeeds it returns with the gotten denode locked().
196  *
197  * pmp	     - address of msdosfsmount structure of the filesystem containing
198  *	       the denode of interest.  The pm_dev field and the address of
199  *	       the msdosfsmount structure are used.
200  * dirclust  - which cluster bp contains, if dirclust is 0 (root directory)
201  *	       diroffset is relative to the beginning of the root directory,
202  *	       otherwise it is cluster relative.
203  * diroffset - offset past begin of cluster of denode we want
204  * depp	     - returns the address of the gotten denode.
205  */
206 int
207 deget(pmp, dirclust, diroffset, depp)
208 	struct msdosfsmount *pmp;	/* so we know the maj/min number */
209 	u_long dirclust;		/* cluster this dir entry came from */
210 	u_long diroffset;		/* index of entry within the cluster */
211 	struct denode **depp;		/* returns the addr of the gotten denode */
212 {
213 	int error;
214 	extern int (**msdosfs_vnodeop_p) __P((void *));
215 	struct direntry *direntptr;
216 	struct denode *ldep;
217 	struct vnode *nvp;
218 	struct buf *bp;
219 
220 #ifdef MSDOSFS_DEBUG
221 	printf("deget(pmp %p, dirclust %lu, diroffset %lx, depp %p)\n",
222 	    pmp, dirclust, diroffset, depp);
223 #endif
224 
225 	/*
226 	 * On FAT32 filesystems, root is a (more or less) normal
227 	 * directory
228 	 */
229 	if (FAT32(pmp) && dirclust == MSDOSFSROOT)
230 		dirclust = pmp->pm_rootdirblk;
231 
232 	/*
233 	 * See if the denode is in the denode cache. Use the location of
234 	 * the directory entry to compute the hash value. For subdir use
235 	 * address of "." entry. For root dir (if not FAT32) use cluster
236 	 * MSDOSFSROOT, offset MSDOSFSROOT_OFS
237 	 *
238 	 * NOTE: The check for de_refcnt > 0 below insures the denode being
239 	 * examined does not represent an unlinked but still open file.
240 	 * These files are not to be accessible even when the directory
241 	 * entry that represented the file happens to be reused while the
242 	 * deleted file is still open.
243 	 */
244 	ldep = msdosfs_hashget(pmp->pm_dev, dirclust, diroffset);
245 	if (ldep) {
246 		*depp = ldep;
247 		return (0);
248 	}
249 
250 	/*
251 	 * Directory entry was not in cache, have to create a vnode and
252 	 * copy it from the passed disk buffer.
253 	 */
254 	/* getnewvnode() does a VREF() on the vnode */
255 	error = getnewvnode(VT_MSDOSFS, pmp->pm_mountp,
256 			    msdosfs_vnodeop_p, &nvp);
257 	if (error) {
258 		*depp = 0;
259 		return (error);
260 	}
261 	ldep = pool_get(&msdosfs_denode_pool, PR_WAITOK);
262 	memset(ldep, 0, sizeof *ldep);
263 	nvp->v_data = ldep;
264 	ldep->de_vnode = nvp;
265 	ldep->de_flag = 0;
266 	ldep->de_devvp = 0;
267 	ldep->de_lockf = 0;
268 	ldep->de_dev = pmp->pm_dev;
269 	ldep->de_dirclust = dirclust;
270 	ldep->de_diroffset = diroffset;
271 	fc_purge(ldep, 0);	/* init the fat cache for this denode */
272 
273 	/*
274 	 * Insert the denode into the hash queue and lock the denode so it
275 	 * can't be accessed until we've read it in and have done what we
276 	 * need to it.
277 	 */
278 	vn_lock(nvp, LK_EXCLUSIVE | LK_RETRY);
279 	msdosfs_hashins(ldep);
280 
281 	ldep->de_pmp = pmp;
282 	ldep->de_devvp = pmp->pm_devvp;
283 	ldep->de_refcnt = 1;
284 	/*
285 	 * Copy the directory entry into the denode area of the vnode.
286 	 */
287 	if ((dirclust == MSDOSFSROOT
288 	     || (FAT32(pmp) && dirclust == pmp->pm_rootdirblk))
289 	    && diroffset == MSDOSFSROOT_OFS) {
290 		/*
291 		 * Directory entry for the root directory. There isn't one,
292 		 * so we manufacture one. We should probably rummage
293 		 * through the root directory and find a label entry (if it
294 		 * exists), and then use the time and date from that entry
295 		 * as the time and date for the root denode.
296 		 */
297 		nvp->v_flag |= VROOT; /* should be further down		XXX */
298 
299 		ldep->de_Attributes = ATTR_DIRECTORY;
300 		if (FAT32(pmp))
301 			ldep->de_StartCluster = pmp->pm_rootdirblk;
302 			/* de_FileSize will be filled in further down */
303 		else {
304 			ldep->de_StartCluster = MSDOSFSROOT;
305 			ldep->de_FileSize = pmp->pm_rootdirsize * pmp->pm_BytesPerSec;
306 		}
307 		/*
308 		 * fill in time and date so that dos2unixtime() doesn't
309 		 * spit up when called from msdosfs_getattr() with root
310 		 * denode
311 		 */
312 		ldep->de_CHun = 0;
313 		ldep->de_CTime = 0x0000;	/* 00:00:00	 */
314 		ldep->de_CDate = (0 << DD_YEAR_SHIFT) | (1 << DD_MONTH_SHIFT)
315 		    | (1 << DD_DAY_SHIFT);
316 		/* Jan 1, 1980	 */
317 		ldep->de_ADate = ldep->de_CDate;
318 		ldep->de_MTime = ldep->de_CTime;
319 		ldep->de_MDate = ldep->de_CDate;
320 		/* leave the other fields as garbage */
321 	} else {
322 		error = readep(pmp, dirclust, diroffset, &bp, &direntptr);
323 		if (error)
324 			return (error);
325 		DE_INTERNALIZE(ldep, direntptr);
326 		brelse(bp);
327 	}
328 
329 	/*
330 	 * Fill in a few fields of the vnode and finish filling in the
331 	 * denode.  Then return the address of the found denode.
332 	 */
333 	if (ldep->de_Attributes & ATTR_DIRECTORY) {
334 		/*
335 		 * Since DOS directory entries that describe directories
336 		 * have 0 in the filesize field, we take this opportunity
337 		 * to find out the length of the directory and plug it into
338 		 * the denode structure.
339 		 */
340 		u_long size;
341 
342 		nvp->v_type = VDIR;
343 		if (ldep->de_StartCluster != MSDOSFSROOT) {
344 			error = pcbmap(ldep, CLUST_END, 0, &size, 0);
345 			if (error == E2BIG) {
346 				ldep->de_FileSize = de_cn2off(pmp, size);
347 				error = 0;
348 			} else
349 				printf("deget(): pcbmap returned %d\n", error);
350 		}
351 	} else
352 		nvp->v_type = VREG;
353 	genfs_node_init(nvp, &msdosfs_genfsops);
354 	VREF(ldep->de_devvp);
355 	*depp = ldep;
356 	nvp->v_size = ldep->de_FileSize;
357 	return (0);
358 }
359 
360 int
361 deupdat(dep, waitfor)
362 	struct denode *dep;
363 	int waitfor;
364 {
365 
366 	return (VOP_UPDATE(DETOV(dep), NULL, NULL, waitfor ? UPDATE_WAIT : 0));
367 }
368 
369 /*
370  * Truncate the file described by dep to the length specified by length.
371  */
372 int
373 detrunc(dep, length, flags, cred, p)
374 	struct denode *dep;
375 	u_long length;
376 	int flags;
377 	struct ucred *cred;
378 	struct proc *p;
379 {
380 	int error;
381 	int allerror;
382 	u_long eofentry;
383 	u_long chaintofree;
384 	daddr_t bn, lastblock;
385 	int boff;
386 	int isadir = dep->de_Attributes & ATTR_DIRECTORY;
387 	struct buf *bp;
388 	struct msdosfsmount *pmp = dep->de_pmp;
389 
390 #ifdef MSDOSFS_DEBUG
391 	printf("detrunc(): file %s, length %lu, flags %x\n", dep->de_Name, length, flags);
392 #endif
393 
394 	/*
395 	 * Disallow attempts to truncate the root directory since it is of
396 	 * fixed size.  That's just the way dos filesystems are.  We use
397 	 * the VROOT bit in the vnode because checking for the directory
398 	 * bit and a startcluster of 0 in the denode is not adequate to
399 	 * recognize the root directory at this point in a file or
400 	 * directory's life.
401 	 */
402 	if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp)) {
403 		printf("detrunc(): can't truncate root directory, clust %ld, offset %ld\n",
404 		    dep->de_dirclust, dep->de_diroffset);
405 		return (EINVAL);
406 	}
407 
408 	uvm_vnp_setsize(DETOV(dep), length);
409 
410 	if (dep->de_FileSize < length)
411 		return (deextend(dep, length, cred));
412 	lastblock = de_clcount(pmp, length) - 1;
413 
414 	/*
415 	 * If the desired length is 0 then remember the starting cluster of
416 	 * the file and set the StartCluster field in the directory entry
417 	 * to 0.  If the desired length is not zero, then get the number of
418 	 * the last cluster in the shortened file.  Then get the number of
419 	 * the first cluster in the part of the file that is to be freed.
420 	 * Then set the next cluster pointer in the last cluster of the
421 	 * file to CLUST_EOFE.
422 	 */
423 	if (length == 0) {
424 		chaintofree = dep->de_StartCluster;
425 		dep->de_StartCluster = 0;
426 		eofentry = ~0;
427 	} else {
428 		error = pcbmap(dep, lastblock, 0, &eofentry, 0);
429 		if (error) {
430 #ifdef MSDOSFS_DEBUG
431 			printf("detrunc(): pcbmap fails %d\n", error);
432 #endif
433 			return (error);
434 		}
435 	}
436 
437 	fc_purge(dep, lastblock + 1);
438 
439 	/*
440 	 * If the new length is not a multiple of the cluster size then we
441 	 * must zero the tail end of the new last cluster in case it
442 	 * becomes part of the file again because of a seek.
443 	 */
444 	if ((boff = length & pmp->pm_crbomask) != 0) {
445 		if (isadir) {
446 			bn = cntobn(pmp, eofentry);
447 			error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
448 			    NOCRED, &bp);
449 			if (error) {
450 				brelse(bp);
451 #ifdef MSDOSFS_DEBUG
452 				printf("detrunc(): bread fails %d\n", error);
453 #endif
454 				return (error);
455 			}
456 			memset(bp->b_data + boff, 0, pmp->pm_bpcluster - boff);
457 			if (flags & IO_SYNC)
458 				bwrite(bp);
459 			else
460 				bdwrite(bp);
461 		} else {
462 			uvm_vnp_zerorange(DETOV(dep), length,
463 					  pmp->pm_bpcluster - boff);
464 		}
465 	}
466 
467 	/*
468 	 * Write out the updated directory entry.  Even if the update fails
469 	 * we free the trailing clusters.
470 	 */
471 	dep->de_FileSize = length;
472 	if (!isadir)
473 		dep->de_flag |= DE_UPDATE|DE_MODIFIED;
474 	vtruncbuf(DETOV(dep), lastblock + 1, 0, 0);
475 	allerror = deupdat(dep, 1);
476 #ifdef MSDOSFS_DEBUG
477 	printf("detrunc(): allerror %d, eofentry %lu\n",
478 	       allerror, eofentry);
479 #endif
480 
481 	/*
482 	 * If we need to break the cluster chain for the file then do it
483 	 * now.
484 	 */
485 	if (eofentry != ~0) {
486 		error = fatentry(FAT_GET_AND_SET, pmp, eofentry,
487 				 &chaintofree, CLUST_EOFE);
488 		if (error) {
489 #ifdef MSDOSFS_DEBUG
490 			printf("detrunc(): fatentry errors %d\n", error);
491 #endif
492 			return (error);
493 		}
494 		fc_setcache(dep, FC_LASTFC, de_cluster(pmp, length - 1),
495 			    eofentry);
496 	}
497 
498 	/*
499 	 * Now free the clusters removed from the file because of the
500 	 * truncation.
501 	 */
502 	if (chaintofree != 0 && !MSDOSFSEOF(chaintofree, pmp->pm_fatmask))
503 		freeclusterchain(pmp, chaintofree);
504 
505 	return (allerror);
506 }
507 
508 /*
509  * Extend the file described by dep to length specified by length.
510  */
511 int
512 deextend(dep, length, cred)
513 	struct denode *dep;
514 	u_long length;
515 	struct ucred *cred;
516 {
517 	struct msdosfsmount *pmp = dep->de_pmp;
518 	u_long count, osize;
519 	int error;
520 
521 	/*
522 	 * The root of a DOS filesystem cannot be extended.
523 	 */
524 	if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp))
525 		return (EINVAL);
526 
527 	/*
528 	 * Directories cannot be extended.
529 	 */
530 	if (dep->de_Attributes & ATTR_DIRECTORY)
531 		return (EISDIR);
532 
533 	if (length <= dep->de_FileSize)
534 		panic("deextend: file too large");
535 
536 	/*
537 	 * Compute the number of clusters to allocate.
538 	 */
539 	count = de_clcount(pmp, length) - de_clcount(pmp, dep->de_FileSize);
540 	if (count > 0) {
541 		if (count > pmp->pm_freeclustercount)
542 			return (ENOSPC);
543 		error = extendfile(dep, count, NULL, NULL, DE_CLEAR);
544 		if (error) {
545 			/* truncate the added clusters away again */
546 			(void) detrunc(dep, dep->de_FileSize, 0, cred, NULL);
547 			return (error);
548 		}
549 	}
550 
551 	osize = dep->de_FileSize;
552 	dep->de_FileSize = length;
553 	uvm_vnp_setsize(DETOV(dep), (voff_t)dep->de_FileSize);
554 	dep->de_flag |= DE_UPDATE|DE_MODIFIED;
555 	uvm_vnp_zerorange(DETOV(dep), (off_t)osize,
556 	    (size_t)(dep->de_FileSize - osize));
557 	return (deupdat(dep, 1));
558 }
559 
560 /*
561  * Move a denode to its correct hash queue after the file it represents has
562  * been moved to a new directory.
563  */
564 void
565 reinsert(dep)
566 	struct denode *dep;
567 {
568 	/*
569 	 * Fix up the denode cache.  If the denode is for a directory,
570 	 * there is nothing to do since the hash is based on the starting
571 	 * cluster of the directory file and that hasn't changed.  If for a
572 	 * file the hash is based on the location of the directory entry,
573 	 * so we must remove it from the cache and re-enter it with the
574 	 * hash based on the new location of the directory entry.
575 	 */
576 	if (dep->de_Attributes & ATTR_DIRECTORY)
577 		return;
578 	msdosfs_hashrem(dep);
579 	msdosfs_hashins(dep);
580 }
581 
582 int
583 msdosfs_reclaim(v)
584 	void *v;
585 {
586 	struct vop_reclaim_args /* {
587 		struct vnode *a_vp;
588 	} */ *ap = v;
589 	struct vnode *vp = ap->a_vp;
590 	struct denode *dep = VTODE(vp);
591 
592 #ifdef MSDOSFS_DEBUG
593 	printf("msdosfs_reclaim(): dep %p, file %s, refcnt %ld\n",
594 	    dep, dep->de_Name, dep->de_refcnt);
595 #endif
596 
597 	if (prtactive && vp->v_usecount != 0)
598 		vprint("msdosfs_reclaim(): pushing active", vp);
599 	/*
600 	 * Remove the denode from its hash chain.
601 	 */
602 	msdosfs_hashrem(dep);
603 	/*
604 	 * Purge old data structures associated with the denode.
605 	 */
606 	cache_purge(vp);
607 	if (dep->de_devvp) {
608 		vrele(dep->de_devvp);
609 		dep->de_devvp = 0;
610 	}
611 #if 0 /* XXX */
612 	dep->de_flag = 0;
613 #endif
614 	pool_put(&msdosfs_denode_pool, dep);
615 	vp->v_data = NULL;
616 	return (0);
617 }
618 
619 int
620 msdosfs_inactive(v)
621 	void *v;
622 {
623 	struct vop_inactive_args /* {
624 		struct vnode *a_vp;
625 		struct proc *a_p;
626 	} */ *ap = v;
627 	struct proc *p = ap->a_p;
628 	struct vnode *vp = ap->a_vp;
629 	struct denode *dep = VTODE(vp);
630 	int error = 0;
631 
632 #ifdef MSDOSFS_DEBUG
633 	printf("msdosfs_inactive(): dep %p, de_Name[0] %x\n", dep, dep->de_Name[0]);
634 #endif
635 
636 	if (prtactive && vp->v_usecount != 0)
637 		vprint("msdosfs_inactive(): pushing active", vp);
638 
639 	/*
640 	 * Get rid of denodes related to stale file handles.
641 	 */
642 	if (dep->de_Name[0] == SLOT_DELETED)
643 		goto out;
644 
645 	/*
646 	 * If the file has been deleted and it is on a read/write
647 	 * filesystem, then truncate the file, and mark the directory slot
648 	 * as empty.  (This may not be necessary for the dos filesystem.)
649 	 */
650 #ifdef MSDOSFS_DEBUG
651 	printf("msdosfs_inactive(): dep %p, refcnt %ld, mntflag %x %s\n",
652 	       dep, dep->de_refcnt, vp->v_mount->mnt_flag,
653 		(vp->v_mount->mnt_flag & MNT_RDONLY) ? "MNT_RDONLY" : "");
654 #endif
655 	if (dep->de_refcnt <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
656 		if (dep->de_FileSize != 0) {
657 			error = detrunc(dep, (u_long)0, 0, NOCRED, NULL);
658 		}
659 		dep->de_Name[0] = SLOT_DELETED;
660 	}
661 	deupdat(dep, 0);
662 out:
663 	VOP_UNLOCK(vp, 0);
664 	/*
665 	 * If we are done with the denode, reclaim it
666 	 * so that it can be reused immediately.
667 	 */
668 #ifdef MSDOSFS_DEBUG
669 	printf("msdosfs_inactive(): v_usecount %d, de_Name[0] %x\n",
670 		vp->v_usecount, dep->de_Name[0]);
671 #endif
672 	if (dep->de_Name[0] == SLOT_DELETED)
673 		vrecycle(vp, (struct simplelock *)0, p);
674 	return (error);
675 }
676 
677 int
678 msdosfs_gop_alloc(struct vnode *vp, off_t off, off_t len, int flags,
679     struct ucred *cred)
680 {
681 	return 0;
682 }
683