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 */ 40 41 #include <sys/cdefs.h> 42 __FBSDID("$FreeBSD$"); 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/bio.h> 47 #include <sys/buf.h> 48 #include <sys/vnode.h> 49 #include <sys/mount.h> 50 #include <sys/kernel.h> 51 52 #include <isofs/cd9660/iso.h> 53 #include <isofs/cd9660/cd9660_node.h> 54 #include <isofs/cd9660/cd9660_rrip.h> 55 #include <isofs/cd9660/iso_rrip.h> 56 57 typedef int rrt_func_t(void *, ISO_RRIP_ANALYZE *ana); 58 59 typedef struct { 60 char type[2]; 61 rrt_func_t *func; 62 void (*func2)(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana); 63 int result; 64 } RRIP_TABLE; 65 66 static int cd9660_rrip_altname(ISO_RRIP_ALTNAME *p, ISO_RRIP_ANALYZE *ana); 67 static int cd9660_rrip_attr(ISO_RRIP_ATTR *p, ISO_RRIP_ANALYZE *ana); 68 static int cd9660_rrip_cont(ISO_RRIP_CONT *p, ISO_RRIP_ANALYZE *ana); 69 static void cd9660_rrip_defattr(struct iso_directory_record *isodir, 70 ISO_RRIP_ANALYZE *ana); 71 static void cd9660_rrip_defname(struct iso_directory_record *isodir, 72 ISO_RRIP_ANALYZE *ana); 73 static void cd9660_rrip_deftstamp(struct iso_directory_record *isodir, 74 ISO_RRIP_ANALYZE *ana); 75 static int cd9660_rrip_device(ISO_RRIP_DEVICE *p, ISO_RRIP_ANALYZE *ana); 76 static int cd9660_rrip_extref(ISO_RRIP_EXTREF *p, ISO_RRIP_ANALYZE *ana); 77 static int cd9660_rrip_idflag(ISO_RRIP_IDFLAG *p, ISO_RRIP_ANALYZE *ana); 78 static int cd9660_rrip_loop(struct iso_directory_record *isodir, 79 ISO_RRIP_ANALYZE *ana, RRIP_TABLE *table); 80 static int cd9660_rrip_pclink(ISO_RRIP_CLINK *p, ISO_RRIP_ANALYZE *ana); 81 static int cd9660_rrip_reldir(ISO_RRIP_RELDIR *p, ISO_RRIP_ANALYZE *ana); 82 static int cd9660_rrip_slink(ISO_RRIP_SLINK *p, ISO_RRIP_ANALYZE *ana); 83 static int cd9660_rrip_stop(ISO_SUSP_HEADER *p, ISO_RRIP_ANALYZE *ana); 84 static int cd9660_rrip_tstamp(ISO_RRIP_TSTAMP *p, ISO_RRIP_ANALYZE *ana); 85 86 /* 87 * POSIX file attribute 88 */ 89 static int 90 cd9660_rrip_attr(p,ana) 91 ISO_RRIP_ATTR *p; 92 ISO_RRIP_ANALYZE *ana; 93 { 94 ana->inop->inode.iso_mode = isonum_733(p->mode); 95 ana->inop->inode.iso_uid = isonum_733(p->uid); 96 ana->inop->inode.iso_gid = isonum_733(p->gid); 97 ana->inop->inode.iso_links = isonum_733(p->links); 98 ana->fields &= ~ISO_SUSP_ATTR; 99 return ISO_SUSP_ATTR; 100 } 101 102 static void 103 cd9660_rrip_defattr(isodir,ana) 104 struct iso_directory_record *isodir; 105 ISO_RRIP_ANALYZE *ana; 106 { 107 /* But this is a required field! */ 108 printf("RRIP without PX field?\n"); 109 cd9660_defattr(isodir,ana->inop,NULL,ISO_FTYPE_RRIP); 110 } 111 112 /* 113 * Symbolic Links 114 */ 115 static int 116 cd9660_rrip_slink(p,ana) 117 ISO_RRIP_SLINK *p; 118 ISO_RRIP_ANALYZE *ana; 119 { 120 register ISO_RRIP_SLINK_COMPONENT *pcomp; 121 register ISO_RRIP_SLINK_COMPONENT *pcompe; 122 int len, wlen, cont; 123 char *outbuf, *inbuf; 124 125 pcomp = (ISO_RRIP_SLINK_COMPONENT *)p->component; 126 pcompe = (ISO_RRIP_SLINK_COMPONENT *)((char *)p + isonum_711(p->h.length)); 127 len = *ana->outlen; 128 outbuf = ana->outbuf; 129 cont = ana->cont; 130 131 /* 132 * Gathering a Symbolic name from each component with path 133 */ 134 for (; 135 pcomp < pcompe; 136 pcomp = (ISO_RRIP_SLINK_COMPONENT *)((char *)pcomp + ISO_RRIP_SLSIZ 137 + isonum_711(pcomp->clen))) { 138 139 if (!cont) { 140 if (len < ana->maxlen) { 141 len++; 142 *outbuf++ = '/'; 143 } 144 } 145 cont = 0; 146 147 inbuf = ".."; 148 wlen = 0; 149 150 switch (*pcomp->cflag) { 151 152 case ISO_SUSP_CFLAG_CURRENT: 153 /* Inserting Current */ 154 wlen = 1; 155 break; 156 157 case ISO_SUSP_CFLAG_PARENT: 158 /* Inserting Parent */ 159 wlen = 2; 160 break; 161 162 case ISO_SUSP_CFLAG_ROOT: 163 /* Inserting slash for ROOT */ 164 /* start over from beginning(?) */ 165 outbuf -= len; 166 len = 0; 167 break; 168 169 case ISO_SUSP_CFLAG_VOLROOT: 170 /* Inserting a mount point i.e. "/cdrom" */ 171 /* same as above */ 172 outbuf -= len; 173 len = 0; 174 inbuf = ana->imp->im_mountp->mnt_stat.f_mntonname; 175 wlen = strlen(inbuf); 176 break; 177 178 case ISO_SUSP_CFLAG_HOST: 179 /* Inserting hostname i.e. "kurt.tools.de" */ 180 inbuf = hostname; 181 wlen = strlen(hostname); 182 break; 183 184 case ISO_SUSP_CFLAG_CONTINUE: 185 cont = 1; 186 /* FALLTHROUGH */ 187 case 0: 188 /* Inserting component */ 189 wlen = isonum_711(pcomp->clen); 190 inbuf = pcomp->name; 191 break; 192 default: 193 printf("RRIP with incorrect flags?"); 194 wlen = ana->maxlen + 1; 195 break; 196 } 197 198 if (len + wlen > ana->maxlen) { 199 /* indicate error to caller */ 200 ana->cont = 1; 201 ana->fields = 0; 202 ana->outbuf -= *ana->outlen; 203 *ana->outlen = 0; 204 return 0; 205 } 206 207 bcopy(inbuf,outbuf,wlen); 208 outbuf += wlen; 209 len += wlen; 210 211 } 212 ana->outbuf = outbuf; 213 *ana->outlen = len; 214 ana->cont = cont; 215 216 if (!isonum_711(p->flags)) { 217 ana->fields &= ~ISO_SUSP_SLINK; 218 return ISO_SUSP_SLINK; 219 } 220 return 0; 221 } 222 223 /* 224 * Alternate name 225 */ 226 static int 227 cd9660_rrip_altname(p,ana) 228 ISO_RRIP_ALTNAME *p; 229 ISO_RRIP_ANALYZE *ana; 230 { 231 char *inbuf; 232 int wlen; 233 int cont; 234 235 inbuf = ".."; 236 wlen = 0; 237 cont = 0; 238 239 switch (*p->flags) { 240 case ISO_SUSP_CFLAG_CURRENT: 241 /* Inserting Current */ 242 wlen = 1; 243 break; 244 245 case ISO_SUSP_CFLAG_PARENT: 246 /* Inserting Parent */ 247 wlen = 2; 248 break; 249 250 case ISO_SUSP_CFLAG_HOST: 251 /* Inserting hostname i.e. "kurt.tools.de" */ 252 inbuf = hostname; 253 wlen = strlen(hostname); 254 break; 255 256 case ISO_SUSP_CFLAG_CONTINUE: 257 cont = 1; 258 /* FALLTHROUGH */ 259 case 0: 260 /* Inserting component */ 261 wlen = isonum_711(p->h.length) - 5; 262 inbuf = (char *)p + 5; 263 break; 264 265 default: 266 printf("RRIP with incorrect NM flags?\n"); 267 wlen = ana->maxlen + 1; 268 break; 269 } 270 271 if ((*ana->outlen += wlen) > ana->maxlen) { 272 /* treat as no name field */ 273 ana->fields &= ~ISO_SUSP_ALTNAME; 274 ana->outbuf -= *ana->outlen - wlen; 275 *ana->outlen = 0; 276 return 0; 277 } 278 279 bcopy(inbuf,ana->outbuf,wlen); 280 ana->outbuf += wlen; 281 282 if (!cont) { 283 ana->fields &= ~ISO_SUSP_ALTNAME; 284 return ISO_SUSP_ALTNAME; 285 } 286 return 0; 287 } 288 289 static void 290 cd9660_rrip_defname(isodir,ana) 291 struct iso_directory_record *isodir; 292 ISO_RRIP_ANALYZE *ana; 293 { 294 isofntrans(isodir->name,isonum_711(isodir->name_len), 295 ana->outbuf,ana->outlen, 296 1,isonum_711(isodir->flags)&4, ana->imp->joliet_level); 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 = makeudev(umajor(low), uminor(low)); 420 else 421 ana->inop->inode.iso_rdev = makeudev(high, uminor(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) 477 || isonum_711(p->version) != 1) 478 return 0; 479 ana->fields &= ~ISO_SUSP_EXTREF; 480 return ISO_SUSP_EXTREF; 481 } 482 483 static int 484 cd9660_rrip_loop(isodir,ana,table) 485 struct iso_directory_record *isodir; 486 ISO_RRIP_ANALYZE *ana; 487 RRIP_TABLE *table; 488 { 489 register RRIP_TABLE *ptable; 490 register ISO_SUSP_HEADER *phead; 491 register ISO_SUSP_HEADER *pend; 492 struct buf *bp = NULL; 493 char *pwhead; 494 u_char c; 495 int result; 496 497 /* 498 * Note: If name length is odd, 499 * it will be padding 1 byte after the name 500 */ 501 pwhead = isodir->name + isonum_711(isodir->name_len); 502 if (!(isonum_711(isodir->name_len)&1)) 503 pwhead++; 504 isochar(isodir->name, pwhead, ana->imp->joliet_level, &c); 505 506 /* If it's not the '.' entry of the root dir obey SP field */ 507 if (c != 0 || isonum_733(isodir->extent) != ana->imp->root_extent) 508 pwhead += ana->imp->rr_skip; 509 else 510 pwhead += ana->imp->rr_skip0; 511 512 phead = (ISO_SUSP_HEADER *)pwhead; 513 pend = (ISO_SUSP_HEADER *)((char *)isodir + isonum_711(isodir->length)); 514 515 result = 0; 516 while (1) { 517 ana->iso_ce_len = 0; 518 /* 519 * Note: "pend" should be more than one SUSP header 520 */ 521 while (pend >= phead + 1) { 522 if (isonum_711(phead->version) == 1) { 523 for (ptable = table; ptable->func; ptable++) { 524 if (*phead->type == *ptable->type 525 && phead->type[1] == ptable->type[1]) { 526 result |= ptable->func(phead,ana); 527 break; 528 } 529 } 530 if (!ana->fields) 531 break; 532 } 533 if (result&ISO_SUSP_STOP) { 534 result &= ~ISO_SUSP_STOP; 535 break; 536 } 537 /* plausibility check */ 538 if (isonum_711(phead->length) < sizeof(*phead)) 539 break; 540 /* 541 * move to next SUSP 542 * Hopefully this works with newer versions, too 543 */ 544 phead = (ISO_SUSP_HEADER *)((char *)phead + isonum_711(phead->length)); 545 } 546 547 if (ana->fields && ana->iso_ce_len) { 548 if (ana->iso_ce_blk >= ana->imp->volume_space_size 549 || ana->iso_ce_off + ana->iso_ce_len > ana->imp->logical_block_size 550 || bread(ana->imp->im_devvp, 551 ana->iso_ce_blk << 552 (ana->imp->im_bshift - DEV_BSHIFT), 553 ana->imp->logical_block_size, NOCRED, &bp)) 554 /* what to do now? */ 555 break; 556 phead = (ISO_SUSP_HEADER *)(bp->b_data + ana->iso_ce_off); 557 pend = (ISO_SUSP_HEADER *) ((char *)phead + ana->iso_ce_len); 558 } else 559 break; 560 } 561 if (bp) 562 brelse(bp); 563 /* 564 * If we don't find the Basic SUSP stuffs, just set default value 565 * (attribute/time stamp) 566 */ 567 for (ptable = table; ptable->func2; ptable++) 568 if (!(ptable->result&result)) 569 ptable->func2(isodir,ana); 570 571 return result; 572 } 573 574 /* 575 * Get Attributes. 576 */ 577 /* 578 * XXX the casts are bogus but will do for now. 579 */ 580 #define BC (rrt_func_t *) 581 static RRIP_TABLE rrip_table_analyze[] = { 582 { "PX", BC cd9660_rrip_attr, cd9660_rrip_defattr, ISO_SUSP_ATTR }, 583 { "TF", BC cd9660_rrip_tstamp, cd9660_rrip_deftstamp, ISO_SUSP_TSTAMP }, 584 { "PN", BC cd9660_rrip_device, 0, ISO_SUSP_DEVICE }, 585 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG }, 586 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT }, 587 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP }, 588 { "", 0, 0, 0 } 589 }; 590 591 int 592 cd9660_rrip_analyze(isodir,inop,imp) 593 struct iso_directory_record *isodir; 594 struct iso_node *inop; 595 struct iso_mnt *imp; 596 { 597 ISO_RRIP_ANALYZE analyze; 598 599 analyze.inop = inop; 600 analyze.imp = imp; 601 analyze.fields = ISO_SUSP_ATTR|ISO_SUSP_TSTAMP|ISO_SUSP_DEVICE; 602 603 return cd9660_rrip_loop(isodir,&analyze,rrip_table_analyze); 604 } 605 606 /* 607 * Get Alternate Name. 608 */ 609 static RRIP_TABLE rrip_table_getname[] = { 610 { "NM", BC cd9660_rrip_altname, cd9660_rrip_defname, ISO_SUSP_ALTNAME }, 611 { "CL", BC cd9660_rrip_pclink, 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK }, 612 { "PL", BC cd9660_rrip_pclink, 0, ISO_SUSP_CLINK|ISO_SUSP_PLINK }, 613 { "RE", BC cd9660_rrip_reldir, 0, ISO_SUSP_RELDIR }, 614 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG }, 615 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT }, 616 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP }, 617 { "", 0, 0, 0 } 618 }; 619 620 int 621 cd9660_rrip_getname(isodir,outbuf,outlen,inump,imp) 622 struct iso_directory_record *isodir; 623 char *outbuf; 624 u_short *outlen; 625 ino_t *inump; 626 struct iso_mnt *imp; 627 { 628 ISO_RRIP_ANALYZE analyze; 629 RRIP_TABLE *tab; 630 u_char c; 631 632 analyze.outbuf = outbuf; 633 analyze.outlen = outlen; 634 analyze.maxlen = NAME_MAX; 635 analyze.inump = inump; 636 analyze.imp = imp; 637 analyze.fields = ISO_SUSP_ALTNAME|ISO_SUSP_RELDIR|ISO_SUSP_CLINK|ISO_SUSP_PLINK; 638 *outlen = 0; 639 640 isochar(isodir->name, isodir->name + isonum_711(isodir->name_len), 641 imp->joliet_level, &c); 642 tab = rrip_table_getname; 643 if (c == 0 || c == 1) { 644 cd9660_rrip_defname(isodir,&analyze); 645 646 analyze.fields &= ~ISO_SUSP_ALTNAME; 647 tab++; 648 } 649 650 return cd9660_rrip_loop(isodir,&analyze,tab); 651 } 652 653 /* 654 * Get Symbolic Link. 655 */ 656 static RRIP_TABLE rrip_table_getsymname[] = { 657 { "SL", BC cd9660_rrip_slink, 0, ISO_SUSP_SLINK }, 658 { "RR", BC cd9660_rrip_idflag, 0, ISO_SUSP_IDFLAG }, 659 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT }, 660 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP }, 661 { "", 0, 0, 0 } 662 }; 663 664 int 665 cd9660_rrip_getsymname(isodir,outbuf,outlen,imp) 666 struct iso_directory_record *isodir; 667 char *outbuf; 668 u_short *outlen; 669 struct iso_mnt *imp; 670 { 671 ISO_RRIP_ANALYZE analyze; 672 673 analyze.outbuf = outbuf; 674 analyze.outlen = outlen; 675 *outlen = 0; 676 analyze.maxlen = MAXPATHLEN; 677 analyze.cont = 1; /* don't start with a slash */ 678 analyze.imp = imp; 679 analyze.fields = ISO_SUSP_SLINK; 680 681 return (cd9660_rrip_loop(isodir,&analyze,rrip_table_getsymname)&ISO_SUSP_SLINK); 682 } 683 684 static RRIP_TABLE rrip_table_extref[] = { 685 { "ER", BC cd9660_rrip_extref, 0, ISO_SUSP_EXTREF }, 686 { "CE", BC cd9660_rrip_cont, 0, ISO_SUSP_CONT }, 687 { "ST", BC cd9660_rrip_stop, 0, ISO_SUSP_STOP }, 688 { "", 0, 0, 0 } 689 }; 690 691 /* 692 * Check for Rock Ridge Extension and return offset of its fields. 693 * Note: We insist on the ER field. 694 */ 695 int 696 cd9660_rrip_offset(isodir,imp) 697 struct iso_directory_record *isodir; 698 struct iso_mnt *imp; 699 { 700 ISO_RRIP_OFFSET *p; 701 ISO_RRIP_ANALYZE analyze; 702 703 imp->rr_skip0 = 0; 704 p = (ISO_RRIP_OFFSET *)(isodir->name + 1); 705 if (bcmp(p,"SP\7\1\276\357",6)) { 706 /* Maybe, it's a CDROM XA disc? */ 707 imp->rr_skip0 = 15; 708 p = (ISO_RRIP_OFFSET *)((char *)p + 15); 709 if (bcmp(p,"SP\7\1\276\357",6)) 710 return -1; 711 } 712 713 analyze.imp = imp; 714 analyze.fields = ISO_SUSP_EXTREF; 715 if (!(cd9660_rrip_loop(isodir,&analyze,rrip_table_extref)&ISO_SUSP_EXTREF)) 716 return -1; 717 718 return isonum_711(p->skip); 719 } 720