]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
37839358 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* $NetBSD: cd9660_rrip.c,v 1.11 1994/12/24 15:30:10 cgd Exp $ */ | |
23 | ||
24 | /*- | |
25 | * Copyright (c) 1993, 1994 | |
26 | * The Regents of the University of California. All rights reserved. | |
27 | * | |
28 | * This code is derived from software contributed to Berkeley | |
29 | * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension | |
30 | * Support code is derived from software contributed to Berkeley | |
31 | * by Atsushi Murai (amurai@spec.co.jp). | |
32 | * | |
33 | * Redistribution and use in source and binary forms, with or without | |
34 | * modification, are permitted provided that the following conditions | |
35 | * are met: | |
36 | * 1. Redistributions of source code must retain the above copyright | |
37 | * notice, this list of conditions and the following disclaimer. | |
38 | * 2. Redistributions in binary form must reproduce the above copyright | |
39 | * notice, this list of conditions and the following disclaimer in the | |
40 | * documentation and/or other materials provided with the distribution. | |
41 | * 3. All advertising materials mentioning features or use of this software | |
42 | * must display the following acknowledgement: | |
43 | * This product includes software developed by the University of | |
44 | * California, Berkeley and its contributors. | |
45 | * 4. Neither the name of the University nor the names of its contributors | |
46 | * may be used to endorse or promote products derived from this software | |
47 | * without specific prior written permission. | |
48 | * | |
49 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
50 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
51 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | |
60 | * | |
61 | * @(#)cd9660_rrip.c 8.6 (Berkeley) 12/5/94 | |
62 | ||
63 | ||
64 | ||
65 | * HISTORY | |
66 | * 22-Jan-98 radar 1669467 - ISO 9660 CD support - jwc | |
67 | ||
68 | */ | |
69 | ||
70 | #include <sys/param.h> | |
71 | #include <sys/systm.h> | |
72 | #include <sys/vnode.h> | |
73 | #include <sys/mount.h> | |
74 | #include <sys/namei.h> | |
75 | #include <sys/buf.h> | |
76 | #include <sys/file.h> | |
77 | #include <sys/kernel.h> | |
78 | #include <sys/stat.h> | |
79 | #include <sys/types.h> | |
80 | ||
81 | #include <sys/time.h> | |
82 | ||
83 | #include <isofs/cd9660/iso.h> | |
84 | #include <isofs/cd9660/cd9660_node.h> | |
85 | #include <isofs/cd9660/cd9660_rrip.h> | |
86 | #include <isofs/cd9660/iso_rrip.h> | |
87 | ||
88 | /* | |
89 | * POSIX file attribute | |
90 | */ | |
91 | static int | |
91447636 | 92 | cd9660_rrip_attr(ISO_RRIP_ATTR *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
93 | { |
94 | ana->inop->inode.iso_mode = isonum_733(p->mode); | |
95 | ana->inop->inode.iso_uid = isonum_733(p->uid); | |
96 | ana->inop->inode.iso_gid = isonum_733(p->gid); | |
97 | ana->inop->inode.iso_links = isonum_733(p->links); | |
98 | ana->fields &= ~ISO_SUSP_ATTR; | |
99 | return ISO_SUSP_ATTR; | |
100 | } | |
101 | ||
102 | static void | |
91447636 | 103 | cd9660_rrip_defattr(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
104 | { |
105 | /* But this is a required field! */ | |
106 | printf("RRIP without PX field?\n"); | |
107 | cd9660_defattr(isodir,ana->inop,NULL); | |
108 | } | |
109 | ||
110 | /* | |
111 | * Symbolic Links | |
112 | */ | |
113 | static int | |
91447636 | 114 | cd9660_rrip_slink(ISO_RRIP_SLINK *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
115 | { |
116 | register ISO_RRIP_SLINK_COMPONENT *pcomp; | |
117 | register ISO_RRIP_SLINK_COMPONENT *pcompe; | |
118 | int len, wlen, cont; | |
119 | char *outbuf, *inbuf; | |
120 | ||
121 | pcomp = (ISO_RRIP_SLINK_COMPONENT *)p->component; | |
122 | pcompe = (ISO_RRIP_SLINK_COMPONENT *)((char *)p + isonum_711(p->h.length)); | |
123 | len = *ana->outlen; | |
124 | outbuf = ana->outbuf; | |
125 | cont = ana->cont; | |
126 | ||
127 | /* | |
128 | * Gathering a Symbolic name from each component with path | |
129 | */ | |
130 | for (; | |
131 | pcomp < pcompe; | |
132 | pcomp = (ISO_RRIP_SLINK_COMPONENT *)((char *)pcomp + ISO_RRIP_SLSIZ | |
133 | + isonum_711(pcomp->clen))) { | |
134 | ||
135 | if (!cont) { | |
136 | if (len < ana->maxlen) { | |
137 | len++; | |
138 | *outbuf++ = '/'; | |
139 | } | |
140 | } | |
141 | cont = 0; | |
142 | ||
143 | inbuf = ".."; | |
144 | wlen = 0; | |
145 | ||
146 | switch (*pcomp->cflag) { | |
147 | ||
148 | case ISO_SUSP_CFLAG_CURRENT: | |
149 | /* Inserting Current */ | |
150 | wlen = 1; | |
151 | break; | |
152 | ||
153 | case ISO_SUSP_CFLAG_PARENT: | |
154 | /* Inserting Parent */ | |
155 | wlen = 2; | |
156 | break; | |
157 | ||
158 | case ISO_SUSP_CFLAG_ROOT: | |
159 | /* Inserting slash for ROOT */ | |
160 | /* start over from beginning(?) */ | |
161 | outbuf -= len; | |
162 | len = 0; | |
163 | break; | |
164 | ||
165 | case ISO_SUSP_CFLAG_VOLROOT: | |
166 | /* Inserting a mount point i.e. "/cdrom" */ | |
167 | /* same as above */ | |
168 | outbuf -= len; | |
169 | len = 0; | |
91447636 | 170 | inbuf = &(vfs_statfs(ana->imp->im_mountp)->f_mntonname); |
1c79356b A |
171 | wlen = strlen(inbuf); |
172 | break; | |
173 | ||
174 | case ISO_SUSP_CFLAG_HOST: | |
175 | /* Inserting hostname i.e. "kurt.tools.de" */ | |
176 | inbuf = hostname; | |
177 | wlen = hostnamelen; | |
178 | break; | |
179 | ||
180 | case ISO_SUSP_CFLAG_CONTINUE: | |
181 | cont = 1; | |
182 | /* fall thru */ | |
183 | case 0: | |
184 | /* Inserting component */ | |
185 | wlen = isonum_711(pcomp->clen); | |
186 | inbuf = pcomp->name; | |
187 | break; | |
188 | default: | |
189 | printf("RRIP with incorrect flags?"); | |
190 | wlen = ana->maxlen + 1; | |
191 | break; | |
192 | } | |
193 | ||
194 | if (len + wlen > ana->maxlen) { | |
195 | /* indicate error to caller */ | |
196 | ana->cont = 1; | |
197 | ana->fields = 0; | |
198 | ana->outbuf -= *ana->outlen; | |
199 | *ana->outlen = 0; | |
200 | return 0; | |
201 | } | |
202 | ||
203 | bcopy(inbuf,outbuf,wlen); | |
204 | outbuf += wlen; | |
205 | len += wlen; | |
206 | ||
207 | } | |
208 | ana->outbuf = outbuf; | |
209 | *ana->outlen = len; | |
210 | ana->cont = cont; | |
211 | ||
212 | if (!isonum_711(p->flags)) { | |
213 | ana->fields &= ~ISO_SUSP_SLINK; | |
214 | return ISO_SUSP_SLINK; | |
215 | } | |
216 | return 0; | |
217 | } | |
218 | ||
219 | /* | |
220 | * Alternate name | |
221 | */ | |
222 | static int | |
91447636 | 223 | cd9660_rrip_altname(ISO_RRIP_ALTNAME *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
224 | { |
225 | char *inbuf; | |
226 | int wlen; | |
227 | int cont; | |
228 | ||
229 | inbuf = ".."; | |
230 | wlen = 0; | |
231 | cont = 0; | |
232 | ||
233 | switch (*p->flags) { | |
234 | case ISO_SUSP_CFLAG_CURRENT: | |
235 | /* Inserting Current */ | |
236 | wlen = 1; | |
237 | break; | |
238 | ||
239 | case ISO_SUSP_CFLAG_PARENT: | |
240 | /* Inserting Parent */ | |
241 | wlen = 2; | |
242 | break; | |
243 | ||
244 | case ISO_SUSP_CFLAG_HOST: | |
245 | /* Inserting hostname i.e. "kurt.tools.de" */ | |
246 | inbuf = hostname; | |
247 | wlen = hostnamelen; | |
248 | break; | |
249 | ||
250 | case ISO_SUSP_CFLAG_CONTINUE: | |
251 | cont = 1; | |
252 | /* fall thru */ | |
253 | case 0: | |
254 | /* Inserting component */ | |
255 | wlen = isonum_711(p->h.length) - 5; | |
256 | inbuf = (char *)p + 5; | |
257 | break; | |
258 | ||
259 | default: | |
260 | printf("RRIP with incorrect NM flags?\n"); | |
261 | wlen = ana->maxlen + 1; | |
262 | break; | |
263 | } | |
264 | ||
265 | if ((*ana->outlen += wlen) > ana->maxlen) { | |
266 | /* treat as no name field */ | |
267 | ana->fields &= ~ISO_SUSP_ALTNAME; | |
268 | ana->outbuf -= *ana->outlen - wlen; | |
269 | *ana->outlen = 0; | |
270 | return 0; | |
271 | } | |
272 | ||
273 | bcopy(inbuf,ana->outbuf,wlen); | |
274 | ana->outbuf += wlen; | |
275 | ||
276 | if (!cont) { | |
277 | ana->fields &= ~ISO_SUSP_ALTNAME; | |
278 | return ISO_SUSP_ALTNAME; | |
279 | } | |
280 | return 0; | |
281 | } | |
282 | ||
283 | static void | |
91447636 | 284 | cd9660_rrip_defname(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
285 | { |
286 | strcpy(ana->outbuf,".."); | |
287 | switch (*isodir->name) { | |
288 | default: | |
289 | isofntrans(isodir->name, isonum_711(isodir->name_len), | |
55e303ae A |
290 | ana->outbuf, ana->outlen, 1, |
291 | isonum_711(isodir->flags) & associatedBit); | |
1c79356b A |
292 | break; |
293 | case 0: | |
294 | *ana->outlen = 1; | |
295 | break; | |
296 | case 1: | |
297 | *ana->outlen = 2; | |
298 | break; | |
299 | } | |
300 | } | |
301 | ||
302 | /* | |
303 | * Parent or Child Link | |
304 | */ | |
305 | static int | |
91447636 | 306 | cd9660_rrip_pclink(ISO_RRIP_CLINK *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
307 | { |
308 | *ana->inump = isonum_733(p->dir_loc) << ana->imp->im_bshift; | |
309 | ana->fields &= ~(ISO_SUSP_CLINK|ISO_SUSP_PLINK); | |
310 | return *p->h.type == 'C' ? ISO_SUSP_CLINK : ISO_SUSP_PLINK; | |
311 | } | |
312 | ||
313 | /* | |
314 | * Relocated directory | |
315 | */ | |
91447636 | 316 | /* ARGSUSED */ |
1c79356b | 317 | static int |
91447636 | 318 | cd9660_rrip_reldir(__unused ISO_RRIP_RELDIR *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
319 | { |
320 | /* special hack to make caller aware of RE field */ | |
321 | *ana->outlen = 0; | |
322 | ana->fields = 0; | |
323 | return ISO_SUSP_RELDIR|ISO_SUSP_ALTNAME|ISO_SUSP_CLINK|ISO_SUSP_PLINK; | |
324 | } | |
325 | ||
326 | static int | |
91447636 | 327 | cd9660_rrip_tstamp(ISO_RRIP_TSTAMP *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
328 | { |
329 | u_char *ptime; | |
330 | ||
331 | ptime = p->time; | |
332 | ||
333 | /* Check a format of time stamp (7bytes/17bytes) */ | |
334 | if (!(*p->flags&ISO_SUSP_TSTAMP_FORM17)) { | |
335 | if (*p->flags&ISO_SUSP_TSTAMP_CREAT) | |
336 | ptime += 7; | |
337 | ||
338 | if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) { | |
339 | cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_mtime); | |
340 | ptime += 7; | |
341 | } else | |
342 | bzero(&ana->inop->inode.iso_mtime,sizeof(struct timespec)); | |
343 | ||
344 | if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) { | |
345 | cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_atime); | |
346 | ptime += 7; | |
347 | } else | |
348 | ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime; | |
349 | ||
350 | if (*p->flags&ISO_SUSP_TSTAMP_ATTR) | |
351 | cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_ctime); | |
352 | else | |
353 | ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime; | |
354 | ||
355 | } else { | |
356 | if (*p->flags&ISO_SUSP_TSTAMP_CREAT) | |
357 | ptime += 17; | |
358 | ||
359 | if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) { | |
360 | cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_mtime); | |
361 | ptime += 17; | |
362 | } else | |
363 | bzero(&ana->inop->inode.iso_mtime,sizeof(struct timespec)); | |
364 | ||
365 | if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) { | |
366 | cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_atime); | |
367 | ptime += 17; | |
368 | } else | |
369 | ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime; | |
370 | ||
371 | if (*p->flags&ISO_SUSP_TSTAMP_ATTR) | |
372 | cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_ctime); | |
373 | else | |
374 | ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime; | |
375 | ||
376 | } | |
377 | ana->fields &= ~ISO_SUSP_TSTAMP; | |
378 | return ISO_SUSP_TSTAMP; | |
379 | } | |
380 | ||
381 | static void | |
91447636 A |
382 | cd9660_rrip_deftstamp(struct iso_directory_record *isodir, |
383 | ISO_RRIP_ANALYZE *ana) | |
1c79356b A |
384 | { |
385 | cd9660_deftstamp(isodir,ana->inop,NULL); | |
386 | } | |
387 | ||
388 | /* | |
389 | * POSIX device modes | |
390 | */ | |
391 | static int | |
91447636 | 392 | cd9660_rrip_device(ISO_RRIP_DEVICE *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
393 | { |
394 | u_int high, low; | |
395 | ||
396 | high = isonum_733(p->dev_t_high); | |
397 | low = isonum_733(p->dev_t_low); | |
398 | ||
399 | if (high == 0) | |
400 | ana->inop->inode.iso_rdev = makedev(major(low), minor(low)); | |
401 | else | |
402 | ana->inop->inode.iso_rdev = makedev(high, minor(low)); | |
403 | ana->fields &= ~ISO_SUSP_DEVICE; | |
404 | return ISO_SUSP_DEVICE; | |
405 | } | |
406 | ||
407 | /* | |
408 | * Flag indicating | |
409 | */ | |
410 | static int | |
91447636 | 411 | cd9660_rrip_idflag(ISO_RRIP_IDFLAG *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
412 | { |
413 | ana->fields &= isonum_711(p->flags)|~0xff; /* don't touch high bits */ | |
414 | /* special handling of RE field */ | |
415 | if (ana->fields&ISO_SUSP_RELDIR) | |
416 | return cd9660_rrip_reldir(p,ana); | |
417 | ||
418 | return ISO_SUSP_IDFLAG; | |
419 | } | |
420 | ||
421 | /* | |
422 | * Continuation pointer | |
423 | */ | |
424 | static int | |
91447636 | 425 | cd9660_rrip_cont(ISO_RRIP_CONT *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
426 | { |
427 | ana->iso_ce_blk = isonum_733(p->location); | |
428 | ana->iso_ce_off = isonum_733(p->offset); | |
429 | ana->iso_ce_len = isonum_733(p->length); | |
430 | return ISO_SUSP_CONT; | |
431 | } | |
432 | ||
433 | /* | |
434 | * System Use end | |
435 | */ | |
91447636 | 436 | /* ARGSUSED */ |
1c79356b | 437 | static int |
91447636 | 438 | cd9660_rrip_stop(__unused ISO_SUSP_HEADER *p, __unused ISO_RRIP_ANALYZE *ana) |
1c79356b A |
439 | { |
440 | return ISO_SUSP_STOP; | |
441 | } | |
442 | ||
443 | /* | |
444 | * Extension reference | |
445 | */ | |
446 | static int | |
91447636 | 447 | cd9660_rrip_extref(ISO_RRIP_EXTREF *p, ISO_RRIP_ANALYZE *ana) |
1c79356b A |
448 | { |
449 | if (isonum_711(p->len_id) != 10 | |
450 | || bcmp((char *)p + 8,"RRIP_1991A",10) | |
451 | || isonum_711(p->version) != 1) | |
452 | return 0; | |
453 | ana->fields &= ~ISO_SUSP_EXTREF; | |
454 | return ISO_SUSP_EXTREF; | |
455 | } | |
456 | ||
91447636 A |
457 | typedef int (*rrip_table_func)(ISO_SUSP_HEADER *phead, ISO_RRIP_ANALYZE *ana); |
458 | typedef int (*rrip_table_func2)(struct iso_directory_record *isodir, | |
459 | ISO_RRIP_ANALYZE *ana); | |
1c79356b A |
460 | typedef struct { |
461 | char type[2]; | |
91447636 A |
462 | rrip_table_func func; |
463 | rrip_table_func2 func2; | |
1c79356b A |
464 | int result; |
465 | } RRIP_TABLE; | |
466 | ||
467 | static int | |
91447636 A |
468 | cd9660_rrip_loop(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana, |
469 | RRIP_TABLE *table) | |
1c79356b A |
470 | { |
471 | register RRIP_TABLE *ptable; | |
472 | register ISO_SUSP_HEADER *phead; | |
473 | register ISO_SUSP_HEADER *pend; | |
474 | struct buf *bp = NULL; | |
475 | char *pwhead; | |
476 | int result; | |
477 | ||
478 | /* | |
479 | * Note: If name length is odd, | |
480 | * it will be padding 1 byte after the name | |
481 | */ | |
482 | pwhead = isodir->name + isonum_711(isodir->name_len); | |
483 | if (!(isonum_711(isodir->name_len)&1)) | |
484 | pwhead++; | |
485 | ||
486 | /* If it's not the '.' entry of the root dir obey SP field */ | |
487 | if (*isodir->name != 0 | |
488 | || isonum_733(isodir->extent) != ana->imp->root_extent) | |
489 | pwhead += ana->imp->rr_skip; | |
490 | else | |
491 | pwhead += ana->imp->rr_skip0; | |
492 | ||
493 | phead = (ISO_SUSP_HEADER *)pwhead; | |
494 | pend = (ISO_SUSP_HEADER *)((char *)isodir + isonum_711(isodir->length)); | |
495 | ||
496 | result = 0; | |
497 | while (1) { | |
498 | ana->iso_ce_len = 0; | |
499 | /* | |
500 | * Note: "pend" should be more than one SUSP header | |
501 | */ | |
502 | while (pend >= phead + 1) { | |
503 | if (isonum_711(phead->version) == 1) { | |
504 | for (ptable = table; ptable->func; ptable++) { | |
505 | if (*phead->type == *ptable->type | |
506 | && phead->type[1] == ptable->type[1]) { | |
91447636 | 507 | result |= (ptable->func(phead,ana)); |
1c79356b A |
508 | break; |
509 | } | |
510 | } | |
511 | if (!ana->fields) | |
512 | break; | |
513 | } | |
514 | if (result&ISO_SUSP_STOP) { | |
515 | result &= ~ISO_SUSP_STOP; | |
516 | break; | |
517 | } | |
518 | /* plausibility check */ | |
519 | if (isonum_711(phead->length) < sizeof(*phead)) | |
520 | break; | |
521 | /* | |
522 | * move to next SUSP | |
523 | * Hopefully this works with newer versions, too | |
524 | */ | |
525 | phead = (ISO_SUSP_HEADER *)((char *)phead + isonum_711(phead->length)); | |
526 | } | |
527 | ||
528 | if (ana->fields && ana->iso_ce_len) { | |
529 | if (ana->iso_ce_blk >= ana->imp->volume_space_size | |
530 | || ana->iso_ce_off + ana->iso_ce_len > ana->imp->logical_block_size | |
91447636 | 531 | || buf_bread(ana->imp->im_devvp, |
1c79356b | 532 | #if 1 // radar 1669467 - logical and physical blocksize are the same |
91447636 | 533 | (daddr64_t)((unsigned)ana->iso_ce_blk), |
1c79356b | 534 | #else |
91447636 | 535 | (daddr64_t)((unsigned)(ana->iso_ce_blk << (ana->imp->im_bshift - DEV_BSHIFT))), |
1c79356b A |
536 | #endif // radar 1669467 |
537 | ana->imp->logical_block_size, NOCRED, &bp)) | |
538 | /* what to do now? */ | |
539 | break; | |
91447636 | 540 | phead = (ISO_SUSP_HEADER *)((char *)buf_dataptr(bp) + ana->iso_ce_off); |
1c79356b A |
541 | pend = (ISO_SUSP_HEADER *) ((char *)phead + ana->iso_ce_len); |
542 | } else | |
543 | break; | |
544 | } | |
545 | if (bp) | |
91447636 | 546 | buf_brelse(bp); |
1c79356b A |
547 | /* |
548 | * If we don't find the Basic SUSP stuffs, just set default value | |
549 | * (attribute/time stamp) | |
550 | */ | |
551 | for (ptable = table; ptable->func2; ptable++) | |
552 | if (!(ptable->result&result)) | |
553 | ptable->func2(isodir,ana); | |
554 | ||
555 | return result; | |
556 | } | |
557 | ||
558 | /* | |
559 | * Get Attributes. | |
560 | */ | |
561 | static RRIP_TABLE rrip_table_analyze[] = { | |
91447636 A |
562 | { "PX", (rrip_table_func)cd9660_rrip_attr, |
563 | (rrip_table_func2)cd9660_rrip_defattr, | |
564 | ISO_SUSP_ATTR }, | |
565 | { "TF", (rrip_table_func)cd9660_rrip_tstamp, | |
566 | (rrip_table_func2)cd9660_rrip_deftstamp, | |
567 | ISO_SUSP_TSTAMP }, | |
568 | { "PN", (rrip_table_func)cd9660_rrip_device, | |
569 | 0, ISO_SUSP_DEVICE }, | |
570 | { "RR", (rrip_table_func)cd9660_rrip_idflag, | |
571 | 0, ISO_SUSP_IDFLAG }, | |
572 | { "CE", (rrip_table_func)cd9660_rrip_cont, | |
573 | 0, ISO_SUSP_CONT }, | |
1c79356b A |
574 | { "ST", cd9660_rrip_stop, 0, ISO_SUSP_STOP }, |
575 | { "", 0, 0, 0 } | |
576 | }; | |
577 | ||
578 | int | |
91447636 A |
579 | cd9660_rrip_analyze(struct iso_directory_record *isodir, struct iso_node *inop, |
580 | struct iso_mnt *imp) | |
1c79356b A |
581 | { |
582 | ISO_RRIP_ANALYZE analyze; | |
583 | ||
584 | analyze.inop = inop; | |
585 | analyze.imp = imp; | |
586 | analyze.fields = ISO_SUSP_ATTR|ISO_SUSP_TSTAMP|ISO_SUSP_DEVICE; | |
587 | ||
588 | return cd9660_rrip_loop(isodir,&analyze,rrip_table_analyze); | |
589 | } | |
590 | ||
591 | /* | |
592 | * Get Alternate Name. | |
593 | */ | |
594 | static RRIP_TABLE rrip_table_getname[] = { | |
91447636 A |
595 | { "NM", (rrip_table_func)cd9660_rrip_altname, |
596 | (rrip_table_func2)cd9660_rrip_defname, | |
597 | ISO_SUSP_ALTNAME }, | |
598 | { "CL", (rrip_table_func)cd9660_rrip_pclink, | |
599 | 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK }, | |
600 | { "PL", (rrip_table_func)cd9660_rrip_pclink, | |
601 | 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK }, | |
602 | { "RE", (rrip_table_func)cd9660_rrip_reldir, | |
603 | 0, ISO_SUSP_RELDIR }, | |
604 | { "RR", (rrip_table_func)cd9660_rrip_idflag, | |
605 | 0, ISO_SUSP_IDFLAG }, | |
606 | { "CE", (rrip_table_func)cd9660_rrip_cont, | |
607 | 0, ISO_SUSP_CONT }, | |
1c79356b A |
608 | { "ST", cd9660_rrip_stop, 0, ISO_SUSP_STOP }, |
609 | { "", 0, 0, 0 } | |
610 | }; | |
611 | ||
612 | int | |
91447636 A |
613 | cd9660_rrip_getname(struct iso_directory_record *isodir, char *outbuf, |
614 | u_short *outlen, ino_t *inump, struct iso_mnt *imp) | |
1c79356b A |
615 | { |
616 | ISO_RRIP_ANALYZE analyze; | |
617 | RRIP_TABLE *tab; | |
618 | ||
619 | analyze.outbuf = outbuf; | |
620 | analyze.outlen = outlen; | |
621 | analyze.maxlen = ISO_RRIP_NAMEMAX; | |
622 | analyze.inump = inump; | |
623 | analyze.imp = imp; | |
624 | analyze.fields = ISO_SUSP_ALTNAME|ISO_SUSP_RELDIR|ISO_SUSP_CLINK|ISO_SUSP_PLINK; | |
625 | *outlen = 0; | |
626 | ||
627 | tab = rrip_table_getname; | |
628 | if (*isodir->name == 0 | |
629 | || *isodir->name == 1) { | |
630 | cd9660_rrip_defname(isodir,&analyze); | |
631 | ||
632 | analyze.fields &= ~ISO_SUSP_ALTNAME; | |
633 | tab++; | |
634 | } | |
635 | ||
636 | return cd9660_rrip_loop(isodir,&analyze,tab); | |
637 | } | |
638 | ||
639 | /* | |
640 | * Get Symbolic Link. | |
641 | */ | |
642 | static RRIP_TABLE rrip_table_getsymname[] = { | |
91447636 A |
643 | { "SL", (rrip_table_func)cd9660_rrip_slink, |
644 | 0, ISO_SUSP_SLINK }, | |
645 | { "RR", (rrip_table_func)cd9660_rrip_idflag, | |
646 | 0, ISO_SUSP_IDFLAG }, | |
647 | { "CE", (rrip_table_func)cd9660_rrip_cont, | |
648 | 0, ISO_SUSP_CONT }, | |
1c79356b A |
649 | { "ST", cd9660_rrip_stop, 0, ISO_SUSP_STOP }, |
650 | { "", 0, 0, 0 } | |
651 | }; | |
652 | ||
653 | int | |
91447636 A |
654 | cd9660_rrip_getsymname(struct iso_directory_record *isodir, char *outbuf, |
655 | u_short *outlen, struct iso_mnt *imp) | |
1c79356b A |
656 | { |
657 | ISO_RRIP_ANALYZE analyze; | |
658 | ||
659 | analyze.outbuf = outbuf; | |
660 | analyze.outlen = outlen; | |
661 | *outlen = 0; | |
662 | analyze.maxlen = MAXPATHLEN; | |
663 | analyze.cont = 1; /* don't start with a slash */ | |
664 | analyze.imp = imp; | |
665 | analyze.fields = ISO_SUSP_SLINK; | |
666 | ||
667 | return (cd9660_rrip_loop(isodir,&analyze,rrip_table_getsymname)&ISO_SUSP_SLINK); | |
668 | } | |
669 | ||
670 | static RRIP_TABLE rrip_table_extref[] = { | |
91447636 A |
671 | { "ER", (rrip_table_func)cd9660_rrip_extref, |
672 | 0, ISO_SUSP_EXTREF }, | |
673 | { "CE", (rrip_table_func)cd9660_rrip_cont, | |
674 | 0, ISO_SUSP_CONT }, | |
1c79356b A |
675 | { "ST", cd9660_rrip_stop, 0, ISO_SUSP_STOP }, |
676 | { "", 0, 0, 0 } | |
677 | }; | |
678 | ||
679 | /* | |
680 | * Check for Rock Ridge Extension and return offset of its fields. | |
681 | * Note: We insist on the ER field. | |
682 | */ | |
683 | int | |
91447636 | 684 | cd9660_rrip_offset(struct iso_directory_record *isodir, struct iso_mnt *imp) |
1c79356b A |
685 | { |
686 | ISO_RRIP_OFFSET *p; | |
687 | ISO_RRIP_ANALYZE analyze; | |
688 | ||
689 | imp->rr_skip0 = 0; | |
690 | p = (ISO_RRIP_OFFSET *)(isodir->name + 1); | |
691 | if (bcmp(p,"SP\7\1\276\357",6)) { | |
692 | /* Maybe, it's a CDROM XA disc? */ | |
693 | imp->rr_skip0 = 15; | |
694 | p = (ISO_RRIP_OFFSET *)((char *)p + 15); | |
695 | if (bcmp(p,"SP\7\1\276\357",6)) | |
696 | return -1; | |
697 | } | |
698 | ||
699 | analyze.imp = imp; | |
700 | analyze.fields = ISO_SUSP_EXTREF; | |
701 | if (!(cd9660_rrip_loop(isodir,&analyze,rrip_table_extref)&ISO_SUSP_EXTREF)) | |
702 | return -1; | |
703 | ||
704 | return isonum_711(p->skip); | |
705 | } |