2 /* $NetBSD: msdosfs_lookup.c,v 1.37 1997/11/17 15:36:54 ws Exp $ */
5 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
6 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
36 * Written by Paul Popelka (paulp@uts.amdahl.com)
38 * You can do anything you want with this software, just don't say you wrote
39 * it, and don't remove this notice.
41 * This software is provided "as is".
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.
51 #include <sys/param.h>
52 #include <sys/systm.h>
54 #include <sys/mount.h>
55 #include <sys/namei.h>
56 #include <sys/vnode.h>
58 #include <fs/msdosfs/bpb.h>
59 #include <fs/msdosfs/direntry.h>
60 #include <fs/msdosfs/denode.h>
61 #include <fs/msdosfs/fat.h>
62 #include <fs/msdosfs/msdosfsmount.h>
64 static int msdosfs_lookup_(struct vnode *vdp, struct vnode **vpp,
65 struct componentname *cnp, uint64_t *inum);
68 msdosfs_lookup(struct vop_cachedlookup_args *ap)
71 return (msdosfs_lookup_(ap->a_dvp, ap->a_vpp, ap->a_cnp, NULL));
80 msdosfs_deget_dotdot(struct mount *mp, void *arg, int lkflags,
83 struct deget_dotdot *dd_arg;
85 struct msdosfsmount *pmp;
88 pmp = VFSTOMSDOSFS(mp);
90 error = deget(pmp, dd_arg->cluster, dd_arg->blkoff, &rdp);
97 * When we search a directory the blocks containing directory entries are
98 * read and examined. The directory entries contain information that would
99 * normally be in the inode of a unix filesystem. This means that some of
100 * a directory's contents may also be in memory resident denodes (sort of
101 * an inode). This can cause problems if we are searching while some other
102 * process is modifying a directory. To prevent one process from accessing
103 * incompletely modified directory information we depend upon being the
104 * sole owner of a directory block. bread/brelse provide this service.
105 * This being the case, when a process modifies a directory it must first
106 * acquire the disk block that contains the directory entry to be modified.
107 * Then update the disk block and the denode, and then write the disk block
108 * out to disk. This way disk blocks containing directory entries and in
109 * memory denode's will be in synch.
112 msdosfs_lookup_(struct vnode *vdp, struct vnode **vpp,
113 struct componentname *cnp, uint64_t *dd_inum)
125 int isadir; /* ~0 if found direntry is a directory */
126 u_long scn; /* starting cluster number */
130 struct msdosfsmount *pmp;
131 struct buf *bp = NULL;
132 struct direntry *dep = NULL;
133 struct deget_dotdot dd_arg;
134 u_char dosfilename[12];
135 int flags = cnp->cn_flags;
136 int nameiop = cnp->cn_nameiop;
141 int chksum = -1, chksum_ok;
145 printf("msdosfs_lookup(): looking for %s\n", cnp->cn_nameptr);
150 printf("msdosfs_lookup(): vdp %p, dp %p, Attr %02x\n",
151 vdp, dp, dp->de_Attributes);
158 * If they are going after the . or .. entry in the root directory,
159 * they won't find it. DOS filesystems don't have them in the root
160 * directory. So, we fake it. deget() is in on this scam too.
162 if ((vdp->v_vflag & VV_ROOT) && cnp->cn_nameptr[0] == '.' &&
163 (cnp->cn_namelen == 1 ||
164 (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] == '.'))) {
165 isadir = ATTR_DIRECTORY;
168 printf("msdosfs_lookup(): looking for . or .. in root directory\n");
170 cluster = MSDOSFSROOT;
171 blkoff = MSDOSFSROOT_OFS;
175 switch (unix2dosfn((const u_char *)cnp->cn_nameptr, dosfilename,
176 cnp->cn_namelen, 0, pmp)) {
182 wincnt = winSlotCnt((const u_char *)cnp->cn_nameptr,
183 cnp->cn_namelen, pmp) + 1;
187 wincnt = winSlotCnt((const u_char *)cnp->cn_nameptr,
188 cnp->cn_namelen, pmp) + 1;
191 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME) {
195 unlen = winLenFixup(cnp->cn_nameptr, cnp->cn_namelen);
198 * Suppress search for slots unless creating
199 * file and at end of pathname, in which case
200 * we watch for a place to put the new file in
201 * case it doesn't already exist.
204 if ((nameiop == CREATE || nameiop == RENAME) &&
209 printf("msdosfs_lookup(): dos version of filename %s, length %ld\n",
210 dosfilename, cnp->cn_namelen);
213 * Search the directory pointed at by vdp for the name pointed at
214 * by cnp->cn_nameptr.
219 * The outer loop ranges over the clusters that make up the
220 * directory. Note that the root directory is different from all
221 * other directories. It has a fixed number of blocks that are not
222 * part of the pool of allocatable clusters. So, we treat it a
223 * little differently. The root directory starts at "cluster" 0.
226 for (frcn = 0;; frcn++) {
227 error = pcbmap(dp, frcn, &bn, &cluster, &blsize);
233 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
238 for (blkoff = 0; blkoff < blsize;
239 blkoff += sizeof(struct direntry),
240 diroff += sizeof(struct direntry)) {
241 dep = (struct direntry *)(bp->b_data + blkoff);
243 * If the slot is empty and we are still looking
244 * for an empty then remember this one. If the
245 * slot is not empty then check to see if it
246 * matches what we are looking for. If the slot
247 * has never been filled with anything, then the
248 * remainder of the directory has never been used,
249 * so there is no point in searching it.
251 if (dep->deName[0] == SLOT_EMPTY ||
252 dep->deName[0] == SLOT_DELETED) {
254 * Drop memory of previous long matches
259 if (slotcount < wincnt) {
263 if (dep->deName[0] == SLOT_EMPTY) {
269 * If there wasn't enough space for our winentries,
270 * forget about the empty space
272 if (slotcount < wincnt)
276 * Check for Win95 long filename entry
278 if (dep->deAttributes == ATTR_WIN95) {
279 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
282 chksum = win2unixfn(&nb,
283 (struct winentry *)dep, chksum,
288 chksum = winChkName(&nb,
289 (const u_char *)cnp->cn_nameptr, unlen,
297 * Ignore volume labels (anywhere, not just
298 * the root directory).
300 if (dep->deAttributes & ATTR_VOLUME) {
306 * Check for a checksum or name match
308 chksum_ok = (chksum == winChksum(dep->deName));
310 && (!olddos || bcmp(dosfilename, dep->deName, 11))) {
315 printf("msdosfs_lookup(): match blkoff %d, diroff %d\n",
319 * Remember where this directory
320 * entry came from for whoever did
323 dp->de_fndoffset = diroff;
324 if (chksum_ok && nameiop == RENAME) {
326 * Target had correct long name
327 * directory entries, reuse them
330 dp->de_fndcnt = wincnt - 1;
333 * Long name directory entries
334 * not present or corrupt, can only
335 * reuse dos directory entry.
342 } /* for (blkoff = 0; .... */
344 * Release the buffer holding the directory cluster just
348 } /* for (frcn = 0; ; frcn++) */
352 * We hold no disk buffers at this point.
356 * Fixup the slot description to point to the place where
357 * we might put the new DOS direntry (putting the Win95
358 * long name entries before that)
364 if (wincnt > slotcount)
365 slotoffset += sizeof(struct direntry) * (wincnt - slotcount);
368 * If we get here we didn't find the entry we were looking for. But
369 * that's ok if we are creating or renaming and are at the end of
370 * the pathname and the directory hasn't been removed.
373 printf("msdosfs_lookup(): op %d, refcnt %ld\n",
374 nameiop, dp->de_refcnt);
375 printf(" slotcount %d, slotoffset %d\n",
376 slotcount, slotoffset);
378 if ((nameiop == CREATE || nameiop == RENAME) &&
379 (flags & ISLASTCN) && dp->de_refcnt != 0) {
381 * Access for write is interpreted as allowing
382 * creation of files in the directory.
384 error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, cnp->cn_thread);
388 * Return an indication of where the new directory
389 * entry should be put.
391 dp->de_fndoffset = slotoffset;
392 dp->de_fndcnt = wincnt - 1;
395 * We return with the directory locked, so that
396 * the parameters we set up above will still be
397 * valid if we actually decide to do a direnter().
398 * We return ni_vp == NULL to indicate that the entry
399 * does not currently exist; we leave a pointer to
400 * the (locked) directory inode in ndp->ni_dvp.
401 * The pathname buffer is saved so that the name
402 * can be obtained later.
404 * NB - if the directory is unlocked, then this
405 * information cannot be used.
407 cnp->cn_flags |= SAVENAME;
408 return (EJUSTRETURN);
412 * Insert name into cache (as non-existent) if appropriate.
414 * XXX Negative caching is broken for msdosfs because the name
415 * cache doesn't understand peculiarities such as case insensitivity
416 * and 8.3 filenames. Hence, it may not invalidate all negative
417 * entries if a file with this name is later created.
419 if ((cnp->cn_flags & MAKEENTRY) != 0)
420 cache_enter(vdp, *vpp, cnp);
426 * NOTE: We still have the buffer with matched directory entry at
429 isadir = dep->deAttributes & ATTR_DIRECTORY;
430 scn = getushort(dep->deStartCluster);
432 scn |= getushort(dep->deHighClust) << 16;
433 if (scn == pmp->pm_rootdirblk) {
435 * There should actually be 0 here.
436 * Just ignore the error.
444 if (cluster == MSDOSFSROOT)
445 blkoff = MSDOSFSROOT_OFS;
448 } else if (cluster == MSDOSFSROOT)
452 * Now release buf to allow deget to read the entry again.
453 * Reserving it here and giving it to deget could result
461 * If we entered at foundroot, then we are looking for the . or ..
462 * entry of the filesystems root directory. isadir and scn were
463 * setup before jumping here. And, bp is already null.
465 if (FAT32(pmp) && scn == MSDOSFSROOT)
466 scn = pmp->pm_rootdirblk;
468 if (dd_inum != NULL) {
469 *dd_inum = (uint64_t)pmp->pm_bpcluster * scn + blkoff;
474 * If deleting, and at end of pathname, return
475 * parameters which can be used to remove file.
477 if (nameiop == DELETE && (flags & ISLASTCN)) {
479 * Don't allow deleting the root.
481 if (blkoff == MSDOSFSROOT_OFS)
485 * Write access to directory required to delete files.
487 error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, cnp->cn_thread);
492 * Return pointer to current entry in dp->i_offset.
493 * Save directory inode pointer in ndp->ni_dvp for dirremove().
495 if (dp->de_StartCluster == scn && isadir) { /* "." */
500 error = deget(pmp, cluster, blkoff, &tdp);
508 * If rewriting (RENAME), return the inode and the
509 * information required to rewrite the present directory
510 * Must get inode of directory entry to verify it's a
511 * regular file, or empty directory.
513 if (nameiop == RENAME && (flags & ISLASTCN)) {
514 if (blkoff == MSDOSFSROOT_OFS)
517 error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, cnp->cn_thread);
522 * Careful about locking second inode.
523 * This can only occur if the target is ".".
525 if (dp->de_StartCluster == scn && isadir)
528 if ((error = deget(pmp, cluster, blkoff, &tdp)) != 0)
531 cnp->cn_flags |= SAVENAME;
536 * Step through the translation in the name. We do not `vput' the
537 * directory because we may need it again if a symbolic link
538 * is relative to the current directory. Instead we save it
539 * unlocked as "pdp". We must get the target inode before unlocking
540 * the directory to insure that the inode will not be removed
541 * before we get it. We prevent deadlock by always fetching
542 * inodes from the root, moving down the directory tree. Thus
543 * when following backward pointers ".." we must unlock the
544 * parent directory before getting the requested directory.
547 if (flags & ISDOTDOT) {
548 dd_arg.cluster = cluster;
549 dd_arg.blkoff = blkoff;
550 error = vn_vget_ino_gen(vdp, msdosfs_deget_dotdot,
551 &dd_arg, cnp->cn_lkflags, vpp);
557 * Recheck that ".." still points to the inode we
558 * looked up before pdp lock was dropped.
560 error = msdosfs_lookup_(pdp, NULL, cnp, &inode1);
566 if (VTODE(*vpp)->de_inode != inode1) {
570 } else if (dp->de_StartCluster == scn && isadir) {
571 VREF(vdp); /* we want ourself, ie "." */
574 if ((error = deget(pmp, cluster, blkoff, &tdp)) != 0)
580 * Insert name into cache if appropriate.
582 if (cnp->cn_flags & MAKEENTRY)
583 cache_enter(vdp, *vpp, cnp);
588 * dep - directory entry to copy into the directory
589 * ddep - directory to add to
590 * depp - return the address of the denode for the created directory entry
592 * cnp - componentname needed for Win95 long filenames
595 createde(struct denode *dep, struct denode *ddep, struct denode **depp,
596 struct componentname *cnp)
599 u_long dirclust, diroffset;
600 struct direntry *ndep;
601 struct msdosfsmount *pmp = ddep->de_pmp;
607 printf("createde(dep %p, ddep %p, depp %p, cnp %p)\n",
608 dep, ddep, depp, cnp);
612 * If no space left in the directory then allocate another cluster
613 * and chain it onto the end of the file. There is one exception
614 * to this. That is, if the root directory has no more space it
615 * can NOT be expanded. extendfile() checks for and fails attempts
616 * to extend the root directory. We just return an error in that
619 if (ddep->de_fndoffset >= ddep->de_FileSize) {
620 diroffset = ddep->de_fndoffset + sizeof(struct direntry)
622 dirclust = de_clcount(pmp, diroffset);
623 error = extendfile(ddep, dirclust, 0, 0, DE_CLEAR);
625 (void)detrunc(ddep, ddep->de_FileSize, 0, NOCRED);
630 * Update the size of the directory
632 ddep->de_FileSize += de_cn2off(pmp, dirclust);
636 * We just read in the cluster with space. Copy the new directory
637 * entry in. Then write it to disk. NOTE: DOS directories
638 * do not get smaller as clusters are emptied.
640 error = pcbmap(ddep, de_cluster(pmp, ddep->de_fndoffset),
641 &bn, &dirclust, &blsize);
644 diroffset = ddep->de_fndoffset;
645 if (dirclust != MSDOSFSROOT)
646 diroffset &= pmp->pm_crbomask;
647 if ((error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp)) != 0) {
651 ndep = bptoep(pmp, bp, ddep->de_fndoffset);
653 DE_EXTERNALIZE(ndep, dep);
656 * Now write the Win95 long name
658 if (ddep->de_fndcnt > 0) {
659 uint8_t chksum = winChksum(ndep->deName);
660 const u_char *un = (const u_char *)cnp->cn_nameptr;
661 int unlen = cnp->cn_namelen;
664 while (--ddep->de_fndcnt >= 0) {
665 if (!(ddep->de_fndoffset & pmp->pm_crbomask)) {
666 if (DOINGASYNC(DETOV(ddep)))
668 else if ((error = bwrite(bp)) != 0)
671 ddep->de_fndoffset -= sizeof(struct direntry);
679 error = bread(pmp->pm_devvp, bn, blsize,
685 ndep = bptoep(pmp, bp, ddep->de_fndoffset);
688 ddep->de_fndoffset -= sizeof(struct direntry);
690 if (!unix2winfn(un, unlen, (struct winentry *)ndep,
696 if (DOINGASYNC(DETOV(ddep)))
698 else if ((error = bwrite(bp)) != 0)
702 * If they want us to return with the denode gotten.
705 if (dep->de_Attributes & ATTR_DIRECTORY) {
706 dirclust = dep->de_StartCluster;
707 if (FAT32(pmp) && dirclust == pmp->pm_rootdirblk)
708 dirclust = MSDOSFSROOT;
709 if (dirclust == MSDOSFSROOT)
710 diroffset = MSDOSFSROOT_OFS;
714 return deget(pmp, dirclust, diroffset, depp);
721 * Be sure a directory is empty except for "." and "..". Return 1 if empty,
722 * return 0 if not empty or error.
725 dosdirempty(struct denode *dep)
732 struct msdosfsmount *pmp = dep->de_pmp;
733 struct direntry *dentp;
736 * Since the filesize field in directory entries for a directory is
737 * zero, we just have to feel our way through the directory until
738 * we hit end of file.
740 for (cn = 0;; cn++) {
741 if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
743 return (1); /* it's empty */
746 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
751 for (dentp = (struct direntry *)bp->b_data;
752 (char *)dentp < bp->b_data + blsize;
754 if (dentp->deName[0] != SLOT_DELETED &&
755 (dentp->deAttributes & ATTR_VOLUME) == 0) {
757 * In dos directories an entry whose name
758 * starts with SLOT_EMPTY (0) starts the
759 * beginning of the unused part of the
760 * directory, so we can just return that it
763 if (dentp->deName[0] == SLOT_EMPTY) {
768 * Any names other than "." and ".." in a
769 * directory mean it is not empty.
771 if (bcmp(dentp->deName, ". ", 11) &&
772 bcmp(dentp->deName, ".. ", 11)) {
775 printf("dosdirempty(): entry found %02x, %02x\n",
776 dentp->deName[0], dentp->deName[1]);
778 return (0); /* not empty */
788 * Check to see if the directory described by target is in some
789 * subdirectory of source. This prevents something like the following from
790 * succeeding and leaving a bunch or files and directories orphaned. mv
791 * /a/b/c /a/b/c/d/e/f Where c and f are directories.
793 * source - the inode for /a/b/c
794 * target - the inode for /a/b/c/d/e/f
796 * Returns 0 if target is NOT a subdirectory of source.
797 * Otherwise returns a non-zero error number.
798 * The target inode is always unlocked on return.
801 doscheckpath(struct denode *source, struct denode *target)
804 struct msdosfsmount *pmp;
807 struct buf *bp = NULL;
811 if ((target->de_Attributes & ATTR_DIRECTORY) == 0 ||
812 (source->de_Attributes & ATTR_DIRECTORY) == 0) {
816 if (dep->de_StartCluster == source->de_StartCluster) {
820 if (dep->de_StartCluster == MSDOSFSROOT)
824 if (pmp != source->de_pmp)
825 panic("doscheckpath: source and target on different filesystems");
827 if (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)
831 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0) {
835 scn = dep->de_StartCluster;
836 error = bread(pmp->pm_devvp, cntobn(pmp, scn),
837 pmp->pm_bpcluster, NOCRED, &bp);
841 ep = (struct direntry *) bp->b_data + 1;
842 if ((ep->deAttributes & ATTR_DIRECTORY) == 0 ||
843 bcmp(ep->deName, ".. ", 11) != 0) {
847 scn = getushort(ep->deStartCluster);
849 scn |= getushort(ep->deHighClust) << 16;
851 if (scn == source->de_StartCluster) {
855 if (scn == MSDOSFSROOT)
857 if (FAT32(pmp) && scn == pmp->pm_rootdirblk) {
859 * scn should be 0 in this case,
860 * but we silently ignore the error.
868 /* NOTE: deget() clears dep on error */
869 if ((error = deget(pmp, scn, 0, &dep)) != 0)
876 if (error == ENOTDIR)
877 printf("doscheckpath(): .. not a directory?\n");
885 * Read in the disk block containing the directory entry (dirclu, dirofs)
886 * and return the address of the buf header, and the address of the
887 * directory entry within the block.
890 readep(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset,
891 struct buf **bpp, struct direntry **epp)
897 blsize = pmp->pm_bpcluster;
898 if (dirclust == MSDOSFSROOT
899 && de_blk(pmp, diroffset + blsize) > pmp->pm_rootdirsize)
900 blsize = de_bn2off(pmp, pmp->pm_rootdirsize) & pmp->pm_crbomask;
901 bn = detobn(pmp, dirclust, diroffset);
902 if ((error = bread(pmp->pm_devvp, bn, blsize, NOCRED, bpp)) != 0) {
908 *epp = bptoep(pmp, *bpp, diroffset);
913 * Read in the disk block containing the directory entry dep came from and
914 * return the address of the buf header, and the address of the directory
915 * entry within the block.
918 readde(struct denode *dep, struct buf **bpp, struct direntry **epp)
921 return (readep(dep->de_pmp, dep->de_dirclust, dep->de_diroffset,
926 * Remove a directory entry. At this point the file represented by the
927 * directory entry to be removed is still full length until no one has it
928 * open. When the file no longer being used msdosfs_inactive() is called
929 * and will truncate the file to 0 length. When the vnode containing the
930 * denode is needed for some other purpose by VFS it will call
931 * msdosfs_reclaim() which will remove the denode from the denode cache.
933 * pdep directory where the entry is removed
934 * dep file to be removed
937 removede(struct denode *pdep, struct denode *dep)
944 struct msdosfsmount *pmp = pdep->de_pmp;
945 u_long offset = pdep->de_fndoffset;
948 printf("removede(): filename %s, dep %p, offset %08lx\n",
949 dep->de_Name, dep, offset);
953 offset += sizeof(struct direntry);
955 offset -= sizeof(struct direntry);
956 error = pcbmap(pdep, de_cluster(pmp, offset), &bn, 0, &blsize);
959 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
964 ep = bptoep(pmp, bp, offset);
966 * Check whether, if we came here the second time, i.e.
967 * when underflowing into the previous block, the last
968 * entry in this block is a longfilename entry, too.
970 if (ep->deAttributes != ATTR_WIN95
971 && offset != pdep->de_fndoffset) {
975 offset += sizeof(struct direntry);
978 * We are a bit aggressive here in that we delete any Win95
979 * entries preceding this entry, not just the ones we "own".
980 * Since these presumably aren't valid anyway,
981 * there should be no harm.
983 offset -= sizeof(struct direntry);
984 ep--->deName[0] = SLOT_DELETED;
985 if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95)
986 || !(offset & pmp->pm_crbomask)
987 || ep->deAttributes != ATTR_WIN95)
990 if (DOINGASYNC(DETOV(pdep)))
992 else if ((error = bwrite(bp)) != 0)
994 } while (!(pmp->pm_flags & MSDOSFSMNT_NOWIN95)
995 && !(offset & pmp->pm_crbomask)
1001 * Create a unique DOS name in dvp
1004 uniqdosname(struct denode *dep, struct componentname *cnp, u_char *cp)
1006 struct msdosfsmount *pmp = dep->de_pmp;
1007 struct direntry *dentp;
1015 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1016 return (unix2dosfn((const u_char *)cnp->cn_nameptr, cp,
1017 cnp->cn_namelen, 0, pmp) ? 0 : EINVAL);
1019 for (gen = 1;; gen++) {
1021 * Generate DOS name with generation number
1023 if (!unix2dosfn((const u_char *)cnp->cn_nameptr, cp,
1024 cnp->cn_namelen, gen, pmp))
1025 return gen == 1 ? EINVAL : EEXIST;
1028 * Now look for a dir entry with this exact name
1030 for (cn = error = 0; !error; cn++) {
1031 if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
1032 if (error == E2BIG) /* EOF reached and not found */
1036 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1041 for (dentp = (struct direntry *)bp->b_data;
1042 (char *)dentp < bp->b_data + blsize;
1044 if (dentp->deName[0] == SLOT_EMPTY) {
1046 * Last used entry and not found
1052 * Ignore volume labels and Win95 entries
1054 if (dentp->deAttributes & ATTR_VOLUME)
1056 if (!bcmp(dentp->deName, cp, 11)) {