1 | /* vi: set sw=4 ts=4: */
|
---|
2 | /*
|
---|
3 | * Mini dumpkmap implementation for busybox
|
---|
4 | *
|
---|
5 | * Copyright (C) Arne Bernin <arne@matrix.loopback.org>
|
---|
6 | *
|
---|
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
8 | *
|
---|
9 | */
|
---|
10 | /* no options, no getopt */
|
---|
11 |
|
---|
12 | #include "libbb.h"
|
---|
13 |
|
---|
14 | /* From <linux/kd.h> */
|
---|
15 | struct kbentry {
|
---|
16 | unsigned char kb_table;
|
---|
17 | unsigned char kb_index;
|
---|
18 | unsigned short kb_value;
|
---|
19 | };
|
---|
20 | #define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
---|
21 |
|
---|
22 | /* From <linux/keyboard.h> */
|
---|
23 | #define NR_KEYS 128
|
---|
24 | #define MAX_NR_KEYMAPS 256
|
---|
25 |
|
---|
26 | int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
27 | int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
|
---|
28 | {
|
---|
29 | struct kbentry ke;
|
---|
30 | int i, j, fd;
|
---|
31 | RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
|
---|
32 |
|
---|
33 | /* When user accidentally runs "dumpkmap FILE"
|
---|
34 | * instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
|
---|
35 | * Let's prevent it: */
|
---|
36 | if (argv[1])
|
---|
37 | bb_show_usage();
|
---|
38 | /* bb_warn_ignoring_args(argv[1]);*/
|
---|
39 |
|
---|
40 | fd = get_console_fd_or_die();
|
---|
41 |
|
---|
42 | write(STDOUT_FILENO, "bkeymap", 7);
|
---|
43 |
|
---|
44 | /* Here we want to set everything to 0 except for indexes:
|
---|
45 | * [0-2] [4-6] [8-10] [12] */
|
---|
46 | memset(flags, 0x00, MAX_NR_KEYMAPS);
|
---|
47 | memset(flags, 0x01, 13);
|
---|
48 | flags[3] = flags[7] = flags[11] = 0;
|
---|
49 |
|
---|
50 | /* dump flags */
|
---|
51 | write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
|
---|
52 |
|
---|
53 | for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
---|
54 | if (flags[i] == 1) {
|
---|
55 | for (j = 0; j < NR_KEYS; j++) {
|
---|
56 | ke.kb_index = j;
|
---|
57 | ke.kb_table = i;
|
---|
58 | if (!ioctl_or_perror(fd, KDGKBENT, &ke,
|
---|
59 | "ioctl failed with %s, %s, %p",
|
---|
60 | (char *)&ke.kb_index,
|
---|
61 | (char *)&ke.kb_table,
|
---|
62 | &ke.kb_value)
|
---|
63 | ) {
|
---|
64 | write(STDOUT_FILENO, (void*)&ke.kb_value, 2);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 | if (ENABLE_FEATURE_CLEAN_UP) {
|
---|
70 | close(fd);
|
---|
71 | RELEASE_CONFIG_BUFFER(flags);
|
---|
72 | }
|
---|
73 | return EXIT_SUCCESS;
|
---|
74 | }
|
---|