mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Fester <cfester@wms.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Matt Waddel <matt.waddel@freescale.com>,
	Greg Ungerer <gerg@snapgear.com>
Subject: Re: [PATCH] ROMFS 0 byte file read error
Date: Wed, 30 Jul 2008 16:25:52 -0500	[thread overview]
Message-ID: <20080730212552.GA4016@kaboom.dhcp.chi.wms.com> (raw)
In-Reply-To: <alpine.LFD.1.10.0807301052180.3334@nehalem.linux-foundation.org>


On Wed, Jul 30, 2008 at 11:06:29AM -0700, Linus Torvalds wrote:
> Something like this. UNTESTED. Pls verify and send back if this is ok. The 
> patch is certainly bigger, but I think that the end result is more 
> obvious.
> 
> 		Linus

I tested this patch by:
1.)  cat'ing the 0 length file.
2.)  doing a diff between the loop mounted filesystem and the source
directory for the romfs image.
3.)  cp -rdp'ing the contents of the loop mounted filesystem to another
directory, diffing that directory to the source directory.

All of those tests pass.  The image I'm testing with is about 23MB, with
900 files and directories.

I agree that your patch generates far more straightforward code than the
original.  Coolbeans!

Let me know if there's anything else I should do to test.  Also, let me
know if there's other pressing work to be done to this driver and I'll
try my best at de-crustifying it.

Thanks,
Chris Fester

> 
> ---
>  fs/romfs/inode.c |   37 +++++++++++++++++++++++--------------
>  1 files changed, 23 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/romfs/inode.c b/fs/romfs/inode.c
> index 8e51a2a..60d2f82 100644
> --- a/fs/romfs/inode.c
> +++ b/fs/romfs/inode.c
> @@ -418,7 +418,8 @@ static int
>  romfs_readpage(struct file *file, struct page * page)
>  {
>  	struct inode *inode = page->mapping->host;
> -	loff_t offset, avail, readlen;
> +	loff_t offset, size;
> +	unsigned long filled;
>  	void *buf;
>  	int result = -EIO;
>  
> @@ -430,21 +431,29 @@ romfs_readpage(struct file *file, struct page * page)
>  
>  	/* 32 bit warning -- but not for us :) */
>  	offset = page_offset(page);
> -	if (offset < i_size_read(inode)) {
> -		avail = inode->i_size-offset;
> -		readlen = min_t(unsigned long, avail, PAGE_SIZE);
> -		if (romfs_copyfrom(inode, buf, ROMFS_I(inode)->i_dataoffset+offset, readlen) == readlen) {
> -			if (readlen < PAGE_SIZE) {
> -				memset(buf + readlen,0,PAGE_SIZE-readlen);
> -			}
> -			SetPageUptodate(page);
> -			result = 0;
> +	size = i_size_read(inode);
> +	filled = 0;
> +	result = 0;
> +	if (offset < size) {
> +		unsigned long readlen;
> +
> +		size -= offset;
> +		readlen = size > PAGE_SIZE ? PAGE_SIZE : size;
> +
> +		filled = romfs_copyfrom(inode, buf, ROMFS_I(inode)->i_dataoffset+offset, readlen);
> +
> +		if (filled != readlen) {
> +			SetPageError(page);
> +			filled = 0;
> +			result = -EIO;
>  		}
>  	}
> -	if (result) {
> -		memset(buf, 0, PAGE_SIZE);
> -		SetPageError(page);
> -	}
> +
> +	if (filled < PAGE_SIZE)
> +		memset(buf + filled, 0, PAGE_SIZE-filled);
> +
> +	if (!result)
> +		SetPageUptodate(page);
>  	flush_dcache_page(page);
>  
>  	unlock_page(page);

      reply	other threads:[~2008-07-30 21:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-30 16:10 Chris Fester
2008-07-30 18:06 ` Linus Torvalds
2008-07-30 21:25   ` Chris Fester [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080730212552.GA4016@kaboom.dhcp.chi.wms.com \
    --to=cfester@wms.com \
    --cc=gerg@snapgear.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt.waddel@freescale.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®