1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley
8 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
9 * Support code is derived from software contributed to Berkeley
10 * by Atsushi Murai (amurai@spec.co.jp).
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)cd9660_rrip.c 8.6 (Berkeley) 12/5/94
37 */
38
39 #include <sys/cdefs.h>
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/bio.h>
43 #include <sys/buf.h>
44 #include <sys/jail.h>
45 #include <sys/vnode.h>
46 #include <sys/mount.h>
47 #include <sys/kernel.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
cd9660_rrip_attr(p,ana)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
cd9660_rrip_defattr(isodir,ana)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
cd9660_rrip_slink(p,ana)113 cd9660_rrip_slink(p,ana)
114 ISO_RRIP_SLINK *p;
115 ISO_RRIP_ANALYZE *ana;
116 {
117 ISO_RRIP_SLINK_COMPONENT *pcomp;
118 ISO_RRIP_SLINK_COMPONENT *pcompe;
119 int len, wlen, cont;
120 char *outbuf, *inbuf;
121 char hostbuf[MAXHOSTNAMELEN];
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 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 case ISO_SUSP_CFLAG_CURRENT:
149 /* Inserting Current */
150 wlen = 1;
151 break;
152
153 case ISO_SUSP_CFLAG_PARENT:
154 /* Inserting Parent */
155 wlen = 2;
156 break;
157
158 case ISO_SUSP_CFLAG_ROOT:
159 /* Inserting slash for ROOT */
160 /* Double slash, nothing really to do here. */
161 break;
162
163 case ISO_SUSP_CFLAG_VOLROOT:
164 /* Inserting a mount point i.e. "/cdrom" */
165 /* same as above */
166 outbuf -= len;
167 len = 0;
168 inbuf = ana->imp->im_mountp->mnt_stat.f_mntonname;
169 wlen = strlen(inbuf);
170 break;
171
172 case ISO_SUSP_CFLAG_HOST:
173 /* Inserting hostname i.e. "kurt.tools.de" */
174 getcredhostname(curthread->td_ucred, hostbuf,
175 sizeof(hostbuf));
176 inbuf = hostbuf;
177 wlen = strlen(inbuf);
178 break;
179
180 case ISO_SUSP_CFLAG_CONTINUE:
181 cont = 1;
182 /* FALLTHROUGH */
183 case 0:
184 /* Inserting component */
185 wlen = isonum_711(pcomp->clen);
186 inbuf = pcomp->name;
187 break;
188 default:
189 printf("RRIP with incorrect flags?");
190 wlen = ana->maxlen + 1;
191 break;
192 }
193
194 if (len + wlen > ana->maxlen) {
195 /* indicate error to caller */
196 ana->cont = 1;
197 ana->fields = 0;
198 ana->outbuf -= *ana->outlen;
199 *ana->outlen = 0;
200 return 0;
201 }
202
203 memcpy(outbuf, inbuf, wlen);
204 outbuf += wlen;
205 len += wlen;
206 }
207 ana->outbuf = outbuf;
208 *ana->outlen = len;
209 ana->cont = cont;
210
211 if (!isonum_711(p->flags)) {
212 ana->fields &= ~ISO_SUSP_SLINK;
213 return ISO_SUSP_SLINK;
214 }
215 return 0;
216 }
217
218 /*
219 * Alternate name
220 */
221 static int
cd9660_rrip_altname(p,ana)222 cd9660_rrip_altname(p,ana)
223 ISO_RRIP_ALTNAME *p;
224 ISO_RRIP_ANALYZE *ana;
225 {
226 char *inbuf;
227 int wlen;
228 int cont;
229 char hostbuf[MAXHOSTNAMELEN];
230
231 inbuf = "..";
232 wlen = 0;
233 cont = 0;
234
235 switch (*p->flags) {
236 case ISO_SUSP_CFLAG_CURRENT:
237 /* Inserting Current */
238 wlen = 1;
239 break;
240
241 case ISO_SUSP_CFLAG_PARENT:
242 /* Inserting Parent */
243 wlen = 2;
244 break;
245
246 case ISO_SUSP_CFLAG_HOST:
247 /* Inserting hostname i.e. "kurt.tools.de" */
248 getcredhostname(curthread->td_ucred, hostbuf, sizeof(hostbuf));
249 inbuf = hostbuf;
250 wlen = strlen(inbuf);
251 break;
252
253 case ISO_SUSP_CFLAG_CONTINUE:
254 cont = 1;
255 /* FALLTHROUGH */
256 case 0:
257 /* Inserting component */
258 wlen = isonum_711(p->h.length) - 5;
259 inbuf = (char *)p + 5;
260 break;
261
262 default:
263 printf("RRIP with incorrect NM flags?\n");
264 wlen = ana->maxlen + 1;
265 break;
266 }
267
268 if ((*ana->outlen += wlen) > ana->maxlen) {
269 /* treat as no name field */
270 ana->fields &= ~ISO_SUSP_ALTNAME;
271 ana->outbuf -= *ana->outlen - wlen;
272 *ana->outlen = 0;
273 return 0;
274 }
275
276 memcpy(ana->outbuf, inbuf, wlen);
277 ana->outbuf += wlen;
278
279 if (!cont) {
280 ana->fields &= ~ISO_SUSP_ALTNAME;
281 return ISO_SUSP_ALTNAME;
282 }
283 return 0;
284 }
285
286 static void
cd9660_rrip_defname(isodir,ana)287 cd9660_rrip_defname(isodir,ana)
288 struct iso_directory_record *isodir;
289 ISO_RRIP_ANALYZE *ana;
290 {
291 isofntrans(isodir->name,isonum_711(isodir->name_len),
292 ana->outbuf,ana->outlen,
293 1,isonum_711(isodir->flags)&4, ana->imp->joliet_level,
294 ana->imp->im_flags, ana->imp->im_d2l);
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
cd9660_rrip_pclink(p,ana)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
cd9660_rrip_reldir(p,ana)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
cd9660_rrip_tstamp(p,ana)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 memset(&ana->inop->inode.iso_mtime, 0, 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 memset(&ana->inop->inode.iso_mtime, 0, 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 ana->fields &= ~ISO_SUSP_TSTAMP;
391 return ISO_SUSP_TSTAMP;
392 }
393
394 static void
cd9660_rrip_deftstamp(isodir,ana)395 cd9660_rrip_deftstamp(isodir,ana)
396 struct iso_directory_record *isodir;
397 ISO_RRIP_ANALYZE *ana;
398 {
399 cd9660_deftstamp(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
400 }
401
402 /*
403 * POSIX device modes
404 */
405 static int
cd9660_rrip_device(p,ana)406 cd9660_rrip_device(p,ana)
407 ISO_RRIP_DEVICE *p;
408 ISO_RRIP_ANALYZE *ana;
409 {
410 u_int high, low;
411
412 high = isonum_733(p->dev_t_high);
413 low = isonum_733(p->dev_t_low);
414
415 if (high == 0)
416 ana->inop->inode.iso_rdev = makedev(major(low), minor(low));
417 else
418 ana->inop->inode.iso_rdev = makedev(high, minor(low));
419 ana->fields &= ~ISO_SUSP_DEVICE;
420 return ISO_SUSP_DEVICE;
421 }
422
423 /*
424 * Flag indicating
425 */
426 static int
cd9660_rrip_idflag(p,ana)427 cd9660_rrip_idflag(p,ana)
428 ISO_RRIP_IDFLAG *p;
429 ISO_RRIP_ANALYZE *ana;
430 {
431 ana->fields &= isonum_711(p->flags)|~0xff; /* don't touch high bits */
432 /* special handling of RE field */
433 if (ana->fields&ISO_SUSP_RELDIR)
434 return cd9660_rrip_reldir(/* XXX */ (ISO_RRIP_RELDIR *)p,ana);
435
436 return ISO_SUSP_IDFLAG;
437 }
438
439 /*
440 * Continuation pointer
441 */
442 static int
cd9660_rrip_cont(p,ana)443 cd9660_rrip_cont(p,ana)
444 ISO_RRIP_CONT *p;
445 ISO_RRIP_ANALYZE *ana;
446 {
447 ana->iso_ce_blk = isonum_733(p->location);
448 ana->iso_ce_off = isonum_733(p->offset);
449 ana->iso_ce_len = isonum_733(p->length);
450 return ISO_SUSP_CONT;
451 }
452
453 /*
454 * System Use end
455 */
456 static int
cd9660_rrip_stop(p,ana)457 cd9660_rrip_stop(p,ana)
458 ISO_SUSP_HEADER *p;
459 ISO_RRIP_ANALYZE *ana;
460 {
461 return ISO_SUSP_STOP;
462 }
463
464 /*
465 * Extension reference
466 */
467 static int
cd9660_rrip_extref(p,ana)468 cd9660_rrip_extref(p,ana)
469 ISO_RRIP_EXTREF *p;
470 ISO_RRIP_ANALYZE *ana;
471 {
472 if ( ! ((isonum_711(p->len_id) == 10
473 && bcmp((char *)p + 8,"RRIP_1991A",10) == 0)
474 || (isonum_711(p->len_id) == 10
475 && bcmp((char *)p + 8,"IEEE_P1282",10) == 0)
476 || (isonum_711(p->len_id) == 9
477 && bcmp((char *)p + 8,"IEEE_1282", 9) == 0))
478 || isonum_711(p->version) != 1)
479 return 0;
480 ana->fields &= ~ISO_SUSP_EXTREF;
481 return ISO_SUSP_EXTREF;
482 }
483
484 static int
cd9660_rrip_loop(isodir,ana,table)485 cd9660_rrip_loop(isodir,ana,table)
486 struct iso_directory_record *isodir;
487 ISO_RRIP_ANALYZE *ana;
488 RRIP_TABLE *table;
489 {
490 RRIP_TABLE *ptable;
491 ISO_SUSP_HEADER *phead;
492 ISO_SUSP_HEADER *pend;
493 struct buf *bp = NULL;
494 char *pwhead;
495 u_short c;
496 int result;
497
498 /*
499 * Note: If name length is odd,
500 * it will be padding 1 byte after the name
501 */
502 pwhead = isodir->name + isonum_711(isodir->name_len);
503 if (!(isonum_711(isodir->name_len)&1))
504 pwhead++;
505 isochar(isodir->name, pwhead, ana->imp->joliet_level, &c, NULL,
506 ana->imp->im_flags, ana->imp->im_d2l);
507
508 /* If it's not the '.' entry of the root dir obey SP field */
509 if (c != 0 || isonum_733(isodir->extent) != ana->imp->root_extent)
510 pwhead += ana->imp->rr_skip;
511 else
512 pwhead += ana->imp->rr_skip0;
513
514 phead = (ISO_SUSP_HEADER *)pwhead;
515 pend = (ISO_SUSP_HEADER *)((char *)isodir + isonum_711(isodir->length));
516
517 result = 0;
518 while (1) {
519 ana->iso_ce_len = 0;
520 /*
521 * Note: "pend" should be more than one SUSP header
522 */
523 while (pend >= phead + 1) {
524 if (isonum_711(phead->version) == 1) {
525 for (ptable = table; ptable->func; ptable++) {
526 if (*phead->type == *ptable->type
527 && phead->type[1] == ptable->type[1]) {
528 result |= ptable->func(phead,ana);
529 break;
530 }
531 }
532 if (!ana->fields)
533 break;
534 }
535 if (result&ISO_SUSP_STOP) {
536 result &= ~ISO_SUSP_STOP;
537 break;
538 }
539 /* plausibility check */
540 if (isonum_711(phead->length) < sizeof(*phead))
541 break;
542 /*
543 * move to next SUSP
544 * Hopefully this works with newer versions, too
545 */
546 phead = (ISO_SUSP_HEADER *)((char *)phead + isonum_711(phead->length));
547 }
548
549 if (ana->fields && ana->iso_ce_len) {
550 if (ana->iso_ce_blk >= ana->imp->volume_space_size ||
551 ana->iso_ce_off + ana->iso_ce_len >
552 ana->imp->logical_block_size)
553 break;
554 if (bp != NULL) {
555 brelse(bp);
556 bp = NULL;
557 }
558 if (bread(ana->imp->im_devvp,
559 ana->iso_ce_blk <<
560 (ana->imp->im_bshift - DEV_BSHIFT),
561 ana->imp->logical_block_size, NOCRED, &bp) != 0)
562 /* what to do now? */
563 break;
564 phead = (ISO_SUSP_HEADER *)(bp->b_data + ana->iso_ce_off);
565 pend = (ISO_SUSP_HEADER *) ((char *)phead + ana->iso_ce_len);
566 } else
567 break;
568 }
569 if (bp)
570 brelse(bp);
571 /*
572 * If we don't find the Basic SUSP stuffs, just set default value
573 * (attribute/time stamp)
574 */
575 for (ptable = table; ptable->func2; ptable++)
576 if (!(ptable->result&result))
577 ptable->func2(isodir,ana);
578
579 return result;
580 }
581
582 /*
583 * Get Attributes.
584 */
585 /*
586 * XXX the casts are bogus but will do for now.
587 */
588 #define BC (rrt_func_t *)
589 static RRIP_TABLE rrip_table_analyze[] = {
590 { "PX", BC cd9660_rrip_attr, cd9660_rrip_defattr, ISO_SUSP_ATTR },
591 { "TF", BC cd9660_rrip_tstamp, cd9660_rrip_deftstamp, ISO_SUSP_TSTAMP },
592 { "PN", BC cd9660_rrip_device, 0, ISO_SUSP_DEVICE },
593 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
594 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
595 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
596 { "", 0, 0, 0 }
597 };
598
599 int
cd9660_rrip_analyze(isodir,inop,imp)600 cd9660_rrip_analyze(isodir,inop,imp)
601 struct iso_directory_record *isodir;
602 struct iso_node *inop;
603 struct iso_mnt *imp;
604 {
605 ISO_RRIP_ANALYZE analyze;
606
607 analyze.inop = inop;
608 analyze.imp = imp;
609 analyze.fields = ISO_SUSP_ATTR|ISO_SUSP_TSTAMP|ISO_SUSP_DEVICE;
610
611 return cd9660_rrip_loop(isodir,&analyze,rrip_table_analyze);
612 }
613
614 /*
615 * Get Alternate Name.
616 */
617 static RRIP_TABLE rrip_table_getname[] = {
618 { "NM", BC cd9660_rrip_altname, cd9660_rrip_defname, ISO_SUSP_ALTNAME },
619 { "CL", BC cd9660_rrip_pclink, 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK },
620 { "PL", BC cd9660_rrip_pclink, 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK },
621 { "RE", BC cd9660_rrip_reldir, 0, ISO_SUSP_RELDIR },
622 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
623 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
624 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
625 { "", 0, 0, 0 }
626 };
627
628 int
cd9660_rrip_getname(isodir,outbuf,outlen,inump,imp)629 cd9660_rrip_getname(isodir,outbuf,outlen,inump,imp)
630 struct iso_directory_record *isodir;
631 char *outbuf;
632 u_short *outlen;
633 cd_ino_t *inump;
634 struct iso_mnt *imp;
635 {
636 ISO_RRIP_ANALYZE analyze;
637 RRIP_TABLE *tab;
638 u_short c;
639
640 analyze.outbuf = outbuf;
641 analyze.outlen = outlen;
642 analyze.maxlen = NAME_MAX;
643 analyze.inump = inump;
644 analyze.imp = imp;
645 analyze.fields = ISO_SUSP_ALTNAME|ISO_SUSP_RELDIR|ISO_SUSP_CLINK|ISO_SUSP_PLINK;
646 *outlen = 0;
647
648 isochar(isodir->name, isodir->name + isonum_711(isodir->name_len),
649 imp->joliet_level, &c, NULL, imp->im_flags, imp->im_d2l);
650 tab = rrip_table_getname;
651 if (c == 0 || c == 1) {
652 cd9660_rrip_defname(isodir,&analyze);
653
654 analyze.fields &= ~ISO_SUSP_ALTNAME;
655 tab++;
656 }
657
658 return cd9660_rrip_loop(isodir,&analyze,tab);
659 }
660
661 /*
662 * Get Symbolic Link.
663 */
664 static RRIP_TABLE rrip_table_getsymname[] = {
665 { "SL", BC cd9660_rrip_slink, 0, ISO_SUSP_SLINK },
666 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
667 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
668 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
669 { "", 0, 0, 0 }
670 };
671
672 int
cd9660_rrip_getsymname(isodir,outbuf,outlen,imp)673 cd9660_rrip_getsymname(isodir,outbuf,outlen,imp)
674 struct iso_directory_record *isodir;
675 char *outbuf;
676 u_short *outlen;
677 struct iso_mnt *imp;
678 {
679 ISO_RRIP_ANALYZE analyze;
680
681 analyze.outbuf = outbuf;
682 analyze.outlen = outlen;
683 *outlen = 0;
684 analyze.maxlen = MAXPATHLEN;
685 analyze.cont = 1; /* don't start with a slash */
686 analyze.imp = imp;
687 analyze.fields = ISO_SUSP_SLINK;
688
689 return (cd9660_rrip_loop(isodir,&analyze,rrip_table_getsymname)&ISO_SUSP_SLINK);
690 }
691
692 static RRIP_TABLE rrip_table_extref[] = {
693 { "ER", BC cd9660_rrip_extref, 0, ISO_SUSP_EXTREF },
694 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
695 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
696 { "", 0, 0, 0 }
697 };
698
699 /*
700 * Check for Rock Ridge Extension and return offset of its fields.
701 * Note: We insist on the ER field.
702 */
703 int
cd9660_rrip_offset(isodir,imp)704 cd9660_rrip_offset(isodir,imp)
705 struct iso_directory_record *isodir;
706 struct iso_mnt *imp;
707 {
708 ISO_RRIP_OFFSET *p;
709 ISO_RRIP_ANALYZE analyze;
710
711 imp->rr_skip0 = 0;
712 p = (ISO_RRIP_OFFSET *)(isodir->name + 1);
713 if (bcmp(p,"SP\7\1\276\357",6)) {
714 /* Maybe, it's a CDROM XA disc? */
715 imp->rr_skip0 = 15;
716 p = (ISO_RRIP_OFFSET *)((char *)p + 15);
717 if (bcmp(p,"SP\7\1\276\357",6))
718 return -1;
719 }
720
721 analyze.imp = imp;
722 analyze.fields = ISO_SUSP_EXTREF;
723 if (!(cd9660_rrip_loop(isodir,&analyze,rrip_table_extref)&ISO_SUSP_EXTREF))
724 return -1;
725
726 return isonum_711(p->skip);
727 }
728