From owner-FreeBSD-users-jp@jp.freebsd.org  Sun Nov 17 18:22:14 1996
Received: by jaz.jp.freebsd.org (8.7.3+2.6Wbeta5/8.7.3) id SAA04755
	Sun, 17 Nov 1996 18:22:14 +0900 (JST)
Received: by jaz.jp.freebsd.org (8.7.3+2.6Wbeta5/8.7.3) with ESMTP id SAA04750
	for <FreeBSD-users-jp@jp.freebsd.org>; Sun, 17 Nov 1996 18:22:13 +0900 (JST)
Received: from aulin.st.rim.or.jp (ppp901.st.rim.or.jp [202.247.140.1]) by mail.st.rim.or.jp (8.7.5/3.4W3-rim1.1) with SMTP id SAA08224; Sun, 17 Nov 1996 18:22:10 +0900 (JST)
Received: from localhost (localhost [127.0.0.1]) by aulin.st.rim.or.jp (8.6.12/3.3W7-95011320) with SMTP id SAA00310; Sun, 17 Nov 1996 18:19:59 +0900
Message-Id: <199611170919.SAA00310@aulin.st.rim.or.jp>
To: FreeBSD-users-jp@jp.freebsd.org
cc: yokamura@st.rim.or.jp
In-reply-to: Your message of "Sat, 16 Nov 96 17:54:39 JST."
             <199611160854.RAA00300@aulin.st.rim.or.jp> 
Date: Sun, 17 Nov 1996 18:19:59 +0900
From: Okamura Yoshihito <yokamura@aulin.st.rim.or.jp>
Reply-To: FreeBSD-users-jp@jp.freebsd.org
X-Distribute: distribute [version 2.1 (Alpha) patchlevel=19]
X-Sequence: FreeBSD-users-jp 6415
Subject: [FreeBSD-users-jp 6415] grep on isofs and msdosfs 
Errors-To: owner-FreeBSD-users-jp@jp.freebsd.org
Sender: owner-FreeBSD-users-jp@jp.freebsd.org

$B!!2,B<$G$9!#(BISOFS$B$H(BMSDOSFS$B$K(BHAVE_WORKING_MMAP=1$B$G(Bmake$B$5$l$?(Bgrep$B$r;HMQ$9(B
$B$k$H(Bpanic$B$9$k7o$G$9$,!"$3$l$i$N%U%!%$%k%7%9%F%`$K(Bufs$B$G9T$C$F$$$k=hM}$H(B
$B$[$\F1MM$N=hM}$rDI2C$7$^$7$?!#$$$^$N$H$3$m$3$l$G(Bpanic$B$dIT6q9g$O=P$F$*$j(B
$B$^$;$s$,!";d$O(BMSDOSFS$B$O(Bread only$B$G$7$+%^%&%s%H$7$F$*$j$^$;$s$N$G!"=q$-(B
$B9~$_$O$7$F$*$j$^$;$s!#(B

$B!!0JA0;d$,:n@.$7$?%Q%C%A$O=hM}$,IT==J,$J$N$G!"$3$A$i$r;HMQ$9$k$3$H$r$*(B
$B4+$a$7$^$9!#(B


*** cd9660_node.c.orig	Wed Jun 12 12:41:35 1996
--- cd9660_node.c	Sun Nov 17 17:36:34 1996
*************** iso_ilock(ip)
*** 420,428 ****
  {
  
  	while (ip->i_flag & ILOCKED) {
  		ip->i_flag |= IWANT;
- 		if (ip->i_spare0 == curproc->p_pid)
- 			panic("locking against myself");
  		ip->i_spare1 = curproc->p_pid;
  		(void) tsleep((caddr_t)ip, PINOD, "isoilk", 0);
  	}
--- 420,435 ----
  {
  
  	while (ip->i_flag & ILOCKED) {
+ 		if (ip->i_spare0 == curproc->p_pid) {
+ 			if((ip->i_flag & IRECURSE) == 0)
+ 				panic("locking against myself");
+ 			else {
+ 				++ip->i_lockcount;
+ 				return(0);
+ 			}
+ 				
+ 		}
  		ip->i_flag |= IWANT;
  		ip->i_spare1 = curproc->p_pid;
  		(void) tsleep((caddr_t)ip, PINOD, "isoilk", 0);
  	}
*************** iso_iunlock(ip)
*** 440,449 ****
  	register struct iso_node *ip;
  {
  
  	if ((ip->i_flag & ILOCKED) == 0)
  		vprint("iso_iunlock: unlocked inode", ITOV(ip));
  	ip->i_spare0 = 0;
! 	ip->i_flag &= ~ILOCKED;
  	if (ip->i_flag&IWANT) {
  		ip->i_flag &= ~IWANT;
  		wakeup((caddr_t)ip);
--- 447,460 ----
  	register struct iso_node *ip;
  {
  
+ 	if(ip->i_lockcount > 0) {
+ 		--ip->i_lockcount;
+ 		return(0);
+ 	}
  	if ((ip->i_flag & ILOCKED) == 0)
  		vprint("iso_iunlock: unlocked inode", ITOV(ip));
  	ip->i_spare0 = 0;
! 	ip->i_flag &= ~(ILOCKED|IRECURSE);
  	if (ip->i_flag&IWANT) {
  		ip->i_flag &= ~IWANT;
  		wakeup((caddr_t)ip);

*** cd9660_node.h.orig	Fri Mar 17 03:12:16 1995
--- cd9660_node.h	Sun Nov 17 17:11:29 1996
*************** struct iso_node {
*** 95,100 ****
--- 95,101 ----
  	long iso_start;		/* actual start of data of file (may be different */
  				/* from iso_extent, if file has extended attributes) */
  	ISO_RRIP_INODE	inode;
+ 	int		i_lockcount; /* Process lock count (recursion) */
  };
  
  #define	i_forw		i_chain[0]
*************** struct iso_node {
*** 104,109 ****
--- 105,111 ----
  #define	ILOCKED		0x0001		/* inode is locked */
  #define	IWANT		0x0002		/* some process waiting on lock */
  #define	IACC		0x0020		/* inode access time to be updated */
+ #define	IRECURSE	0x0400		/* Recursion expected */
  
  #define VTOI(vp) ((struct iso_node *)(vp)->v_data)
  #define ITOV(ip) ((ip)->i_vnode)

*** cd9660_vnops.c.org	Wed Jun 26 03:30:21 1996
--- cd9660_vnops.c	Sun Nov 17 17:14:38 1996
*************** cd9660_read(ap)
*** 331,337 ****
--- 331,341 ----
  			return (error);
  		}
  
+ 		if (uio->uio_segflg != UIO_NOCOPY)
+ 			ip->i_flag |= IRECURSE;
  		error = uiomove(bp->b_un.b_addr + on, (int)n, uio);
+ 		if (uio->uio_segflg != UIO_NOCOPY)
+ 			ip->i_flag &= ~IRECURSE;
  		brelse(bp);
  	} while (error == 0 && uio->uio_resid > 0 && n != 0);
  	return (error);

*** denode.h.org	Tue May 30 17:07:32 1995
--- denode.h	Sun Nov 17 17:48:48 1996
*************** struct denode {
*** 159,164 ****
--- 159,165 ----
  	u_short de_StartCluster; /* starting cluster of file */
  	u_long de_FileSize;	/* size of file in bytes */
  	struct fatcache de_fc[FC_SIZE];	/* fat cache */
+ 	int	de_lockcount;	/* Process lock count (recursion) */
  };
  
  /*
*************** struct denode {
*** 169,174 ****
--- 170,176 ----
  #define	DE_UPDATE	0x0004	/* modification time update request */
  #define	DE_MODIFIED	0x0080	/* denode has been modified, but DE_UPDATE
  				 * isn't set */
+ #define DE_RECURSE	0x0400	/* Recursion expected */
  
  /*
   * Transfer directory entries between internal and external form.

*** msdosfs_vnops.c.org	Wed Jul  3 03:40:22 1996
--- msdosfs_vnops.c	Sun Nov 17 17:56:08 1996
*************** msdosfs_read(ap)
*** 535,541 ****
--- 535,545 ----
  			brelse(bp);
  			return error;
  		}
+ 		if (uio->uio_segflg != UIO_NOCOPY)
+ 			dep->de_flag |= DE_RECURSE;
  		error = uiomove(bp->b_data + on, (int) n, uio);
+ 		if (uio->uio_segflg != UIO_NOCOPY)
+ 			dep->de_flag &= ~DE_RECURSE;
  		/*
  		 * If we have read everything from this block or have read
  		 * to end of file then we are done with this block.  Mark
*************** msdosfs_write(ap)
*** 728,734 ****
--- 732,742 ----
  		/*
  		 * Copy the data from user space into the buf header.
  		 */
+ 		if (uio->uio_segflg != UIO_NOCOPY)
+ 			dep->de_flag |= DE_RECURSE;
  		error = uiomove(bp->b_data + croffset, n, uio);
+ 		if (uio->uio_segflg != UIO_NOCOPY)
+ 			dep->de_flag &= ~DE_RECURSE;
  
  		/*
  		 * If they want this synchronous then write it and wait for
*************** msdosfs_lock(ap)
*** 1757,1765 ****
  	struct denode *dep = VTODE(ap->a_vp);
  
  	while (dep->de_flag & DE_LOCKED) {
  		dep->de_flag |= DE_WANTED;
- 		if (dep->de_lockholder == curproc->p_pid)
- 			panic("msdosfs_lock: locking against myself");
  		dep->de_lockwaiter = curproc->p_pid;
  		(void) tsleep((caddr_t) dep, PINOD, "msdlck", 0);
  	}
--- 1765,1779 ----
  	struct denode *dep = VTODE(ap->a_vp);
  
  	while (dep->de_flag & DE_LOCKED) {
+ 		if (dep->de_lockholder == curproc->p_pid) {
+ 			if ((dep->de_flag & DE_RECURSE) == 0)
+ 				panic("msdosfs_lock: locking against myself");
+ 			else {
+ 				++dep->de_lockcount;
+ 				return 0;
+ 			}
+ 		}
  		dep->de_flag |= DE_WANTED;
  		dep->de_lockwaiter = curproc->p_pid;
  		(void) tsleep((caddr_t) dep, PINOD, "msdlck", 0);
  	}
*************** msdosfs_unlock(ap)
*** 1777,1786 ****
  {
  	struct denode *dep = VTODE(ap->a_vp);
  
  	if (!(dep->de_flag & DE_LOCKED))
  		panic("msdosfs_unlock: denode not locked");
  	dep->de_lockholder = 0;
! 	dep->de_flag &= ~DE_LOCKED;
  	if (dep->de_flag & DE_WANTED) {
  		dep->de_flag &= ~DE_WANTED;
  		wakeup((caddr_t) dep);
--- 1791,1804 ----
  {
  	struct denode *dep = VTODE(ap->a_vp);
  
+ 	if(dep->de_lockcount > 0) {
+ 		--dep->de_lockcount;
+ 		return 0;
+ 	}
  	if (!(dep->de_flag & DE_LOCKED))
  		panic("msdosfs_unlock: denode not locked");
  	dep->de_lockholder = 0;
! 	dep->de_flag &= ~(DE_LOCKED|DE_RECURSE);
  	if (dep->de_flag & DE_WANTED) {
  		dep->de_flag &= ~DE_WANTED;
  		wakeup((caddr_t) dep);



					okamura 
