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