2 * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/fs/hpfs/hpfs_lookup.c,v 1.1 1999/12/09 19:09:59 semenu Exp $
27 * $DragonFly: src/sys/vfs/hpfs/hpfs_lookup.c,v 1.4 2003/08/07 21:17:41 dillon Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
35 #include <sys/types.h>
37 #include <sys/vnode.h>
38 #include <sys/mount.h>
39 #include <sys/namei.h>
40 #include <sys/malloc.h>
44 #include "hpfsmount.h"
45 #include "hpfs_subr.h"
47 int hpfs_removedirent (struct hpfsmount
*, lsn_t
, char *, int, int *);
50 * This routine traverse the b+ tree representing directory
51 * looking for file named 'name'. Returns buf struct and hpfsdirent
52 * pointer. Calling routine is supposed to brelse buffer.
53 * name is supposed in Unix encodeing.
56 hpfs_genlookupbyname (
61 struct hpfsdirent
**depp
)
63 struct hpfsmount
*hpmp
= dhp
->h_hpmp
;
66 struct hpfsdirent
*dep
;
70 dprintf(("hpfs_genlookupbyname(0x%x, %s (%d)): \n",
71 dhp
->h_no
, name
, namelen
));
73 lsn
= ((alleaf_t
*)dhp
->h_fn
.fn_abd
)->al_lsn
;
75 error
= hpfs_breaddirblk (hpmp
, lsn
, &bp
);
79 dp
= (struct dirblk
*) bp
->b_data
;
82 while(!(dep
->de_flag
& DE_END
)) {
83 dprintf(("no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x\n",
84 dep
->de_fnode
, dep
->de_size
, dep
->de_namelen
,
85 dep
->de_namelen
, dep
->de_name
, dep
->de_flag
));
87 res
= hpfs_cmpfname(hpmp
, name
, namelen
,
88 dep
->de_name
, dep
->de_namelen
, dep
->de_cpid
);
96 dep
= (hpfsdirent_t
*)(((caddr_t
)dep
) + dep
->de_reclen
);
99 if (dep
->de_flag
& DE_DOWN
) {
100 lsn
= DE_DOWNLSN(dep
);
114 struct componentname
*cnp
,
118 struct hpfsnode
*dhp
= VTOHP(dvp
);
119 dprintf(("hpfs_makefnode(0x%x, %s, %ld): \n",
120 dhp
->h_no
, cnp
->cn_nameptr
, cnp
->cn_namelen
));
128 struct hpfsmount
*hpmp
,
137 struct hpfsdirent
*dep
;
141 dprintf(("hpfs_removedirent(0x%x, %.*s, %d): \n",
142 lsn
, namelen
, name
, namelen
));
144 error
= hpfs_breaddirblk (hpmp
, lsn
, &bp
);
148 dbp
= (dirblk_t
*) bp
->b_data
;
149 deoff
= sizeof(dirblk_t
);
150 dep
= DB_DIRENT(dbp
);
152 while(!(dep
->de_flag
& DE_END
)) {
153 dprintf(("no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x\n",
154 dep
->de_fnode
, dep
->de_size
, dep
->de_namelen
,
155 dep
->de_namelen
, dep
->de_name
, dep
->de_flag
));
157 res
= hpfs_cmpfname(hpmp
, name
, namelen
,
158 dep
->de_name
, dep
->de_namelen
, dep
->de_cpid
);
160 if (dep
->de_flag
& DE_DOWN
) {
163 /* XXX we can copy less */
164 bcopy (DE_NEXTDE(dep
), dep
, DB_BSIZE
- deoff
- dep
->de_reclen
);
165 dbp
->d_freeoff
-= dep
->de_reclen
;
173 deoff
+= dep
->de_reclen
;
174 dep
= DB_NEXTDE(dep
);
177 if (dep
->de_flag
& DE_DOWN
) {
178 error
= hpfs_removede (hpmp
, DE_DOWNLSN(dep
), name
, namelen
, &ret
);
184 if (deoff
> sizeof (dirblk_t
)) {
185 } else if (deoff
+ dep
->de_reclen
< dbp
->db_freeoff
) {
202 struct componentname
*cnp
)
205 struct hpfsnode
*dhp
= VTOHP(dvp
);
206 struct hpfsnode
*hp
= VTOHP(vp
);
207 dprintf(("hpfs_removefnode(0x%x, 0x%x, %s, %ld): \n",
208 dhp
->h_no
, hp
->h_no
, cnp
->cn_nameptr
, cnp
->cn_namelen
));