Subject: MSDOSFS: Bugs setting EOF flag in msdosfs_readdir()
To: None <netbsd-bugs@sun-lamp.cs.berkeley.edu>
From: Mike Hartman <mikeh@hds.com>
List: netbsd-bugs
Date: 08/30/1994 09:13:52
File:		msdosfs_vnops.c
Function:	msdosfs_readdir()
Description:	There are two instances where the EOF flag is not properly
		set.  In the first instance, the uio offset is at or past the
		EOF, but the EOF flag is not set.  In the second instance,
		the math to determine EOF is missing parenthesis to properly
		order the expression evaluation.

		Sample fix follows.


--
Michael Hartman			  |
Software Engineer		  | Internet: mikeh@hds.com
Human Designed Systems, Inc.	  |
421 Feheley Drive		  | phone:    (610) 277-8300
King of Prussia, PA 19406  (USA)  | FAX:      (610) 275-5739
----------------------------------------------------------------



*** msdosfs_vnops.c	Fri Aug 19 09:34:18 1994
--- msdosfs_vnops.c	Tue Aug 30 09:05:37 1994
***************
*** 1497,1508 ****
  	while (!error && uio->uio_resid > 0 && ap->a_ncookies > 0) {
  		lbn = (uio->uio_offset - bias) >> pmp->pm_cnshift;
  		on = (uio->uio_offset - bias) & pmp->pm_crbomask;
  		n = min((u_long) (pmp->pm_bpcluster - on), uio->uio_resid);
  		diff = dep->de_FileSize - (uio->uio_offset - bias);
! 		if (diff <= 0)
  			return 0;
  		if (diff < n)
  			n = diff;
  		error = pcbmap(dep, lbn, &bn, &cn);
  		if (error)
  			break;
--- 1497,1510 ----
  	while (!error && uio->uio_resid > 0 && ap->a_ncookies > 0) {
  		lbn = (uio->uio_offset - bias) >> pmp->pm_cnshift;
  		on = (uio->uio_offset - bias) & pmp->pm_crbomask;
  		n = min((u_long) (pmp->pm_bpcluster - on), uio->uio_resid);
  		diff = dep->de_FileSize - (uio->uio_offset - bias);
! 		if (diff <= 0) {
! 			*ap->a_eofflag = 1;
  			return 0;
+ 		}
  		if (diff < n)
  			n = diff;
  		error = pcbmap(dep, lbn, &bn, &cn);
  		if (error)
  			break;
***************
*** 1640,1650 ****
  	/*
  	 * I don't know why we bother setting this eofflag, getdirentries()
  	 * in vfs_syscalls.c doesn't bother to look at it when we return.
  	 * (because NFS uses it in nfs_serv.c -- JMP)
  	 */
! 	if (dep->de_FileSize - uio->uio_offset - bias <= 0)
  		*ap->a_eofflag = 1;
  	else
  		*ap->a_eofflag = 0;
  	return error;
  }
--- 1642,1652 ----
  	/*
  	 * I don't know why we bother setting this eofflag, getdirentries()
  	 * in vfs_syscalls.c doesn't bother to look at it when we return.
  	 * (because NFS uses it in nfs_serv.c -- JMP)
  	 */
! 	if (dep->de_FileSize - (uio->uio_offset - bias) <= 0)
  		*ap->a_eofflag = 1;
  	else
  		*ap->a_eofflag = 0;
  	return error;
  }


------------------------------------------------------------------------------