Home | History | Annotate | Line # | Download | only in cd9660
cd9660_node.c revision 1.23
      1  1.23      matt /*	$NetBSD: cd9660_node.c,v 1.23 2008/02/27 19:43:36 matt 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.23      matt __KERNEL_RCSID(0, "$NetBSD: cd9660_node.c,v 1.23 2008/02/27 19:43:36 matt 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.1  jdolecek 	isohashtbl = hashinit(desiredvnodes, HASH_LIST, M_ISOFSMNT, M_WAITOK,
     87   1.1  jdolecek 	    &isohash);
     88  1.19        ad 	mutex_init(&cd9660_ihash_lock, MUTEX_DEFAULT, IPL_NONE);
     89  1.19        ad 	mutex_init(&cd9660_hashlock, MUTEX_DEFAULT, IPL_NONE);
     90   1.1  jdolecek }
     91   1.1  jdolecek 
     92   1.1  jdolecek /*
     93   1.1  jdolecek  * Reinitialize inode hash table.
     94   1.1  jdolecek  */
     95   1.1  jdolecek 
     96   1.1  jdolecek void
     97  1.23      matt cd9660_reinit(void)
     98   1.1  jdolecek {
     99   1.1  jdolecek 	struct iso_node *ip;
    100   1.1  jdolecek 	struct ihashhead *oldhash1, *hash1;
    101   1.1  jdolecek 	u_long oldmask1, mask1, val;
    102   1.1  jdolecek 	u_int i;
    103   1.1  jdolecek 
    104   1.1  jdolecek 	hash1 = hashinit(desiredvnodes, HASH_LIST, M_ISOFSMNT, M_WAITOK,
    105   1.1  jdolecek 	    &mask1);
    106   1.1  jdolecek 
    107  1.19        ad 	mutex_enter(&cd9660_ihash_lock);
    108   1.1  jdolecek 	oldhash1 = isohashtbl;
    109   1.1  jdolecek 	oldmask1 = isohash;
    110   1.1  jdolecek 	isohashtbl = hash1;
    111   1.1  jdolecek 	isohash = mask1;
    112   1.1  jdolecek 	for (i = 0; i <= oldmask1; i++) {
    113   1.1  jdolecek 		while ((ip = LIST_FIRST(&oldhash1[i])) != NULL) {
    114   1.1  jdolecek 			LIST_REMOVE(ip, i_hash);
    115   1.1  jdolecek 			val = INOHASH(ip->i_dev, ip->i_number);
    116   1.1  jdolecek 			LIST_INSERT_HEAD(&hash1[val], ip, i_hash);
    117   1.1  jdolecek 		}
    118   1.1  jdolecek 	}
    119  1.19        ad 	mutex_exit(&cd9660_ihash_lock);
    120   1.1  jdolecek 	hashdone(oldhash1, M_ISOFSMNT);
    121   1.1  jdolecek }
    122   1.1  jdolecek 
    123   1.1  jdolecek /*
    124   1.1  jdolecek  * Destroy node pool and hash table.
    125   1.1  jdolecek  */
    126   1.1  jdolecek void
    127  1.23      matt cd9660_done(void)
    128   1.1  jdolecek {
    129   1.1  jdolecek 	hashdone(isohashtbl, M_ISOFSMNT);
    130   1.1  jdolecek 	pool_destroy(&cd9660_node_pool);
    131  1.19        ad 	mutex_destroy(&cd9660_ihash_lock);
    132  1.19        ad 	mutex_destroy(&cd9660_hashlock);
    133   1.6    atatat 	malloc_type_detach(M_ISOFSMNT);
    134   1.1  jdolecek }
    135   1.1  jdolecek 
    136   1.1  jdolecek /*
    137   1.1  jdolecek  * Use the device/inum pair to find the incore inode, and return a pointer
    138   1.1  jdolecek  * to it. If it is in core, but locked, wait for it.
    139   1.1  jdolecek  */
    140   1.1  jdolecek struct vnode *
    141  1.23      matt cd9660_ihashget(dev_t dev, ino_t inum, int flags)
    142   1.1  jdolecek {
    143   1.1  jdolecek 	struct iso_node *ip;
    144   1.1  jdolecek 	struct vnode *vp;
    145   1.1  jdolecek 
    146   1.1  jdolecek loop:
    147  1.19        ad 	mutex_enter(&cd9660_ihash_lock);
    148   1.1  jdolecek 	LIST_FOREACH(ip, &isohashtbl[INOHASH(dev, inum)], i_hash) {
    149   1.1  jdolecek 		if (inum == ip->i_number && dev == ip->i_dev) {
    150   1.1  jdolecek 			vp = ITOV(ip);
    151  1.19        ad 			if (flags == 0) {
    152  1.19        ad 				mutex_exit(&cd9660_ihash_lock);
    153  1.19        ad 			} else {
    154  1.20        ad 				mutex_enter(&vp->v_interlock);
    155  1.19        ad 				mutex_exit(&cd9660_ihash_lock);
    156  1.19        ad 				if (vget(vp, flags | LK_INTERLOCK))
    157  1.19        ad 					goto loop;
    158  1.19        ad 			}
    159   1.1  jdolecek 			return (vp);
    160   1.1  jdolecek 		}
    161   1.1  jdolecek 	}
    162  1.19        ad 	mutex_exit(&cd9660_ihash_lock);
    163   1.1  jdolecek 	return (NULL);
    164   1.1  jdolecek }
    165   1.1  jdolecek 
    166   1.1  jdolecek /*
    167   1.1  jdolecek  * Insert the inode into the hash table, and return it locked.
    168   1.1  jdolecek  *
    169   1.1  jdolecek  * ip->i_vnode must be initialized first.
    170   1.1  jdolecek  */
    171   1.1  jdolecek void
    172  1.23      matt cd9660_ihashins(struct iso_node *ip)
    173   1.1  jdolecek {
    174   1.1  jdolecek 	struct ihashhead *ipp;
    175   1.1  jdolecek 
    176  1.19        ad 	KASSERT(mutex_owned(&cd9660_hashlock));
    177  1.19        ad 
    178  1.19        ad 	mutex_enter(&cd9660_ihash_lock);
    179   1.1  jdolecek 	ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)];
    180   1.1  jdolecek 	LIST_INSERT_HEAD(ipp, ip, i_hash);
    181  1.19        ad 	mutex_exit(&cd9660_ihash_lock);
    182   1.1  jdolecek 
    183  1.22        ad 	vlockmgr(&ip->i_vnode->v_lock, LK_EXCLUSIVE);
    184   1.1  jdolecek }
    185   1.1  jdolecek 
    186   1.1  jdolecek /*
    187   1.1  jdolecek  * Remove the inode from the hash table.
    188   1.1  jdolecek  */
    189   1.1  jdolecek void
    190  1.23      matt cd9660_ihashrem(struct iso_node *ip)
    191   1.1  jdolecek {
    192  1.19        ad 	mutex_enter(&cd9660_ihash_lock);
    193   1.1  jdolecek 	LIST_REMOVE(ip, i_hash);
    194  1.19        ad 	mutex_exit(&cd9660_ihash_lock);
    195   1.1  jdolecek }
    196   1.1  jdolecek 
    197   1.1  jdolecek /*
    198   1.1  jdolecek  * Last reference to an inode, write the inode out and if necessary,
    199   1.1  jdolecek  * truncate and deallocate the file.
    200   1.1  jdolecek  */
    201   1.1  jdolecek int
    202  1.23      matt cd9660_inactive(void *v)
    203   1.1  jdolecek {
    204   1.1  jdolecek 	struct vop_inactive_args /* {
    205   1.1  jdolecek 		struct vnode *a_vp;
    206  1.20        ad 		bool *a_recycle;
    207   1.1  jdolecek 	} */ *ap = v;
    208   1.1  jdolecek 	struct vnode *vp = ap->a_vp;
    209   1.1  jdolecek 	struct iso_node *ip = VTOI(vp);
    210   1.1  jdolecek 	int error = 0;
    211   1.9     perry 
    212   1.1  jdolecek 	/*
    213   1.1  jdolecek 	 * If we are done with the inode, reclaim it
    214   1.1  jdolecek 	 * so that it can be reused immediately.
    215   1.1  jdolecek 	 */
    216  1.20        ad 	ip->i_flag = 0;
    217  1.20        ad 	*ap->a_recycle = (ip->inode.iso_mode == 0);
    218  1.20        ad 	VOP_UNLOCK(vp, 0);
    219   1.1  jdolecek 	return error;
    220   1.1  jdolecek }
    221   1.1  jdolecek 
    222   1.1  jdolecek /*
    223   1.1  jdolecek  * Reclaim an inode so that it can be used for other purposes.
    224   1.1  jdolecek  */
    225   1.1  jdolecek int
    226  1.23      matt cd9660_reclaim(void *v)
    227   1.1  jdolecek {
    228   1.1  jdolecek 	struct vop_reclaim_args /* {
    229   1.1  jdolecek 		struct vnode *a_vp;
    230  1.13  christos 		struct lwp *a_l;
    231   1.1  jdolecek 	} */ *ap = v;
    232   1.1  jdolecek 	struct vnode *vp = ap->a_vp;
    233   1.1  jdolecek 	struct iso_node *ip = VTOI(vp);
    234   1.9     perry 
    235  1.21        ad 	if (prtactive && vp->v_usecount > 1)
    236   1.1  jdolecek 		vprint("cd9660_reclaim: pushing active", vp);
    237   1.1  jdolecek 	/*
    238   1.1  jdolecek 	 * Remove the inode from its hash chain.
    239   1.1  jdolecek 	 */
    240   1.1  jdolecek 	cd9660_ihashrem(ip);
    241   1.1  jdolecek 	/*
    242   1.1  jdolecek 	 * Purge old data structures associated with the inode.
    243   1.1  jdolecek 	 */
    244   1.1  jdolecek 	cache_purge(vp);
    245   1.1  jdolecek 	if (ip->i_devvp) {
    246   1.1  jdolecek 		vrele(ip->i_devvp);
    247   1.1  jdolecek 		ip->i_devvp = 0;
    248   1.1  jdolecek 	}
    249  1.14        ad 	genfs_node_destroy(vp);
    250   1.1  jdolecek 	pool_put(&cd9660_node_pool, vp->v_data);
    251   1.1  jdolecek 	vp->v_data = NULL;
    252   1.1  jdolecek 	return (0);
    253   1.1  jdolecek }
    254   1.1  jdolecek 
    255   1.1  jdolecek /*
    256   1.1  jdolecek  * File attributes
    257   1.1  jdolecek  */
    258   1.1  jdolecek void
    259  1.23      matt cd9660_defattr(struct iso_directory_record *isodir, struct iso_node *inop,
    260  1.23      matt 	struct buf *bp)
    261   1.1  jdolecek {
    262   1.1  jdolecek 	struct buf *bp2 = NULL;
    263   1.1  jdolecek 	struct iso_mnt *imp;
    264   1.1  jdolecek 	struct iso_extended_attributes *ap = NULL;
    265   1.1  jdolecek 	int off;
    266   1.9     perry 
    267   1.1  jdolecek 	if (isonum_711(isodir->flags)&2) {
    268   1.1  jdolecek 		inop->inode.iso_mode = S_IFDIR;
    269   1.1  jdolecek 		/*
    270   1.1  jdolecek 		 * If we return 2, fts() will assume there are no subdirectories
    271   1.1  jdolecek 		 * (just links for the path and .), so instead we return 1.
    272   1.1  jdolecek 		 */
    273   1.1  jdolecek 		inop->inode.iso_links = 1;
    274   1.1  jdolecek 	} else {
    275   1.1  jdolecek 		inop->inode.iso_mode = S_IFREG;
    276   1.1  jdolecek 		inop->inode.iso_links = 1;
    277   1.1  jdolecek 	}
    278   1.1  jdolecek 	if (!bp
    279   1.1  jdolecek 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
    280   1.1  jdolecek 	    && (off = isonum_711(isodir->ext_attr_length))) {
    281  1.12      yamt 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift),
    282  1.12      yamt 		    NULL, &bp2);
    283   1.1  jdolecek 		bp = bp2;
    284   1.1  jdolecek 	}
    285   1.1  jdolecek 	if (bp) {
    286   1.1  jdolecek 		ap = (struct iso_extended_attributes *)bp->b_data;
    287   1.9     perry 
    288   1.1  jdolecek 		if (isonum_711(ap->version) == 1) {
    289   1.1  jdolecek 			if (!(ap->perm[1]&0x10))
    290   1.1  jdolecek 				inop->inode.iso_mode |= S_IRUSR;
    291   1.1  jdolecek 			if (!(ap->perm[1]&0x40))
    292   1.1  jdolecek 				inop->inode.iso_mode |= S_IXUSR;
    293   1.1  jdolecek 			if (!(ap->perm[0]&0x01))
    294   1.1  jdolecek 				inop->inode.iso_mode |= S_IRGRP;
    295   1.1  jdolecek 			if (!(ap->perm[0]&0x04))
    296   1.1  jdolecek 				inop->inode.iso_mode |= S_IXGRP;
    297   1.1  jdolecek 			if (!(ap->perm[0]&0x10))
    298   1.1  jdolecek 				inop->inode.iso_mode |= S_IROTH;
    299   1.1  jdolecek 			if (!(ap->perm[0]&0x40))
    300   1.1  jdolecek 				inop->inode.iso_mode |= S_IXOTH;
    301   1.1  jdolecek 			inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
    302   1.1  jdolecek 			inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
    303   1.1  jdolecek 		} else
    304   1.1  jdolecek 			ap = NULL;
    305   1.1  jdolecek 	}
    306   1.1  jdolecek 	if (!ap) {
    307   1.1  jdolecek 		inop->inode.iso_mode |=
    308   1.1  jdolecek 		    S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
    309   1.1  jdolecek 		inop->inode.iso_uid = (uid_t)0;
    310   1.1  jdolecek 		inop->inode.iso_gid = (gid_t)0;
    311   1.1  jdolecek 	}
    312   1.1  jdolecek 	if (bp2)
    313  1.17        ad 		brelse(bp2, 0);
    314   1.1  jdolecek }
    315   1.1  jdolecek 
    316   1.1  jdolecek /*
    317   1.1  jdolecek  * Time stamps
    318   1.1  jdolecek  */
    319   1.1  jdolecek void
    320  1.23      matt cd9660_deftstamp(struct iso_directory_record *isodir, struct iso_node *inop,
    321  1.23      matt 	struct buf *bp)
    322   1.1  jdolecek {
    323   1.1  jdolecek 	struct buf *bp2 = NULL;
    324   1.1  jdolecek 	struct iso_mnt *imp;
    325   1.1  jdolecek 	struct iso_extended_attributes *ap = NULL;
    326   1.1  jdolecek 	int off;
    327   1.9     perry 
    328   1.1  jdolecek 	if (!bp
    329   1.1  jdolecek 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
    330   1.1  jdolecek 	    && (off = isonum_711(isodir->ext_attr_length))) {
    331  1.12      yamt 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift),
    332  1.12      yamt 		    NULL, &bp2);
    333   1.1  jdolecek 		bp = bp2;
    334   1.1  jdolecek 	}
    335   1.1  jdolecek 	if (bp) {
    336   1.1  jdolecek 		ap = (struct iso_extended_attributes *)bp->b_data;
    337   1.9     perry 
    338   1.1  jdolecek 		if (isonum_711(ap->version) == 1) {
    339   1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
    340   1.1  jdolecek 				cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
    341   1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
    342   1.1  jdolecek 				inop->inode.iso_ctime = inop->inode.iso_atime;
    343   1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
    344   1.1  jdolecek 				inop->inode.iso_mtime = inop->inode.iso_ctime;
    345   1.1  jdolecek 		} else
    346   1.1  jdolecek 			ap = NULL;
    347   1.1  jdolecek 	}
    348   1.1  jdolecek 	if (!ap) {
    349   1.1  jdolecek 		cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime);
    350   1.1  jdolecek 		inop->inode.iso_atime = inop->inode.iso_ctime;
    351   1.1  jdolecek 		inop->inode.iso_mtime = inop->inode.iso_ctime;
    352   1.1  jdolecek 	}
    353   1.1  jdolecek 	if (bp2)
    354  1.17        ad 		brelse(bp2, 0);
    355   1.1  jdolecek }
    356   1.1  jdolecek 
    357   1.1  jdolecek int
    358  1.23      matt cd9660_tstamp_conv7(const u_char *pi, struct timespec *pu)
    359   1.1  jdolecek {
    360   1.1  jdolecek 	int crtime, days;
    361   1.1  jdolecek 	int y, m, d, hour, minute, second, tz;
    362   1.9     perry 
    363   1.1  jdolecek 	y = pi[0] + 1900;
    364   1.1  jdolecek 	m = pi[1];
    365   1.1  jdolecek 	d = pi[2];
    366   1.1  jdolecek 	hour = pi[3];
    367   1.1  jdolecek 	minute = pi[4];
    368   1.1  jdolecek 	second = pi[5];
    369   1.1  jdolecek 	tz = pi[6];
    370   1.9     perry 
    371   1.1  jdolecek 	if (y < 1970) {
    372   1.1  jdolecek 		pu->tv_sec  = 0;
    373   1.1  jdolecek 		pu->tv_nsec = 0;
    374   1.1  jdolecek 		return 0;
    375   1.1  jdolecek 	} else {
    376   1.1  jdolecek #ifdef	ORIGINAL
    377   1.1  jdolecek 		/* computes day number relative to Sept. 19th,1989 */
    378   1.1  jdolecek 		/* don't even *THINK* about changing formula. It works! */
    379   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;
    380   1.1  jdolecek #else
    381   1.1  jdolecek 		/*
    382   1.1  jdolecek 		 * Changed :-) to make it relative to Jan. 1st, 1970
    383   1.1  jdolecek 		 * and to disambiguate negative division
    384   1.1  jdolecek 		 */
    385   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;
    386   1.1  jdolecek #endif
    387   1.1  jdolecek 		crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
    388   1.9     perry 
    389   1.1  jdolecek 		/* timezone offset is unreliable on some disks */
    390   1.1  jdolecek 		if (-48 <= tz && tz <= 52)
    391   1.1  jdolecek 			crtime -= tz * 15 * 60;
    392   1.1  jdolecek 	}
    393   1.1  jdolecek 	pu->tv_sec  = crtime;
    394   1.1  jdolecek 	pu->tv_nsec = 0;
    395   1.1  jdolecek 	return 1;
    396   1.1  jdolecek }
    397   1.1  jdolecek 
    398   1.1  jdolecek static u_int
    399  1.23      matt cd9660_chars2ui(const u_char *begin, int len)
    400   1.1  jdolecek {
    401   1.1  jdolecek 	u_int rc;
    402   1.9     perry 
    403   1.1  jdolecek 	for (rc = 0; --len >= 0;) {
    404   1.1  jdolecek 		rc *= 10;
    405   1.1  jdolecek 		rc += *begin++ - '0';
    406   1.1  jdolecek 	}
    407   1.1  jdolecek 	return rc;
    408   1.1  jdolecek }
    409   1.1  jdolecek 
    410   1.1  jdolecek int
    411  1.23      matt cd9660_tstamp_conv17(const u_char *pi, struct timespec *pu)
    412   1.1  jdolecek {
    413  1.10  christos 	u_char tbuf[7];
    414   1.9     perry 
    415   1.1  jdolecek 	/* year:"0001"-"9999" -> -1900  */
    416  1.10  christos 	tbuf[0] = cd9660_chars2ui(pi,4) - 1900;
    417   1.9     perry 
    418   1.1  jdolecek 	/* month: " 1"-"12"      -> 1 - 12 */
    419  1.10  christos 	tbuf[1] = cd9660_chars2ui(pi + 4,2);
    420   1.9     perry 
    421   1.1  jdolecek 	/* day:   " 1"-"31"      -> 1 - 31 */
    422  1.10  christos 	tbuf[2] = cd9660_chars2ui(pi + 6,2);
    423   1.9     perry 
    424   1.1  jdolecek 	/* hour:  " 0"-"23"      -> 0 - 23 */
    425  1.10  christos 	tbuf[3] = cd9660_chars2ui(pi + 8,2);
    426   1.9     perry 
    427   1.1  jdolecek 	/* minute:" 0"-"59"      -> 0 - 59 */
    428  1.10  christos 	tbuf[4] = cd9660_chars2ui(pi + 10,2);
    429   1.9     perry 
    430   1.1  jdolecek 	/* second:" 0"-"59"      -> 0 - 59 */
    431  1.10  christos 	tbuf[5] = cd9660_chars2ui(pi + 12,2);
    432   1.9     perry 
    433   1.1  jdolecek 	/* difference of GMT */
    434  1.10  christos 	tbuf[6] = pi[16];
    435   1.9     perry 
    436  1.10  christos 	return cd9660_tstamp_conv7(tbuf,pu);
    437   1.1  jdolecek }
    438   1.1  jdolecek 
    439   1.1  jdolecek ino_t
    440  1.23      matt isodirino(struct iso_directory_record *isodir, struct iso_mnt *imp)
    441   1.1  jdolecek {
    442   1.1  jdolecek 	ino_t ino;
    443   1.1  jdolecek 
    444   1.1  jdolecek 	ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
    445   1.1  jdolecek 	      << imp->im_bshift;
    446   1.1  jdolecek 	return (ino);
    447   1.1  jdolecek }
    448