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/kernel.h> 57 #include <sys/malloc.h> 58 #include <sys/proc.h> 59 #include <sys/mount.h> 60 #include <sys/vnode.h> 61 #include <sys/time.h> 62 63 #include <vm/vm.h> 64 #include <vm/vm_extern.h> 65 66 #include <sys/buf2.h> 67 68 #include "bpb.h" 69 #include "msdosfsmount.h" 70 #include "direntry.h" 71 #include "denode.h" 72 #include "fat.h" 73 74 static MALLOC_DEFINE(M_MSDOSFSNODE, "MSDOSFS node", "MSDOSFS vnode private part"); 75 76 /* 77 * Hash table caching denode instances. 78 * 79 * denodes are keyed by the disk location (cluster num, entry offset) of the 80 * directory entry of the file they represent. 81 * 82 * denodes representing deleted but still opened files are left in this cache 83 * until reclaimed. Deleted directory entries can be reused when files are 84 * renamed or new files created. As a consequence, several denodes associated 85 * with the same entry may coexist in this cache as long as a single one of 86 * them map to an existing file (de_refcnt > 0). 87 * 88 * R/w access to this cache is protected by dehash_token. 89 */ 90 static struct denode **dehashtbl; 91 static u_long dehash; /* size of hash table - 1 */ 92 static struct lwkt_token dehash_token; 93 94 #define DEHASH(dev, dcl, doff) (dehashtbl[(minor(dev) + (dcl) + (doff) / \ 95 sizeof(struct direntry)) & dehash]) 96 97 /*ARGSUSED*/ 98 int 99 msdosfs_init(struct vfsconf *vfsp) 100 { 101 dehash = vfs_inodehashsize(); 102 dehashtbl = kmalloc(sizeof(void *) * dehash, 103 M_MSDOSFSMNT, M_WAITOK|M_ZERO); 104 --dehash; 105 lwkt_token_init(&dehash_token, "msdosihash"); 106 107 return (0); 108 } 109 110 int 111 msdosfs_uninit(struct vfsconf *vfsp) 112 { 113 if (dehashtbl) 114 kfree(dehashtbl, M_MSDOSFSMNT); 115 return (0); 116 } 117 118 static struct denode * 119 msdosfs_hashget(cdev_t dev, u_long dirclust, u_long diroff) 120 { 121 struct denode *dep; 122 struct vnode *vp; 123 124 lwkt_gettoken(&dehash_token); 125 loop: 126 for (dep = DEHASH(dev, dirclust, diroff); dep; dep = dep->de_next) { 127 if (dirclust != dep->de_dirclust 128 || diroff != dep->de_diroffset 129 || dev != dep->de_dev 130 || dep->de_refcnt <= 0) { 131 continue; 132 } 133 vp = DETOV(dep); 134 if (vget(vp, LK_EXCLUSIVE)) 135 goto loop; 136 137 /* 138 * We must check to see if the inode has been ripped 139 * out from under us after blocking. 140 */ 141 for (dep = DEHASH(dev, dirclust, diroff); dep; 142 dep = dep->de_next) { 143 if (dirclust == dep->de_dirclust 144 && diroff == dep->de_diroffset 145 && dev == dep->de_dev 146 && dep->de_refcnt > 0) { 147 break; 148 } 149 } 150 if (dep == NULL || DETOV(dep) != vp) { 151 vput(vp); 152 goto loop; 153 } 154 lwkt_reltoken(&dehash_token); 155 return (dep); 156 } 157 lwkt_reltoken(&dehash_token); 158 return (NULL); 159 } 160 161 /* 162 * Try to insert specified denode into the hash table. Return 0 on success 163 * and EBUSY if there is already a denode with the same key. 164 */ 165 static 166 int 167 msdosfs_hashins(struct denode *dep) 168 { 169 struct denode **depp, *deq; 170 171 lwkt_gettoken(&dehash_token); 172 depp = &DEHASH(dep->de_dev, dep->de_dirclust, dep->de_diroffset); 173 while ((deq = *depp) != NULL) { 174 if (deq->de_dev == dep->de_dev && 175 deq->de_dirclust == dep->de_dirclust && 176 deq->de_diroffset == dep->de_diroffset && 177 deq->de_refcnt > 0) { 178 lwkt_reltoken(&dehash_token); 179 return(EBUSY); 180 } 181 depp = &deq->de_next; 182 } 183 dep->de_next = NULL; 184 *depp = dep; 185 lwkt_reltoken(&dehash_token); 186 return(0); 187 } 188 189 static 190 void 191 msdosfs_hashrem(struct denode *dep) 192 { 193 struct denode **depp, *deq; 194 195 lwkt_gettoken(&dehash_token); 196 depp = &DEHASH(dep->de_dev, dep->de_dirclust, dep->de_diroffset); 197 while ((deq = *depp) != NULL) { 198 if (dep == deq) 199 break; 200 depp = &deq->de_next; 201 } 202 KKASSERT(dep == deq); 203 *depp = dep->de_next; 204 dep->de_next = NULL; 205 lwkt_reltoken(&dehash_token); 206 } 207 208 void 209 msdosfs_reinsert(struct denode *ip, u_long new_dirclust, u_long new_diroffset) 210 { 211 int error; 212 213 lwkt_gettoken(&dehash_token); 214 msdosfs_hashrem(ip); 215 ip->de_dirclust = new_dirclust; 216 ip->de_diroffset = new_diroffset; 217 error = msdosfs_hashins(ip); 218 KASSERT(!error, ("msdosfs_reinsert: insertion failed %d", error)); 219 lwkt_reltoken(&dehash_token); 220 } 221 222 /* 223 * If deget() succeeds it returns with the gotten denode locked(). 224 * 225 * pmp - address of msdosfsmount structure of the filesystem containing 226 * the denode of interest. The address of 227 * the msdosfsmount structure are used. 228 * dirclust - which cluster bp contains, if dirclust is 0 (root directory) 229 * diroffset is relative to the beginning of the root directory, 230 * otherwise it is cluster relative. 231 * diroffset - offset past begin of cluster of denode we want 232 * depp - returns the address of the gotten denode. 233 */ 234 int 235 deget(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset, 236 struct denode **depp) 237 { 238 int error; 239 cdev_t dev = pmp->pm_dev; 240 struct mount *mntp = pmp->pm_mountp; 241 struct direntry *direntptr; 242 struct denode *ldep; 243 struct vnode *nvp; 244 struct buf *bp; 245 246 mprintf("deget(pmp %p, dirclust %lu, diroffset %lx, depp %p)\n", 247 pmp, dirclust, diroffset, depp); 248 249 /* 250 * On FAT32 filesystems, root is a (more or less) normal 251 * directory 252 */ 253 if (FAT32(pmp) && dirclust == MSDOSFSROOT) 254 dirclust = pmp->pm_rootdirblk; 255 256 again: 257 /* 258 * See if the denode is in the denode cache. Use the location of 259 * the directory entry to compute the hash value. For subdir use 260 * address of "." entry. For root dir (if not FAT32) use cluster 261 * MSDOSFSROOT, offset MSDOSFSROOT_OFS 262 * 263 * NOTE: The check for de_refcnt > 0 below insures the denode being 264 * examined does not represent an unlinked but still open file. 265 * These files are not to be accessible even when the directory 266 * entry that represented the file happens to be reused while the 267 * deleted file is still open. 268 */ 269 ldep = msdosfs_hashget(dev, dirclust, diroffset); 270 if (ldep) { 271 *depp = ldep; 272 return (0); 273 } 274 275 /* 276 * Do the MALLOC before the getnewvnode since doing so afterward 277 * might cause a bogus v_data pointer to get dereferenced 278 * elsewhere if MALLOC should block. 279 */ 280 ldep = kmalloc(sizeof(struct denode), M_MSDOSFSNODE, M_WAITOK | M_ZERO); 281 282 /* 283 * Directory entry was not in cache, have to create a vnode and 284 * copy it from the passed disk buffer. 285 */ 286 287 /* getnewvnode() does a vref() on the vnode */ 288 error = getnewvnode(VT_MSDOSFS, mntp, &nvp, VLKTIMEOUT, 0); 289 if (error) { 290 *depp = NULL; 291 kfree(ldep, M_MSDOSFSNODE); 292 return error; 293 } 294 295 ldep->de_vnode = nvp; 296 ldep->de_flag = 0; 297 ldep->de_devvp = 0; 298 ldep->de_dev = dev; 299 ldep->de_dirclust = dirclust; 300 ldep->de_diroffset = diroffset; 301 fc_purge(ldep, 0); /* init the fat cache for this denode */ 302 303 /* 304 * Insert the denode into the hash queue. If a collision occurs 305 * throw away the vnode and try again. 306 */ 307 error = msdosfs_hashins(ldep); 308 if (error == EBUSY) { 309 nvp->v_type = VBAD; 310 vx_put(nvp); 311 kfree(ldep, M_MSDOSFSNODE); 312 goto again; 313 } else if (error) { 314 nvp->v_type = VBAD; 315 vx_put(nvp); 316 kfree(ldep, M_MSDOSFSNODE); 317 *depp = NULL; 318 return (EINVAL); 319 } 320 nvp->v_data = ldep; 321 ldep->de_pmp = pmp; 322 ldep->de_refcnt = 1; 323 /* 324 * Copy the directory entry into the denode area of the vnode. 325 */ 326 if ((dirclust == MSDOSFSROOT 327 || (FAT32(pmp) && dirclust == pmp->pm_rootdirblk)) 328 && diroffset == MSDOSFSROOT_OFS) { 329 /* 330 * Directory entry for the root directory. There isn't one, 331 * so we manufacture one. We should probably rummage 332 * through the root directory and find a label entry (if it 333 * exists), and then use the time and date from that entry 334 * as the time and date for the root denode. 335 */ 336 vsetflags(nvp, VROOT); /* should be further down XXX */ 337 338 ldep->de_Attributes = ATTR_DIRECTORY; 339 ldep->de_LowerCase = 0; 340 if (FAT32(pmp)) { 341 ldep->de_StartCluster = pmp->pm_rootdirblk; 342 /* de_FileSize will be filled in further down */ 343 } else { 344 ldep->de_StartCluster = MSDOSFSROOT; 345 ldep->de_FileSize = pmp->pm_rootdirsize * DEV_BSIZE; 346 } 347 /* 348 * fill in time and date so that fattime2timespec() doesn't 349 * spit up when called from msdosfs_getattr() with root 350 * denode 351 */ 352 ldep->de_CHun = 0; 353 ldep->de_CTime = 0x0000; /* 00:00:00 */ 354 ldep->de_CDate = (0 << DD_YEAR_SHIFT) | (1 << DD_MONTH_SHIFT) 355 | (1 << DD_DAY_SHIFT); 356 /* Jan 1, 1980 */ 357 ldep->de_ADate = ldep->de_CDate; 358 ldep->de_MTime = ldep->de_CTime; 359 ldep->de_MDate = ldep->de_CDate; 360 /* leave the other fields as garbage */ 361 } else { 362 error = readep(pmp, dirclust, diroffset, &bp, &direntptr); 363 if (error) { 364 /* 365 * The denode does not contain anything useful, so 366 * it would be wrong to leave it on its hash chain. 367 * Arrange for vput() to just forget about it. 368 */ 369 ldep->de_Name[0] = SLOT_DELETED; 370 nvp->v_type = VBAD; 371 372 vx_put(nvp); 373 *depp = NULL; 374 return (error); 375 } 376 DE_INTERNALIZE(ldep, direntptr); 377 brelse(bp); 378 } 379 380 /* 381 * Fill in a few fields of the vnode and finish filling in the 382 * denode. Then return the address of the found denode. 383 */ 384 if (ldep->de_Attributes & ATTR_DIRECTORY) { 385 /* 386 * Since DOS directory entries that describe directories 387 * have 0 in the filesize field, we take this opportunity 388 * to find out the length of the directory and plug it into 389 * the denode structure. 390 */ 391 u_long size; 392 393 /* 394 * XXX it sometimes happens that the "." entry has cluster 395 * number 0 when it shouldn't. Use the actual cluster number 396 * instead of what is written in directory entry. 397 */ 398 if (diroffset == 0 && ldep->de_StartCluster != dirclust) { 399 kprintf("deget(): \".\" entry at clust %lu != %lu\n", 400 dirclust, ldep->de_StartCluster); 401 ldep->de_StartCluster = dirclust; 402 } 403 404 nvp->v_type = VDIR; 405 if (ldep->de_StartCluster != MSDOSFSROOT) { 406 error = pcbmap(ldep, 0xffff, NULL, &size, NULL); 407 if (error == E2BIG) { 408 ldep->de_FileSize = de_cn2off(pmp, size); 409 error = 0; 410 } else 411 kprintf("deget(): pcbmap returned %d\n", error); 412 } 413 } else { 414 nvp->v_type = VREG; 415 } 416 417 ldep->de_modrev = init_va_filerev(); 418 ldep->de_devvp = pmp->pm_devvp; 419 vref(ldep->de_devvp); 420 vinitvmio(nvp, ldep->de_FileSize, PAGE_SIZE, -1); 421 /* 422 * Leave nvp locked and refd so the returned inode is effectively 423 * locked and refd. 424 */ 425 *depp = ldep; 426 return (0); 427 } 428 429 int 430 deupdat(struct denode *dep, int waitfor) 431 { 432 int error; 433 struct buf *bp; 434 struct direntry *dirp; 435 struct timespec ts; 436 437 if (DETOV(dep)->v_mount->mnt_flag & MNT_RDONLY) 438 return (0); 439 vfs_timestamp(&ts); 440 DETIMES(dep, &ts, &ts, &ts); 441 if ((dep->de_flag & DE_MODIFIED) == 0) 442 return (0); 443 dep->de_flag &= ~DE_MODIFIED; 444 if (dep->de_Attributes & ATTR_DIRECTORY) 445 return (0); 446 if (dep->de_refcnt <= 0) 447 return (0); 448 error = readde(dep, &bp, &dirp); 449 if (error) 450 return (error); 451 DE_EXTERNALIZE(dirp, dep); 452 if (waitfor) { 453 return (bwrite(bp)); 454 } else { 455 bdwrite(bp); 456 return (0); 457 } 458 } 459 460 /* 461 * Truncate the file described by dep to the length specified by length. 462 */ 463 int 464 detrunc(struct denode *dep, u_long length, int flags) 465 { 466 int error; 467 int allerror; 468 u_long eofentry; 469 u_long chaintofree; 470 daddr_t bn, cn; 471 int boff; 472 int isadir = dep->de_Attributes & ATTR_DIRECTORY; 473 struct buf *bp; 474 struct msdosfsmount *pmp = dep->de_pmp; 475 476 mprintf("detrunc(): file %s, length %lu, flags %x\n", dep->de_Name, 477 length, flags); 478 479 /* 480 * Disallow attempts to truncate the root directory since it is of 481 * fixed size. That's just the way dos filesystems are. We use 482 * the VROOT bit in the vnode because checking for the directory 483 * bit and a startcluster of 0 in the denode is not adequate to 484 * recognize the root directory at this point in a file or 485 * directory's life. 486 */ 487 if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp)) { 488 kprintf("detrunc(): can't truncate root directory, clust %ld, " 489 "offset %ld\n", 490 dep->de_dirclust, dep->de_diroffset); 491 return (EINVAL); 492 } 493 494 if (dep->de_FileSize < length) { 495 vnode_pager_setsize(DETOV(dep), length); 496 return deextend(dep, length); 497 } 498 499 /* 500 * If the desired length is 0 then remember the starting cluster of 501 * the file and set the StartCluster field in the directory entry 502 * to 0. If the desired length is not zero, then get the number of 503 * the last cluster in the shortened file. Then get the number of 504 * the first cluster in the part of the file that is to be freed. 505 * Then set the next cluster pointer in the last cluster of the 506 * file to CLUST_EOFE. 507 */ 508 if (length == 0) { 509 chaintofree = dep->de_StartCluster; 510 dep->de_StartCluster = 0; 511 eofentry = ~0; 512 } else { 513 error = pcbmap(dep, de_clcount(pmp, length) - 1, 514 NULL, &eofentry, NULL); 515 if (error) { 516 mprintf("detrunc(): pcbmap fails %d\n", error); 517 return (error); 518 } 519 } 520 521 fc_purge(dep, de_clcount(pmp, length)); 522 523 /* 524 * If the new length is not a multiple of the cluster size then we 525 * must zero the tail end of the new last cluster in case it 526 * becomes part of the file again because of a seek. 527 */ 528 if ((boff = length & pmp->pm_crbomask) != 0) { 529 if (isadir) { 530 bn = cntobn(pmp, eofentry); 531 error = bread(pmp->pm_devvp, de_bn2doff(pmp, bn), 532 pmp->pm_bpcluster, &bp); 533 } else { 534 cn = de_cluster(pmp, length); 535 error = bread(DETOV(dep), de_cn2doff(pmp, cn), 536 pmp->pm_bpcluster, &bp); 537 } 538 if (error) { 539 brelse(bp); 540 mprintf("detrunc(): bread fails %d\n", error); 541 return (error); 542 } 543 memset(bp->b_data + boff, 0, pmp->pm_bpcluster - boff); 544 if ((flags & IO_SYNC) != 0) 545 bwrite(bp); 546 else 547 bdwrite(bp); 548 } 549 550 /* 551 * Write out the updated directory entry. Even if the update fails 552 * we free the trailing clusters. 553 */ 554 dep->de_FileSize = length; 555 if (!isadir) 556 dep->de_flag |= DE_UPDATE | DE_MODIFIED; 557 allerror = vtruncbuf(DETOV(dep), length, pmp->pm_bpcluster); 558 #ifdef MSDOSFS_DEBUG 559 if (allerror) 560 kprintf("detrunc(): vtruncbuf error %d\n", allerror); 561 #endif 562 error = deupdat(dep, 1); 563 if (error != 0 && allerror == 0) 564 allerror = error; 565 mprintf("detrunc(): allerror %d, eofentry %lu\n", 566 allerror, eofentry); 567 568 /* 569 * If we need to break the cluster chain for the file then do it 570 * now. 571 */ 572 if (eofentry != ~0) { 573 error = fatentry(FAT_GET_AND_SET, pmp, eofentry, 574 &chaintofree, CLUST_EOFE); 575 if (error) { 576 mprintf("detrunc(): fatentry errors %d\n", error); 577 return (error); 578 } 579 fc_setcache(dep, FC_LASTFC, de_cluster(pmp, length - 1), 580 eofentry); 581 } 582 583 /* 584 * Now free the clusters removed from the file because of the 585 * truncation. 586 */ 587 if (chaintofree != 0 && !MSDOSFSEOF(pmp, chaintofree)) 588 freeclusterchain(pmp, chaintofree); 589 590 return (allerror); 591 } 592 593 /* 594 * Extend the file described by dep to length specified by length. 595 */ 596 int 597 deextend(struct denode *dep, u_long length) 598 { 599 struct msdosfsmount *pmp = dep->de_pmp; 600 u_long count; 601 int error; 602 603 /* 604 * The root of a DOS filesystem cannot be extended. 605 */ 606 if ((DETOV(dep)->v_flag & VROOT) && !FAT32(pmp)) 607 return (EINVAL); 608 609 /* 610 * Directories cannot be extended. 611 */ 612 if (dep->de_Attributes & ATTR_DIRECTORY) 613 return (EISDIR); 614 615 if (length <= dep->de_FileSize) 616 panic("deextend: file too large"); 617 618 /* 619 * Compute the number of clusters to allocate. 620 */ 621 count = de_clcount(pmp, length) - de_clcount(pmp, dep->de_FileSize); 622 if (count > 0) { 623 if (count > pmp->pm_freeclustercount) 624 return (ENOSPC); 625 error = extendfile(dep, count, NULL, NULL, DE_CLEAR); 626 if (error) { 627 /* truncate the added clusters away again */ 628 detrunc(dep, dep->de_FileSize, 0); 629 return (error); 630 } 631 } 632 dep->de_FileSize = length; 633 dep->de_flag |= DE_UPDATE | DE_MODIFIED; 634 return (deupdat(dep, 1)); 635 } 636 637 int 638 msdosfs_reclaim(struct vop_reclaim_args *ap) 639 { 640 struct vnode *vp = ap->a_vp; 641 struct denode *dep = VTODE(vp); 642 643 mprintf("msdosfs_reclaim(): dep %p, file %s, refcnt %ld\n", 644 dep, dep ? (char *)dep->de_Name : "?", dep ? dep->de_refcnt : -1); 645 646 if (prtactive && VREFCNT(vp) > 1) 647 vprint("msdosfs_reclaim(): pushing active", vp); 648 /* 649 * Remove the denode from its hash chain. 650 */ 651 vp->v_data = NULL; 652 if (dep) { 653 msdosfs_hashrem(dep); 654 if (dep->de_devvp) { 655 vrele(dep->de_devvp); 656 dep->de_devvp = 0; 657 } 658 kfree(dep, M_MSDOSFSNODE); 659 } 660 return (0); 661 } 662 663 int 664 msdosfs_inactive(struct vop_inactive_args *ap) 665 { 666 struct vnode *vp = ap->a_vp; 667 struct denode *dep = VTODE(vp); 668 int error = 0; 669 670 mprintf("msdosfs_inactive(): dep %p, de_Name[0] %x\n", 671 dep, (dep ? dep->de_Name[0] : 0)); 672 673 if (prtactive && VREFCNT(vp) > 1) 674 vprint("msdosfs_inactive(): pushing active", vp); 675 676 /* 677 * Ignore denodes related to stale file handles. 678 */ 679 if (dep == NULL || dep->de_Name[0] == SLOT_DELETED || dep->de_Name[0] == SLOT_EMPTY) 680 goto out; 681 682 /* 683 * If the file has been deleted and it is on a read/write 684 * filesystem, then truncate the file, and mark the directory slot 685 * as empty. (This may not be necessary for the dos filesystem.) 686 */ 687 mprintf("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 if (dep->de_refcnt <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { 690 error = detrunc(dep, (u_long) 0, 0); 691 dep->de_flag |= DE_UPDATE; 692 dep->de_Name[0] = SLOT_DELETED; 693 } 694 deupdat(dep, 0); 695 696 out: 697 /* 698 * If we are done with the denode, reclaim it 699 * so that it can be reused immediately. 700 */ 701 mprintf("msdosfs_inactive(): v_refcnt 0x%08x, de_Name[0] %x\n", 702 vp->v_refcnt, (dep ? dep->de_Name[0] : 0)); 703 if (dep == NULL || dep->de_Name[0] == SLOT_DELETED || dep->de_Name[0] == SLOT_EMPTY) 704 vrecycle(vp); 705 return (error); 706 } 707