linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leonard Michlmayr <leonard.michlmayr@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: surbhi.palande@canonical.com, linux-kernel@vger.kernel.org,
	474597@bugs.launchpad.net
Subject: [PATCH 2.6.32.7] ext4: number of blocks for fiemap
Date: Fri, 12 Feb 2010 19:42:16 +0100	[thread overview]
Message-ID: <1266000136.4310.36.camel@michlmayr> (raw)
In-Reply-To: <4B701793.9010005@canonical.com>

Problem:
fs/ext4/extents.c:ext4_fiemap rounds the length of the requested range
down to blocksize. This is not the true number of blocks that cover the
requested region. This problem is especially impressive if the user
requests only the first byte of a file: not a single extent will be
reported.

Solution:
Calculate the last byte of the region and round to blocksize. Then get
the number of blocks by subtracting last_blk - start_blk and adding 1
for the first block. (The variable last_blk is introduced just for
easier reading.) This patch will fix this.

I already suggested this patch some time ago, this is the same patch for
a more recent kernel version.

Signed-off-by: Leonard Michlmayr <leonard.michlmayr@gmail.com>

diff -rup linux-2.6.32.7/fs/ext4/extents.c linux-2.6.32.7-lm/fs/ext4/extents.c
--- linux-2.6.32.7/fs/ext4/extents.c	2010-01-29 00:06:20.000000000 +0100
+++ linux-2.6.32.7-lm/fs/ext4/extents.c	2010-02-11 21:26:40.000000000 +0100
@@ -3711,6 +3711,7 @@ int ext4_fiemap(struct inode *inode, str
 		__u64 start, __u64 len)
 {
 	ext4_lblk_t start_blk;
+	ext4_lblk_t last_blk;
 	ext4_lblk_t len_blks;
 	int error = 0;
 
@@ -3726,7 +3727,9 @@ int ext4_fiemap(struct inode *inode, str
 		error = ext4_xattr_fiemap(inode, fieinfo);
 	} else {
 		start_blk = start >> inode->i_sb->s_blocksize_bits;
-		len_blks = len >> inode->i_sb->s_blocksize_bits;
+		/* the last byte in the range is (start + len - 1) */
+		last_blk = (start + len - 1) >> inode->i_sb->s_blocksize_bits;
+		len_blks = last_blk - start_blk + 1;
 
 		/*
 		 * Walk the extent tree gathering extent information.





  reply	other threads:[~2010-02-12 18:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-04 18:42 ext4_fiemap gives 0 extents for files smaller than a block (patch included) Leonard Michlmayr
2009-11-04 19:44 ` Andreas Dilger
2009-11-04 21:44   ` Leonard Michlmayr
2010-02-08 13:54     ` Surbhi Palande
2010-02-12 18:42       ` Leonard Michlmayr [this message]
2010-02-12 21:49         ` [PATCH 2.6.32.7] ext4: number of blocks for fiemap Andreas Dilger
2010-02-12 23:20           ` Leonard Michlmayr
2010-02-15 19:50             ` tytso
2010-02-15 20:33               ` Eric Sandeen
2010-02-15 22:01                 ` tytso
2010-01-25 19:04   ` ext4_fiemap gives 0 extents for files smaller than a block (patch included) Leonard Michlmayr

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=1266000136.4310.36.camel@michlmayr \
    --to=leonard.michlmayr@gmail.com \
    --cc=474597@bugs.launchpad.net \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=surbhi.palande@canonical.com \
    /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;
as well as URLs for NNTP newsgroup(s).