xref: /freebsd/sys/fs/cd9660/cd9660_rrip.c (revision 39beb93c)
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  * 4. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)cd9660_rrip.c	8.6 (Berkeley) 12/5/94
35  */
36 
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/bio.h>
43 #include <sys/buf.h>
44 #include <sys/vnode.h>
45 #include <sys/mount.h>
46 #include <sys/kernel.h>
47 #include <sys/vimage.h>
48 
49 #include <fs/cd9660/iso.h>
50 #include <fs/cd9660/cd9660_node.h>
51 #include <fs/cd9660/cd9660_rrip.h>
52 #include <fs/cd9660/iso_rrip.h>
53 
54 typedef int	rrt_func_t(void *, ISO_RRIP_ANALYZE *ana);
55 
56 typedef struct {
57 	char type[2];
58 	rrt_func_t *func;
59 	void (*func2)(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana);
60 	int result;
61 } RRIP_TABLE;
62 
63 static int	cd9660_rrip_altname(ISO_RRIP_ALTNAME *p, ISO_RRIP_ANALYZE *ana);
64 static int	cd9660_rrip_attr(ISO_RRIP_ATTR *p, ISO_RRIP_ANALYZE *ana);
65 static int	cd9660_rrip_cont(ISO_RRIP_CONT *p, ISO_RRIP_ANALYZE *ana);
66 static void	cd9660_rrip_defattr(struct iso_directory_record *isodir,
67 		    ISO_RRIP_ANALYZE *ana);
68 static void	cd9660_rrip_defname(struct iso_directory_record *isodir,
69 		    ISO_RRIP_ANALYZE *ana);
70 static void	cd9660_rrip_deftstamp(struct iso_directory_record *isodir,
71 		    ISO_RRIP_ANALYZE *ana);
72 static int	cd9660_rrip_device(ISO_RRIP_DEVICE *p, ISO_RRIP_ANALYZE *ana);
73 static int	cd9660_rrip_extref(ISO_RRIP_EXTREF *p, ISO_RRIP_ANALYZE *ana);
74 static int	cd9660_rrip_idflag(ISO_RRIP_IDFLAG *p, ISO_RRIP_ANALYZE *ana);
75 static int	cd9660_rrip_loop(struct iso_directory_record *isodir,
76 		    ISO_RRIP_ANALYZE *ana, RRIP_TABLE *table);
77 static int	cd9660_rrip_pclink(ISO_RRIP_CLINK *p, ISO_RRIP_ANALYZE *ana);
78 static int	cd9660_rrip_reldir(ISO_RRIP_RELDIR *p, ISO_RRIP_ANALYZE *ana);
79 static int	cd9660_rrip_slink(ISO_RRIP_SLINK *p, ISO_RRIP_ANALYZE *ana);
80 static int	cd9660_rrip_stop(ISO_SUSP_HEADER *p, ISO_RRIP_ANALYZE *ana);
81 static int	cd9660_rrip_tstamp(ISO_RRIP_TSTAMP *p, ISO_RRIP_ANALYZE *ana);
82 
83 /*
84  * POSIX file attribute
85  */
86 static int
87 cd9660_rrip_attr(p,ana)
88 	ISO_RRIP_ATTR *p;
89 	ISO_RRIP_ANALYZE *ana;
90 {
91 	ana->inop->inode.iso_mode = isonum_733(p->mode);
92 	ana->inop->inode.iso_uid = isonum_733(p->uid);
93 	ana->inop->inode.iso_gid = isonum_733(p->gid);
94 	ana->inop->inode.iso_links = isonum_733(p->links);
95 	ana->fields &= ~ISO_SUSP_ATTR;
96 	return ISO_SUSP_ATTR;
97 }
98 
99 static void
100 cd9660_rrip_defattr(isodir,ana)
101 	struct iso_directory_record *isodir;
102 	ISO_RRIP_ANALYZE *ana;
103 {
104 	/* But this is a required field! */
105 	printf("RRIP without PX field?\n");
106 	cd9660_defattr(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
107 }
108 
109 /*
110  * Symbolic Links
111  */
112 static int
113 cd9660_rrip_slink(p,ana)
114 	ISO_RRIP_SLINK	*p;
115 	ISO_RRIP_ANALYZE *ana;
116 {
117 	INIT_VPROCG(TD_TO_VPROCG(curthread));
118 	ISO_RRIP_SLINK_COMPONENT *pcomp;
119 	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 			/* Double slash, nothing really to do here. */
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;
170 			inbuf = ana->imp->im_mountp->mnt_stat.f_mntonname;
171 			wlen = strlen(inbuf);
172 			break;
173 
174 		case ISO_SUSP_CFLAG_HOST:
175 			/* XXXRW: locking. */
176 			/* Inserting hostname i.e. "kurt.tools.de" */
177 			inbuf = V_hostname;
178 			wlen = strlen(V_hostname);
179 			break;
180 
181 		case ISO_SUSP_CFLAG_CONTINUE:
182 			cont = 1;
183 			/* FALLTHROUGH */
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  */
223 static int
224 cd9660_rrip_altname(p,ana)
225 	ISO_RRIP_ALTNAME *p;
226 	ISO_RRIP_ANALYZE *ana;
227 {
228 	INIT_VPROCG(TD_TO_VPROCG(curthread));
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 		/* XXXRW: locking. */
250 		/* Inserting hostname i.e. "kurt.tools.de" */
251 		inbuf = V_hostname;
252 		wlen = strlen(V_hostname);
253 		break;
254 
255 	case ISO_SUSP_CFLAG_CONTINUE:
256 		cont = 1;
257 		/* FALLTHROUGH */
258 	case 0:
259 		/* Inserting component */
260 		wlen = isonum_711(p->h.length) - 5;
261 		inbuf = (char *)p + 5;
262 		break;
263 
264 	default:
265 		printf("RRIP with incorrect NM flags?\n");
266 		wlen = ana->maxlen + 1;
267 		break;
268 	}
269 
270 	if ((*ana->outlen += wlen) > ana->maxlen) {
271 		/* treat as no name field */
272 		ana->fields &= ~ISO_SUSP_ALTNAME;
273 		ana->outbuf -= *ana->outlen - wlen;
274 		*ana->outlen = 0;
275 		return 0;
276 	}
277 
278 	bcopy(inbuf,ana->outbuf,wlen);
279 	ana->outbuf += wlen;
280 
281 	if (!cont) {
282 		ana->fields &= ~ISO_SUSP_ALTNAME;
283 		return ISO_SUSP_ALTNAME;
284 	}
285 	return 0;
286 }
287 
288 static void
289 cd9660_rrip_defname(isodir,ana)
290 	struct iso_directory_record *isodir;
291 	ISO_RRIP_ANALYZE *ana;
292 {
293 	isofntrans(isodir->name,isonum_711(isodir->name_len),
294 		   ana->outbuf,ana->outlen,
295 		   1,isonum_711(isodir->flags)&4, ana->imp->joliet_level,
296 		   ana->imp->im_flags, ana->imp->im_d2l);
297 	switch (*ana->outbuf) {
298 	default:
299 		break;
300 	case 1:
301 		*ana->outlen = 2;
302 		/* FALLTHROUGH */
303 	case 0:
304 		/* outlen is 1 already */
305 		strcpy(ana->outbuf,"..");
306 		break;
307 	}
308 }
309 
310 /*
311  * Parent or Child Link
312  */
313 static int
314 cd9660_rrip_pclink(p,ana)
315 	ISO_RRIP_CLINK	*p;
316 	ISO_RRIP_ANALYZE *ana;
317 {
318 	*ana->inump = isonum_733(p->dir_loc) << ana->imp->im_bshift;
319 	ana->fields &= ~(ISO_SUSP_CLINK|ISO_SUSP_PLINK);
320 	return *p->h.type == 'C' ? ISO_SUSP_CLINK : ISO_SUSP_PLINK;
321 }
322 
323 /*
324  * Relocated directory
325  */
326 static int
327 cd9660_rrip_reldir(p,ana)
328 	ISO_RRIP_RELDIR	 *p;
329 	ISO_RRIP_ANALYZE *ana;
330 {
331 	/* special hack to make caller aware of RE field */
332 	*ana->outlen = 0;
333 	ana->fields = 0;
334 	return ISO_SUSP_RELDIR|ISO_SUSP_ALTNAME|ISO_SUSP_CLINK|ISO_SUSP_PLINK;
335 }
336 
337 static int
338 cd9660_rrip_tstamp(p,ana)
339 	ISO_RRIP_TSTAMP *p;
340 	ISO_RRIP_ANALYZE *ana;
341 {
342 	u_char *ptime;
343 
344 	ptime = p->time;
345 
346 	/* Check a format of time stamp (7bytes/17bytes) */
347 	if (!(*p->flags&ISO_SUSP_TSTAMP_FORM17)) {
348 		if (*p->flags&ISO_SUSP_TSTAMP_CREAT)
349 			ptime += 7;
350 
351 		if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) {
352 			cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_mtime,
353 					    ISO_FTYPE_RRIP);
354 			ptime += 7;
355 		} else
356 			bzero(&ana->inop->inode.iso_mtime,sizeof(struct timespec));
357 
358 		if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) {
359 			cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_atime,
360 					    ISO_FTYPE_RRIP);
361 			ptime += 7;
362 		} else
363 			ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime;
364 
365 		if (*p->flags&ISO_SUSP_TSTAMP_ATTR)
366 			cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_ctime,
367 					    ISO_FTYPE_RRIP);
368 		else
369 			ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime;
370 
371 	} else {
372 		if (*p->flags&ISO_SUSP_TSTAMP_CREAT)
373 			ptime += 17;
374 
375 		if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) {
376 			cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_mtime);
377 			ptime += 17;
378 		} else
379 			bzero(&ana->inop->inode.iso_mtime,sizeof(struct timespec));
380 
381 		if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) {
382 			cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_atime);
383 			ptime += 17;
384 		} else
385 			ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime;
386 
387 		if (*p->flags&ISO_SUSP_TSTAMP_ATTR)
388 			cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_ctime);
389 		else
390 			ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime;
391 
392 	}
393 	ana->fields &= ~ISO_SUSP_TSTAMP;
394 	return ISO_SUSP_TSTAMP;
395 }
396 
397 static void
398 cd9660_rrip_deftstamp(isodir,ana)
399 	struct iso_directory_record  *isodir;
400 	ISO_RRIP_ANALYZE *ana;
401 {
402 	cd9660_deftstamp(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
403 }
404 
405 /*
406  * POSIX device modes
407  */
408 static int
409 cd9660_rrip_device(p,ana)
410 	ISO_RRIP_DEVICE *p;
411 	ISO_RRIP_ANALYZE *ana;
412 {
413 	u_int high, low;
414 
415 	high = isonum_733(p->dev_t_high);
416 	low  = isonum_733(p->dev_t_low);
417 
418 	if (high == 0)
419 		ana->inop->inode.iso_rdev = makedev(major(low), minor(low));
420 	else
421 		ana->inop->inode.iso_rdev = makedev(high, minor(low));
422 	ana->fields &= ~ISO_SUSP_DEVICE;
423 	return ISO_SUSP_DEVICE;
424 }
425 
426 /*
427  * Flag indicating
428  */
429 static int
430 cd9660_rrip_idflag(p,ana)
431 	ISO_RRIP_IDFLAG *p;
432 	ISO_RRIP_ANALYZE *ana;
433 {
434 	ana->fields &= isonum_711(p->flags)|~0xff; /* don't touch high bits */
435 	/* special handling of RE field */
436 	if (ana->fields&ISO_SUSP_RELDIR)
437 		return cd9660_rrip_reldir(/* XXX */ (ISO_RRIP_RELDIR *)p,ana);
438 
439 	return ISO_SUSP_IDFLAG;
440 }
441 
442 /*
443  * Continuation pointer
444  */
445 static int
446 cd9660_rrip_cont(p,ana)
447 	ISO_RRIP_CONT *p;
448 	ISO_RRIP_ANALYZE *ana;
449 {
450 	ana->iso_ce_blk = isonum_733(p->location);
451 	ana->iso_ce_off = isonum_733(p->offset);
452 	ana->iso_ce_len = isonum_733(p->length);
453 	return ISO_SUSP_CONT;
454 }
455 
456 /*
457  * System Use end
458  */
459 static int
460 cd9660_rrip_stop(p,ana)
461 	ISO_SUSP_HEADER *p;
462 	ISO_RRIP_ANALYZE *ana;
463 {
464 	return ISO_SUSP_STOP;
465 }
466 
467 /*
468  * Extension reference
469  */
470 static int
471 cd9660_rrip_extref(p,ana)
472 	ISO_RRIP_EXTREF *p;
473 	ISO_RRIP_ANALYZE *ana;
474 {
475 	if ( ! ((isonum_711(p->len_id) == 10
476 	      && bcmp((char *)p + 8,"RRIP_1991A",10) == 0)
477 	    || (isonum_711(p->len_id) == 10
478 	      && bcmp((char *)p + 8,"IEEE_P1282",10) == 0)
479 	    || (isonum_711(p->len_id) ==  9
480 	      && bcmp((char *)p + 8,"IEEE_1282",  9) == 0))
481 	    || isonum_711(p->version) != 1)
482 		return 0;
483 	ana->fields &= ~ISO_SUSP_EXTREF;
484 	return ISO_SUSP_EXTREF;
485 }
486 
487 static int
488 cd9660_rrip_loop(isodir,ana,table)
489 	struct iso_directory_record *isodir;
490 	ISO_RRIP_ANALYZE *ana;
491 	RRIP_TABLE *table;
492 {
493 	RRIP_TABLE *ptable;
494 	ISO_SUSP_HEADER *phead;
495 	ISO_SUSP_HEADER *pend;
496 	struct buf *bp = NULL;
497 	char *pwhead;
498 	u_short c;
499 	int result;
500 
501 	/*
502 	 * Note: If name length is odd,
503 	 *	 it will be padding 1 byte after the name
504 	 */
505 	pwhead = isodir->name + isonum_711(isodir->name_len);
506 	if (!(isonum_711(isodir->name_len)&1))
507 		pwhead++;
508 	isochar(isodir->name, pwhead, ana->imp->joliet_level, &c, NULL,
509 		ana->imp->im_flags, ana->imp->im_d2l);
510 
511 	/* If it's not the '.' entry of the root dir obey SP field */
512 	if (c != 0 || isonum_733(isodir->extent) != ana->imp->root_extent)
513 		pwhead += ana->imp->rr_skip;
514 	else
515 		pwhead += ana->imp->rr_skip0;
516 
517 	phead = (ISO_SUSP_HEADER *)pwhead;
518 	pend = (ISO_SUSP_HEADER *)((char *)isodir + isonum_711(isodir->length));
519 
520 	result = 0;
521 	while (1) {
522 		ana->iso_ce_len = 0;
523 		/*
524 		 * Note: "pend" should be more than one SUSP header
525 		 */
526 		while (pend >= phead + 1) {
527 			if (isonum_711(phead->version) == 1) {
528 				for (ptable = table; ptable->func; ptable++) {
529 					if (*phead->type == *ptable->type
530 					    && phead->type[1] == ptable->type[1]) {
531 						result |= ptable->func(phead,ana);
532 						break;
533 					}
534 				}
535 				if (!ana->fields)
536 					break;
537 			}
538 			if (result&ISO_SUSP_STOP) {
539 				result &= ~ISO_SUSP_STOP;
540 				break;
541 			}
542 			/* plausibility check */
543 			if (isonum_711(phead->length) < sizeof(*phead))
544 				break;
545 			/*
546 			 * move to next SUSP
547 			 * Hopefully this works with newer versions, too
548 			 */
549 			phead = (ISO_SUSP_HEADER *)((char *)phead + isonum_711(phead->length));
550 		}
551 
552 		if (ana->fields && ana->iso_ce_len) {
553 			if (ana->iso_ce_blk >= ana->imp->volume_space_size
554 			    || ana->iso_ce_off + ana->iso_ce_len > ana->imp->logical_block_size
555 			    || bread(ana->imp->im_devvp,
556 				     ana->iso_ce_blk <<
557 				     (ana->imp->im_bshift - DEV_BSHIFT),
558 				     ana->imp->logical_block_size, NOCRED, &bp))
559 				/* what to do now? */
560 				break;
561 			phead = (ISO_SUSP_HEADER *)(bp->b_data + ana->iso_ce_off);
562 			pend = (ISO_SUSP_HEADER *) ((char *)phead + ana->iso_ce_len);
563 		} else
564 			break;
565 	}
566 	if (bp)
567 		brelse(bp);
568 	/*
569 	 * If we don't find the Basic SUSP stuffs, just set default value
570 	 *   (attribute/time stamp)
571 	 */
572 	for (ptable = table; ptable->func2; ptable++)
573 		if (!(ptable->result&result))
574 			ptable->func2(isodir,ana);
575 
576 	return result;
577 }
578 
579 /*
580  * Get Attributes.
581  */
582 /*
583  * XXX the casts are bogus but will do for now.
584  */
585 #define	BC	(rrt_func_t *)
586 static RRIP_TABLE rrip_table_analyze[] = {
587 	{ "PX", BC cd9660_rrip_attr,	cd9660_rrip_defattr,	ISO_SUSP_ATTR },
588 	{ "TF", BC cd9660_rrip_tstamp,	cd9660_rrip_deftstamp,	ISO_SUSP_TSTAMP },
589 	{ "PN", BC cd9660_rrip_device,	0,			ISO_SUSP_DEVICE },
590 	{ "RR", BC cd9660_rrip_idflag,	0,			ISO_SUSP_IDFLAG },
591 	{ "CE", BC cd9660_rrip_cont,	0,			ISO_SUSP_CONT },
592 	{ "ST", BC cd9660_rrip_stop,	0,			ISO_SUSP_STOP },
593 	{ "",	0,			0,			0 }
594 };
595 
596 int
597 cd9660_rrip_analyze(isodir,inop,imp)
598 	struct iso_directory_record *isodir;
599 	struct iso_node *inop;
600 	struct iso_mnt *imp;
601 {
602 	ISO_RRIP_ANALYZE analyze;
603 
604 	analyze.inop = inop;
605 	analyze.imp = imp;
606 	analyze.fields = ISO_SUSP_ATTR|ISO_SUSP_TSTAMP|ISO_SUSP_DEVICE;
607 
608 	return cd9660_rrip_loop(isodir,&analyze,rrip_table_analyze);
609 }
610 
611 /*
612  * Get Alternate Name.
613  */
614 static RRIP_TABLE rrip_table_getname[] = {
615 	{ "NM", BC cd9660_rrip_altname,	cd9660_rrip_defname,	ISO_SUSP_ALTNAME },
616 	{ "CL", BC cd9660_rrip_pclink,	0,			ISO_SUSP_CLINK|ISO_SUSP_PLINK },
617 	{ "PL", BC cd9660_rrip_pclink,	0,			ISO_SUSP_CLINK|ISO_SUSP_PLINK },
618 	{ "RE", BC cd9660_rrip_reldir,	0,			ISO_SUSP_RELDIR },
619 	{ "RR", BC cd9660_rrip_idflag,	0,			ISO_SUSP_IDFLAG },
620 	{ "CE", BC cd9660_rrip_cont,	0,			ISO_SUSP_CONT },
621 	{ "ST", BC cd9660_rrip_stop,	0,			ISO_SUSP_STOP },
622 	{ "",	0,			0,			0 }
623 };
624 
625 int
626 cd9660_rrip_getname(isodir,outbuf,outlen,inump,imp)
627 	struct iso_directory_record *isodir;
628 	char *outbuf;
629 	u_short *outlen;
630 	ino_t *inump;
631 	struct iso_mnt *imp;
632 {
633 	ISO_RRIP_ANALYZE analyze;
634 	RRIP_TABLE *tab;
635 	u_short c;
636 
637 	analyze.outbuf = outbuf;
638 	analyze.outlen = outlen;
639 	analyze.maxlen = NAME_MAX;
640 	analyze.inump = inump;
641 	analyze.imp = imp;
642 	analyze.fields = ISO_SUSP_ALTNAME|ISO_SUSP_RELDIR|ISO_SUSP_CLINK|ISO_SUSP_PLINK;
643 	*outlen = 0;
644 
645 	isochar(isodir->name, isodir->name + isonum_711(isodir->name_len),
646 		imp->joliet_level, &c, NULL, imp->im_flags, imp->im_d2l);
647 	tab = rrip_table_getname;
648 	if (c == 0 || c == 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  */
661 static RRIP_TABLE rrip_table_getsymname[] = {
662 	{ "SL", BC cd9660_rrip_slink,	0,			ISO_SUSP_SLINK },
663 	{ "RR", BC cd9660_rrip_idflag,	0,			ISO_SUSP_IDFLAG },
664 	{ "CE", BC cd9660_rrip_cont,	0,			ISO_SUSP_CONT },
665 	{ "ST", BC cd9660_rrip_stop,	0,			ISO_SUSP_STOP },
666 	{ "",	0,			0,			0 }
667 };
668 
669 int
670 cd9660_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 
689 static RRIP_TABLE rrip_table_extref[] = {
690 	{ "ER", BC cd9660_rrip_extref,	0,			ISO_SUSP_EXTREF },
691 	{ "CE", BC cd9660_rrip_cont,	0,			ISO_SUSP_CONT },
692 	{ "ST", BC 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  */
700 int
701 cd9660_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 }
725