1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * ISO 9660 System Use Sharing Protocol extension filesystem specifications
24*0Sstevel@tonic-gate * Copyright (c) 1991,2000,2001 by Sun Microsystems, Inc.
25*0Sstevel@tonic-gate * All rights reserved.
26*0Sstevel@tonic-gate */
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate #include <sys/types.h>
31*0Sstevel@tonic-gate #include <sys/t_lock.h>
32*0Sstevel@tonic-gate #include <sys/param.h>
33*0Sstevel@tonic-gate #include <sys/systm.h>
34*0Sstevel@tonic-gate #include <sys/sysmacros.h>
35*0Sstevel@tonic-gate #include <sys/kmem.h>
36*0Sstevel@tonic-gate #include <sys/signal.h>
37*0Sstevel@tonic-gate #include <sys/user.h>
38*0Sstevel@tonic-gate #include <sys/proc.h>
39*0Sstevel@tonic-gate #include <sys/disp.h>
40*0Sstevel@tonic-gate #include <sys/buf.h>
41*0Sstevel@tonic-gate #include <sys/pathname.h>
42*0Sstevel@tonic-gate #include <sys/vfs.h>
43*0Sstevel@tonic-gate #include <sys/vnode.h>
44*0Sstevel@tonic-gate #include <sys/file.h>
45*0Sstevel@tonic-gate #include <sys/uio.h>
46*0Sstevel@tonic-gate #include <sys/conf.h>
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate #include <vm/page.h>
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
51*0Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
52*0Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
53*0Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
54*0Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
55*0Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate #include <sys/statvfs.h>
58*0Sstevel@tonic-gate #include <sys/mount.h>
59*0Sstevel@tonic-gate #include <sys/swap.h>
60*0Sstevel@tonic-gate #include <sys/errno.h>
61*0Sstevel@tonic-gate #include <sys/debug.h>
62*0Sstevel@tonic-gate #include "fs/fs_subr.h"
63*0Sstevel@tonic-gate #include <sys/cmn_err.h>
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate /*
68*0Sstevel@tonic-gate * Common Signatures for all SUSP
69*0Sstevel@tonic-gate */
70*0Sstevel@tonic-gate ext_signature_t susp_signature_table[ ] = {
71*0Sstevel@tonic-gate SUSP_SP, share_protocol, /* must be first in table */
72*0Sstevel@tonic-gate SUSP_CE, share_continue, /* must be second in table */
73*0Sstevel@tonic-gate SUSP_PD, share_padding,
74*0Sstevel@tonic-gate SUSP_ER, share_ext_ref,
75*0Sstevel@tonic-gate SUSP_ST, share_stop,
76*0Sstevel@tonic-gate (char *)NULL, NULL
77*0Sstevel@tonic-gate };
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate /*
80*0Sstevel@tonic-gate * These are global pointers referring to the above table, so the
81*0Sstevel@tonic-gate * positions must not change as marked on the right above.
82*0Sstevel@tonic-gate */
83*0Sstevel@tonic-gate ext_signature_t *susp_sp = &susp_signature_table[0];
84*0Sstevel@tonic-gate ext_signature_t *susp_ce = &susp_signature_table[1];
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gate /*
88*0Sstevel@tonic-gate * ext name version implemented signature table
89*0Sstevel@tonic-gate *
90*0Sstevel@tonic-gate * the SUSP must be the first entry in the table.
91*0Sstevel@tonic-gate * the RRIP must be the second entry in the table. We need to be able
92*0Sstevel@tonic-gate * to check the RRIP bit being set, so we must know it's position.
93*0Sstevel@tonic-gate * RRIP_BIT is set to 2 in rrip.h
94*0Sstevel@tonic-gate */
95*0Sstevel@tonic-gate extension_name_t extension_name_table[] = {
96*0Sstevel@tonic-gate "SUSP_1991A", SUSP_VERSION, susp_signature_table, /* #1 */
97*0Sstevel@tonic-gate RRIP_ER_EXT_ID, RRIP_EXT_VERSION, rrip_signature_table,
98*0Sstevel@tonic-gate (char *)NULL, 0, (ext_signature_t *)NULL
99*0Sstevel@tonic-gate };
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gate extension_name_t *susp_ext_name = extension_name_table;
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gate /*
104*0Sstevel@tonic-gate * share_protocol()
105*0Sstevel@tonic-gate *
106*0Sstevel@tonic-gate * sig_handler() for SUSP signature "SP"
107*0Sstevel@tonic-gate *
108*0Sstevel@tonic-gate * This function looks for the "SP" signature field, which means that
109*0Sstevel@tonic-gate * the SUSP is supported on the current CD-ROM. It looks for the word
110*0Sstevel@tonic-gate * 0xBEEF in the signature. If that exists, the SUSP is implemented.
111*0Sstevel@tonic-gate * The function will then set the implemented bit in the "SUSP" entry
112*0Sstevel@tonic-gate * of the extention_name_table[]. If the bytes don't match, then we
113*0Sstevel@tonic-gate * return a big fat NULL and treat this as an ISO 9660 CD-ROM.
114*0Sstevel@tonic-gate */
115*0Sstevel@tonic-gate uchar_t *
share_protocol(sig_args_t * sig_args_p)116*0Sstevel@tonic-gate share_protocol(sig_args_t *sig_args_p)
117*0Sstevel@tonic-gate {
118*0Sstevel@tonic-gate uchar_t *sp_ptr = sig_args_p->SUF_ptr;
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate /* Let's check the check bytes */
121*0Sstevel@tonic-gate if (!CHECK_BYTES_OK(sp_ptr))
122*0Sstevel@tonic-gate return ((uchar_t *)NULL);
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate /*
125*0Sstevel@tonic-gate * Ah, we have the go ahead, so let's set the implemented bit
126*0Sstevel@tonic-gate * of the SUSP in the extension_name_table[]
127*0Sstevel@tonic-gate */
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate if (SUSP_VERSION < SUF_VER(sp_ptr)) {
130*0Sstevel@tonic-gate cmn_err(CE_NOTE,
131*0Sstevel@tonic-gate "System Use Sharing Protocol ver. %d:not supported\n",
132*0Sstevel@tonic-gate (int)SUF_VER(sp_ptr));
133*0Sstevel@tonic-gate return ((uchar_t *)NULL);
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate SET_SUSP_BIT(sig_args_p->fsp);
137*0Sstevel@tonic-gate
138*0Sstevel@tonic-gate sig_args_p->fsp->hsfs_sua_off = SP_SUA_OFFSET(sp_ptr);
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate return (sp_ptr + SUF_LEN(sp_ptr));
141*0Sstevel@tonic-gate }
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate /*
144*0Sstevel@tonic-gate * share_ext_ref()
145*0Sstevel@tonic-gate *
146*0Sstevel@tonic-gate * sig_handler() for SUSP signature "ER"
147*0Sstevel@tonic-gate *
148*0Sstevel@tonic-gate * This function looks for the "ER" signature field, which lists an
149*0Sstevel@tonic-gate * extension that is implemented on the current CD-ROM. The function
150*0Sstevel@tonic-gate * will then search through the extention_name_table[], looking for the
151*0Sstevel@tonic-gate * extension reference in this SUF.
152*0Sstevel@tonic-gate *
153*0Sstevel@tonic-gate * If the correct extension reference is found, and the version number
154*0Sstevel@tonic-gate * in the "ER" SUF is less than or equal to the version specified in
155*0Sstevel@tonic-gate * the extension_name_table, the implemented bit will be set to 1.
156*0Sstevel@tonic-gate *
157*0Sstevel@tonic-gate * If the version number in the "ER" field is greater than that in the
158*0Sstevel@tonic-gate * extension_name_table or no reference can be matched, the reference
159*0Sstevel@tonic-gate * will be skipped the function will return the next field.
160*0Sstevel@tonic-gate */
161*0Sstevel@tonic-gate uchar_t *
share_ext_ref(sig_args_t * sig_args_p)162*0Sstevel@tonic-gate share_ext_ref(sig_args_t *sig_args_p)
163*0Sstevel@tonic-gate {
164*0Sstevel@tonic-gate uchar_t *er_ptr = sig_args_p->SUF_ptr;
165*0Sstevel@tonic-gate extension_name_t *extnp;
166*0Sstevel@tonic-gate int index;
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate /*
169*0Sstevel@tonic-gate * Find appropriate extension and signature table
170*0Sstevel@tonic-gate */
171*0Sstevel@tonic-gate for (extnp = extension_name_table, index = 0;
172*0Sstevel@tonic-gate extnp->extension_name != (char *)NULL;
173*0Sstevel@tonic-gate extnp++, index++) {
174*0Sstevel@tonic-gate if (strncmp(extnp->extension_name,
175*0Sstevel@tonic-gate (char *)ER_ext_id(er_ptr),
176*0Sstevel@tonic-gate ER_ID_LEN(er_ptr)) == 0) {
177*0Sstevel@tonic-gate SET_IMPL_BIT(sig_args_p->fsp, index);
178*0Sstevel@tonic-gate }
179*0Sstevel@tonic-gate }
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate return (er_ptr + SUF_LEN(er_ptr));
182*0Sstevel@tonic-gate }
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate /*
185*0Sstevel@tonic-gate * share_continue()
186*0Sstevel@tonic-gate *
187*0Sstevel@tonic-gate * sig_handler() for SUSP signature "CE"
188*0Sstevel@tonic-gate *
189*0Sstevel@tonic-gate * This function looks for the "CE" signature field. This means that
190*0Sstevel@tonic-gate * the SUA is continued in another block on the CD-ROM. Because it is
191*0Sstevel@tonic-gate * not a requirement that this "CE" field come at the end of the SUA,
192*0Sstevel@tonic-gate * this function will only set up a structure containing the
193*0Sstevel@tonic-gate * information needed to read the next SUA, somewhere on the disk.
194*0Sstevel@tonic-gate *
195*0Sstevel@tonic-gate * The end of the SUA is signaled by 2 NULL bytes, where the next
196*0Sstevel@tonic-gate * signature would have been.
197*0Sstevel@tonic-gate *
198*0Sstevel@tonic-gate * This one will be tough to implement.
199*0Sstevel@tonic-gate */
200*0Sstevel@tonic-gate uchar_t *
share_continue(sig_args_t * sig_args_p)201*0Sstevel@tonic-gate share_continue(sig_args_t *sig_args_p)
202*0Sstevel@tonic-gate {
203*0Sstevel@tonic-gate uchar_t *ce_ptr = sig_args_p->SUF_ptr;
204*0Sstevel@tonic-gate
205*0Sstevel@tonic-gate sig_args_p->cont_info_p->cont_lbn = CE_BLK_LOC(ce_ptr);
206*0Sstevel@tonic-gate sig_args_p->cont_info_p->cont_offset = CE_OFFSET(ce_ptr);
207*0Sstevel@tonic-gate sig_args_p->cont_info_p->cont_len = CE_CONT_LEN(ce_ptr);
208*0Sstevel@tonic-gate
209*0Sstevel@tonic-gate return (ce_ptr + SUF_LEN(ce_ptr));
210*0Sstevel@tonic-gate }
211*0Sstevel@tonic-gate
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gate /*
214*0Sstevel@tonic-gate * share_padding()
215*0Sstevel@tonic-gate *
216*0Sstevel@tonic-gate * sig_handler() for SUSP signature "PD"
217*0Sstevel@tonic-gate *
218*0Sstevel@tonic-gate * All this function is needed for is bypassing a certain number of
219*0Sstevel@tonic-gate * bytes. So, we just advance past this field and we're set.
220*0Sstevel@tonic-gate */
221*0Sstevel@tonic-gate uchar_t *
share_padding(sig_args_t * sig_args_p)222*0Sstevel@tonic-gate share_padding(sig_args_t *sig_args_p)
223*0Sstevel@tonic-gate {
224*0Sstevel@tonic-gate uchar_t *pd_ptr = sig_args_p->SUF_ptr;
225*0Sstevel@tonic-gate
226*0Sstevel@tonic-gate return (pd_ptr + SUF_LEN(pd_ptr));
227*0Sstevel@tonic-gate }
228*0Sstevel@tonic-gate
229*0Sstevel@tonic-gate
230*0Sstevel@tonic-gate
231*0Sstevel@tonic-gate /*
232*0Sstevel@tonic-gate * share_stop()
233*0Sstevel@tonic-gate *
234*0Sstevel@tonic-gate * sig_handler() for SUSP signature "ST"
235*0Sstevel@tonic-gate *
236*0Sstevel@tonic-gate * All this is used for is signaling the end of an SUA.
237*0Sstevel@tonic-gate * It fills the flag variable with the
238*0Sstevel@tonic-gate */
239*0Sstevel@tonic-gate uchar_t *
share_stop(sig_args_t * sig_args_p)240*0Sstevel@tonic-gate share_stop(sig_args_t *sig_args_p)
241*0Sstevel@tonic-gate {
242*0Sstevel@tonic-gate uchar_t *st_ptr = sig_args_p->SUF_ptr;
243*0Sstevel@tonic-gate
244*0Sstevel@tonic-gate sig_args_p->flags = END_OF_SUA; /* stop parsing the SUA NOW!!!! */
245*0Sstevel@tonic-gate
246*0Sstevel@tonic-gate return (st_ptr + SUF_LEN(st_ptr));
247*0Sstevel@tonic-gate }
248