linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Tso <tytso@mit.edu>
To: Peng Tao <bergwolf@gmail.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH-e2fsprogs] filefrag: accept positive ioctl return value
Date: Tue, 2 Jun 2009 08:59:14 -0400	[thread overview]
Message-ID: <20090602125914.GT31943@mit.edu> (raw)
In-Reply-To: <1243944761-18673-1-git-send-email-bergwolf@gmail.com>

On Tue, Jun 02, 2009 at 08:12:41PM +0800, Peng Tao wrote:
> Some ioctl() returns non-negative value on success. filefrag_fiemap should
> treat positive ioctl() return values as success.
> This can be triggered by running filefrag on btrfs partitions.

Thanks for reporting this!

It turns out that wasn't the only bug in that code; the syscall
infrastructure will take a negative return value and maps that to -1,
and moves the (negative) error code to a positive value in errno.  So
the more appropriate patch is as follows.

						- Ted

commit e78968f7a42fb1fa75c356dd323d957b307b887f
Author: Theodore Ts'o <tytso@mit.edu>
Date:   Tue Jun 2 08:45:22 2009 -0400

    filefrag: Fix error checking for the fiemap ioctl
    
    Thanks to Peng Tao for reporting this problem.
    
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

diff --git a/misc/filefrag.c b/misc/filefrag.c
index 80ac05c..7095949 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -201,15 +201,14 @@ int filefrag_fiemap(int fd, int blk_shift, int *num_extents)
 		fiemap->fm_flags = flags;
 		fiemap->fm_extent_count = count;
 		rc = ioctl(fd, FS_IOC_FIEMAP, (unsigned long) fiemap);
-		if (rc == -EBADR) {
-			if (fiemap_incompat_printed == 0) {
+		if (rc < 0) {
+			if (errno == EBADR && fiemap_incompat_printed == 0) {
 				printf("FIEMAP failed with unsupported "
 				       "flags %x\n", fiemap->fm_flags);
 				fiemap_incompat_printed = 1;
 			}
-		}
-		if (rc)
 			return rc;
+		}
 
 		if (!verbose) {
 			*num_extents = fiemap->fm_mapped_extents;

      parent reply	other threads:[~2009-06-02 12:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02 12:12 [PATCH-e2fsprogs] filefrag: accept positive ioctl return value Peng Tao
2009-06-02 12:40 ` Theodore Tso
2009-06-02 17:10   ` Peng Tao
2009-06-02 12:59 ` Theodore Tso [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=20090602125914.GT31943@mit.edu \
    --to=tytso@mit.edu \
    --cc=bergwolf@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    /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).