@@ -34,6 +34,8 @@
#include <linux/fs.h>
#include <linux/limits.h>
#include <ctype.h>
+#include <attr/xattr.h>
+#include <attr/attributes.h>
#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;
+}
@@ -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,