From patchwork Mon Nov 4 07:17:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 3134741 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 100299F432 for ; Mon, 4 Nov 2013 07:09:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F29952030D for ; Mon, 4 Nov 2013 07:09:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A982C2030B for ; Mon, 4 Nov 2013 07:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752230Ab3KDHJX (ORCPT ); Mon, 4 Nov 2013 02:09:23 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:23866 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752113Ab3KDHJV (ORCPT ); Mon, 4 Nov 2013 02:09:21 -0500 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rA479Fp8000822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Nov 2013 07:09:16 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rA479EVA021156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 4 Nov 2013 07:09:15 GMT Received: from abhmt101.oracle.com (abhmt101.oracle.com [141.146.116.53]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rA479DCi002015; Mon, 4 Nov 2013 07:09:14 GMT Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 03 Nov 2013 23:09:13 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: jbacik@fusionio.com, dsterba@suse.cz Subject: [PATCH] btrfs-progs: define BTRFS_UUID_UNPARSE_SIZE for uuid unparse buf size Date: Mon, 4 Nov 2013 15:17:41 +0800 Message-Id: <1383549461-6764-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.1.164.g2d0029e X-Source-IP: acsinet22.oracle.com [141.146.126.238] 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, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 we use 37 as the allocation size to hold the uuid_unparse, here it defines BTRFS_UUID_UNPARSE_SIZE for the same. Signed-off-by: Anand Jain --- btrfs-debug-tree.c | 5 +++-- btrfs-list.c | 2 +- btrfs-show-super.c | 2 +- cmds-check.c | 2 +- cmds-filesystem.c | 17 +++++++++-------- cmds-scrub.c | 6 +++--- cmds-subvolume.c | 2 +- print-tree.c | 9 +++++---- utils.h | 2 ++ 9 files changed, 26 insertions(+), 21 deletions(-) diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c index 4a83770..f37de9d 100644 --- a/btrfs-debug-tree.c +++ b/btrfs-debug-tree.c @@ -27,6 +27,7 @@ #include "print-tree.h" #include "transaction.h" #include "version.h" +#include "utils.h" static int print_usage(void) { @@ -125,7 +126,7 @@ int main(int ac, char **av) struct extent_buffer *leaf; struct btrfs_disk_key disk_key; struct btrfs_key found_key; - char uuidbuf[37]; + char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; int ret; int slot; int extent_only = 0; @@ -392,7 +393,7 @@ no_node: (unsigned long long)btrfs_super_total_bytes(info->super_copy)); printf("bytes used %llu\n", (unsigned long long)btrfs_super_bytes_used(info->super_copy)); - uuidbuf[36] = '\0'; + uuidbuf[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0'; uuid_unparse(info->super_copy->fsid, uuidbuf); printf("uuid %s\n", uuidbuf); printf("%s\n", BTRFS_BUILD_VERSION); diff --git a/btrfs-list.c b/btrfs-list.c index f3618b9..6a38dd5 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -1331,7 +1331,7 @@ static void print_subvolume_column(struct root_info *subv, enum btrfs_list_column_enum column) { char tstr[256]; - char uuidparse[37]; + char uuidparse[BTRFS_UUID_UNPARSED_SIZE]; BUG_ON(column >= BTRFS_LIST_ALL || column < 0); diff --git a/btrfs-show-super.c b/btrfs-show-super.c index 0c3c73c..b87f16a 100644 --- a/btrfs-show-super.c +++ b/btrfs-show-super.c @@ -165,7 +165,7 @@ static int check_csum_sblock(void *sb, int csum_size) static void dump_superblock(struct btrfs_super_block *sb) { int i; - char *s, buf[36+1]; + char *s, buf[BTRFS_UUID_UNPARSED_SIZE]; u8 *p; printf("csum\t\t\t0x"); diff --git a/cmds-check.c b/cmds-check.c index 573c606..59942d4 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -6128,7 +6128,7 @@ int cmd_check(int argc, char **argv) struct btrfs_root *root; struct btrfs_fs_info *info; u64 bytenr = 0; - char uuidbuf[37]; + char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; int ret; int num; int option_index = 0; diff --git a/cmds-filesystem.c b/cmds-filesystem.c index f40178a..9295a1a 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -183,10 +183,10 @@ static int cmd_df(int argc, char **argv) static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label, char *search) { - char uuidbuf[37]; + char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; int search_len = strlen(search); - search_len = min(search_len, 37); + search_len = min(search_len, BTRFS_UUID_UNPARSED_SIZE); uuid_unparse(fsid, uuidbuf); if (!strncmp(uuidbuf, search, search_len)) return 1; @@ -202,12 +202,12 @@ static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label, static int uuid_search(struct btrfs_fs_devices *fs_devices, char *search) { - char uuidbuf[37]; + char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; struct list_head *cur; struct btrfs_device *device; int search_len = strlen(search); - search_len = min(search_len, 37); + search_len = min(search_len, BTRFS_UUID_UNPARSED_SIZE); uuid_unparse(fs_devices->fsid, uuidbuf); if (!strncmp(uuidbuf, search, search_len)) return 1; @@ -238,7 +238,7 @@ static int cmp_device_id(void *priv, struct list_head *a, static void print_one_uuid(struct btrfs_fs_devices *fs_devices) { - char uuidbuf[37]; + char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; struct list_head *cur; struct btrfs_device *device; u64 devs_found = 0; @@ -292,7 +292,7 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, char *label, char *path) { int i; - char uuidbuf[37]; + char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; struct btrfs_ioctl_dev_info_args *tmp_dev_info; uuid_unparse(fs_info->fsid, uuidbuf); @@ -366,7 +366,8 @@ static int check_arg_type(char *input) return BTRFS_ARG_UNKNOWN; } - if (strlen(input) == 36 && !uuid_parse(input, out)) + if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) && + !uuid_parse(input, out)) return BTRFS_ARG_UUID; return BTRFS_ARG_UNKNOWN; @@ -469,7 +470,7 @@ static int cmd_show(int argc, char **argv) char mp[BTRFS_PATH_NAME_MAX + 1]; char path[PATH_MAX]; __u8 fsid[BTRFS_FSID_SIZE]; - char uuid_buf[37]; + char uuid_buf[BTRFS_UUID_UNPARSED_SIZE]; while (1) { int long_index; diff --git a/cmds-scrub.c b/cmds-scrub.c index 605af45..b933770 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -867,7 +867,7 @@ static void *scrub_progress_cycle(void *ctx) int perr = 0; /* positive / pthread error returns */ int old; int i; - char fsid[37]; + char fsid[BTRFS_UUID_UNPARSED_SIZE]; struct scrub_progress *sp; struct scrub_progress *sp_last; struct scrub_progress *sp_shared; @@ -1089,7 +1089,7 @@ static int scrub_start(int argc, char **argv, int resume) struct scrub_file_record **past_scrubs = NULL; struct scrub_file_record *last_scrub = NULL; char *datafile = strdup(SCRUB_DATA_FILE); - char fsid[37]; + char fsid[BTRFS_UUID_UNPARSED_SIZE]; char sock_path[BTRFS_PATH_NAME_MAX + 1] = ""; struct scrub_progress_cycle spc; pthread_mutex_t spc_write_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -1615,7 +1615,7 @@ static int cmd_scrub_status(int argc, char **argv) int print_raw = 0; int do_stats_per_dev = 0; int c; - char fsid[37]; + char fsid[BTRFS_UUID_UNPARSED_SIZE]; int fdres = -1; int err = 0; DIR *dirstream = NULL; diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 76dab1f..f9cbc78 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -823,7 +823,7 @@ static int cmd_subvol_show(int argc, char **argv) struct root_info get_ri; struct btrfs_list_filter_set *filter_set; char tstr[256]; - char uuidparse[37]; + char uuidparse[BTRFS_UUID_UNPARSED_SIZE]; char *fullpath = NULL, *svpath = NULL, *mnt = NULL; char raw_prefix[] = "\t\t\t\t"; u64 sv_id, mntid; diff --git a/print-tree.c b/print-tree.c index 76037fe..c52e5da 100644 --- a/print-tree.c +++ b/print-tree.c @@ -24,6 +24,7 @@ #include "ctree.h" #include "disk-io.h" #include "print-tree.h" +#include "utils.h" static void print_dir_item_type(struct extent_buffer *eb, @@ -187,21 +188,21 @@ static void print_dev_item(struct extent_buffer *eb, static void print_uuids(struct extent_buffer *eb) { - char fs_uuid[37]; - char chunk_uuid[37]; + char fs_uuid[BTRFS_UUID_UNPARSED_SIZE]; + char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE]; u8 disk_uuid[BTRFS_UUID_SIZE]; read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(), BTRFS_FSID_SIZE); - fs_uuid[36] = '\0'; + fs_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0'; uuid_unparse(disk_uuid, fs_uuid); read_extent_buffer(eb, disk_uuid, (unsigned long)btrfs_header_chunk_tree_uuid(eb), BTRFS_UUID_SIZE); - chunk_uuid[36] = '\0'; + chunk_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0'; uuid_unparse(disk_uuid, chunk_uuid); printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid); } diff --git a/utils.h b/utils.h index 8c64575..b91bbee 100644 --- a/utils.h +++ b/utils.h @@ -37,6 +37,8 @@ #define BTRFS_ARG_UUID 2 #define BTRFS_ARG_BLKDEV 3 +#define BTRFS_UUID_UNPARSED_SIZE 37 + int make_btrfs(int fd, const char *device, const char *label, u64 blocks[6], u64 num_bytes, u32 nodesize, u32 leafsize, u32 sectorsize, u32 stripesize, u64 features);