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 $
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
34 #include <sys/types.h>
36 #include <sys/vnode.h>
37 #include <sys/mount.h>
38 #include <sys/namei.h>
39 #include <sys/malloc.h>
42 #include <fs/hpfs/hpfs.h>
43 #include <fs/hpfs/hpfsmount.h>
44 #include <fs/hpfs/hpfs_subr.h>
46 int hpfs_removedirent (struct hpfsmount *, lsn_t, char *, int, int *);
49 * This routine traverse the b+ tree representing directory
50 * looking for file named 'name'. Returns buf struct and hpfsdirent
51 * pointer. Calling routine is supposed to brelse buffer.
52 * name is supposed in Unix encodeing.
55 hpfs_genlookupbyname (
60 struct hpfsdirent **depp)
62 struct hpfsmount *hpmp = dhp->h_hpmp;
65 struct hpfsdirent *dep;
69 dprintf(("hpfs_genlookupbyname(0x%x, %s (%d)): \n",
70 dhp->h_no, name, namelen));
72 lsn = ((alleaf_t *)dhp->h_fn.fn_abd)->al_lsn;
74 error = hpfs_breaddirblk (hpmp, lsn, &bp);
78 dp = (struct dirblk *) bp->b_data;
81 while(!(dep->de_flag & DE_END)) {
82 dprintf(("no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x\n",
83 dep->de_fnode, dep->de_size, dep->de_namelen,
84 dep->de_namelen, dep->de_name, dep->de_flag));
86 res = hpfs_cmpfname(hpmp, name, namelen,
87 dep->de_name, dep->de_namelen, dep->de_cpid);
95 dep = (hpfsdirent_t *)(((caddr_t)dep) + dep->de_reclen);
98 if (dep->de_flag & DE_DOWN) {
99 lsn = DE_DOWNLSN(dep);
113 struct componentname *cnp,
117 register struct hpfsnode *dhp = VTOHP(dvp);
118 dprintf(("hpfs_makefnode(0x%x, %s, %ld): \n",
119 dhp->h_no, cnp->cn_nameptr, cnp->cn_namelen));
127 struct hpfsmount *hpmp,
136 struct hpfsdirent *dep;
140 dprintf(("hpfs_removedirent(0x%x, %.*s, %d): \n",
141 lsn, namelen, name, namelen));
143 error = hpfs_breaddirblk (hpmp, lsn, &bp);
147 dbp = (dirblk_t *) bp->b_data;
148 deoff = sizeof(dirblk_t);
149 dep = DB_DIRENT(dbp);
151 while(!(dep->de_flag & DE_END)) {
152 dprintf(("no: 0x%x, size: %d, name: %2d:%.*s, flag: 0x%x\n",
153 dep->de_fnode, dep->de_size, dep->de_namelen,
154 dep->de_namelen, dep->de_name, dep->de_flag));
156 res = hpfs_cmpfname(hpmp, name, namelen,
157 dep->de_name, dep->de_namelen, dep->de_cpid);
159 if (dep->de_flag & DE_DOWN) {
162 /* XXX we can copy less */
163 bcopy (DE_NEXTDE(dep), dep, DB_BSIZE - deoff - dep->de_reclen);
164 dbp->d_freeoff -= dep->de_reclen;
172 deoff += dep->de_reclen;
173 dep = DB_NEXTDE(dep);
176 if (dep->de_flag & DE_DOWN) {
177 error = hpfs_removede (hpmp, DE_DOWNLSN(dep), name, namelen, &ret);
183 if (deoff > sizeof (dirblk_t)) {
184 } else if (deoff + dep->de_reclen < dbp->db_freeoff) {
201 struct componentname *cnp)
204 register struct hpfsnode *dhp = VTOHP(dvp);
205 register struct hpfsnode *hp = VTOHP(vp);
206 dprintf(("hpfs_removefnode(0x%x, 0x%x, %s, %ld): \n",
207 dhp->h_no, hp->h_no, cnp->cn_nameptr, cnp->cn_namelen));