aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/xattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs/xattr.c')
-rw-r--r--lib/sqfs/xattr.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/sqfs/xattr.c b/lib/sqfs/xattr.c
new file mode 100644
index 0000000..db8edf4
--- /dev/null
+++ b/lib/sqfs/xattr.c
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * write_xattr.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+#include "squashfs.h"
+
+#include <string.h>
+
+static const struct {
+ const char *prefix;
+ E_SQFS_XATTR_TYPE type;
+} xattr_types[] = {
+ { "user.", SQUASHFS_XATTR_USER },
+ { "trusted.", SQUASHFS_XATTR_TRUSTED },
+ { "security.", SQUASHFS_XATTR_SECURITY },
+};
+
+int sqfs_get_xattr_prefix_id(const char *key)
+{
+ size_t i, len;
+
+ for (i = 0; i < sizeof(xattr_types) / sizeof(xattr_types[0]); ++i) {
+ len = strlen(xattr_types[i].prefix);
+
+ if (strncmp(key, xattr_types[i].prefix, len) == 0 &&
+ strlen(key) > len) {
+ return xattr_types[i].type;
+ }
+ }
+
+ return -1;
+}
+
+const char *sqfs_get_xattr_prefix(E_SQFS_XATTR_TYPE id)
+{
+ size_t i;
+
+ for (i = 0; i < sizeof(xattr_types) / sizeof(xattr_types[0]); ++i) {
+ if (xattr_types[i].type == id)
+ return xattr_types[i].prefix;
+ }
+
+ return NULL;
+}
+
+bool sqfs_has_xattr(const char *key)
+{
+ return sqfs_get_xattr_prefix_id(key) >= 0;
+}