From nobody@FreeBSD.org  Sun Mar 24 02:47:10 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 98CAE833
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 24 Mar 2013 02:47:10 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 7155F7B0
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 24 Mar 2013 02:47:10 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r2O2l9Q5013101
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 24 Mar 2013 02:47:09 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r2O2l9hW013100;
	Sun, 24 Mar 2013 02:47:09 GMT
	(envelope-from nobody)
Message-Id: <201303240247.r2O2l9hW013100@red.freebsd.org>
Date: Sun, 24 Mar 2013 02:47:09 GMT
From: Eric van Gyzen <eric@vangyzen.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] libstand fails on ext2fs directories with more than one block
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         177328
>Category:       kern
>Synopsis:       [patch] libstand fails on ext2fs directories with more than one block
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pfg
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 24 02:50:00 UTC 2013
>Closed-Date:    Fri Jun 14 03:32:57 UTC 2013
>Last-Modified:  Fri Jun 14 03:32:57 UTC 2013
>Originator:     Eric van Gyzen
>Release:        8.1-RELEASE
>Organization:
Dell, Inc.
>Environment:
N/A
>Description:
When booting from an ext2fs file system, the loader skips the first 1k of a file if the directory entry for that file isn't in the first 1k of the directory of the root directory.
>How-To-Repeat:
Put several files in the boot directory, then add the kernel, to ensure that the kernel's directory entry isn't in the first block of the directory.
>Fix:
Port this fix from ufs.c (from 2004):

http://svnweb.freebsd.org/base?view=revision&revision=134760

We've been running with the attached patch since August 2011.

Patch attached with submission follows:

diff --git a/src/lib/libstand/ext2fs.c b/src/lib/libstand/ext2fs.c
index 53c4f56..40ce167 100644
--- a/src/lib/libstand/ext2fs.c
+++ b/src/lib/libstand/ext2fs.c
@@ -536,6 +536,17 @@ ext2fs_open(const char *upath, struct open_file *f)
 	 * Found terminal component.
 	 */
 	error = 0;
+
+        // Reset the seek pointer to 0 when a file is successfully opened,
+        // since otherwise the initial seek offset will contain the directory
+        // offset of the filesystem block that contained its directory entry.
+        // This bug was mostly harmless because typically the directory is
+        // less than one filesystem block in size so the offset would be zero.
+        // It did however generally break loading a kernel from the (large)
+        // kernel compile directory.
+        // http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libstand/ufs.c#rev1.15
+        fp->f_seekp = 0;
+
 out:
 	if (buf)
 		free(buf);
@@ -585,6 +596,16 @@ read_inode(ino_t inumber, struct open_file *f)
 		fp->f_blkno[level] = -1;
 	fp->f_buf_blkno = -1;
 
+        // Reset the seek pointer to 0 when a file is successfully opened,
+        // since otherwise the initial seek offset will contain the directory
+        // offset of the filesystem block that contained its directory entry.
+        // This bug was mostly harmless because typically the directory is
+        // less than one filesystem block in size so the offset would be zero.
+        // It did however generally break loading a kernel from the (large)
+        // kernel compile directory.
+        // http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libstand/ufs.c#rev1.15
+        fp->f_seekp = 0;
+
 out:
 	free(buf);
 	return (error);	 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->pfg 
Responsible-Changed-By: pfg 
Responsible-Changed-When: Sat Jun 8 17:28:43 UTC 2013 
Responsible-Changed-Why:  
I will take care of this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177328 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177328: commit references a PR
Date: Sun,  9 Jun 2013 01:19:35 +0000 (UTC)

 Author: pfg
 Date: Sun Jun  9 01:19:22 2013
 New Revision: 251561
 URL: http://svnweb.freebsd.org/changeset/base/251561
 
 Log:
   libstand: Reset the seek pointer in ext2fs as done in UFS.
   
   Based on r134760:
   
   Reset the seek pointer to 0 when a file is successfully opened,
   since otherwise the initial seek offset will contain the directory
   offset of the filesystem block that contained its directory entry.
   This bug was mostly harmless because typically the directory is
   less than one filesystem block in size so the offset would be zero.
   It did however generally break loading a kernel from the (large)
   kernel compile directory.
   
   Also reset the seek pointer when a new inode is opened in read_inode(),
   though this is not actually necessary now because all callers set
   it afterwards.
   
   PR:		177328
   Submitted by:	Eric van Gyzen
   Reviewed by:	iedowse
   MFC after:	5 days
 
 Modified:
   head/lib/libstand/ext2fs.c
 
 Modified: head/lib/libstand/ext2fs.c
 ==============================================================================
 --- head/lib/libstand/ext2fs.c	Sat Jun  8 23:48:13 2013	(r251560)
 +++ head/lib/libstand/ext2fs.c	Sun Jun  9 01:19:22 2013	(r251561)
 @@ -536,6 +536,7 @@ ext2fs_open(const char *upath, struct op
  	 * Found terminal component.
  	 */
  	error = 0;
 +	fp->f_seekp = 0;
  out:
  	if (buf)
  		free(buf);
 @@ -584,6 +585,7 @@ read_inode(ino_t inumber, struct open_fi
  	for (level = 0; level < NIADDR; level++)
  		fp->f_blkno[level] = -1;
  	fp->f_buf_blkno = -1;
 +	fp->f_seekp = 0;
  
  out:
  	free(buf);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: pfg 
State-Changed-When: Sun Jun 9 01:40:27 UTC 2013 
State-Changed-Why:  
Committed to -current. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177328 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177328: commit references a PR
Date: Fri, 14 Jun 2013 02:51:22 +0000 (UTC)

 Author: pfg
 Date: Fri Jun 14 02:51:03 2013
 New Revision: 251726
 URL: http://svnweb.freebsd.org/changeset/base/251726
 
 Log:
   MFC	r251561:
   
   libstand: Reset the seek pointer in ext2fs as done in UFS.
   
   Reset the seek pointer to 0 when a file is successfully opened,
   since otherwise the initial seek offset will contain the directory
   offset of the filesystem block that contained its directory entry.
   This bug was mostly harmless because typically the directory is
   less than one filesystem block in size so the offset would be zero.
   It did however generally break loading a kernel from the (large)
   kernel compile directory.
   
   Also reset the seek pointer when a new inode is opened in read_inode(),
   though this is not actually necessary now because all callers set
   it afterwards.
   
   PR:		177328
   Submitted by:	Eric van Gyzen
   Reviewed by:	iedowse
 
 Modified:
   stable/9/lib/libstand/ext2fs.c
 Directory Properties:
   stable/9/   (props changed)
   stable/9/lib/   (props changed)
   stable/9/lib/libstand/   (props changed)
 
 Modified: stable/9/lib/libstand/ext2fs.c
 ==============================================================================
 --- stable/9/lib/libstand/ext2fs.c	Fri Jun 14 02:25:40 2013	(r251725)
 +++ stable/9/lib/libstand/ext2fs.c	Fri Jun 14 02:51:03 2013	(r251726)
 @@ -536,6 +536,7 @@ ext2fs_open(const char *upath, struct op
  	 * Found terminal component.
  	 */
  	error = 0;
 +	fp->f_seekp = 0;
  out:
  	if (buf)
  		free(buf);
 @@ -584,6 +585,7 @@ read_inode(ino_t inumber, struct open_fi
  	for (level = 0; level < NIADDR; level++)
  		fp->f_blkno[level] = -1;
  	fp->f_buf_blkno = -1;
 +	fp->f_seekp = 0;
  
  out:
  	free(buf);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177328: commit references a PR
Date: Fri, 14 Jun 2013 03:22:07 +0000 (UTC)

 Author: pfg
 Date: Fri Jun 14 03:21:53 2013
 New Revision: 251727
 URL: http://svnweb.freebsd.org/changeset/base/251727
 
 Log:
   MFC	r251561:
   
   libstand: Reset the seek pointer in ext2fs as done in UFS.
   
   PR:		177328
   Submitted by:	Eric van Gyzen
   Reviewed by:	iedowse
 
 Modified:
   stable/8/lib/libstand/ext2fs.c
 Directory Properties:
   stable/8/   (props changed)
   stable/8/lib/   (props changed)
   stable/8/lib/libstand/   (props changed)
 
 Modified: stable/8/lib/libstand/ext2fs.c
 ==============================================================================
 --- stable/8/lib/libstand/ext2fs.c	Fri Jun 14 02:51:03 2013	(r251726)
 +++ stable/8/lib/libstand/ext2fs.c	Fri Jun 14 03:21:53 2013	(r251727)
 @@ -536,6 +536,7 @@ ext2fs_open(const char *upath, struct op
  	 * Found terminal component.
  	 */
  	error = 0;
 +	fp->f_seekp = 0;
  out:
  	if (buf)
  		free(buf);
 @@ -584,6 +585,7 @@ read_inode(ino_t inumber, struct open_fi
  	for (level = 0; level < NIADDR; level++)
  		fp->f_blkno[level] = -1;
  	fp->f_buf_blkno = -1;
 +	fp->f_seekp = 0;
  
  out:
  	free(buf);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: pfg 
State-Changed-When: Fri Jun 14 03:30:31 UTC 2013 
State-Changed-Why:  
Merged (without comments like in UFS). 
Thank you for your contribution! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177328 
>Unformatted:
