From patchwork Thu May 5 18:21:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 94295 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 CA5421007D1 for ; Fri, 6 May 2011 04:21:14 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755686Ab1EESVM (ORCPT ); Thu, 5 May 2011 14:21:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60060 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755626Ab1EESVL (ORCPT ); Thu, 5 May 2011 14:21:11 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p45ILA6e032665 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 5 May 2011 14:21:10 -0400 Received: from liberator.sandeen.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p45IL8Ad027342 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 5 May 2011 14:21:10 -0400 Message-ID: <4DC2EA94.8040100@redhat.com> Date: Thu, 05 May 2011 13:21:08 -0500 From: Eric Sandeen User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: Andreas Dilger CC: ext4 development Subject: [PATCH V2] filefrag: count 0 extents properly when verbose References: <4CEC4C86.1030806@redhat.com> <4D9F3B71.2050808@redhat.com> <569EBA4C-A6BB-4E64-88B9-F2F946891B56@dilger.ca> In-Reply-To: <569EBA4C-A6BB-4E64-88B9-F2F946891B56@dilger.ca> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org # rm -f a; touch a; filefrag a /boot/a: 0 extents found works properly, but # rm -f a; touch a; filefrag -v a Filesystem type is: ef53 Filesystem cylinder groups is approximately 61 File size of a is 0 (0 blocks, blocksize 1024) ext logical physical expected length flags a: 1 extent found yields 1 extent when it should be 0. Fix this up by special-casing no extents returned in verbose mode; skip printing the header for the columns too, since there are no columns to print. Also, in nonverbose mode we can set fm_extent_count to 0 so that FIEMAP will just query the extent count without gathering details; clarify this with a comment. Addresses-redhat-bugzilla: 653234 Signed-off-by: Eric Sandeen --- 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 d604b6c..2795e15 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -180,6 +180,10 @@ static int filefrag_fiemap(int fd, int blk_shift, int *num_extents) memset(fiemap, 0, sizeof(struct fiemap)); + /* + * If count (and therefore fm_extent_count) == 0, FIEMAP + * returns count of extents found without filling in details. + */ if (!verbose) count = 0; @@ -204,6 +208,14 @@ static int filefrag_fiemap(int fd, int blk_shift, int *num_extents) } if (verbose && !fiemap_header_printed) { + /* + * No extents on first call? + * Skip header and show 0 extents. + */ + if (fiemap->fm_mapped_extents == 0) { + *num_extents = 0; + goto out; + } printf(" ext %*s %*s %*s length flags\n", logical_width, "logical", physical_width, "physical", physical_width, "expected");