From patchwork Tue Jan 29 06:24:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jeff.liu" X-Patchwork-Id: 2059431 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 49BF43FDD1 for ; Tue, 29 Jan 2013 06:25:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753879Ab3A2GZJ (ORCPT ); Tue, 29 Jan 2013 01:25:09 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:51204 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753523Ab3A2GZH (ORCPT ); Tue, 29 Jan 2013 01:25:07 -0500 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r0T6OINm024169 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 29 Jan 2013 06:24:19 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r0T6OIWh025708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 29 Jan 2013 06:24:18 GMT Received: from abhmt110.oracle.com (abhmt110.oracle.com [141.146.116.62]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r0T6OHg1006539; Tue, 29 Jan 2013 00:24:17 -0600 Received: from [192.168.1.103] (/221.223.96.144) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Jan 2013 22:24:17 -0800 Message-ID: <51076B0C.2060602@oracle.com> Date: Tue, 29 Jan 2013 14:24:12 +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 1/2] btrfs-progs: refactor check_label() X-Source-IP: ucsinet22.oracle.com [156.151.31.94] 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 at them to utils.[c|h], we can do pre-checking against the input label string with it. Also, fix the input lable length verfication from BTRFS_LABEL_SIZE to BTRFS_LABEL_SIZE - 1. Signed-off-by: Jie Liu CC: David Sterba CC: Gene Czarcinski --- utils.c | 8 ++++++-- utils.h | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/utils.c b/utils.c index d59bca3..034da8f 100644 --- a/utils.c +++ b/utils.c @@ -1122,17 +1122,21 @@ char *pretty_sizes(u64 size) -1 if the label is too long -2 if the label contains an invalid character */ -int check_label(char *input) +static int check_label(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] == '\\') { + fprintf(stderr, "ERROR: Label %s contains invalid " + "characters\n", input); return -2; } } 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);