This source file includes following definitions.
- cd9660_lookup
- cd9660_bufatoff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 #include <sys/param.h>
43 #include <sys/namei.h>
44 #include <sys/buf.h>
45 #include <sys/file.h>
46 #include <sys/vnode.h>
47 #include <sys/mount.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
50
51 #include <isofs/cd9660/iso.h>
52 #include <isofs/cd9660/cd9660_extern.h>
53 #include <isofs/cd9660/cd9660_node.h>
54 #include <isofs/cd9660/iso_rrip.h>
55 #include <isofs/cd9660/cd9660_rrip.h>
56
57 struct nchstats iso_nchstats;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 int
95 cd9660_lookup(v)
96 void *v;
97 {
98 struct vop_lookup_args *ap = v;
99 register struct vnode *vdp;
100 register struct iso_node *dp;
101 register struct iso_mnt *imp;
102 struct buf *bp;
103 struct iso_directory_record *ep = NULL;
104
105 int entryoffsetinblock;
106 int saveoffset = -1;
107 int numdirpasses;
108 doff_t endsearch;
109 struct vnode *pdp;
110 struct vnode *tdp;
111 u_long bmask;
112 int lockparent;
113 int wantparent;
114 int error;
115 ino_t ino = 0;
116 int reclen;
117 u_short namelen;
118 char *altname;
119 int res;
120 int assoc, len;
121 char *name;
122 struct vnode **vpp = ap->a_vpp;
123 struct componentname *cnp = ap->a_cnp;
124 struct ucred *cred = cnp->cn_cred;
125 int flags;
126 int nameiop = cnp->cn_nameiop;
127 struct proc *p = cnp->cn_proc;
128
129 cnp->cn_flags &= ~PDIRUNLOCK;
130 flags = cnp->cn_flags;
131
132 bp = NULL;
133 *vpp = NULL;
134 vdp = ap->a_dvp;
135 dp = VTOI(vdp);
136 imp = dp->i_mnt;
137 lockparent = flags & LOCKPARENT;
138 wantparent = flags & (LOCKPARENT|WANTPARENT);
139
140
141
142
143 if ((error = VOP_ACCESS(vdp, VEXEC, cred, cnp->cn_proc)) != 0)
144 return (error);
145
146 if ((flags & ISLASTCN) && (vdp->v_mount->mnt_flag & MNT_RDONLY) &&
147 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
148 return (EROFS);
149
150
151
152
153
154
155
156
157 if ((error = cache_lookup(vdp, vpp, cnp)) >= 0)
158 return (error);
159
160 len = cnp->cn_namelen;
161 name = cnp->cn_nameptr;
162
163
164
165 assoc = (imp->iso_ftype != ISO_FTYPE_RRIP && *name == ASSOCCHAR);
166 if (assoc) {
167 len--;
168 name++;
169 }
170
171
172
173
174
175
176
177
178
179
180
181
182 bmask = imp->im_bmask;
183 if (nameiop != LOOKUP || dp->i_diroff == 0 ||
184 dp->i_diroff > dp->i_size) {
185 entryoffsetinblock = 0;
186 dp->i_offset = 0;
187 numdirpasses = 1;
188 } else {
189 dp->i_offset = dp->i_diroff;
190 if ((entryoffsetinblock = dp->i_offset & bmask) &&
191 (error = cd9660_bufatoff(dp, (off_t)dp->i_offset, NULL,
192 &bp)))
193 return (error);
194 numdirpasses = 2;
195 iso_nchstats.ncs_2passes++;
196 }
197 endsearch = dp->i_size;
198
199 searchloop:
200 while (dp->i_offset < endsearch) {
201
202
203
204
205
206 if ((dp->i_offset & bmask) == 0) {
207 if (bp != NULL)
208 brelse(bp);
209 error = cd9660_bufatoff(dp, (off_t)dp->i_offset,
210 NULL, &bp);
211 if (error)
212 return (error);
213 entryoffsetinblock = 0;
214 }
215
216
217
218 ep = (struct iso_directory_record *)
219 ((char *)bp->b_data + entryoffsetinblock);
220
221 reclen = isonum_711(ep->length);
222 if (reclen == 0) {
223
224 dp->i_offset =
225 (dp->i_offset & ~bmask) + imp->logical_block_size;
226 continue;
227 }
228
229 if (reclen < ISO_DIRECTORY_RECORD_SIZE)
230
231 break;
232
233 if (entryoffsetinblock + reclen > imp->logical_block_size)
234
235 break;
236
237 namelen = isonum_711(ep->name_len);
238
239 if (reclen < ISO_DIRECTORY_RECORD_SIZE + namelen)
240
241 break;
242
243
244
245
246 switch (imp->iso_ftype) {
247 default:
248 if ((!(isonum_711(ep->flags)&4)) == !assoc) {
249 if ((len == 1
250 && *name == '.')
251 || (flags & ISDOTDOT)) {
252 if (namelen == 1
253 && ep->name[0] == ((flags & ISDOTDOT) ? 1 : 0)) {
254
255
256
257
258 dp->i_ino = isodirino(ep, imp);
259 goto found;
260 }
261 if (namelen != 1
262 || ep->name[0] != 0)
263 goto notfound;
264 } else if (!(res = isofncmp(name, len,
265 ep->name, namelen, imp->joliet_level))) {
266 if (isonum_711(ep->flags)&2)
267 ino = isodirino(ep, imp);
268 else
269 ino = dbtob(bp->b_blkno)
270 + entryoffsetinblock;
271 saveoffset = dp->i_offset;
272 } else if (ino)
273 goto foundino;
274 #ifdef NOSORTBUG
275 else if (res < 0)
276 goto notfound;
277 else if (res > 0 && numdirpasses == 2)
278 numdirpasses++;
279 #endif
280 }
281 break;
282 case ISO_FTYPE_RRIP:
283 if (isonum_711(ep->flags)&2)
284 ino = isodirino(ep, imp);
285 else
286 ino = dbtob(bp->b_blkno) + entryoffsetinblock;
287 dp->i_ino = ino;
288 MALLOC(altname, char *, NAME_MAX, M_TEMP, M_WAITOK);
289 cd9660_rrip_getname(ep,altname,&namelen,&dp->i_ino,imp);
290 if (namelen == cnp->cn_namelen
291 && !bcmp(name,altname,namelen)) {
292 FREE(altname, M_TEMP);
293 goto found;
294 }
295 FREE(altname, M_TEMP);
296 ino = 0;
297 break;
298 }
299 dp->i_offset += reclen;
300 entryoffsetinblock += reclen;
301 }
302 if (ino) {
303 foundino:
304 dp->i_ino = ino;
305 if (saveoffset != dp->i_offset) {
306 if (lblkno(imp, dp->i_offset) !=
307 lblkno(imp, saveoffset)) {
308 if (bp != NULL)
309 brelse(bp);
310 if ((error = cd9660_bufatoff(dp,
311 (off_t)saveoffset, NULL, &bp)) != 0)
312 return (error);
313 }
314 entryoffsetinblock = saveoffset & bmask;
315 ep = (struct iso_directory_record *)
316 ((char *)bp->b_data + entryoffsetinblock);
317 dp->i_offset = saveoffset;
318 }
319 goto found;
320 }
321 notfound:
322
323
324
325
326 if (numdirpasses == 2) {
327 numdirpasses--;
328 dp->i_offset = 0;
329 endsearch = dp->i_diroff;
330 goto searchloop;
331 }
332 if (bp != NULL)
333 brelse(bp);
334
335
336
337
338 if (cnp->cn_flags & MAKEENTRY)
339 cache_enter(vdp, *vpp, cnp);
340 if (nameiop == CREATE || nameiop == RENAME)
341 return (EJUSTRETURN);
342 return (ENOENT);
343
344 found:
345 if (numdirpasses == 2)
346 iso_nchstats.ncs_pass2++;
347
348
349
350
351
352
353 if ((flags & ISLASTCN) && nameiop == LOOKUP)
354 dp->i_diroff = dp->i_offset;
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375 pdp = vdp;
376
377
378
379
380 if (flags & ISDOTDOT) {
381 brelse(bp);
382 VOP_UNLOCK(pdp, 0, p);
383 cnp->cn_flags |= PDIRUNLOCK;
384 error = cd9660_vget_internal(vdp->v_mount, dp->i_ino, &tdp,
385 dp->i_ino != ino, NULL);
386 if (error) {
387 if (vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, p) == 0)
388 cnp->cn_flags &= ~PDIRUNLOCK;
389 return (error);
390 }
391 if (lockparent && (flags & ISLASTCN)) {
392 if ((error = vn_lock(pdp, LK_EXCLUSIVE, p))) {
393 vput(tdp);
394 return (error);
395 }
396 cnp->cn_flags &= ~PDIRUNLOCK;
397 }
398 *vpp = tdp;
399 } else if (dp->i_number == dp->i_ino) {
400 brelse(bp);
401 VREF(vdp);
402 *vpp = vdp;
403 } else {
404 error = cd9660_vget_internal(vdp->v_mount, dp->i_ino, &tdp,
405 dp->i_ino != ino, ep);
406 brelse(bp);
407 if (error)
408 return (error);
409 if (!lockparent || !(flags & ISLASTCN)) {
410 VOP_UNLOCK(pdp, 0, p);
411 cnp->cn_flags |= PDIRUNLOCK;
412 }
413 *vpp = tdp;
414 }
415
416
417
418
419 if (cnp->cn_flags & MAKEENTRY)
420 cache_enter(vdp, *vpp, cnp);
421 return (0);
422 }
423
424
425
426
427
428
429 int
430 cd9660_bufatoff(struct iso_node *ip, off_t offset, char **res,
431 struct buf **bpp)
432 {
433 struct iso_mnt *imp;
434 struct buf *bp;
435 daddr64_t lbn;
436 int bsize, error;
437 struct vnode *vp = ITOV(ip);
438
439 imp = ip->i_mnt;
440 lbn = lblkno(imp, offset);
441 bsize = blksize(imp, ip, lbn);
442
443 if ((error = bread(vp, lbn, bsize, NOCRED, &bp)) != 0) {
444 brelse(bp);
445 *bpp = NULL;
446 return (error);
447 }
448 if (res)
449 *res = (char *)bp->b_data + blkoff(imp, offset);
450 *bpp = bp;
451 return (0);
452 }