@@ -19,10 +19,26 @@
extern struct nls_charset default_charset;
static struct nls_charset *charsets = &default_charset;
static DEFINE_SPINLOCK(nls_lock);
-static struct nls_table *nls_load_table(struct nls_charset *charset)
+
+static struct nls_table *nls_load_table(struct nls_charset *charset,
+ const char *version,
+ unsigned int flags)
{
- /* For now, return the default table, which is the first one found. */
- return charset->tables;
+ struct nls_table *tbl;
+
+ /* If there is no load_table hook, only 1 table is supported and
+ * it must have been loaded statically.
+ */
+ if (charset->load_table)
+ tbl = charset->load_table(version, flags);
+ else
+ tbl = charset->tables;
+
+ if (IS_ERR(tbl))
+ return tbl;
+
+ tbl->flags = flags;
+ return tbl;
}
int __register_nls(struct nls_charset *nls, struct module *owner)
@@ -85,21 +101,36 @@ static struct nls_charset *find_nls(const char *charset)
return nls;
}
-struct nls_table *load_nls(char *charset)
+struct nls_table *load_nls_version(const char *charset, const char *version,
+ unsigned int flags)
{
struct nls_charset *nls_charset;
nls_charset = try_then_request_module(find_nls(charset),
"nls_%s", charset);
- if (!IS_ERR(nls_charset))
+ if (IS_ERR(nls_charset))
+ return ERR_PTR(-EINVAL);
+
+ return nls_load_table(nls_charset, version, flags);
+}
+EXPORT_SYMBOL(load_nls_version);
+
+struct nls_table *load_nls(char *charset)
+{
+ struct nls_table *table = load_nls_version(charset, NULL, 0);
+
+ /* Pre-versioned load_nls() didn't return error pointers. Let's
+ * keep the abi for now to prevent breakage.
+ */
+ if (IS_ERR(table))
return NULL;
- return nls_load_table(nls_charset);
+ return table;
}
void unload_nls(struct nls_table *nls)
{
- if (nls)
+ if (!IS_ERR_OR_NULL(nls))
module_put(nls->charset->owner);
}
@@ -30,6 +30,9 @@ struct nls_ops {
struct nls_table {
const struct nls_charset *charset;
+ unsigned int version;
+ unsigned int flags;
+
const struct nls_ops *ops;
const unsigned char *charset2lower;
const unsigned char *charset2upper;
@@ -42,6 +45,8 @@ struct nls_charset {
struct module *owner;
struct nls_table *tables;
struct nls_charset *next;
+ struct nls_table *(*load_table)(const char *version,
+ unsigned int flags);
};
/* this value hold the maximum octet of charset */
@@ -58,6 +63,9 @@ enum utf16_endian {
extern int __register_nls(struct nls_charset *, struct module *);
extern int unregister_nls(struct nls_charset *);
extern struct nls_table *load_nls(char *);
+extern struct nls_table *load_nls_version(const char *charset,
+ const char *version,
+ unsigned int flags);
extern void unload_nls(struct nls_table *);
extern struct nls_table *load_nls_default(void);
#define register_nls(nls) __register_nls((nls), THIS_MODULE)