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_vnodeop_p, &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_devvp = 0; 262 ldep->de_dev = dev; 263 ldep->de_dirclust = dirclust; 264 ldep->de_diroffset = diroffset; 265 fc_purge(ldep, 0); /* init the fat cache for this denode */ 266 267 /* 268 * Lock the denode so that it can't be accessed until we've read 269 * it in and have done what we need to it. Do this here instead 270 * of at the start of msdosfs_hashins() so that reinsert() can 271 * call msdosfs_hashins() with a locked denode. 272 */ 273 if (VOP_LOCK(nvp, LK_EXCLUSIVE, td) != 0) 274 panic("deget: unexpected lock failure"); 275 276 /* 277 * Insert the denode into the hash queue. 278 */ 279 msdosfs_hashins(ldep); 280 281 ldep->de_pmp = pmp; 282 ldep->de_refcnt = 1; 283 /* 284 * Copy the directory entry into the denode area of the vnode. 285 */ 286 if ((dirclust == MSDOSFSROOT 287 || (FAT32(pmp) && dirclust == pmp->pm_rootdirblk)) 288 && diroffset == MSDOSFSROOT_OFS) { 289 /* 290 * Directory entry for the root directory. There isn't one, 291 * so we manufacture one. We should probably rummage 292 * through the root directory and find a label entry (if it 293 * exists), and then use the time and date from that entry 294 * as the time and date for the root denode. 295 */ 296 nvp->v_vflag |= VV_ROOT; /* should be further down XXX */ 297 298 ldep->de_Attributes = ATTR_DIRECTORY; 299 ldep->de_LowerCase = 0; 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 * DEV_BSIZE; 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 /* 325 * The denode does not contain anything useful, so 326 * it would be wrong to leave it on its hash chain. 327 * Arrange for vput() to just forget about it. 328 */ 329 ldep->de_Name[0] = SLOT_DELETED; 330 331 vput(nvp); 332 *depp = NULL; 333 return (error); 334 } 335 DE_INTERNALIZE(ldep, direntptr); 336 brelse(bp); 337 } 338 339 /* 340 * Fill in a few fields of the vnode and finish filling in the 341 * denode. Then return the address of the found denode. 342 */ 343 if (ldep->de_Attributes & ATTR_DIRECTORY) { 344 /* 345 * Since DOS directory entries that describe directories 346 * have 0 in the filesize field, we take this opportunity 347 * to find out the length of the directory and plug it into 348 * the denode structure. 349 */ 350 u_long size; 351 352 /* 353 * XXX Sometimes, these arrives that . entry have cluster 354 * number 0, when it shouldn't. Use real cluster number 355 * instead of what is written in directory entry. 356 */ 357 if ((diroffset == 0) && (ldep->de_StartCluster != dirclust)) { 358 printf("deget(): . entry at clust %ld != %ld\n", 359 dirclust, ldep->de_StartCluster); 360 ldep->de_StartCluster = dirclust; 361 } 362 363 nvp->v_type = VDIR; 364 if (ldep->de_StartCluster != MSDOSFSROOT) { 365 error = pcbmap(ldep, 0xffff, 0, &size, 0); 366 if (error == E2BIG) { 367 ldep->de_FileSize = de_cn2off(pmp, size); 368 error = 0; 369 } else 370 printf("deget(): pcbmap returned %d\n", error); 371 } 372 } else 373 nvp->v_type = VREG; 374 375 ldep->de_modrev = init_va_filerev(); 376 ldep->de_devvp = pmp->pm_devvp; 377 VREF(ldep->de_devvp); 378 *depp = ldep; 379 return (0); 380 } 381 382 int 383 deupdat(dep, waitfor) 384 struct denode *dep; 385 int waitfor; 386 { 387 int error; 388 struct buf *bp; 389 struct direntry *dirp; 390 struct timespec ts; 391 392 if (DETOV(dep)->v_mount->mnt_flag & MNT_RDONLY) 393 return (0); 394 getnanotime(&ts); 395 DETIMES(dep, &ts, &ts, &ts); 396 if ((dep->de_flag & DE_MODIFIED) == 0) 397 return (0); 398 dep->de_flag &= ~DE_MODIFIED; 399 if (dep->de_Attributes & ATTR_DIRECTORY) 400 return (0); 401 if (dep->de_refcnt <= 0) 402 return (0); 403 error = readde(dep, &bp, &dirp); 404 if (error) 405 return (error); 406 DE_EXTERNALIZE(dirp, dep); 407 if (waitfor) 408 return (bwrite(bp)); 409 else { 410 bdwrite(bp); 411 return (0); 412 } 413 } 414 415 /* 416 * Truncate the file described by dep to the length specified by length. 417 */ 418 int 419 detrunc(dep, length, flags, cred, td) 420 struct denode *dep; 421 u_long length; 422 int flags; 423 struct ucred *cred; 424 struct thread *td; 425 { 426 int error; 427 int allerror; 428 u_long eofentry; 429 u_long chaintofree; 430 daddr_t bn; 431 int boff; 432 int isadir = dep->de_Attributes & ATTR_DIRECTORY; 433 struct buf *bp; 434 struct msdosfsmount *pmp = dep->de_pmp; 435 436 #ifdef MSDOSFS_DEBUG 437 printf("detrunc(): file %s, length %lu, flags %x\n", dep->de_Name, length, flags); 438 #endif 439 440 /* 441 * Disallow attempts to truncate the root directory since it is of 442 * fixed size. That's just the way dos filesystems are. We use 443 * the VROOT bit in the vnode because checking for the directory 444 * bit and a startcluster of 0 in the denode is not adequate to 445 * recognize the root directory at this point in a file or 446 * directory's life. 447 */ 448 if ((DETOV(dep)->v_vflag & VV_ROOT) && !FAT32(pmp)) { 449 printf("detrunc(): can't truncate root directory, clust %ld, offset %ld\n", 450 dep->de_dirclust, dep->de_diroffset); 451 return (EINVAL); 452 } 453 454 455 if (dep->de_FileSize < length) { 456 vnode_pager_setsize(DETOV(dep), length); 457 return deextend(dep, length, cred); 458 } 459 460 /* 461 * If the desired length is 0 then remember the starting cluster of 462 * the file and set the StartCluster field in the directory entry 463 * to 0. If the desired length is not zero, then get the number of 464 * the last cluster in the shortened file. Then get the number of 465 * the first cluster in the part of the file that is to be freed. 466 * Then set the next cluster pointer in the last cluster of the 467 * file to CLUST_EOFE. 468 */ 469 if (length == 0) { 470 chaintofree = dep->de_StartCluster; 471 dep->de_StartCluster = 0; 472 eofentry = ~0; 473 } else { 474 error = pcbmap(dep, de_clcount(pmp, length) - 1, 0, 475 &eofentry, 0); 476 if (error) { 477 #ifdef MSDOSFS_DEBUG 478 printf("detrunc(): pcbmap fails %d\n", error); 479 #endif 480 return (error); 481 } 482 } 483 484 fc_purge(dep, de_clcount(pmp, length)); 485 486 /* 487 * If the new length is not a multiple of the cluster size then we 488 * must zero the tail end of the new last cluster in case it 489 * becomes part of the file again because of a seek. 490 */ 491 if ((boff = length & pmp->pm_crbomask) != 0) { 492 if (isadir) { 493 bn = cntobn(pmp, eofentry); 494 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster, 495 NOCRED, &bp); 496 if (error) { 497 brelse(bp); 498 #ifdef MSDOSFS_DEBUG 499 printf("detrunc(): bread fails %d\n", error); 500 #endif 501 return (error); 502 } 503 bzero(bp->b_data + boff, pmp->pm_bpcluster - boff); 504 if (flags & IO_SYNC) 505 bwrite(bp); 506 else 507 bdwrite(bp); 508 } 509 } 510 511 /* 512 * Write out the updated directory entry. Even if the update fails 513 * we free the trailing clusters. 514 */ 515 dep->de_FileSize = length; 516 if (!isadir) 517 dep->de_flag |= DE_UPDATE|DE_MODIFIED; 518 allerror = vtruncbuf(DETOV(dep), cred, td, length, pmp->pm_bpcluster); 519 #ifdef MSDOSFS_DEBUG 520 if (allerror) 521 printf("detrunc(): vtruncbuf error %d\n", allerror); 522 #endif 523 error = deupdat(dep, 1); 524 if (error && (allerror == 0)) 525 allerror = error; 526 #ifdef MSDOSFS_DEBUG 527 printf("detrunc(): allerror %d, eofentry %lu\n", 528 allerror, eofentry); 529 #endif 530 531 /* 532 * If we need to break the cluster chain for the file then do it 533 * now. 534 */ 535 if (eofentry != ~0) { 536 error = fatentry(FAT_GET_AND_SET, pmp, eofentry, 537 &chaintofree, CLUST_EOFE); 538 if (error) { 539 #ifdef MSDOSFS_DEBUG 540 printf("detrunc(): fatentry errors %d\n", error); 541 #endif 542 return (error); 543 } 544 fc_setcache(dep, FC_LASTFC, de_cluster(pmp, length - 1), 545 eofentry); 546 } 547 548 /* 549 * Now free the clusters removed from the file because of the 550 * truncation. 551 */ 552 if (chaintofree != 0 && !MSDOSFSEOF(pmp, chaintofree)) 553 freeclusterchain(pmp, chaintofree); 554 555 return (allerror); 556 } 557 558 /* 559 * Extend the file described by dep to length specified by length. 560 */ 561 int 562 deextend(dep, length, cred) 563 struct denode *dep; 564 u_long length; 565 struct ucred *cred; 566 { 567 struct msdosfsmount *pmp = dep->de_pmp; 568 u_long count; 569 int error; 570 571 /* 572 * The root of a DOS filesystem cannot be extended. 573 */ 574 if ((DETOV(dep)->v_vflag & VV_ROOT) && !FAT32(pmp)) 575 return (EINVAL); 576 577 /* 578 * Directories cannot be extended. 579 */ 580 if (dep->de_Attributes & ATTR_DIRECTORY) 581 return (EISDIR); 582 583 if (length <= dep->de_FileSize) 584 panic("deextend: file too large"); 585 586 /* 587 * Compute the number of clusters to allocate. 588 */ 589 count = de_clcount(pmp, length) - de_clcount(pmp, dep->de_FileSize); 590 if (count > 0) { 591 if (count > pmp->pm_freeclustercount) 592 return (ENOSPC); 593 error = extendfile(dep, count, NULL, NULL, DE_CLEAR); 594 if (error) { 595 /* truncate the added clusters away again */ 596 (void) detrunc(dep, dep->de_FileSize, 0, cred, NULL); 597 return (error); 598 } 599 } 600 dep->de_FileSize = length; 601 dep->de_flag |= DE_UPDATE|DE_MODIFIED; 602 return (deupdat(dep, 1)); 603 } 604 605 /* 606 * Move a denode to its correct hash queue after the file it represents has 607 * been moved to a new directory. 608 */ 609 void 610 reinsert(dep) 611 struct denode *dep; 612 { 613 /* 614 * Fix up the denode cache. If the denode is for a directory, 615 * there is nothing to do since the hash is based on the starting 616 * cluster of the directory file and that hasn't changed. If for a 617 * file the hash is based on the location of the directory entry, 618 * so we must remove it from the cache and re-enter it with the 619 * hash based on the new location of the directory entry. 620 */ 621 if (dep->de_Attributes & ATTR_DIRECTORY) 622 return; 623 msdosfs_hashrem(dep); 624 msdosfs_hashins(dep); 625 } 626 627 int 628 msdosfs_reclaim(ap) 629 struct vop_reclaim_args /* { 630 struct vnode *a_vp; 631 } */ *ap; 632 { 633 struct vnode *vp = ap->a_vp; 634 struct denode *dep = VTODE(vp); 635 636 #ifdef MSDOSFS_DEBUG 637 printf("msdosfs_reclaim(): dep %p, file %s, refcnt %ld\n", 638 dep, dep->de_Name, dep->de_refcnt); 639 #endif 640 641 if (prtactive && vrefcnt(vp) != 0) 642 vprint("msdosfs_reclaim(): pushing active", vp); 643 /* 644 * Remove the denode from its hash chain. 645 */ 646 msdosfs_hashrem(dep); 647 /* 648 * Purge old data structures associated with the denode. 649 */ 650 if (dep->de_devvp) { 651 vrele(dep->de_devvp); 652 dep->de_devvp = 0; 653 } 654 #if 0 /* XXX */ 655 dep->de_flag = 0; 656 #endif 657 FREE(dep, M_MSDOSFSNODE); 658 vp->v_data = NULL; 659 660 return (0); 661 } 662 663 int 664 msdosfs_inactive(ap) 665 struct vop_inactive_args /* { 666 struct vnode *a_vp; 667 struct thread *a_td; 668 } */ *ap; 669 { 670 struct vnode *vp = ap->a_vp; 671 struct denode *dep = VTODE(vp); 672 struct thread *td = ap->a_td; 673 int error = 0; 674 675 #ifdef MSDOSFS_DEBUG 676 printf("msdosfs_inactive(): dep %p, de_Name[0] %x\n", dep, dep->de_Name[0]); 677 #endif 678 679 if (prtactive && vrefcnt(vp) != 0) 680 vprint("msdosfs_inactive(): pushing active", vp); 681 682 /* 683 * Ignore denodes related to stale file handles. 684 */ 685 if (dep->de_Name[0] == SLOT_DELETED) 686 goto out; 687 688 /* 689 * If the file has been deleted and it is on a read/write 690 * filesystem, then truncate the file, and mark the directory slot 691 * as empty. (This may not be necessary for the dos filesystem.) 692 */ 693 #ifdef MSDOSFS_DEBUG 694 printf("msdosfs_inactive(): dep %p, refcnt %ld, mntflag %x, MNT_RDONLY %x\n", 695 dep, dep->de_refcnt, vp->v_mount->mnt_flag, MNT_RDONLY); 696 #endif 697 if (dep->de_refcnt <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { 698 error = detrunc(dep, (u_long) 0, 0, NOCRED, td); 699 dep->de_flag |= DE_UPDATE; 700 dep->de_Name[0] = SLOT_DELETED; 701 } 702 deupdat(dep, 0); 703 704 out: 705 VOP_UNLOCK(vp, 0, td); 706 /* 707 * If we are done with the denode, reclaim it 708 * so that it can be reused immediately. 709 */ 710 #ifdef MSDOSFS_DEBUG 711 printf("msdosfs_inactive(): v_usecount %d, de_Name[0] %x\n", 712 vrefcnt(vp), dep->de_Name[0]); 713 #endif 714 if (dep->de_Name[0] == SLOT_DELETED) 715 vrecycle(vp, NULL, td); 716 return (error); 717 } 718