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