From patchwork Wed Dec 17 20:14:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 5509141 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 9DE019F1D4 for ; Wed, 17 Dec 2014 20:13:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C2239208BC for ; Wed, 17 Dec 2014 20:13:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D900E209DE for ; Wed, 17 Dec 2014 20:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751302AbaLQUND (ORCPT ); Wed, 17 Dec 2014 15:13:03 -0500 Received: from mail-wg0-f47.google.com ([74.125.82.47]:53461 "EHLO mail-wg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750953AbaLQUNA (ORCPT ); Wed, 17 Dec 2014 15:13:00 -0500 Received: by mail-wg0-f47.google.com with SMTP id n12so21123430wgh.6 for ; Wed, 17 Dec 2014 12:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tAPeiZ8xSrZjqb7HepodgXz47gegmxFJvdgJdO4R5/Y=; b=uHEAL4n+wetWWLseWX1LGT34yeWpapZ+ysDWsSa7pUo1JrBdfks9fNBtUJH194Ri9x V0eybc9GOW7M2Q/FEkoZ5BUfBTMQI59tvBv2eTfxZqk4tPnV3/Y5rgie/iQ06lqcAW6S BTsyDE5ZJizaJZjTfvtu4A1fc1ECzgmm4vYPHDSMZ5FHznmH6poI4gWMDICIx4PcFICD EdW+REhUaSnTlIeSBGjy69FVfmdDlBh/CPWBJFbFWqU2PhFgZ4IGl40cc400YST3aoRd YZgkrtLUMl/oW8GbRfJs5YgyJknMMD3K6eKTL1aJrDPrfdPRgNI+AWM4T/cCQl0e/M25 v8fQ== X-Received: by 10.194.188.39 with SMTP id fx7mr72849880wjc.113.1418847179765; Wed, 17 Dec 2014 12:12:59 -0800 (PST) Received: from venice.bhome (ppp-133-85.24-151.libero.it. [151.24.85.133]) by mx.google.com with ESMTPSA id pu3sm6360357wjc.14.2014.12.17.12.12.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Dec 2014 12:12:59 -0800 (PST) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Goffredo Baroncelli Subject: [PATCH 5/8] Return the fsid from make_btrfs() Date: Wed, 17 Dec 2014 21:14:09 +0100 Message-Id: <1418847252-14184-6-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418847252-14184-1-git-send-email-kreijack@inwind.it> References: <1418847252-14184-1-git-send-email-kreijack@inwind.it> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 The function make_btrfs() has as argument the fsid of the filesystem. If this fsid is empty or null make_btrfs() generates a new fsid. However If the buffer is valid (but the string is empty) the generated fsid is copied back to the caller. Signed-off-by: Goffredo Baroncelli Reviewed-by: Satoru Takeuchi --- mkfs.c | 7 ++++--- utils.c | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mkfs.c b/mkfs.c index 042d12e..70c88ea 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1281,7 +1281,7 @@ int main(int ac, char **av) int dev_cnt = 0; int saved_optind; char estr[100]; - char *fs_uuid = NULL; + char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 }; u64 features = DEFAULT_MKFS_FEATURES; while(1) { @@ -1356,7 +1356,8 @@ int main(int ac, char **av) source_dir_set = 1; break; case 'U': - fs_uuid = optarg; + strncpy(fs_uuid,optarg, + BTRFS_UUID_UNPARSED_SIZE - 1); break; case 'K': discard = 0; @@ -1387,7 +1388,7 @@ int main(int ac, char **av) exit(1); } - if (fs_uuid) { + if (*fs_uuid) { uuid_t dummy_uuid; if (uuid_parse(fs_uuid, dummy_uuid) != 0) { diff --git a/utils.c b/utils.c index 3f50e4d..c7f1b2f 100644 --- a/utils.c +++ b/utils.c @@ -203,7 +203,7 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid, memset(&super, 0, sizeof(super)); num_bytes = (num_bytes / sectorsize) * sectorsize; - if (fs_uuid) { + if (fs_uuid && *fs_uuid) { if (uuid_parse(fs_uuid, super.fsid) != 0) { fprintf(stderr, "could not parse UUID: %s\n", fs_uuid); ret = -EINVAL; @@ -216,6 +216,11 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid, } } else { uuid_generate(super.fsid); + /* + * if the fs_uuid is a valid pointer, return the generated uuid + */ + if (fs_uuid) + uuid_unparse(super.fsid, fs_uuid); } uuid_generate(super.dev_item.uuid); uuid_generate(chunk_tree_uuid);