Home | History | Annotate | Line # | Download | only in cd9660
cd9660_node.c revision 1.29
      1  1.29     rmind /*	$NetBSD: cd9660_node.c,v 1.29 2011/06/12 03:35:52 rmind Exp $	*/
      2   1.1  jdolecek 
      3   1.1  jdolecek /*-
      4   1.1  jdolecek  * Copyright (c) 1982, 1986, 1989, 1994
      5   1.1  jdolecek  *	The Regents of the University of California.  All rights reserved.
      6   1.1  jdolecek  *
      7   1.1  jdolecek  * This code is derived from software contributed to Berkeley
      8   1.1  jdolecek  * by Pace Willisson (pace (at) blitz.com).  The Rock Ridge Extension
      9   1.1  jdolecek  * Support code is derived from software contributed to Berkeley
     10   1.1  jdolecek  * by Atsushi Murai (amurai (at) spec.co.jp).
     11   1.1  jdolecek  *
     12   1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     13   1.1  jdolecek  * modification, are permitted provided that the following conditions
     14   1.1  jdolecek  * are met:
     15   1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     16   1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     17   1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     19   1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     20   1.5       agc  * 3. Neither the name of the University nor the names of its contributors
     21   1.1  jdolecek  *    may be used to endorse or promote products derived from this software
     22   1.1  jdolecek  *    without specific prior written permission.
     23   1.1  jdolecek  *
     24   1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25   1.1  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26   1.1  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27   1.1  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28   1.1  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29   1.1  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30   1.1  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31   1.1  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32   1.1  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33   1.1  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34   1.1  jdolecek  * SUCH DAMAGE.
     35   1.1  jdolecek  *
     36   1.1  jdolecek  *	@(#)cd9660_node.c	8.8 (Berkeley) 5/22/95
     37   1.1  jdolecek  */
     38   1.1  jdolecek 
     39   1.1  jdolecek #include <sys/cdefs.h>
     40  1.29     rmind __KERNEL_RCSID(0, "$NetBSD: cd9660_node.c,v 1.29 2011/06/12 03:35:52 rmind Exp $");
     41   1.1  jdolecek 
     42   1.1  jdolecek #include <sys/param.h>
     43   1.1  jdolecek #include <sys/systm.h>
     44   1.1  jdolecek #include <sys/mount.h>
     45   1.1  jdolecek #include <sys/proc.h>
     46   1.1  jdolecek #include <sys/file.h>
     47   1.1  jdolecek #include <sys/buf.h>
     48   1.1  jdolecek #include <sys/vnode.h>
     49   1.1  jdolecek #include <sys/namei.h>
     50   1.1  jdolecek #include <sys/kernel.h>
     51   1.1  jdolecek #include <sys/malloc.h>
     52   1.1  jdolecek #include <sys/pool.h>
     53   1.1  jdolecek #include <sys/stat.h>
     54   1.1  jdolecek 
     55   1.1  jdolecek #include <fs/cd9660/iso.h>
     56   1.1  jdolecek #include <fs/cd9660/cd9660_extern.h>
     57   1.1  jdolecek #include <fs/cd9660/cd9660_node.h>
     58   1.1  jdolecek #include <fs/cd9660/cd9660_mount.h>
     59   1.1  jdolecek #include <fs/cd9660/iso_rrip.h>
     60   1.1  jdolecek 
     61   1.1  jdolecek /*
     62   1.1  jdolecek  * Structures associated with iso_node caching.
     63   1.1  jdolecek  */
     64   1.1  jdolecek LIST_HEAD(ihashhead, iso_node) *isohashtbl;
     65   1.1  jdolecek u_long isohash;
     66   1.1  jdolecek #define	INOHASH(device, inum)	(((device) + ((inum)>>12)) & isohash)
     67  1.19        ad kmutex_t cd9660_ihash_lock;
     68  1.19        ad kmutex_t cd9660_hashlock;
     69   1.1  jdolecek 
     70   1.1  jdolecek extern int prtactive;	/* 1 => print out reclaim of active vnodes */
     71   1.1  jdolecek 
     72  1.16     pooka struct pool cd9660_node_pool;
     73   1.1  jdolecek 
     74  1.23      matt static u_int cd9660_chars2ui(const u_char *, int);
     75   1.1  jdolecek 
     76   1.1  jdolecek /*
     77   1.1  jdolecek  * Initialize hash links for inodes and dnodes.
     78   1.1  jdolecek  */
     79   1.1  jdolecek void
     80  1.23      matt cd9660_init(void)
     81   1.1  jdolecek {
     82  1.16     pooka 
     83   1.6    atatat 	malloc_type_attach(M_ISOFSMNT);
     84   1.8    atatat 	pool_init(&cd9660_node_pool, sizeof(struct iso_node), 0, 0, 0,
     85  1.15        ad 	    "cd9660nopl", &pool_allocator_nointr, IPL_NONE);
     86  1.24        ad 	isohashtbl = hashinit(desiredvnodes, HASH_LIST, true, &isohash);
     87  1.19        ad 	mutex_init(&cd9660_ihash_lock, MUTEX_DEFAULT, IPL_NONE);
     88  1.19        ad 	mutex_init(&cd9660_hashlock, MUTEX_DEFAULT, IPL_NONE);
     89   1.1  jdolecek }
     90   1.1  jdolecek 
     91   1.1  jdolecek /*
     92   1.1  jdolecek  * Reinitialize inode hash table.
     93   1.1  jdolecek  */
     94   1.1  jdolecek 
     95   1.1  jdolecek void
     96  1.23      matt cd9660_reinit(void)
     97   1.1  jdolecek {
     98   1.1  jdolecek 	struct iso_node *ip;
     99   1.1  jdolecek 	struct ihashhead *oldhash1, *hash1;
    100   1.1  jdolecek 	u_long oldmask1, mask1, val;
    101   1.1  jdolecek 	u_int i;
    102   1.1  jdolecek 
    103  1.24        ad 	hash1 = hashinit(desiredvnodes, HASH_LIST, true, &mask1);
    104   1.1  jdolecek 
    105  1.19        ad 	mutex_enter(&cd9660_ihash_lock);
    106   1.1  jdolecek 	oldhash1 = isohashtbl;
    107   1.1  jdolecek 	oldmask1 = isohash;
    108   1.1  jdolecek 	isohashtbl = hash1;
    109   1.1  jdolecek 	isohash = mask1;
    110   1.1  jdolecek 	for (i = 0; i <= oldmask1; i++) {
    111   1.1  jdolecek 		while ((ip = LIST_FIRST(&oldhash1[i])) != NULL) {
    112   1.1  jdolecek 			LIST_REMOVE(ip, i_hash);
    113   1.1  jdolecek 			val = INOHASH(ip->i_dev, ip->i_number);
    114   1.1  jdolecek 			LIST_INSERT_HEAD(&hash1[val], ip, i_hash);
    115   1.1  jdolecek 		}
    116   1.1  jdolecek 	}
    117  1.19        ad 	mutex_exit(&cd9660_ihash_lock);
    118  1.24        ad 	hashdone(oldhash1, HASH_LIST, oldmask1);
    119   1.1  jdolecek }
    120   1.1  jdolecek 
    121   1.1  jdolecek /*
    122   1.1  jdolecek  * Destroy node pool and hash table.
    123   1.1  jdolecek  */
    124   1.1  jdolecek void
    125  1.23      matt cd9660_done(void)
    126   1.1  jdolecek {
    127  1.24        ad 	hashdone(isohashtbl, HASH_LIST, isohash);
    128   1.1  jdolecek 	pool_destroy(&cd9660_node_pool);
    129  1.19        ad 	mutex_destroy(&cd9660_ihash_lock);
    130  1.19        ad 	mutex_destroy(&cd9660_hashlock);
    131   1.6    atatat 	malloc_type_detach(M_ISOFSMNT);
    132   1.1  jdolecek }
    133   1.1  jdolecek 
    134   1.1  jdolecek /*
    135   1.1  jdolecek  * Use the device/inum pair to find the incore inode, and return a pointer
    136   1.1  jdolecek  * to it. If it is in core, but locked, wait for it.
    137   1.1  jdolecek  */
    138   1.1  jdolecek struct vnode *
    139  1.23      matt cd9660_ihashget(dev_t dev, ino_t inum, int flags)
    140   1.1  jdolecek {
    141   1.1  jdolecek 	struct iso_node *ip;
    142   1.1  jdolecek 	struct vnode *vp;
    143   1.1  jdolecek 
    144   1.1  jdolecek loop:
    145  1.19        ad 	mutex_enter(&cd9660_ihash_lock);
    146   1.1  jdolecek 	LIST_FOREACH(ip, &isohashtbl[INOHASH(dev, inum)], i_hash) {
    147   1.1  jdolecek 		if (inum == ip->i_number && dev == ip->i_dev) {
    148   1.1  jdolecek 			vp = ITOV(ip);
    149  1.19        ad 			if (flags == 0) {
    150  1.19        ad 				mutex_exit(&cd9660_ihash_lock);
    151  1.19        ad 			} else {
    152  1.29     rmind 				mutex_enter(vp->v_interlock);
    153  1.19        ad 				mutex_exit(&cd9660_ihash_lock);
    154  1.27   hannken 				if (vget(vp, flags))
    155  1.19        ad 					goto loop;
    156  1.19        ad 			}
    157   1.1  jdolecek 			return (vp);
    158   1.1  jdolecek 		}
    159   1.1  jdolecek 	}
    160  1.19        ad 	mutex_exit(&cd9660_ihash_lock);
    161   1.1  jdolecek 	return (NULL);
    162   1.1  jdolecek }
    163   1.1  jdolecek 
    164   1.1  jdolecek /*
    165   1.1  jdolecek  * Insert the inode into the hash table, and return it locked.
    166   1.1  jdolecek  *
    167   1.1  jdolecek  * ip->i_vnode must be initialized first.
    168   1.1  jdolecek  */
    169   1.1  jdolecek void
    170  1.23      matt cd9660_ihashins(struct iso_node *ip)
    171   1.1  jdolecek {
    172   1.1  jdolecek 	struct ihashhead *ipp;
    173   1.1  jdolecek 
    174  1.19        ad 	KASSERT(mutex_owned(&cd9660_hashlock));
    175  1.19        ad 
    176  1.19        ad 	mutex_enter(&cd9660_ihash_lock);
    177   1.1  jdolecek 	ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)];
    178   1.1  jdolecek 	LIST_INSERT_HEAD(ipp, ip, i_hash);
    179  1.19        ad 	mutex_exit(&cd9660_ihash_lock);
    180   1.1  jdolecek 
    181  1.26   hannken 	VOP_LOCK(ITOV(ip), LK_EXCLUSIVE);
    182   1.1  jdolecek }
    183   1.1  jdolecek 
    184   1.1  jdolecek /*
    185   1.1  jdolecek  * Remove the inode from the hash table.
    186   1.1  jdolecek  */
    187   1.1  jdolecek void
    188  1.23      matt cd9660_ihashrem(struct iso_node *ip)
    189   1.1  jdolecek {
    190  1.19        ad 	mutex_enter(&cd9660_ihash_lock);
    191   1.1  jdolecek 	LIST_REMOVE(ip, i_hash);
    192  1.19        ad 	mutex_exit(&cd9660_ihash_lock);
    193   1.1  jdolecek }
    194   1.1  jdolecek 
    195   1.1  jdolecek /*
    196   1.1  jdolecek  * Last reference to an inode, write the inode out and if necessary,
    197   1.1  jdolecek  * truncate and deallocate the file.
    198   1.1  jdolecek  */
    199   1.1  jdolecek int
    200  1.23      matt cd9660_inactive(void *v)
    201   1.1  jdolecek {
    202   1.1  jdolecek 	struct vop_inactive_args /* {
    203   1.1  jdolecek 		struct vnode *a_vp;
    204  1.20        ad 		bool *a_recycle;
    205   1.1  jdolecek 	} */ *ap = v;
    206   1.1  jdolecek 	struct vnode *vp = ap->a_vp;
    207   1.1  jdolecek 	struct iso_node *ip = VTOI(vp);
    208   1.1  jdolecek 	int error = 0;
    209   1.9     perry 
    210   1.1  jdolecek 	/*
    211   1.1  jdolecek 	 * If we are done with the inode, reclaim it
    212   1.1  jdolecek 	 * so that it can be reused immediately.
    213   1.1  jdolecek 	 */
    214  1.20        ad 	ip->i_flag = 0;
    215  1.20        ad 	*ap->a_recycle = (ip->inode.iso_mode == 0);
    216  1.25   hannken 	VOP_UNLOCK(vp);
    217   1.1  jdolecek 	return error;
    218   1.1  jdolecek }
    219   1.1  jdolecek 
    220   1.1  jdolecek /*
    221   1.1  jdolecek  * Reclaim an inode so that it can be used for other purposes.
    222   1.1  jdolecek  */
    223   1.1  jdolecek int
    224  1.23      matt cd9660_reclaim(void *v)
    225   1.1  jdolecek {
    226   1.1  jdolecek 	struct vop_reclaim_args /* {
    227   1.1  jdolecek 		struct vnode *a_vp;
    228  1.13  christos 		struct lwp *a_l;
    229   1.1  jdolecek 	} */ *ap = v;
    230   1.1  jdolecek 	struct vnode *vp = ap->a_vp;
    231   1.1  jdolecek 	struct iso_node *ip = VTOI(vp);
    232   1.9     perry 
    233  1.21        ad 	if (prtactive && vp->v_usecount > 1)
    234   1.1  jdolecek 		vprint("cd9660_reclaim: pushing active", vp);
    235   1.1  jdolecek 	/*
    236   1.1  jdolecek 	 * Remove the inode from its hash chain.
    237   1.1  jdolecek 	 */
    238   1.1  jdolecek 	cd9660_ihashrem(ip);
    239   1.1  jdolecek 	/*
    240   1.1  jdolecek 	 * Purge old data structures associated with the inode.
    241   1.1  jdolecek 	 */
    242   1.1  jdolecek 	if (ip->i_devvp) {
    243   1.1  jdolecek 		vrele(ip->i_devvp);
    244   1.1  jdolecek 		ip->i_devvp = 0;
    245   1.1  jdolecek 	}
    246  1.14        ad 	genfs_node_destroy(vp);
    247   1.1  jdolecek 	pool_put(&cd9660_node_pool, vp->v_data);
    248   1.1  jdolecek 	vp->v_data = NULL;
    249   1.1  jdolecek 	return (0);
    250   1.1  jdolecek }
    251   1.1  jdolecek 
    252   1.1  jdolecek /*
    253   1.1  jdolecek  * File attributes
    254   1.1  jdolecek  */
    255   1.1  jdolecek void
    256  1.23      matt cd9660_defattr(struct iso_directory_record *isodir, struct iso_node *inop,
    257  1.23      matt 	struct buf *bp)
    258   1.1  jdolecek {
    259   1.1  jdolecek 	struct buf *bp2 = NULL;
    260   1.1  jdolecek 	struct iso_mnt *imp;
    261   1.1  jdolecek 	struct iso_extended_attributes *ap = NULL;
    262   1.1  jdolecek 	int off;
    263   1.9     perry 
    264   1.1  jdolecek 	if (isonum_711(isodir->flags)&2) {
    265   1.1  jdolecek 		inop->inode.iso_mode = S_IFDIR;
    266   1.1  jdolecek 		/*
    267   1.1  jdolecek 		 * If we return 2, fts() will assume there are no subdirectories
    268   1.1  jdolecek 		 * (just links for the path and .), so instead we return 1.
    269   1.1  jdolecek 		 */
    270   1.1  jdolecek 		inop->inode.iso_links = 1;
    271   1.1  jdolecek 	} else {
    272   1.1  jdolecek 		inop->inode.iso_mode = S_IFREG;
    273   1.1  jdolecek 		inop->inode.iso_links = 1;
    274   1.1  jdolecek 	}
    275   1.1  jdolecek 	if (!bp
    276   1.1  jdolecek 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
    277   1.1  jdolecek 	    && (off = isonum_711(isodir->ext_attr_length))) {
    278  1.12      yamt 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift),
    279  1.12      yamt 		    NULL, &bp2);
    280   1.1  jdolecek 		bp = bp2;
    281   1.1  jdolecek 	}
    282   1.1  jdolecek 	if (bp) {
    283   1.1  jdolecek 		ap = (struct iso_extended_attributes *)bp->b_data;
    284   1.9     perry 
    285   1.1  jdolecek 		if (isonum_711(ap->version) == 1) {
    286   1.1  jdolecek 			if (!(ap->perm[1]&0x10))
    287   1.1  jdolecek 				inop->inode.iso_mode |= S_IRUSR;
    288   1.1  jdolecek 			if (!(ap->perm[1]&0x40))
    289   1.1  jdolecek 				inop->inode.iso_mode |= S_IXUSR;
    290   1.1  jdolecek 			if (!(ap->perm[0]&0x01))
    291   1.1  jdolecek 				inop->inode.iso_mode |= S_IRGRP;
    292   1.1  jdolecek 			if (!(ap->perm[0]&0x04))
    293   1.1  jdolecek 				inop->inode.iso_mode |= S_IXGRP;
    294   1.1  jdolecek 			if (!(ap->perm[0]&0x10))
    295   1.1  jdolecek 				inop->inode.iso_mode |= S_IROTH;
    296   1.1  jdolecek 			if (!(ap->perm[0]&0x40))
    297   1.1  jdolecek 				inop->inode.iso_mode |= S_IXOTH;
    298   1.1  jdolecek 			inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
    299   1.1  jdolecek 			inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
    300   1.1  jdolecek 		} else
    301   1.1  jdolecek 			ap = NULL;
    302   1.1  jdolecek 	}
    303   1.1  jdolecek 	if (!ap) {
    304   1.1  jdolecek 		inop->inode.iso_mode |=
    305   1.1  jdolecek 		    S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
    306   1.1  jdolecek 		inop->inode.iso_uid = (uid_t)0;
    307   1.1  jdolecek 		inop->inode.iso_gid = (gid_t)0;
    308   1.1  jdolecek 	}
    309   1.1  jdolecek 	if (bp2)
    310  1.17        ad 		brelse(bp2, 0);
    311   1.1  jdolecek }
    312   1.1  jdolecek 
    313   1.1  jdolecek /*
    314   1.1  jdolecek  * Time stamps
    315   1.1  jdolecek  */
    316   1.1  jdolecek void
    317  1.23      matt cd9660_deftstamp(struct iso_directory_record *isodir, struct iso_node *inop,
    318  1.23      matt 	struct buf *bp)
    319   1.1  jdolecek {
    320   1.1  jdolecek 	struct buf *bp2 = NULL;
    321   1.1  jdolecek 	struct iso_mnt *imp;
    322   1.1  jdolecek 	struct iso_extended_attributes *ap = NULL;
    323   1.1  jdolecek 	int off;
    324   1.9     perry 
    325   1.1  jdolecek 	if (!bp
    326   1.1  jdolecek 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
    327   1.1  jdolecek 	    && (off = isonum_711(isodir->ext_attr_length))) {
    328  1.12      yamt 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift),
    329  1.12      yamt 		    NULL, &bp2);
    330   1.1  jdolecek 		bp = bp2;
    331   1.1  jdolecek 	}
    332   1.1  jdolecek 	if (bp) {
    333   1.1  jdolecek 		ap = (struct iso_extended_attributes *)bp->b_data;
    334   1.9     perry 
    335   1.1  jdolecek 		if (isonum_711(ap->version) == 1) {
    336   1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
    337   1.1  jdolecek 				cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
    338   1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
    339   1.1  jdolecek 				inop->inode.iso_ctime = inop->inode.iso_atime;
    340   1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
    341   1.1  jdolecek 				inop->inode.iso_mtime = inop->inode.iso_ctime;
    342   1.1  jdolecek 		} else
    343   1.1  jdolecek 			ap = NULL;
    344   1.1  jdolecek 	}
    345   1.1  jdolecek 	if (!ap) {
    346   1.1  jdolecek 		cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime);
    347   1.1  jdolecek 		inop->inode.iso_atime = inop->inode.iso_ctime;
    348   1.1  jdolecek 		inop->inode.iso_mtime = inop->inode.iso_ctime;
    349   1.1  jdolecek 	}
    350   1.1  jdolecek 	if (bp2)
    351  1.17        ad 		brelse(bp2, 0);
    352   1.1  jdolecek }
    353   1.1  jdolecek 
    354   1.1  jdolecek int
    355  1.23      matt cd9660_tstamp_conv7(const u_char *pi, struct timespec *pu)
    356   1.1  jdolecek {
    357   1.1  jdolecek 	int crtime, days;
    358   1.1  jdolecek 	int y, m, d, hour, minute, second, tz;
    359   1.9     perry 
    360   1.1  jdolecek 	y = pi[0] + 1900;
    361   1.1  jdolecek 	m = pi[1];
    362   1.1  jdolecek 	d = pi[2];
    363   1.1  jdolecek 	hour = pi[3];
    364   1.1  jdolecek 	minute = pi[4];
    365   1.1  jdolecek 	second = pi[5];
    366   1.1  jdolecek 	tz = pi[6];
    367   1.9     perry 
    368   1.1  jdolecek 	if (y < 1970) {
    369   1.1  jdolecek 		pu->tv_sec  = 0;
    370   1.1  jdolecek 		pu->tv_nsec = 0;
    371   1.1  jdolecek 		return 0;
    372   1.1  jdolecek 	} else {
    373   1.1  jdolecek #ifdef	ORIGINAL
    374   1.1  jdolecek 		/* computes day number relative to Sept. 19th,1989 */
    375   1.1  jdolecek 		/* don't even *THINK* about changing formula. It works! */
    376   1.1  jdolecek 		days = 367*(y-1980)-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4+275*m/9+d-100;
    377   1.1  jdolecek #else
    378   1.1  jdolecek 		/*
    379   1.1  jdolecek 		 * Changed :-) to make it relative to Jan. 1st, 1970
    380   1.1  jdolecek 		 * and to disambiguate negative division
    381   1.1  jdolecek 		 */
    382   1.1  jdolecek 		days = 367*(y-1960)-7*(y+(m+9)/12)/4-3*((y+(m+9)/12-1)/100+1)/4+275*m/9+d-239;
    383   1.1  jdolecek #endif
    384   1.1  jdolecek 		crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
    385   1.9     perry 
    386   1.1  jdolecek 		/* timezone offset is unreliable on some disks */
    387   1.1  jdolecek 		if (-48 <= tz && tz <= 52)
    388   1.1  jdolecek 			crtime -= tz * 15 * 60;
    389   1.1  jdolecek 	}
    390   1.1  jdolecek 	pu->tv_sec  = crtime;
    391   1.1  jdolecek 	pu->tv_nsec = 0;
    392   1.1  jdolecek 	return 1;
    393   1.1  jdolecek }
    394   1.1  jdolecek 
    395   1.1  jdolecek static u_int
    396  1.23      matt cd9660_chars2ui(const u_char *begin, int len)
    397   1.1  jdolecek {
    398   1.1  jdolecek 	u_int rc;
    399   1.9     perry 
    400   1.1  jdolecek 	for (rc = 0; --len >= 0;) {
    401   1.1  jdolecek 		rc *= 10;
    402   1.1  jdolecek 		rc += *begin++ - '0';
    403   1.1  jdolecek 	}
    404   1.1  jdolecek 	return rc;
    405   1.1  jdolecek }
    406   1.1  jdolecek 
    407   1.1  jdolecek int
    408  1.23      matt cd9660_tstamp_conv17(const u_char *pi, struct timespec *pu)
    409   1.1  jdolecek {
    410  1.10  christos 	u_char tbuf[7];
    411   1.9     perry 
    412   1.1  jdolecek 	/* year:"0001"-"9999" -> -1900  */
    413  1.10  christos 	tbuf[0] = cd9660_chars2ui(pi,4) - 1900;
    414   1.9     perry 
    415   1.1  jdolecek 	/* month: " 1"-"12"      -> 1 - 12 */
    416  1.10  christos 	tbuf[1] = cd9660_chars2ui(pi + 4,2);
    417   1.9     perry 
    418   1.1  jdolecek 	/* day:   " 1"-"31"      -> 1 - 31 */
    419  1.10  christos 	tbuf[2] = cd9660_chars2ui(pi + 6,2);
    420   1.9     perry 
    421   1.1  jdolecek 	/* hour:  " 0"-"23"      -> 0 - 23 */
    422  1.10  christos 	tbuf[3] = cd9660_chars2ui(pi + 8,2);
    423   1.9     perry 
    424   1.1  jdolecek 	/* minute:" 0"-"59"      -> 0 - 59 */
    425  1.10  christos 	tbuf[4] = cd9660_chars2ui(pi + 10,2);
    426   1.9     perry 
    427   1.1  jdolecek 	/* second:" 0"-"59"      -> 0 - 59 */
    428  1.10  christos 	tbuf[5] = cd9660_chars2ui(pi + 12,2);
    429   1.9     perry 
    430   1.1  jdolecek 	/* difference of GMT */
    431  1.10  christos 	tbuf[6] = pi[16];
    432   1.9     perry 
    433  1.10  christos 	return cd9660_tstamp_conv7(tbuf,pu);
    434   1.1  jdolecek }
    435   1.1  jdolecek 
    436   1.1  jdolecek ino_t
    437  1.23      matt isodirino(struct iso_directory_record *isodir, struct iso_mnt *imp)
    438   1.1  jdolecek {
    439   1.1  jdolecek 	ino_t ino;
    440   1.1  jdolecek 
    441   1.1  jdolecek 	ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
    442   1.1  jdolecek 	      << imp->im_bshift;
    443   1.1  jdolecek 	return (ino);
    444   1.1  jdolecek }
    445