Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / vfs / hpfs / hpfs_lookup.c
1 /*-
2  * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/fs/hpfs/hpfs_lookup.c,v 1.1 1999/12/09 19:09:59 semenu Exp $
27  */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/proc.h>
33 #include <sys/time.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <sys/vnode.h>
37 #include <sys/mount.h>
38 #include <sys/namei.h>
39 #include <sys/malloc.h>
40 #include <sys/buf.h>
41
42 #include <fs/hpfs/hpfs.h>
43 #include <fs/hpfs/hpfsmount.h>
44 #include <fs/hpfs/hpfs_subr.h>
45
46 int     hpfs_removedirent (struct hpfsmount *, lsn_t, char *, int, int *);
47
48 /*
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.
53  */
54 int
55 hpfs_genlookupbyname (
56         struct hpfsnode *dhp,
57         char *name,
58         int namelen,
59         struct buf **bpp,
60         struct hpfsdirent **depp)
61 {
62         struct hpfsmount *hpmp = dhp->h_hpmp;
63         struct buf *bp;
64         struct dirblk *dp;
65         struct hpfsdirent *dep;
66         lsn_t lsn;
67         int error, res;
68
69         dprintf(("hpfs_genlookupbyname(0x%x, %s (%d)): \n", 
70                 dhp->h_no, name, namelen));
71
72         lsn = ((alleaf_t *)dhp->h_fn.fn_abd)->al_lsn;
73 dive:
74         error = hpfs_breaddirblk (hpmp, lsn, &bp);
75         if (error)
76                 return (error);
77
78         dp = (struct dirblk *) bp->b_data;
79         dep = D_DIRENT(dp);
80
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));
85
86                 res = hpfs_cmpfname(hpmp, name, namelen,
87                                 dep->de_name, dep->de_namelen, dep->de_cpid);
88                 if (res == 0) {
89                         *bpp = bp;
90                         *depp = dep;
91                         return (0);
92                 } else if (res < 0)
93                         break;
94
95                 dep = (hpfsdirent_t *)(((caddr_t)dep) + dep->de_reclen);
96         }
97
98         if (dep->de_flag & DE_DOWN) {
99                 lsn = DE_DOWNLSN(dep);
100                 brelse(bp);
101                 goto dive;
102         }
103
104         brelse(bp);
105
106         return (ENOENT);
107 }
108
109 int
110 hpfs_makefnode (
111         struct vnode * dvp,
112         struct vnode ** vpp,
113         struct componentname *cnp,
114         struct vattr *vap)
115 {
116 #ifdef HPFS_DEBUG
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));
120 #endif
121
122         return (EOPNOTSUPP);
123 }
124
125 int
126 hpfs_removedirent (
127         struct hpfsmount *hpmp,
128         lsn_t lsn,
129         char *name,
130         int namelen,
131         int *retp)
132 {
133 #if 0
134         struct buf *bp;
135         dirblk_t *dbp;
136         struct hpfsdirent *dep;
137         int deoff;
138         int error, ret;
139
140         dprintf(("hpfs_removedirent(0x%x, %.*s, %d): \n",
141                  lsn, namelen, name, namelen));
142
143         error = hpfs_breaddirblk (hpmp, lsn, &bp);
144         if (error)
145                 return (error);
146
147         dbp = (dirblk_t *) bp->b_data;
148         deoff = sizeof(dirblk_t);
149         dep = DB_DIRENT(dbp);
150
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));
155
156                 res = hpfs_cmpfname(hpmp, name, namelen,
157                                 dep->de_name, dep->de_namelen, dep->de_cpid);
158                 if (res == 0) {
159                         if (dep->de_flag & DE_DOWN) {
160                                 /*XXXXXX*/
161                         } else {
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;
165                                 *retp = 0;
166                         }
167                         bdwrite (bp);
168                         return (0);
169                 } else if (res < 0)
170                         break;
171
172                 deoff += dep->de_reclen;
173                 dep = DB_NEXTDE(dep);
174         }
175
176         if (dep->de_flag & DE_DOWN) {
177                 error = hpfs_removede (hpmp, DE_DOWNLSN(dep), name, namelen, &ret);
178                 if (error) {
179                         brelse (bp);
180                         return (error);
181                 }
182                 if (ret == 0) {
183                         if (deoff > sizeof (dirblk_t)) {
184                         } else if (deoff + dep->de_reclen < dbp->db_freeoff) {
185                         }
186                 }
187         } else {
188                 error = ENOENT;
189         }
190
191         brelse (bp);
192         return (error);
193 #endif
194         return (EOPNOTSUPP);
195 }
196
197 int
198 hpfs_removefnode (
199         struct vnode * dvp,
200         struct vnode * vp,
201         struct componentname *cnp)
202 {
203 #ifdef HPFS_DEBUG
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));
208 #endif
209
210
211         return (EOPNOTSUPP);
212 }