1 Submitted by: Alexander E. Patrakov <patrakov@ums.usu.ru>
2 Signed-off-by: Alexander E. Patrakov <patrakov@ums.usu.ru>
4 Initial Package Version: 2.6.15
5 Upstream Status: Rejected: they say it modifies the meaning of an existing ioctl
6 Origin: http://chris.heathens.co.nz/linux/downloads/patches-2.6.4-cdh1.tar.gz
7 Porting to linux-2.6.16 by Alexander E. Patrakov
8 Description: This patch fixes dead keys and copy/paste of non-ASCII characters
9 in UTF-8 mode on Linux console.
10 See more details about the original patch at:
11 http://chris.heathens.co.nz/linux/utf8.html
13 diff -ur linux-2.6.15-rc6.orig/drivers/char/consolemap.c linux-2.6.15-rc6.my/drivers/char/consolemap.c
14 --- linux-2.6.15-rc6.orig/drivers/char/consolemap.c 2005-12-25 10:00:12.000000000 +0500
15 +++ linux-2.6.15-rc6.my/drivers/char/consolemap.c 2005-12-25 10:01:22.000000000 +0500
17 unsigned long refcount;
19 unsigned char *inverse_translations[4];
20 + u16 *inverse_trans_unicode;
28 +static void set_inverse_trans_unicode(struct vc_data *conp,
29 + struct uni_pagedir *p)
36 + q = p->inverse_trans_unicode;
38 + q = p->inverse_trans_unicode =
39 + kmalloc(MAX_GLYPH * sizeof(u16), GFP_KERNEL);
43 + memset(q, 0, MAX_GLYPH * sizeof(u16));
45 + for (i = 0; i < 32; i++) {
46 + p1 = p->uni_pgdir[i];
49 + for (j = 0; j < 32; j++) {
53 + for (k = 0; k < 64; k++) {
55 + if (glyph >= 0 && glyph < MAX_GLYPH
57 + q[glyph] = (i << 11) + (j << 6) + k;
63 unsigned short *set_translate(int m, struct vc_data *vc)
65 inv_translate[vc->vc_num] = m;
67 * Inverse translation is impossible for several reasons:
68 * 1. The font<->character maps are not 1-1.
69 * 2. The text may have been written while a different translation map
70 - * was active, or using Unicode.
72 * Still, it is now possible to a certain extent to cut and paste non-ASCII.
74 -unsigned char inverse_translate(struct vc_data *conp, int glyph)
75 +u16 inverse_translate(struct vc_data *conp, int glyph, int use_unicode)
77 struct uni_pagedir *p;
79 if (glyph < 0 || glyph >= MAX_GLYPH)
81 - else if (!(p = (struct uni_pagedir *)*conp->vc_uni_pagedir_loc) ||
82 - !p->inverse_translations[inv_translate[conp->vc_num]])
83 + else if (!(p = (struct uni_pagedir *)*conp->vc_uni_pagedir_loc))
86 - return p->inverse_translations[inv_translate[conp->vc_num]][glyph];
87 + else if (use_unicode) {
88 + if (!p->inverse_trans_unicode)
91 + return p->inverse_trans_unicode[glyph];
93 + m = inv_translate[conp->vc_num];
94 + if (!p->inverse_translations[m])
97 + return p->inverse_translations[m][glyph];
101 static void update_user_maps(void)
103 p = (struct uni_pagedir *)*vc_cons[i].d->vc_uni_pagedir_loc;
105 set_inverse_transl(vc_cons[i].d, p, USER_MAP);
106 + set_inverse_trans_unicode(vc_cons[i].d, p);
111 kfree(p->inverse_translations[i]);
112 p->inverse_translations[i] = NULL;
114 + if (p->inverse_trans_unicode) {
115 + kfree(p->inverse_trans_unicode);
116 + p->inverse_trans_unicode = NULL;
120 void con_free_unimap(struct vc_data *vc)
123 for (i = 0; i <= 3; i++)
124 set_inverse_transl(vc, p, i); /* Update all inverse translations */
125 + set_inverse_trans_unicode(vc, p);
131 for (i = 0; i <= 3; i++)
132 set_inverse_transl(vc, p, i); /* Update all inverse translations */
133 + set_inverse_trans_unicode(vc, p);
138 p->readonly = rdonly;
141 +/* may be called during an interrupt */
142 +u32 conv_8bit_to_uni(unsigned char c)
145 + * Always use USER_MAP. This function is used by the keyboard,
146 + * which shouldn't be affected by G0/G1 switching, etc.
147 + * If the user map still contains default values, i.e. the
148 + * direct-to-font mapping, then assume user is using Latin1.
150 + unsigned short uni = translations[USER_MAP][c];
151 + return uni == (0xf000 | c) ? c : uni;
155 conv_uni_to_pc(struct vc_data *conp, long ucs)
157 diff -ur linux-2.6.15-rc6.orig/drivers/char/keyboard.c linux-2.6.15-rc6.my/drivers/char/keyboard.c
158 --- linux-2.6.15-rc6.orig/drivers/char/keyboard.c 2005-12-25 10:00:12.000000000 +0500
159 +++ linux-2.6.15-rc6.my/drivers/char/keyboard.c 2005-12-25 10:01:22.000000000 +0500
161 #include <linux/init.h>
162 #include <linux/slab.h>
164 +#include <linux/consolemap.h>
165 #include <linux/kbd_kern.h>
166 #include <linux/kbd_diacr.h>
167 #include <linux/vt_kern.h>
169 * Many other routines do put_queue, but I think either
170 * they produce ASCII, or they produce some user-assigned
171 * string, and in both cases we might assume that it is
172 - * in utf-8 already. UTF-8 is defined for words of up to 31 bits,
173 - * but we need only 16 bits here
174 + * in utf-8 already.
176 -static void to_utf8(struct vc_data *vc, ushort c)
177 +static void to_utf8(struct vc_data *vc, uint c)
181 @@ -341,14 +341,33 @@
182 /* 110***** 10****** */
183 put_queue(vc, 0xc0 | (c >> 6));
184 put_queue(vc, 0x80 | (c & 0x3f));
186 + } else if (c < 0x10000) {
187 + if (c >= 0xD800 && c < 0xE000)
191 /* 1110**** 10****** 10****** */
192 put_queue(vc, 0xe0 | (c >> 12));
193 put_queue(vc, 0x80 | ((c >> 6) & 0x3f));
194 put_queue(vc, 0x80 | (c & 0x3f));
195 + } else if (c < 0x110000) {
196 + /* 11110*** 10****** 10****** 10****** */
197 + put_queue(vc, 0xf0 | (c >> 18));
198 + put_queue(vc, 0x80 | ((c >> 12) & 0x3f));
199 + put_queue(vc, 0x80 | ((c >> 6) & 0x3f));
200 + put_queue(vc, 0x80 | (c & 0x3f));
204 +static void put_8bit(struct vc_data *vc, u8 c)
206 + if (kbd->kbdmode != VC_UNICODE || c < 32 || c == 127)
207 + /* Don't translate control chars */
210 + to_utf8(vc, conv_8bit_to_uni(c));
214 * Called after returning from RAW mode or when changing consoles - recompute
215 * shift_down[] and shift_state from key_down[] maybe called when keymap is
217 if (ch == ' ' || ch == d)
226 static void fn_enter(struct vc_data *vc, struct pt_regs *regs)
229 - put_queue(vc, diacr);
230 + put_8bit(vc, diacr);
238 - put_queue(vc, value);
239 + put_8bit(vc, value);
245 if (up_flag && shift_state != old_state && npadch != -1) {
246 if (kbd->kbdmode == VC_UNICODE)
247 - to_utf8(vc, npadch & 0xffff);
248 + to_utf8(vc, npadch);
250 put_queue(vc, npadch & 0xff);
252 diff -ur linux-2.6.15-rc6.orig/drivers/char/selection.c linux-2.6.15-rc6.my/drivers/char/selection.c
253 --- linux-2.6.15-rc6.orig/drivers/char/selection.c 2005-12-25 10:00:12.000000000 +0500
254 +++ linux-2.6.15-rc6.my/drivers/char/selection.c 2005-12-25 10:01:22.000000000 +0500
257 #include <asm/uaccess.h>
259 +#include <linux/kbd_kern.h>
260 #include <linux/vt_kern.h>
261 #include <linux/consolemap.h>
262 #include <linux/selection.h>
264 /* Variables for selection control. */
265 /* Use a dynamic buffer, instead of static (Dec 1994) */
266 struct vc_data *sel_cons; /* must not be disallocated */
267 +static int use_unicode;
268 static volatile int sel_start = -1; /* cleared by clear_selection */
270 static int sel_buffer_lth;
272 complement_pos(sel_cons, where);
275 -static unsigned char
279 - return inverse_translate(sel_cons, screen_glyph(sel_cons, n));
280 + return inverse_translate(sel_cons, screen_glyph(sel_cons, n),
284 /* remove the current selection highlight, if any,
286 0xFF7FFFFF /* latin-1 accented letters, not division sign */
289 -static inline int inword(const unsigned char c) {
290 - return ( inwordLut[c>>5] >> (c & 0x1F) ) & 1;
291 +static inline int inword(const u16 c) {
292 + return c > 0xff || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1);
295 /* set inwordLut contents. Invoked by ioctl(). */
296 @@ -108,13 +111,36 @@
297 return (v > u) ? u : v;
300 +/* stores the char in UTF8 and returns the number of bytes used (1-3) */
301 +int store_utf8(u16 c, char *p)
307 + } else if (c < 0x800) {
308 + /* 110***** 10****** */
309 + p[0] = 0xc0 | (c >> 6);
310 + p[1] = 0x80 | (c & 0x3f);
313 + /* 1110**** 10****** 10****** */
314 + p[0] = 0xe0 | (c >> 12);
315 + p[1] = 0x80 | ((c >> 6) & 0x3f);
316 + p[2] = 0x80 | (c & 0x3f);
321 /* set the current selection. Invoked by ioctl() or by kernel code. */
322 int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty)
324 struct vc_data *vc = vc_cons[fg_console].d;
325 int sel_mode, new_sel_start, new_sel_end, spc;
328 + int i, ps, pe, multiplier;
330 + struct kbd_struct *kbd = kbd_table + fg_console;
332 poke_blanked_console();
336 sel_cons = vc_cons[fg_console].d;
339 + use_unicode = kbd && kbd->kbdmode == VC_UNICODE;
343 case TIOCL_SELCHAR: /* character-by-character selection */
345 sel_end = new_sel_end;
347 /* Allocate a new buffer before freeing the old one ... */
348 - bp = kmalloc((sel_end-sel_start)/2+1, GFP_KERNEL);
349 + multiplier = use_unicode ? 3 : 1; /* chars can take up to 3 bytes */
350 + bp = kmalloc((sel_end-sel_start)/2*multiplier+1, GFP_KERNEL);
352 printk(KERN_WARNING "selection: kmalloc() failed\n");
357 for (i = sel_start; i <= sel_end; i += 2) {
359 - if (!isspace(*bp++))
362 + bp += store_utf8(c, bp);
367 if (! ((i + 2) % vc->vc_size_row)) {
368 /* strip trailing blanks from line and add newline,
369 diff -ur linux-2.6.15-rc6.orig/include/linux/consolemap.h linux-2.6.15-rc6.my/include/linux/consolemap.h
370 --- linux-2.6.15-rc6.orig/include/linux/consolemap.h 2005-12-25 10:00:13.000000000 +0500
371 +++ linux-2.6.15-rc6.my/include/linux/consolemap.h 2005-12-25 10:01:22.000000000 +0500
376 -extern unsigned char inverse_translate(struct vc_data *conp, int glyph);
377 +extern u16 inverse_translate(struct vc_data *conp, int glyph, int use_unicode);
378 extern unsigned short *set_translate(int m, struct vc_data *vc);
379 extern int conv_uni_to_pc(struct vc_data *conp, long ucs);
380 +extern u32 conv_8bit_to_uni(unsigned char c);