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