summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Krisman Bertazi <krisman@collabora.com>2020-04-07 15:36:57 -0400
committerGabriel Krisman Bertazi <krisman@collabora.com>2020-05-18 15:07:13 -0400
commitcfeb007a96b15cafe1b8cc7aa8d43da77a97b7ae (patch)
tree66014112380163792b27235e7478fecd64686cf9
parentd269543a1dcb29d198f1e8f0dd0a249a563bc2ee (diff)
downloadunicode-next-v5.8.tar.gz
unicode: Expose available encodings in sysfsunicode-next-v5.8
A filesystem configuration utility has no way to detect which filename encodings are supported by the running kernel. This means, for instance, mkfs has no way to tell if the generated filesystem will be mountable in the current kernel or not. Also, users have no easy way to know if they can update the encoding in their filesystems and still have something functional in the end. This exposes details of the encodings available in the unicode subsystem to fill that gap. Cc: Theodore Ts'o <tytso@mit.edu> Cc: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
-rw-r--r--Documentation/ABI/testing/sysfs-fs-unicode6
-rw-r--r--fs/unicode/utf8-core.c55
-rw-r--r--fs/unicode/utf8n.h4
3 files changed, 65 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-fs-unicode b/Documentation/ABI/testing/sysfs-fs-unicode
new file mode 100644
index 00000000000000..b56e0dda655084
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-fs-unicode
@@ -0,0 +1,6 @@
+What: /sys/fs/unicode/<encoding>/latest_version
+Date: April 2020
+Contact: Gabriel Krisman Bertazi <krisman@collabora.com>
+Description:
+ The latest version of the Unicode Standard supported by
+ this encoding in this kernel.
diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c
index 2a878b739115d2..a075d024d78304 100644
--- a/fs/unicode/utf8-core.c
+++ b/fs/unicode/utf8-core.c
@@ -6,6 +6,7 @@
#include <linux/parser.h>
#include <linux/errno.h>
#include <linux/unicode.h>
+#include <linux/fs.h>
#include "utf8n.h"
@@ -212,4 +213,58 @@ void utf8_unload(struct unicode_map *um)
}
EXPORT_SYMBOL(utf8_unload);
+static ssize_t latest_version_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ int l = utf8version_latest();
+
+ return snprintf(buf, PAGE_SIZE, "%d.%d.%d\n",
+ UNICODE_AGE_MAJ(l), UNICODE_AGE_MIN(l),
+ UNICODE_AGE_REV(l));
+}
+
+#define UNICODE_ATTR(x) \
+ static struct kobj_attribute x ## _attr = __ATTR_RO(x)
+
+UNICODE_ATTR(latest_version);
+
+static struct attribute *encoding_attrs[] = {
+ &latest_version_attr.attr,
+ NULL,
+};
+static const struct attribute_group encoding_attr_group = {
+ .attrs = encoding_attrs,
+};
+
+static struct kobject *unicode_kobj;
+static struct kobject *utf8_kobj;
+
+static int __init unicode_init(void)
+{
+ int ret = 0;
+
+ unicode_kobj = kobject_create_and_add("unicode", fs_kobj);
+ if (!unicode_kobj)
+ return -ENOMEM;
+
+ utf8_kobj = kobject_create_and_add("utf-8", unicode_kobj);
+ if (!utf8_kobj) {
+ ret = -ENOMEM;
+ goto fail_unicode;
+ }
+
+ ret = sysfs_create_group(utf8_kobj, &encoding_attr_group);
+ if (ret)
+ goto fail_utf8;
+
+ return 0;
+
+fail_utf8:
+ kobject_put(utf8_kobj);
+fail_unicode:
+ kobject_put(unicode_kobj);
+ return ret;
+}
+fs_initcall(unicode_init);
+
MODULE_LICENSE("GPL v2");
diff --git a/fs/unicode/utf8n.h b/fs/unicode/utf8n.h
index 0acd530c2c791e..a14fa1e2f4c8e2 100644
--- a/fs/unicode/utf8n.h
+++ b/fs/unicode/utf8n.h
@@ -21,6 +21,10 @@
((unsigned int)(MIN) << UNICODE_MIN_SHIFT) | \
((unsigned int)(REV)))
+#define UNICODE_AGE_MAJ(x) ((x) >> UNICODE_MAJ_SHIFT & 0xff)
+#define UNICODE_AGE_MIN(x) ((x) >> UNICODE_MIN_SHIFT & 0xff)
+#define UNICODE_AGE_REV(x) ((x) & 0xff)
+
/* Highest unicode version supported by the data tables. */
extern int utf8version_is_supported(u8 maj, u8 min, u8 rev);
extern int utf8version_latest(void);