Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1436ybz; Tue, 21 Apr 2020 13:54:23 -0700 (PDT) X-Google-Smtp-Source: APiQypI/nKqjNJC3s3ilpn6PZJxaIzgV7ul9+hvAqhG0UimylQ1VdigNZke/W6P74w8mkoWOl6G5 X-Received: by 2002:a50:c60c:: with SMTP id k12mr20385296edg.111.1587502463555; Tue, 21 Apr 2020 13:54:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587502463; cv=none; d=google.com; s=arc-20160816; b=RbTqT7htOMnOAQgEV0ew35iuouD85IMFkwu4CbzRbeL3ap0E9FjeI7G+MD6RI7Eow1 xAgu07ObSE95Ajnz4jPxOIIr+rnfgD/Y/gUao9ExtPfkyIdr0QiQoS1U0ax1+oumc2LB ojycbR4jdCchE9vAecT8RYuh9tedvicmIbCIhzg+dKUidyiwEGGTNZayMQkl8XSJZ3Nu rIj9iNnnzZB693zHaWKIHp4Cas+FKg5f6YkEDZ01ptjCj22I7b6WoLWXEo2MUWD7NANH t/ECFZkIU+gRpSX2ZykY/qM+ccP90AXLdBZSdvzf3hvMOP6iQF5PVWkEgN0+gpFjbasW RTlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=TBcDFJbcw0QLE3NOF7fNVGq+10v7luGmYMYykkkrHPY=; b=yEdWV3zDvTcOMtC+PXaJ18RpI1LW/xKKAF2qXRMKWD7W4r6L8l9VfVGAF+VFiNGFtK 5BgiPNYI0OvSGRb5lqhoTHbBVY5JAoKtZm3PTiCCARWcPk8VzUvLRWvzYoAV2qqnCqC0 Loi67ftjWibviLYzCCEkKOYCykofsy5QER0PSskuc2KX+EJEtvXLsAYFBse9dpgpg2tN XUiIC+csdP4Tddo2GxqlcVe+G2A5Dklu5eL2Fsz/wN4WOez/k8CpnUP5zrYL/XhcWDUu zYUhN3YCcBL1FFPGbOdbIq5JHmT4CqzvTkDFZON03czwo/ri8x68BN4EVxFJFgYNDny2 lCbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si2081186edx.31.2020.04.21.13.53.54; Tue, 21 Apr 2020 13:54:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726067AbgDUUxt (ORCPT + 99 others); Tue, 21 Apr 2020 16:53:49 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:38066 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbgDUUxt (ORCPT ); Tue, 21 Apr 2020 16:53:49 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id C95702A05E0 From: Gabriel Krisman Bertazi To: linux-ext4@vger.kernel.org Cc: ezequiel@collabora.com, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com, Theodore Ts'o , Jaegeuk Kim Subject: [PATCH v3] unicode: Expose available encodings in sysfs Date: Tue, 21 Apr 2020 16:53:35 -0400 Message-Id: <20200421205335.2344628-1-krisman@collabora.com> X-Mailer: git-send-email 2.26.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 Cc: Jaegeuk Kim Signed-off-by: Gabriel Krisman Bertazi Changes since v2: - Change sysfs topology (Ezequiel) - Add end period (Ezequiel) - change module_init to fs_initcall (Ezequiel) Changes since v1: - Make init functions static. (lkp) --- Documentation/ABI/testing/sysfs-fs-unicode | 6 +++ fs/unicode/utf8-core.c | 55 ++++++++++++++++++++++ fs/unicode/utf8n.h | 4 ++ 3 files changed, 65 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-fs-unicode diff --git a/Documentation/ABI/testing/sysfs-fs-unicode b/Documentation/ABI/testing/sysfs-fs-unicode new file mode 100644 index 000000000000..b56e0dda6550 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-fs-unicode @@ -0,0 +1,6 @@ +What: /sys/fs/unicode//latest_version +Date: April 2020 +Contact: Gabriel Krisman Bertazi +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 2a878b739115..a075d024d783 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -6,6 +6,7 @@ #include #include #include +#include #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 0acd530c2c79..a14fa1e2f4c8 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); -- 2.26.1