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