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