From patchwork Tue Dec 9 08:27:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5460861 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AC6C99F2E8 for ; Tue, 9 Dec 2014 08:27:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E4E8C2017D for ; Tue, 9 Dec 2014 08:27:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 259FE2015A for ; Tue, 9 Dec 2014 08:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754031AbaLII1p (ORCPT ); Tue, 9 Dec 2014 03:27:45 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:8765 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752480AbaLII1o (ORCPT ); Tue, 9 Dec 2014 03:27:44 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="44726098" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 09 Dec 2014 16:24:26 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id sB98RLQc013485 for ; Tue, 9 Dec 2014 16:27:21 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 9 Dec 2014 16:27:48 +0800 From: Qu Wenruo To: Subject: [PATCH v4 08/13] btrfs-progs: Add count_digit() function to help calculate filename len. Date: Tue, 9 Dec 2014 16:27:27 +0800 Message-ID: <1418113652-25088-9-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418113652-25088-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1418113652-25088-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add count_digit() function in utils.h to help calculate filename with ino suffix. Signed-off-by: Qu Wenruo --- Changelog: v4: Newly introduced. --- utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utils.h b/utils.h index 289e86b..f68d6d8 100644 --- a/utils.h +++ b/utils.h @@ -161,4 +161,22 @@ static inline u64 btrfs_min_dev_size(u32 leafsize) int find_next_key(struct btrfs_path *path, struct btrfs_key *key); +/* + * Get the length of the string converted from a u64 number. + * + * Result is equal to log10(num) + 1, but without the use of math library. + */ +static inline int count_digit(u64 num) +{ + int ret = 0; + + if (num == 0) + return 1; + while (num > 0) { + ret++; + num /= 10; + } + return ret; +} + #endif