From patchwork Mon Jul 9 17:29:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Carrier X-Patchwork-Id: 1174211 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 9414ADFB7C for ; Mon, 9 Jul 2012 17:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751383Ab2GIR34 (ORCPT ); Mon, 9 Jul 2012 13:29:56 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:47878 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981Ab2GIR34 (ORCPT ); Mon, 9 Jul 2012 13:29:56 -0400 Received: by lbbgm6 with SMTP id gm6so20477019lbb.19 for ; Mon, 09 Jul 2012 10:29:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=Uj7ESXq9ZXHEXGu4AcpXD4qY5QGGZTjyS3iyLLn0rFI=; b=P9OQwMKeJReTgi8Vg0QGMn8xJVmiwd7D+ch1jclq2ygxtg5Zzd4ft4CvujDHKbk8sz n+IIUMccyMVRomtWQ7VaTPYsL2gmcxQ4vBzAnApMZa/ONDHjdrzbdd16wF04fYdHlcdN XXtR4BLZfXNV4T46NJGSi6EWIjUwwp2wpo7a3UZNp3dZAdLG2uP5GCb/4zzKDWgGg7Fy QtQpPruLGTlASdVHmUJNzMyeP3SKDYv3UDAJxODIJ4C/VPCf6PigADNC6QC7BPVTqphG LzyVnOsKtqraQImBdtDZMzP6C0UM8EHdJVi+E5sDBlW10OUiFa5xsrd0/lduGXLGCVA5 fpfw== Received: by 10.112.38.161 with SMTP id h1mr19005374lbk.85.1341854994709; Mon, 09 Jul 2012 10:29:54 -0700 (PDT) Received: from bar.spotify.net (155.60.236.194.office.spotify.net. [194.236.60.155]) by mx.google.com with ESMTPS id j3sm16752890lbh.0.2012.07.09.10.29.53 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 Jul 2012 10:29:53 -0700 (PDT) From: Pierre Carrier To: linux-btrfs@vger.kernel.org Cc: Pierre Carrier Subject: [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes Date: Mon, 9 Jul 2012 17:29:34 +0000 Message-Id: <1341854974-14502-1-git-send-email-pierre@spotify.com> X-Mailer: git-send-email 1.7.11.1 In-Reply-To: <1341853347-11788-2-git-send-email-pierre@spotify.com> References: <1341853347-11788-2-git-send-email-pierre@spotify.com> X-Gm-Message-State: ALoCoQnmkzySwSPIqrPbhiqS/j89HcdGueVaNuBOcf5OJOfW7QQQi0V9zeWHD+gnwwX6zxs31POA Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Before, sizes below 1KB are still displayed in KB, but without a unit. Signed-off-by: Pierre Carrier diff --git a/utils.c b/utils.c index aade9e2..937e763 100644 --- a/utils.c +++ b/utils.c @@ -1108,13 +1108,20 @@ char *pretty_sizes(u64 size) size /= 1024; num_divs++; } - if (num_divs == 0) + if (num_divs <= 1) { num_divs = 1; + fraction = (float)fract_size; + } else + fraction = (float)fract_size / 1024; + if (num_divs > ARRAY_SIZE(size_strs)) return NULL; - fraction = (float)fract_size / 1024; + pretty = malloc(pretty_len); + if (!pretty) + return NULL; + snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]); return pretty; }