Home | History | Annotate | Line # | Download | only in cd9660
cd9660_node.c revision 1.24.22.3
      1  1.24.22.3     rmind /*	$NetBSD: cd9660_node.c,v 1.24.22.3 2011/03/05 20:55:03 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.24.22.3     rmind __KERNEL_RCSID(0, "$NetBSD: cd9660_node.c,v 1.24.22.3 2011/03/05 20:55:03 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.24.22.1     rmind 				mutex_enter(vp->v_interlock);
    153       1.19        ad 				mutex_exit(&cd9660_ihash_lock);
    154  1.24.22.3     rmind 				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.24.22.2     rmind 	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.24.22.2     rmind 	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 	cache_purge(vp);
    243        1.1  jdolecek 	if (ip->i_devvp) {
    244        1.1  jdolecek 		vrele(ip->i_devvp);
    245        1.1  jdolecek 		ip->i_devvp = 0;
    246        1.1  jdolecek 	}
    247       1.14        ad 	genfs_node_destroy(vp);
    248        1.1  jdolecek 	pool_put(&cd9660_node_pool, vp->v_data);
    249        1.1  jdolecek 	vp->v_data = NULL;
    250        1.1  jdolecek 	return (0);
    251        1.1  jdolecek }
    252        1.1  jdolecek 
    253        1.1  jdolecek /*
    254        1.1  jdolecek  * File attributes
    255        1.1  jdolecek  */
    256        1.1  jdolecek void
    257       1.23      matt cd9660_defattr(struct iso_directory_record *isodir, struct iso_node *inop,
    258       1.23      matt 	struct buf *bp)
    259        1.1  jdolecek {
    260        1.1  jdolecek 	struct buf *bp2 = NULL;
    261        1.1  jdolecek 	struct iso_mnt *imp;
    262        1.1  jdolecek 	struct iso_extended_attributes *ap = NULL;
    263        1.1  jdolecek 	int off;
    264        1.9     perry 
    265        1.1  jdolecek 	if (isonum_711(isodir->flags)&2) {
    266        1.1  jdolecek 		inop->inode.iso_mode = S_IFDIR;
    267        1.1  jdolecek 		/*
    268        1.1  jdolecek 		 * If we return 2, fts() will assume there are no subdirectories
    269        1.1  jdolecek 		 * (just links for the path and .), so instead we return 1.
    270        1.1  jdolecek 		 */
    271        1.1  jdolecek 		inop->inode.iso_links = 1;
    272        1.1  jdolecek 	} else {
    273        1.1  jdolecek 		inop->inode.iso_mode = S_IFREG;
    274        1.1  jdolecek 		inop->inode.iso_links = 1;
    275        1.1  jdolecek 	}
    276        1.1  jdolecek 	if (!bp
    277        1.1  jdolecek 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
    278        1.1  jdolecek 	    && (off = isonum_711(isodir->ext_attr_length))) {
    279       1.12      yamt 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift),
    280       1.12      yamt 		    NULL, &bp2);
    281        1.1  jdolecek 		bp = bp2;
    282        1.1  jdolecek 	}
    283        1.1  jdolecek 	if (bp) {
    284        1.1  jdolecek 		ap = (struct iso_extended_attributes *)bp->b_data;
    285        1.9     perry 
    286        1.1  jdolecek 		if (isonum_711(ap->version) == 1) {
    287        1.1  jdolecek 			if (!(ap->perm[1]&0x10))
    288        1.1  jdolecek 				inop->inode.iso_mode |= S_IRUSR;
    289        1.1  jdolecek 			if (!(ap->perm[1]&0x40))
    290        1.1  jdolecek 				inop->inode.iso_mode |= S_IXUSR;
    291        1.1  jdolecek 			if (!(ap->perm[0]&0x01))
    292        1.1  jdolecek 				inop->inode.iso_mode |= S_IRGRP;
    293        1.1  jdolecek 			if (!(ap->perm[0]&0x04))
    294        1.1  jdolecek 				inop->inode.iso_mode |= S_IXGRP;
    295        1.1  jdolecek 			if (!(ap->perm[0]&0x10))
    296        1.1  jdolecek 				inop->inode.iso_mode |= S_IROTH;
    297        1.1  jdolecek 			if (!(ap->perm[0]&0x40))
    298        1.1  jdolecek 				inop->inode.iso_mode |= S_IXOTH;
    299        1.1  jdolecek 			inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
    300        1.1  jdolecek 			inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
    301        1.1  jdolecek 		} else
    302        1.1  jdolecek 			ap = NULL;
    303        1.1  jdolecek 	}
    304        1.1  jdolecek 	if (!ap) {
    305        1.1  jdolecek 		inop->inode.iso_mode |=
    306        1.1  jdolecek 		    S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
    307        1.1  jdolecek 		inop->inode.iso_uid = (uid_t)0;
    308        1.1  jdolecek 		inop->inode.iso_gid = (gid_t)0;
    309        1.1  jdolecek 	}
    310        1.1  jdolecek 	if (bp2)
    311       1.17        ad 		brelse(bp2, 0);
    312        1.1  jdolecek }
    313        1.1  jdolecek 
    314        1.1  jdolecek /*
    315        1.1  jdolecek  * Time stamps
    316        1.1  jdolecek  */
    317        1.1  jdolecek void
    318       1.23      matt cd9660_deftstamp(struct iso_directory_record *isodir, struct iso_node *inop,
    319       1.23      matt 	struct buf *bp)
    320        1.1  jdolecek {
    321        1.1  jdolecek 	struct buf *bp2 = NULL;
    322        1.1  jdolecek 	struct iso_mnt *imp;
    323        1.1  jdolecek 	struct iso_extended_attributes *ap = NULL;
    324        1.1  jdolecek 	int off;
    325        1.9     perry 
    326        1.1  jdolecek 	if (!bp
    327        1.1  jdolecek 	    && ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
    328        1.1  jdolecek 	    && (off = isonum_711(isodir->ext_attr_length))) {
    329       1.12      yamt 		cd9660_blkatoff(ITOV(inop), (off_t)-(off << imp->im_bshift),
    330       1.12      yamt 		    NULL, &bp2);
    331        1.1  jdolecek 		bp = bp2;
    332        1.1  jdolecek 	}
    333        1.1  jdolecek 	if (bp) {
    334        1.1  jdolecek 		ap = (struct iso_extended_attributes *)bp->b_data;
    335        1.9     perry 
    336        1.1  jdolecek 		if (isonum_711(ap->version) == 1) {
    337        1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
    338        1.1  jdolecek 				cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
    339        1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
    340        1.1  jdolecek 				inop->inode.iso_ctime = inop->inode.iso_atime;
    341        1.1  jdolecek 			if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
    342        1.1  jdolecek 				inop->inode.iso_mtime = inop->inode.iso_ctime;
    343        1.1  jdolecek 		} else
    344        1.1  jdolecek 			ap = NULL;
    345        1.1  jdolecek 	}
    346        1.1  jdolecek 	if (!ap) {
    347        1.1  jdolecek 		cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime);
    348        1.1  jdolecek 		inop->inode.iso_atime = inop->inode.iso_ctime;
    349        1.1  jdolecek 		inop->inode.iso_mtime = inop->inode.iso_ctime;
    350        1.1  jdolecek 	}
    351        1.1  jdolecek 	if (bp2)
    352       1.17        ad 		brelse(bp2, 0);
    353        1.1  jdolecek }
    354        1.1  jdolecek 
    355        1.1  jdolecek int
    356       1.23      matt cd9660_tstamp_conv7(const u_char *pi, struct timespec *pu)
    357        1.1  jdolecek {
    358        1.1  jdolecek 	int crtime, days;
    359        1.1  jdolecek 	int y, m, d, hour, minute, second, tz;
    360        1.9     perry 
    361        1.1  jdolecek 	y = pi[0] + 1900;
    362        1.1  jdolecek 	m = pi[1];
    363        1.1  jdolecek 	d = pi[2];
    364        1.1  jdolecek 	hour = pi[3];
    365        1.1  jdolecek 	minute = pi[4];
    366        1.1  jdolecek 	second = pi[5];
    367        1.1  jdolecek 	tz = pi[6];
    368        1.9     perry 
    369        1.1  jdolecek 	if (y < 1970) {
    370        1.1  jdolecek 		pu->tv_sec  = 0;
    371        1.1  jdolecek 		pu->tv_nsec = 0;
    372        1.1  jdolecek 		return 0;
    373        1.1  jdolecek 	} else {
    374        1.1  jdolecek #ifdef	ORIGINAL
    375        1.1  jdolecek 		/* computes day number relative to Sept. 19th,1989 */
    376        1.1  jdolecek 		/* don't even *THINK* about changing formula. It works! */
    377        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;
    378        1.1  jdolecek #else
    379        1.1  jdolecek 		/*
    380        1.1  jdolecek 		 * Changed :-) to make it relative to Jan. 1st, 1970
    381        1.1  jdolecek 		 * and to disambiguate negative division
    382        1.1  jdolecek 		 */
    383        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;
    384        1.1  jdolecek #endif
    385        1.1  jdolecek 		crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
    386        1.9     perry 
    387        1.1  jdolecek 		/* timezone offset is unreliable on some disks */
    388        1.1  jdolecek 		if (-48 <= tz && tz <= 52)
    389        1.1  jdolecek 			crtime -= tz * 15 * 60;
    390        1.1  jdolecek 	}
    391        1.1  jdolecek 	pu->tv_sec  = crtime;
    392        1.1  jdolecek 	pu->tv_nsec = 0;
    393        1.1  jdolecek 	return 1;
    394        1.1  jdolecek }
    395        1.1  jdolecek 
    396        1.1  jdolecek static u_int
    397       1.23      matt cd9660_chars2ui(const u_char *begin, int len)
    398        1.1  jdolecek {
    399        1.1  jdolecek 	u_int rc;
    400        1.9     perry 
    401        1.1  jdolecek 	for (rc = 0; --len >= 0;) {
    402        1.1  jdolecek 		rc *= 10;
    403        1.1  jdolecek 		rc += *begin++ - '0';
    404        1.1  jdolecek 	}
    405        1.1  jdolecek 	return rc;
    406        1.1  jdolecek }
    407        1.1  jdolecek 
    408        1.1  jdolecek int
    409       1.23      matt cd9660_tstamp_conv17(const u_char *pi, struct timespec *pu)
    410        1.1  jdolecek {
    411       1.10  christos 	u_char tbuf[7];
    412        1.9     perry 
    413        1.1  jdolecek 	/* year:"0001"-"9999" -> -1900  */
    414       1.10  christos 	tbuf[0] = cd9660_chars2ui(pi,4) - 1900;
    415        1.9     perry 
    416        1.1  jdolecek 	/* month: " 1"-"12"      -> 1 - 12 */
    417       1.10  christos 	tbuf[1] = cd9660_chars2ui(pi + 4,2);
    418        1.9     perry 
    419        1.1  jdolecek 	/* day:   " 1"-"31"      -> 1 - 31 */
    420       1.10  christos 	tbuf[2] = cd9660_chars2ui(pi + 6,2);
    421        1.9     perry 
    422        1.1  jdolecek 	/* hour:  " 0"-"23"      -> 0 - 23 */
    423       1.10  christos 	tbuf[3] = cd9660_chars2ui(pi + 8,2);
    424        1.9     perry 
    425        1.1  jdolecek 	/* minute:" 0"-"59"      -> 0 - 59 */
    426       1.10  christos 	tbuf[4] = cd9660_chars2ui(pi + 10,2);
    427        1.9     perry 
    428        1.1  jdolecek 	/* second:" 0"-"59"      -> 0 - 59 */
    429       1.10  christos 	tbuf[5] = cd9660_chars2ui(pi + 12,2);
    430        1.9     perry 
    431        1.1  jdolecek 	/* difference of GMT */
    432       1.10  christos 	tbuf[6] = pi[16];
    433        1.9     perry 
    434       1.10  christos 	return cd9660_tstamp_conv7(tbuf,pu);
    435        1.1  jdolecek }
    436        1.1  jdolecek 
    437        1.1  jdolecek ino_t
    438       1.23      matt isodirino(struct iso_directory_record *isodir, struct iso_mnt *imp)
    439        1.1  jdolecek {
    440        1.1  jdolecek 	ino_t ino;
    441        1.1  jdolecek 
    442        1.1  jdolecek 	ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
    443        1.1  jdolecek 	      << imp->im_bshift;
    444        1.1  jdolecek 	return (ino);
    445        1.1  jdolecek }
    446