xref: /freebsd/sys/fs/cd9660/cd9660_node.c (revision 89c9a483526f9340e86daccfb8a575cf2d153821)
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
39c3aac50fSPeter Wemm  * $FreeBSD$
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>
459626b608SPoul-Henning Kamp #include <sys/bio.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>
501b367556SJason Evans #include <sys/mutex.h>
51a18b1f1dSJason Evans 
52df8bae1dSRodney W. Grimes #include <isofs/cd9660/iso.h>
53df8bae1dSRodney W. Grimes #include <isofs/cd9660/cd9660_node.h>
54996c772fSJohn Dyson #include <isofs/cd9660/cd9660_mount.h>
55df8bae1dSRodney W. Grimes 
56996c772fSJohn Dyson /*
57996c772fSJohn Dyson  * Structures associated with iso_node caching.
58996c772fSJohn Dyson  */
59303b270bSEivind Eklund static struct iso_node **isohashtbl;
60303b270bSEivind Eklund static u_long isohash;
61bfbb9ce6SPoul-Henning Kamp #define	INOHASH(device, inum)	((minor(device) + ((inum)>>12)) & isohash)
621b367556SJason Evans static struct mtx cd9660_ihash_mtx;
63df8bae1dSRodney W. Grimes 
6489c9a483SAlfred Perlstein static void cd9660_ihashrem(struct iso_node *);
6589c9a483SAlfred Perlstein static unsigned	cd9660_chars2ui(unsigned char *begin, int len);
6610dd32cdSBruce Evans 
67df8bae1dSRodney W. Grimes /*
68df8bae1dSRodney W. Grimes  * Initialize hash links for inodes and dnodes.
69df8bae1dSRodney W. Grimes  */
7026f9a767SRodney W. Grimes int
71996c772fSJohn Dyson cd9660_init(vfsp)
72996c772fSJohn Dyson 	struct vfsconf *vfsp;
73df8bae1dSRodney W. Grimes {
74df8bae1dSRodney W. Grimes 
75996c772fSJohn Dyson 	isohashtbl = hashinit(desiredvnodes, M_ISOFSMNT, &isohash);
761b367556SJason Evans 	mtx_init(&cd9660_ihash_mtx, "cd9660_ihash", MTX_DEF);
7726f9a767SRodney W. Grimes 	return (0);
78df8bae1dSRodney W. Grimes }
79df8bae1dSRodney W. Grimes 
806843189aSBoris Popov int
816843189aSBoris Popov cd9660_uninit(vfsp)
826843189aSBoris Popov 	struct vfsconf *vfsp;
836843189aSBoris Popov {
846843189aSBoris Popov 
856843189aSBoris Popov 	if (isohashtbl != NULL)
866843189aSBoris Popov 		free(isohashtbl, M_ISOFSMNT);
876843189aSBoris Popov 	return (0);
886843189aSBoris Popov }
896843189aSBoris Popov 
90df8bae1dSRodney W. Grimes 
91df8bae1dSRodney W. Grimes /*
92996c772fSJohn Dyson  * Use the device/inum pair to find the incore inode, and return a pointer
93996c772fSJohn Dyson  * to it. If it is in core, but locked, wait for it.
94df8bae1dSRodney W. Grimes  */
95a0595d02SKirk McKusick int
96a0595d02SKirk McKusick cd9660_ihashget(dev, inum, flags, vpp)
97996c772fSJohn Dyson 	dev_t dev;
98996c772fSJohn Dyson 	ino_t inum;
99a0595d02SKirk McKusick 	int flags;
100a0595d02SKirk McKusick 	struct vnode **vpp;
101df8bae1dSRodney W. Grimes {
102b40ce416SJulian Elischer 	struct thread *td = curthread;		/* XXX */
103996c772fSJohn Dyson 	struct iso_node *ip;
104996c772fSJohn Dyson 	struct vnode *vp;
105a0595d02SKirk McKusick 	int error;
106df8bae1dSRodney W. Grimes 
107a0595d02SKirk McKusick 	*vpp = NULL;
108df8bae1dSRodney W. Grimes loop:
1099ed346baSBosko Milekic 	mtx_lock(&cd9660_ihash_mtx);
110996c772fSJohn Dyson 	for (ip = isohashtbl[INOHASH(dev, inum)]; ip; ip = ip->i_next) {
111996c772fSJohn Dyson 		if (inum == ip->i_number && dev == ip->i_dev) {
112df8bae1dSRodney W. Grimes 			vp = ITOV(ip);
1139ed346baSBosko Milekic 			mtx_lock(&vp->v_interlock);
1149ed346baSBosko Milekic 			mtx_unlock(&cd9660_ihash_mtx);
115a0595d02SKirk McKusick 			error = vget(vp, flags | LK_INTERLOCK, td);
116a0595d02SKirk McKusick 			if (error == ENOENT)
117996c772fSJohn Dyson 				goto loop;
118a0595d02SKirk McKusick 			if (error)
119a0595d02SKirk McKusick 				return (error);
120a0595d02SKirk McKusick 			*vpp = vp;
121a0595d02SKirk McKusick 			return (0);
122df8bae1dSRodney W. Grimes 		}
123df8bae1dSRodney W. Grimes 	}
1249ed346baSBosko Milekic 	mtx_unlock(&cd9660_ihash_mtx);
125a0595d02SKirk McKusick 	return (0);
126996c772fSJohn Dyson }
127df8bae1dSRodney W. Grimes 
128996c772fSJohn Dyson /*
129996c772fSJohn Dyson  * Insert the inode into the hash table, and return it locked.
130996c772fSJohn Dyson  */
131996c772fSJohn Dyson void
132996c772fSJohn Dyson cd9660_ihashins(ip)
133996c772fSJohn Dyson 	struct iso_node *ip;
134996c772fSJohn Dyson {
135996c772fSJohn Dyson 	struct iso_node **ipp, *iq;
136df8bae1dSRodney W. Grimes 
1379ed346baSBosko Milekic 	mtx_lock(&cd9660_ihash_mtx);
138996c772fSJohn Dyson 	ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)];
139d254af07SMatthew Dillon 	if ((iq = *ipp) != NULL)
140996c772fSJohn Dyson 		iq->i_prev = &ip->i_next;
141996c772fSJohn Dyson 	ip->i_next = iq;
142996c772fSJohn Dyson 	ip->i_prev = ipp;
143df8bae1dSRodney W. Grimes 	*ipp = ip;
1449ed346baSBosko Milekic 	mtx_unlock(&cd9660_ihash_mtx);
145996c772fSJohn Dyson 
146b40ce416SJulian Elischer 	lockmgr(&ip->i_vnode->v_lock, LK_EXCLUSIVE, (struct mtx *)0, curthread);
147df8bae1dSRodney W. Grimes }
148df8bae1dSRodney W. Grimes 
149df8bae1dSRodney W. Grimes /*
150996c772fSJohn Dyson  * Remove the inode from the hash table.
151df8bae1dSRodney W. Grimes  */
152f041a9bdSPoul-Henning Kamp static void
153996c772fSJohn Dyson cd9660_ihashrem(ip)
154df8bae1dSRodney W. Grimes 	register struct iso_node *ip;
155df8bae1dSRodney W. Grimes {
156996c772fSJohn Dyson 	register struct iso_node *iq;
157df8bae1dSRodney W. Grimes 
1589ed346baSBosko Milekic 	mtx_lock(&cd9660_ihash_mtx);
159d254af07SMatthew Dillon 	if ((iq = ip->i_next) != NULL)
160996c772fSJohn Dyson 		iq->i_prev = ip->i_prev;
161996c772fSJohn Dyson 	*ip->i_prev = iq;
162996c772fSJohn Dyson #ifdef DIAGNOSTIC
163996c772fSJohn Dyson 	ip->i_next = NULL;
164996c772fSJohn Dyson 	ip->i_prev = NULL;
165996c772fSJohn Dyson #endif
1669ed346baSBosko Milekic 	mtx_unlock(&cd9660_ihash_mtx);
167df8bae1dSRodney W. Grimes }
168df8bae1dSRodney W. Grimes 
169df8bae1dSRodney W. Grimes /*
170df8bae1dSRodney W. Grimes  * Last reference to an inode, write the inode out and if necessary,
171df8bae1dSRodney W. Grimes  * truncate and deallocate the file.
172df8bae1dSRodney W. Grimes  */
173df8bae1dSRodney W. Grimes int
174df8bae1dSRodney W. Grimes cd9660_inactive(ap)
175df8bae1dSRodney W. Grimes 	struct vop_inactive_args /* {
176df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
177b40ce416SJulian Elischer 		struct thread *a_td;
178df8bae1dSRodney W. Grimes 	} */ *ap;
179df8bae1dSRodney W. Grimes {
180df8bae1dSRodney W. Grimes 	struct vnode *vp = ap->a_vp;
181b40ce416SJulian Elischer 	struct thread *td = ap->a_td;
182df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
1831295d82eSGary Palmer 	int error = 0;
184df8bae1dSRodney W. Grimes 
185df8bae1dSRodney W. Grimes 	if (prtactive && vp->v_usecount != 0)
186df8bae1dSRodney W. Grimes 		vprint("cd9660_inactive: pushing active", vp);
187df8bae1dSRodney W. Grimes 
188df8bae1dSRodney W. Grimes 	ip->i_flag = 0;
189b40ce416SJulian Elischer 	VOP_UNLOCK(vp, 0, td);
190df8bae1dSRodney W. Grimes 	/*
191df8bae1dSRodney W. Grimes 	 * If we are done with the inode, reclaim it
192df8bae1dSRodney W. Grimes 	 * so that it can be reused immediately.
193df8bae1dSRodney W. Grimes 	 */
194996c772fSJohn Dyson 	if (ip->inode.iso_mode == 0)
195b40ce416SJulian Elischer 		vrecycle(vp, NULL, td);
196df8bae1dSRodney W. Grimes 	return error;
197df8bae1dSRodney W. Grimes }
198df8bae1dSRodney W. Grimes 
199df8bae1dSRodney W. Grimes /*
200df8bae1dSRodney W. Grimes  * Reclaim an inode so that it can be used for other purposes.
201df8bae1dSRodney W. Grimes  */
202df8bae1dSRodney W. Grimes int
203df8bae1dSRodney W. Grimes cd9660_reclaim(ap)
204df8bae1dSRodney W. Grimes 	struct vop_reclaim_args /* {
205df8bae1dSRodney W. Grimes 		struct vnode *a_vp;
206b40ce416SJulian Elischer 		struct thread *a_td;
207df8bae1dSRodney W. Grimes 	} */ *ap;
208df8bae1dSRodney W. Grimes {
209df8bae1dSRodney W. Grimes 	register struct vnode *vp = ap->a_vp;
210df8bae1dSRodney W. Grimes 	register struct iso_node *ip = VTOI(vp);
211df8bae1dSRodney W. Grimes 
212df8bae1dSRodney W. Grimes 	if (prtactive && vp->v_usecount != 0)
213df8bae1dSRodney W. Grimes 		vprint("cd9660_reclaim: pushing active", vp);
214df8bae1dSRodney W. Grimes 	/*
215df8bae1dSRodney W. Grimes 	 * Remove the inode from its hash chain.
216df8bae1dSRodney W. Grimes 	 */
217996c772fSJohn Dyson 	cd9660_ihashrem(ip);
218df8bae1dSRodney W. Grimes 	/*
219df8bae1dSRodney W. Grimes 	 * Purge old data structures associated with the inode.
220df8bae1dSRodney W. Grimes 	 */
221df8bae1dSRodney W. Grimes 	cache_purge(vp);
222df8bae1dSRodney W. Grimes 	if (ip->i_devvp) {
223df8bae1dSRodney W. Grimes 		vrele(ip->i_devvp);
224df8bae1dSRodney W. Grimes 		ip->i_devvp = 0;
225df8bae1dSRodney W. Grimes 	}
226a18b1f1dSJason Evans 	lockdestroy(&ip->i_vnode->v_lock);
227df8bae1dSRodney W. Grimes 	FREE(vp->v_data, M_ISOFSNODE);
228df8bae1dSRodney W. Grimes 	vp->v_data = NULL;
22926f9a767SRodney W. Grimes 	return (0);
230df8bae1dSRodney W. Grimes }
231df8bae1dSRodney W. Grimes 
232df8bae1dSRodney W. Grimes /*
233df8bae1dSRodney W. Grimes  * File attributes
234df8bae1dSRodney W. Grimes  */
235df8bae1dSRodney W. Grimes void
236988fa8efSJoerg Wunsch cd9660_defattr(isodir, inop, bp, ftype)
237df8bae1dSRodney W. Grimes 	struct iso_directory_record *isodir;
238df8bae1dSRodney W. Grimes 	struct iso_node *inop;
239df8bae1dSRodney W. Grimes 	struct buf *bp;
240988fa8efSJoerg Wunsch 	enum ISO_FTYPE ftype;
241df8bae1dSRodney W. Grimes {
242df8bae1dSRodney W. Grimes 	struct buf *bp2 = NULL;
243df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
244df8bae1dSRodney W. Grimes 	struct iso_extended_attributes *ap = NULL;
245df8bae1dSRodney W. Grimes 	int off;
246df8bae1dSRodney W. Grimes 
247988fa8efSJoerg Wunsch 	/* high sierra does not have timezone data, flag is one byte ahead */
248988fa8efSJoerg Wunsch 	if (isonum_711(ftype == ISO_FTYPE_HIGH_SIERRA?
249988fa8efSJoerg Wunsch 		       &isodir->date[6]: isodir->flags)&2) {
250df8bae1dSRodney W. Grimes 		inop->inode.iso_mode = S_IFDIR;
251df8bae1dSRodney W. Grimes 		/*
252df8bae1dSRodney W. Grimes 		 * If we return 2, fts() will assume there are no subdirectories
253df8bae1dSRodney W. Grimes 		 * (just links for the path and .), so instead we return 1.
254df8bae1dSRodney W. Grimes 		 */
255df8bae1dSRodney W. Grimes 		inop->inode.iso_links = 1;
256df8bae1dSRodney W. Grimes 	} else {
257df8bae1dSRodney W. Grimes 		inop->inode.iso_mode = S_IFREG;
258df8bae1dSRodney W. Grimes 		inop->inode.iso_links = 1;
259df8bae1dSRodney W. Grimes 	}
260df8bae1dSRodney W. Grimes 	if (!bp
261df8bae1dSRodney W. Grimes 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
262df8bae1dSRodney W. Grimes 	    && (off = isonum_711(isodir->ext_attr_length))) {
263cec0f20cSPoul-Henning Kamp 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
264996c772fSJohn Dyson 			     &bp2);
265df8bae1dSRodney W. Grimes 		bp = bp2;
266df8bae1dSRodney W. Grimes 	}
267df8bae1dSRodney W. Grimes 	if (bp) {
268996c772fSJohn Dyson 		ap = (struct iso_extended_attributes *)bp->b_data;
269df8bae1dSRodney W. Grimes 
270df8bae1dSRodney W. Grimes 		if (isonum_711(ap->version) == 1) {
271df8bae1dSRodney W. Grimes 			if (!(ap->perm[0]&0x40))
272df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VEXEC >> 6;
273df8bae1dSRodney W. Grimes 			if (!(ap->perm[0]&0x10))
274df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VREAD >> 6;
275df8bae1dSRodney W. Grimes 			if (!(ap->perm[0]&4))
276df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VEXEC >> 3;
277df8bae1dSRodney W. Grimes 			if (!(ap->perm[0]&1))
278df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VREAD >> 3;
279df8bae1dSRodney W. Grimes 			if (!(ap->perm[1]&0x40))
280df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VEXEC;
281df8bae1dSRodney W. Grimes 			if (!(ap->perm[1]&0x10))
282df8bae1dSRodney W. Grimes 				inop->inode.iso_mode |= VREAD;
283df8bae1dSRodney W. Grimes 			inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
284df8bae1dSRodney W. Grimes 			inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
285df8bae1dSRodney W. Grimes 		} else
286df8bae1dSRodney W. Grimes 			ap = NULL;
287df8bae1dSRodney W. Grimes 	}
288df8bae1dSRodney W. Grimes 	if (!ap) {
289df8bae1dSRodney W. Grimes 		inop->inode.iso_mode |= VREAD|VEXEC|(VREAD|VEXEC)>>3|(VREAD|VEXEC)>>6;
290df8bae1dSRodney W. Grimes 		inop->inode.iso_uid = (uid_t)0;
291df8bae1dSRodney W. Grimes 		inop->inode.iso_gid = (gid_t)0;
292df8bae1dSRodney W. Grimes 	}
293df8bae1dSRodney W. Grimes 	if (bp2)
294df8bae1dSRodney W. Grimes 		brelse(bp2);
295df8bae1dSRodney W. Grimes }
296df8bae1dSRodney W. Grimes 
297df8bae1dSRodney W. Grimes /*
298df8bae1dSRodney W. Grimes  * Time stamps
299df8bae1dSRodney W. Grimes  */
300df8bae1dSRodney W. Grimes void
301988fa8efSJoerg Wunsch cd9660_deftstamp(isodir,inop,bp,ftype)
302df8bae1dSRodney W. Grimes 	struct iso_directory_record *isodir;
303df8bae1dSRodney W. Grimes 	struct iso_node *inop;
304df8bae1dSRodney W. Grimes 	struct buf *bp;
305988fa8efSJoerg Wunsch 	enum ISO_FTYPE ftype;
306df8bae1dSRodney W. Grimes {
307df8bae1dSRodney W. Grimes 	struct buf *bp2 = NULL;
308df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
309df8bae1dSRodney W. Grimes 	struct iso_extended_attributes *ap = NULL;
310df8bae1dSRodney W. Grimes 	int off;
311df8bae1dSRodney W. Grimes 
312df8bae1dSRodney W. Grimes 	if (!bp
313df8bae1dSRodney W. Grimes 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
314df8bae1dSRodney W. Grimes 	    && (off = isonum_711(isodir->ext_attr_length))) {
315cec0f20cSPoul-Henning Kamp 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
316996c772fSJohn Dyson 			     &bp2);
317df8bae1dSRodney W. Grimes 		bp = bp2;
318df8bae1dSRodney W. Grimes 	}
319df8bae1dSRodney W. Grimes 	if (bp) {
320996c772fSJohn Dyson 		ap = (struct iso_extended_attributes *)bp->b_data;
321df8bae1dSRodney W. Grimes 
322596d40b9SBruce Evans 		if (ftype != ISO_FTYPE_HIGH_SIERRA
323596d40b9SBruce Evans 		    && isonum_711(ap->version) == 1) {
324df8bae1dSRodney W. Grimes 			if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
325df8bae1dSRodney W. Grimes 				cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
326df8bae1dSRodney W. Grimes 			if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
327df8bae1dSRodney W. Grimes 				inop->inode.iso_ctime = inop->inode.iso_atime;
328df8bae1dSRodney W. Grimes 			if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
329df8bae1dSRodney W. Grimes 				inop->inode.iso_mtime = inop->inode.iso_ctime;
330df8bae1dSRodney W. Grimes 		} else
331df8bae1dSRodney W. Grimes 			ap = NULL;
332df8bae1dSRodney W. Grimes 	}
333df8bae1dSRodney W. Grimes 	if (!ap) {
334988fa8efSJoerg Wunsch 		cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime,ftype);
335df8bae1dSRodney W. Grimes 		inop->inode.iso_atime = inop->inode.iso_ctime;
336df8bae1dSRodney W. Grimes 		inop->inode.iso_mtime = inop->inode.iso_ctime;
337df8bae1dSRodney W. Grimes 	}
338df8bae1dSRodney W. Grimes 	if (bp2)
339df8bae1dSRodney W. Grimes 		brelse(bp2);
340df8bae1dSRodney W. Grimes }
341df8bae1dSRodney W. Grimes 
342df8bae1dSRodney W. Grimes int
343988fa8efSJoerg Wunsch cd9660_tstamp_conv7(pi,pu,ftype)
344996c772fSJohn Dyson 	u_char *pi;
3451dbaf90cSBruce Evans 	struct timespec *pu;
346988fa8efSJoerg Wunsch 	enum ISO_FTYPE ftype;
347df8bae1dSRodney W. Grimes {
348df8bae1dSRodney W. Grimes 	int crtime, days;
349df8bae1dSRodney W. Grimes 	int y, m, d, hour, minute, second, tz;
350df8bae1dSRodney W. Grimes 
351df8bae1dSRodney W. Grimes 	y = pi[0] + 1900;
352df8bae1dSRodney W. Grimes 	m = pi[1];
353df8bae1dSRodney W. Grimes 	d = pi[2];
354df8bae1dSRodney W. Grimes 	hour = pi[3];
355df8bae1dSRodney W. Grimes 	minute = pi[4];
356df8bae1dSRodney W. Grimes 	second = pi[5];
357988fa8efSJoerg Wunsch 	if(ftype != ISO_FTYPE_HIGH_SIERRA)
358df8bae1dSRodney W. Grimes 		tz = pi[6];
359988fa8efSJoerg Wunsch 	else
360988fa8efSJoerg Wunsch 		/* original high sierra misses timezone data */
361988fa8efSJoerg Wunsch 		tz = 0;
362df8bae1dSRodney W. Grimes 
363df8bae1dSRodney W. Grimes 	if (y < 1970) {
36495a1574eSNate Williams 		pu->tv_sec  = 0;
36595a1574eSNate Williams 		pu->tv_nsec = 0;
366df8bae1dSRodney W. Grimes 		return 0;
367df8bae1dSRodney W. Grimes 	} else {
368df8bae1dSRodney W. Grimes #ifdef	ORIGINAL
369df8bae1dSRodney W. Grimes 		/* computes day number relative to Sept. 19th,1989 */
370df8bae1dSRodney W. Grimes 		/* don't even *THINK* about changing formula. It works! */
371df8bae1dSRodney 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;
372df8bae1dSRodney W. Grimes #else
373df8bae1dSRodney W. Grimes 		/*
374df8bae1dSRodney W. Grimes 		 * Changed :-) to make it relative to Jan. 1st, 1970
375df8bae1dSRodney W. Grimes 		 * and to disambiguate negative division
376df8bae1dSRodney W. Grimes 		 */
377df8bae1dSRodney 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;
378df8bae1dSRodney W. Grimes #endif
379df8bae1dSRodney W. Grimes 		crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
380df8bae1dSRodney W. Grimes 
381df8bae1dSRodney W. Grimes 		/* timezone offset is unreliable on some disks */
382df8bae1dSRodney W. Grimes 		if (-48 <= tz && tz <= 52)
3832d091ecfSBruce Evans 			crtime -= tz * 15 * 60;
384df8bae1dSRodney W. Grimes 	}
38595a1574eSNate Williams 	pu->tv_sec  = crtime;
38695a1574eSNate Williams 	pu->tv_nsec = 0;
387df8bae1dSRodney W. Grimes 	return 1;
388df8bae1dSRodney W. Grimes }
389df8bae1dSRodney W. Grimes 
390996c772fSJohn Dyson static u_int
391df8bae1dSRodney W. Grimes cd9660_chars2ui(begin,len)
392996c772fSJohn Dyson 	u_char *begin;
393df8bae1dSRodney W. Grimes 	int len;
394df8bae1dSRodney W. Grimes {
395996c772fSJohn Dyson 	u_int rc;
396df8bae1dSRodney W. Grimes 
397df8bae1dSRodney W. Grimes 	for (rc = 0; --len >= 0;) {
398df8bae1dSRodney W. Grimes 		rc *= 10;
399df8bae1dSRodney W. Grimes 		rc += *begin++ - '0';
400df8bae1dSRodney W. Grimes 	}
401df8bae1dSRodney W. Grimes 	return rc;
402df8bae1dSRodney W. Grimes }
403df8bae1dSRodney W. Grimes 
404df8bae1dSRodney W. Grimes int
405df8bae1dSRodney W. Grimes cd9660_tstamp_conv17(pi,pu)
406996c772fSJohn Dyson 	u_char *pi;
4071dbaf90cSBruce Evans 	struct timespec *pu;
408df8bae1dSRodney W. Grimes {
409996c772fSJohn Dyson 	u_char buf[7];
410df8bae1dSRodney W. Grimes 
411df8bae1dSRodney W. Grimes 	/* year:"0001"-"9999" -> -1900  */
412df8bae1dSRodney W. Grimes 	buf[0] = cd9660_chars2ui(pi,4) - 1900;
413df8bae1dSRodney W. Grimes 
414df8bae1dSRodney W. Grimes 	/* month: " 1"-"12"   -> 1 - 12 */
415df8bae1dSRodney W. Grimes 	buf[1] = cd9660_chars2ui(pi + 4,2);
416df8bae1dSRodney W. Grimes 
417df8bae1dSRodney W. Grimes 	/* day:	  " 1"-"31"   -> 1 - 31 */
418df8bae1dSRodney W. Grimes 	buf[2] = cd9660_chars2ui(pi + 6,2);
419df8bae1dSRodney W. Grimes 
420df8bae1dSRodney W. Grimes 	/* hour:  " 0"-"23"   -> 0 - 23 */
421df8bae1dSRodney W. Grimes 	buf[3] = cd9660_chars2ui(pi + 8,2);
422df8bae1dSRodney W. Grimes 
423df8bae1dSRodney W. Grimes 	/* minute:" 0"-"59"   -> 0 - 59 */
424df8bae1dSRodney W. Grimes 	buf[4] = cd9660_chars2ui(pi + 10,2);
425df8bae1dSRodney W. Grimes 
426df8bae1dSRodney W. Grimes 	/* second:" 0"-"59"   -> 0 - 59 */
427df8bae1dSRodney W. Grimes 	buf[5] = cd9660_chars2ui(pi + 12,2);
428df8bae1dSRodney W. Grimes 
429df8bae1dSRodney W. Grimes 	/* difference of GMT */
430df8bae1dSRodney W. Grimes 	buf[6] = pi[16];
431df8bae1dSRodney W. Grimes 
432988fa8efSJoerg Wunsch 	return cd9660_tstamp_conv7(buf, pu, ISO_FTYPE_DEFAULT);
433df8bae1dSRodney W. Grimes }
434df8bae1dSRodney W. Grimes 
435996c772fSJohn Dyson ino_t
436996c772fSJohn Dyson isodirino(isodir, imp)
437df8bae1dSRodney W. Grimes 	struct iso_directory_record *isodir;
438df8bae1dSRodney W. Grimes 	struct iso_mnt *imp;
439df8bae1dSRodney W. Grimes {
440996c772fSJohn Dyson 	ino_t ino;
441996c772fSJohn Dyson 
442996c772fSJohn Dyson 	ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
443996c772fSJohn Dyson 	      << imp->im_bshift;
444996c772fSJohn Dyson 	return (ino);
445df8bae1dSRodney W. Grimes }
446