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, u_int64_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, u_int64_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(dep, ddep, depp, cnp)
598 struct denode **depp;
599 struct componentname *cnp;
602 u_long dirclust, diroffset;
603 struct direntry *ndep;
604 struct msdosfsmount *pmp = ddep->de_pmp;
610 printf("createde(dep %p, ddep %p, depp %p, cnp %p)\n",
611 dep, ddep, depp, cnp);
615 * If no space left in the directory then allocate another cluster
616 * and chain it onto the end of the file. There is one exception
617 * to this. That is, if the root directory has no more space it
618 * can NOT be expanded. extendfile() checks for and fails attempts
619 * to extend the root directory. We just return an error in that
622 if (ddep->de_fndoffset >= ddep->de_FileSize) {
623 diroffset = ddep->de_fndoffset + sizeof(struct direntry)
625 dirclust = de_clcount(pmp, diroffset);
626 error = extendfile(ddep, dirclust, 0, 0, DE_CLEAR);
628 (void)detrunc(ddep, ddep->de_FileSize, 0, NOCRED);
633 * Update the size of the directory
635 ddep->de_FileSize += de_cn2off(pmp, dirclust);
639 * We just read in the cluster with space. Copy the new directory
640 * entry in. Then write it to disk. NOTE: DOS directories
641 * do not get smaller as clusters are emptied.
643 error = pcbmap(ddep, de_cluster(pmp, ddep->de_fndoffset),
644 &bn, &dirclust, &blsize);
647 diroffset = ddep->de_fndoffset;
648 if (dirclust != MSDOSFSROOT)
649 diroffset &= pmp->pm_crbomask;
650 if ((error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp)) != 0) {
654 ndep = bptoep(pmp, bp, ddep->de_fndoffset);
656 DE_EXTERNALIZE(ndep, dep);
659 * Now write the Win95 long name
661 if (ddep->de_fndcnt > 0) {
662 u_int8_t chksum = winChksum(ndep->deName);
663 const u_char *un = (const u_char *)cnp->cn_nameptr;
664 int unlen = cnp->cn_namelen;
667 while (--ddep->de_fndcnt >= 0) {
668 if (!(ddep->de_fndoffset & pmp->pm_crbomask)) {
669 if (DOINGASYNC(DETOV(ddep)))
671 else if ((error = bwrite(bp)) != 0)
674 ddep->de_fndoffset -= sizeof(struct direntry);
682 error = bread(pmp->pm_devvp, bn, blsize,
688 ndep = bptoep(pmp, bp, ddep->de_fndoffset);
691 ddep->de_fndoffset -= sizeof(struct direntry);
693 if (!unix2winfn(un, unlen, (struct winentry *)ndep,
699 if (DOINGASYNC(DETOV(ddep)))
701 else if ((error = bwrite(bp)) != 0)
705 * If they want us to return with the denode gotten.
708 if (dep->de_Attributes & ATTR_DIRECTORY) {
709 dirclust = dep->de_StartCluster;
710 if (FAT32(pmp) && dirclust == pmp->pm_rootdirblk)
711 dirclust = MSDOSFSROOT;
712 if (dirclust == MSDOSFSROOT)
713 diroffset = MSDOSFSROOT_OFS;
717 return deget(pmp, dirclust, diroffset, depp);
724 * Be sure a directory is empty except for "." and "..". Return 1 if empty,
725 * return 0 if not empty or error.
736 struct msdosfsmount *pmp = dep->de_pmp;
737 struct direntry *dentp;
740 * Since the filesize field in directory entries for a directory is
741 * zero, we just have to feel our way through the directory until
742 * we hit end of file.
744 for (cn = 0;; cn++) {
745 if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
747 return (1); /* it's empty */
750 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
755 for (dentp = (struct direntry *)bp->b_data;
756 (char *)dentp < bp->b_data + blsize;
758 if (dentp->deName[0] != SLOT_DELETED &&
759 (dentp->deAttributes & ATTR_VOLUME) == 0) {
761 * In dos directories an entry whose name
762 * starts with SLOT_EMPTY (0) starts the
763 * beginning of the unused part of the
764 * directory, so we can just return that it
767 if (dentp->deName[0] == SLOT_EMPTY) {
772 * Any names other than "." and ".." in a
773 * directory mean it is not empty.
775 if (bcmp(dentp->deName, ". ", 11) &&
776 bcmp(dentp->deName, ".. ", 11)) {
779 printf("dosdirempty(): entry found %02x, %02x\n",
780 dentp->deName[0], dentp->deName[1]);
782 return (0); /* not empty */
792 * Check to see if the directory described by target is in some
793 * subdirectory of source. This prevents something like the following from
794 * succeeding and leaving a bunch or files and directories orphaned. mv
795 * /a/b/c /a/b/c/d/e/f Where c and f are directories.
797 * source - the inode for /a/b/c
798 * target - the inode for /a/b/c/d/e/f
800 * Returns 0 if target is NOT a subdirectory of source.
801 * Otherwise returns a non-zero error number.
802 * The target inode is always unlocked on return.
805 doscheckpath(source, target)
806 struct denode *source;
807 struct denode *target;
810 struct msdosfsmount *pmp;
813 struct buf *bp = NULL;
817 if ((target->de_Attributes & ATTR_DIRECTORY) == 0 ||
818 (source->de_Attributes & ATTR_DIRECTORY) == 0) {
822 if (dep->de_StartCluster == source->de_StartCluster) {
826 if (dep->de_StartCluster == MSDOSFSROOT)
830 if (pmp != source->de_pmp)
831 panic("doscheckpath: source and target on different filesystems");
833 if (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)
837 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0) {
841 scn = dep->de_StartCluster;
842 error = bread(pmp->pm_devvp, cntobn(pmp, scn),
843 pmp->pm_bpcluster, NOCRED, &bp);
847 ep = (struct direntry *) bp->b_data + 1;
848 if ((ep->deAttributes & ATTR_DIRECTORY) == 0 ||
849 bcmp(ep->deName, ".. ", 11) != 0) {
853 scn = getushort(ep->deStartCluster);
855 scn |= getushort(ep->deHighClust) << 16;
857 if (scn == source->de_StartCluster) {
861 if (scn == MSDOSFSROOT)
863 if (FAT32(pmp) && scn == pmp->pm_rootdirblk) {
865 * scn should be 0 in this case,
866 * but we silently ignore the error.
874 /* NOTE: deget() clears dep on error */
875 if ((error = deget(pmp, scn, 0, &dep)) != 0)
882 if (error == ENOTDIR)
883 printf("doscheckpath(): .. not a directory?\n");
891 * Read in the disk block containing the directory entry (dirclu, dirofs)
892 * and return the address of the buf header, and the address of the
893 * directory entry within the block.
896 readep(pmp, dirclust, diroffset, bpp, epp)
897 struct msdosfsmount *pmp;
898 u_long dirclust, diroffset;
900 struct direntry **epp;
906 blsize = pmp->pm_bpcluster;
907 if (dirclust == MSDOSFSROOT
908 && de_blk(pmp, diroffset + blsize) > pmp->pm_rootdirsize)
909 blsize = de_bn2off(pmp, pmp->pm_rootdirsize) & pmp->pm_crbomask;
910 bn = detobn(pmp, dirclust, diroffset);
911 if ((error = bread(pmp->pm_devvp, bn, blsize, NOCRED, bpp)) != 0) {
917 *epp = bptoep(pmp, *bpp, diroffset);
922 * Read in the disk block containing the directory entry dep came from and
923 * return the address of the buf header, and the address of the directory
924 * entry within the block.
927 readde(dep, bpp, epp)
930 struct direntry **epp;
933 return (readep(dep->de_pmp, dep->de_dirclust, dep->de_diroffset,
938 * Remove a directory entry. At this point the file represented by the
939 * directory entry to be removed is still full length until noone has it
940 * open. When the file no longer being used msdosfs_inactive() is called
941 * and will truncate the file to 0 length. When the vnode containing the
942 * denode is needed for some other purpose by VFS it will call
943 * msdosfs_reclaim() which will remove the denode from the denode cache.
947 struct denode *pdep; /* directory where the entry is removed */
948 struct denode *dep; /* file to be removed */
955 struct msdosfsmount *pmp = pdep->de_pmp;
956 u_long offset = pdep->de_fndoffset;
959 printf("removede(): filename %s, dep %p, offset %08lx\n",
960 dep->de_Name, dep, offset);
964 offset += sizeof(struct direntry);
966 offset -= sizeof(struct direntry);
967 error = pcbmap(pdep, de_cluster(pmp, offset), &bn, 0, &blsize);
970 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
975 ep = bptoep(pmp, bp, offset);
977 * Check whether, if we came here the second time, i.e.
978 * when underflowing into the previous block, the last
979 * entry in this block is a longfilename entry, too.
981 if (ep->deAttributes != ATTR_WIN95
982 && offset != pdep->de_fndoffset) {
986 offset += sizeof(struct direntry);
989 * We are a bit agressive here in that we delete any Win95
990 * entries preceding this entry, not just the ones we "own".
991 * Since these presumably aren't valid anyway,
992 * there should be no harm.
994 offset -= sizeof(struct direntry);
995 ep--->deName[0] = SLOT_DELETED;
996 if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95)
997 || !(offset & pmp->pm_crbomask)
998 || ep->deAttributes != ATTR_WIN95)
1001 if (DOINGASYNC(DETOV(pdep)))
1003 else if ((error = bwrite(bp)) != 0)
1005 } while (!(pmp->pm_flags & MSDOSFSMNT_NOWIN95)
1006 && !(offset & pmp->pm_crbomask)
1012 * Create a unique DOS name in dvp
1015 uniqdosname(dep, cnp, cp)
1017 struct componentname *cnp;
1020 struct msdosfsmount *pmp = dep->de_pmp;
1021 struct direntry *dentp;
1029 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1030 return (unix2dosfn((const u_char *)cnp->cn_nameptr, cp,
1031 cnp->cn_namelen, 0, pmp) ? 0 : EINVAL);
1033 for (gen = 1;; gen++) {
1035 * Generate DOS name with generation number
1037 if (!unix2dosfn((const u_char *)cnp->cn_nameptr, cp,
1038 cnp->cn_namelen, gen, pmp))
1039 return gen == 1 ? EINVAL : EEXIST;
1042 * Now look for a dir entry with this exact name
1044 for (cn = error = 0; !error; cn++) {
1045 if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
1046 if (error == E2BIG) /* EOF reached and not found */
1050 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1055 for (dentp = (struct direntry *)bp->b_data;
1056 (char *)dentp < bp->b_data + blsize;
1058 if (dentp->deName[0] == SLOT_EMPTY) {
1060 * Last used entry and not found
1066 * Ignore volume labels and Win95 entries
1068 if (dentp->deAttributes & ATTR_VOLUME)
1070 if (!bcmp(dentp->deName, cp, 11)) {
1081 * Find any Win'95 long filename entry in directory dep
1087 struct msdosfsmount *pmp = dep->de_pmp;
1088 struct direntry *dentp;
1096 * Read through the directory looking for Win'95 entries
1097 * Note: Error currently handled just as EOF XXX
1099 for (cn = 0;; cn++) {
1100 if (pcbmap(dep, cn, &bn, 0, &blsize))
1102 if (bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp)) {
1106 for (dentp = (struct direntry *)bp->b_data;
1107 (char *)dentp < bp->b_data + blsize;
1109 if (dentp->deName[0] == SLOT_EMPTY) {
1111 * Last used entry and not found
1116 if (dentp->deName[0] == SLOT_DELETED) {
1118 * Ignore deleted files
1119 * Note: might be an indication of Win'95 anyway XXX
1123 if (dentp->deAttributes == ATTR_WIN95) {