From: Anand jain <Anand.Jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: Anand Jain <anand.jain@oracle.com>
Subject: [PATCH 2/2] Btrfs-progs: add feature to label subvol and snapshot
Date: Thu, 1 Nov 2012 18:46:09 +0800 [thread overview]
Message-ID: <1351766770-4044-3-git-send-email-Anand.Jain@oracle.com> (raw)
In-Reply-To: <1351766770-4044-1-git-send-email-Anand.Jain@oracle.com>
From: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
btrfslabel.c | 40 ++++++++++++++++++++++++++++++++++++++++
btrfslabel.h | 4 +++-
cmds-filesystem.c | 34 +++++++++++++++++++++++++++++-----
ioctl.h | 2 ++
4 files changed, 74 insertions(+), 6 deletions(-)
diff --git a/btrfslabel.c b/btrfslabel.c
index cb142b0..90fe618 100644
--- a/btrfslabel.c
+++ b/btrfslabel.c
@@ -126,3 +126,43 @@ int set_label(char *btrfs_dev, char *nLabel)
change_label_unmounted(btrfs_dev, nLabel);
return 0;
}
+
+int get_subvol_label(char *subvol)
+{
+ int fd, e=0;
+ char label[BTRFS_LABEL_SIZE+1];
+
+ fd = open_file_or_dir(subvol);
+
+ if(ioctl(fd, BTRFS_IOC_SUBVOL_GETLABEL, label) < 0) {
+ e = errno;
+ fprintf(stderr, "ERROR: get subvol label failed, %s\n",
+ strerror(e));
+ close(fd);
+ return -e;
+ }
+ label[BTRFS_LABEL_SIZE] = '\0';
+ printf("%s\n",label);
+ close(fd);
+ return 0;
+}
+
+int set_subvol_label(char *subvol, char *labelp)
+{
+ int fd, e=0;
+ char label[BTRFS_LABEL_SIZE];
+
+ fd = open_file_or_dir(subvol);
+
+ memset(label, 0, BTRFS_LABEL_SIZE);
+ strcpy(label, labelp);
+ if(ioctl(fd, BTRFS_IOC_SUBVOL_SETLABEL, label) < 0) {
+ e = errno;
+ fprintf(stderr, "ERROR: set subvol label failed, %s\n",
+ strerror(e));
+ close(fd);
+ return -e;
+ }
+ close(fd);
+ return 0;
+}
diff --git a/btrfslabel.h b/btrfslabel.h
index abf43ad..3db4180 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);
+int set_subvol_label(char *subvol, char *labelp);
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 9c43d35..718e70b 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -22,6 +22,7 @@
#include <errno.h>
#include <uuid/uuid.h>
#include <ctype.h>
+#include <sys/stat.h>
#include "kerncompat.h"
#include "ctree.h"
@@ -517,18 +518,41 @@ static int cmd_resize(int argc, char **argv)
}
static const char * const cmd_label_usage[] = {
- "btrfs filesystem label <device> [<newlabel>]",
- "Get or change the label of an unmounted filesystem",
- "With one argument, get the label of filesystem on <device>.",
- "If <newlabel> is passed, set the filesystem label to <newlabel>.",
+ "btrfs filesystem label [-t] <device>|<subvol> [<newlabel>]",
+ "Read or modify filesystem or subvol or snapshot label",
+ "-t Read or modify label for the specified subvol or snapshot.",
NULL
};
static int cmd_label(int argc, char **argv)
{
- if (check_argc_min(argc, 2) || check_argc_max(argc, 3))
+ struct stat st;
+ char subvol[BTRFS_PATH_NAME_MAX+1];
+
+ if (check_argc_min(argc, 2) || check_argc_max(argc, 4))
usage(cmd_label_usage);
+ if(getopt(argc, argv, "t:") != -1) {
+ if(optarg == NULL || strlen(optarg) > BTRFS_PATH_NAME_MAX)
+ return -1;
+ else {
+ strcpy(subvol,optarg);
+ if(stat(subvol, &st) < 0) {
+ fprintf(stderr, "Error: %s\n",strerror(errno));
+ return -errno;
+ }
+ if(!S_ISDIR(st.st_mode)) {
+ fprintf(stderr, "Error: Not a dir\n");
+ return -1;
+ }
+ }
+ if (argc > 3)
+ return set_subvol_label(argv[2], argv[3]);
+ else
+ return get_subvol_label(argv[2]);
+ return 0;
+ }
+
if (argc > 2)
return set_label(argv[1], argv[2]);
else
diff --git a/ioctl.h b/ioctl.h
index 6fda3a1..009fa6e 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -432,4 +432,6 @@ struct btrfs_ioctl_clone_range_args {
struct btrfs_ioctl_qgroup_create_args)
#define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
struct btrfs_ioctl_qgroup_limit_args)
+#define BTRFS_IOC_SUBVOL_GETLABEL _IOWR(BTRFS_IOCTL_MAGIC, 55, __u64)
+#define BTRFS_IOC_SUBVOL_SETLABEL _IOW(BTRFS_IOCTL_MAGIC, 56, __u64)
#endif
--
1.7.1
next prev parent reply other threads:[~2012-11-01 10:42 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-01 10:46 [Request for review] [RFC] Add label support for snapshots and subvols Anand jain
2012-11-01 10:46 ` [PATCH 1/2] Btrfs-progs: move open_file_or_dir() to utils.c Anand jain
2012-11-01 10:46 ` Anand jain [this message]
2012-11-01 10:46 ` [PATCH] Btrfs: add label to snapshot and subvol Anand jain
2012-11-05 7:39 ` Jan Schmidt
2012-11-16 5:15 ` Anand Jain
2012-11-01 22:16 ` [Request for review] [RFC] Add label support for snapshots and subvols cwillu
2012-11-01 22:28 ` Fajar A. Nugraha
2012-11-01 22:32 ` Hugo Mills
2012-11-01 22:49 ` Fajar A. Nugraha
2012-11-05 7:24 ` Anand Jain
2012-11-05 23:22 ` David Sterba
2012-11-01 23:04 ` Goffredo Baroncelli
2012-11-16 4:52 ` [Request for review v2] " Anand jain
2012-11-16 4:52 ` [PATCH 1/3] Btrfs-progs: move open_file_or_dir() to utils.c Anand jain
2012-11-16 4:52 ` [PATCH v2] Btrfs: add label to snapshot and subvol Anand jain
2012-11-16 6:33 ` Miao Xie
2012-11-27 18:26 ` Anand Jain
2012-11-16 4:52 ` [PATCH 2/3] Btrfs-progs: add feature to label subvol and snapshot Anand jain
2012-11-16 4:52 ` [PATCH 3/3] Btrfs-progs: cmd option to show or set the subvol label Anand jain
2012-11-27 18:29 ` [Request for review v3] [RFC] Add label support for snapshots and subvols Anand jain
2012-11-27 18:29 ` [PATCH v3] Btrfs: add label to snapshot and subvol Anand jain
2012-11-28 3:05 ` Miao Xie
2012-11-28 10:02 ` Anand Jain
2012-11-28 10:25 ` Miao Xie
2012-11-28 12:17 ` Anand Jain
2012-11-28 12:15 ` Anand jain
2012-11-27 18:29 ` [PATCH 1/3] Btrfs-progs: move open_file_or_dir() to utils.c Anand jain
2012-11-27 18:29 ` [PATCH 2/3] Btrfs-progs: add feature to label subvol and snapshot Anand jain
2012-11-27 18:29 ` [PATCH 3/3] Btrfs-progs: cmd option to show or set the subvol label Anand jain
2012-11-30 15:47 ` [PATCH 0/3] Add subvol and snapshot attribute label Anand jain
2012-11-30 15:48 ` [PATCH 1/3] Btrfs-progs: move open_file_or_dir() to utils.c Anand jain
2012-11-30 15:48 ` [PATCH 2/3] Btrfs-progs: add attribute label for subvol and snapshot Anand jain
2012-11-30 15:48 ` [PATCH 3/3] Btrfs-progs: cmd option to show or set the subvol label Anand jain
2013-02-25 5:31 ` [PATCH 0/2 v4] Btrfs-progs: Add support for " Anand Jain
2013-02-25 5:31 ` [PATCH 1/2 v4] Btrfs-progs: add feature to label subvol and snapshot Anand Jain
2013-02-25 5:31 ` [PATCH 2/2 v4] Btrfs-progs: cmd option to show or set the subvol label Anand Jain
2013-02-25 5:31 ` [PATCH v4] Btrfs: Add support for " Anand Jain
2013-02-25 5:31 ` [PATCH v4] Btrfs: ability to add label to snapshot and subvol Anand Jain
2013-02-25 20:45 ` Hugo Mills
2013-03-01 10:36 ` Anand Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1351766770-4044-3-git-send-email-Anand.Jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).