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> 45df8bae1dSRodney W. Grimes #include <sys/proc.h> 469626b608SPoul-Henning Kamp #include <sys/bio.h> 47df8bae1dSRodney W. Grimes #include <sys/buf.h> 48df8bae1dSRodney W. Grimes #include <sys/vnode.h> 49df8bae1dSRodney W. Grimes #include <sys/malloc.h> 50df8bae1dSRodney W. Grimes #include <sys/stat.h> 51df8bae1dSRodney W. Grimes 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) 62289bdf33SBruce Evans #ifndef NULL_SIMPLELOCKS 63303b270bSEivind Eklund static struct simplelock cd9660_ihash_slock; 64289bdf33SBruce Evans #endif 65df8bae1dSRodney W. Grimes 66f041a9bdSPoul-Henning Kamp static void cd9660_ihashrem __P((struct iso_node *)); 6710dd32cdSBruce Evans static unsigned cd9660_chars2ui __P((unsigned char *begin, int len)); 6810dd32cdSBruce Evans 69df8bae1dSRodney W. Grimes /* 70df8bae1dSRodney W. Grimes * Initialize hash links for inodes and dnodes. 71df8bae1dSRodney W. Grimes */ 7226f9a767SRodney W. Grimes int 73996c772fSJohn Dyson cd9660_init(vfsp) 74996c772fSJohn Dyson struct vfsconf *vfsp; 75df8bae1dSRodney W. Grimes { 76df8bae1dSRodney W. Grimes 77996c772fSJohn Dyson isohashtbl = hashinit(desiredvnodes, M_ISOFSMNT, &isohash); 78996c772fSJohn Dyson simple_lock_init(&cd9660_ihash_slock); 7926f9a767SRodney W. Grimes return (0); 80df8bae1dSRodney W. Grimes } 81df8bae1dSRodney W. Grimes 82df8bae1dSRodney W. Grimes 83df8bae1dSRodney W. Grimes /* 84996c772fSJohn Dyson * Use the device/inum pair to find the incore inode, and return a pointer 85996c772fSJohn Dyson * to it. If it is in core, but locked, wait for it. 86df8bae1dSRodney W. Grimes */ 87996c772fSJohn Dyson struct vnode * 88996c772fSJohn Dyson cd9660_ihashget(dev, inum) 89996c772fSJohn Dyson dev_t dev; 90996c772fSJohn Dyson ino_t inum; 91df8bae1dSRodney W. Grimes { 92996c772fSJohn Dyson struct proc *p = curproc; /* XXX */ 93996c772fSJohn Dyson struct iso_node *ip; 94996c772fSJohn Dyson struct vnode *vp; 95df8bae1dSRodney W. Grimes 96df8bae1dSRodney W. Grimes loop: 97996c772fSJohn Dyson simple_lock(&cd9660_ihash_slock); 98996c772fSJohn Dyson for (ip = isohashtbl[INOHASH(dev, inum)]; ip; ip = ip->i_next) { 99996c772fSJohn Dyson if (inum == ip->i_number && dev == ip->i_dev) { 100df8bae1dSRodney W. Grimes vp = ITOV(ip); 101996c772fSJohn Dyson simple_lock(&vp->v_interlock); 102996c772fSJohn Dyson simple_unlock(&cd9660_ihash_slock); 103996c772fSJohn Dyson if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, p)) 104996c772fSJohn Dyson goto loop; 105996c772fSJohn Dyson return (vp); 106df8bae1dSRodney W. Grimes } 107df8bae1dSRodney W. Grimes } 108996c772fSJohn Dyson simple_unlock(&cd9660_ihash_slock); 109996c772fSJohn Dyson return (NULL); 110996c772fSJohn Dyson } 111df8bae1dSRodney W. Grimes 112996c772fSJohn Dyson /* 113996c772fSJohn Dyson * Insert the inode into the hash table, and return it locked. 114996c772fSJohn Dyson */ 115996c772fSJohn Dyson void 116996c772fSJohn Dyson cd9660_ihashins(ip) 117996c772fSJohn Dyson struct iso_node *ip; 118996c772fSJohn Dyson { 119996c772fSJohn Dyson struct proc *p = curproc; /* XXX */ 120996c772fSJohn Dyson struct iso_node **ipp, *iq; 121df8bae1dSRodney W. Grimes 122996c772fSJohn Dyson simple_lock(&cd9660_ihash_slock); 123996c772fSJohn Dyson ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)]; 124d254af07SMatthew Dillon if ((iq = *ipp) != NULL) 125996c772fSJohn Dyson iq->i_prev = &ip->i_next; 126996c772fSJohn Dyson ip->i_next = iq; 127996c772fSJohn Dyson ip->i_prev = ipp; 128df8bae1dSRodney W. Grimes *ipp = ip; 129996c772fSJohn Dyson simple_unlock(&cd9660_ihash_slock); 130996c772fSJohn Dyson 131996c772fSJohn Dyson lockmgr(&ip->i_lock, LK_EXCLUSIVE, (struct simplelock *)0, p); 132df8bae1dSRodney W. Grimes } 133df8bae1dSRodney W. Grimes 134df8bae1dSRodney W. Grimes /* 135996c772fSJohn Dyson * Remove the inode from the hash table. 136df8bae1dSRodney W. Grimes */ 137f041a9bdSPoul-Henning Kamp static void 138996c772fSJohn Dyson cd9660_ihashrem(ip) 139df8bae1dSRodney W. Grimes register struct iso_node *ip; 140df8bae1dSRodney W. Grimes { 141996c772fSJohn Dyson register struct iso_node *iq; 142df8bae1dSRodney W. Grimes 143996c772fSJohn Dyson simple_lock(&cd9660_ihash_slock); 144d254af07SMatthew Dillon if ((iq = ip->i_next) != NULL) 145996c772fSJohn Dyson iq->i_prev = ip->i_prev; 146996c772fSJohn Dyson *ip->i_prev = iq; 147996c772fSJohn Dyson #ifdef DIAGNOSTIC 148996c772fSJohn Dyson ip->i_next = NULL; 149996c772fSJohn Dyson ip->i_prev = NULL; 150996c772fSJohn Dyson #endif 151996c772fSJohn Dyson simple_unlock(&cd9660_ihash_slock); 152df8bae1dSRodney W. Grimes } 153df8bae1dSRodney W. Grimes 154df8bae1dSRodney W. Grimes /* 155df8bae1dSRodney W. Grimes * Last reference to an inode, write the inode out and if necessary, 156df8bae1dSRodney W. Grimes * truncate and deallocate the file. 157df8bae1dSRodney W. Grimes */ 158df8bae1dSRodney W. Grimes int 159df8bae1dSRodney W. Grimes cd9660_inactive(ap) 160df8bae1dSRodney W. Grimes struct vop_inactive_args /* { 161df8bae1dSRodney W. Grimes struct vnode *a_vp; 162996c772fSJohn Dyson struct proc *a_p; 163df8bae1dSRodney W. Grimes } */ *ap; 164df8bae1dSRodney W. Grimes { 165df8bae1dSRodney W. Grimes struct vnode *vp = ap->a_vp; 166996c772fSJohn Dyson struct proc *p = ap->a_p; 167df8bae1dSRodney W. Grimes register struct iso_node *ip = VTOI(vp); 1681295d82eSGary Palmer int error = 0; 169df8bae1dSRodney W. Grimes 170df8bae1dSRodney W. Grimes if (prtactive && vp->v_usecount != 0) 171df8bae1dSRodney W. Grimes vprint("cd9660_inactive: pushing active", vp); 172df8bae1dSRodney W. Grimes 173df8bae1dSRodney W. Grimes ip->i_flag = 0; 174996c772fSJohn Dyson VOP_UNLOCK(vp, 0, p); 175df8bae1dSRodney W. Grimes /* 176df8bae1dSRodney W. Grimes * If we are done with the inode, reclaim it 177df8bae1dSRodney W. Grimes * so that it can be reused immediately. 178df8bae1dSRodney W. Grimes */ 179996c772fSJohn Dyson if (ip->inode.iso_mode == 0) 180996c772fSJohn Dyson vrecycle(vp, (struct simplelock *)0, p); 181df8bae1dSRodney W. Grimes return error; 182df8bae1dSRodney W. Grimes } 183df8bae1dSRodney W. Grimes 184df8bae1dSRodney W. Grimes /* 185df8bae1dSRodney W. Grimes * Reclaim an inode so that it can be used for other purposes. 186df8bae1dSRodney W. Grimes */ 187df8bae1dSRodney W. Grimes int 188df8bae1dSRodney W. Grimes cd9660_reclaim(ap) 189df8bae1dSRodney W. Grimes struct vop_reclaim_args /* { 190df8bae1dSRodney W. Grimes struct vnode *a_vp; 191996c772fSJohn Dyson struct proc *a_p; 192df8bae1dSRodney W. Grimes } */ *ap; 193df8bae1dSRodney W. Grimes { 194df8bae1dSRodney W. Grimes register struct vnode *vp = ap->a_vp; 195df8bae1dSRodney W. Grimes register struct iso_node *ip = VTOI(vp); 196df8bae1dSRodney W. Grimes 197df8bae1dSRodney W. Grimes if (prtactive && vp->v_usecount != 0) 198df8bae1dSRodney W. Grimes vprint("cd9660_reclaim: pushing active", vp); 199df8bae1dSRodney W. Grimes /* 200df8bae1dSRodney W. Grimes * Remove the inode from its hash chain. 201df8bae1dSRodney W. Grimes */ 202996c772fSJohn Dyson cd9660_ihashrem(ip); 203df8bae1dSRodney W. Grimes /* 204df8bae1dSRodney W. Grimes * Purge old data structures associated with the inode. 205df8bae1dSRodney W. Grimes */ 206df8bae1dSRodney W. Grimes cache_purge(vp); 207df8bae1dSRodney W. Grimes if (ip->i_devvp) { 208df8bae1dSRodney W. Grimes vrele(ip->i_devvp); 209df8bae1dSRodney W. Grimes ip->i_devvp = 0; 210df8bae1dSRodney W. Grimes } 211df8bae1dSRodney W. Grimes FREE(vp->v_data, M_ISOFSNODE); 212df8bae1dSRodney W. Grimes vp->v_data = NULL; 21326f9a767SRodney W. Grimes return (0); 214df8bae1dSRodney W. Grimes } 215df8bae1dSRodney W. Grimes 216df8bae1dSRodney W. Grimes /* 217df8bae1dSRodney W. Grimes * File attributes 218df8bae1dSRodney W. Grimes */ 219df8bae1dSRodney W. Grimes void 220988fa8efSJoerg Wunsch cd9660_defattr(isodir, inop, bp, ftype) 221df8bae1dSRodney W. Grimes struct iso_directory_record *isodir; 222df8bae1dSRodney W. Grimes struct iso_node *inop; 223df8bae1dSRodney W. Grimes struct buf *bp; 224988fa8efSJoerg Wunsch enum ISO_FTYPE ftype; 225df8bae1dSRodney W. Grimes { 226df8bae1dSRodney W. Grimes struct buf *bp2 = NULL; 227df8bae1dSRodney W. Grimes struct iso_mnt *imp; 228df8bae1dSRodney W. Grimes struct iso_extended_attributes *ap = NULL; 229df8bae1dSRodney W. Grimes int off; 230df8bae1dSRodney W. Grimes 231988fa8efSJoerg Wunsch /* high sierra does not have timezone data, flag is one byte ahead */ 232988fa8efSJoerg Wunsch if (isonum_711(ftype == ISO_FTYPE_HIGH_SIERRA? 233988fa8efSJoerg Wunsch &isodir->date[6]: isodir->flags)&2) { 234df8bae1dSRodney W. Grimes inop->inode.iso_mode = S_IFDIR; 235df8bae1dSRodney W. Grimes /* 236df8bae1dSRodney W. Grimes * If we return 2, fts() will assume there are no subdirectories 237df8bae1dSRodney W. Grimes * (just links for the path and .), so instead we return 1. 238df8bae1dSRodney W. Grimes */ 239df8bae1dSRodney W. Grimes inop->inode.iso_links = 1; 240df8bae1dSRodney W. Grimes } else { 241df8bae1dSRodney W. Grimes inop->inode.iso_mode = S_IFREG; 242df8bae1dSRodney W. Grimes inop->inode.iso_links = 1; 243df8bae1dSRodney W. Grimes } 244df8bae1dSRodney W. Grimes if (!bp 245df8bae1dSRodney W. Grimes && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT) 246df8bae1dSRodney W. Grimes && (off = isonum_711(isodir->ext_attr_length))) { 247cec0f20cSPoul-Henning Kamp cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL, 248996c772fSJohn Dyson &bp2); 249df8bae1dSRodney W. Grimes bp = bp2; 250df8bae1dSRodney W. Grimes } 251df8bae1dSRodney W. Grimes if (bp) { 252996c772fSJohn Dyson ap = (struct iso_extended_attributes *)bp->b_data; 253df8bae1dSRodney W. Grimes 254df8bae1dSRodney W. Grimes if (isonum_711(ap->version) == 1) { 255df8bae1dSRodney W. Grimes if (!(ap->perm[0]&0x40)) 256df8bae1dSRodney W. Grimes inop->inode.iso_mode |= VEXEC >> 6; 257df8bae1dSRodney W. Grimes if (!(ap->perm[0]&0x10)) 258df8bae1dSRodney W. Grimes inop->inode.iso_mode |= VREAD >> 6; 259df8bae1dSRodney W. Grimes if (!(ap->perm[0]&4)) 260df8bae1dSRodney W. Grimes inop->inode.iso_mode |= VEXEC >> 3; 261df8bae1dSRodney W. Grimes if (!(ap->perm[0]&1)) 262df8bae1dSRodney W. Grimes inop->inode.iso_mode |= VREAD >> 3; 263df8bae1dSRodney W. Grimes if (!(ap->perm[1]&0x40)) 264df8bae1dSRodney W. Grimes inop->inode.iso_mode |= VEXEC; 265df8bae1dSRodney W. Grimes if (!(ap->perm[1]&0x10)) 266df8bae1dSRodney W. Grimes inop->inode.iso_mode |= VREAD; 267df8bae1dSRodney W. Grimes inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */ 268df8bae1dSRodney W. Grimes inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */ 269df8bae1dSRodney W. Grimes } else 270df8bae1dSRodney W. Grimes ap = NULL; 271df8bae1dSRodney W. Grimes } 272df8bae1dSRodney W. Grimes if (!ap) { 273df8bae1dSRodney W. Grimes inop->inode.iso_mode |= VREAD|VEXEC|(VREAD|VEXEC)>>3|(VREAD|VEXEC)>>6; 274df8bae1dSRodney W. Grimes inop->inode.iso_uid = (uid_t)0; 275df8bae1dSRodney W. Grimes inop->inode.iso_gid = (gid_t)0; 276df8bae1dSRodney W. Grimes } 277df8bae1dSRodney W. Grimes if (bp2) 278df8bae1dSRodney W. Grimes brelse(bp2); 279df8bae1dSRodney W. Grimes } 280df8bae1dSRodney W. Grimes 281df8bae1dSRodney W. Grimes /* 282df8bae1dSRodney W. Grimes * Time stamps 283df8bae1dSRodney W. Grimes */ 284df8bae1dSRodney W. Grimes void 285988fa8efSJoerg Wunsch cd9660_deftstamp(isodir,inop,bp,ftype) 286df8bae1dSRodney W. Grimes struct iso_directory_record *isodir; 287df8bae1dSRodney W. Grimes struct iso_node *inop; 288df8bae1dSRodney W. Grimes struct buf *bp; 289988fa8efSJoerg Wunsch enum ISO_FTYPE ftype; 290df8bae1dSRodney W. Grimes { 291df8bae1dSRodney W. Grimes struct buf *bp2 = NULL; 292df8bae1dSRodney W. Grimes struct iso_mnt *imp; 293df8bae1dSRodney W. Grimes struct iso_extended_attributes *ap = NULL; 294df8bae1dSRodney W. Grimes int off; 295df8bae1dSRodney W. Grimes 296df8bae1dSRodney W. Grimes if (!bp 297df8bae1dSRodney W. Grimes && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT) 298df8bae1dSRodney W. Grimes && (off = isonum_711(isodir->ext_attr_length))) { 299cec0f20cSPoul-Henning Kamp cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL, 300996c772fSJohn Dyson &bp2); 301df8bae1dSRodney W. Grimes bp = bp2; 302df8bae1dSRodney W. Grimes } 303df8bae1dSRodney W. Grimes if (bp) { 304996c772fSJohn Dyson ap = (struct iso_extended_attributes *)bp->b_data; 305df8bae1dSRodney W. Grimes 306596d40b9SBruce Evans if (ftype != ISO_FTYPE_HIGH_SIERRA 307596d40b9SBruce Evans && isonum_711(ap->version) == 1) { 308df8bae1dSRodney W. Grimes if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime)) 309df8bae1dSRodney W. Grimes cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime); 310df8bae1dSRodney W. Grimes if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime)) 311df8bae1dSRodney W. Grimes inop->inode.iso_ctime = inop->inode.iso_atime; 312df8bae1dSRodney W. Grimes if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime)) 313df8bae1dSRodney W. Grimes inop->inode.iso_mtime = inop->inode.iso_ctime; 314df8bae1dSRodney W. Grimes } else 315df8bae1dSRodney W. Grimes ap = NULL; 316df8bae1dSRodney W. Grimes } 317df8bae1dSRodney W. Grimes if (!ap) { 318988fa8efSJoerg Wunsch cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime,ftype); 319df8bae1dSRodney W. Grimes inop->inode.iso_atime = inop->inode.iso_ctime; 320df8bae1dSRodney W. Grimes inop->inode.iso_mtime = inop->inode.iso_ctime; 321df8bae1dSRodney W. Grimes } 322df8bae1dSRodney W. Grimes if (bp2) 323df8bae1dSRodney W. Grimes brelse(bp2); 324df8bae1dSRodney W. Grimes } 325df8bae1dSRodney W. Grimes 326df8bae1dSRodney W. Grimes int 327988fa8efSJoerg Wunsch cd9660_tstamp_conv7(pi,pu,ftype) 328996c772fSJohn Dyson u_char *pi; 3291dbaf90cSBruce Evans struct timespec *pu; 330988fa8efSJoerg Wunsch enum ISO_FTYPE ftype; 331df8bae1dSRodney W. Grimes { 332df8bae1dSRodney W. Grimes int crtime, days; 333df8bae1dSRodney W. Grimes int y, m, d, hour, minute, second, tz; 334df8bae1dSRodney W. Grimes 335df8bae1dSRodney W. Grimes y = pi[0] + 1900; 336df8bae1dSRodney W. Grimes m = pi[1]; 337df8bae1dSRodney W. Grimes d = pi[2]; 338df8bae1dSRodney W. Grimes hour = pi[3]; 339df8bae1dSRodney W. Grimes minute = pi[4]; 340df8bae1dSRodney W. Grimes second = pi[5]; 341988fa8efSJoerg Wunsch if(ftype != ISO_FTYPE_HIGH_SIERRA) 342df8bae1dSRodney W. Grimes tz = pi[6]; 343988fa8efSJoerg Wunsch else 344988fa8efSJoerg Wunsch /* original high sierra misses timezone data */ 345988fa8efSJoerg Wunsch tz = 0; 346df8bae1dSRodney W. Grimes 347df8bae1dSRodney W. Grimes if (y < 1970) { 34895a1574eSNate Williams pu->tv_sec = 0; 34995a1574eSNate Williams pu->tv_nsec = 0; 350df8bae1dSRodney W. Grimes return 0; 351df8bae1dSRodney W. Grimes } else { 352df8bae1dSRodney W. Grimes #ifdef ORIGINAL 353df8bae1dSRodney W. Grimes /* computes day number relative to Sept. 19th,1989 */ 354df8bae1dSRodney W. Grimes /* don't even *THINK* about changing formula. It works! */ 355df8bae1dSRodney 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; 356df8bae1dSRodney W. Grimes #else 357df8bae1dSRodney W. Grimes /* 358df8bae1dSRodney W. Grimes * Changed :-) to make it relative to Jan. 1st, 1970 359df8bae1dSRodney W. Grimes * and to disambiguate negative division 360df8bae1dSRodney W. Grimes */ 361df8bae1dSRodney 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; 362df8bae1dSRodney W. Grimes #endif 363df8bae1dSRodney W. Grimes crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second; 364df8bae1dSRodney W. Grimes 365df8bae1dSRodney W. Grimes /* timezone offset is unreliable on some disks */ 366df8bae1dSRodney W. Grimes if (-48 <= tz && tz <= 52) 3672d091ecfSBruce Evans crtime -= tz * 15 * 60; 368df8bae1dSRodney W. Grimes } 36995a1574eSNate Williams pu->tv_sec = crtime; 37095a1574eSNate Williams pu->tv_nsec = 0; 371df8bae1dSRodney W. Grimes return 1; 372df8bae1dSRodney W. Grimes } 373df8bae1dSRodney W. Grimes 374996c772fSJohn Dyson static u_int 375df8bae1dSRodney W. Grimes cd9660_chars2ui(begin,len) 376996c772fSJohn Dyson u_char *begin; 377df8bae1dSRodney W. Grimes int len; 378df8bae1dSRodney W. Grimes { 379996c772fSJohn Dyson u_int rc; 380df8bae1dSRodney W. Grimes 381df8bae1dSRodney W. Grimes for (rc = 0; --len >= 0;) { 382df8bae1dSRodney W. Grimes rc *= 10; 383df8bae1dSRodney W. Grimes rc += *begin++ - '0'; 384df8bae1dSRodney W. Grimes } 385df8bae1dSRodney W. Grimes return rc; 386df8bae1dSRodney W. Grimes } 387df8bae1dSRodney W. Grimes 388df8bae1dSRodney W. Grimes int 389df8bae1dSRodney W. Grimes cd9660_tstamp_conv17(pi,pu) 390996c772fSJohn Dyson u_char *pi; 3911dbaf90cSBruce Evans struct timespec *pu; 392df8bae1dSRodney W. Grimes { 393996c772fSJohn Dyson u_char buf[7]; 394df8bae1dSRodney W. Grimes 395df8bae1dSRodney W. Grimes /* year:"0001"-"9999" -> -1900 */ 396df8bae1dSRodney W. Grimes buf[0] = cd9660_chars2ui(pi,4) - 1900; 397df8bae1dSRodney W. Grimes 398df8bae1dSRodney W. Grimes /* month: " 1"-"12" -> 1 - 12 */ 399df8bae1dSRodney W. Grimes buf[1] = cd9660_chars2ui(pi + 4,2); 400df8bae1dSRodney W. Grimes 401df8bae1dSRodney W. Grimes /* day: " 1"-"31" -> 1 - 31 */ 402df8bae1dSRodney W. Grimes buf[2] = cd9660_chars2ui(pi + 6,2); 403df8bae1dSRodney W. Grimes 404df8bae1dSRodney W. Grimes /* hour: " 0"-"23" -> 0 - 23 */ 405df8bae1dSRodney W. Grimes buf[3] = cd9660_chars2ui(pi + 8,2); 406df8bae1dSRodney W. Grimes 407df8bae1dSRodney W. Grimes /* minute:" 0"-"59" -> 0 - 59 */ 408df8bae1dSRodney W. Grimes buf[4] = cd9660_chars2ui(pi + 10,2); 409df8bae1dSRodney W. Grimes 410df8bae1dSRodney W. Grimes /* second:" 0"-"59" -> 0 - 59 */ 411df8bae1dSRodney W. Grimes buf[5] = cd9660_chars2ui(pi + 12,2); 412df8bae1dSRodney W. Grimes 413df8bae1dSRodney W. Grimes /* difference of GMT */ 414df8bae1dSRodney W. Grimes buf[6] = pi[16]; 415df8bae1dSRodney W. Grimes 416988fa8efSJoerg Wunsch return cd9660_tstamp_conv7(buf, pu, ISO_FTYPE_DEFAULT); 417df8bae1dSRodney W. Grimes } 418df8bae1dSRodney W. Grimes 419996c772fSJohn Dyson ino_t 420996c772fSJohn Dyson isodirino(isodir, imp) 421df8bae1dSRodney W. Grimes struct iso_directory_record *isodir; 422df8bae1dSRodney W. Grimes struct iso_mnt *imp; 423df8bae1dSRodney W. Grimes { 424996c772fSJohn Dyson ino_t ino; 425996c772fSJohn Dyson 426996c772fSJohn Dyson ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length)) 427996c772fSJohn Dyson << imp->im_bshift; 428996c772fSJohn Dyson return (ino); 429df8bae1dSRodney W. Grimes } 430