aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/xattr/xattr.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-06-07 23:38:06 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-06-09 06:04:08 +0200
commit1f210bab667a540379243050b5ce3465086e1124 (patch)
tree2f3aafe42326cc47a6f5952d3e4bb980ce41e4a1 /lib/sqfs/xattr/xattr.c
parent04be64583149515f774bf01f03b1be6121649668 (diff)
Cleanup: split libsquashfs xattr writer code
This commit moves the libsquashfs xattr related code into a sub directory and splits the xattr writer code up into several files. No actual code is changed. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/xattr/xattr.c')
-rw-r--r--lib/sqfs/xattr/xattr.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/sqfs/xattr/xattr.c b/lib/sqfs/xattr/xattr.c
new file mode 100644
index 0000000..29ecebf
--- /dev/null
+++ b/lib/sqfs/xattr/xattr.c
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: LGPL-3.0-or-later */
+/*
+ * write_xattr.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#define SQFS_BUILDING_DLL
+#include "config.h"
+#include "sqfs/xattr.h"
+#include "sqfs/error.h"
+
+#include <string.h>
+
+static const struct {
+ const char *prefix;
+ SQFS_XATTR_TYPE type;
+} xattr_types[] = {
+ { "user.", SQFS_XATTR_USER },
+ { "trusted.", SQFS_XATTR_TRUSTED },
+ { "security.", SQFS_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 SQFS_ERROR_UNSUPPORTED;
+}
+
+const char *sqfs_get_xattr_prefix(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;
+}