2004-05-20 09:39:34 +04:00
|
|
|
/* $NetBSD: cd9660_node.c,v 1.8 2004/05/20 05:39:34 atatat Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-06-08 15:22:45 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1982, 1986, 1989, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley
|
|
|
|
* by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
|
|
|
|
* Support code is derived from software contributed to Berkeley
|
|
|
|
* by Atsushi Murai (amurai@spec.co.jp).
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-06-08 15:22:45 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)cd9660_node.c 8.8 (Berkeley) 5/22/95
|
1994-06-08 15:22:45 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-12 18:25:01 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-05-20 09:39:34 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: cd9660_node.c,v 1.8 2004/05/20 05:39:34 atatat Exp $");
|
2001-11-12 18:25:01 +03:00
|
|
|
|
1994-06-08 15:22:45 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/vnode.h>
|
1996-02-10 00:31:50 +03:00
|
|
|
#include <sys/namei.h>
|
1994-06-08 15:22:45 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
1998-09-01 07:40:19 +04:00
|
|
|
#include <sys/pool.h>
|
1994-06-08 15:22:45 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2002-12-23 20:52:02 +03:00
|
|
|
#include <fs/cd9660/iso.h>
|
|
|
|
#include <fs/cd9660/cd9660_extern.h>
|
|
|
|
#include <fs/cd9660/cd9660_node.h>
|
|
|
|
#include <fs/cd9660/cd9660_mount.h>
|
|
|
|
#include <fs/cd9660/iso_rrip.h>
|
1994-06-08 15:22:45 +04:00
|
|
|
|
1994-07-14 02:30:07 +04:00
|
|
|
/*
|
|
|
|
* Structures associated with iso_node caching.
|
|
|
|
*/
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_HEAD(ihashhead, iso_node) *isohashtbl;
|
1994-07-14 02:30:07 +04:00
|
|
|
u_long isohash;
|
|
|
|
#define INOHASH(device, inum) (((device) + ((inum)>>12)) & isohash)
|
1998-03-01 05:20:01 +03:00
|
|
|
struct simplelock cd9660_ihash_slock;
|
1994-06-08 15:22:45 +04:00
|
|
|
|
1994-07-14 02:30:07 +04:00
|
|
|
#ifdef ISODEVMAP
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_HEAD(idvhashhead, iso_dnode) *idvhashtbl;
|
1994-07-14 02:30:07 +04:00
|
|
|
u_long idvhash;
|
|
|
|
#define DNOHASH(device, inum) (((device) + ((inum)>>12)) & idvhash)
|
1994-06-08 15:22:45 +04:00
|
|
|
#endif
|
|
|
|
|
2001-02-03 15:48:43 +03:00
|
|
|
extern int prtactive; /* 1 => print out reclaim of active vnodes */
|
1994-06-08 15:22:45 +04:00
|
|
|
|
2004-04-25 20:42:40 +04:00
|
|
|
POOL_INIT(cd9660_node_pool, sizeof(struct iso_node), 0, 0, 0, "cd9660nopl",
|
|
|
|
&pool_allocator_nointr);
|
1998-09-01 07:40:19 +04:00
|
|
|
|
1996-02-10 00:31:50 +03:00
|
|
|
static u_int cd9660_chars2ui __P((u_char *, int));
|
|
|
|
|
1994-06-08 15:22:45 +04:00
|
|
|
/*
|
|
|
|
* Initialize hash links for inodes and dnodes.
|
|
|
|
*/
|
1996-02-10 00:31:50 +03:00
|
|
|
void
|
1994-06-08 15:22:45 +04:00
|
|
|
cd9660_init()
|
|
|
|
{
|
2004-03-27 07:43:43 +03:00
|
|
|
#ifdef _LKM
|
|
|
|
malloc_type_attach(M_ISOFSMNT);
|
2004-05-20 09:39:34 +04:00
|
|
|
pool_init(&cd9660_node_pool, sizeof(struct iso_node), 0, 0, 0,
|
|
|
|
"cd9660nopl", &pool_allocator_nointr);
|
2004-03-27 07:43:43 +03:00
|
|
|
#endif
|
2000-11-08 17:28:12 +03:00
|
|
|
isohashtbl = hashinit(desiredvnodes, HASH_LIST, M_ISOFSMNT, M_WAITOK,
|
|
|
|
&isohash);
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock_init(&cd9660_ihash_slock);
|
1994-07-14 02:30:07 +04:00
|
|
|
#ifdef ISODEVMAP
|
2000-11-08 17:28:12 +03:00
|
|
|
idvhashtbl = hashinit(desiredvnodes / 8, HASH_LIST, M_ISOFSMNT,
|
|
|
|
M_WAITOK, &idvhash);
|
1994-06-08 15:22:45 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
/*
|
|
|
|
* Reinitialize inode hash table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
cd9660_reinit()
|
|
|
|
{
|
|
|
|
struct iso_node *ip;
|
|
|
|
struct ihashhead *oldhash1, *hash1;
|
|
|
|
u_long oldmask1, mask1, val;
|
|
|
|
#ifdef ISODEVMAP
|
|
|
|
struct iso_dnode *dp;
|
|
|
|
struct idvhashhead *oldhash2, *hash2;
|
|
|
|
u_long oldmask2, mask2;
|
|
|
|
#endif
|
2002-11-07 11:13:10 +03:00
|
|
|
u_int i;
|
2001-09-15 20:12:54 +04:00
|
|
|
|
|
|
|
hash1 = hashinit(desiredvnodes, HASH_LIST, M_ISOFSMNT, M_WAITOK,
|
|
|
|
&mask1);
|
|
|
|
#ifdef ISODEVMAP
|
|
|
|
hash2 = hashinit(desiredvnodes / 8, HASH_LIST, M_ISOFSMNT, M_WAITOK,
|
|
|
|
&mask2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
simple_lock(&cd9660_ihash_slock);
|
|
|
|
oldhash1 = isohashtbl;
|
|
|
|
oldmask1 = isohash;
|
|
|
|
isohashtbl = hash1;
|
|
|
|
isohash = mask1;
|
|
|
|
#ifdef ISODEVMAP
|
|
|
|
oldhash2 = idvhashtbl;
|
|
|
|
oldmask2 = idvhash;
|
|
|
|
idvhashtbl = hash2;
|
|
|
|
idvhash = mask2;
|
|
|
|
for (i = 0; i <= oldmask2; i++) {
|
|
|
|
while ((dp = LIST_FIRST(&oldhash2[i])) != NULL) {
|
|
|
|
LIST_REMOVE(dp, d_hash);
|
|
|
|
val = DNOHASH(dp->i_dev, dp->i_number);
|
|
|
|
LIST_INSERT_HEAD(&hash2[val], dp, d_hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
for (i = 0; i <= oldmask1; i++) {
|
|
|
|
while ((ip = LIST_FIRST(&oldhash1[i])) != NULL) {
|
|
|
|
LIST_REMOVE(ip, i_hash);
|
|
|
|
val = INOHASH(ip->i_dev, ip->i_number);
|
|
|
|
LIST_INSERT_HEAD(&hash1[val], ip, i_hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
simple_unlock(&cd9660_ihash_slock);
|
|
|
|
hashdone(oldhash1, M_ISOFSMNT);
|
|
|
|
#ifdef ISODEVMAP
|
|
|
|
hashdone(oldhash2, M_ISOFSMNT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-03-16 21:08:17 +03:00
|
|
|
/*
|
|
|
|
* Destroy node pool and hash table.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cd9660_done()
|
|
|
|
{
|
|
|
|
hashdone(isohashtbl, M_ISOFSMNT);
|
|
|
|
#ifdef ISODEVMAP
|
|
|
|
hashdone(idvhashtbl, M_ISOFSMNT);
|
|
|
|
#endif
|
2004-03-27 07:43:43 +03:00
|
|
|
#ifdef _LKM
|
2004-05-20 09:39:34 +04:00
|
|
|
pool_destroy(&cd9660_node_pool);
|
2004-03-27 07:43:43 +03:00
|
|
|
malloc_type_detach(M_ISOFSMNT);
|
|
|
|
#endif
|
2000-03-16 21:08:17 +03:00
|
|
|
}
|
|
|
|
|
1994-07-14 02:30:07 +04:00
|
|
|
#ifdef ISODEVMAP
|
1994-06-08 15:22:45 +04:00
|
|
|
/*
|
|
|
|
* Enter a new node into the device hash list
|
|
|
|
*/
|
|
|
|
struct iso_dnode *
|
1994-07-14 02:30:07 +04:00
|
|
|
iso_dmap(device, inum, create)
|
|
|
|
dev_t device;
|
|
|
|
ino_t inum;
|
1994-06-08 15:22:45 +04:00
|
|
|
int create;
|
|
|
|
{
|
2001-09-15 20:12:54 +04:00
|
|
|
struct iso_dnode *dp;
|
|
|
|
struct idvhashhead *hp;
|
1994-07-14 02:30:07 +04:00
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
hp = &idvhashtbl[DNOHASH(device, inum)];
|
|
|
|
LIST_FOREACH(dp, hp, d_hash) {
|
1994-07-14 02:30:07 +04:00
|
|
|
if (inum == dp->i_number && device == dp->i_dev)
|
|
|
|
return (dp);
|
2001-09-15 20:12:54 +04:00
|
|
|
}
|
1994-06-08 15:22:45 +04:00
|
|
|
|
|
|
|
if (!create)
|
1994-07-14 02:30:07 +04:00
|
|
|
return (NULL);
|
1994-06-08 15:22:45 +04:00
|
|
|
|
1994-07-14 02:30:07 +04:00
|
|
|
MALLOC(dp, struct iso_dnode *, sizeof(struct iso_dnode), M_CACHE,
|
|
|
|
M_WAITOK);
|
2001-09-15 20:12:54 +04:00
|
|
|
dp->i_dev = device;
|
|
|
|
dp->i_number = inum;
|
|
|
|
LIST_INSERT_HEAD(hp, dp, d_hash);
|
1994-07-14 02:30:07 +04:00
|
|
|
return (dp);
|
1994-06-08 15:22:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-07-14 02:30:07 +04:00
|
|
|
iso_dunmap(device)
|
|
|
|
dev_t device;
|
1994-06-08 15:22:45 +04:00
|
|
|
{
|
2001-09-15 20:12:54 +04:00
|
|
|
struct idvhashhead *dpp;
|
|
|
|
struct iso_dnode *dp, *dq;
|
1994-06-08 15:22:45 +04:00
|
|
|
|
1994-07-14 02:30:07 +04:00
|
|
|
for (dpp = idvhashtbl; dpp <= idvhashtbl + idvhash; dpp++) {
|
2001-09-15 20:12:54 +04:00
|
|
|
for (dp = LIST_FIRST(dpp); dp != NULL; dp = dq) {
|
|
|
|
dq = LIST_NEXT(dp, d_hash);
|
1994-07-14 02:30:07 +04:00
|
|
|
if (device == dp->i_dev) {
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_REMOVE(dp, d_hash);
|
1994-07-14 02:30:07 +04:00
|
|
|
FREE(dp, M_CACHE);
|
1994-06-08 15:22:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
1994-07-14 02:30:07 +04:00
|
|
|
* Use the device/inum pair to find the incore inode, and return a pointer
|
|
|
|
* to it. If it is in core, but locked, wait for it.
|
1994-06-08 15:22:45 +04:00
|
|
|
*/
|
1994-07-14 02:30:07 +04:00
|
|
|
struct vnode *
|
2003-06-29 22:43:21 +04:00
|
|
|
cd9660_ihashget(dev, inum)
|
1998-03-01 05:20:01 +03:00
|
|
|
dev_t dev;
|
1994-07-14 02:30:07 +04:00
|
|
|
ino_t inum;
|
1994-06-08 15:22:45 +04:00
|
|
|
{
|
1998-03-01 05:20:01 +03:00
|
|
|
struct iso_node *ip;
|
1994-07-14 02:30:07 +04:00
|
|
|
struct vnode *vp;
|
1994-06-08 15:22:45 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
loop:
|
|
|
|
simple_lock(&cd9660_ihash_slock);
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_FOREACH(ip, &isohashtbl[INOHASH(dev, inum)], i_hash) {
|
1998-03-01 05:20:01 +03:00
|
|
|
if (inum == ip->i_number && dev == ip->i_dev) {
|
|
|
|
vp = ITOV(ip);
|
|
|
|
simple_lock(&vp->v_interlock);
|
|
|
|
simple_unlock(&cd9660_ihash_slock);
|
2003-06-29 22:43:21 +04:00
|
|
|
if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK))
|
1998-03-01 05:20:01 +03:00
|
|
|
goto loop;
|
|
|
|
return (vp);
|
1994-06-08 15:22:45 +04:00
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
|
|
|
simple_unlock(&cd9660_ihash_slock);
|
|
|
|
return (NULL);
|
1994-07-14 02:30:07 +04:00
|
|
|
}
|
1994-06-08 15:22:45 +04:00
|
|
|
|
1994-07-14 02:30:07 +04:00
|
|
|
/*
|
|
|
|
* Insert the inode into the hash table, and return it locked.
|
1999-07-08 05:05:58 +04:00
|
|
|
*
|
|
|
|
* ip->i_vnode must be initialized first.
|
1994-07-14 02:30:07 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
cd9660_ihashins(ip)
|
|
|
|
struct iso_node *ip;
|
|
|
|
{
|
2001-09-15 20:12:54 +04:00
|
|
|
struct ihashhead *ipp;
|
1994-07-14 02:30:07 +04:00
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock(&cd9660_ihash_slock);
|
1994-07-14 02:30:07 +04:00
|
|
|
ipp = &isohashtbl[INOHASH(ip->i_dev, ip->i_number)];
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_INSERT_HEAD(ipp, ip, i_hash);
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_unlock(&cd9660_ihash_slock);
|
|
|
|
|
1999-07-08 05:05:58 +04:00
|
|
|
lockmgr(&ip->i_vnode->v_lock, LK_EXCLUSIVE, &ip->i_vnode->v_interlock);
|
1994-06-08 15:22:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-07-14 02:30:07 +04:00
|
|
|
* Remove the inode from the hash table.
|
1994-06-08 15:22:45 +04:00
|
|
|
*/
|
1994-07-14 02:30:07 +04:00
|
|
|
void
|
|
|
|
cd9660_ihashrem(ip)
|
2000-03-30 16:13:30 +04:00
|
|
|
struct iso_node *ip;
|
1994-06-08 15:22:45 +04:00
|
|
|
{
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_lock(&cd9660_ihash_slock);
|
2001-09-15 20:12:54 +04:00
|
|
|
LIST_REMOVE(ip, i_hash);
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_unlock(&cd9660_ihash_slock);
|
1994-06-08 15:22:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Last reference to an inode, write the inode out and if necessary,
|
|
|
|
* truncate and deallocate the file.
|
|
|
|
*/
|
|
|
|
int
|
1996-02-10 00:31:50 +03:00
|
|
|
cd9660_inactive(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:22:45 +04:00
|
|
|
struct vop_inactive_args /* {
|
|
|
|
struct vnode *a_vp;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct proc *a_p;
|
1996-02-10 00:31:50 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:22:45 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = ap->a_p;
|
2000-03-30 16:13:30 +04:00
|
|
|
struct iso_node *ip = VTOI(vp);
|
1994-12-24 18:30:03 +03:00
|
|
|
int error = 0;
|
1994-06-08 15:22:45 +04:00
|
|
|
|
|
|
|
if (prtactive && vp->v_usecount != 0)
|
|
|
|
vprint("cd9660_inactive: pushing active", vp);
|
|
|
|
|
|
|
|
ip->i_flag = 0;
|
1998-03-01 05:20:01 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1994-06-08 15:22:45 +04:00
|
|
|
/*
|
|
|
|
* If we are done with the inode, reclaim it
|
|
|
|
* so that it can be reused immediately.
|
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
if (ip->inode.iso_mode == 0)
|
2003-06-30 02:28:00 +04:00
|
|
|
vrecycle(vp, (struct simplelock *)0, p);
|
1994-06-08 15:22:45 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reclaim an inode so that it can be used for other purposes.
|
|
|
|
*/
|
|
|
|
int
|
1996-02-10 00:31:50 +03:00
|
|
|
cd9660_reclaim(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:22:45 +04:00
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct proc *a_p;
|
1996-02-10 00:31:50 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:13:30 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct iso_node *ip = VTOI(vp);
|
1994-06-08 15:22:45 +04:00
|
|
|
|
|
|
|
if (prtactive && vp->v_usecount != 0)
|
|
|
|
vprint("cd9660_reclaim: pushing active", vp);
|
|
|
|
/*
|
|
|
|
* Remove the inode from its hash chain.
|
|
|
|
*/
|
1994-07-14 02:30:07 +04:00
|
|
|
cd9660_ihashrem(ip);
|
1994-06-08 15:22:45 +04:00
|
|
|
/*
|
|
|
|
* Purge old data structures associated with the inode.
|
|
|
|
*/
|
|
|
|
cache_purge(vp);
|
|
|
|
if (ip->i_devvp) {
|
|
|
|
vrele(ip->i_devvp);
|
|
|
|
ip->i_devvp = 0;
|
|
|
|
}
|
1998-09-01 07:40:19 +04:00
|
|
|
pool_put(&cd9660_node_pool, vp->v_data);
|
1994-06-08 15:22:45 +04:00
|
|
|
vp->v_data = NULL;
|
1994-07-14 02:30:07 +04:00
|
|
|
return (0);
|
1994-06-08 15:22:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File attributes
|
|
|
|
*/
|
|
|
|
void
|
1994-07-19 18:14:08 +04:00
|
|
|
cd9660_defattr(isodir, inop, bp)
|
1994-06-08 15:22:45 +04:00
|
|
|
struct iso_directory_record *isodir;
|
|
|
|
struct iso_node *inop;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
struct buf *bp2 = NULL;
|
|
|
|
struct iso_mnt *imp;
|
|
|
|
struct iso_extended_attributes *ap = NULL;
|
|
|
|
int off;
|
|
|
|
|
|
|
|
if (isonum_711(isodir->flags)&2) {
|
|
|
|
inop->inode.iso_mode = S_IFDIR;
|
|
|
|
/*
|
|
|
|
* If we return 2, fts() will assume there are no subdirectories
|
|
|
|
* (just links for the path and .), so instead we return 1.
|
|
|
|
*/
|
|
|
|
inop->inode.iso_links = 1;
|
|
|
|
} else {
|
|
|
|
inop->inode.iso_mode = S_IFREG;
|
|
|
|
inop->inode.iso_links = 1;
|
|
|
|
}
|
|
|
|
if (!bp
|
1994-07-19 18:14:08 +04:00
|
|
|
&& ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
|
1994-06-08 15:22:45 +04:00
|
|
|
&& (off = isonum_711(isodir->ext_attr_length))) {
|
1994-07-19 19:27:40 +04:00
|
|
|
VOP_BLKATOFF(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
|
1994-07-19 19:07:36 +04:00
|
|
|
&bp2);
|
1994-06-08 15:22:45 +04:00
|
|
|
bp = bp2;
|
|
|
|
}
|
|
|
|
if (bp) {
|
1994-06-15 03:54:44 +04:00
|
|
|
ap = (struct iso_extended_attributes *)bp->b_data;
|
1994-06-08 15:22:45 +04:00
|
|
|
|
|
|
|
if (isonum_711(ap->version) == 1) {
|
|
|
|
if (!(ap->perm[1]&0x10))
|
1997-05-05 11:13:57 +04:00
|
|
|
inop->inode.iso_mode |= S_IRUSR;
|
|
|
|
if (!(ap->perm[1]&0x40))
|
|
|
|
inop->inode.iso_mode |= S_IXUSR;
|
|
|
|
if (!(ap->perm[0]&0x01))
|
|
|
|
inop->inode.iso_mode |= S_IRGRP;
|
|
|
|
if (!(ap->perm[0]&0x04))
|
|
|
|
inop->inode.iso_mode |= S_IXGRP;
|
|
|
|
if (!(ap->perm[0]&0x10))
|
|
|
|
inop->inode.iso_mode |= S_IROTH;
|
|
|
|
if (!(ap->perm[0]&0x40))
|
|
|
|
inop->inode.iso_mode |= S_IXOTH;
|
1994-06-08 15:22:45 +04:00
|
|
|
inop->inode.iso_uid = isonum_723(ap->owner); /* what about 0? */
|
|
|
|
inop->inode.iso_gid = isonum_723(ap->group); /* what about 0? */
|
|
|
|
} else
|
|
|
|
ap = NULL;
|
|
|
|
}
|
|
|
|
if (!ap) {
|
1997-05-05 11:13:57 +04:00
|
|
|
inop->inode.iso_mode |=
|
|
|
|
S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
|
1994-06-08 15:22:45 +04:00
|
|
|
inop->inode.iso_uid = (uid_t)0;
|
|
|
|
inop->inode.iso_gid = (gid_t)0;
|
|
|
|
}
|
|
|
|
if (bp2)
|
|
|
|
brelse(bp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Time stamps
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cd9660_deftstamp(isodir,inop,bp)
|
|
|
|
struct iso_directory_record *isodir;
|
|
|
|
struct iso_node *inop;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
struct buf *bp2 = NULL;
|
|
|
|
struct iso_mnt *imp;
|
|
|
|
struct iso_extended_attributes *ap = NULL;
|
|
|
|
int off;
|
|
|
|
|
|
|
|
if (!bp
|
1994-07-19 18:14:08 +04:00
|
|
|
&& ((imp = inop->i_mnt)->im_flags & ISOFSMNT_EXTATT)
|
1994-06-08 15:22:45 +04:00
|
|
|
&& (off = isonum_711(isodir->ext_attr_length))) {
|
1994-07-19 19:27:40 +04:00
|
|
|
VOP_BLKATOFF(ITOV(inop), (off_t)-(off << imp->im_bshift), NULL,
|
1994-07-19 19:07:36 +04:00
|
|
|
&bp2);
|
1994-06-08 15:22:45 +04:00
|
|
|
bp = bp2;
|
|
|
|
}
|
|
|
|
if (bp) {
|
1994-06-15 03:54:44 +04:00
|
|
|
ap = (struct iso_extended_attributes *)bp->b_data;
|
1994-06-08 15:22:45 +04:00
|
|
|
|
|
|
|
if (isonum_711(ap->version) == 1) {
|
|
|
|
if (!cd9660_tstamp_conv17(ap->ftime,&inop->inode.iso_atime))
|
|
|
|
cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_atime);
|
|
|
|
if (!cd9660_tstamp_conv17(ap->ctime,&inop->inode.iso_ctime))
|
|
|
|
inop->inode.iso_ctime = inop->inode.iso_atime;
|
|
|
|
if (!cd9660_tstamp_conv17(ap->mtime,&inop->inode.iso_mtime))
|
|
|
|
inop->inode.iso_mtime = inop->inode.iso_ctime;
|
|
|
|
} else
|
|
|
|
ap = NULL;
|
|
|
|
}
|
|
|
|
if (!ap) {
|
|
|
|
cd9660_tstamp_conv7(isodir->date,&inop->inode.iso_ctime);
|
|
|
|
inop->inode.iso_atime = inop->inode.iso_ctime;
|
|
|
|
inop->inode.iso_mtime = inop->inode.iso_ctime;
|
|
|
|
}
|
|
|
|
if (bp2)
|
|
|
|
brelse(bp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cd9660_tstamp_conv7(pi,pu)
|
1994-09-22 06:47:31 +04:00
|
|
|
u_char *pi;
|
1994-09-22 06:44:35 +04:00
|
|
|
struct timespec *pu;
|
1994-06-08 15:22:45 +04:00
|
|
|
{
|
|
|
|
int crtime, days;
|
|
|
|
int y, m, d, hour, minute, second, tz;
|
|
|
|
|
|
|
|
y = pi[0] + 1900;
|
|
|
|
m = pi[1];
|
|
|
|
d = pi[2];
|
|
|
|
hour = pi[3];
|
|
|
|
minute = pi[4];
|
|
|
|
second = pi[5];
|
|
|
|
tz = pi[6];
|
|
|
|
|
|
|
|
if (y < 1970) {
|
1996-02-01 03:18:04 +03:00
|
|
|
pu->tv_sec = 0;
|
|
|
|
pu->tv_nsec = 0;
|
1994-06-08 15:22:45 +04:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
#ifdef ORIGINAL
|
|
|
|
/* computes day number relative to Sept. 19th,1989 */
|
|
|
|
/* don't even *THINK* about changing formula. It works! */
|
|
|
|
days = 367*(y-1980)-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4+275*m/9+d-100;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Changed :-) to make it relative to Jan. 1st, 1970
|
|
|
|
* and to disambiguate negative division
|
|
|
|
*/
|
|
|
|
days = 367*(y-1960)-7*(y+(m+9)/12)/4-3*((y+(m+9)/12-1)/100+1)/4+275*m/9+d-239;
|
|
|
|
#endif
|
|
|
|
crtime = ((((days * 24) + hour) * 60 + minute) * 60) + second;
|
|
|
|
|
|
|
|
/* timezone offset is unreliable on some disks */
|
|
|
|
if (-48 <= tz && tz <= 52)
|
|
|
|
crtime -= tz * 15 * 60;
|
|
|
|
}
|
1996-02-01 03:18:04 +03:00
|
|
|
pu->tv_sec = crtime;
|
|
|
|
pu->tv_nsec = 0;
|
1994-06-08 15:22:45 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1994-07-03 13:51:58 +04:00
|
|
|
static u_int
|
1994-06-08 15:22:45 +04:00
|
|
|
cd9660_chars2ui(begin,len)
|
1994-07-03 13:51:58 +04:00
|
|
|
u_char *begin;
|
1994-06-08 15:22:45 +04:00
|
|
|
int len;
|
|
|
|
{
|
1994-07-03 13:51:58 +04:00
|
|
|
u_int rc;
|
1994-06-08 15:22:45 +04:00
|
|
|
|
|
|
|
for (rc = 0; --len >= 0;) {
|
|
|
|
rc *= 10;
|
|
|
|
rc += *begin++ - '0';
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cd9660_tstamp_conv17(pi,pu)
|
1994-07-03 13:51:58 +04:00
|
|
|
u_char *pi;
|
1994-09-22 06:44:35 +04:00
|
|
|
struct timespec *pu;
|
1994-06-08 15:22:45 +04:00
|
|
|
{
|
1994-07-03 13:51:58 +04:00
|
|
|
u_char buf[7];
|
1994-06-08 15:22:45 +04:00
|
|
|
|
|
|
|
/* year:"0001"-"9999" -> -1900 */
|
|
|
|
buf[0] = cd9660_chars2ui(pi,4) - 1900;
|
|
|
|
|
|
|
|
/* month: " 1"-"12" -> 1 - 12 */
|
|
|
|
buf[1] = cd9660_chars2ui(pi + 4,2);
|
|
|
|
|
|
|
|
/* day: " 1"-"31" -> 1 - 31 */
|
|
|
|
buf[2] = cd9660_chars2ui(pi + 6,2);
|
|
|
|
|
|
|
|
/* hour: " 0"-"23" -> 0 - 23 */
|
|
|
|
buf[3] = cd9660_chars2ui(pi + 8,2);
|
|
|
|
|
|
|
|
/* minute:" 0"-"59" -> 0 - 59 */
|
|
|
|
buf[4] = cd9660_chars2ui(pi + 10,2);
|
|
|
|
|
|
|
|
/* second:" 0"-"59" -> 0 - 59 */
|
|
|
|
buf[5] = cd9660_chars2ui(pi + 12,2);
|
|
|
|
|
|
|
|
/* difference of GMT */
|
|
|
|
buf[6] = pi[16];
|
|
|
|
|
|
|
|
return cd9660_tstamp_conv7(buf,pu);
|
|
|
|
}
|
|
|
|
|
1994-07-19 18:14:08 +04:00
|
|
|
ino_t
|
|
|
|
isodirino(isodir, imp)
|
1994-06-08 15:22:45 +04:00
|
|
|
struct iso_directory_record *isodir;
|
|
|
|
struct iso_mnt *imp;
|
|
|
|
{
|
1994-07-19 18:14:08 +04:00
|
|
|
ino_t ino;
|
|
|
|
|
|
|
|
ino = (isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length))
|
|
|
|
<< imp->im_bshift;
|
|
|
|
return (ino);
|
1994-06-08 15:22:45 +04:00
|
|
|
}
|