2000-07-11 17:29:36 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Mini dumpkmap implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) Arne Bernin <arne@matrix.loopback.org>
|
|
|
|
*
|
2006-07-12 07:56:04 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2000-07-11 17:29:36 +00:00
|
|
|
*
|
|
|
|
*/
|
2008-05-19 08:18:50 +00:00
|
|
|
/* no options, no getopt */
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2000-07-11 17:29:36 +00:00
|
|
|
|
|
|
|
/* From <linux/kd.h> */
|
|
|
|
struct kbentry {
|
|
|
|
unsigned char kb_table;
|
|
|
|
unsigned char kb_index;
|
|
|
|
unsigned short kb_value;
|
|
|
|
};
|
2005-07-31 22:09:33 +00:00
|
|
|
#define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
2000-07-11 17:29:36 +00:00
|
|
|
|
|
|
|
/* From <linux/keyboard.h> */
|
2005-07-31 22:09:33 +00:00
|
|
|
#define NR_KEYS 128
|
|
|
|
#define MAX_NR_KEYMAPS 256
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
2000-07-11 17:29:36 +00:00
|
|
|
{
|
|
|
|
struct kbentry ke;
|
|
|
|
int i, j, fd;
|
2010-01-04 12:16:08 +00:00
|
|
|
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2010-01-04 12:16:08 +00:00
|
|
|
/* bb_warn_ignoring_args(argv[1]);*/
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2008-08-05 23:32:27 +00:00
|
|
|
fd = get_console_fd_or_die();
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2008-05-19 08:18:50 +00:00
|
|
|
write(STDOUT_FILENO, "bkeymap", 7);
|
2000-07-11 17:29:36 +00:00
|
|
|
|
2005-07-31 22:06:38 +00:00
|
|
|
/* Here we want to set everything to 0 except for indexes:
|
|
|
|
* [0-2] [4-6] [8-10] [12] */
|
2005-07-31 20:51:58 +00:00
|
|
|
memset(flags, 0x00, MAX_NR_KEYMAPS);
|
2005-07-31 22:06:38 +00:00
|
|
|
memset(flags, 0x01, 13);
|
|
|
|
flags[3] = flags[7] = flags[11] = 0;
|
2004-03-15 08:29:22 +00:00
|
|
|
|
2000-07-11 17:29:36 +00:00
|
|
|
/* dump flags */
|
2008-05-19 08:18:50 +00:00
|
|
|
write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
|
2000-07-11 17:29:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
|
|
|
if (flags[i] == 1) {
|
|
|
|
for (j = 0; j < NR_KEYS; j++) {
|
|
|
|
ke.kb_index = j;
|
|
|
|
ke.kb_table = i;
|
2007-07-14 22:07:14 +00:00
|
|
|
if (!ioctl_or_perror(fd, KDGKBENT, &ke,
|
|
|
|
"ioctl failed with %s, %s, %p",
|
2005-07-30 09:24:49 +00:00
|
|
|
(char *)&ke.kb_index,
|
|
|
|
(char *)&ke.kb_table,
|
2007-07-14 22:07:14 +00:00
|
|
|
&ke.kb_value)
|
|
|
|
) {
|
2008-05-19 08:18:50 +00:00
|
|
|
write(STDOUT_FILENO, (void*)&ke.kb_value, 2);
|
2005-07-30 09:24:49 +00:00
|
|
|
}
|
2000-07-11 17:29:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-19 08:18:50 +00:00
|
|
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
|
|
|
close(fd);
|
|
|
|
RELEASE_CONFIG_BUFFER(flags);
|
|
|
|
}
|
2000-12-01 02:55:13 +00:00
|
|
|
return EXIT_SUCCESS;
|
2000-07-11 17:29:36 +00:00
|
|
|
}
|