iso.h revision 45773
11541Srgrimes/*-
21541Srgrimes * Copyright (c) 1994
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley
61541Srgrimes * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
71541Srgrimes * Support code is derived from software contributed to Berkeley
81541Srgrimes * by Atsushi Murai (amurai@spec.co.jp).
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
3822521Sdyson *	@(#)iso.h	8.6 (Berkeley) 5/10/95
3945773Sdcs * $Id: iso.h,v 1.16 1997/05/07 13:23:04 joerg Exp $
401541Srgrimes */
411541Srgrimes
421541Srgrimes#define ISODCL(from, to) (to - from + 1)
431541Srgrimes
441541Srgrimesstruct iso_volume_descriptor {
451541Srgrimes	char type[ISODCL(1,1)]; /* 711 */
461541Srgrimes	char id[ISODCL(2,6)];
471541Srgrimes	char version[ISODCL(7,7)];
485651Sjoerg	char unused[ISODCL(8,8)];
495651Sjoerg	char type_sierra[ISODCL(9,9)]; /* 711 */
505651Sjoerg	char id_sierra[ISODCL(10,14)];
515651Sjoerg	char version_sierra[ISODCL(15,15)];
525651Sjoerg	char data[ISODCL(16,2048)];
531541Srgrimes};
541541Srgrimes
551541Srgrimes/* volume descriptor types */
561541Srgrimes#define ISO_VD_PRIMARY 1
5745773Sdcs#define ISO_VD_SUPPLEMENTARY 2
581541Srgrimes#define ISO_VD_END 255
591541Srgrimes
601541Srgrimes#define ISO_STANDARD_ID "CD001"
615651Sjoerg#define ISO_ECMA_ID	"CDW01"
621541Srgrimes
635651Sjoerg#define ISO_SIERRA_ID	"CDROM"
645651Sjoerg
651541Srgrimesstruct iso_primary_descriptor {
665651Sjoerg	char type			[ISODCL (  1,	1)]; /* 711 */
675651Sjoerg	char id				[ISODCL (  2,	6)];
685651Sjoerg	char version			[ISODCL (  7,	7)]; /* 711 */
695651Sjoerg	char unused1			[ISODCL (  8,	8)];
701541Srgrimes	char system_id			[ISODCL (  9,  40)]; /* achars */
711541Srgrimes	char volume_id			[ISODCL ( 41,  72)]; /* dchars */
721541Srgrimes	char unused2			[ISODCL ( 73,  80)];
731541Srgrimes	char volume_space_size		[ISODCL ( 81,  88)]; /* 733 */
741541Srgrimes	char unused3			[ISODCL ( 89, 120)];
751541Srgrimes	char volume_set_size		[ISODCL (121, 124)]; /* 723 */
761541Srgrimes	char volume_sequence_number	[ISODCL (125, 128)]; /* 723 */
771541Srgrimes	char logical_block_size		[ISODCL (129, 132)]; /* 723 */
781541Srgrimes	char path_table_size		[ISODCL (133, 140)]; /* 733 */
791541Srgrimes	char type_l_path_table		[ISODCL (141, 144)]; /* 731 */
801541Srgrimes	char opt_type_l_path_table	[ISODCL (145, 148)]; /* 731 */
811541Srgrimes	char type_m_path_table		[ISODCL (149, 152)]; /* 732 */
821541Srgrimes	char opt_type_m_path_table	[ISODCL (153, 156)]; /* 732 */
831541Srgrimes	char root_directory_record	[ISODCL (157, 190)]; /* 9.1 */
841541Srgrimes	char volume_set_id		[ISODCL (191, 318)]; /* dchars */
851541Srgrimes	char publisher_id		[ISODCL (319, 446)]; /* achars */
861541Srgrimes	char preparer_id		[ISODCL (447, 574)]; /* achars */
871541Srgrimes	char application_id		[ISODCL (575, 702)]; /* achars */
881541Srgrimes	char copyright_file_id		[ISODCL (703, 739)]; /* 7.5 dchars */
891541Srgrimes	char abstract_file_id		[ISODCL (740, 776)]; /* 7.5 dchars */
901541Srgrimes	char bibliographic_file_id	[ISODCL (777, 813)]; /* 7.5 dchars */
911541Srgrimes	char creation_date		[ISODCL (814, 830)]; /* 8.4.26.1 */
921541Srgrimes	char modification_date		[ISODCL (831, 847)]; /* 8.4.26.1 */
931541Srgrimes	char expiration_date		[ISODCL (848, 864)]; /* 8.4.26.1 */
941541Srgrimes	char effective_date		[ISODCL (865, 881)]; /* 8.4.26.1 */
951541Srgrimes	char file_structure_version	[ISODCL (882, 882)]; /* 711 */
961541Srgrimes	char unused4			[ISODCL (883, 883)];
971541Srgrimes	char application_data		[ISODCL (884, 1395)];
981541Srgrimes	char unused5			[ISODCL (1396, 2048)];
991541Srgrimes};
1001541Srgrimes#define ISO_DEFAULT_BLOCK_SIZE		2048
1011541Srgrimes
10245773Sdcs/*
10345773Sdcs * Used by Microsoft Joliet extension to ISO9660. Almost the same
10445773Sdcs * as PVD, but byte position 8 is a flag, and 89-120 is for escape.
10545773Sdcs */
10645773Sdcs
10745773Sdcsstruct iso_supplementary_descriptor {
10845773Sdcs      char type                       [ISODCL (  1,   1)]; /* 711 */
10945773Sdcs      char id                         [ISODCL (  2,   6)];
11045773Sdcs      char version                    [ISODCL (  7,   7)]; /* 711 */
11145773Sdcs      char flags                      [ISODCL (  8,   8)]; /* 711? */
11245773Sdcs      char system_id                  [ISODCL (  9,  40)]; /* achars */
11345773Sdcs      char volume_id                  [ISODCL ( 41,  72)]; /* dchars */
11445773Sdcs      char unused2                    [ISODCL ( 73,  80)];
11545773Sdcs      char volume_space_size          [ISODCL ( 81,  88)]; /* 733 */
11645773Sdcs      char escape                     [ISODCL ( 89, 120)];
11745773Sdcs      char volume_set_size            [ISODCL (121, 124)]; /* 723 */
11845773Sdcs      char volume_sequence_number     [ISODCL (125, 128)]; /* 723 */
11945773Sdcs      char logical_block_size         [ISODCL (129, 132)]; /* 723 */
12045773Sdcs      char path_table_size            [ISODCL (133, 140)]; /* 733 */
12145773Sdcs      char type_l_path_table          [ISODCL (141, 144)]; /* 731 */
12245773Sdcs      char opt_type_l_path_table      [ISODCL (145, 148)]; /* 731 */
12345773Sdcs      char type_m_path_table          [ISODCL (149, 152)]; /* 732 */
12445773Sdcs      char opt_type_m_path_table      [ISODCL (153, 156)]; /* 732 */
12545773Sdcs      char root_directory_record      [ISODCL (157, 190)]; /* 9.1 */
12645773Sdcs      char volume_set_id              [ISODCL (191, 318)]; /* dchars */
12745773Sdcs      char publisher_id               [ISODCL (319, 446)]; /* achars */
12845773Sdcs      char preparer_id                [ISODCL (447, 574)]; /* achars */
12945773Sdcs      char application_id             [ISODCL (575, 702)]; /* achars */
13045773Sdcs      char copyright_file_id          [ISODCL (703, 739)]; /* 7.5 dchars */
13145773Sdcs      char abstract_file_id           [ISODCL (740, 776)]; /* 7.5 dchars */
13245773Sdcs      char bibliographic_file_id      [ISODCL (777, 813)]; /* 7.5 dchars */
13345773Sdcs      char creation_date              [ISODCL (814, 830)]; /* 8.4.26.1 */
13445773Sdcs      char modification_date          [ISODCL (831, 847)]; /* 8.4.26.1 */
13545773Sdcs      char expiration_date            [ISODCL (848, 864)]; /* 8.4.26.1 */
13645773Sdcs      char effective_date             [ISODCL (865, 881)]; /* 8.4.26.1 */
13745773Sdcs      char file_structure_version     [ISODCL (882, 882)]; /* 711 */
13845773Sdcs      char unused4                    [ISODCL (883, 883)];
13945773Sdcs      char application_data           [ISODCL (884, 1395)];
14045773Sdcs      char unused5                    [ISODCL (1396, 2048)];
14145773Sdcs};
14245773Sdcs
1435651Sjoergstruct iso_sierra_primary_descriptor {
1445651Sjoerg	char unknown1			[ISODCL (  1,	8)]; /* 733 */
1455651Sjoerg	char type			[ISODCL (  9,	9)]; /* 711 */
1465651Sjoerg	char id				[ISODCL ( 10,  14)];
1475651Sjoerg	char version			[ISODCL ( 15,  15)]; /* 711 */
1485651Sjoerg	char unused1			[ISODCL ( 16,  16)];
1495651Sjoerg	char system_id			[ISODCL ( 17,  48)]; /* achars */
1505651Sjoerg	char volume_id			[ISODCL ( 49,  80)]; /* dchars */
1515651Sjoerg	char unused2			[ISODCL ( 81,  88)];
1525651Sjoerg	char volume_space_size		[ISODCL ( 89,  96)]; /* 733 */
1535651Sjoerg	char unused3			[ISODCL ( 97, 128)];
1545651Sjoerg	char volume_set_size		[ISODCL (129, 132)]; /* 723 */
1555651Sjoerg	char volume_sequence_number	[ISODCL (133, 136)]; /* 723 */
1565651Sjoerg	char logical_block_size		[ISODCL (137, 140)]; /* 723 */
1575651Sjoerg	char path_table_size		[ISODCL (141, 148)]; /* 733 */
1585651Sjoerg	char type_l_path_table		[ISODCL (149, 152)]; /* 731 */
1595651Sjoerg	char opt_type_l_path_table	[ISODCL (153, 156)]; /* 731 */
1605651Sjoerg	char unknown2			[ISODCL (157, 160)]; /* 731 */
1615651Sjoerg	char unknown3			[ISODCL (161, 164)]; /* 731 */
1625651Sjoerg	char type_m_path_table		[ISODCL (165, 168)]; /* 732 */
1635651Sjoerg	char opt_type_m_path_table	[ISODCL (169, 172)]; /* 732 */
1645651Sjoerg	char unknown4			[ISODCL (173, 176)]; /* 732 */
1655651Sjoerg	char unknown5			[ISODCL (177, 180)]; /* 732 */
1665651Sjoerg	char root_directory_record	[ISODCL (181, 214)]; /* 9.1 */
1675651Sjoerg	char volume_set_id		[ISODCL (215, 342)]; /* dchars */
1685651Sjoerg	char publisher_id		[ISODCL (343, 470)]; /* achars */
1695651Sjoerg	char preparer_id		[ISODCL (471, 598)]; /* achars */
1705651Sjoerg	char application_id		[ISODCL (599, 726)]; /* achars */
1715651Sjoerg	char copyright_id		[ISODCL (727, 790)]; /* achars */
1725651Sjoerg	char creation_date		[ISODCL (791, 806)]; /* ? */
1735651Sjoerg	char modification_date		[ISODCL (807, 822)]; /* ? */
1745651Sjoerg	char expiration_date		[ISODCL (823, 838)]; /* ? */
1755651Sjoerg	char effective_date		[ISODCL (839, 854)]; /* ? */
1765651Sjoerg	char file_structure_version	[ISODCL (855, 855)]; /* 711 */
1775651Sjoerg	char unused4			[ISODCL (856, 2048)];
1785651Sjoerg};
1795651Sjoerg
1801541Srgrimesstruct iso_directory_record {
1811541Srgrimes	char length			[ISODCL (1, 1)]; /* 711 */
1821541Srgrimes	char ext_attr_length		[ISODCL (2, 2)]; /* 711 */
18322521Sdyson	u_char extent			[ISODCL (3, 10)]; /* 733 */
18422521Sdyson	u_char size			[ISODCL (11, 18)]; /* 733 */
1851541Srgrimes	char date			[ISODCL (19, 25)]; /* 7 by 711 */
1861541Srgrimes	char flags			[ISODCL (26, 26)];
1871541Srgrimes	char file_unit_size		[ISODCL (27, 27)]; /* 711 */
1881541Srgrimes	char interleave			[ISODCL (28, 28)]; /* 711 */
1891541Srgrimes	char volume_sequence_number	[ISODCL (29, 32)]; /* 723 */
1901541Srgrimes	char name_len			[ISODCL (33, 33)]; /* 711 */
19122521Sdyson	char name			[1];			/* XXX */
1921541Srgrimes};
1931541Srgrimes/* can't take sizeof(iso_directory_record), because of possible alignment
1941541Srgrimes   of the last entry (34 instead of 33) */
1951541Srgrimes#define ISO_DIRECTORY_RECORD_SIZE	33
1961541Srgrimes
1971541Srgrimesstruct iso_extended_attributes {
19822521Sdyson	u_char owner			[ISODCL (1, 4)]; /* 723 */
19922521Sdyson	u_char group			[ISODCL (5, 8)]; /* 723 */
20022521Sdyson	u_char perm			[ISODCL (9, 10)]; /* 9.5.3 */
2011541Srgrimes	char ctime			[ISODCL (11, 27)]; /* 8.4.26.1 */
2021541Srgrimes	char mtime			[ISODCL (28, 44)]; /* 8.4.26.1 */
2031541Srgrimes	char xtime			[ISODCL (45, 61)]; /* 8.4.26.1 */
2041541Srgrimes	char ftime			[ISODCL (62, 78)]; /* 8.4.26.1 */
2051541Srgrimes	char recfmt			[ISODCL (79, 79)]; /* 711 */
2061541Srgrimes	char recattr			[ISODCL (80, 80)]; /* 711 */
20722521Sdyson	u_char reclen			[ISODCL (81, 84)]; /* 723 */
2081541Srgrimes	char system_id			[ISODCL (85, 116)]; /* achars */
2091541Srgrimes	char system_use			[ISODCL (117, 180)];
2101541Srgrimes	char version			[ISODCL (181, 181)]; /* 711 */
2111541Srgrimes	char len_esc			[ISODCL (182, 182)]; /* 711 */
2121541Srgrimes	char reserved			[ISODCL (183, 246)];
21322521Sdyson	u_char len_au			[ISODCL (247, 250)]; /* 723 */
2141541Srgrimes};
2151541Srgrimes
21625531Sjoerg#ifdef KERNEL
21725531Sjoerg
2181541Srgrimes/* CD-ROM Format type */
2195651Sjoergenum ISO_FTYPE	{ ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP,
22045773Sdcs		  ISO_FTYPE_JOLIET, ISO_FTYPE_ECMA, ISO_FTYPE_HIGH_SIERRA };
2211541Srgrimes
2221541Srgrimes#ifndef	ISOFSMNT_ROOT
2231541Srgrimes#define	ISOFSMNT_ROOT	0
2241541Srgrimes#endif
2251541Srgrimes
2261541Srgrimesstruct iso_mnt {
2271541Srgrimes	int im_flags;
2281541Srgrimes
2291541Srgrimes	struct mount *im_mountp;
2301541Srgrimes	dev_t im_dev;
2311541Srgrimes	struct vnode *im_devvp;
2321541Srgrimes
2331541Srgrimes	int logical_block_size;
2341541Srgrimes	int im_bshift;
2351541Srgrimes	int im_bmask;
2368876Srgrimes
2371541Srgrimes	int volume_space_size;
2381541Srgrimes	struct netexport im_export;
2398876Srgrimes
2401541Srgrimes	char root[ISODCL (157, 190)];
2411541Srgrimes	int root_extent;
2421541Srgrimes	int root_size;
2435651Sjoerg	enum ISO_FTYPE	iso_ftype;
2448876Srgrimes
2451541Srgrimes	int rr_skip;
2461541Srgrimes	int rr_skip0;
24745773Sdcs
24845773Sdcs	int joliet_level;
2491541Srgrimes};
2501541Srgrimes
2511541Srgrimes#define VFSTOISOFS(mp)	((struct iso_mnt *)((mp)->mnt_data))
2521541Srgrimes
25322521Sdyson#define blkoff(imp, loc)	((loc) & (imp)->im_bmask)
25422521Sdyson#define lblktosize(imp, blk)	((blk) << (imp)->im_bshift)
25522521Sdyson#define lblkno(imp, loc)	((loc) >> (imp)->im_bshift)
25622521Sdyson#define blksize(imp, ip, lbn)	((imp)->logical_block_size)
2571541Srgrimes
25822521Sdysonint cd9660_vget_internal __P((struct mount *, ino_t, struct vnode **, int,
25922521Sdyson			      struct iso_directory_record *));
26022521Sdysonint cd9660_init __P((struct vfsconf *));
26122521Sdyson#define cd9660_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
26222521Sdyson                                    size_t, struct proc *)))eopnotsupp)
2631541Srgrimes
26412158Sbdeextern vop_t **cd9660_vnodeop_p;
26522521Sdysonextern vop_t **cd9660_specop_p;
26622521Sdysonextern vop_t **cd9660_fifoop_p;
2671541Srgrimes
26845773Sdcsint isochar __P((u_char *, u_char *, int, u_char *));
26945773Sdcsint isofncmp __P((u_char *, int, u_char *, int, int));
27045773Sdcsvoid isofntrans __P((u_char *, int, u_char *, u_short *, int, int, int));
27125531Sjoergino_t isodirino __P((struct iso_directory_record *, struct iso_mnt *));
27225531Sjoerg
27325531Sjoerg#endif /* KERNEL */
27425531Sjoerg
27525531Sjoerg/*
27625531Sjoerg * The isonum_xxx functions are inlined anyway, and could come handy even
27725531Sjoerg * outside the kernel.  Thus we don't hide them here.
27825531Sjoerg */
27925531Sjoerg
28022521Sdysonstatic __inline int isonum_711 __P((u_char *));
28122521Sdysonstatic __inline int
2821541Srgrimesisonum_711(p)
28322521Sdyson	u_char *p;
2841541Srgrimes{
2851541Srgrimes	return *p;
2861541Srgrimes}
2871541Srgrimes
28822521Sdysonstatic __inline int isonum_712 __P((char *));
28922521Sdysonstatic __inline int
2901541Srgrimesisonum_712(p)
2911541Srgrimes	char *p;
2921541Srgrimes{
2931541Srgrimes	return *p;
2941541Srgrimes}
2951541Srgrimes
29622521Sdyson#ifndef UNALIGNED_ACCESS
29722521Sdyson
29822521Sdysonstatic __inline int isonum_723 __P((u_char *));
29922521Sdysonstatic __inline int
30022521Sdysonisonum_723(p)
30122521Sdyson	u_char *p;
3021541Srgrimes{
30322521Sdyson	return *p|(p[1] << 8);
3041541Srgrimes}
3051541Srgrimes
30622521Sdysonstatic __inline int isonum_733 __P((u_char *));
30722521Sdysonstatic __inline int
30822521Sdysonisonum_733(p)
30922521Sdyson	u_char *p;
3101541Srgrimes{
31122521Sdyson	return *p|(p[1] << 8)|(p[2] << 16)|(p[3] << 24);
3121541Srgrimes}
3131541Srgrimes
31422521Sdyson#else /* UNALIGNED_ACCESS */
31522521Sdyson
31622521Sdyson#if BYTE_ORDER == LITTLE_ENDIAN
31722521Sdyson
31822521Sdysonstatic __inline int
3191541Srgrimesisonum_723(p)
32022521Sdyson	u_char *p
3211541Srgrimes{
32222521Sdyson	return *(u_int16t *)p;
3231541Srgrimes}
3241541Srgrimes
32522521Sdysonstatic __inline int
32622521Sdysonisonum_733(p)
32722521Sdyson	u_char *p;
3281541Srgrimes{
32922521Sdyson	return *(u_int32t *)p;
3301541Srgrimes}
3311541Srgrimes
33222521Sdyson#endif
33322521Sdyson
33422521Sdyson#if BYTE_ORDER == BIG_ENDIAN
33522521Sdyson
33622521Sdysonstatic __inline int
33722521Sdysonisonum_723(p)
33822521Sdyson	u_char *p
3391541Srgrimes{
34022521Sdyson	return *(u_int16t *)(p + 2);
3411541Srgrimes}
3421541Srgrimes
34322521Sdysonstatic __inline int
3441541Srgrimesisonum_733(p)
34522521Sdyson	u_char *p;
3461541Srgrimes{
34722521Sdyson	return *(u_int32t *)(p + 4);
3481541Srgrimes}
3491541Srgrimes
35022521Sdyson#endif
3511541Srgrimes
35222521Sdyson#endif /* UNALIGNED_ACCESS */
35322521Sdyson
3541541Srgrimes/*
3551541Srgrimes * Associated files have a leading '='.
3561541Srgrimes */
3571541Srgrimes#define	ASSOCCHAR	'='
358