From patchwork Fri Nov 30 15:48:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 1825571 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 50D943FC23 for ; Fri, 30 Nov 2012 15:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030935Ab2K3Pm7 (ORCPT ); Fri, 30 Nov 2012 10:42:59 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:39663 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030929Ab2K3Pmz (ORCPT ); Fri, 30 Nov 2012 10:42:55 -0500 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qAUFgsYH001920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 30 Nov 2012 15:42:55 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qAUFgruA015329 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 30 Nov 2012 15:42:54 GMT Received: from abhmt109.oracle.com (abhmt109.oracle.com [141.146.116.61]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id qAUFgrD4030499 for ; Fri, 30 Nov 2012 09:42:53 -0600 Received: from localhost.localdomain (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 30 Nov 2012 07:42:53 -0800 From: Anand jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/3] Btrfs-progs: add attribute label for subvol and snapshot Date: Fri, 30 Nov 2012 23:48:01 +0800 Message-Id: <1354290482-5324-3-git-send-email-Anand.Jain@oracle.com> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1354290482-5324-1-git-send-email-Anand.Jain@oracle.com> References: <1351766770-4044-1-git-send-email-Anand.Jain@oracle.com> <1354290482-5324-1-git-send-email-Anand.Jain@oracle.com> X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Anand Jain Signed-off-by: Anand Jain --- btrfslabel.c | 38 ++++++++++++++++++++++++++++++++++++++ btrfslabel.h | 4 +++- ctree.h | 1 + 3 files changed, 42 insertions(+), 1 deletions(-) diff --git a/btrfslabel.c b/btrfslabel.c index cb142b0..8c424e5 100644 --- a/btrfslabel.c +++ b/btrfslabel.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include "kerncompat.h" #include "ctree.h" #include "utils.h" @@ -126,3 +128,39 @@ int set_label(char *btrfs_dev, char *nLabel) change_label_unmounted(btrfs_dev, nLabel); return 0; } + +int get_subvol_label(char *subvol, char *labelp) +{ + int ret; + ret = getxattr(subvol, "user.label", labelp, BTRFS_SUBVOL_LABEL_SIZE); + if(ret < 0) { + labelp = ""; + fprintf(stderr, "ERROR: get subvol label failed, %s\n", + strerror(errno)); + return -errno; + } + labelp[ret] = '\0'; + return 0; +} + +int set_subvol_label(char *subvol, char *labelp) +{ + int e=0; + char label[BTRFS_SUBVOL_LABEL_SIZE+1]; + + if (strlen(labelp) > BTRFS_SUBVOL_LABEL_SIZE) { + fprintf(stderr, "ERROR: Subvol label is more than max length %d\n", + BTRFS_SUBVOL_LABEL_SIZE); + return -1; + } + memset(label, 0, BTRFS_SUBVOL_LABEL_SIZE+1); + strcpy(label, labelp); + if(setxattr(subvol, "user.label", label, BTRFS_SUBVOL_LABEL_SIZE, + ATTR_ROOT) == -1) { + e = errno; + fprintf(stderr, "ERROR: set subvol label failed, %s\n", + strerror(e)); + return -e; + } + return 0; +} diff --git a/btrfslabel.h b/btrfslabel.h index abf43ad..1abc483 100644 --- a/btrfslabel.h +++ b/btrfslabel.h @@ -2,4 +2,6 @@ int get_label(char *btrfs_dev); -int set_label(char *btrfs_dev, char *nLabel); \ No newline at end of file +int set_label(char *btrfs_dev, char *nLabel); +int get_subvol_label(char *subvol, char *labelp); +int set_subvol_label(char *subvol, char *labelp); diff --git a/ctree.h b/ctree.h index 293b24f..993dbcf 100644 --- a/ctree.h +++ b/ctree.h @@ -325,6 +325,7 @@ struct btrfs_header { */ #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048 #define BTRFS_LABEL_SIZE 256 +#define BTRFS_SUBVOL_LABEL_SIZE 32 /* * just in case we somehow lose the roots and are not able to mount,