From: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
To: viro@ZenIV.linux.org.uk
Cc: jra@google.com, tytso@mit.edu, olaf@sgi.com,
darrick.wong@oracle.com, kernel@lists.collabora.co.uk,
linux-fsdevel@vger.kernel.org, david@fromorbit.com, jack@suse.cz,
linux-kernel@vger.kernel.org,
Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Subject: [PATCH v2 04/15] nls: Split default charset from NLS core
Date: Mon, 21 May 2018 14:36:06 -0300 [thread overview]
Message-ID: <20180521173617.31625-5-krisman@collabora.co.uk> (raw)
In-Reply-To: <20180521173617.31625-1-krisman@collabora.co.uk>
Changes since v1:
- Fix build as a module (kbuild test robot)
Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
---
fs/nls/Makefile | 1 +
fs/nls/nls_core.c | 94 ++++++++++++++++++++++++++++
fs/nls/{nls_base.c => nls_default.c} | 93 +++------------------------
3 files changed, 102 insertions(+), 86 deletions(-)
create mode 100644 fs/nls/nls_core.c
rename fs/nls/{nls_base.c => nls_default.c} (90%)
diff --git a/fs/nls/Makefile b/fs/nls/Makefile
index ac54db297128..5f42ceff9d15 100644
--- a/fs/nls/Makefile
+++ b/fs/nls/Makefile
@@ -3,6 +3,7 @@
# Makefile for native language support
#
+nls_base-y := nls_core.o nls_default.o
obj-$(CONFIG_NLS) += nls_base.o
obj-$(CONFIG_NLS_CODEPAGE_437) += nls_cp437.o
diff --git a/fs/nls/nls_core.c b/fs/nls/nls_core.c
new file mode 100644
index 000000000000..3f7de8f4c5b2
--- /dev/null
+++ b/fs/nls/nls_core.c
@@ -0,0 +1,94 @@
+/*
+ * linux/fs/nls/nls_core.c
+ *
+ * Native language support--charsets and unicode translations.
+ * By Gordon Chaffee 1996, 1997
+ *
+ * Unicode based case conversion 1999 by Wolfram Pienkoss
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/nls.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/kmod.h>
+#include <linux/spinlock.h>
+
+static struct nls_table default_table;
+static struct nls_table *tables = &default_table;
+static DEFINE_SPINLOCK(nls_lock);
+
+int __register_nls(struct nls_table *nls, struct module *owner)
+{
+ struct nls_table ** tmp = &tables;
+
+ if (nls->next)
+ return -EBUSY;
+
+ nls->owner = owner;
+ spin_lock(&nls_lock);
+ while (*tmp) {
+ if (nls == *tmp) {
+ spin_unlock(&nls_lock);
+ return -EBUSY;
+ }
+ tmp = &(*tmp)->next;
+ }
+ nls->next = tables;
+ tables = nls;
+ spin_unlock(&nls_lock);
+ return 0;
+}
+EXPORT_SYMBOL(__register_nls);
+
+int unregister_nls(struct nls_table * nls)
+{
+ struct nls_table ** tmp = &tables;
+
+ spin_lock(&nls_lock);
+ while (*tmp) {
+ if (nls == *tmp) {
+ *tmp = nls->next;
+ spin_unlock(&nls_lock);
+ return 0;
+ }
+ tmp = &(*tmp)->next;
+ }
+ spin_unlock(&nls_lock);
+ return -EINVAL;
+}
+
+static struct nls_table *find_nls(char *charset)
+{
+ struct nls_table *nls;
+ spin_lock(&nls_lock);
+ for (nls = tables; nls; nls = nls->next) {
+ if (!strcmp(nls_charset_name(nls), charset))
+ break;
+ if (nls->alias && !strcmp(nls->alias, charset))
+ break;
+ }
+ if (nls && !try_module_get(nls->owner))
+ nls = NULL;
+ spin_unlock(&nls_lock);
+ return nls;
+}
+
+struct nls_table *load_nls(char *charset)
+{
+ return try_then_request_module(find_nls(charset), "nls_%s", charset);
+}
+
+void unload_nls(struct nls_table *nls)
+{
+ if (nls)
+ module_put(nls->owner);
+}
+
+EXPORT_SYMBOL(unregister_nls);
+EXPORT_SYMBOL(unload_nls);
+EXPORT_SYMBOL(load_nls);
+
+MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/nls_base.c b/fs/nls/nls_default.c
similarity index 90%
rename from fs/nls/nls_base.c
rename to fs/nls/nls_default.c
index 0bb0acf6893f..c5d7e8391b22 100644
--- a/fs/nls/nls_base.c
+++ b/fs/nls/nls_default.c
@@ -1,5 +1,5 @@
/*
- * linux/fs/nls/nls_base.c
+ * linux/fs/nls/nls_default.c
*
* Native language support--charsets and unicode translations.
* By Gordon Chaffee 1996, 1997
@@ -8,23 +8,17 @@
*
*/
+/*
+ * Sample implementation from Unicode home page.
+ * http://www.stonehand.com/unicode/standard/fss-utf.html
+ */
+
#include <linux/module.h>
-#include <linux/string.h>
-#include <linux/nls.h>
-#include <linux/kernel.h>
-#include <linux/errno.h>
-#include <linux/kmod.h>
-#include <linux/spinlock.h>
#include <asm/byteorder.h>
+#include <linux/nls.h>
static struct nls_table default_table;
-static struct nls_table *tables = &default_table;
-static DEFINE_SPINLOCK(nls_lock);
-/*
- * Sample implementation from Unicode home page.
- * http://www.stonehand.com/unicode/standard/fss-utf.html
- */
struct utf8_table {
int cmask;
int cval;
@@ -232,73 +226,6 @@ int utf16s_to_utf8s(const wchar_t *pwcs, int inlen, enum utf16_endian endian,
}
EXPORT_SYMBOL(utf16s_to_utf8s);
-int __register_nls(struct nls_table *nls, struct module *owner)
-{
- struct nls_table ** tmp = &tables;
-
- if (nls->next)
- return -EBUSY;
-
- nls->owner = owner;
- spin_lock(&nls_lock);
- while (*tmp) {
- if (nls == *tmp) {
- spin_unlock(&nls_lock);
- return -EBUSY;
- }
- tmp = &(*tmp)->next;
- }
- nls->next = tables;
- tables = nls;
- spin_unlock(&nls_lock);
- return 0;
-}
-EXPORT_SYMBOL(__register_nls);
-
-int unregister_nls(struct nls_table * nls)
-{
- struct nls_table ** tmp = &tables;
-
- spin_lock(&nls_lock);
- while (*tmp) {
- if (nls == *tmp) {
- *tmp = nls->next;
- spin_unlock(&nls_lock);
- return 0;
- }
- tmp = &(*tmp)->next;
- }
- spin_unlock(&nls_lock);
- return -EINVAL;
-}
-
-static struct nls_table *find_nls(char *charset)
-{
- struct nls_table *nls;
- spin_lock(&nls_lock);
- for (nls = tables; nls; nls = nls->next) {
- if (!strcmp(nls_charset_name(nls), charset))
- break;
- if (nls->alias && !strcmp(nls->alias, charset))
- break;
- }
- if (nls && !try_module_get(nls->owner))
- nls = NULL;
- spin_unlock(&nls_lock);
- return nls;
-}
-
-struct nls_table *load_nls(char *charset)
-{
- return try_then_request_module(find_nls(charset), "nls_%s", charset);
-}
-
-void unload_nls(struct nls_table *nls)
-{
- if (nls)
- module_put(nls->owner);
-}
-
static const wchar_t charset2uni[256] = {
/* 0x00*/
0x0000, 0x0001, 0x0002, 0x0003,
@@ -543,10 +470,4 @@ struct nls_table *load_nls_default(void)
else
return &default_table;
}
-
-EXPORT_SYMBOL(unregister_nls);
-EXPORT_SYMBOL(unload_nls);
-EXPORT_SYMBOL(load_nls);
EXPORT_SYMBOL(load_nls_default);
-
-MODULE_LICENSE("Dual BSD/GPL");
--
2.17.0
next prev parent reply other threads:[~2018-05-21 17:36 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-21 17:36 [PATCH v2 00/15] NLS refactor and UTF-8 normalization Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 01/15] nls: Wrap uni2char/char2uni callers Gabriel Krisman Bertazi
2018-05-22 8:37 ` Jan Kara
2018-05-22 8:40 ` Jan Kara
2018-05-21 17:36 ` [PATCH v2 02/15] nls: Wrap charset field access Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 03/15] nls: Wrap charset hooks in ops structure Gabriel Krisman Bertazi
2018-05-21 17:36 ` Gabriel Krisman Bertazi [this message]
2018-05-21 17:36 ` [PATCH v2 05/15] nls: Split struct nls_charset from struct nls_table Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 06/15] nls: Add support for multiple versions of an encoding Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 07/15] nls: Add new interface for string comparisons Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 08/15] nls: Let charsets define the behavior of tolower/toupper Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 09/15] nls: Add optional normalization and casefold hooks Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 10/15] nls: utf8norm: Add unicode character database files Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 11/15] scripts: add trie generator for UTF-8 Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 12/15] nls: utf8norm: Introduce code for UTF-8 normalization Gabriel Krisman Bertazi
2018-05-31 5:47 ` kbuild test robot
2018-05-21 17:36 ` [PATCH v2 13/15] nls: utf8norm: reduce the size of utf8data[] Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 14/15] nls: utf8norm: Integrate utf8norm code with NLS subsystem Gabriel Krisman Bertazi
2018-05-21 17:36 ` [PATCH v2 15/15] nls: utf8norm: Introduce test module for utf8norm implementation Gabriel Krisman Bertazi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180521173617.31625-5-krisman@collabora.co.uk \
--to=krisman@collabora.co.uk \
--cc=darrick.wong@oracle.com \
--cc=david@fromorbit.com \
--cc=jack@suse.cz \
--cc=jra@google.com \
--cc=kernel@lists.collabora.co.uk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=olaf@sgi.com \
--cc=tytso@mit.edu \
--cc=viro@ZenIV.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).