1 /* $FreeBSD: src/sys/msdosfs/msdosfs_lookup.c,v 1.30.2.1 2000/11/03 15:55:39 bp Exp $ */
2 /* $DragonFly: src/sys/vfs/msdosfs/msdosfs_lookup.c,v 1.13 2004/11/12 00:09:36 dillon Exp $ */
3 /* $NetBSD: msdosfs_lookup.c,v 1.37 1997/11/17 15:36:54 ws Exp $ */
6 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
7 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
9 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by TooLs GmbH.
22 * 4. The name of TooLs GmbH may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Written by Paul Popelka (paulp@uts.amdahl.com)
39 * You can do anything you want with this software, just don't say you wrote
40 * it, and don't remove this notice.
42 * This software is provided "as is".
44 * The author supplies this software to be publicly redistributed on the
45 * understanding that the author is not responsible for the correct
46 * functioning of this software in any circumstances and is not liable for
47 * any damages caused by this software.
52 #include <sys/param.h>
53 #include <sys/systm.h>
55 #include <sys/vnode.h>
57 #include <sys/namei.h>
58 #include <sys/mount.h>
63 #include "msdosfsmount.h"
67 * When we search a directory the blocks containing directory entries are
68 * read and examined. The directory entries contain information that would
69 * normally be in the inode of a unix filesystem. This means that some of
70 * a directory's contents may also be in memory resident denodes (sort of
71 * an inode). This can cause problems if we are searching while some other
72 * process is modifying a directory. To prevent one process from accessing
73 * incompletely modified directory information we depend upon being the
74 * sole owner of a directory block. bread/brelse provide this service.
75 * This being the case, when a process modifies a directory it must first
76 * acquire the disk block that contains the directory entry to be modified.
77 * Then update the disk block and the denode, and then write the disk block
78 * out to disk. This way disk blocks containing directory entries and in
79 * memory denode's will be in synch.
81 * msdosfs_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
82 * struct componentname *a_cnp)
85 msdosfs_lookup(struct vop_lookup_args *ap)
87 struct vnode *vdp = ap->a_dvp;
88 struct vnode **vpp = ap->a_vpp;
89 struct componentname *cnp = ap->a_cnp;
101 int isadir; /* ~0 if found direntry is a directory */
102 u_long scn; /* starting cluster number */
106 struct msdosfsmount *pmp;
108 struct direntry *dep = NULL;
109 u_char dosfilename[12];
110 int flags = cnp->cn_flags;
111 int nameiop = cnp->cn_nameiop;
112 struct thread *td = cnp->cn_td;
118 cnp->cn_flags &= ~CNP_PDIRUNLOCK;
121 printf("msdosfs_lookup(): looking for %s\n", cnp->cn_nameptr);
126 lockparent = flags & CNP_LOCKPARENT;
127 wantparent = flags & (CNP_LOCKPARENT | CNP_WANTPARENT);
129 printf("msdosfs_lookup(): vdp %p, dp %p, Attr %02x\n",
130 vdp, dp, dp->de_Attributes);
134 * If they are going after the . or .. entry in the root directory,
135 * they won't find it. DOS filesystems don't have them in the root
136 * directory. So, we fake it. deget() is in on this scam too.
138 if ((vdp->v_flag & VROOT) && cnp->cn_nameptr[0] == '.' &&
139 (cnp->cn_namelen == 1 ||
140 (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] == '.'))) {
141 isadir = ATTR_DIRECTORY;
144 printf("msdosfs_lookup(): looking for . or .. in root directory\n");
146 cluster = MSDOSFSROOT;
147 blkoff = MSDOSFSROOT_OFS;
151 switch (unix2dosfn((const u_char *)cnp->cn_nameptr, dosfilename,
153 pmp->pm_flags & MSDOSFSMNT_U2WTABLE, pmp->pm_u2d,
154 pmp->pm_flags & MSDOSFSMNT_ULTABLE, pmp->pm_lu)) {
160 wincnt = winSlotCnt((const u_char *)cnp->cn_nameptr,
161 cnp->cn_namelen) + 1;
165 wincnt = winSlotCnt((const u_char *)cnp->cn_nameptr,
166 cnp->cn_namelen) + 1;
169 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME) {
173 unlen = winLenFixup(cnp->cn_nameptr, cnp->cn_namelen);
176 * Suppress search for slots unless creating
177 * file and at end of pathname, in which case
178 * we watch for a place to put the new file in
179 * case it doesn't already exist.
182 if (nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME)
186 printf("msdosfs_lookup(): dos version of filename %s, length %ld\n",
187 dosfilename, cnp->cn_namelen);
190 * Search the directory pointed at by vdp for the name pointed at
191 * by cnp->cn_nameptr.
195 * The outer loop ranges over the clusters that make up the
196 * directory. Note that the root directory is different from all
197 * other directories. It has a fixed number of blocks that are not
198 * part of the pool of allocatable clusters. So, we treat it a
199 * little differently. The root directory starts at "cluster" 0.
202 for (frcn = 0;; frcn++) {
203 error = pcbmap(dp, frcn, &bn, &cluster, &blsize);
209 error = bread(pmp->pm_devvp, bn, blsize, &bp);
214 for (blkoff = 0; blkoff < blsize;
215 blkoff += sizeof(struct direntry),
216 diroff += sizeof(struct direntry)) {
217 dep = (struct direntry *)(bp->b_data + blkoff);
219 * If the slot is empty and we are still looking
220 * for an empty then remember this one. If the
221 * slot is not empty then check to see if it
222 * matches what we are looking for. If the slot
223 * has never been filled with anything, then the
224 * remainder of the directory has never been used,
225 * so there is no point in searching it.
227 if (dep->deName[0] == SLOT_EMPTY ||
228 dep->deName[0] == SLOT_DELETED) {
230 * Drop memory of previous long matches
234 if (slotcount < wincnt) {
238 if (dep->deName[0] == SLOT_EMPTY) {
244 * If there wasn't enough space for our winentries,
245 * forget about the empty space
247 if (slotcount < wincnt)
251 * Check for Win95 long filename entry
253 if (dep->deAttributes == ATTR_WIN95) {
254 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
257 chksum = winChkName((const u_char *)cnp->cn_nameptr,
259 (struct winentry *)dep,
261 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
263 pmp->pm_flags & MSDOSFSMNT_ULTABLE,
269 * Ignore volume labels (anywhere, not just
270 * the root directory).
272 if (dep->deAttributes & ATTR_VOLUME) {
278 * Check for a checksum or name match
280 if (chksum != winChksum(dep->deName)
281 && (!olddos || bcmp(dosfilename, dep->deName, 11))) {
286 printf("msdosfs_lookup(): match blkoff %d, diroff %d\n",
290 * Remember where this directory
291 * entry came from for whoever did
294 dp->de_fndoffset = diroff;
295 dp->de_fndcnt = wincnt - 1;
299 } /* for (blkoff = 0; .... */
301 * Release the buffer holding the directory cluster just
305 } /* for (frcn = 0; ; frcn++) */
309 * We hold no disk buffers at this point.
313 * Fixup the slot description to point to the place where
314 * we might put the new DOS direntry (putting the Win95
315 * long name entries before that)
321 if (wincnt > slotcount)
322 slotoffset += sizeof(struct direntry) * (wincnt - slotcount);
325 * If we get here we didn't find the entry we were looking for. But
326 * that's ok if we are creating or renaming and are at the end of
327 * the pathname and the directory hasn't been removed.
330 printf("msdosfs_lookup(): op %d, refcnt %ld\n",
331 nameiop, dp->de_refcnt);
332 printf(" slotcount %d, slotoffset %d\n",
333 slotcount, slotoffset);
335 if ((nameiop == NAMEI_CREATE || nameiop == NAMEI_RENAME) &&
336 dp->de_refcnt != 0) {
338 * Access for write is interpreted as allowing
339 * creation of files in the directory.
341 error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, cnp->cn_td);
345 * Return an indication of where the new directory
346 * entry should be put.
348 dp->de_fndoffset = slotoffset;
349 dp->de_fndcnt = wincnt - 1;
352 * We return with the directory locked, so that
353 * the parameters we set up above will still be
354 * valid if we actually decide to do a direnter().
355 * We return ni_vp == NULL to indicate that the entry
356 * does not currently exist; we leave a pointer to
357 * the (locked) directory inode in ndp->ni_dvp.
358 * The pathname buffer is saved so that the name
359 * can be obtained later.
361 * NB - if the directory is unlocked, then this
362 * information cannot be used.
365 VOP_UNLOCK(vdp, 0, td);
366 cnp->cn_flags |= CNP_PDIRUNLOCK;
368 return (EJUSTRETURN);
374 * NOTE: We still have the buffer with matched directory entry at
377 isadir = dep->deAttributes & ATTR_DIRECTORY;
378 scn = getushort(dep->deStartCluster);
380 scn |= getushort(dep->deHighClust) << 16;
381 if (scn == pmp->pm_rootdirblk) {
383 * There should actually be 0 here.
384 * Just ignore the error.
392 if (cluster == MSDOSFSROOT)
393 blkoff = MSDOSFSROOT_OFS;
396 } else if (cluster == MSDOSFSROOT)
400 * Now release buf to allow deget to read the entry again.
401 * Reserving it here and giving it to deget could result
409 * If we entered at foundroot, then we are looking for the . or ..
410 * entry of the filesystems root directory. isadir and scn were
411 * setup before jumping here. And, bp is already null.
413 if (FAT32(pmp) && scn == MSDOSFSROOT)
414 scn = pmp->pm_rootdirblk;
417 * If deleting, and at end of pathname, return
418 * parameters which can be used to remove file.
419 * If the wantparent flag isn't set, we return only
420 * the directory (in ndp->ni_dvp), otherwise we go
421 * on and lock the inode, being careful with ".".
423 if (nameiop == NAMEI_DELETE) {
425 * Don't allow deleting the root.
427 if (blkoff == MSDOSFSROOT_OFS)
428 return EROFS; /* really? XXX */
431 * Write access to directory required to delete files.
433 error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, cnp->cn_td);
438 * Return pointer to current entry in dp->i_offset.
439 * Save directory inode pointer in ndp->ni_dvp for dirremove().
441 if (dp->de_StartCluster == scn && isadir) { /* "." */
446 error = deget(pmp, cluster, blkoff, &tdp);
451 VOP_UNLOCK(vdp, 0, td);
452 cnp->cn_flags |= CNP_PDIRUNLOCK;
458 * If rewriting (RENAME), return the inode and the
459 * information required to rewrite the present directory
460 * Must get inode of directory entry to verify it's a
461 * regular file, or empty directory.
463 if (nameiop == NAMEI_RENAME && wantparent) {
464 if (blkoff == MSDOSFSROOT_OFS)
465 return EROFS; /* really? XXX */
467 error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, cnp->cn_td);
472 * Careful about locking second inode.
473 * This can only occur if the target is ".".
475 if (dp->de_StartCluster == scn && isadir)
478 if ((error = deget(pmp, cluster, blkoff, &tdp)) != 0)
482 VOP_UNLOCK(vdp, 0, td);
483 cnp->cn_flags |= CNP_PDIRUNLOCK;
489 * Step through the translation in the name. We do not `vput' the
490 * directory because we may need it again if a symbolic link
491 * is relative to the current directory. Instead we save it
492 * unlocked as "pdp". We must get the target inode before unlocking
493 * the directory to insure that the inode will not be removed
494 * before we get it. We prevent deadlock by always fetching
495 * inodes from the root, moving down the directory tree. Thus
496 * when following backward pointers ".." we must unlock the
497 * parent directory before getting the requested directory.
498 * There is a potential race condition here if both the current
499 * and parent directories are removed before the VFS_VGET for the
500 * inode associated with ".." returns. We hope that this occurs
501 * infrequently since we cannot avoid this race condition without
502 * implementing a sophisticated deadlock detection algorithm.
503 * Note also that this simple deadlock detection scheme will not
504 * work if the file system has any hard links other than ".."
505 * that point backwards in the directory structure.
508 if (flags & CNP_ISDOTDOT) {
509 VOP_UNLOCK(pdp, 0, td);
510 cnp->cn_flags |= CNP_PDIRUNLOCK;
511 error = deget(pmp, cluster, blkoff, &tdp);
513 vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, td);
514 cnp->cn_flags &= ~CNP_PDIRUNLOCK;
518 error = vn_lock(pdp, LK_EXCLUSIVE, td);
523 cnp->cn_flags &= ~CNP_PDIRUNLOCK;
526 } else if (dp->de_StartCluster == scn && isadir) {
527 vref(vdp); /* we want ourself, ie "." */
530 if ((error = deget(pmp, cluster, blkoff, &tdp)) != 0)
533 VOP_UNLOCK(pdp, 0, td);
534 cnp->cn_flags |= CNP_PDIRUNLOCK;
542 * dep - directory entry to copy into the directory
543 * ddep - directory to add to
544 * depp - return the address of the denode for the created directory entry
546 * cnp - componentname needed for Win95 long filenames
549 createde(struct denode *dep, struct denode *ddep, struct denode **depp,
550 struct componentname *cnp)
553 u_long dirclust, diroffset;
554 struct direntry *ndep;
555 struct msdosfsmount *pmp = ddep->de_pmp;
561 printf("createde(dep %p, ddep %p, depp %p, cnp %p)\n",
562 dep, ddep, depp, cnp);
566 * If no space left in the directory then allocate another cluster
567 * and chain it onto the end of the file. There is one exception
568 * to this. That is, if the root directory has no more space it
569 * can NOT be expanded. extendfile() checks for and fails attempts
570 * to extend the root directory. We just return an error in that
573 if (ddep->de_fndoffset >= ddep->de_FileSize) {
574 diroffset = ddep->de_fndoffset + sizeof(struct direntry)
576 dirclust = de_clcount(pmp, diroffset);
577 error = extendfile(ddep, dirclust, 0, 0, DE_CLEAR);
579 (void)detrunc(ddep, ddep->de_FileSize, 0, NULL);
584 * Update the size of the directory
586 ddep->de_FileSize += de_cn2off(pmp, dirclust);
590 * We just read in the cluster with space. Copy the new directory
591 * entry in. Then write it to disk. NOTE: DOS directories
592 * do not get smaller as clusters are emptied.
594 error = pcbmap(ddep, de_cluster(pmp, ddep->de_fndoffset),
595 &bn, &dirclust, &blsize);
598 diroffset = ddep->de_fndoffset;
599 if (dirclust != MSDOSFSROOT)
600 diroffset &= pmp->pm_crbomask;
601 if ((error = bread(pmp->pm_devvp, bn, blsize, &bp)) != 0) {
605 ndep = bptoep(pmp, bp, ddep->de_fndoffset);
607 DE_EXTERNALIZE(ndep, dep);
610 * Now write the Win95 long name
612 if (ddep->de_fndcnt > 0) {
613 u_int8_t chksum = winChksum(ndep->deName);
614 const u_char *un = (const u_char *)cnp->cn_nameptr;
615 int unlen = cnp->cn_namelen;
618 while (--ddep->de_fndcnt >= 0) {
619 if (!(ddep->de_fndoffset & pmp->pm_crbomask)) {
620 if ((error = bwrite(bp)) != 0)
623 ddep->de_fndoffset -= sizeof(struct direntry);
631 error = bread(pmp->pm_devvp, bn, blsize, &bp);
636 ndep = bptoep(pmp, bp, ddep->de_fndoffset);
639 ddep->de_fndoffset -= sizeof(struct direntry);
641 if (!unix2winfn(un, unlen, (struct winentry *)ndep,
643 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
649 if ((error = bwrite(bp)) != 0)
653 * If they want us to return with the denode gotten.
656 if (dep->de_Attributes & ATTR_DIRECTORY) {
657 dirclust = dep->de_StartCluster;
658 if (FAT32(pmp) && dirclust == pmp->pm_rootdirblk)
659 dirclust = MSDOSFSROOT;
660 if (dirclust == MSDOSFSROOT)
661 diroffset = MSDOSFSROOT_OFS;
665 return deget(pmp, dirclust, diroffset, depp);
672 * Be sure a directory is empty except for "." and "..". Return 1 if empty,
673 * return 0 if not empty or error.
676 dosdirempty(struct denode *dep)
683 struct msdosfsmount *pmp = dep->de_pmp;
684 struct direntry *dentp;
687 * Since the filesize field in directory entries for a directory is
688 * zero, we just have to feel our way through the directory until
689 * we hit end of file.
691 for (cn = 0;; cn++) {
692 if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
694 return (1); /* it's empty */
697 error = bread(pmp->pm_devvp, bn, blsize, &bp);
702 for (dentp = (struct direntry *)bp->b_data;
703 (char *)dentp < bp->b_data + blsize;
705 if (dentp->deName[0] != SLOT_DELETED &&
706 (dentp->deAttributes & ATTR_VOLUME) == 0) {
708 * In dos directories an entry whose name
709 * starts with SLOT_EMPTY (0) starts the
710 * beginning of the unused part of the
711 * directory, so we can just return that it
714 if (dentp->deName[0] == SLOT_EMPTY) {
719 * Any names other than "." and ".." in a
720 * directory mean it is not empty.
722 if (bcmp(dentp->deName, ". ", 11) &&
723 bcmp(dentp->deName, ".. ", 11)) {
726 printf("dosdirempty(): entry found %02x, %02x\n",
727 dentp->deName[0], dentp->deName[1]);
729 return (0); /* not empty */
739 * Check to see if the directory described by target is in some
740 * subdirectory of source. This prevents something like the following from
741 * succeeding and leaving a bunch or files and directories orphaned. mv
742 * /a/b/c /a/b/c/d/e/f Where c and f are directories.
744 * source - the inode for /a/b/c
745 * target - the inode for /a/b/c/d/e/f
747 * Returns 0 if target is NOT a subdirectory of source.
748 * Otherwise returns a non-zero error number.
749 * The target inode is always unlocked on return.
752 doscheckpath(struct denode *source, struct denode *target)
755 struct msdosfsmount *pmp;
758 struct buf *bp = NULL;
762 if ((target->de_Attributes & ATTR_DIRECTORY) == 0 ||
763 (source->de_Attributes & ATTR_DIRECTORY) == 0) {
767 if (dep->de_StartCluster == source->de_StartCluster) {
771 if (dep->de_StartCluster == MSDOSFSROOT)
775 if (pmp != source->de_pmp)
776 panic("doscheckpath: source and target on different filesystems");
778 if (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)
782 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0) {
786 scn = dep->de_StartCluster;
787 error = bread(pmp->pm_devvp, cntobn(pmp, scn),
788 pmp->pm_bpcluster, &bp);
792 ep = (struct direntry *) bp->b_data + 1;
793 if ((ep->deAttributes & ATTR_DIRECTORY) == 0 ||
794 bcmp(ep->deName, ".. ", 11) != 0) {
798 scn = getushort(ep->deStartCluster);
800 scn |= getushort(ep->deHighClust) << 16;
802 if (scn == source->de_StartCluster) {
806 if (scn == MSDOSFSROOT)
808 if (FAT32(pmp) && scn == pmp->pm_rootdirblk) {
810 * scn should be 0 in this case,
811 * but we silently ignore the error.
819 /* NOTE: deget() clears dep on error */
820 if ((error = deget(pmp, scn, 0, &dep)) != 0)
826 if (error == ENOTDIR)
827 printf("doscheckpath(): .. not a directory?\n");
834 * Read in the disk block containing the directory entry (dirclu, dirofs)
835 * and return the address of the buf header, and the address of the
836 * directory entry within the block.
839 readep(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset,
840 struct buf **bpp, struct direntry **epp)
846 blsize = pmp->pm_bpcluster;
847 if (dirclust == MSDOSFSROOT
848 && de_blk(pmp, diroffset + blsize) > pmp->pm_rootdirsize)
849 blsize = de_bn2off(pmp, pmp->pm_rootdirsize) & pmp->pm_crbomask;
850 bn = detobn(pmp, dirclust, diroffset);
851 if ((error = bread(pmp->pm_devvp, bn, blsize, bpp)) != 0) {
857 *epp = bptoep(pmp, *bpp, diroffset);
862 * Read in the disk block containing the directory entry dep came from and
863 * return the address of the buf header, and the address of the directory
864 * entry within the block.
867 readde(struct denode *dep, struct buf **bpp, struct direntry **epp)
869 return (readep(dep->de_pmp, dep->de_dirclust, dep->de_diroffset,
874 * Remove a directory entry. At this point the file represented by the
875 * directory entry to be removed is still full length until noone has it
876 * open. When the file no longer being used msdosfs_inactive() is called
877 * and will truncate the file to 0 length. When the vnode containing the
878 * denode is needed for some other purpose by VFS it will call
879 * msdosfs_reclaim() which will remove the denode from the denode cache.
882 removede(struct denode *pdep, /* directory where the entry is removed */
883 struct denode *dep) /* file to be removed */
890 struct msdosfsmount *pmp = pdep->de_pmp;
891 u_long offset = pdep->de_fndoffset;
894 printf("removede(): filename %s, dep %p, offset %08lx\n",
895 dep->de_Name, dep, offset);
899 offset += sizeof(struct direntry);
901 offset -= sizeof(struct direntry);
902 error = pcbmap(pdep, de_cluster(pmp, offset), &bn, 0, &blsize);
905 error = bread(pmp->pm_devvp, bn, blsize, &bp);
910 ep = bptoep(pmp, bp, offset);
912 * Check whether, if we came here the second time, i.e.
913 * when underflowing into the previous block, the last
914 * entry in this block is a longfilename entry, too.
916 if (ep->deAttributes != ATTR_WIN95
917 && offset != pdep->de_fndoffset) {
921 offset += sizeof(struct direntry);
924 * We are a bit agressive here in that we delete any Win95
925 * entries preceding this entry, not just the ones we "own".
926 * Since these presumably aren't valid anyway,
927 * there should be no harm.
929 offset -= sizeof(struct direntry);
930 ep--->deName[0] = SLOT_DELETED;
931 if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95)
932 || !(offset & pmp->pm_crbomask)
933 || ep->deAttributes != ATTR_WIN95)
936 if ((error = bwrite(bp)) != 0)
938 } while (!(pmp->pm_flags & MSDOSFSMNT_NOWIN95)
939 && !(offset & pmp->pm_crbomask)
945 * Create a unique DOS name in dvp
948 uniqdosname(struct denode *dep, struct componentname *cnp, u_char *cp)
950 struct msdosfsmount *pmp = dep->de_pmp;
951 struct direntry *dentp;
959 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
960 return (unix2dosfn((const u_char *)cnp->cn_nameptr, cp,
962 pmp->pm_flags & MSDOSFSMNT_U2WTABLE, pmp->pm_u2d,
963 pmp->pm_flags & MSDOSFSMNT_ULTABLE, pmp->pm_lu) ?
966 for (gen = 1;; gen++) {
968 * Generate DOS name with generation number
970 if (!unix2dosfn((const u_char *)cnp->cn_nameptr, cp,
971 cnp->cn_namelen, gen,
972 pmp->pm_flags & MSDOSFSMNT_U2WTABLE, pmp->pm_u2d,
973 pmp->pm_flags & MSDOSFSMNT_ULTABLE, pmp->pm_lu))
974 return gen == 1 ? EINVAL : EEXIST;
977 * Now look for a dir entry with this exact name
979 for (cn = error = 0; !error; cn++) {
980 if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
981 if (error == E2BIG) /* EOF reached and not found */
985 error = bread(pmp->pm_devvp, bn, blsize, &bp);
990 for (dentp = (struct direntry *)bp->b_data;
991 (char *)dentp < bp->b_data + blsize;
993 if (dentp->deName[0] == SLOT_EMPTY) {
995 * Last used entry and not found
1001 * Ignore volume labels and Win95 entries
1003 if (dentp->deAttributes & ATTR_VOLUME)
1005 if (!bcmp(dentp->deName, cp, 11)) {
1016 * Find any Win'95 long filename entry in directory dep
1019 findwin95(struct denode *dep)
1021 struct msdosfsmount *pmp = dep->de_pmp;
1022 struct direntry *dentp;
1030 * Read through the directory looking for Win'95 entries
1031 * Note: Error currently handled just as EOF XXX
1033 for (cn = 0;; cn++) {
1034 if (pcbmap(dep, cn, &bn, 0, &blsize))
1036 if (bread(pmp->pm_devvp, bn, blsize, &bp)) {
1040 for (dentp = (struct direntry *)bp->b_data;
1041 (char *)dentp < bp->b_data + blsize;
1043 if (dentp->deName[0] == SLOT_EMPTY) {
1045 * Last used entry and not found
1050 if (dentp->deName[0] == SLOT_DELETED) {
1052 * Ignore deleted files
1053 * Note: might be an indication of Win'95 anyway XXX
1057 if (dentp->deAttributes == ATTR_WIN95) {