From patchwork Fri May 30 18:10:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 354294 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C722714003E for ; Sat, 31 May 2014 04:10:21 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933202AbaE3SKU (ORCPT ); Fri, 30 May 2014 14:10:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61362 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754385AbaE3SKU (ORCPT ); Fri, 30 May 2014 14:10:20 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4UIAI6h030646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 30 May 2014 14:10:18 -0400 Received: from liberator.sandeen.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s4UIAHwb016474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 30 May 2014 14:10:18 -0400 Message-ID: <5388C989.8050100@redhat.com> Date: Fri, 30 May 2014 13:10:17 -0500 From: Eric Sandeen User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: ext4 development CC: Andreas Dilger Subject: [PATCH V3] filefrag: filefrag: fix issues with 29758d2 References: <53876D7D.8050108@redhat.com> In-Reply-To: <53876D7D.8050108@redhat.com> X-Enigmail-Version: 1.6 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 29758d2 filefrag: exit with error code if an error is hit introduced a couple errors; in one case it missed returning a value, and possibly picked up errno from (unchecked) close(), and in the other used a test where it needed an assignment. So capture the error, move perror() directly after the failed call in both cases, and fix the assignment. Also fix a precedence problem with: if (fe_flags & mask == 0) which is equivalent to: if (fe_flags & (mask == 0)) but we need: if ((fe_flags & mask) == 0) Signed-off-by: Eric Sandeen Reviewed-by: Andreas Dilger --- -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/misc/filefrag.c b/misc/filefrag.c index 37c4416..820821b 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -175,7 +175,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex, for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) { char hex[6]; - if (fe_flags & mask == 0) + if ((fe_flags & mask) == 0) continue; sprintf(hex, "%#04x,", mask); print_flag(&fe_flags, mask, flags, hex); @@ -378,17 +378,18 @@ static int frag_report(const char *filename) #else if (fstat(fd, &st) < 0) { #endif - close(fd); rc = -errno; perror("stat"); + close(fd); return rc; } if (last_device != st.st_dev) { if (fstatfs(fd, &fsinfo) < 0) { - close(fd); + rc = -errno; perror("fstatfs"); - return; + close(fd); + return rc; } if (verbose) printf("Filesystem type is: %lx\n", @@ -556,7 +557,7 @@ int main(int argc, char**argv) int rc2 = frag_report(*cpp); if (rc2 < 0 && rc == 0) - rc == rc2; + rc = rc2; } return rc;