0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/module.h>
0009 #include <linux/kernel.h>
0010 #include <linux/string.h>
0011 #include <linux/nls.h>
0012 #include <linux/errno.h>
0013
0014 static struct nls_table *p_nls;
0015
0016 static int uni2char(const wchar_t uni,
0017 unsigned char *out, int boundlen)
0018 {
0019 if (boundlen <= 0)
0020 return -ENAMETOOLONG;
0021
0022 if ((uni & 0xffaf) == 0x040e || (uni & 0xffce) == 0x254c) {
0023
0024 if (uni == 0x040e)
0025 out[0] = 0xbe;
0026 else if (uni == 0x045e)
0027 out[0] = 0xae;
0028 else if (uni == 0x255d || uni == 0x256c)
0029 return 0;
0030 else
0031 return p_nls->uni2char(uni, out, boundlen);
0032 return 1;
0033 }
0034 else
0035
0036 return p_nls->uni2char(uni, out, boundlen);
0037 }
0038
0039 static int char2uni(const unsigned char *rawstring, int boundlen,
0040 wchar_t *uni)
0041 {
0042 int n;
0043
0044 if ((*rawstring & 0xef) != 0xae) {
0045
0046 *uni = (*rawstring & 0x10) ? 0x040e : 0x045e;
0047 return 1;
0048 }
0049
0050 n = p_nls->char2uni(rawstring, boundlen, uni);
0051 return n;
0052 }
0053
0054 static struct nls_table table = {
0055 .charset = "koi8-ru",
0056 .uni2char = uni2char,
0057 .char2uni = char2uni,
0058 };
0059
0060 static int __init init_nls_koi8_ru(void)
0061 {
0062 p_nls = load_nls("koi8-u");
0063
0064 if (p_nls) {
0065 table.charset2upper = p_nls->charset2upper;
0066 table.charset2lower = p_nls->charset2lower;
0067 return register_nls(&table);
0068 }
0069
0070 return -EINVAL;
0071 }
0072
0073 static void __exit exit_nls_koi8_ru(void)
0074 {
0075 unregister_nls(&table);
0076 unload_nls(p_nls);
0077 }
0078
0079 module_init(init_nls_koi8_ru)
0080 module_exit(exit_nls_koi8_ru)
0081
0082 MODULE_LICENSE("Dual BSD/GPL");