xref: /freebsd/sys/fs/cd9660/cd9660_node.c (revision cec0f20ce75cb0da74afcd4d65a9795fd0864604)
1df8bae1dSRodney W. Grimes /*-
2996c772fSJohn Dyson  * Copyright (c) 1982, 1986, 1989, 1994, 1995
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley
6df8bae1dSRodney W. Grimes  * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
7df8bae1dSRodney W. Grimes  * Support code is derived from software contributed to Berkeley
8df8bae1dSRodney W. Grimes  * by Atsushi Murai (amurai@spec.co.jp).
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
19df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
20df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
21df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
22df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
23df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
24df8bae1dSRodney W. Grimes  *    without specific prior written permission.
25df8bae1dSRodney W. Grimes  *
26df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
37df8bae1dSRodney W. Grimes  *
38df8bae1dSRodney W. Grimes  *	@(#)cd9660_node.c	8.2 (Berkeley) 1/23/94
39cec0f20cSPoul-Henning Kamp  * $Id: cd9660_node.c,v 1.20 1997/08/02 14:31:18 bde Exp $
40df8bae1dSRodney W. Grimes  */
41df8bae1dSRodney W. Grimes 
42df8bae1dSRodney W. Grimes #include <sys/param.h>
43df8bae1dSRodney W. Grimes #include <sys/systm.h>
44df8bae1dSRodney W. Grimes #include <sys/mount.h>
45df8bae1dSRodney W. Grimes #include <sys/proc.h>
46df8bae1dSRodney W. Grimes #include <sys/buf.h>
47df8bae1dSRodney W. Grimes #include <sys/vnode.h>
48df8bae1dSRodney W. Grimes #include <sys/malloc.h>
49df8bae1dSRodney W. Grimes #include <sys/stat.h>
50df8bae1dSRodney W. Grimes 
51df8bae1dSRodney W. Grimes #include <isofs/cd9660/iso.h>
52df8bae1dSRodney W. Grimes #include <isofs/cd9660/cd9660_node.h>
53996c772fSJohn Dyson #include <isofs/cd9660/cd9660_mount.h>
54df8bae1dSRodney W. Grimes 
55996c772fSJohn Dyson /*
56996c772fSJohn Dyson  * Structures associated with iso_node caching.
57996c772fSJohn Dyson  */
58996c772fSJohn Dyson struct iso_node **isohashtbl;
59996c772fSJohn Dyson u_long isohash;
60996c772fSJohn Dyson #define	INOHASH(device, inum)	(((device) + ((inum)>>12)) & isohash)
61996c772fSJohn Dyson struct simplelock cd9660_ihash_slock;
62df8bae1dSRodney W. Grimes 
63df8bae1dSRodney W. Grimes 
6410dd32cdSBruce Evans static unsigned	cd9660_chars2ui __P((unsigned char *begin, int len));
6510dd32cdSBruce Evans 
66df8bae1dSRodney W. Grimes /*
67df8bae1dSRodney W. Grimes  * Initialize hash links for inodes and dnodes.
68df8bae1dSRodney W. Grimes  */
6926f9a767SRodney W. Grimes int
70996c772fSJohn Dyson cd9660_init(vfsp)
71996c772fSJohn Dyson 	struct vfsconf *vfsp;
72df8bae1dSRodney W. Grimes {
73df8bae1dSRodney W. Grimes 
74996c772fSJohn Dyson 	isohashtbl = hashinit(desiredvnodes, M_ISOFSMNT, &isohash);
75996c772fSJohn Dyson 	simple_lock_init(&cd9660_ihash_slock);
7626f9a767SRodney W. Grimes 	return (0);
77df8bae1dSRodney W. Grimes }
78df8bae1dSRodney W. Grimes 
79df8bae1dSRodney W. Grimes 
80df8bae1dSRodney W. Grimes /*
81996c772fSJohn Dyson  * Use the device/inum pair to find the incore inode, and return a pointer
82996c772fSJohn Dyson  * to it. If it is in core, but locked, wait for it.
83df8bae1dSRodney W. Grimes  */
84996c772fSJohn Dyson struct vnode *
85996c772fSJohn Dyson cd9660_ihashget(dev, inum)
86996c772fSJohn Dyson 	dev_t dev;
87996c772fSJohn Dyson 	ino_t inum;
88df8bae1dSRodney W. Grimes {
89996c772fSJohn Dyson 	struct proc *p = curproc;		/* XXX */
90996c772fSJohn Dyson 	struct iso_node *ip;
91996c772fSJohn Dyson 	struct vnode *vp;
92df8bae1dSRodney W. Grimes 
93df8bae1dSRodney W. Grimes loop:
94996c772fSJohn Dyson 	simple_lock(&cd9660_ihash_slock);
95996c772fSJohn Dyson 	for (ip = isohashtbl[INOHASH(dev, inum)]; ip; ip = ip->i_next) {
96996c772fSJohn Dyson 		if (inum == ip->i_number && dev == ip->i_dev) {
97df8bae1dSRodney W. Grimes 			vp = ITOV(ip);
98996c772fSJohn Dyson 			simple_lock(&vp->v_interlock);
99996c772fSJohn Dyson 			simple_unlock(&cd9660_ihash_slock);
100996c772fSJohn Dyson 			if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, p))
101996c772fSJohn Dyson 				goto loop;
102996c772fSJohn Dyson 			return (vp);
103df8bae1dSRodney W. Grimes 		}
104df8bae1dSRodney W. Grimes 	}
105996c772fSJohn Dyson 	simple_unlock(&cd9660_ihash_slock);
106996c772fSJohn Dyson 	return (NULL);
107996c772fSJohn Dyson }
108df8bae1dSRodney W. Grimes 
109996c772fSJohn Dyson /*
110996c772fSJohn Dyson  * Insert the inode into the hash table, and return it locked.
111996c772fSJohn Dyson  */
112996c772fSJohn Dyson void
113996c772fSJohn Dyson cd9660_ihashins(ip)
114996c772fSJohn Dyson 	struct iso_node *ip;
115996c772fSJohn Dyson {
116996c772fSJohn Dyson 	struct proc *p = curproc;		/* XXX */
117996c772fSJohn Dyson 	struct iso_node **ipp, *iq;
118df8bae1dSRodney W. Grimes 
119996c772fSJohn Dyson 	simple_lock(&cd9660_ihash_slock);
120996c772fSJohn Dyson 	ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)];
121996c772fSJohn Dyson 	if (iq = *ipp)
122996c772fSJohn Dyson 		iq->i_prev = &ip->i_next;
123996c772fSJohn Dyson 	ip->i_next = iq;
124996c772fSJohn Dyson 	ip->i_prev = ipp;
125df8bae1dSRodney W. Grimes 	*ipp = ip;
126996c772fSJohn Dyson 	simple_unlock(&cd9660_ihash_slock);
127996c772fSJohn Dyson 
128996c772fSJohn Dyson 	lockmgr(&ip->i_lock, LK_EXCLUSIVE, (struct simplelock *)0, p);
129df8bae1dSRodney W. Grimes }
130df8bae1dSRodney W. Grimes 
131df8bae1dSRodney W. Grimes /*
132996c772fSJohn Dyson  * Remove the inode from the hash table.
133df8bae1dSRodney W. Grimes  */
134996c772fSJohn Dyson void
135996c772fSJohn Dyson cd9660_ihashrem(ip)
136df8bae1dSRodney W. Grimes 	register struct iso_node *ip;
137df8bae1dSRodney W. Grimes {
138996c772fSJohn Dyson 	register struct iso_node *iq;
139df8bae1dSRodney W. Grimes 
140996c772fSJohn Dyson 	simple_lock(&cd9660_ihash_slock);
141996c772fSJohn Dyson 	if (iq = ip->i_next)
142996c772fSJohn Dyson 		iq->i_prev = ip->i_prev;
143996c772fSJohn Dyson 	*ip->i_prev = iq;
144996c772fSJohn Dyson #ifdef DIAGNOSTIC
145996c772fSJohn Dyson 	ip->i_next = NULL;
146996c772fSJohn Dyson 	ip->i_prev = NULL;
147996c772fSJohn Dyson #endif
148996c772fSJohn Dyson 	simple_unlock(&cd9660_ihash_slock);
149df8bae1dSRodney W. Grimes }
150df8bae1dSRodney W. Grimes 
151df8bae1dSRodney W. Grimes /*
152df8bae1dSRodney W. Grimes  * Last reference to an inode, write the inode out and if necessary,
153df8bae1dSRodney W. Grimes  * truncate and deallocate the file.
154df8bae1dSRodney W. Grimes  */
155df8bae1dSRodney W. Grimes int
156df8bae1dSRodney W. Grimes cd9660_inactive(ap)
157df8bae1dSRodney W. Grimes 	struct vop_inactive_args /* {
158df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
159996c772fSJohn Dyson 		struct proc *a_p;
160df8bae1dSRodney W. Grimes 	} */ *ap;
161df8bae1dSRodney W. Grimes {
162df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
163996c772fSJohn Dyson 	struct proc *p = ap->a_p;
164df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
1651295d82eSGary Palmer 	int error = 0;
166df8bae1dSRodney W. Grimes 
167df8bae1dSRodney W. Grimes 	if (prtactive && vp->v_usecount != 0)
168df8bae1dSRodney W. Grimes 		vprint("cd9660_inactive: pushing active", vp);
169df8bae1dSRodney W. Grimes 
170df8bae1dSRodney W. Grimes 	ip->i_flag = 0;
171996c772fSJohn Dyson 	VOP_UNLOCK(vp, 0, p);
172df8bae1dSRodney W. Grimes 	/*
173df8bae1dSRodney W. Grimes 	 * If we are done with the inode, reclaim it
174df8bae1dSRodney W. Grimes 	 * so that it can be reused immediately.
175df8bae1dSRodney W. Grimes 	 */
176996c772fSJohn Dyson 	if (ip->inode.iso_mode == 0)
177996c772fSJohn Dyson 		vrecycle(vp, (struct simplelock *)0, p);
178df8bae1dSRodney W. Grimes 	return error;
179df8bae1dSRodney W. Grimes }
180df8bae1dSRodney W. Grimes 
181df8bae1dSRodney W. Grimes /*
182df8bae1dSRodney W. Grimes  * Reclaim an inode so that it can be used for other purposes.
183df8bae1dSRodney W. Grimes  */
184df8bae1dSRodney W. Grimes int
185df8bae1dSRodney W. Grimes cd9660_reclaim(ap)
186df8bae1dSRodney W. Grimes 	struct vop_reclaim_args /* {
187df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
188996c772fSJohn Dyson 		struct proc *a_p;
189df8bae1dSRodney W. Grimes 	} */ *ap;
190df8bae1dSRodney W. Grimes {
191df8bae1dSRodney W. Grimes 	register struct vnode *vp = ap->a_vp;
192df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
193df8bae1dSRodney W. Grimes 
194df8bae1dSRodney W. Grimes 	if (prtactive && vp->v_usecount != 0)
195df8bae1dSRodney W. Grimes 		vprint("cd9660_reclaim: pushing active", vp);
196df8bae1dSRodney W. Grimes 	/*
197df8bae1dSRodney W. Grimes 	 * Remove the inode from its hash chain.
198df8bae1dSRodney W. Grimes 	 */
199996c772fSJohn Dyson 	cd9660_ihashrem(ip);
200df8bae1dSRodney W. Grimes 	/*
201df8bae1dSRodney W. Grimes 	 * Purge old data structures associated with the inode.
202df8bae1dSRodney W. Grimes 	 */
203df8bae1dSRodney W. Grimes 	cache_purge(vp);
204df8bae1dSRodney W. Grimes 	if (ip->i_devvp) {
205df8bae1dSRodney W. Grimes 		vrele(ip->i_devvp);
206df8bae1dSRodney W. Grimes 		ip->i_devvp = 0;
207df8bae1dSRodney W. Grimes 	}
208df8bae1dSRodney W. Grimes 	FREE(vp->v_data, M_ISOFSNODE);
209df8bae1dSRodney W. Grimes 	vp->v_data = NULL;
21026f9a767SRodney W. Grimes 	return (0);
211df8bae1dSRodney W. Grimes }
212df8bae1dSRodney W. Grimes 
213df8bae1dSRodney W. Grimes /*
214df8bae1dSRodney W. Grimes  * File attributes
215df8bae1dSRodney W. Grimes  */
216df8bae1dSRodney W. Grimes void
217988fa8efSJoerg Wunsch cd9660_defattr(isodir, inop, bp, ftype)
218df8bae1dSRodney W. Grimes 	struct iso_directory_record *isodir;
219df8bae1dSRodney W. Grimes 	struct iso_node *inop;
220df8bae1dSRodney W. Grimes 	struct buf *bp;
221988fa8efSJoerg Wunsch 	enum ISO_FTYPE ftype;
222df8bae1dSRodney W. Grimes {
223df8bae1dSRodney W. Grimes 	struct buf *bp2 = NULL;
224df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
225df8bae1dSRodney W. Grimes 	struct iso_extended_attributes *ap = NULL;
226df8bae1dSRodney W. Grimes 	int off;
227df8bae1dSRodney W. Grimes 
228988fa8efSJoerg Wunsch 	/* high sierra does not have timezone data, flag is one byte ahead */
229988fa8efSJoerg Wunsch 	if (isonum_711(ftype == ISO_FTYPE_HIGH_SIERRA?
230988fa8efSJoerg Wunsch 		       &isodir->date[6]: isodir->flags)&2) {
231df8bae1dSRodney W. Grimes 		inop->inode.iso_mode = S_IFDIR;
232df8bae1dSRodney W. Grimes 		/*
233df8bae1dSRodney W. Grimes 		 * If we return 2, fts() will assume there are no subdirectories
234df8bae1dSRodney W. Grimes 		 * (just links for the path and .), so instead we return 1.
235df8bae1dSRodney W. Grimes 		 */
236df8bae1dSRodney W. Grimes 		inop->inode.iso_links = 1;
237df8bae1dSRodney W. Grimes 	} else {
238df8bae1dSRodney W. Grimes 		inop->inode.iso_mode = S_IFREG;
239df8bae1dSRodney W. Grimes 		inop->inode.iso_links = 1;
240df8bae1dSRodney W. Grimes 	}
241df8bae1dSRodney W. Grimes 	if (!bp
242df8bae1dSRodney W. Grimes 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
243df8bae1dSRodney W. Grimes 	    && (off = isonum_711(isodir->ext_attr_length))) {
244cec0f20cSPoul-Henning Kamp 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
245996c772fSJohn Dyson 			     &bp2);
246df8bae1dSRodney W. Grimes 		bp = bp2;
247df8bae1dSRodney W. Grimes 	}
248df8bae1dSRodney W. Grimes 	if (bp) {
249996c772fSJohn Dyson 		ap = (struct iso_extended_attributes *)bp->b_data;
250df8bae1dSRodney W. Grimes 
251df8bae1dSRodney W. Grimes 		if (isonum_711(ap->version) == 1) {
252df8bae1dSRodney W. Grimes 			if (!(ap->perm[0]&0x40))
253df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VEXEC >> 6;
254df8bae1dSRodney W. Grimes 			if (!(ap->perm[0]&0x10))
255df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VREAD >> 6;
256df8bae1dSRodney W. Grimes 			if (!(ap->perm[0]&4))
257df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VEXEC >> 3;
258df8bae1dSRodney W. Grimes 			if (!(ap->perm[0]&1))
259df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VREAD >> 3;
260df8bae1dSRodney W. Grimes 			if (!(ap->perm[1]&0x40))
261df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VEXEC;
262df8bae1dSRodney W. Grimes 			if (!(ap->perm[1]&0x10))
263df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VREAD;
264df8bae1dSRodney W. Grimes 			inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
265df8bae1dSRodney W. Grimes 			inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
266df8bae1dSRodney W. Grimes 		} else
267df8bae1dSRodney W. Grimes 			ap = NULL;
268df8bae1dSRodney W. Grimes 	}
269df8bae1dSRodney W. Grimes 	if (!ap) {
270df8bae1dSRodney W. Grimes 		inop->inode.iso_mode |= VREAD|VEXEC|(VREAD|VEXEC)>>3|(VREAD|VEXEC)>>6;
271df8bae1dSRodney W. Grimes 		inop->inode.iso_uid = (uid_t)0;
272df8bae1dSRodney W. Grimes 		inop->inode.iso_gid = (gid_t)0;
273df8bae1dSRodney W. Grimes 	}
274df8bae1dSRodney W. Grimes 	if (bp2)
275df8bae1dSRodney W. Grimes 		brelse(bp2);
276df8bae1dSRodney W. Grimes }
277df8bae1dSRodney W. Grimes 
278df8bae1dSRodney W. Grimes /*
279df8bae1dSRodney W. Grimes  * Time stamps
280df8bae1dSRodney W. Grimes  */
281df8bae1dSRodney W. Grimes void
282988fa8efSJoerg Wunsch cd9660_deftstamp(isodir,inop,bp,ftype)
283df8bae1dSRodney W. Grimes 	struct iso_directory_record *isodir;
284df8bae1dSRodney W. Grimes 	struct iso_node *inop;
285df8bae1dSRodney W. Grimes 	struct buf *bp;
286988fa8efSJoerg Wunsch 	enum ISO_FTYPE ftype;
287df8bae1dSRodney W. Grimes {
288df8bae1dSRodney W. Grimes 	struct buf *bp2 = NULL;
289df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
290df8bae1dSRodney W. Grimes 	struct iso_extended_attributes *ap = NULL;
291df8bae1dSRodney W. Grimes 	int off;
292df8bae1dSRodney W. Grimes 
293df8bae1dSRodney W. Grimes 	if (!bp
294df8bae1dSRodney W. Grimes 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
295df8bae1dSRodney W. Grimes 	    && (off = isonum_711(isodir->ext_attr_length))) {
296cec0f20cSPoul-Henning Kamp 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
297996c772fSJohn Dyson 			     &bp2);
298df8bae1dSRodney W. Grimes 		bp = bp2;
299df8bae1dSRodney W. Grimes 	}
300df8bae1dSRodney W. Grimes 	if (bp) {
301996c772fSJohn Dyson 		ap = (struct iso_extended_attributes *)bp->b_data;
302df8bae1dSRodney W. Grimes 
303596d40b9SBruce Evans 		if (ftype != ISO_FTYPE_HIGH_SIERRA
304596d40b9SBruce Evans 		    && isonum_711(ap->version) == 1) {
305df8bae1dSRodney W. Grimes 			if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
306df8bae1dSRodney W. Grimes 				cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
307df8bae1dSRodney W. Grimes 			if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
308df8bae1dSRodney W. Grimes 				inop->inode.iso_ctime = inop->inode.iso_atime;
309df8bae1dSRodney W. Grimes 			if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
310df8bae1dSRodney W. Grimes 				inop->inode.iso_mtime = inop->inode.iso_ctime;
311df8bae1dSRodney W. Grimes 		} else
312df8bae1dSRodney W. Grimes 			ap = NULL;
313df8bae1dSRodney W. Grimes 	}
314df8bae1dSRodney W. Grimes 	if (!ap) {
315988fa8efSJoerg Wunsch 		cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime,ftype);
316df8bae1dSRodney W. Grimes 		inop->inode.iso_atime = inop->inode.iso_ctime;
317df8bae1dSRodney W. Grimes 		inop->inode.iso_mtime = inop->inode.iso_ctime;
318df8bae1dSRodney W. Grimes 	}
319df8bae1dSRodney W. Grimes 	if (bp2)
320df8bae1dSRodney W. Grimes 		brelse(bp2);
321df8bae1dSRodney W. Grimes }
322df8bae1dSRodney W. Grimes 
323df8bae1dSRodney W. Grimes int
324988fa8efSJoerg Wunsch cd9660_tstamp_conv7(pi,pu,ftype)
325996c772fSJohn Dyson 	u_char *pi;
3261dbaf90cSBruce Evans 	struct timespec *pu;
327988fa8efSJoerg Wunsch 	enum ISO_FTYPE ftype;
328df8bae1dSRodney W. Grimes {
329df8bae1dSRodney W. Grimes 	int crtime, days;
330df8bae1dSRodney W. Grimes 	int y, m, d, hour, minute, second, tz;
331df8bae1dSRodney W. Grimes 
332df8bae1dSRodney W. Grimes 	y = pi[0] + 1900;
333df8bae1dSRodney W. Grimes 	m = pi[1];
334df8bae1dSRodney W. Grimes 	d = pi[2];
335df8bae1dSRodney W. Grimes 	hour = pi[3];
336df8bae1dSRodney W. Grimes 	minute = pi[4];
337df8bae1dSRodney W. Grimes 	second = pi[5];
338988fa8efSJoerg Wunsch 	if(ftype != ISO_FTYPE_HIGH_SIERRA)
339df8bae1dSRodney W. Grimes 		tz = pi[6];
340988fa8efSJoerg Wunsch 	else
341988fa8efSJoerg Wunsch 		/* original high sierra misses timezone data */
342988fa8efSJoerg Wunsch 		tz = 0;
343df8bae1dSRodney W. Grimes 
344df8bae1dSRodney W. Grimes 	if (y < 1970) {
34595a1574eSNate Williams 		pu->tv_sec  = 0;
34695a1574eSNate Williams 		pu->tv_nsec = 0;
347df8bae1dSRodney W. Grimes 		return 0;
348df8bae1dSRodney W. Grimes 	} else {
349df8bae1dSRodney W. Grimes #ifdef	ORIGINAL
350df8bae1dSRodney W. Grimes 		/* computes day number relative to Sept. 19th,1989 */
351df8bae1dSRodney W. Grimes 		/* don't even *THINK* about changing formula. It works! */
352df8bae1dSRodney W. Grimes 		days = 367*(y-1980)-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4+275*m/9+d-100;
353df8bae1dSRodney W. Grimes #else
354df8bae1dSRodney W. Grimes 		/*
355df8bae1dSRodney W. Grimes 		 * Changed :-) to make it relative to Jan. 1st, 1970
356df8bae1dSRodney W. Grimes 		 * and to disambiguate negative division
357df8bae1dSRodney W. Grimes 		 */
358df8bae1dSRodney W. Grimes 		days = 367*(y-1960)-7*(y+(m+9)/12)/4-3*((y+(m+9)/12-1)/100+1)/4+275*m/9+d-239;
359df8bae1dSRodney W. Grimes #endif
360df8bae1dSRodney W. Grimes 		crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
361df8bae1dSRodney W. Grimes 
362df8bae1dSRodney W. Grimes 		/* timezone offset is unreliable on some disks */
363df8bae1dSRodney W. Grimes 		if (-48 <= tz && tz <= 52)
3642d091ecfSBruce Evans 			crtime -= tz * 15 * 60;
365df8bae1dSRodney W. Grimes 	}
36695a1574eSNate Williams 	pu->tv_sec  = crtime;
36795a1574eSNate Williams 	pu->tv_nsec = 0;
368df8bae1dSRodney W. Grimes 	return 1;
369df8bae1dSRodney W. Grimes }
370df8bae1dSRodney W. Grimes 
371996c772fSJohn Dyson static u_int
372df8bae1dSRodney W. Grimes cd9660_chars2ui(begin,len)
373996c772fSJohn Dyson 	u_char *begin;
374df8bae1dSRodney W. Grimes 	int len;
375df8bae1dSRodney W. Grimes {
376996c772fSJohn Dyson 	u_int rc;
377df8bae1dSRodney W. Grimes 
378df8bae1dSRodney W. Grimes 	for (rc = 0; --len >= 0;) {
379df8bae1dSRodney W. Grimes 		rc *= 10;
380df8bae1dSRodney W. Grimes 		rc += *begin++ - '0';
381df8bae1dSRodney W. Grimes 	}
382df8bae1dSRodney W. Grimes 	return rc;
383df8bae1dSRodney W. Grimes }
384df8bae1dSRodney W. Grimes 
385df8bae1dSRodney W. Grimes int
386df8bae1dSRodney W. Grimes cd9660_tstamp_conv17(pi,pu)
387996c772fSJohn Dyson 	u_char *pi;
3881dbaf90cSBruce Evans 	struct timespec *pu;
389df8bae1dSRodney W. Grimes {
390996c772fSJohn Dyson 	u_char buf[7];
391df8bae1dSRodney W. Grimes 
392df8bae1dSRodney W. Grimes 	/* year:"0001"-"9999" -> -1900  */
393df8bae1dSRodney W. Grimes 	buf[0] = cd9660_chars2ui(pi,4) - 1900;
394df8bae1dSRodney W. Grimes 
395df8bae1dSRodney W. Grimes 	/* month: " 1"-"12"   -> 1 - 12 */
396df8bae1dSRodney W. Grimes 	buf[1] = cd9660_chars2ui(pi + 4,2);
397df8bae1dSRodney W. Grimes 
398df8bae1dSRodney W. Grimes 	/* day:	  " 1"-"31"   -> 1 - 31 */
399df8bae1dSRodney W. Grimes 	buf[2] = cd9660_chars2ui(pi + 6,2);
400df8bae1dSRodney W. Grimes 
401df8bae1dSRodney W. Grimes 	/* hour:  " 0"-"23"   -> 0 - 23 */
402df8bae1dSRodney W. Grimes 	buf[3] = cd9660_chars2ui(pi + 8,2);
403df8bae1dSRodney W. Grimes 
404df8bae1dSRodney W. Grimes 	/* minute:" 0"-"59"   -> 0 - 59 */
405df8bae1dSRodney W. Grimes 	buf[4] = cd9660_chars2ui(pi + 10,2);
406df8bae1dSRodney W. Grimes 
407df8bae1dSRodney W. Grimes 	/* second:" 0"-"59"   -> 0 - 59 */
408df8bae1dSRodney W. Grimes 	buf[5] = cd9660_chars2ui(pi + 12,2);
409df8bae1dSRodney W. Grimes 
410df8bae1dSRodney W. Grimes 	/* difference of GMT */
411df8bae1dSRodney W. Grimes 	buf[6] = pi[16];
412df8bae1dSRodney W. Grimes 
413988fa8efSJoerg Wunsch 	return cd9660_tstamp_conv7(buf, pu, ISO_FTYPE_DEFAULT);
414df8bae1dSRodney W. Grimes }
415df8bae1dSRodney W. Grimes 
416996c772fSJohn Dyson ino_t
417996c772fSJohn Dyson isodirino(isodir, imp)
418df8bae1dSRodney W. Grimes 	struct iso_directory_record *isodir;
419df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
420df8bae1dSRodney W. Grimes {
421996c772fSJohn Dyson 	ino_t ino;
422996c772fSJohn Dyson 
423996c772fSJohn Dyson 	ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
424996c772fSJohn Dyson 	      << imp->im_bshift;
425996c772fSJohn Dyson 	return (ino);
426df8bae1dSRodney W. Grimes }
427