2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* $NetBSD: cd9660_rrip.c,v 1.11 1994/12/24 15:30:10 cgd Exp $ */
25 * Copyright (c) 1993, 1994
26 * The Regents of the University of California. All rights reserved.
28 * This code is derived from software contributed to Berkeley
29 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
30 * Support code is derived from software contributed to Berkeley
31 * by Atsushi Murai (amurai@spec.co.jp).
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)cd9660_rrip.c 8.6 (Berkeley) 12/5/94
66 * 22-Jan-98 radar 1669467 - ISO 9660 CD support - jwc
70 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/vnode.h>
73 #include <sys/mount.h>
74 #include <sys/namei.h>
77 #include <sys/kernel.h>
79 #include <sys/types.h>
83 #include <isofs/cd9660/iso.h>
84 #include <isofs/cd9660/cd9660_node.h>
85 #include <isofs/cd9660/cd9660_rrip.h>
86 #include <isofs/cd9660/iso_rrip.h>
89 * POSIX file attribute
92 cd9660_rrip_attr(p
,ana
)
94 ISO_RRIP_ANALYZE
*ana
;
96 ana
->inop
->inode
.iso_mode
= isonum_733(p
->mode
);
97 ana
->inop
->inode
.iso_uid
= isonum_733(p
->uid
);
98 ana
->inop
->inode
.iso_gid
= isonum_733(p
->gid
);
99 ana
->inop
->inode
.iso_links
= isonum_733(p
->links
);
100 ana
->fields
&= ~ISO_SUSP_ATTR
;
101 return ISO_SUSP_ATTR
;
105 cd9660_rrip_defattr(isodir
,ana
)
106 struct iso_directory_record
*isodir
;
107 ISO_RRIP_ANALYZE
*ana
;
109 /* But this is a required field! */
110 printf("RRIP without PX field?\n");
111 cd9660_defattr(isodir
,ana
->inop
,NULL
);
118 cd9660_rrip_slink(p
,ana
)
120 ISO_RRIP_ANALYZE
*ana
;
122 register ISO_RRIP_SLINK_COMPONENT
*pcomp
;
123 register ISO_RRIP_SLINK_COMPONENT
*pcompe
;
125 char *outbuf
, *inbuf
;
127 pcomp
= (ISO_RRIP_SLINK_COMPONENT
*)p
->component
;
128 pcompe
= (ISO_RRIP_SLINK_COMPONENT
*)((char *)p
+ isonum_711(p
->h
.length
));
130 outbuf
= ana
->outbuf
;
134 * Gathering a Symbolic name from each component with path
138 pcomp
= (ISO_RRIP_SLINK_COMPONENT
*)((char *)pcomp
+ ISO_RRIP_SLSIZ
139 + isonum_711(pcomp
->clen
))) {
142 if (len
< ana
->maxlen
) {
152 switch (*pcomp
->cflag
) {
154 case ISO_SUSP_CFLAG_CURRENT
:
155 /* Inserting Current */
159 case ISO_SUSP_CFLAG_PARENT
:
160 /* Inserting Parent */
164 case ISO_SUSP_CFLAG_ROOT
:
165 /* Inserting slash for ROOT */
166 /* start over from beginning(?) */
171 case ISO_SUSP_CFLAG_VOLROOT
:
172 /* Inserting a mount point i.e. "/cdrom" */
176 inbuf
= ana
->imp
->im_mountp
->mnt_stat
.f_mntonname
;
177 wlen
= strlen(inbuf
);
180 case ISO_SUSP_CFLAG_HOST
:
181 /* Inserting hostname i.e. "kurt.tools.de" */
186 case ISO_SUSP_CFLAG_CONTINUE
:
190 /* Inserting component */
191 wlen
= isonum_711(pcomp
->clen
);
195 printf("RRIP with incorrect flags?");
196 wlen
= ana
->maxlen
+ 1;
200 if (len
+ wlen
> ana
->maxlen
) {
201 /* indicate error to caller */
204 ana
->outbuf
-= *ana
->outlen
;
209 bcopy(inbuf
,outbuf
,wlen
);
214 ana
->outbuf
= outbuf
;
218 if (!isonum_711(p
->flags
)) {
219 ana
->fields
&= ~ISO_SUSP_SLINK
;
220 return ISO_SUSP_SLINK
;
229 cd9660_rrip_altname(p
,ana
)
231 ISO_RRIP_ANALYZE
*ana
;
242 case ISO_SUSP_CFLAG_CURRENT
:
243 /* Inserting Current */
247 case ISO_SUSP_CFLAG_PARENT
:
248 /* Inserting Parent */
252 case ISO_SUSP_CFLAG_HOST
:
253 /* Inserting hostname i.e. "kurt.tools.de" */
258 case ISO_SUSP_CFLAG_CONTINUE
:
262 /* Inserting component */
263 wlen
= isonum_711(p
->h
.length
) - 5;
264 inbuf
= (char *)p
+ 5;
268 printf("RRIP with incorrect NM flags?\n");
269 wlen
= ana
->maxlen
+ 1;
273 if ((*ana
->outlen
+= wlen
) > ana
->maxlen
) {
274 /* treat as no name field */
275 ana
->fields
&= ~ISO_SUSP_ALTNAME
;
276 ana
->outbuf
-= *ana
->outlen
- wlen
;
281 bcopy(inbuf
,ana
->outbuf
,wlen
);
285 ana
->fields
&= ~ISO_SUSP_ALTNAME
;
286 return ISO_SUSP_ALTNAME
;
292 cd9660_rrip_defname(isodir
,ana
)
293 struct iso_directory_record
*isodir
;
294 ISO_RRIP_ANALYZE
*ana
;
296 strcpy(ana
->outbuf
,"..");
297 switch (*isodir
->name
) {
299 isofntrans(isodir
->name
, isonum_711(isodir
->name_len
),
300 ana
->outbuf
, ana
->outlen
, 1);
312 * Parent or Child Link
315 cd9660_rrip_pclink(p
,ana
)
317 ISO_RRIP_ANALYZE
*ana
;
319 *ana
->inump
= isonum_733(p
->dir_loc
) << ana
->imp
->im_bshift
;
320 ana
->fields
&= ~(ISO_SUSP_CLINK
|ISO_SUSP_PLINK
);
321 return *p
->h
.type
== 'C' ? ISO_SUSP_CLINK
: ISO_SUSP_PLINK
;
325 * Relocated directory
328 cd9660_rrip_reldir(p
,ana
)
330 ISO_RRIP_ANALYZE
*ana
;
332 /* special hack to make caller aware of RE field */
335 return ISO_SUSP_RELDIR
|ISO_SUSP_ALTNAME
|ISO_SUSP_CLINK
|ISO_SUSP_PLINK
;
339 cd9660_rrip_tstamp(p
,ana
)
341 ISO_RRIP_ANALYZE
*ana
;
347 /* Check a format of time stamp (7bytes/17bytes) */
348 if (!(*p
->flags
&ISO_SUSP_TSTAMP_FORM17
)) {
349 if (*p
->flags
&ISO_SUSP_TSTAMP_CREAT
)
352 if (*p
->flags
&ISO_SUSP_TSTAMP_MODIFY
) {
353 cd9660_tstamp_conv7(ptime
,&ana
->inop
->inode
.iso_mtime
);
356 bzero(&ana
->inop
->inode
.iso_mtime
,sizeof(struct timespec
));
358 if (*p
->flags
&ISO_SUSP_TSTAMP_ACCESS
) {
359 cd9660_tstamp_conv7(ptime
,&ana
->inop
->inode
.iso_atime
);
362 ana
->inop
->inode
.iso_atime
= ana
->inop
->inode
.iso_mtime
;
364 if (*p
->flags
&ISO_SUSP_TSTAMP_ATTR
)
365 cd9660_tstamp_conv7(ptime
,&ana
->inop
->inode
.iso_ctime
);
367 ana
->inop
->inode
.iso_ctime
= ana
->inop
->inode
.iso_mtime
;
370 if (*p
->flags
&ISO_SUSP_TSTAMP_CREAT
)
373 if (*p
->flags
&ISO_SUSP_TSTAMP_MODIFY
) {
374 cd9660_tstamp_conv17(ptime
,&ana
->inop
->inode
.iso_mtime
);
377 bzero(&ana
->inop
->inode
.iso_mtime
,sizeof(struct timespec
));
379 if (*p
->flags
&ISO_SUSP_TSTAMP_ACCESS
) {
380 cd9660_tstamp_conv17(ptime
,&ana
->inop
->inode
.iso_atime
);
383 ana
->inop
->inode
.iso_atime
= ana
->inop
->inode
.iso_mtime
;
385 if (*p
->flags
&ISO_SUSP_TSTAMP_ATTR
)
386 cd9660_tstamp_conv17(ptime
,&ana
->inop
->inode
.iso_ctime
);
388 ana
->inop
->inode
.iso_ctime
= ana
->inop
->inode
.iso_mtime
;
391 ana
->fields
&= ~ISO_SUSP_TSTAMP
;
392 return ISO_SUSP_TSTAMP
;
396 cd9660_rrip_deftstamp(isodir
,ana
)
397 struct iso_directory_record
*isodir
;
398 ISO_RRIP_ANALYZE
*ana
;
400 cd9660_deftstamp(isodir
,ana
->inop
,NULL
);
407 cd9660_rrip_device(p
,ana
)
409 ISO_RRIP_ANALYZE
*ana
;
413 high
= isonum_733(p
->dev_t_high
);
414 low
= isonum_733(p
->dev_t_low
);
417 ana
->inop
->inode
.iso_rdev
= makedev(major(low
), minor(low
));
419 ana
->inop
->inode
.iso_rdev
= makedev(high
, minor(low
));
420 ana
->fields
&= ~ISO_SUSP_DEVICE
;
421 return ISO_SUSP_DEVICE
;
428 cd9660_rrip_idflag(p
,ana
)
430 ISO_RRIP_ANALYZE
*ana
;
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(p
,ana
);
437 return ISO_SUSP_IDFLAG
;
441 * Continuation pointer
444 cd9660_rrip_cont(p
,ana
)
446 ISO_RRIP_ANALYZE
*ana
;
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
;
458 cd9660_rrip_stop(p
,ana
)
460 ISO_RRIP_ANALYZE
*ana
;
462 return ISO_SUSP_STOP
;
466 * Extension reference
469 cd9660_rrip_extref(p
,ana
)
471 ISO_RRIP_ANALYZE
*ana
;
473 if (isonum_711(p
->len_id
) != 10
474 || bcmp((char *)p
+ 8,"RRIP_1991A",10)
475 || isonum_711(p
->version
) != 1)
477 ana
->fields
&= ~ISO_SUSP_EXTREF
;
478 return ISO_SUSP_EXTREF
;
489 cd9660_rrip_loop(isodir
,ana
,table
)
490 struct iso_directory_record
*isodir
;
491 ISO_RRIP_ANALYZE
*ana
;
494 register RRIP_TABLE
*ptable
;
495 register ISO_SUSP_HEADER
*phead
;
496 register ISO_SUSP_HEADER
*pend
;
497 struct buf
*bp
= NULL
;
502 * Note: If name length is odd,
503 * it will be padding 1 byte after the name
505 pwhead
= isodir
->name
+ isonum_711(isodir
->name_len
);
506 if (!(isonum_711(isodir
->name_len
)&1))
509 /* If it's not the '.' entry of the root dir obey SP field */
510 if (*isodir
->name
!= 0
511 || isonum_733(isodir
->extent
) != ana
->imp
->root_extent
)
512 pwhead
+= ana
->imp
->rr_skip
;
514 pwhead
+= ana
->imp
->rr_skip0
;
516 phead
= (ISO_SUSP_HEADER
*)pwhead
;
517 pend
= (ISO_SUSP_HEADER
*)((char *)isodir
+ isonum_711(isodir
->length
));
523 * Note: "pend" should be more than one SUSP header
525 while (pend
>= phead
+ 1) {
526 if (isonum_711(phead
->version
) == 1) {
527 for (ptable
= table
; ptable
->func
; ptable
++) {
528 if (*phead
->type
== *ptable
->type
529 && phead
->type
[1] == ptable
->type
[1]) {
530 result
|= ptable
->func(phead
,ana
);
537 if (result
&ISO_SUSP_STOP
) {
538 result
&= ~ISO_SUSP_STOP
;
541 /* plausibility check */
542 if (isonum_711(phead
->length
) < sizeof(*phead
))
546 * Hopefully this works with newer versions, too
548 phead
= (ISO_SUSP_HEADER
*)((char *)phead
+ isonum_711(phead
->length
));
551 if (ana
->fields
&& ana
->iso_ce_len
) {
552 if (ana
->iso_ce_blk
>= ana
->imp
->volume_space_size
553 || ana
->iso_ce_off
+ ana
->iso_ce_len
> ana
->imp
->logical_block_size
554 || bread(ana
->imp
->im_devvp
,
555 #if 1 // radar 1669467 - logical and physical blocksize are the same
558 ana
->iso_ce_blk
<< (ana
->imp
->im_bshift
- DEV_BSHIFT
),
559 #endif // radar 1669467
560 ana
->imp
->logical_block_size
, NOCRED
, &bp
))
561 /* what to do now? */
563 phead
= (ISO_SUSP_HEADER
*)(bp
->b_data
+ ana
->iso_ce_off
);
564 pend
= (ISO_SUSP_HEADER
*) ((char *)phead
+ ana
->iso_ce_len
);
571 * If we don't find the Basic SUSP stuffs, just set default value
572 * (attribute/time stamp)
574 for (ptable
= table
; ptable
->func2
; ptable
++)
575 if (!(ptable
->result
&result
))
576 ptable
->func2(isodir
,ana
);
584 static RRIP_TABLE rrip_table_analyze
[] = {
585 { "PX", cd9660_rrip_attr
, cd9660_rrip_defattr
, ISO_SUSP_ATTR
},
586 { "TF", cd9660_rrip_tstamp
, cd9660_rrip_deftstamp
, ISO_SUSP_TSTAMP
},
587 { "PN", cd9660_rrip_device
, 0, ISO_SUSP_DEVICE
},
588 { "RR", cd9660_rrip_idflag
, 0, ISO_SUSP_IDFLAG
},
589 { "CE", cd9660_rrip_cont
, 0, ISO_SUSP_CONT
},
590 { "ST", cd9660_rrip_stop
, 0, ISO_SUSP_STOP
},
595 cd9660_rrip_analyze(isodir
,inop
,imp
)
596 struct iso_directory_record
*isodir
;
597 struct iso_node
*inop
;
600 ISO_RRIP_ANALYZE analyze
;
604 analyze
.fields
= ISO_SUSP_ATTR
|ISO_SUSP_TSTAMP
|ISO_SUSP_DEVICE
;
606 return cd9660_rrip_loop(isodir
,&analyze
,rrip_table_analyze
);
610 * Get Alternate Name.
612 static RRIP_TABLE rrip_table_getname
[] = {
613 { "NM", cd9660_rrip_altname
, cd9660_rrip_defname
, ISO_SUSP_ALTNAME
},
614 { "CL", cd9660_rrip_pclink
, 0, ISO_SUSP_CLINK
|ISO_SUSP_PLINK
},
615 { "PL", cd9660_rrip_pclink
, 0, ISO_SUSP_CLINK
|ISO_SUSP_PLINK
},
616 { "RE", cd9660_rrip_reldir
, 0, ISO_SUSP_RELDIR
},
617 { "RR", cd9660_rrip_idflag
, 0, ISO_SUSP_IDFLAG
},
618 { "CE", cd9660_rrip_cont
, 0, ISO_SUSP_CONT
},
619 { "ST", cd9660_rrip_stop
, 0, ISO_SUSP_STOP
},
624 cd9660_rrip_getname(isodir
,outbuf
,outlen
,inump
,imp
)
625 struct iso_directory_record
*isodir
;
631 ISO_RRIP_ANALYZE analyze
;
634 analyze
.outbuf
= outbuf
;
635 analyze
.outlen
= outlen
;
636 analyze
.maxlen
= ISO_RRIP_NAMEMAX
;
637 analyze
.inump
= inump
;
639 analyze
.fields
= ISO_SUSP_ALTNAME
|ISO_SUSP_RELDIR
|ISO_SUSP_CLINK
|ISO_SUSP_PLINK
;
642 tab
= rrip_table_getname
;
643 if (*isodir
->name
== 0
644 || *isodir
->name
== 1) {
645 cd9660_rrip_defname(isodir
,&analyze
);
647 analyze
.fields
&= ~ISO_SUSP_ALTNAME
;
651 return cd9660_rrip_loop(isodir
,&analyze
,tab
);
657 static RRIP_TABLE rrip_table_getsymname
[] = {
658 { "SL", cd9660_rrip_slink
, 0, ISO_SUSP_SLINK
},
659 { "RR", cd9660_rrip_idflag
, 0, ISO_SUSP_IDFLAG
},
660 { "CE", cd9660_rrip_cont
, 0, ISO_SUSP_CONT
},
661 { "ST", cd9660_rrip_stop
, 0, ISO_SUSP_STOP
},
666 cd9660_rrip_getsymname(isodir
,outbuf
,outlen
,imp
)
667 struct iso_directory_record
*isodir
;
672 ISO_RRIP_ANALYZE analyze
;
674 analyze
.outbuf
= outbuf
;
675 analyze
.outlen
= outlen
;
677 analyze
.maxlen
= MAXPATHLEN
;
678 analyze
.cont
= 1; /* don't start with a slash */
680 analyze
.fields
= ISO_SUSP_SLINK
;
682 return (cd9660_rrip_loop(isodir
,&analyze
,rrip_table_getsymname
)&ISO_SUSP_SLINK
);
685 static RRIP_TABLE rrip_table_extref
[] = {
686 { "ER", cd9660_rrip_extref
, 0, ISO_SUSP_EXTREF
},
687 { "CE", cd9660_rrip_cont
, 0, ISO_SUSP_CONT
},
688 { "ST", cd9660_rrip_stop
, 0, ISO_SUSP_STOP
},
693 * Check for Rock Ridge Extension and return offset of its fields.
694 * Note: We insist on the ER field.
697 cd9660_rrip_offset(isodir
,imp
)
698 struct iso_directory_record
*isodir
;
702 ISO_RRIP_ANALYZE analyze
;
705 p
= (ISO_RRIP_OFFSET
*)(isodir
->name
+ 1);
706 if (bcmp(p
,"SP\7\1\276\357",6)) {
707 /* Maybe, it's a CDROM XA disc? */
709 p
= (ISO_RRIP_OFFSET
*)((char *)p
+ 15);
710 if (bcmp(p
,"SP\7\1\276\357",6))
715 analyze
.fields
= ISO_SUSP_EXTREF
;
716 if (!(cd9660_rrip_loop(isodir
,&analyze
,rrip_table_extref
)&ISO_SUSP_EXTREF
))
719 return isonum_711(p
->skip
);