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