@@ -126,3 +126,48 @@ 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 fd, e=0;
+
+ fd = open_file_or_dir(subvol);
+
+ if(ioctl(fd, BTRFS_IOC_SUBVOL_GETLABEL, labelp) < 0) {
+ e = errno;
+ fprintf(stderr, "ERROR: get subvol label failed, %s\n",
+ strerror(e));
+ close(fd);
+ return -e;
+ }
+ labelp[BTRFS_LABEL_SIZE] = '\0';
+ if (!strlen(labelp))
+ return -1;
+ close(fd);
+ return 0;
+}
+
+int set_subvol_label(char *subvol, char *labelp)
+{
+ int fd, 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);
+ fd = open_file_or_dir(subvol);
+
+ 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;
+}
@@ -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);
@@ -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,
@@ -702,7 +703,8 @@ struct btrfs_root_item {
struct btrfs_timespec otime;
struct btrfs_timespec stime;
struct btrfs_timespec rtime;
- __le64 reserved[8]; /* for future */
+ char label[BTRFS_SUBVOL_LABEL_SIZE];
+ __le64 reserved[4]; /* for future */
} __attribute__ ((__packed__));
/*
@@ -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
@@ -330,6 +330,8 @@ static void print_root(struct extent_buffer *leaf, int slot)
btrfs_root_stransid(&root_item),
btrfs_root_rtransid(&root_item));
}
+ if (strlen(root_item.label))
+ printf("\t\tlabel %s\n", root_item.label);
}
if (btrfs_root_refs(&root_item) == 0) {
struct btrfs_key drop_key;