1952a6212SJordan K. Hubbard /* $NetBSD: msdosfs_lookup.c,v 1.37 1997/11/17 15:36:54 ws Exp $ */
227a0bc89SDoug Rabson
327a0bc89SDoug Rabson /*-
4d63027b6SPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause
5d63027b6SPedro F. Giffuni *
6952a6212SJordan K. Hubbard * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
7952a6212SJordan K. Hubbard * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
827a0bc89SDoug Rabson * All rights reserved.
927a0bc89SDoug Rabson * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
1027a0bc89SDoug Rabson *
1127a0bc89SDoug Rabson * Redistribution and use in source and binary forms, with or without
1227a0bc89SDoug Rabson * modification, are permitted provided that the following conditions
1327a0bc89SDoug Rabson * are met:
1427a0bc89SDoug Rabson * 1. Redistributions of source code must retain the above copyright
1527a0bc89SDoug Rabson * notice, this list of conditions and the following disclaimer.
1627a0bc89SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright
1727a0bc89SDoug Rabson * notice, this list of conditions and the following disclaimer in the
1827a0bc89SDoug Rabson * documentation and/or other materials provided with the distribution.
1927a0bc89SDoug Rabson * 3. All advertising materials mentioning features or use of this software
2027a0bc89SDoug Rabson * must display the following acknowledgement:
2127a0bc89SDoug Rabson * This product includes software developed by TooLs GmbH.
2227a0bc89SDoug Rabson * 4. The name of TooLs GmbH may not be used to endorse or promote products
2327a0bc89SDoug Rabson * derived from this software without specific prior written permission.
2427a0bc89SDoug Rabson *
2527a0bc89SDoug Rabson * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2627a0bc89SDoug Rabson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2727a0bc89SDoug Rabson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2827a0bc89SDoug Rabson * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2927a0bc89SDoug Rabson * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3027a0bc89SDoug Rabson * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3127a0bc89SDoug Rabson * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3227a0bc89SDoug Rabson * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3327a0bc89SDoug Rabson * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3427a0bc89SDoug Rabson * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3527a0bc89SDoug Rabson */
36d167cf6fSWarner Losh /*-
3727a0bc89SDoug Rabson * Written by Paul Popelka (paulp@uts.amdahl.com)
3827a0bc89SDoug Rabson *
3927a0bc89SDoug Rabson * You can do anything you want with this software, just don't say you wrote
4027a0bc89SDoug Rabson * it, and don't remove this notice.
4127a0bc89SDoug Rabson *
4227a0bc89SDoug Rabson * This software is provided "as is".
4327a0bc89SDoug Rabson *
4427a0bc89SDoug Rabson * The author supplies this software to be publicly redistributed on the
4527a0bc89SDoug Rabson * understanding that the author is not responsible for the correct
4627a0bc89SDoug Rabson * functioning of this software in any circumstances and is not liable for
4727a0bc89SDoug Rabson * any damages caused by this software.
4827a0bc89SDoug Rabson *
4927a0bc89SDoug Rabson * October 1992
5027a0bc89SDoug Rabson */
5127a0bc89SDoug Rabson
5227a0bc89SDoug Rabson #include <sys/param.h>
53919d1ea2SPeter Wemm #include <sys/systm.h>
5427a0bc89SDoug Rabson #include <sys/buf.h>
5527a0bc89SDoug Rabson #include <sys/mount.h>
56a878a31cSBruce Evans #include <sys/namei.h>
57a878a31cSBruce Evans #include <sys/vnode.h>
5827a0bc89SDoug Rabson
591166fb51SRuslan Ermilov #include <fs/msdosfs/bpb.h>
601166fb51SRuslan Ermilov #include <fs/msdosfs/direntry.h>
611166fb51SRuslan Ermilov #include <fs/msdosfs/denode.h>
621166fb51SRuslan Ermilov #include <fs/msdosfs/fat.h>
63a878a31cSBruce Evans #include <fs/msdosfs/msdosfsmount.h>
6427a0bc89SDoug Rabson
65aec97963SKonstantin Belousov static int
msdosfs_lookup_checker(struct msdosfsmount * pmp,struct vnode * dvp,struct denode * tdp,struct vnode ** vpp)66aec97963SKonstantin Belousov msdosfs_lookup_checker(struct msdosfsmount *pmp, struct vnode *dvp,
67aec97963SKonstantin Belousov struct denode *tdp, struct vnode **vpp)
68aec97963SKonstantin Belousov {
69aec97963SKonstantin Belousov struct vnode *vp;
70aec97963SKonstantin Belousov
71aec97963SKonstantin Belousov vp = DETOV(tdp);
72aec97963SKonstantin Belousov
73aec97963SKonstantin Belousov /*
74aec97963SKonstantin Belousov * Lookup assumes that directory cannot be hardlinked.
75aec97963SKonstantin Belousov * Corrupted msdosfs filesystem could break this assumption.
76aec97963SKonstantin Belousov */
77aec97963SKonstantin Belousov if (vp == dvp) {
78aec97963SKonstantin Belousov vput(vp);
7941e85eeaSKonstantin Belousov msdosfs_integrity_error(pmp);
80aec97963SKonstantin Belousov *vpp = NULL;
81aec97963SKonstantin Belousov return (EBADF);
82aec97963SKonstantin Belousov }
83aec97963SKonstantin Belousov
84aec97963SKonstantin Belousov *vpp = vp;
85aec97963SKonstantin Belousov return (0);
86aec97963SKonstantin Belousov }
87aec97963SKonstantin Belousov
88db811dd7SKonstantin Belousov int
msdosfs_lookup(struct vop_cachedlookup_args * ap)89db811dd7SKonstantin Belousov msdosfs_lookup(struct vop_cachedlookup_args *ap)
90db811dd7SKonstantin Belousov {
91db811dd7SKonstantin Belousov
9295d42526SKonstantin Belousov return (msdosfs_lookup_ino(ap->a_dvp, ap->a_vpp, ap->a_cnp, NULL,
9395d42526SKonstantin Belousov NULL));
94db811dd7SKonstantin Belousov }
95db811dd7SKonstantin Belousov
96a6945216SKonstantin Belousov struct deget_dotdot {
97a6945216SKonstantin Belousov u_long cluster;
98a6945216SKonstantin Belousov int blkoff;
99a6945216SKonstantin Belousov };
100a6945216SKonstantin Belousov
101a6945216SKonstantin Belousov static int
msdosfs_deget_dotdot(struct mount * mp,void * arg,int lkflags,struct vnode ** rvp)102a6945216SKonstantin Belousov msdosfs_deget_dotdot(struct mount *mp, void *arg, int lkflags,
103a6945216SKonstantin Belousov struct vnode **rvp)
104a6945216SKonstantin Belousov {
105a6945216SKonstantin Belousov struct deget_dotdot *dd_arg;
106a6945216SKonstantin Belousov struct denode *rdp;
107a6945216SKonstantin Belousov struct msdosfsmount *pmp;
108a6945216SKonstantin Belousov int error;
109a6945216SKonstantin Belousov
110a6945216SKonstantin Belousov pmp = VFSTOMSDOSFS(mp);
111a6945216SKonstantin Belousov dd_arg = arg;
112ae7e8a02SKonstantin Belousov error = deget(pmp, dd_arg->cluster, dd_arg->blkoff,
113ae7e8a02SKonstantin Belousov LK_EXCLUSIVE, &rdp);
114a6945216SKonstantin Belousov if (error == 0)
115a6945216SKonstantin Belousov *rvp = DETOV(rdp);
116a6945216SKonstantin Belousov return (error);
117a6945216SKonstantin Belousov }
118a6945216SKonstantin Belousov
11927a0bc89SDoug Rabson /*
12027a0bc89SDoug Rabson * When we search a directory the blocks containing directory entries are
12127a0bc89SDoug Rabson * read and examined. The directory entries contain information that would
12227a0bc89SDoug Rabson * normally be in the inode of a unix filesystem. This means that some of
12327a0bc89SDoug Rabson * a directory's contents may also be in memory resident denodes (sort of
12427a0bc89SDoug Rabson * an inode). This can cause problems if we are searching while some other
12527a0bc89SDoug Rabson * process is modifying a directory. To prevent one process from accessing
12627a0bc89SDoug Rabson * incompletely modified directory information we depend upon being the
127b84d2921SPoul-Henning Kamp * sole owner of a directory block. bread/brelse provide this service.
12827a0bc89SDoug Rabson * This being the case, when a process modifies a directory it must first
12927a0bc89SDoug Rabson * acquire the disk block that contains the directory entry to be modified.
13027a0bc89SDoug Rabson * Then update the disk block and the denode, and then write the disk block
13127a0bc89SDoug Rabson * out to disk. This way disk blocks containing directory entries and in
13227a0bc89SDoug Rabson * memory denode's will be in synch.
13327a0bc89SDoug Rabson */
13492d4e088SKonstantin Belousov int
msdosfs_lookup_ino(struct vnode * vdp,struct vnode ** vpp,struct componentname * cnp,daddr_t * scnp,u_long * blkoffp)13595d42526SKonstantin Belousov msdosfs_lookup_ino(struct vnode *vdp, struct vnode **vpp, struct componentname
13695d42526SKonstantin Belousov *cnp, daddr_t *scnp, u_long *blkoffp)
13727a0bc89SDoug Rabson {
138c2819440SBruce Evans struct mbnambuf nb;
13927a0bc89SDoug Rabson daddr_t bn;
14027a0bc89SDoug Rabson int error;
141952a6212SJordan K. Hubbard int slotcount;
142952a6212SJordan K. Hubbard int slotoffset = 0;
14327a0bc89SDoug Rabson int frcn;
14427a0bc89SDoug Rabson u_long cluster;
14595d42526SKonstantin Belousov u_long blkoff;
14627a0bc89SDoug Rabson int diroff;
147952a6212SJordan K. Hubbard int blsize;
14827a0bc89SDoug Rabson int isadir; /* ~0 if found direntry is a directory */
14995d42526SKonstantin Belousov daddr_t scn; /* starting cluster number */
15027a0bc89SDoug Rabson struct vnode *pdp;
15127a0bc89SDoug Rabson struct denode *dp;
15227a0bc89SDoug Rabson struct denode *tdp;
15327a0bc89SDoug Rabson struct msdosfsmount *pmp;
154f7a3729cSKevin Lo struct buf *bp = NULL;
15527a0bc89SDoug Rabson struct direntry *dep = NULL;
156a6945216SKonstantin Belousov struct deget_dotdot dd_arg;
15727a0bc89SDoug Rabson u_char dosfilename[12];
15827a0bc89SDoug Rabson int flags = cnp->cn_flags;
15927a0bc89SDoug Rabson int nameiop = cnp->cn_nameiop;
16069a36f24SMike Smith int unlen;
16123c53312SEd Maste uint64_t inode1;
16227a0bc89SDoug Rabson
163952a6212SJordan K. Hubbard int wincnt = 1;
1646a5bf04aSTim J. Robbins int chksum = -1, chksum_ok;
165952a6212SJordan K. Hubbard int olddos = 1;
166952a6212SJordan K. Hubbard
16727a0bc89SDoug Rabson #ifdef MSDOSFS_DEBUG
16827a0bc89SDoug Rabson printf("msdosfs_lookup(): looking for %s\n", cnp->cn_nameptr);
16927a0bc89SDoug Rabson #endif
17027a0bc89SDoug Rabson dp = VTODE(vdp);
17127a0bc89SDoug Rabson pmp = dp->de_pmp;
17227a0bc89SDoug Rabson #ifdef MSDOSFS_DEBUG
173952a6212SJordan K. Hubbard printf("msdosfs_lookup(): vdp %p, dp %p, Attr %02x\n",
17427a0bc89SDoug Rabson vdp, dp, dp->de_Attributes);
17527a0bc89SDoug Rabson #endif
17627a0bc89SDoug Rabson
177db811dd7SKonstantin Belousov restart:
17884caee6bSKonstantin Belousov if (vpp != NULL)
17984caee6bSKonstantin Belousov *vpp = NULL;
18027a0bc89SDoug Rabson /*
18127a0bc89SDoug Rabson * If they are going after the . or .. entry in the root directory,
18227a0bc89SDoug Rabson * they won't find it. DOS filesystems don't have them in the root
18327a0bc89SDoug Rabson * directory. So, we fake it. deget() is in on this scam too.
18427a0bc89SDoug Rabson */
185e6e370a7SJeff Roberson if ((vdp->v_vflag & VV_ROOT) && cnp->cn_nameptr[0] == '.' &&
18627a0bc89SDoug Rabson (cnp->cn_namelen == 1 ||
18727a0bc89SDoug Rabson (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] == '.'))) {
18827a0bc89SDoug Rabson isadir = ATTR_DIRECTORY;
18927a0bc89SDoug Rabson scn = MSDOSFSROOT;
19027a0bc89SDoug Rabson #ifdef MSDOSFS_DEBUG
19127a0bc89SDoug Rabson printf("msdosfs_lookup(): looking for . or .. in root directory\n");
19227a0bc89SDoug Rabson #endif
19327a0bc89SDoug Rabson cluster = MSDOSFSROOT;
194952a6212SJordan K. Hubbard blkoff = MSDOSFSROOT_OFS;
19527a0bc89SDoug Rabson goto foundroot;
19627a0bc89SDoug Rabson }
19727a0bc89SDoug Rabson
198952a6212SJordan K. Hubbard switch (unix2dosfn((const u_char *)cnp->cn_nameptr, dosfilename,
199c4f02a89SMax Khon cnp->cn_namelen, 0, pmp)) {
200952a6212SJordan K. Hubbard case 0:
201*0b2c159cSJose Luis Duran if (nameiop == CREATE || nameiop == RENAME)
202952a6212SJordan K. Hubbard return (EINVAL);
203*0b2c159cSJose Luis Duran return (ENOENT);
204952a6212SJordan K. Hubbard case 1:
205952a6212SJordan K. Hubbard break;
206952a6212SJordan K. Hubbard case 2:
207952a6212SJordan K. Hubbard wincnt = winSlotCnt((const u_char *)cnp->cn_nameptr,
208c4f02a89SMax Khon cnp->cn_namelen, pmp) + 1;
209952a6212SJordan K. Hubbard break;
210952a6212SJordan K. Hubbard case 3:
211952a6212SJordan K. Hubbard olddos = 0;
212952a6212SJordan K. Hubbard wincnt = winSlotCnt((const u_char *)cnp->cn_nameptr,
213c4f02a89SMax Khon cnp->cn_namelen, pmp) + 1;
214952a6212SJordan K. Hubbard break;
21527a0bc89SDoug Rabson }
216011cdb57SDmitrij Tejblum if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME) {
217952a6212SJordan K. Hubbard wincnt = 1;
218011cdb57SDmitrij Tejblum olddos = 1;
219011cdb57SDmitrij Tejblum }
22069a36f24SMike Smith unlen = winLenFixup(cnp->cn_nameptr, cnp->cn_namelen);
22127a0bc89SDoug Rabson
222952a6212SJordan K. Hubbard /*
223952a6212SJordan K. Hubbard * Suppress search for slots unless creating
224952a6212SJordan K. Hubbard * file and at end of pathname, in which case
225952a6212SJordan K. Hubbard * we watch for a place to put the new file in
226952a6212SJordan K. Hubbard * case it doesn't already exist.
227952a6212SJordan K. Hubbard */
228952a6212SJordan K. Hubbard slotcount = wincnt;
229952a6212SJordan K. Hubbard if ((nameiop == CREATE || nameiop == RENAME) &&
230952a6212SJordan K. Hubbard (flags & ISLASTCN))
231952a6212SJordan K. Hubbard slotcount = 0;
232952a6212SJordan K. Hubbard
23327a0bc89SDoug Rabson #ifdef MSDOSFS_DEBUG
234952a6212SJordan K. Hubbard printf("msdosfs_lookup(): dos version of filename %s, length %ld\n",
23527a0bc89SDoug Rabson dosfilename, cnp->cn_namelen);
23627a0bc89SDoug Rabson #endif
23727a0bc89SDoug Rabson /*
23827a0bc89SDoug Rabson * Search the directory pointed at by vdp for the name pointed at
23927a0bc89SDoug Rabson * by cnp->cn_nameptr.
24027a0bc89SDoug Rabson */
24127a0bc89SDoug Rabson tdp = NULL;
242c2819440SBruce Evans mbnambuf_init(&nb);
24327a0bc89SDoug Rabson /*
24427a0bc89SDoug Rabson * The outer loop ranges over the clusters that make up the
24527a0bc89SDoug Rabson * directory. Note that the root directory is different from all
24627a0bc89SDoug Rabson * other directories. It has a fixed number of blocks that are not
24727a0bc89SDoug Rabson * part of the pool of allocatable clusters. So, we treat it a
24827a0bc89SDoug Rabson * little differently. The root directory starts at "cluster" 0.
24927a0bc89SDoug Rabson */
250952a6212SJordan K. Hubbard diroff = 0;
25127a0bc89SDoug Rabson for (frcn = 0;; frcn++) {
252952a6212SJordan K. Hubbard error = pcbmap(dp, frcn, &bn, &cluster, &blsize);
253c3c6d51eSPoul-Henning Kamp if (error) {
25427a0bc89SDoug Rabson if (error == E2BIG)
25527a0bc89SDoug Rabson break;
256952a6212SJordan K. Hubbard return (error);
25727a0bc89SDoug Rabson }
258952a6212SJordan K. Hubbard error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
259952a6212SJordan K. Hubbard if (error) {
260952a6212SJordan K. Hubbard return (error);
261952a6212SJordan K. Hubbard }
262952a6212SJordan K. Hubbard for (blkoff = 0; blkoff < blsize;
263952a6212SJordan K. Hubbard blkoff += sizeof(struct direntry),
264952a6212SJordan K. Hubbard diroff += sizeof(struct direntry)) {
265952a6212SJordan K. Hubbard dep = (struct direntry *)(bp->b_data + blkoff);
26627a0bc89SDoug Rabson /*
26727a0bc89SDoug Rabson * If the slot is empty and we are still looking
26827a0bc89SDoug Rabson * for an empty then remember this one. If the
26927a0bc89SDoug Rabson * slot is not empty then check to see if it
27027a0bc89SDoug Rabson * matches what we are looking for. If the slot
27127a0bc89SDoug Rabson * has never been filled with anything, then the
27227a0bc89SDoug Rabson * remainder of the directory has never been used,
27327a0bc89SDoug Rabson * so there is no point in searching it.
27427a0bc89SDoug Rabson */
27527a0bc89SDoug Rabson if (dep->deName[0] == SLOT_EMPTY ||
27627a0bc89SDoug Rabson dep->deName[0] == SLOT_DELETED) {
277952a6212SJordan K. Hubbard /*
278952a6212SJordan K. Hubbard * Drop memory of previous long matches
279952a6212SJordan K. Hubbard */
280952a6212SJordan K. Hubbard chksum = -1;
281c2819440SBruce Evans mbnambuf_init(&nb);
282952a6212SJordan K. Hubbard
283952a6212SJordan K. Hubbard if (slotcount < wincnt) {
284952a6212SJordan K. Hubbard slotcount++;
28527a0bc89SDoug Rabson slotoffset = diroff;
28627a0bc89SDoug Rabson }
28727a0bc89SDoug Rabson if (dep->deName[0] == SLOT_EMPTY) {
28827a0bc89SDoug Rabson brelse(bp);
28927a0bc89SDoug Rabson goto notfound;
29027a0bc89SDoug Rabson }
29127a0bc89SDoug Rabson } else {
29227a0bc89SDoug Rabson /*
293952a6212SJordan K. Hubbard * If there wasn't enough space for our winentries,
294952a6212SJordan K. Hubbard * forget about the empty space
295952a6212SJordan K. Hubbard */
296952a6212SJordan K. Hubbard if (slotcount < wincnt)
297952a6212SJordan K. Hubbard slotcount = 0;
298952a6212SJordan K. Hubbard
299952a6212SJordan K. Hubbard /*
300952a6212SJordan K. Hubbard * Check for Win95 long filename entry
301952a6212SJordan K. Hubbard */
302952a6212SJordan K. Hubbard if (dep->deAttributes == ATTR_WIN95) {
303952a6212SJordan K. Hubbard if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
304952a6212SJordan K. Hubbard continue;
305952a6212SJordan K. Hubbard
306c2819440SBruce Evans chksum = win2unixfn(&nb,
307c2819440SBruce Evans (struct winentry *)dep, chksum,
308c4f02a89SMax Khon pmp);
309c4f02a89SMax Khon continue;
310c4f02a89SMax Khon }
311c4f02a89SMax Khon
312c2819440SBruce Evans chksum = winChkName(&nb,
313c2819440SBruce Evans (const u_char *)cnp->cn_nameptr, unlen,
314c2819440SBruce Evans chksum, pmp);
315c4f02a89SMax Khon if (chksum == -2) {
316c4f02a89SMax Khon chksum = -1;
317952a6212SJordan K. Hubbard continue;
318952a6212SJordan K. Hubbard }
319952a6212SJordan K. Hubbard
320952a6212SJordan K. Hubbard /*
32127a0bc89SDoug Rabson * Ignore volume labels (anywhere, not just
32227a0bc89SDoug Rabson * the root directory).
32327a0bc89SDoug Rabson */
324952a6212SJordan K. Hubbard if (dep->deAttributes & ATTR_VOLUME) {
325952a6212SJordan K. Hubbard chksum = -1;
326952a6212SJordan K. Hubbard continue;
327952a6212SJordan K. Hubbard }
328952a6212SJordan K. Hubbard
329952a6212SJordan K. Hubbard /*
330952a6212SJordan K. Hubbard * Check for a checksum or name match
331952a6212SJordan K. Hubbard */
33248d1bcf8SKonstantin Belousov chksum_ok = (chksum == winChksum(dep->deName));
3336a5bf04aSTim J. Robbins if (!chksum_ok
334952a6212SJordan K. Hubbard && (!olddos || bcmp(dosfilename, dep->deName, 11))) {
335952a6212SJordan K. Hubbard chksum = -1;
336952a6212SJordan K. Hubbard continue;
337952a6212SJordan K. Hubbard }
33827a0bc89SDoug Rabson #ifdef MSDOSFS_DEBUG
3392d8cf575SStefan Eßer printf("msdosfs_lookup(): match blkoff %lu, diroff %d\n",
340952a6212SJordan K. Hubbard blkoff, diroff);
34127a0bc89SDoug Rabson #endif
34227a0bc89SDoug Rabson /*
34327a0bc89SDoug Rabson * Remember where this directory
34427a0bc89SDoug Rabson * entry came from for whoever did
345952a6212SJordan K. Hubbard * this lookup.
34627a0bc89SDoug Rabson */
34727a0bc89SDoug Rabson dp->de_fndoffset = diroff;
3486a5bf04aSTim J. Robbins if (chksum_ok && nameiop == RENAME) {
3496a5bf04aSTim J. Robbins /*
3506a5bf04aSTim J. Robbins * Target had correct long name
3516a5bf04aSTim J. Robbins * directory entries, reuse them
3526a5bf04aSTim J. Robbins * as needed.
3536a5bf04aSTim J. Robbins */
354191e6fd0SDmitrij Tejblum dp->de_fndcnt = wincnt - 1;
3556a5bf04aSTim J. Robbins } else {
3566a5bf04aSTim J. Robbins /*
3576a5bf04aSTim J. Robbins * Long name directory entries
3586a5bf04aSTim J. Robbins * not present or corrupt, can only
3596a5bf04aSTim J. Robbins * reuse dos directory entry.
3606a5bf04aSTim J. Robbins */
3616a5bf04aSTim J. Robbins dp->de_fndcnt = 0;
3626a5bf04aSTim J. Robbins }
363952a6212SJordan K. Hubbard
36427a0bc89SDoug Rabson goto found;
36527a0bc89SDoug Rabson }
366952a6212SJordan K. Hubbard } /* for (blkoff = 0; .... */
36727a0bc89SDoug Rabson /*
36827a0bc89SDoug Rabson * Release the buffer holding the directory cluster just
36927a0bc89SDoug Rabson * searched.
37027a0bc89SDoug Rabson */
37127a0bc89SDoug Rabson brelse(bp);
37227a0bc89SDoug Rabson } /* for (frcn = 0; ; frcn++) */
373952a6212SJordan K. Hubbard
374952a6212SJordan K. Hubbard notfound:
37527a0bc89SDoug Rabson /*
37627a0bc89SDoug Rabson * We hold no disk buffers at this point.
37727a0bc89SDoug Rabson */
37827a0bc89SDoug Rabson
37927a0bc89SDoug Rabson /*
380952a6212SJordan K. Hubbard * Fixup the slot description to point to the place where
381952a6212SJordan K. Hubbard * we might put the new DOS direntry (putting the Win95
382952a6212SJordan K. Hubbard * long name entries before that)
383952a6212SJordan K. Hubbard */
384952a6212SJordan K. Hubbard if (!slotcount) {
385952a6212SJordan K. Hubbard slotcount = 1;
386952a6212SJordan K. Hubbard slotoffset = diroff;
387952a6212SJordan K. Hubbard }
388952a6212SJordan K. Hubbard if (wincnt > slotcount)
389952a6212SJordan K. Hubbard slotoffset += sizeof(struct direntry) * (wincnt - slotcount);
390952a6212SJordan K. Hubbard
391952a6212SJordan K. Hubbard /*
39227a0bc89SDoug Rabson * If we get here we didn't find the entry we were looking for. But
39327a0bc89SDoug Rabson * that's ok if we are creating or renaming and are at the end of
39427a0bc89SDoug Rabson * the pathname and the directory hasn't been removed.
39527a0bc89SDoug Rabson */
39627a0bc89SDoug Rabson #ifdef MSDOSFS_DEBUG
397952a6212SJordan K. Hubbard printf("msdosfs_lookup(): op %d, refcnt %ld\n",
398952a6212SJordan K. Hubbard nameiop, dp->de_refcnt);
399952a6212SJordan K. Hubbard printf(" slotcount %d, slotoffset %d\n",
400952a6212SJordan K. Hubbard slotcount, slotoffset);
40127a0bc89SDoug Rabson #endif
40227a0bc89SDoug Rabson if ((nameiop == CREATE || nameiop == RENAME) &&
40327a0bc89SDoug Rabson (flags & ISLASTCN) && dp->de_refcnt != 0) {
404952a6212SJordan K. Hubbard /*
405952a6212SJordan K. Hubbard * Access for write is interpreted as allowing
406952a6212SJordan K. Hubbard * creation of files in the directory.
407952a6212SJordan K. Hubbard */
408b4a58fbfSMateusz Guzik error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, curthread);
409d8762fa6SBruce Evans if (error)
410952a6212SJordan K. Hubbard return (error);
411952a6212SJordan K. Hubbard /*
412952a6212SJordan K. Hubbard * Return an indication of where the new directory
413952a6212SJordan K. Hubbard * entry should be put.
414952a6212SJordan K. Hubbard */
41527a0bc89SDoug Rabson dp->de_fndoffset = slotoffset;
416952a6212SJordan K. Hubbard dp->de_fndcnt = wincnt - 1;
417952a6212SJordan K. Hubbard
418952a6212SJordan K. Hubbard /*
419952a6212SJordan K. Hubbard * We return with the directory locked, so that
420952a6212SJordan K. Hubbard * the parameters we set up above will still be
421952a6212SJordan K. Hubbard * valid if we actually decide to do a direnter().
422952a6212SJordan K. Hubbard * We return ni_vp == NULL to indicate that the entry
423952a6212SJordan K. Hubbard * does not currently exist; we leave a pointer to
424952a6212SJordan K. Hubbard * the (locked) directory inode in ndp->ni_dvp.
425952a6212SJordan K. Hubbard *
426952a6212SJordan K. Hubbard * NB - if the directory is unlocked, then this
427952a6212SJordan K. Hubbard * information cannot be used.
428952a6212SJordan K. Hubbard */
429952a6212SJordan K. Hubbard return (EJUSTRETURN);
43027a0bc89SDoug Rabson }
43123e8fcafSDavid Schultz #if 0
43227a0bc89SDoug Rabson /*
433952a6212SJordan K. Hubbard * Insert name into cache (as non-existent) if appropriate.
43423e8fcafSDavid Schultz *
43523e8fcafSDavid Schultz * XXX Negative caching is broken for msdosfs because the name
43623e8fcafSDavid Schultz * cache doesn't understand peculiarities such as case insensitivity
43723e8fcafSDavid Schultz * and 8.3 filenames. Hence, it may not invalidate all negative
43823e8fcafSDavid Schultz * entries if a file with this name is later created.
43927a0bc89SDoug Rabson */
4406c21f6edSKonstantin Belousov if ((cnp->cn_flags & MAKEENTRY) != 0)
44127a0bc89SDoug Rabson cache_enter(vdp, *vpp, cnp);
44223e8fcafSDavid Schultz #endif
443952a6212SJordan K. Hubbard return (ENOENT);
44427a0bc89SDoug Rabson
445952a6212SJordan K. Hubbard found:
44627a0bc89SDoug Rabson /*
44727a0bc89SDoug Rabson * NOTE: We still have the buffer with matched directory entry at
44827a0bc89SDoug Rabson * this point.
44927a0bc89SDoug Rabson */
45027a0bc89SDoug Rabson isadir = dep->deAttributes & ATTR_DIRECTORY;
45127a0bc89SDoug Rabson scn = getushort(dep->deStartCluster);
452952a6212SJordan K. Hubbard if (FAT32(pmp)) {
453952a6212SJordan K. Hubbard scn |= getushort(dep->deHighClust) << 16;
454952a6212SJordan K. Hubbard if (scn == pmp->pm_rootdirblk) {
455952a6212SJordan K. Hubbard /*
456952a6212SJordan K. Hubbard * There should actually be 0 here.
457952a6212SJordan K. Hubbard * Just ignore the error.
458952a6212SJordan K. Hubbard */
459952a6212SJordan K. Hubbard scn = MSDOSFSROOT;
460952a6212SJordan K. Hubbard }
461952a6212SJordan K. Hubbard }
46227a0bc89SDoug Rabson
463952a6212SJordan K. Hubbard if (isadir) {
464952a6212SJordan K. Hubbard cluster = scn;
465952a6212SJordan K. Hubbard if (cluster == MSDOSFSROOT)
466952a6212SJordan K. Hubbard blkoff = MSDOSFSROOT_OFS;
467952a6212SJordan K. Hubbard else
468952a6212SJordan K. Hubbard blkoff = 0;
469952a6212SJordan K. Hubbard } else if (cluster == MSDOSFSROOT)
470952a6212SJordan K. Hubbard blkoff = diroff;
471952a6212SJordan K. Hubbard
472952a6212SJordan K. Hubbard /*
473952a6212SJordan K. Hubbard * Now release buf to allow deget to read the entry again.
474952a6212SJordan K. Hubbard * Reserving it here and giving it to deget could result
475952a6212SJordan K. Hubbard * in a deadlock.
476952a6212SJordan K. Hubbard */
477952a6212SJordan K. Hubbard brelse(bp);
4780d3e502fSPedro F. Giffuni bp = NULL;
479952a6212SJordan K. Hubbard
480952a6212SJordan K. Hubbard foundroot:
48127a0bc89SDoug Rabson /*
48227a0bc89SDoug Rabson * If we entered at foundroot, then we are looking for the . or ..
48327a0bc89SDoug Rabson * entry of the filesystems root directory. isadir and scn were
484952a6212SJordan K. Hubbard * setup before jumping here. And, bp is already null.
48527a0bc89SDoug Rabson */
486952a6212SJordan K. Hubbard if (FAT32(pmp) && scn == MSDOSFSROOT)
487952a6212SJordan K. Hubbard scn = pmp->pm_rootdirblk;
48827a0bc89SDoug Rabson
48995d42526SKonstantin Belousov if (scnp != NULL) {
49095d42526SKonstantin Belousov *scnp = cluster;
49195d42526SKonstantin Belousov *blkoffp = blkoff;
492db811dd7SKonstantin Belousov return (0);
493db811dd7SKonstantin Belousov }
494db811dd7SKonstantin Belousov
49527a0bc89SDoug Rabson /*
496952a6212SJordan K. Hubbard * If deleting, and at end of pathname, return
497952a6212SJordan K. Hubbard * parameters which can be used to remove file.
49827a0bc89SDoug Rabson */
49927a0bc89SDoug Rabson if (nameiop == DELETE && (flags & ISLASTCN)) {
500952a6212SJordan K. Hubbard /*
501952a6212SJordan K. Hubbard * Don't allow deleting the root.
502952a6212SJordan K. Hubbard */
503952a6212SJordan K. Hubbard if (blkoff == MSDOSFSROOT_OFS)
5049ba671deSKonstantin Belousov return (EBUSY);
505952a6212SJordan K. Hubbard
506952a6212SJordan K. Hubbard /*
507952a6212SJordan K. Hubbard * Write access to directory required to delete files.
508952a6212SJordan K. Hubbard */
509b4a58fbfSMateusz Guzik error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, curthread);
510952a6212SJordan K. Hubbard if (error)
511952a6212SJordan K. Hubbard return (error);
512952a6212SJordan K. Hubbard
513952a6212SJordan K. Hubbard /*
514952a6212SJordan K. Hubbard * Return pointer to current entry in dp->i_offset.
515952a6212SJordan K. Hubbard * Save directory inode pointer in ndp->ni_dvp for dirremove().
516952a6212SJordan K. Hubbard */
51727a0bc89SDoug Rabson if (dp->de_StartCluster == scn && isadir) { /* "." */
51827a0bc89SDoug Rabson VREF(vdp);
51927a0bc89SDoug Rabson *vpp = vdp;
520952a6212SJordan K. Hubbard return (0);
52127a0bc89SDoug Rabson }
522ae7e8a02SKonstantin Belousov error = deget(pmp, cluster, blkoff, LK_EXCLUSIVE, &tdp);
523952a6212SJordan K. Hubbard if (error)
524952a6212SJordan K. Hubbard return (error);
525aec97963SKonstantin Belousov return (msdosfs_lookup_checker(pmp, vdp, tdp, vpp));
52627a0bc89SDoug Rabson }
52727a0bc89SDoug Rabson
52827a0bc89SDoug Rabson /*
529952a6212SJordan K. Hubbard * If rewriting (RENAME), return the inode and the
530952a6212SJordan K. Hubbard * information required to rewrite the present directory
531952a6212SJordan K. Hubbard * Must get inode of directory entry to verify it's a
532952a6212SJordan K. Hubbard * regular file, or empty directory.
53327a0bc89SDoug Rabson */
534fcc9c112SJeff Roberson if (nameiop == RENAME && (flags & ISLASTCN)) {
535952a6212SJordan K. Hubbard if (blkoff == MSDOSFSROOT_OFS)
5369ba671deSKonstantin Belousov return (EBUSY);
537952a6212SJordan K. Hubbard
538b4a58fbfSMateusz Guzik error = VOP_ACCESS(vdp, VWRITE, cnp->cn_cred, curthread);
539952a6212SJordan K. Hubbard if (error)
540952a6212SJordan K. Hubbard return (error);
541952a6212SJordan K. Hubbard
542952a6212SJordan K. Hubbard /*
543952a6212SJordan K. Hubbard * Careful about locking second inode.
544952a6212SJordan K. Hubbard * This can only occur if the target is ".".
545952a6212SJordan K. Hubbard */
546952a6212SJordan K. Hubbard if (dp->de_StartCluster == scn && isadir)
547952a6212SJordan K. Hubbard return (EISDIR);
548952a6212SJordan K. Hubbard
549ae7e8a02SKonstantin Belousov if ((error = deget(pmp, cluster, blkoff, LK_EXCLUSIVE,
550ae7e8a02SKonstantin Belousov &tdp)) != 0)
551952a6212SJordan K. Hubbard return (error);
552aec97963SKonstantin Belousov if ((error = msdosfs_lookup_checker(pmp, vdp, tdp, vpp))
553aec97963SKonstantin Belousov != 0)
554aec97963SKonstantin Belousov return (error);
555952a6212SJordan K. Hubbard return (0);
55627a0bc89SDoug Rabson }
55727a0bc89SDoug Rabson
55827a0bc89SDoug Rabson /*
559952a6212SJordan K. Hubbard * Step through the translation in the name. We do not `vput' the
560952a6212SJordan K. Hubbard * directory because we may need it again if a symbolic link
561952a6212SJordan K. Hubbard * is relative to the current directory. Instead we save it
562952a6212SJordan K. Hubbard * unlocked as "pdp". We must get the target inode before unlocking
563952a6212SJordan K. Hubbard * the directory to insure that the inode will not be removed
564952a6212SJordan K. Hubbard * before we get it. We prevent deadlock by always fetching
565952a6212SJordan K. Hubbard * inodes from the root, moving down the directory tree. Thus
566952a6212SJordan K. Hubbard * when following backward pointers ".." we must unlock the
567952a6212SJordan K. Hubbard * parent directory before getting the requested directory.
56827a0bc89SDoug Rabson */
56927a0bc89SDoug Rabson pdp = vdp;
57027a0bc89SDoug Rabson if (flags & ISDOTDOT) {
571a6945216SKonstantin Belousov dd_arg.cluster = cluster;
572a6945216SKonstantin Belousov dd_arg.blkoff = blkoff;
573a6945216SKonstantin Belousov error = vn_vget_ino_gen(vdp, msdosfs_deget_dotdot,
574a6945216SKonstantin Belousov &dd_arg, cnp->cn_lkflags, vpp);
575a6945216SKonstantin Belousov if (error != 0) {
57684caee6bSKonstantin Belousov *vpp = NULL;
577952a6212SJordan K. Hubbard return (error);
57884caee6bSKonstantin Belousov }
579db811dd7SKonstantin Belousov /*
580db811dd7SKonstantin Belousov * Recheck that ".." still points to the inode we
581db811dd7SKonstantin Belousov * looked up before pdp lock was dropped.
582db811dd7SKonstantin Belousov */
58395d42526SKonstantin Belousov error = msdosfs_lookup_ino(pdp, NULL, cnp, &scn, &blkoff);
584db811dd7SKonstantin Belousov if (error) {
585db811dd7SKonstantin Belousov vput(*vpp);
58684caee6bSKonstantin Belousov *vpp = NULL;
587db811dd7SKonstantin Belousov return (error);
588db811dd7SKonstantin Belousov }
58995d42526SKonstantin Belousov if (FAT32(pmp) && scn == MSDOSFSROOT)
59095d42526SKonstantin Belousov scn = pmp->pm_rootdirblk;
591445d3d22SStefan Eßer inode1 = DETOI(pmp, scn, blkoff);
592db811dd7SKonstantin Belousov if (VTODE(*vpp)->de_inode != inode1) {
593db811dd7SKonstantin Belousov vput(*vpp);
594db811dd7SKonstantin Belousov goto restart;
595db811dd7SKonstantin Belousov }
59641e85eeaSKonstantin Belousov error = msdosfs_lookup_checker(pmp, vdp, VTODE(*vpp), vpp);
59741e85eeaSKonstantin Belousov if (error != 0)
59841e85eeaSKonstantin Belousov return (error);
599952a6212SJordan K. Hubbard } else if (dp->de_StartCluster == scn && isadir) {
6001319c433SKonstantin Belousov if (cnp->cn_namelen != 1 || cnp->cn_nameptr[0] != '.') {
6011319c433SKonstantin Belousov /* fs is corrupted, non-dot lookup returned dvp */
60241e85eeaSKonstantin Belousov msdosfs_integrity_error(pmp);
6031319c433SKonstantin Belousov return (EBADF);
6041319c433SKonstantin Belousov }
605952a6212SJordan K. Hubbard VREF(vdp); /* we want ourself, ie "." */
60627a0bc89SDoug Rabson *vpp = vdp;
60727a0bc89SDoug Rabson } else {
608ae7e8a02SKonstantin Belousov if ((error = deget(pmp, cluster, blkoff, LK_EXCLUSIVE,
609ae7e8a02SKonstantin Belousov &tdp)) != 0)
610952a6212SJordan K. Hubbard return (error);
611aec97963SKonstantin Belousov if ((error = msdosfs_lookup_checker(pmp, vdp, tdp, vpp)) != 0)
612aec97963SKonstantin Belousov return (error);
61327a0bc89SDoug Rabson }
61427a0bc89SDoug Rabson
61527a0bc89SDoug Rabson /*
616952a6212SJordan K. Hubbard * Insert name into cache if appropriate.
61727a0bc89SDoug Rabson */
61827a0bc89SDoug Rabson if (cnp->cn_flags & MAKEENTRY)
61927a0bc89SDoug Rabson cache_enter(vdp, *vpp, cnp);
620952a6212SJordan K. Hubbard return (0);
62127a0bc89SDoug Rabson }
62227a0bc89SDoug Rabson
62327a0bc89SDoug Rabson /*
62427a0bc89SDoug Rabson * dep - directory entry to copy into the directory
62527a0bc89SDoug Rabson * ddep - directory to add to
62627a0bc89SDoug Rabson * depp - return the address of the denode for the created directory entry
62727a0bc89SDoug Rabson * if depp != 0
628952a6212SJordan K. Hubbard * cnp - componentname needed for Win95 long filenames
62927a0bc89SDoug Rabson */
63027a0bc89SDoug Rabson int
createde(struct denode * dep,struct denode * ddep,struct denode ** depp,struct componentname * cnp)63110c9700fSEd Maste createde(struct denode *dep, struct denode *ddep, struct denode **depp,
63210c9700fSEd Maste struct componentname *cnp)
63327a0bc89SDoug Rabson {
63427a0bc89SDoug Rabson int error;
63527a0bc89SDoug Rabson u_long dirclust, diroffset;
63627a0bc89SDoug Rabson struct direntry *ndep;
63727a0bc89SDoug Rabson struct msdosfsmount *pmp = ddep->de_pmp;
63827a0bc89SDoug Rabson struct buf *bp;
639952a6212SJordan K. Hubbard daddr_t bn;
640952a6212SJordan K. Hubbard int blsize;
64127a0bc89SDoug Rabson
64227a0bc89SDoug Rabson #ifdef MSDOSFS_DEBUG
643952a6212SJordan K. Hubbard printf("createde(dep %p, ddep %p, depp %p, cnp %p)\n",
644952a6212SJordan K. Hubbard dep, ddep, depp, cnp);
64527a0bc89SDoug Rabson #endif
64627a0bc89SDoug Rabson
64727a0bc89SDoug Rabson /*
64827a0bc89SDoug Rabson * If no space left in the directory then allocate another cluster
64927a0bc89SDoug Rabson * and chain it onto the end of the file. There is one exception
65027a0bc89SDoug Rabson * to this. That is, if the root directory has no more space it
65127a0bc89SDoug Rabson * can NOT be expanded. extendfile() checks for and fails attempts
65227a0bc89SDoug Rabson * to extend the root directory. We just return an error in that
65327a0bc89SDoug Rabson * case.
65427a0bc89SDoug Rabson */
655952a6212SJordan K. Hubbard if (ddep->de_fndoffset >= ddep->de_FileSize) {
656952a6212SJordan K. Hubbard diroffset = ddep->de_fndoffset + sizeof(struct direntry)
657952a6212SJordan K. Hubbard - ddep->de_FileSize;
658952a6212SJordan K. Hubbard dirclust = de_clcount(pmp, diroffset);
659952a6212SJordan K. Hubbard error = extendfile(ddep, dirclust, 0, 0, DE_CLEAR);
660952a6212SJordan K. Hubbard if (error) {
661c52fd858SEdward Tomasz Napierala (void)detrunc(ddep, ddep->de_FileSize, 0, NOCRED);
66227a0bc89SDoug Rabson return error;
663952a6212SJordan K. Hubbard }
664952a6212SJordan K. Hubbard
66527a0bc89SDoug Rabson /*
66627a0bc89SDoug Rabson * Update the size of the directory
66727a0bc89SDoug Rabson */
668952a6212SJordan K. Hubbard ddep->de_FileSize += de_cn2off(pmp, dirclust);
669952a6212SJordan K. Hubbard }
670952a6212SJordan K. Hubbard
67127a0bc89SDoug Rabson /*
672952a6212SJordan K. Hubbard * We just read in the cluster with space. Copy the new directory
67327a0bc89SDoug Rabson * entry in. Then write it to disk. NOTE: DOS directories
67427a0bc89SDoug Rabson * do not get smaller as clusters are emptied.
67527a0bc89SDoug Rabson */
676952a6212SJordan K. Hubbard error = pcbmap(ddep, de_cluster(pmp, ddep->de_fndoffset),
677952a6212SJordan K. Hubbard &bn, &dirclust, &blsize);
67827a0bc89SDoug Rabson if (error)
67927a0bc89SDoug Rabson return error;
680952a6212SJordan K. Hubbard diroffset = ddep->de_fndoffset;
681952a6212SJordan K. Hubbard if (dirclust != MSDOSFSROOT)
682952a6212SJordan K. Hubbard diroffset &= pmp->pm_crbomask;
683952a6212SJordan K. Hubbard if ((error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp)) != 0) {
684952a6212SJordan K. Hubbard brelse(bp);
685952a6212SJordan K. Hubbard return error;
68627a0bc89SDoug Rabson }
687952a6212SJordan K. Hubbard ndep = bptoep(pmp, bp, ddep->de_fndoffset);
688c33db74bSStefan Eßer rootde_alloced(ddep);
689952a6212SJordan K. Hubbard
69027a0bc89SDoug Rabson DE_EXTERNALIZE(ndep, dep);
69127a0bc89SDoug Rabson
69227a0bc89SDoug Rabson /*
693952a6212SJordan K. Hubbard * Now write the Win95 long name
694952a6212SJordan K. Hubbard */
695952a6212SJordan K. Hubbard if (ddep->de_fndcnt > 0) {
69623c53312SEd Maste uint8_t chksum = winChksum(ndep->deName);
697952a6212SJordan K. Hubbard const u_char *un = (const u_char *)cnp->cn_nameptr;
698952a6212SJordan K. Hubbard int unlen = cnp->cn_namelen;
699952a6212SJordan K. Hubbard int cnt = 1;
700952a6212SJordan K. Hubbard
701952a6212SJordan K. Hubbard while (--ddep->de_fndcnt >= 0) {
702952a6212SJordan K. Hubbard if (!(ddep->de_fndoffset & pmp->pm_crbomask)) {
7032aacee77SKonstantin Belousov if (DOINGASYNC(DETOV(ddep)))
704cb65c1eeSBruce Evans bdwrite(bp);
705cb65c1eeSBruce Evans else if ((error = bwrite(bp)) != 0)
706952a6212SJordan K. Hubbard return error;
707952a6212SJordan K. Hubbard
708952a6212SJordan K. Hubbard ddep->de_fndoffset -= sizeof(struct direntry);
709952a6212SJordan K. Hubbard error = pcbmap(ddep,
710952a6212SJordan K. Hubbard de_cluster(pmp,
711952a6212SJordan K. Hubbard ddep->de_fndoffset),
712952a6212SJordan K. Hubbard &bn, 0, &blsize);
713952a6212SJordan K. Hubbard if (error)
714952a6212SJordan K. Hubbard return error;
715952a6212SJordan K. Hubbard
716952a6212SJordan K. Hubbard error = bread(pmp->pm_devvp, bn, blsize,
717952a6212SJordan K. Hubbard NOCRED, &bp);
718952a6212SJordan K. Hubbard if (error) {
719952a6212SJordan K. Hubbard return error;
720952a6212SJordan K. Hubbard }
721952a6212SJordan K. Hubbard ndep = bptoep(pmp, bp, ddep->de_fndoffset);
722952a6212SJordan K. Hubbard } else {
723952a6212SJordan K. Hubbard ndep--;
724952a6212SJordan K. Hubbard ddep->de_fndoffset -= sizeof(struct direntry);
725952a6212SJordan K. Hubbard }
726c33db74bSStefan Eßer rootde_alloced(ddep);
72713df76f2SAndrey A. Chernov if (!unix2winfn(un, unlen, (struct winentry *)ndep,
728c4f02a89SMax Khon cnt++, chksum, pmp))
729952a6212SJordan K. Hubbard break;
730952a6212SJordan K. Hubbard }
731952a6212SJordan K. Hubbard }
732952a6212SJordan K. Hubbard
7332aacee77SKonstantin Belousov if (DOINGASYNC(DETOV(ddep)))
734cb65c1eeSBruce Evans bdwrite(bp);
735cb65c1eeSBruce Evans else if ((error = bwrite(bp)) != 0)
736952a6212SJordan K. Hubbard return error;
737952a6212SJordan K. Hubbard
738952a6212SJordan K. Hubbard /*
73927a0bc89SDoug Rabson * If they want us to return with the denode gotten.
74027a0bc89SDoug Rabson */
74127a0bc89SDoug Rabson if (depp) {
742952a6212SJordan K. Hubbard if (dep->de_Attributes & ATTR_DIRECTORY) {
743952a6212SJordan K. Hubbard dirclust = dep->de_StartCluster;
744952a6212SJordan K. Hubbard if (FAT32(pmp) && dirclust == pmp->pm_rootdirblk)
745952a6212SJordan K. Hubbard dirclust = MSDOSFSROOT;
746952a6212SJordan K. Hubbard if (dirclust == MSDOSFSROOT)
747952a6212SJordan K. Hubbard diroffset = MSDOSFSROOT_OFS;
748952a6212SJordan K. Hubbard else
749952a6212SJordan K. Hubbard diroffset = 0;
75027a0bc89SDoug Rabson }
751ae7e8a02SKonstantin Belousov return (deget(pmp, dirclust, diroffset, LK_EXCLUSIVE, depp));
75227a0bc89SDoug Rabson }
753952a6212SJordan K. Hubbard
75427a0bc89SDoug Rabson return 0;
75527a0bc89SDoug Rabson }
75627a0bc89SDoug Rabson
75727a0bc89SDoug Rabson /*
75827a0bc89SDoug Rabson * Be sure a directory is empty except for "." and "..". Return 1 if empty,
75927a0bc89SDoug Rabson * return 0 if not empty or error.
76027a0bc89SDoug Rabson */
76127a0bc89SDoug Rabson int
dosdirempty(struct denode * dep)76210c9700fSEd Maste dosdirempty(struct denode *dep)
76327a0bc89SDoug Rabson {
764952a6212SJordan K. Hubbard int blsize;
76527a0bc89SDoug Rabson int error;
76627a0bc89SDoug Rabson u_long cn;
76727a0bc89SDoug Rabson daddr_t bn;
76827a0bc89SDoug Rabson struct buf *bp;
76927a0bc89SDoug Rabson struct msdosfsmount *pmp = dep->de_pmp;
77027a0bc89SDoug Rabson struct direntry *dentp;
77127a0bc89SDoug Rabson
77227a0bc89SDoug Rabson /*
77327a0bc89SDoug Rabson * Since the filesize field in directory entries for a directory is
77427a0bc89SDoug Rabson * zero, we just have to feel our way through the directory until
77527a0bc89SDoug Rabson * we hit end of file.
77627a0bc89SDoug Rabson */
77727a0bc89SDoug Rabson for (cn = 0;; cn++) {
778952a6212SJordan K. Hubbard if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
77927a0bc89SDoug Rabson if (error == E2BIG)
780952a6212SJordan K. Hubbard return (1); /* it's empty */
781952a6212SJordan K. Hubbard return (0);
782952a6212SJordan K. Hubbard }
783952a6212SJordan K. Hubbard error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
784952a6212SJordan K. Hubbard if (error) {
785952a6212SJordan K. Hubbard return (0);
786952a6212SJordan K. Hubbard }
787952a6212SJordan K. Hubbard for (dentp = (struct direntry *)bp->b_data;
788952a6212SJordan K. Hubbard (char *)dentp < bp->b_data + blsize;
789952a6212SJordan K. Hubbard dentp++) {
790952a6212SJordan K. Hubbard if (dentp->deName[0] != SLOT_DELETED &&
791952a6212SJordan K. Hubbard (dentp->deAttributes & ATTR_VOLUME) == 0) {
79227a0bc89SDoug Rabson /*
79327a0bc89SDoug Rabson * In dos directories an entry whose name
79427a0bc89SDoug Rabson * starts with SLOT_EMPTY (0) starts the
79527a0bc89SDoug Rabson * beginning of the unused part of the
79627a0bc89SDoug Rabson * directory, so we can just return that it
79727a0bc89SDoug Rabson * is empty.
79827a0bc89SDoug Rabson */
79927a0bc89SDoug Rabson if (dentp->deName[0] == SLOT_EMPTY) {
80027a0bc89SDoug Rabson brelse(bp);
801952a6212SJordan K. Hubbard return (1);
80227a0bc89SDoug Rabson }
80327a0bc89SDoug Rabson /*
80427a0bc89SDoug Rabson * Any names other than "." and ".." in a
80527a0bc89SDoug Rabson * directory mean it is not empty.
80627a0bc89SDoug Rabson */
80727a0bc89SDoug Rabson if (bcmp(dentp->deName, ". ", 11) &&
80827a0bc89SDoug Rabson bcmp(dentp->deName, ".. ", 11)) {
80927a0bc89SDoug Rabson brelse(bp);
81027a0bc89SDoug Rabson #ifdef MSDOSFS_DEBUG
811952a6212SJordan K. Hubbard printf("dosdirempty(): entry found %02x, %02x\n",
812952a6212SJordan K. Hubbard dentp->deName[0], dentp->deName[1]);
81327a0bc89SDoug Rabson #endif
814952a6212SJordan K. Hubbard return (0); /* not empty */
81527a0bc89SDoug Rabson }
81627a0bc89SDoug Rabson }
81727a0bc89SDoug Rabson }
81827a0bc89SDoug Rabson brelse(bp);
81927a0bc89SDoug Rabson }
82027a0bc89SDoug Rabson /* NOTREACHED */
82127a0bc89SDoug Rabson }
82227a0bc89SDoug Rabson
82327a0bc89SDoug Rabson /*
82427a0bc89SDoug Rabson * Check to see if the directory described by target is in some
82527a0bc89SDoug Rabson * subdirectory of source. This prevents something like the following from
82627a0bc89SDoug Rabson * succeeding and leaving a bunch or files and directories orphaned. mv
82727a0bc89SDoug Rabson * /a/b/c /a/b/c/d/e/f Where c and f are directories.
82827a0bc89SDoug Rabson *
82927a0bc89SDoug Rabson * source - the inode for /a/b/c
83027a0bc89SDoug Rabson * target - the inode for /a/b/c/d/e/f
83127a0bc89SDoug Rabson *
83227a0bc89SDoug Rabson * Returns 0 if target is NOT a subdirectory of source.
83327a0bc89SDoug Rabson * Otherwise returns a non-zero error number.
83427a0bc89SDoug Rabson */
83527a0bc89SDoug Rabson int
doscheckpath(struct denode * source,struct denode * target,daddr_t * wait_scn)83695d42526SKonstantin Belousov doscheckpath(struct denode *source, struct denode *target, daddr_t *wait_scn)
83727a0bc89SDoug Rabson {
83827a0bc89SDoug Rabson daddr_t scn;
83927a0bc89SDoug Rabson struct msdosfsmount *pmp;
84027a0bc89SDoug Rabson struct direntry *ep;
84127a0bc89SDoug Rabson struct denode *dep;
84227a0bc89SDoug Rabson struct buf *bp = NULL;
84327a0bc89SDoug Rabson int error = 0;
84427a0bc89SDoug Rabson
84595d42526SKonstantin Belousov *wait_scn = 0;
846952a6212SJordan K. Hubbard
84795d42526SKonstantin Belousov pmp = target->de_pmp;
8486ae13c0fSKonstantin Belousov lockmgr_assert(&pmp->pm_checkpath_lock, KA_XLOCKED);
84995d42526SKonstantin Belousov KASSERT(pmp == source->de_pmp,
85095d42526SKonstantin Belousov ("doscheckpath: source and target on different filesystems"));
85195d42526SKonstantin Belousov
85295d42526SKonstantin Belousov if ((target->de_Attributes & ATTR_DIRECTORY) == 0 ||
85395d42526SKonstantin Belousov (source->de_Attributes & ATTR_DIRECTORY) == 0)
85495d42526SKonstantin Belousov return (ENOTDIR);
85595d42526SKonstantin Belousov
85695d42526SKonstantin Belousov if (target->de_StartCluster == source->de_StartCluster)
85795d42526SKonstantin Belousov return (EEXIST);
85895d42526SKonstantin Belousov
85995d42526SKonstantin Belousov if (target->de_StartCluster == MSDOSFSROOT ||
86095d42526SKonstantin Belousov (FAT32(pmp) && target->de_StartCluster == pmp->pm_rootdirblk))
86195d42526SKonstantin Belousov return (0);
86295d42526SKonstantin Belousov
86395d42526SKonstantin Belousov dep = target;
86495d42526SKonstantin Belousov vget(DETOV(dep), LK_EXCLUSIVE);
86527a0bc89SDoug Rabson for (;;) {
86627a0bc89SDoug Rabson if ((dep->de_Attributes & ATTR_DIRECTORY) == 0) {
86727a0bc89SDoug Rabson error = ENOTDIR;
868952a6212SJordan K. Hubbard break;
86927a0bc89SDoug Rabson }
87027a0bc89SDoug Rabson scn = dep->de_StartCluster;
87127a0bc89SDoug Rabson error = bread(pmp->pm_devvp, cntobn(pmp, scn),
87227a0bc89SDoug Rabson pmp->pm_bpcluster, NOCRED, &bp);
87395d42526SKonstantin Belousov if (error != 0)
87427a0bc89SDoug Rabson break;
875952a6212SJordan K. Hubbard
87627a0bc89SDoug Rabson ep = (struct direntry *)bp->b_data + 1;
87727a0bc89SDoug Rabson if ((ep->deAttributes & ATTR_DIRECTORY) == 0 ||
87827a0bc89SDoug Rabson bcmp(ep->deName, ".. ", 11) != 0) {
87927a0bc89SDoug Rabson error = ENOTDIR;
88095d42526SKonstantin Belousov brelse(bp);
88127a0bc89SDoug Rabson break;
88227a0bc89SDoug Rabson }
88395d42526SKonstantin Belousov
88427a0bc89SDoug Rabson scn = getushort(ep->deStartCluster);
885952a6212SJordan K. Hubbard if (FAT32(pmp))
886952a6212SJordan K. Hubbard scn |= getushort(ep->deHighClust) << 16;
88795d42526SKonstantin Belousov brelse(bp);
888952a6212SJordan K. Hubbard
88927a0bc89SDoug Rabson if (scn == source->de_StartCluster) {
89027a0bc89SDoug Rabson error = EINVAL;
89127a0bc89SDoug Rabson break;
89227a0bc89SDoug Rabson }
89327a0bc89SDoug Rabson if (scn == MSDOSFSROOT)
89427a0bc89SDoug Rabson break;
895952a6212SJordan K. Hubbard if (FAT32(pmp) && scn == pmp->pm_rootdirblk) {
896952a6212SJordan K. Hubbard /*
897952a6212SJordan K. Hubbard * scn should be 0 in this case,
898952a6212SJordan K. Hubbard * but we silently ignore the error.
899952a6212SJordan K. Hubbard */
900952a6212SJordan K. Hubbard break;
901952a6212SJordan K. Hubbard }
902952a6212SJordan K. Hubbard
90327a0bc89SDoug Rabson vput(DETOV(dep));
90495d42526SKonstantin Belousov dep = NULL;
905952a6212SJordan K. Hubbard /* NOTE: deget() clears dep on error */
90695d42526SKonstantin Belousov error = deget(pmp, scn, 0, LK_EXCLUSIVE | LK_NOWAIT, &dep);
90795d42526SKonstantin Belousov if (error != 0) {
90895d42526SKonstantin Belousov *wait_scn = scn;
90927a0bc89SDoug Rabson break;
91027a0bc89SDoug Rabson }
91195d42526SKonstantin Belousov }
91254cf9198SKonstantin Belousov #ifdef MSDOSFS_DEBUG
91327a0bc89SDoug Rabson if (error == ENOTDIR)
91427a0bc89SDoug Rabson printf("doscheckpath(): .. not a directory?\n");
91554cf9198SKonstantin Belousov #endif
91627a0bc89SDoug Rabson if (dep != NULL)
91727a0bc89SDoug Rabson vput(DETOV(dep));
918952a6212SJordan K. Hubbard return (error);
91927a0bc89SDoug Rabson }
92027a0bc89SDoug Rabson
92127a0bc89SDoug Rabson /*
92227a0bc89SDoug Rabson * Read in the disk block containing the directory entry (dirclu, dirofs)
92327a0bc89SDoug Rabson * and return the address of the buf header, and the address of the
92427a0bc89SDoug Rabson * directory entry within the block.
92527a0bc89SDoug Rabson */
92627a0bc89SDoug Rabson int
readep(struct msdosfsmount * pmp,u_long dirclust,u_long diroffset,struct buf ** bpp,struct direntry ** epp)92710c9700fSEd Maste readep(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset,
92810c9700fSEd Maste struct buf **bpp, struct direntry **epp)
92927a0bc89SDoug Rabson {
93027a0bc89SDoug Rabson int error;
93127a0bc89SDoug Rabson daddr_t bn;
932952a6212SJordan K. Hubbard int blsize;
93327a0bc89SDoug Rabson
934952a6212SJordan K. Hubbard blsize = pmp->pm_bpcluster;
935952a6212SJordan K. Hubbard if (dirclust == MSDOSFSROOT
936952a6212SJordan K. Hubbard && de_blk(pmp, diroffset + blsize) > pmp->pm_rootdirsize)
937952a6212SJordan K. Hubbard blsize = de_bn2off(pmp, pmp->pm_rootdirsize) & pmp->pm_crbomask;
938952a6212SJordan K. Hubbard bn = detobn(pmp, dirclust, diroffset);
939952a6212SJordan K. Hubbard if ((error = bread(pmp->pm_devvp, bn, blsize, NOCRED, bpp)) != 0) {
940952a6212SJordan K. Hubbard brelse(*bpp);
94127a0bc89SDoug Rabson *bpp = NULL;
942952a6212SJordan K. Hubbard return (error);
94327a0bc89SDoug Rabson }
94427a0bc89SDoug Rabson if (epp)
945952a6212SJordan K. Hubbard *epp = bptoep(pmp, *bpp, diroffset);
946952a6212SJordan K. Hubbard return (0);
94727a0bc89SDoug Rabson }
94827a0bc89SDoug Rabson
94927a0bc89SDoug Rabson /*
95027a0bc89SDoug Rabson * Read in the disk block containing the directory entry dep came from and
95127a0bc89SDoug Rabson * return the address of the buf header, and the address of the directory
95227a0bc89SDoug Rabson * entry within the block.
95327a0bc89SDoug Rabson */
95427a0bc89SDoug Rabson int
readde(struct denode * dep,struct buf ** bpp,struct direntry ** epp)95510c9700fSEd Maste readde(struct denode *dep, struct buf **bpp, struct direntry **epp)
95627a0bc89SDoug Rabson {
957952a6212SJordan K. Hubbard
958952a6212SJordan K. Hubbard return (readep(dep->de_pmp, dep->de_dirclust, dep->de_diroffset,
959952a6212SJordan K. Hubbard bpp, epp));
960952a6212SJordan K. Hubbard }
961952a6212SJordan K. Hubbard
962952a6212SJordan K. Hubbard /*
963952a6212SJordan K. Hubbard * Remove a directory entry. At this point the file represented by the
964952a6212SJordan K. Hubbard * directory entry to be removed is still full length until no one has it
965952a6212SJordan K. Hubbard * open. When the file no longer being used msdosfs_inactive() is called
966952a6212SJordan K. Hubbard * and will truncate the file to 0 length. When the vnode containing the
967952a6212SJordan K. Hubbard * denode is needed for some other purpose by VFS it will call
968952a6212SJordan K. Hubbard * msdosfs_reclaim() which will remove the denode from the denode cache.
9694882501bSEd Maste *
9704882501bSEd Maste * pdep directory where the entry is removed
9714882501bSEd Maste * dep file to be removed
972952a6212SJordan K. Hubbard */
973952a6212SJordan K. Hubbard int
removede(struct denode * pdep,struct denode * dep)97410c9700fSEd Maste removede(struct denode *pdep, struct denode *dep)
975952a6212SJordan K. Hubbard {
976952a6212SJordan K. Hubbard int error;
977952a6212SJordan K. Hubbard struct direntry *ep;
978952a6212SJordan K. Hubbard struct buf *bp;
979952a6212SJordan K. Hubbard daddr_t bn;
980952a6212SJordan K. Hubbard int blsize;
981952a6212SJordan K. Hubbard struct msdosfsmount *pmp = pdep->de_pmp;
982952a6212SJordan K. Hubbard u_long offset = pdep->de_fndoffset;
983952a6212SJordan K. Hubbard
984952a6212SJordan K. Hubbard #ifdef MSDOSFS_DEBUG
985952a6212SJordan K. Hubbard printf("removede(): filename %s, dep %p, offset %08lx\n",
986952a6212SJordan K. Hubbard dep->de_Name, dep, offset);
987952a6212SJordan K. Hubbard #endif
988952a6212SJordan K. Hubbard
989952a6212SJordan K. Hubbard dep->de_refcnt--;
990952a6212SJordan K. Hubbard offset += sizeof(struct direntry);
991952a6212SJordan K. Hubbard do {
992952a6212SJordan K. Hubbard offset -= sizeof(struct direntry);
993952a6212SJordan K. Hubbard error = pcbmap(pdep, de_cluster(pmp, offset), &bn, 0, &blsize);
994952a6212SJordan K. Hubbard if (error)
995952a6212SJordan K. Hubbard return error;
996952a6212SJordan K. Hubbard error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
997952a6212SJordan K. Hubbard if (error) {
998952a6212SJordan K. Hubbard return error;
999952a6212SJordan K. Hubbard }
1000952a6212SJordan K. Hubbard ep = bptoep(pmp, bp, offset);
1001952a6212SJordan K. Hubbard /*
1002952a6212SJordan K. Hubbard * Check whether, if we came here the second time, i.e.
1003952a6212SJordan K. Hubbard * when underflowing into the previous block, the last
1004952a6212SJordan K. Hubbard * entry in this block is a longfilename entry, too.
1005952a6212SJordan K. Hubbard */
1006952a6212SJordan K. Hubbard if (ep->deAttributes != ATTR_WIN95
1007952a6212SJordan K. Hubbard && offset != pdep->de_fndoffset) {
1008952a6212SJordan K. Hubbard brelse(bp);
1009952a6212SJordan K. Hubbard break;
1010952a6212SJordan K. Hubbard }
1011952a6212SJordan K. Hubbard offset += sizeof(struct direntry);
1012952a6212SJordan K. Hubbard while (1) {
1013952a6212SJordan K. Hubbard /*
1014b3a15dddSPedro F. Giffuni * We are a bit aggressive here in that we delete any Win95
1015952a6212SJordan K. Hubbard * entries preceding this entry, not just the ones we "own".
1016952a6212SJordan K. Hubbard * Since these presumably aren't valid anyway,
1017952a6212SJordan K. Hubbard * there should be no harm.
1018952a6212SJordan K. Hubbard */
1019952a6212SJordan K. Hubbard offset -= sizeof(struct direntry);
1020952a6212SJordan K. Hubbard ep--->deName[0] = SLOT_DELETED;
1021c33db74bSStefan Eßer rootde_freed(pdep);
1022952a6212SJordan K. Hubbard if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95)
1023952a6212SJordan K. Hubbard || !(offset & pmp->pm_crbomask)
1024952a6212SJordan K. Hubbard || ep->deAttributes != ATTR_WIN95)
1025952a6212SJordan K. Hubbard break;
1026952a6212SJordan K. Hubbard }
10272aacee77SKonstantin Belousov if (DOINGASYNC(DETOV(pdep)))
1028cb65c1eeSBruce Evans bdwrite(bp);
1029cb65c1eeSBruce Evans else if ((error = bwrite(bp)) != 0)
1030952a6212SJordan K. Hubbard return error;
1031952a6212SJordan K. Hubbard } while (!(pmp->pm_flags & MSDOSFSMNT_NOWIN95)
1032952a6212SJordan K. Hubbard && !(offset & pmp->pm_crbomask)
1033952a6212SJordan K. Hubbard && offset);
1034952a6212SJordan K. Hubbard return 0;
1035952a6212SJordan K. Hubbard }
1036952a6212SJordan K. Hubbard
1037952a6212SJordan K. Hubbard /*
1038952a6212SJordan K. Hubbard * Create a unique DOS name in dvp
1039952a6212SJordan K. Hubbard */
1040952a6212SJordan K. Hubbard int
uniqdosname(struct denode * dep,struct componentname * cnp,u_char * cp)104110c9700fSEd Maste uniqdosname(struct denode *dep, struct componentname *cnp, u_char *cp)
1042952a6212SJordan K. Hubbard {
1043952a6212SJordan K. Hubbard struct msdosfsmount *pmp = dep->de_pmp;
1044952a6212SJordan K. Hubbard struct direntry *dentp;
1045952a6212SJordan K. Hubbard int gen;
1046952a6212SJordan K. Hubbard int blsize;
1047952a6212SJordan K. Hubbard u_long cn;
1048952a6212SJordan K. Hubbard daddr_t bn;
1049952a6212SJordan K. Hubbard struct buf *bp;
1050952a6212SJordan K. Hubbard int error;
1051952a6212SJordan K. Hubbard
1052af9f1d50SDmitrij Tejblum if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1053011cdb57SDmitrij Tejblum return (unix2dosfn((const u_char *)cnp->cn_nameptr, cp,
1054c4f02a89SMax Khon cnp->cn_namelen, 0, pmp) ? 0 : EINVAL);
1055011cdb57SDmitrij Tejblum
1056952a6212SJordan K. Hubbard for (gen = 1;; gen++) {
1057952a6212SJordan K. Hubbard /*
1058952a6212SJordan K. Hubbard * Generate DOS name with generation number
1059952a6212SJordan K. Hubbard */
1060952a6212SJordan K. Hubbard if (!unix2dosfn((const u_char *)cnp->cn_nameptr, cp,
1061c4f02a89SMax Khon cnp->cn_namelen, gen, pmp))
1062952a6212SJordan K. Hubbard return gen == 1 ? EINVAL : EEXIST;
1063952a6212SJordan K. Hubbard
1064952a6212SJordan K. Hubbard /*
1065952a6212SJordan K. Hubbard * Now look for a dir entry with this exact name
1066952a6212SJordan K. Hubbard */
1067952a6212SJordan K. Hubbard for (cn = error = 0; !error; cn++) {
1068952a6212SJordan K. Hubbard if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
1069952a6212SJordan K. Hubbard if (error == E2BIG) /* EOF reached and not found */
1070952a6212SJordan K. Hubbard return 0;
1071952a6212SJordan K. Hubbard return error;
1072952a6212SJordan K. Hubbard }
1073952a6212SJordan K. Hubbard error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1074952a6212SJordan K. Hubbard if (error) {
1075952a6212SJordan K. Hubbard return error;
1076952a6212SJordan K. Hubbard }
1077952a6212SJordan K. Hubbard for (dentp = (struct direntry *)bp->b_data;
1078952a6212SJordan K. Hubbard (char *)dentp < bp->b_data + blsize;
1079952a6212SJordan K. Hubbard dentp++) {
1080952a6212SJordan K. Hubbard if (dentp->deName[0] == SLOT_EMPTY) {
1081952a6212SJordan K. Hubbard /*
1082952a6212SJordan K. Hubbard * Last used entry and not found
1083952a6212SJordan K. Hubbard */
1084952a6212SJordan K. Hubbard brelse(bp);
1085952a6212SJordan K. Hubbard return 0;
1086952a6212SJordan K. Hubbard }
1087952a6212SJordan K. Hubbard /*
1088952a6212SJordan K. Hubbard * Ignore volume labels and Win95 entries
1089952a6212SJordan K. Hubbard */
1090952a6212SJordan K. Hubbard if (dentp->deAttributes & ATTR_VOLUME)
1091952a6212SJordan K. Hubbard continue;
1092952a6212SJordan K. Hubbard if (!bcmp(dentp->deName, cp, 11)) {
1093952a6212SJordan K. Hubbard error = EEXIST;
1094952a6212SJordan K. Hubbard break;
1095952a6212SJordan K. Hubbard }
1096952a6212SJordan K. Hubbard }
1097952a6212SJordan K. Hubbard brelse(bp);
1098952a6212SJordan K. Hubbard }
1099952a6212SJordan K. Hubbard }
1100952a6212SJordan K. Hubbard }
1101