From patchwork Tue Jun 26 13:59:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 167405 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 DB0CB1007D4 for ; Tue, 26 Jun 2012 23:59:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751542Ab2FZN7W (ORCPT ); Tue, 26 Jun 2012 09:59:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57089 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751310Ab2FZN7W (ORCPT ); Tue, 26 Jun 2012 09:59:22 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5QDxACp001321 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Jun 2012 09:59:10 -0400 Received: from Liberator-563.local (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5QDx8DC028158 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Tue, 26 Jun 2012 09:59:09 -0400 Message-ID: <4FE9C02C.8040703@redhat.com> Date: Tue, 26 Jun 2012 09:59:08 -0400 From: Eric Sandeen User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: ext4 development CC: maxnet@onlinehome.de Subject: [PATCH] filefrag: Fix segfault on virtual fs X-Enigmail-Version: 1.4.2 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org filefrag on a virtual fs like proc segfaults: # filefrag /proc/filesystems Floating point exception because stat.f_blocks is 0, so the calculation of cylgroups is 0, which leads to a divide by 0 when calculating expected extents. Since it's only used for ext2 filesystems anyway, just move the calculation of expected under "if (is_ext2)" to fix this. Reported-by: Max Beikirch 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 0583e91..b6e7d62 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -365,11 +366,12 @@ static void frag_report(const char *filename) else printf("%s: %d extents found", filename, num_extents); /* count, and thus expected, only set for indirect FIBMAP'd files */ - expected = (count/((bs*8)-(fsinfo.f_files/8/cylgroups)-3))+1; - if (is_ext2 && expected && expected < num_extents) - printf(", perfection would be %d extent%s\n", expected, - (expected>1) ? "s" : ""); - else + if (is_ext2) { + expected = (count/((bs*8)-(fsinfo.f_files/8/cylgroups)-3))+1; + if (expected && expected < num_extents) + printf(", perfection would be %d extent%s\n", expected, + (expected>1) ? "s" : ""); + } else fputc('\n', stdout); close(fd); once = 0;