xref: /freebsd/sys/fs/cd9660/cd9660_rrip.c (revision 96e69c8e3167a57b8b37317796eba3068d12a771)
1df8bae1dSRodney W. Grimes /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
4df8bae1dSRodney W. Grimes  * Copyright (c) 1993, 1994
5df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
6df8bae1dSRodney W. Grimes  *
7df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley
8df8bae1dSRodney W. Grimes  * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
9df8bae1dSRodney W. Grimes  * Support code is derived from software contributed to Berkeley
10df8bae1dSRodney W. Grimes  * by Atsushi Murai (amurai@spec.co.jp).
11df8bae1dSRodney W. Grimes  *
12df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
13df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
14df8bae1dSRodney W. Grimes  * are met:
15df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
17df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
18df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
19df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
20fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
21df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
22df8bae1dSRodney W. Grimes  *    without specific prior written permission.
23df8bae1dSRodney W. Grimes  *
24df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37df8bae1dSRodney W. Grimes #include <sys/param.h>
381dbaf90cSBruce Evans #include <sys/systm.h>
399626b608SPoul-Henning Kamp #include <sys/bio.h>
40df8bae1dSRodney W. Grimes #include <sys/buf.h>
4176ca6f88SJamie Gritton #include <sys/jail.h>
42df8bae1dSRodney W. Grimes #include <sys/vnode.h>
43df8bae1dSRodney W. Grimes #include <sys/mount.h>
44df8bae1dSRodney W. Grimes #include <sys/kernel.h>
45df8bae1dSRodney W. Grimes 
46a8d36d0dSCraig Rodrigues #include <fs/cd9660/iso.h>
47a8d36d0dSCraig Rodrigues #include <fs/cd9660/cd9660_node.h>
48a8d36d0dSCraig Rodrigues #include <fs/cd9660/cd9660_rrip.h>
49a8d36d0dSCraig Rodrigues #include <fs/cd9660/iso_rrip.h>
50df8bae1dSRodney W. Grimes 
5189c9a483SAlfred Perlstein typedef int	rrt_func_t(void *, ISO_RRIP_ANALYZE *ana);
5210dd32cdSBruce Evans 
5310dd32cdSBruce Evans typedef struct {
5410dd32cdSBruce Evans 	char type[2];
5510dd32cdSBruce Evans 	rrt_func_t *func;
5689c9a483SAlfred Perlstein 	void (*func2)(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana);
5710dd32cdSBruce Evans 	int result;
5810dd32cdSBruce Evans } RRIP_TABLE;
5910dd32cdSBruce Evans 
6089c9a483SAlfred Perlstein static int	cd9660_rrip_altname(ISO_RRIP_ALTNAME *p, ISO_RRIP_ANALYZE *ana);
6189c9a483SAlfred Perlstein static int	cd9660_rrip_attr(ISO_RRIP_ATTR *p, ISO_RRIP_ANALYZE *ana);
6289c9a483SAlfred Perlstein static int	cd9660_rrip_cont(ISO_RRIP_CONT *p, ISO_RRIP_ANALYZE *ana);
6389c9a483SAlfred Perlstein static void	cd9660_rrip_defattr(struct iso_directory_record *isodir,
6489c9a483SAlfred Perlstein 		    ISO_RRIP_ANALYZE *ana);
6589c9a483SAlfred Perlstein static void	cd9660_rrip_defname(struct iso_directory_record *isodir,
6689c9a483SAlfred Perlstein 		    ISO_RRIP_ANALYZE *ana);
6789c9a483SAlfred Perlstein static void	cd9660_rrip_deftstamp(struct iso_directory_record *isodir,
6889c9a483SAlfred Perlstein 		    ISO_RRIP_ANALYZE *ana);
6989c9a483SAlfred Perlstein static int	cd9660_rrip_device(ISO_RRIP_DEVICE *p, ISO_RRIP_ANALYZE *ana);
7089c9a483SAlfred Perlstein static int	cd9660_rrip_extref(ISO_RRIP_EXTREF *p, ISO_RRIP_ANALYZE *ana);
7189c9a483SAlfred Perlstein static int	cd9660_rrip_idflag(ISO_RRIP_IDFLAG *p, ISO_RRIP_ANALYZE *ana);
7289c9a483SAlfred Perlstein static int	cd9660_rrip_loop(struct iso_directory_record *isodir,
7369c59d87SBruce Evans 		    ISO_RRIP_ANALYZE *ana, RRIP_TABLE *table);
7489c9a483SAlfred Perlstein static int	cd9660_rrip_pclink(ISO_RRIP_CLINK *p, ISO_RRIP_ANALYZE *ana);
7589c9a483SAlfred Perlstein static int	cd9660_rrip_reldir(ISO_RRIP_RELDIR *p, ISO_RRIP_ANALYZE *ana);
7689c9a483SAlfred Perlstein static int	cd9660_rrip_slink(ISO_RRIP_SLINK *p, ISO_RRIP_ANALYZE *ana);
7789c9a483SAlfred Perlstein static int	cd9660_rrip_stop(ISO_SUSP_HEADER *p, ISO_RRIP_ANALYZE *ana);
7889c9a483SAlfred Perlstein static int	cd9660_rrip_tstamp(ISO_RRIP_TSTAMP *p, ISO_RRIP_ANALYZE *ana);
7910dd32cdSBruce Evans 
80df8bae1dSRodney W. Grimes /*
81df8bae1dSRodney W. Grimes  * POSIX file attribute
82df8bae1dSRodney W. Grimes  */
83df8bae1dSRodney W. Grimes static int
cd9660_rrip_attr(ISO_RRIP_ATTR * p,ISO_RRIP_ANALYZE * ana)84a5f59e85SEd Maste cd9660_rrip_attr(ISO_RRIP_ATTR *p, ISO_RRIP_ANALYZE *ana)
85df8bae1dSRodney W. Grimes {
86996c772fSJohn Dyson 	ana->inop->inode.iso_mode = isonum_733(p->mode);
87996c772fSJohn Dyson 	ana->inop->inode.iso_uid = isonum_733(p->uid);
88996c772fSJohn Dyson 	ana->inop->inode.iso_gid = isonum_733(p->gid);
89996c772fSJohn Dyson 	ana->inop->inode.iso_links = isonum_733(p->links);
90df8bae1dSRodney W. Grimes 	ana->fields &= ~ISO_SUSP_ATTR;
91df8bae1dSRodney W. Grimes 	return ISO_SUSP_ATTR;
92df8bae1dSRodney W. Grimes }
93df8bae1dSRodney W. Grimes 
94df8bae1dSRodney W. Grimes static void
cd9660_rrip_defattr(struct iso_directory_record * isodir,ISO_RRIP_ANALYZE * ana)95a5f59e85SEd Maste cd9660_rrip_defattr(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana)
96df8bae1dSRodney W. Grimes {
97df8bae1dSRodney W. Grimes 	/* But this is a required field! */
98df8bae1dSRodney W. Grimes 	printf("RRIP without PX field?\n");
99988fa8efSJoerg Wunsch 	cd9660_defattr(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
100df8bae1dSRodney W. Grimes }
101df8bae1dSRodney W. Grimes 
102df8bae1dSRodney W. Grimes /*
103df8bae1dSRodney W. Grimes  * Symbolic Links
104df8bae1dSRodney W. Grimes  */
105df8bae1dSRodney W. Grimes static int
cd9660_rrip_slink(ISO_RRIP_SLINK * p,ISO_RRIP_ANALYZE * ana)106a5f59e85SEd Maste cd9660_rrip_slink(ISO_RRIP_SLINK *p, ISO_RRIP_ANALYZE *ana)
107df8bae1dSRodney W. Grimes {
108bffd1b7aSPoul-Henning Kamp 	ISO_RRIP_SLINK_COMPONENT *pcomp;
109bffd1b7aSPoul-Henning Kamp 	ISO_RRIP_SLINK_COMPONENT *pcompe;
110df8bae1dSRodney W. Grimes 	int len, wlen, cont;
111df8bae1dSRodney W. Grimes 	char *outbuf, *inbuf;
11276ca6f88SJamie Gritton 	char hostbuf[MAXHOSTNAMELEN];
113df8bae1dSRodney W. Grimes 
114df8bae1dSRodney W. Grimes 	pcomp = (ISO_RRIP_SLINK_COMPONENT *)p->component;
115df8bae1dSRodney W. Grimes 	pcompe = (ISO_RRIP_SLINK_COMPONENT *)((char *)p + isonum_711(p->h.length));
116df8bae1dSRodney W. Grimes 	len = *ana->outlen;
117df8bae1dSRodney W. Grimes 	outbuf = ana->outbuf;
118df8bae1dSRodney W. Grimes 	cont = ana->cont;
119df8bae1dSRodney W. Grimes 
120df8bae1dSRodney W. Grimes 	/*
121df8bae1dSRodney W. Grimes 	 * Gathering a Symbolic name from each component with path
122df8bae1dSRodney W. Grimes 	 */
123df8bae1dSRodney W. Grimes 	for (;
124df8bae1dSRodney W. Grimes 	     pcomp < pcompe;
125df8bae1dSRodney W. Grimes 	     pcomp = (ISO_RRIP_SLINK_COMPONENT *)((char *)pcomp + ISO_RRIP_SLSIZ
126df8bae1dSRodney W. Grimes 						  + isonum_711(pcomp->clen))) {
127df8bae1dSRodney W. Grimes 		if (!cont) {
128df8bae1dSRodney W. Grimes 			if (len < ana->maxlen) {
129df8bae1dSRodney W. Grimes 				len++;
130df8bae1dSRodney W. Grimes 				*outbuf++ = '/';
131df8bae1dSRodney W. Grimes 			}
132df8bae1dSRodney W. Grimes 		}
133df8bae1dSRodney W. Grimes 		cont = 0;
134df8bae1dSRodney W. Grimes 
135df8bae1dSRodney W. Grimes 		inbuf = "..";
136df8bae1dSRodney W. Grimes 		wlen = 0;
137df8bae1dSRodney W. Grimes 
138df8bae1dSRodney W. Grimes 		switch (*pcomp->cflag) {
139df8bae1dSRodney W. Grimes 		case ISO_SUSP_CFLAG_CURRENT:
140df8bae1dSRodney W. Grimes 			/* Inserting Current */
141df8bae1dSRodney W. Grimes 			wlen = 1;
142df8bae1dSRodney W. Grimes 			break;
143df8bae1dSRodney W. Grimes 
144df8bae1dSRodney W. Grimes 		case ISO_SUSP_CFLAG_PARENT:
145df8bae1dSRodney W. Grimes 			/* Inserting Parent */
146df8bae1dSRodney W. Grimes 			wlen = 2;
147df8bae1dSRodney W. Grimes 			break;
148df8bae1dSRodney W. Grimes 
149df8bae1dSRodney W. Grimes 		case ISO_SUSP_CFLAG_ROOT:
150df8bae1dSRodney W. Grimes 			/* Inserting slash for ROOT */
151f7d5a532SJoerg Wunsch 			/* Double slash, nothing really to do here. */
152df8bae1dSRodney W. Grimes 			break;
153df8bae1dSRodney W. Grimes 
154df8bae1dSRodney W. Grimes 		case ISO_SUSP_CFLAG_VOLROOT:
155df8bae1dSRodney W. Grimes 			/* Inserting a mount point i.e. "/cdrom" */
156df8bae1dSRodney W. Grimes 			/* same as above */
157df8bae1dSRodney W. Grimes 			outbuf -= len;
158df8bae1dSRodney W. Grimes 			len = 0;
159df8bae1dSRodney W. Grimes 			inbuf = ana->imp->im_mountp->mnt_stat.f_mntonname;
160df8bae1dSRodney W. Grimes 			wlen = strlen(inbuf);
161df8bae1dSRodney W. Grimes 			break;
162df8bae1dSRodney W. Grimes 
163df8bae1dSRodney W. Grimes 		case ISO_SUSP_CFLAG_HOST:
164df8bae1dSRodney W. Grimes 			/* Inserting hostname i.e. "kurt.tools.de" */
16576ca6f88SJamie Gritton 			getcredhostname(curthread->td_ucred, hostbuf,
16676ca6f88SJamie Gritton 			    sizeof(hostbuf));
16776ca6f88SJamie Gritton 			inbuf = hostbuf;
16876ca6f88SJamie Gritton 			wlen = strlen(inbuf);
169df8bae1dSRodney W. Grimes 			break;
170df8bae1dSRodney W. Grimes 
171df8bae1dSRodney W. Grimes 		case ISO_SUSP_CFLAG_CONTINUE:
172df8bae1dSRodney W. Grimes 			cont = 1;
17393b0017fSPhilippe Charnier 			/* FALLTHROUGH */
174df8bae1dSRodney W. Grimes 		case 0:
175df8bae1dSRodney W. Grimes 			/* Inserting component */
176df8bae1dSRodney W. Grimes 			wlen = isonum_711(pcomp->clen);
177df8bae1dSRodney W. Grimes 			inbuf = pcomp->name;
178df8bae1dSRodney W. Grimes 			break;
179df8bae1dSRodney W. Grimes 		default:
180df8bae1dSRodney W. Grimes 			printf("RRIP with incorrect flags?");
181df8bae1dSRodney W. Grimes 			wlen = ana->maxlen + 1;
182df8bae1dSRodney W. Grimes 			break;
183df8bae1dSRodney W. Grimes 		}
184df8bae1dSRodney W. Grimes 
185df8bae1dSRodney W. Grimes 		if (len + wlen > ana->maxlen) {
186df8bae1dSRodney W. Grimes 			/* indicate error to caller */
187df8bae1dSRodney W. Grimes 			ana->cont = 1;
188df8bae1dSRodney W. Grimes 			ana->fields = 0;
189df8bae1dSRodney W. Grimes 			ana->outbuf -= *ana->outlen;
190df8bae1dSRodney W. Grimes 			*ana->outlen = 0;
191df8bae1dSRodney W. Grimes 			return 0;
192df8bae1dSRodney W. Grimes 		}
193df8bae1dSRodney W. Grimes 
194a6274b81SEd Maste 		memcpy(outbuf, inbuf, wlen);
195df8bae1dSRodney W. Grimes 		outbuf += wlen;
196df8bae1dSRodney W. Grimes 		len += wlen;
197df8bae1dSRodney W. Grimes 	}
198df8bae1dSRodney W. Grimes 	ana->outbuf = outbuf;
199df8bae1dSRodney W. Grimes 	*ana->outlen = len;
200df8bae1dSRodney W. Grimes 	ana->cont = cont;
201df8bae1dSRodney W. Grimes 
202df8bae1dSRodney W. Grimes 	if (!isonum_711(p->flags)) {
203df8bae1dSRodney W. Grimes 		ana->fields &= ~ISO_SUSP_SLINK;
204df8bae1dSRodney W. Grimes 		return ISO_SUSP_SLINK;
205df8bae1dSRodney W. Grimes 	}
206df8bae1dSRodney W. Grimes 	return 0;
207df8bae1dSRodney W. Grimes }
208df8bae1dSRodney W. Grimes 
209df8bae1dSRodney W. Grimes /*
210df8bae1dSRodney W. Grimes  * Alternate name
211df8bae1dSRodney W. Grimes  */
212df8bae1dSRodney W. Grimes static int
cd9660_rrip_altname(ISO_RRIP_ALTNAME * p,ISO_RRIP_ANALYZE * ana)213a5f59e85SEd Maste cd9660_rrip_altname(ISO_RRIP_ALTNAME *p, ISO_RRIP_ANALYZE *ana)
214df8bae1dSRodney W. Grimes {
215df8bae1dSRodney W. Grimes 	char *inbuf;
216df8bae1dSRodney W. Grimes 	int wlen;
217df8bae1dSRodney W. Grimes 	int cont;
21876ca6f88SJamie Gritton 	char hostbuf[MAXHOSTNAMELEN];
219df8bae1dSRodney W. Grimes 
220df8bae1dSRodney W. Grimes 	inbuf = "..";
221df8bae1dSRodney W. Grimes 	wlen = 0;
222df8bae1dSRodney W. Grimes 	cont = 0;
223df8bae1dSRodney W. Grimes 
224df8bae1dSRodney W. Grimes 	switch (*p->flags) {
225df8bae1dSRodney W. Grimes 	case ISO_SUSP_CFLAG_CURRENT:
226df8bae1dSRodney W. Grimes 		/* Inserting Current */
227df8bae1dSRodney W. Grimes 		wlen = 1;
228df8bae1dSRodney W. Grimes 		break;
229df8bae1dSRodney W. Grimes 
230df8bae1dSRodney W. Grimes 	case ISO_SUSP_CFLAG_PARENT:
231df8bae1dSRodney W. Grimes 		/* Inserting Parent */
232df8bae1dSRodney W. Grimes 		wlen = 2;
233df8bae1dSRodney W. Grimes 		break;
234df8bae1dSRodney W. Grimes 
235df8bae1dSRodney W. Grimes 	case ISO_SUSP_CFLAG_HOST:
236df8bae1dSRodney W. Grimes 		/* Inserting hostname i.e. "kurt.tools.de" */
23776ca6f88SJamie Gritton 		getcredhostname(curthread->td_ucred, hostbuf, sizeof(hostbuf));
23876ca6f88SJamie Gritton 		inbuf = hostbuf;
23976ca6f88SJamie Gritton 		wlen = strlen(inbuf);
240df8bae1dSRodney W. Grimes 		break;
241df8bae1dSRodney W. Grimes 
242df8bae1dSRodney W. Grimes 	case ISO_SUSP_CFLAG_CONTINUE:
243df8bae1dSRodney W. Grimes 		cont = 1;
24493b0017fSPhilippe Charnier 		/* FALLTHROUGH */
245df8bae1dSRodney W. Grimes 	case 0:
246df8bae1dSRodney W. Grimes 		/* Inserting component */
247df8bae1dSRodney W. Grimes 		wlen = isonum_711(p->h.length) - 5;
248df8bae1dSRodney W. Grimes 		inbuf = (char *)p + 5;
249df8bae1dSRodney W. Grimes 		break;
250df8bae1dSRodney W. Grimes 
251df8bae1dSRodney W. Grimes 	default:
252df8bae1dSRodney W. Grimes 		printf("RRIP with incorrect NM flags?\n");
253df8bae1dSRodney W. Grimes 		wlen = ana->maxlen + 1;
254df8bae1dSRodney W. Grimes 		break;
255df8bae1dSRodney W. Grimes 	}
256df8bae1dSRodney W. Grimes 
257df8bae1dSRodney W. Grimes 	if ((*ana->outlen += wlen) > ana->maxlen) {
258df8bae1dSRodney W. Grimes 		/* treat as no name field */
259df8bae1dSRodney W. Grimes 		ana->fields &= ~ISO_SUSP_ALTNAME;
260df8bae1dSRodney W. Grimes 		ana->outbuf -= *ana->outlen - wlen;
261df8bae1dSRodney W. Grimes 		*ana->outlen = 0;
262df8bae1dSRodney W. Grimes 		return 0;
263df8bae1dSRodney W. Grimes 	}
264df8bae1dSRodney W. Grimes 
265a6274b81SEd Maste 	memcpy(ana->outbuf, inbuf, wlen);
266df8bae1dSRodney W. Grimes 	ana->outbuf += wlen;
267df8bae1dSRodney W. Grimes 
268df8bae1dSRodney W. Grimes 	if (!cont) {
269df8bae1dSRodney W. Grimes 		ana->fields &= ~ISO_SUSP_ALTNAME;
270df8bae1dSRodney W. Grimes 		return ISO_SUSP_ALTNAME;
271df8bae1dSRodney W. Grimes 	}
272df8bae1dSRodney W. Grimes 	return 0;
273df8bae1dSRodney W. Grimes }
274df8bae1dSRodney W. Grimes 
275df8bae1dSRodney W. Grimes static void
cd9660_rrip_defname(struct iso_directory_record * isodir,ISO_RRIP_ANALYZE * ana)276a5f59e85SEd Maste cd9660_rrip_defname(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana)
277df8bae1dSRodney W. Grimes {
278df8bae1dSRodney W. Grimes 	isofntrans(isodir->name,isonum_711(isodir->name_len),
279df8bae1dSRodney W. Grimes 		   ana->outbuf,ana->outlen,
280c4f02a89SMax Khon 		   1,isonum_711(isodir->flags)&4, ana->imp->joliet_level,
281c4f02a89SMax Khon 		   ana->imp->im_flags, ana->imp->im_d2l);
28244e568e2SDaniel C. Sobral 	switch (*ana->outbuf) {
28344e568e2SDaniel C. Sobral 	default:
284df8bae1dSRodney W. Grimes 		break;
285df8bae1dSRodney W. Grimes 	case 1:
286df8bae1dSRodney W. Grimes 		*ana->outlen = 2;
28744e568e2SDaniel C. Sobral 		/* FALLTHROUGH */
28844e568e2SDaniel C. Sobral 	case 0:
28944e568e2SDaniel C. Sobral 		/* outlen is 1 already */
29044e568e2SDaniel C. Sobral 		strcpy(ana->outbuf,"..");
291df8bae1dSRodney W. Grimes 		break;
292df8bae1dSRodney W. Grimes 	}
293df8bae1dSRodney W. Grimes }
294df8bae1dSRodney W. Grimes 
295df8bae1dSRodney W. Grimes /*
296df8bae1dSRodney W. Grimes  * Parent or Child Link
297df8bae1dSRodney W. Grimes  */
298df8bae1dSRodney W. Grimes static int
cd9660_rrip_pclink(ISO_RRIP_CLINK * p,ISO_RRIP_ANALYZE * ana)299a5f59e85SEd Maste cd9660_rrip_pclink(ISO_RRIP_CLINK *p, ISO_RRIP_ANALYZE *ana)
300df8bae1dSRodney W. Grimes {
301df8bae1dSRodney W. Grimes 	*ana->inump = isonum_733(p->dir_loc) << ana->imp->im_bshift;
302df8bae1dSRodney W. Grimes 	ana->fields &= ~(ISO_SUSP_CLINK|ISO_SUSP_PLINK);
303df8bae1dSRodney W. Grimes 	return *p->h.type == 'C' ? ISO_SUSP_CLINK : ISO_SUSP_PLINK;
304df8bae1dSRodney W. Grimes }
305df8bae1dSRodney W. Grimes 
306df8bae1dSRodney W. Grimes /*
307df8bae1dSRodney W. Grimes  * Relocated directory
308df8bae1dSRodney W. Grimes  */
309df8bae1dSRodney W. Grimes static int
cd9660_rrip_reldir(ISO_RRIP_RELDIR * p,ISO_RRIP_ANALYZE * ana)310a5f59e85SEd Maste cd9660_rrip_reldir(ISO_RRIP_RELDIR *p, ISO_RRIP_ANALYZE *ana)
311df8bae1dSRodney W. Grimes {
312df8bae1dSRodney W. Grimes 	/* special hack to make caller aware of RE field */
313df8bae1dSRodney W. Grimes 	*ana->outlen = 0;
314df8bae1dSRodney W. Grimes 	ana->fields = 0;
315df8bae1dSRodney W. Grimes 	return ISO_SUSP_RELDIR|ISO_SUSP_ALTNAME|ISO_SUSP_CLINK|ISO_SUSP_PLINK;
316df8bae1dSRodney W. Grimes }
317df8bae1dSRodney W. Grimes 
318df8bae1dSRodney W. Grimes static int
cd9660_rrip_tstamp(ISO_RRIP_TSTAMP * p,ISO_RRIP_ANALYZE * ana)319a5f59e85SEd Maste cd9660_rrip_tstamp(ISO_RRIP_TSTAMP *p, ISO_RRIP_ANALYZE *ana)
320df8bae1dSRodney W. Grimes {
321996c772fSJohn Dyson 	u_char *ptime;
322df8bae1dSRodney W. Grimes 
323df8bae1dSRodney W. Grimes 	ptime = p->time;
324df8bae1dSRodney W. Grimes 
325df8bae1dSRodney W. Grimes 	/* Check a format of time stamp (7bytes/17bytes) */
326df8bae1dSRodney W. Grimes 	if (!(*p->flags&ISO_SUSP_TSTAMP_FORM17)) {
327df8bae1dSRodney W. Grimes 		if (*p->flags&ISO_SUSP_TSTAMP_CREAT)
328df8bae1dSRodney W. Grimes 			ptime += 7;
329df8bae1dSRodney W. Grimes 
330df8bae1dSRodney W. Grimes 		if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) {
331988fa8efSJoerg Wunsch 			cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_mtime,
332988fa8efSJoerg Wunsch 					    ISO_FTYPE_RRIP);
333df8bae1dSRodney W. Grimes 			ptime += 7;
334df8bae1dSRodney W. Grimes 		} else
335a6274b81SEd Maste 			memset(&ana->inop->inode.iso_mtime, 0, sizeof(struct timespec));
336df8bae1dSRodney W. Grimes 
337df8bae1dSRodney W. Grimes 		if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) {
338988fa8efSJoerg Wunsch 			cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_atime,
339988fa8efSJoerg Wunsch 					    ISO_FTYPE_RRIP);
340df8bae1dSRodney W. Grimes 			ptime += 7;
341df8bae1dSRodney W. Grimes 		} else
342df8bae1dSRodney W. Grimes 			ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime;
343df8bae1dSRodney W. Grimes 
344df8bae1dSRodney W. Grimes 		if (*p->flags&ISO_SUSP_TSTAMP_ATTR)
345988fa8efSJoerg Wunsch 			cd9660_tstamp_conv7(ptime,&ana->inop->inode.iso_ctime,
346988fa8efSJoerg Wunsch 					    ISO_FTYPE_RRIP);
347df8bae1dSRodney W. Grimes 		else
348df8bae1dSRodney W. Grimes 			ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime;
349df8bae1dSRodney W. Grimes 
350df8bae1dSRodney W. Grimes 	} else {
351df8bae1dSRodney W. Grimes 		if (*p->flags&ISO_SUSP_TSTAMP_CREAT)
352df8bae1dSRodney W. Grimes 			ptime += 17;
353df8bae1dSRodney W. Grimes 
354df8bae1dSRodney W. Grimes 		if (*p->flags&ISO_SUSP_TSTAMP_MODIFY) {
355df8bae1dSRodney W. Grimes 			cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_mtime);
356df8bae1dSRodney W. Grimes 			ptime += 17;
357df8bae1dSRodney W. Grimes 		} else
358a6274b81SEd Maste 			memset(&ana->inop->inode.iso_mtime, 0, sizeof(struct timespec));
359df8bae1dSRodney W. Grimes 
360df8bae1dSRodney W. Grimes 		if (*p->flags&ISO_SUSP_TSTAMP_ACCESS) {
361df8bae1dSRodney W. Grimes 			cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_atime);
362df8bae1dSRodney W. Grimes 			ptime += 17;
363df8bae1dSRodney W. Grimes 		} else
364df8bae1dSRodney W. Grimes 			ana->inop->inode.iso_atime = ana->inop->inode.iso_mtime;
365df8bae1dSRodney W. Grimes 
366df8bae1dSRodney W. Grimes 		if (*p->flags&ISO_SUSP_TSTAMP_ATTR)
367df8bae1dSRodney W. Grimes 			cd9660_tstamp_conv17(ptime,&ana->inop->inode.iso_ctime);
368df8bae1dSRodney W. Grimes 		else
369df8bae1dSRodney W. Grimes 			ana->inop->inode.iso_ctime = ana->inop->inode.iso_mtime;
370df8bae1dSRodney W. Grimes 	}
371df8bae1dSRodney W. Grimes 	ana->fields &= ~ISO_SUSP_TSTAMP;
372df8bae1dSRodney W. Grimes 	return ISO_SUSP_TSTAMP;
373df8bae1dSRodney W. Grimes }
374df8bae1dSRodney W. Grimes 
375df8bae1dSRodney W. Grimes static void
cd9660_rrip_deftstamp(struct iso_directory_record * isodir,ISO_RRIP_ANALYZE * ana)376a5f59e85SEd Maste cd9660_rrip_deftstamp(struct iso_directory_record *isodir,
377a5f59e85SEd Maste     ISO_RRIP_ANALYZE *ana)
378df8bae1dSRodney W. Grimes {
379988fa8efSJoerg Wunsch 	cd9660_deftstamp(isodir,ana->inop,NULL,ISO_FTYPE_RRIP);
380df8bae1dSRodney W. Grimes }
381df8bae1dSRodney W. Grimes 
382df8bae1dSRodney W. Grimes /*
383df8bae1dSRodney W. Grimes  * POSIX device modes
384df8bae1dSRodney W. Grimes  */
385df8bae1dSRodney W. Grimes static int
cd9660_rrip_device(ISO_RRIP_DEVICE * p,ISO_RRIP_ANALYZE * ana)386a5f59e85SEd Maste cd9660_rrip_device(ISO_RRIP_DEVICE *p, ISO_RRIP_ANALYZE *ana)
387df8bae1dSRodney W. Grimes {
388996c772fSJohn Dyson 	u_int high, low;
389df8bae1dSRodney W. Grimes 
390996c772fSJohn Dyson 	high = isonum_733(p->dev_t_high);
391996c772fSJohn Dyson 	low  = isonum_733(p->dev_t_low);
392df8bae1dSRodney W. Grimes 
393996c772fSJohn Dyson 	if (high == 0)
394a4611ab6SEd Schouten 		ana->inop->inode.iso_rdev = makedev(major(low), minor(low));
395996c772fSJohn Dyson 	else
396a4611ab6SEd Schouten 		ana->inop->inode.iso_rdev = makedev(high, minor(low));
397df8bae1dSRodney W. Grimes 	ana->fields &= ~ISO_SUSP_DEVICE;
398df8bae1dSRodney W. Grimes 	return ISO_SUSP_DEVICE;
399df8bae1dSRodney W. Grimes }
400df8bae1dSRodney W. Grimes 
401df8bae1dSRodney W. Grimes /*
402df8bae1dSRodney W. Grimes  * Flag indicating
403df8bae1dSRodney W. Grimes  */
404df8bae1dSRodney W. Grimes static int
cd9660_rrip_idflag(ISO_RRIP_IDFLAG * p,ISO_RRIP_ANALYZE * ana)405a5f59e85SEd Maste cd9660_rrip_idflag(ISO_RRIP_IDFLAG *p, ISO_RRIP_ANALYZE *ana)
406df8bae1dSRodney W. Grimes {
407df8bae1dSRodney W. Grimes 	ana->fields &= isonum_711(p->flags)|~0xff; /* don't touch high bits */
408df8bae1dSRodney W. Grimes 	/* special handling of RE field */
409df8bae1dSRodney W. Grimes 	if (ana->fields&ISO_SUSP_RELDIR)
41010dd32cdSBruce Evans 		return cd9660_rrip_reldir(/* XXX */ (ISO_RRIP_RELDIR *)p,ana);
411df8bae1dSRodney W. Grimes 
412df8bae1dSRodney W. Grimes 	return ISO_SUSP_IDFLAG;
413df8bae1dSRodney W. Grimes }
414df8bae1dSRodney W. Grimes 
415df8bae1dSRodney W. Grimes /*
416df8bae1dSRodney W. Grimes  * Continuation pointer
417df8bae1dSRodney W. Grimes  */
418df8bae1dSRodney W. Grimes static int
cd9660_rrip_cont(ISO_RRIP_CONT * p,ISO_RRIP_ANALYZE * ana)419a5f59e85SEd Maste cd9660_rrip_cont(ISO_RRIP_CONT *p, ISO_RRIP_ANALYZE *ana)
420df8bae1dSRodney W. Grimes {
421df8bae1dSRodney W. Grimes 	ana->iso_ce_blk = isonum_733(p->location);
422df8bae1dSRodney W. Grimes 	ana->iso_ce_off = isonum_733(p->offset);
423df8bae1dSRodney W. Grimes 	ana->iso_ce_len = isonum_733(p->length);
424df8bae1dSRodney W. Grimes 	return ISO_SUSP_CONT;
425df8bae1dSRodney W. Grimes }
426df8bae1dSRodney W. Grimes 
427df8bae1dSRodney W. Grimes /*
428df8bae1dSRodney W. Grimes  * System Use end
429df8bae1dSRodney W. Grimes  */
430df8bae1dSRodney W. Grimes static int
cd9660_rrip_stop(ISO_SUSP_HEADER * p,ISO_RRIP_ANALYZE * ana)431a5f59e85SEd Maste cd9660_rrip_stop(ISO_SUSP_HEADER *p, ISO_RRIP_ANALYZE *ana)
432df8bae1dSRodney W. Grimes {
433df8bae1dSRodney W. Grimes 	return ISO_SUSP_STOP;
434df8bae1dSRodney W. Grimes }
435df8bae1dSRodney W. Grimes 
436df8bae1dSRodney W. Grimes /*
437df8bae1dSRodney W. Grimes  * Extension reference
438df8bae1dSRodney W. Grimes  */
439df8bae1dSRodney W. Grimes static int
cd9660_rrip_extref(ISO_RRIP_EXTREF * p,ISO_RRIP_ANALYZE * ana)440a5f59e85SEd Maste cd9660_rrip_extref(ISO_RRIP_EXTREF *p, ISO_RRIP_ANALYZE *ana)
441df8bae1dSRodney W. Grimes {
442f7b8cfa8SUlf Lilleengen 	if ( ! ((isonum_711(p->len_id) == 10
443f7b8cfa8SUlf Lilleengen 	      && bcmp((char *)p + 8,"RRIP_1991A",10) == 0)
444f7b8cfa8SUlf Lilleengen 	    || (isonum_711(p->len_id) == 10
445f7b8cfa8SUlf Lilleengen 	      && bcmp((char *)p + 8,"IEEE_P1282",10) == 0)
446f7b8cfa8SUlf Lilleengen 	    || (isonum_711(p->len_id) ==  9
447f7b8cfa8SUlf Lilleengen 	      && bcmp((char *)p + 8,"IEEE_1282",  9) == 0))
448df8bae1dSRodney W. Grimes 	    || isonum_711(p->version) != 1)
449df8bae1dSRodney W. Grimes 		return 0;
450df8bae1dSRodney W. Grimes 	ana->fields &= ~ISO_SUSP_EXTREF;
451df8bae1dSRodney W. Grimes 	return ISO_SUSP_EXTREF;
452df8bae1dSRodney W. Grimes }
453df8bae1dSRodney W. Grimes 
454df8bae1dSRodney W. Grimes static int
cd9660_rrip_loop(struct iso_directory_record * isodir,ISO_RRIP_ANALYZE * ana,RRIP_TABLE * table)455a5f59e85SEd Maste cd9660_rrip_loop(struct iso_directory_record *isodir, ISO_RRIP_ANALYZE *ana,
456a5f59e85SEd Maste     RRIP_TABLE *table)
457df8bae1dSRodney W. Grimes {
458bffd1b7aSPoul-Henning Kamp 	RRIP_TABLE *ptable;
459bffd1b7aSPoul-Henning Kamp 	ISO_SUSP_HEADER *phead;
460bffd1b7aSPoul-Henning Kamp 	ISO_SUSP_HEADER *pend;
461df8bae1dSRodney W. Grimes 	struct buf *bp = NULL;
462df8bae1dSRodney W. Grimes 	char *pwhead;
463c4f02a89SMax Khon 	u_short c;
464df8bae1dSRodney W. Grimes 	int result;
465df8bae1dSRodney W. Grimes 
466df8bae1dSRodney W. Grimes 	/*
467df8bae1dSRodney W. Grimes 	 * Note: If name length is odd,
468df8bae1dSRodney W. Grimes 	 *	 it will be padding 1 byte after the name
469df8bae1dSRodney W. Grimes 	 */
470df8bae1dSRodney W. Grimes 	pwhead = isodir->name + isonum_711(isodir->name_len);
471df8bae1dSRodney W. Grimes 	if (!(isonum_711(isodir->name_len)&1))
472df8bae1dSRodney W. Grimes 		pwhead++;
473c4f02a89SMax Khon 	isochar(isodir->name, pwhead, ana->imp->joliet_level, &c, NULL,
474c4f02a89SMax Khon 		ana->imp->im_flags, ana->imp->im_d2l);
475df8bae1dSRodney W. Grimes 
476df8bae1dSRodney W. Grimes 	/* If it's not the '.' entry of the root dir obey SP field */
47744e568e2SDaniel C. Sobral 	if (c != 0 || isonum_733(isodir->extent) != ana->imp->root_extent)
478df8bae1dSRodney W. Grimes 		pwhead += ana->imp->rr_skip;
479df8bae1dSRodney W. Grimes 	else
480df8bae1dSRodney W. Grimes 		pwhead += ana->imp->rr_skip0;
481df8bae1dSRodney W. Grimes 
482df8bae1dSRodney W. Grimes 	phead = (ISO_SUSP_HEADER *)pwhead;
483df8bae1dSRodney W. Grimes 	pend = (ISO_SUSP_HEADER *)((char *)isodir + isonum_711(isodir->length));
484df8bae1dSRodney W. Grimes 
485df8bae1dSRodney W. Grimes 	result = 0;
486df8bae1dSRodney W. Grimes 	while (1) {
487df8bae1dSRodney W. Grimes 		ana->iso_ce_len = 0;
488df8bae1dSRodney W. Grimes 		/*
489df8bae1dSRodney W. Grimes 		 * Note: "pend" should be more than one SUSP header
490df8bae1dSRodney W. Grimes 		 */
491df8bae1dSRodney W. Grimes 		while (pend >= phead + 1) {
492df8bae1dSRodney W. Grimes 			if (isonum_711(phead->version) == 1) {
493df8bae1dSRodney W. Grimes 				for (ptable = table; ptable->func; ptable++) {
494df8bae1dSRodney W. Grimes 					if (*phead->type == *ptable->type
495df8bae1dSRodney W. Grimes 					    && phead->type[1] == ptable->type[1]) {
496df8bae1dSRodney W. Grimes 						result |= ptable->func(phead,ana);
497df8bae1dSRodney W. Grimes 						break;
498df8bae1dSRodney W. Grimes 					}
499df8bae1dSRodney W. Grimes 				}
500df8bae1dSRodney W. Grimes 				if (!ana->fields)
501df8bae1dSRodney W. Grimes 					break;
502df8bae1dSRodney W. Grimes 			}
503996c772fSJohn Dyson 			if (result&ISO_SUSP_STOP) {
504996c772fSJohn Dyson 				result &= ~ISO_SUSP_STOP;
505996c772fSJohn Dyson 				break;
506996c772fSJohn Dyson 			}
507996c772fSJohn Dyson 			/* plausibility check */
508996c772fSJohn Dyson 			if (isonum_711(phead->length) < sizeof(*phead))
509996c772fSJohn Dyson 				break;
510df8bae1dSRodney W. Grimes 			/*
511df8bae1dSRodney W. Grimes 			 * move to next SUSP
512df8bae1dSRodney W. Grimes 			 * Hopefully this works with newer versions, too
513df8bae1dSRodney W. Grimes 			 */
514df8bae1dSRodney W. Grimes 			phead = (ISO_SUSP_HEADER *)((char *)phead + isonum_711(phead->length));
515df8bae1dSRodney W. Grimes 		}
516df8bae1dSRodney W. Grimes 
517df8bae1dSRodney W. Grimes 		if (ana->fields && ana->iso_ce_len) {
518fa3cf6cdSKonstantin Belousov 			if (ana->iso_ce_blk >= ana->imp->volume_space_size ||
519fa3cf6cdSKonstantin Belousov 			    ana->iso_ce_off + ana->iso_ce_len >
520fa3cf6cdSKonstantin Belousov 			    ana->imp->logical_block_size)
521fa3cf6cdSKonstantin Belousov 				break;
522fa3cf6cdSKonstantin Belousov 			if (bp != NULL) {
523fa3cf6cdSKonstantin Belousov 				brelse(bp);
524fa3cf6cdSKonstantin Belousov 				bp = NULL;
525fa3cf6cdSKonstantin Belousov 			}
526fa3cf6cdSKonstantin Belousov 			if (bread(ana->imp->im_devvp,
527996c772fSJohn Dyson 			    ana->iso_ce_blk <<
528996c772fSJohn Dyson 			    (ana->imp->im_bshift - DEV_BSHIFT),
529fa3cf6cdSKonstantin Belousov 			    ana->imp->logical_block_size, NOCRED, &bp) != 0)
530df8bae1dSRodney W. Grimes 				/* what to do now? */
531df8bae1dSRodney W. Grimes 				break;
532996c772fSJohn Dyson 			phead = (ISO_SUSP_HEADER *)(bp->b_data + ana->iso_ce_off);
533df8bae1dSRodney W. Grimes 			pend = (ISO_SUSP_HEADER *) ((char *)phead + ana->iso_ce_len);
534df8bae1dSRodney W. Grimes 		} else
535df8bae1dSRodney W. Grimes 			break;
536df8bae1dSRodney W. Grimes 	}
537df8bae1dSRodney W. Grimes 	if (bp)
538df8bae1dSRodney W. Grimes 		brelse(bp);
539df8bae1dSRodney W. Grimes 	/*
540df8bae1dSRodney W. Grimes 	 * If we don't find the Basic SUSP stuffs, just set default value
541df8bae1dSRodney W. Grimes 	 *   (attribute/time stamp)
542df8bae1dSRodney W. Grimes 	 */
543df8bae1dSRodney W. Grimes 	for (ptable = table; ptable->func2; ptable++)
544df8bae1dSRodney W. Grimes 		if (!(ptable->result&result))
545df8bae1dSRodney W. Grimes 			ptable->func2(isodir,ana);
546df8bae1dSRodney W. Grimes 
547df8bae1dSRodney W. Grimes 	return result;
548df8bae1dSRodney W. Grimes }
549df8bae1dSRodney W. Grimes 
55010dd32cdSBruce Evans /*
551996c772fSJohn Dyson  * Get Attributes.
552996c772fSJohn Dyson  */
553996c772fSJohn Dyson /*
55410dd32cdSBruce Evans  * XXX the casts are bogus but will do for now.
55510dd32cdSBruce Evans  */
55610dd32cdSBruce Evans #define	BC	(rrt_func_t *)
557df8bae1dSRodney W. Grimes static RRIP_TABLE rrip_table_analyze[] = {
55810dd32cdSBruce Evans 	{ "PX", BC cd9660_rrip_attr,	cd9660_rrip_defattr,	ISO_SUSP_ATTR },
55910dd32cdSBruce Evans 	{ "TF", BC cd9660_rrip_tstamp,	cd9660_rrip_deftstamp,	ISO_SUSP_TSTAMP },
56010dd32cdSBruce Evans 	{ "PN", BC cd9660_rrip_device,	0,			ISO_SUSP_DEVICE },
56110dd32cdSBruce Evans 	{ "RR", BC cd9660_rrip_idflag,	0,			ISO_SUSP_IDFLAG },
56210dd32cdSBruce Evans 	{ "CE", BC cd9660_rrip_cont,	0,			ISO_SUSP_CONT },
56310dd32cdSBruce Evans 	{ "ST", BC cd9660_rrip_stop,	0,			ISO_SUSP_STOP },
564df8bae1dSRodney W. Grimes 	{ "",	0,			0,			0 }
565df8bae1dSRodney W. Grimes };
566df8bae1dSRodney W. Grimes 
567df8bae1dSRodney W. Grimes int
cd9660_rrip_analyze(struct iso_directory_record * isodir,struct iso_node * inop,struct iso_mnt * imp)568a5f59e85SEd Maste cd9660_rrip_analyze(struct iso_directory_record *isodir, struct iso_node *inop,
569a5f59e85SEd Maste     struct iso_mnt *imp)
570df8bae1dSRodney W. Grimes {
571df8bae1dSRodney W. Grimes 	ISO_RRIP_ANALYZE analyze;
572df8bae1dSRodney W. Grimes 
573df8bae1dSRodney W. Grimes 	analyze.inop = inop;
574df8bae1dSRodney W. Grimes 	analyze.imp = imp;
575df8bae1dSRodney W. Grimes 	analyze.fields = ISO_SUSP_ATTR|ISO_SUSP_TSTAMP|ISO_SUSP_DEVICE;
576df8bae1dSRodney W. Grimes 
577df8bae1dSRodney W. Grimes 	return cd9660_rrip_loop(isodir,&analyze,rrip_table_analyze);
578df8bae1dSRodney W. Grimes }
579df8bae1dSRodney W. Grimes 
580df8bae1dSRodney W. Grimes /*
581996c772fSJohn Dyson  * Get Alternate Name.
582df8bae1dSRodney W. Grimes  */
583df8bae1dSRodney W. Grimes static RRIP_TABLE rrip_table_getname[] = {
58410dd32cdSBruce Evans 	{ "NM", BC cd9660_rrip_altname,	cd9660_rrip_defname,	ISO_SUSP_ALTNAME },
58510dd32cdSBruce Evans 	{ "CL", BC cd9660_rrip_pclink,	0,			ISO_SUSP_CLINK|ISO_SUSP_PLINK },
58610dd32cdSBruce Evans 	{ "PL", BC cd9660_rrip_pclink,	0,			ISO_SUSP_CLINK|ISO_SUSP_PLINK },
58710dd32cdSBruce Evans 	{ "RE", BC cd9660_rrip_reldir,	0,			ISO_SUSP_RELDIR },
58810dd32cdSBruce Evans 	{ "RR", BC cd9660_rrip_idflag,	0,			ISO_SUSP_IDFLAG },
58910dd32cdSBruce Evans 	{ "CE", BC cd9660_rrip_cont,	0,			ISO_SUSP_CONT },
59010dd32cdSBruce Evans 	{ "ST", BC cd9660_rrip_stop,	0,			ISO_SUSP_STOP },
591df8bae1dSRodney W. Grimes 	{ "",	0,			0,			0 }
592df8bae1dSRodney W. Grimes };
593df8bae1dSRodney W. Grimes 
594df8bae1dSRodney W. Grimes int
cd9660_rrip_getname(struct iso_directory_record * isodir,char * outbuf,u_short * outlen,ino_t * inump,struct iso_mnt * imp)595a5f59e85SEd Maste cd9660_rrip_getname(struct iso_directory_record *isodir, char *outbuf,
596*96e69c8eSMark Johnston     u_short *outlen, ino_t *inump, struct iso_mnt *imp)
597df8bae1dSRodney W. Grimes {
598df8bae1dSRodney W. Grimes 	ISO_RRIP_ANALYZE analyze;
599df8bae1dSRodney W. Grimes 	RRIP_TABLE *tab;
600c4f02a89SMax Khon 	u_short c;
601df8bae1dSRodney W. Grimes 
602df8bae1dSRodney W. Grimes 	analyze.outbuf = outbuf;
603df8bae1dSRodney W. Grimes 	analyze.outlen = outlen;
604df8bae1dSRodney W. Grimes 	analyze.maxlen = NAME_MAX;
605df8bae1dSRodney W. Grimes 	analyze.inump = inump;
606df8bae1dSRodney W. Grimes 	analyze.imp = imp;
607df8bae1dSRodney W. Grimes 	analyze.fields = ISO_SUSP_ALTNAME|ISO_SUSP_RELDIR|ISO_SUSP_CLINK|ISO_SUSP_PLINK;
608df8bae1dSRodney W. Grimes 	*outlen = 0;
609df8bae1dSRodney W. Grimes 
61044e568e2SDaniel C. Sobral 	isochar(isodir->name, isodir->name + isonum_711(isodir->name_len),
611c4f02a89SMax Khon 		imp->joliet_level, &c, NULL, imp->im_flags, imp->im_d2l);
612df8bae1dSRodney W. Grimes 	tab = rrip_table_getname;
61344e568e2SDaniel C. Sobral 	if (c == 0 || c == 1) {
614df8bae1dSRodney W. Grimes 		cd9660_rrip_defname(isodir,&analyze);
615df8bae1dSRodney W. Grimes 
616df8bae1dSRodney W. Grimes 		analyze.fields &= ~ISO_SUSP_ALTNAME;
617df8bae1dSRodney W. Grimes 		tab++;
618df8bae1dSRodney W. Grimes 	}
619df8bae1dSRodney W. Grimes 
620df8bae1dSRodney W. Grimes 	return cd9660_rrip_loop(isodir,&analyze,tab);
621df8bae1dSRodney W. Grimes }
622df8bae1dSRodney W. Grimes 
623df8bae1dSRodney W. Grimes /*
624996c772fSJohn Dyson  * Get Symbolic Link.
625df8bae1dSRodney W. Grimes  */
626df8bae1dSRodney W. Grimes static RRIP_TABLE rrip_table_getsymname[] = {
62710dd32cdSBruce Evans 	{ "SL", BC cd9660_rrip_slink,	0,			ISO_SUSP_SLINK },
62810dd32cdSBruce Evans 	{ "RR", BC cd9660_rrip_idflag,	0,			ISO_SUSP_IDFLAG },
62910dd32cdSBruce Evans 	{ "CE", BC cd9660_rrip_cont,	0,			ISO_SUSP_CONT },
63010dd32cdSBruce Evans 	{ "ST", BC cd9660_rrip_stop,	0,			ISO_SUSP_STOP },
631df8bae1dSRodney W. Grimes 	{ "",	0,			0,			0 }
632df8bae1dSRodney W. Grimes };
633df8bae1dSRodney W. Grimes 
634df8bae1dSRodney W. Grimes int
cd9660_rrip_getsymname(struct iso_directory_record * isodir,char * outbuf,u_short * outlen,struct iso_mnt * imp)635a5f59e85SEd Maste cd9660_rrip_getsymname(struct iso_directory_record *isodir, char *outbuf,
636a5f59e85SEd Maste     u_short *outlen, struct iso_mnt *imp)
637df8bae1dSRodney W. Grimes {
638df8bae1dSRodney W. Grimes 	ISO_RRIP_ANALYZE analyze;
639df8bae1dSRodney W. Grimes 
640df8bae1dSRodney W. Grimes 	analyze.outbuf = outbuf;
641df8bae1dSRodney W. Grimes 	analyze.outlen = outlen;
642df8bae1dSRodney W. Grimes 	*outlen = 0;
643df8bae1dSRodney W. Grimes 	analyze.maxlen = MAXPATHLEN;
644df8bae1dSRodney W. Grimes 	analyze.cont = 1;		/* don't start with a slash */
645df8bae1dSRodney W. Grimes 	analyze.imp = imp;
646df8bae1dSRodney W. Grimes 	analyze.fields = ISO_SUSP_SLINK;
647df8bae1dSRodney W. Grimes 
648df8bae1dSRodney W. Grimes 	return (cd9660_rrip_loop(isodir,&analyze,rrip_table_getsymname)&ISO_SUSP_SLINK);
649df8bae1dSRodney W. Grimes }
650df8bae1dSRodney W. Grimes 
651df8bae1dSRodney W. Grimes static RRIP_TABLE rrip_table_extref[] = {
65210dd32cdSBruce Evans 	{ "ER", BC cd9660_rrip_extref,	0,			ISO_SUSP_EXTREF },
65310dd32cdSBruce Evans 	{ "CE", BC cd9660_rrip_cont,	0,			ISO_SUSP_CONT },
65410dd32cdSBruce Evans 	{ "ST", BC cd9660_rrip_stop,	0,			ISO_SUSP_STOP },
655df8bae1dSRodney W. Grimes 	{ "",	0,			0,			0 }
656df8bae1dSRodney W. Grimes };
657df8bae1dSRodney W. Grimes 
658df8bae1dSRodney W. Grimes /*
659df8bae1dSRodney W. Grimes  * Check for Rock Ridge Extension and return offset of its fields.
660996c772fSJohn Dyson  * Note: We insist on the ER field.
661df8bae1dSRodney W. Grimes  */
662df8bae1dSRodney W. Grimes int
cd9660_rrip_offset(struct iso_directory_record * isodir,struct iso_mnt * imp)663a5f59e85SEd Maste cd9660_rrip_offset(struct iso_directory_record *isodir, struct iso_mnt *imp)
664df8bae1dSRodney W. Grimes {
665df8bae1dSRodney W. Grimes 	ISO_RRIP_OFFSET *p;
666df8bae1dSRodney W. Grimes 	ISO_RRIP_ANALYZE analyze;
667df8bae1dSRodney W. Grimes 
668df8bae1dSRodney W. Grimes 	imp->rr_skip0 = 0;
669df8bae1dSRodney W. Grimes 	p = (ISO_RRIP_OFFSET *)(isodir->name + 1);
670df8bae1dSRodney W. Grimes 	if (bcmp(p,"SP\7\1\276\357",6)) {
671df8bae1dSRodney W. Grimes 		/* Maybe, it's a CDROM XA disc? */
672df8bae1dSRodney W. Grimes 		imp->rr_skip0 = 15;
673df8bae1dSRodney W. Grimes 		p = (ISO_RRIP_OFFSET *)((char *)p + 15);
674df8bae1dSRodney W. Grimes 		if (bcmp(p,"SP\7\1\276\357",6))
675df8bae1dSRodney W. Grimes 			return -1;
676df8bae1dSRodney W. Grimes 	}
677df8bae1dSRodney W. Grimes 
678df8bae1dSRodney W. Grimes 	analyze.imp = imp;
679df8bae1dSRodney W. Grimes 	analyze.fields = ISO_SUSP_EXTREF;
680df8bae1dSRodney W. Grimes 	if (!(cd9660_rrip_loop(isodir,&analyze,rrip_table_extref)&ISO_SUSP_EXTREF))
681df8bae1dSRodney W. Grimes 		return -1;
682df8bae1dSRodney W. Grimes 
683df8bae1dSRodney W. Grimes 	return isonum_711(p->skip);
684df8bae1dSRodney W. Grimes }
685