From patchwork Wed Jan 30 08:32:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jeff.liu" X-Patchwork-Id: 2066271 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 8E68FDF264 for ; Wed, 30 Jan 2013 08:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752522Ab3A3Idm (ORCPT ); Wed, 30 Jan 2013 03:33:42 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:51198 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751856Ab3A3Idl (ORCPT ); Wed, 30 Jan 2013 03:33:41 -0500 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r0U8WpqB008183 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 30 Jan 2013 08:32:52 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r0U8WoXX022179 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 30 Jan 2013 08:32:50 GMT Received: from abhmt117.oracle.com (abhmt117.oracle.com [141.146.116.69]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r0U8WnDU015414; Wed, 30 Jan 2013 02:32:49 -0600 Received: from [192.168.1.102] (/114.248.204.185) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 30 Jan 2013 00:32:49 -0800 Message-ID: <5108DAAB.10401@oracle.com> Date: Wed, 30 Jan 2013 16:32:43 +0800 From: Jeff Liu User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 MIME-Version: 1.0 To: linux-btrfs@vger.kernel.org CC: dsterba@suse.cz, Gene Czarcinski Subject: [PATCH v2 1/2] btrfs-progs: refactor check_label() X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Refactor check_label(). - Make it be static at first, this is a preparation step since we'll remove btrfslabel.[c|h] and move those functions from there to utils.[c|h], we can do pre-checking against the input label string with it. - Fix the label length check up from BTRFS_LABEL_SIZE to BTRFS_LABEL_SIZE - 1. - Kill the check of label contains an invalid character, see below commits for detail: 79e0e445fc2365e47fc7f060d5a4445d37e184b8 btrfs-progs: kill check for /'s in labels. Signed-off-by: Jie Liu CC: David Sterba CC: Gene Czarcinski --- utils.c | 14 ++++---------- utils.h | 1 - 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/utils.c b/utils.c index d59bca3..9dc688a 100644 --- a/utils.c +++ b/utils.c @@ -1120,23 +1120,17 @@ char *pretty_sizes(u64 size) * Returns: 0 if everything is safe and usable -1 if the label is too long - -2 if the label contains an invalid character */ -int check_label(char *input) +static int check_label(const char *input) { - int i; int len = strlen(input); - if (len > BTRFS_LABEL_SIZE) { + if (len > BTRFS_LABEL_SIZE - 1) { + fprintf(stderr, "ERROR: Label %s is too long (max %d)\n", + input, BTRFS_LABEL_SIZE - 1); return -1; } - for (i = 0; i < len; i++) { - if (input[i] == '/' || input[i] == '\\') { - return -2; - } - } - return 0; } diff --git a/utils.h b/utils.h index 8750f28..a0b782b 100644 --- a/utils.h +++ b/utils.h @@ -42,7 +42,6 @@ int check_mounted_where(int fd, const char *file, char *where, int size, int btrfs_device_already_in_root(struct btrfs_root *root, int fd, int super_offset); char *pretty_sizes(u64 size); -int check_label(char *input); int get_mountpt(char *dev, char *mntpt, size_t size); int btrfs_scan_block_devices(int run_ioctl);