Rename printf -> kprintf in sys/ and add some defines where necessary
[dragonfly.git] / sys / vfs / isofs / cd9660 / cd9660_rrip.c
CommitLineData
984263bc
MD
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: src/sys/isofs/cd9660/cd9660_rrip.c,v 1.17 1999/08/28 00:46:06 peter Exp $
086c1d7e 40 * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_rrip.c,v 1.13 2006/12/23 00:41:29 swildner Exp $
984263bc
MD
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/buf.h>
46#include <sys/vnode.h>
47#include <sys/mount.h>
48#include <sys/kernel.h>
49
1f2de5d4
MD
50#include "iso.h"
51#include "cd9660_node.h"
52#include "cd9660_rrip.h"
53#include "iso_rrip.h"
984263bc 54
a6ee311a 55typedef int rrt_func_t (void *, ISO_RRIP_ANALYZE *ana);
984263bc
MD
56
57typedef struct {
58 char type[2];
59 rrt_func_t *func;
a6ee311a 60 void (*func2) (struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana);
984263bc
MD
61 int result;
62} RRIP_TABLE;
63
a6ee311a
RG
64static int cd9660_rrip_altname (ISO_RRIP_ALTNAME *p,
65 ISO_RRIP_ANALYZE *ana);
66static int cd9660_rrip_attr (ISO_RRIP_ATTR *p, ISO_RRIP_ANALYZE *ana);
67static int cd9660_rrip_cont (ISO_RRIP_CONT *p, ISO_RRIP_ANALYZE *ana);
68static void cd9660_rrip_defattr (struct iso_directory_record *isodir,
69 ISO_RRIP_ANALYZE *ana);
70static void cd9660_rrip_defname (struct iso_directory_record *isodir,
71 ISO_RRIP_ANALYZE *ana);
72static void cd9660_rrip_deftstamp (struct iso_directory_record *isodir,
73 ISO_RRIP_ANALYZE *ana);
74static int cd9660_rrip_device (ISO_RRIP_DEVICE *p,
75 ISO_RRIP_ANALYZE *ana);
76static int cd9660_rrip_extref (ISO_RRIP_EXTREF *p,
77 ISO_RRIP_ANALYZE *ana);
78static int cd9660_rrip_idflag (ISO_RRIP_IDFLAG *p,
79 ISO_RRIP_ANALYZE *ana);
80static int cd9660_rrip_loop (struct iso_directory_record *isodir,
984263bc 81 ISO_RRIP_ANALYZE *ana,
a6ee311a
RG
82 RRIP_TABLE *table);
83static int cd9660_rrip_pclink (ISO_RRIP_CLINK *p,
84 ISO_RRIP_ANALYZE *ana);
85static int cd9660_rrip_reldir (ISO_RRIP_RELDIR *p,
86 ISO_RRIP_ANALYZE *ana);
87static int cd9660_rrip_slink (ISO_RRIP_SLINK *p,
88 ISO_RRIP_ANALYZE *ana);
89static int cd9660_rrip_stop (ISO_SUSP_HEADER *p,
90 ISO_RRIP_ANALYZE *ana);
91static int cd9660_rrip_tstamp (ISO_RRIP_TSTAMP *p,
92 ISO_RRIP_ANALYZE *ana);
984263bc
MD
93
94/*
95 * POSIX file attribute
96 */
97static int
3fa8192b 98cd9660_rrip_attr(ISO_RRIP_ATTR *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
99{
100 ana->inop->inode.iso_mode = isonum_733(p->mode);
101 ana->inop->inode.iso_uid = isonum_733(p->uid);
102 ana->inop->inode.iso_gid = isonum_733(p->gid);
103 ana->inop->inode.iso_links = isonum_733(p->links);
104 ana->fields &= ~ISO_SUSP_ATTR;
105 return ISO_SUSP_ATTR;
106}
107
108static void
3fa8192b 109cd9660_rrip_defattr(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana)
984263bc
MD
110{
111 /* But this is a required field! */
086c1d7e 112 kprintf("RRIP without PX field?\n");
984263bc
MD
113 cd9660_defattr(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
114}
115
116/*
117 * Symbolic Links
118 */
119static int
3fa8192b 120cd9660_rrip_slink(ISO_RRIP_SLINK *p, ISO_RRIP_ANALYZE *ana)
984263bc 121{
3a1b0fdc
RG
122 ISO_RRIP_SLINK_COMPONENT *pcomp;
123 ISO_RRIP_SLINK_COMPONENT *pcompe;
75ffff0d
JS
124 int error, len, wlen, cont;
125 char *outbuf, *inbuf, *freebuf;
984263bc
MD
126
127 pcomp = (ISO_RRIP_SLINK_COMPONENT *)p->component;
128 pcompe = (ISO_RRIP_SLINK_COMPONENT *)((char *)p + isonum_711(p->h.length));
129 len = *ana->outlen;
130 outbuf = ana->outbuf;
131 cont = ana->cont;
75ffff0d 132 freebuf = NULL;
984263bc
MD
133
134 /*
135 * Gathering a Symbolic name from each component with path
136 */
137 for (;
138 pcomp < pcompe;
139 pcomp = (ISO_RRIP_SLINK_COMPONENT *)((char *)pcomp + ISO_RRIP_SLSIZ
140 + isonum_711(pcomp->clen))) {
141
142 if (!cont) {
143 if (len < ana->maxlen) {
144 len++;
145 *outbuf++ = '/';
146 }
147 }
148 cont = 0;
149
150 inbuf = "..";
151 wlen = 0;
152
153 switch (*pcomp->cflag) {
154
155 case ISO_SUSP_CFLAG_CURRENT:
156 /* Inserting Current */
157 wlen = 1;
158 break;
159
160 case ISO_SUSP_CFLAG_PARENT:
161 /* Inserting Parent */
162 wlen = 2;
163 break;
164
165 case ISO_SUSP_CFLAG_ROOT:
166 /* Inserting slash for ROOT */
167 /* start over from beginning(?) */
168 outbuf -= len;
169 len = 0;
170 break;
171
172 case ISO_SUSP_CFLAG_VOLROOT:
173 /* Inserting a mount point i.e. "/cdrom" */
174 /* same as above */
175 outbuf -= len;
176 len = 0;
28623bf9 177 error = cache_fullpath(NULL, &ana->imp->im_mountp->mnt_ncmountpt,
75ffff0d
JS
178 &inbuf, &freebuf);
179 if (error)
180 goto bad;
984263bc
MD
181 wlen = strlen(inbuf);
182 break;
183
184 case ISO_SUSP_CFLAG_HOST:
185 /* Inserting hostname i.e. "kurt.tools.de" */
186 inbuf = hostname;
187 wlen = strlen(hostname);
188 break;
189
190 case ISO_SUSP_CFLAG_CONTINUE:
191 cont = 1;
192 /* fall thru */
193 case 0:
194 /* Inserting component */
195 wlen = isonum_711(pcomp->clen);
196 inbuf = pcomp->name;
197 break;
198 default:
086c1d7e 199 kprintf("RRIP with incorrect flags?");
984263bc
MD
200 wlen = ana->maxlen + 1;
201 break;
202 }
203
75ffff0d
JS
204 if (len + wlen > ana->maxlen)
205 goto bad;
984263bc
MD
206
207 bcopy(inbuf,outbuf,wlen);
208 outbuf += wlen;
209 len += wlen;
210
75ffff0d 211 if (freebuf != NULL) {
efda3bd0 212 kfree(freebuf, M_TEMP);
75ffff0d
JS
213 freebuf = NULL;
214 }
984263bc
MD
215 }
216 ana->outbuf = outbuf;
217 *ana->outlen = len;
218 ana->cont = cont;
219
220 if (!isonum_711(p->flags)) {
221 ana->fields &= ~ISO_SUSP_SLINK;
222 return ISO_SUSP_SLINK;
223 }
224 return 0;
75ffff0d
JS
225
226bad:
2562a071 227 if (freebuf != NULL)
efda3bd0 228 kfree(freebuf, M_TEMP);
75ffff0d
JS
229 ana->cont = 1;
230 ana->fields = 0;
231 ana->outbuf -= *ana->outlen;
232 *ana->outlen = 0;
233 return 0;
984263bc
MD
234}
235
236/*
237 * Alternate name
238 */
239static int
3fa8192b 240cd9660_rrip_altname(ISO_RRIP_ALTNAME *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
241{
242 char *inbuf;
243 int wlen;
244 int cont;
245
246 inbuf = "..";
247 wlen = 0;
248 cont = 0;
249
250 switch (*p->flags) {
251 case ISO_SUSP_CFLAG_CURRENT:
252 /* Inserting Current */
253 wlen = 1;
254 break;
255
256 case ISO_SUSP_CFLAG_PARENT:
257 /* Inserting Parent */
258 wlen = 2;
259 break;
260
261 case ISO_SUSP_CFLAG_HOST:
262 /* Inserting hostname i.e. "kurt.tools.de" */
263 inbuf = hostname;
264 wlen = strlen(hostname);
265 break;
266
267 case ISO_SUSP_CFLAG_CONTINUE:
268 cont = 1;
269 /* fall thru */
270 case 0:
271 /* Inserting component */
272 wlen = isonum_711(p->h.length) - 5;
273 inbuf = (char *)p + 5;
274 break;
275
276 default:
086c1d7e 277 kprintf("RRIP with incorrect NM flags?\n");
984263bc
MD
278 wlen = ana->maxlen + 1;
279 break;
280 }
281
282 if ((*ana->outlen += wlen) > ana->maxlen) {
283 /* treat as no name field */
284 ana->fields &= ~ISO_SUSP_ALTNAME;
285 ana->outbuf -= *ana->outlen - wlen;
286 *ana->outlen = 0;
287 return 0;
288 }
289
290 bcopy(inbuf,ana->outbuf,wlen);
291 ana->outbuf += wlen;
292
293 if (!cont) {
294 ana->fields &= ~ISO_SUSP_ALTNAME;
295 return ISO_SUSP_ALTNAME;
296 }
297 return 0;
298}
299
300static void
3fa8192b 301cd9660_rrip_defname(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana)
984263bc
MD
302{
303 isofntrans(isodir->name,isonum_711(isodir->name_len),
304 ana->outbuf,ana->outlen,
305 1,isonum_711(isodir->flags)&4, ana->imp->joliet_level);
306 switch (*ana->outbuf) {
307 default:
308 break;
309 case 1:
310 *ana->outlen = 2;
311 /* FALL THROUGH */
312 case 0:
313 /* outlen is 1 already */
314 strcpy(ana->outbuf,"..");
315 break;
316 }
317}
318
319/*
320 * Parent or Child Link
321 */
322static int
3fa8192b 323cd9660_rrip_pclink(ISO_RRIP_CLINK *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
324{
325 *ana->inump = isonum_733(p->dir_loc) << ana->imp->im_bshift;
326 ana->fields &= ~(ISO_SUSP_CLINK|ISO_SUSP_PLINK);
327 return *p->h.type == 'C' ? ISO_SUSP_CLINK : ISO_SUSP_PLINK;
328}
329
330/*
331 * Relocated directory
332 */
333static int
3fa8192b 334cd9660_rrip_reldir(ISO_RRIP_RELDIR *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
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
3fa8192b 343cd9660_rrip_tstamp(ISO_RRIP_TSTAMP *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
344{
345 u_char *ptime;
346
347 ptime = p->time;
348
349 /* Check a format of time stamp (7bytes/17bytes) */
350 if (!(*p->flags&ISO_SUSP_TSTAMP_FORM17)) {
351 if (*p->flags&ISO_SUSP_TSTAMP_CREAT)
352 ptime += 7;
353
354 if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) {
355 cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_mtime,
356 ISO_FTYPE_RRIP);
357 ptime += 7;
358 } else
359 bzero(&ana->inop->inode.iso_mtime,sizeof(struct timespec));
360
361 if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) {
362 cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_atime,
363 ISO_FTYPE_RRIP);
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 ISO_FTYPE_RRIP);
371 else
372 ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime;
373
374 } else {
375 if (*p->flags&ISO_SUSP_TSTAMP_CREAT)
376 ptime += 17;
377
378 if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) {
379 cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_mtime);
380 ptime += 17;
381 } else
382 bzero(&ana->inop->inode.iso_mtime,sizeof(struct timespec));
383
384 if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) {
385 cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_atime);
386 ptime += 17;
387 } else
388 ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime;
389
390 if (*p->flags&ISO_SUSP_TSTAMP_ATTR)
391 cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_ctime);
392 else
393 ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime;
394
395 }
396 ana->fields &= ~ISO_SUSP_TSTAMP;
397 return ISO_SUSP_TSTAMP;
398}
399
400static void
3fa8192b 401cd9660_rrip_deftstamp(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana)
984263bc
MD
402{
403 cd9660_deftstamp(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
404}
405
406/*
407 * POSIX device modes
408 */
409static int
3fa8192b 410cd9660_rrip_device(ISO_RRIP_DEVICE *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
411{
412 u_int high, low;
413
414 high = isonum_733(p->dev_t_high);
415 low = isonum_733(p->dev_t_low);
416
417 if (high == 0)
418 ana->inop->inode.iso_rdev = makeudev(umajor(low), uminor(low));
419 else
420 ana->inop->inode.iso_rdev = makeudev(high, uminor(low));
421 ana->fields &= ~ISO_SUSP_DEVICE;
422 return ISO_SUSP_DEVICE;
423}
424
425/*
426 * Flag indicating
427 */
428static int
3fa8192b 429cd9660_rrip_idflag(ISO_RRIP_IDFLAG *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
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 */
442static int
3fa8192b 443cd9660_rrip_cont(ISO_RRIP_CONT *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
444{
445 ana->iso_ce_blk = isonum_733(p->location);
446 ana->iso_ce_off = isonum_733(p->offset);
447 ana->iso_ce_len = isonum_733(p->length);
448 return ISO_SUSP_CONT;
449}
450
451/*
452 * System Use end
453 */
454static int
3fa8192b 455cd9660_rrip_stop(ISO_SUSP_HEADER *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
456{
457 return ISO_SUSP_STOP;
458}
459
460/*
461 * Extension reference
462 */
463static int
3fa8192b 464cd9660_rrip_extref(ISO_RRIP_EXTREF *p, ISO_RRIP_ANALYZE *ana)
984263bc
MD
465{
466 if (isonum_711(p->len_id) != 10
467 || bcmp((char *)p + 8,"RRIP_1991A",10)
468 || isonum_711(p->version) != 1)
469 return 0;
470 ana->fields &= ~ISO_SUSP_EXTREF;
471 return ISO_SUSP_EXTREF;
472}
473
474static int
3fa8192b
CP
475cd9660_rrip_loop(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana,
476 RRIP_TABLE *table)
984263bc 477{
3a1b0fdc
RG
478 RRIP_TABLE *ptable;
479 ISO_SUSP_HEADER *phead;
480 ISO_SUSP_HEADER *pend;
984263bc
MD
481 struct buf *bp = NULL;
482 char *pwhead;
483 u_char c;
484 int result;
485
486 /*
487 * Note: If name length is odd,
488 * it will be padding 1 byte after the name
489 */
490 pwhead = isodir->name + isonum_711(isodir->name_len);
491 if (!(isonum_711(isodir->name_len)&1))
492 pwhead++;
493 isochar(isodir->name, pwhead, ana->imp->joliet_level, &c);
494
495 /* If it's not the '.' entry of the root dir obey SP field */
496 if (c != 0 || isonum_733(isodir->extent) != ana->imp->root_extent)
497 pwhead += ana->imp->rr_skip;
498 else
499 pwhead += ana->imp->rr_skip0;
500
501 phead = (ISO_SUSP_HEADER *)pwhead;
502 pend = (ISO_SUSP_HEADER *)((char *)isodir + isonum_711(isodir->length));
503
504 result = 0;
505 while (1) {
506 ana->iso_ce_len = 0;
507 /*
508 * Note: "pend" should be more than one SUSP header
509 */
510 while (pend >= phead + 1) {
511 if (isonum_711(phead->version) == 1) {
512 for (ptable = table; ptable->func; ptable++) {
513 if (*phead->type == *ptable->type
514 && phead->type[1] == ptable->type[1]) {
515 result |= ptable->func(phead,ana);
516 break;
517 }
518 }
519 if (!ana->fields)
520 break;
521 }
522 if (result&ISO_SUSP_STOP) {
523 result &= ~ISO_SUSP_STOP;
524 break;
525 }
526 /* plausibility check */
527 if (isonum_711(phead->length) < sizeof(*phead))
528 break;
529 /*
530 * move to next SUSP
531 * Hopefully this works with newer versions, too
532 */
533 phead = (ISO_SUSP_HEADER *)((char *)phead + isonum_711(phead->length));
534 }
535
536 if (ana->fields && ana->iso_ce_len) {
537 if (ana->iso_ce_blk >= ana->imp->volume_space_size
538 || ana->iso_ce_off + ana->iso_ce_len > ana->imp->logical_block_size
539 || bread(ana->imp->im_devvp,
54078292 540 lblktooff(ana->imp, ana->iso_ce_blk),
3b568787 541 ana->imp->logical_block_size, &bp))
984263bc
MD
542 /* what to do now? */
543 break;
544 phead = (ISO_SUSP_HEADER *)(bp->b_data + ana->iso_ce_off);
545 pend = (ISO_SUSP_HEADER *) ((char *)phead + ana->iso_ce_len);
546 } else
547 break;
548 }
549 if (bp)
550 brelse(bp);
551 /*
552 * If we don't find the Basic SUSP stuffs, just set default value
553 * (attribute/time stamp)
554 */
555 for (ptable = table; ptable->func2; ptable++)
556 if (!(ptable->result&result))
557 ptable->func2(isodir,ana);
558
559 return result;
560}
561
562/*
563 * Get Attributes.
564 */
565/*
566 * XXX the casts are bogus but will do for now.
567 */
568#define BC (rrt_func_t *)
569static RRIP_TABLE rrip_table_analyze[] = {
570 { "PX", BC cd9660_rrip_attr, cd9660_rrip_defattr, ISO_SUSP_ATTR },
571 { "TF", BC cd9660_rrip_tstamp, cd9660_rrip_deftstamp, ISO_SUSP_TSTAMP },
572 { "PN", BC cd9660_rrip_device, 0, ISO_SUSP_DEVICE },
573 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
574 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
575 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
576 { "", 0, 0, 0 }
577};
578
579int
3fa8192b
CP
580cd9660_rrip_analyze(struct iso_directory_record *isodir, struct iso_node *inop,
581 struct iso_mnt *imp)
984263bc
MD
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[] = {
596 { "NM", BC cd9660_rrip_altname, cd9660_rrip_defname, ISO_SUSP_ALTNAME },
597 { "CL", BC cd9660_rrip_pclink, 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK },
598 { "PL", BC cd9660_rrip_pclink, 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK },
599 { "RE", BC cd9660_rrip_reldir, 0, ISO_SUSP_RELDIR },
600 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
601 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
602 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
603 { "", 0, 0, 0 }
604};
605
606int
3fa8192b
CP
607cd9660_rrip_getname(struct iso_directory_record *isodir, char *outbuf,
608 u_short *outlen, ino_t *inump, struct iso_mnt *imp)
984263bc
MD
609{
610 ISO_RRIP_ANALYZE analyze;
611 RRIP_TABLE *tab;
612 u_char c;
613
614 analyze.outbuf = outbuf;
615 analyze.outlen = outlen;
616 analyze.maxlen = NAME_MAX;
617 analyze.inump = inump;
618 analyze.imp = imp;
619 analyze.fields = ISO_SUSP_ALTNAME|ISO_SUSP_RELDIR|ISO_SUSP_CLINK|ISO_SUSP_PLINK;
620 *outlen = 0;
621
622 isochar(isodir->name, isodir->name + isonum_711(isodir->name_len),
623 imp->joliet_level, &c);
624 tab = rrip_table_getname;
625 if (c == 0 || c == 1) {
626 cd9660_rrip_defname(isodir,&analyze);
627
628 analyze.fields &= ~ISO_SUSP_ALTNAME;
629 tab++;
630 }
631
632 return cd9660_rrip_loop(isodir,&analyze,tab);
633}
634
635/*
636 * Get Symbolic Link.
637 */
638static RRIP_TABLE rrip_table_getsymname[] = {
639 { "SL", BC cd9660_rrip_slink, 0, ISO_SUSP_SLINK },
640 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG },
641 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
642 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
643 { "", 0, 0, 0 }
644};
645
646int
3fa8192b
CP
647cd9660_rrip_getsymname(struct iso_directory_record *isodir, char *outbuf,
648 u_short *outlen, struct iso_mnt *imp)
984263bc
MD
649{
650 ISO_RRIP_ANALYZE analyze;
651
652 analyze.outbuf = outbuf;
653 analyze.outlen = outlen;
654 *outlen = 0;
655 analyze.maxlen = MAXPATHLEN;
656 analyze.cont = 1; /* don't start with a slash */
657 analyze.imp = imp;
658 analyze.fields = ISO_SUSP_SLINK;
659
660 return (cd9660_rrip_loop(isodir,&analyze,rrip_table_getsymname)&ISO_SUSP_SLINK);
661}
662
663static RRIP_TABLE rrip_table_extref[] = {
664 { "ER", BC cd9660_rrip_extref, 0, ISO_SUSP_EXTREF },
665 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT },
666 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP },
667 { "", 0, 0, 0 }
668};
669
670/*
671 * Check for Rock Ridge Extension and return offset of its fields.
672 * Note: We insist on the ER field.
673 */
674int
3fa8192b 675cd9660_rrip_offset(struct iso_directory_record *isodir, struct iso_mnt *imp)
984263bc
MD
676{
677 ISO_RRIP_OFFSET *p;
678 ISO_RRIP_ANALYZE analyze;
679
680 imp->rr_skip0 = 0;
681 p = (ISO_RRIP_OFFSET *)(isodir->name + 1);
682 if (bcmp(p,"SP\7\1\276\357",6)) {
683 /* Maybe, it's a CDROM XA disc? */
684 imp->rr_skip0 = 15;
685 p = (ISO_RRIP_OFFSET *)((char *)p + 15);
686 if (bcmp(p,"SP\7\1\276\357",6))
687 return -1;
688 }
689
690 analyze.imp = imp;
691 analyze.fields = ISO_SUSP_EXTREF;
692 if (!(cd9660_rrip_loop(isodir,&analyze,rrip_table_extref)&ISO_SUSP_EXTREF))
693 return -1;
694
695 return isonum_711(p->skip);
696}