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