blob: 7c6633ae8435aa8148d3c184553ca00827690437 [file] [log] [blame]
Eric Andersen61dc0572000-07-11 17:29:36 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Mini dumpkmap implementation for busybox
4 *
5 * Copyright (C) Arne Bernin <arne@matrix.loopback.org>
6 *
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersen61dc0572000-07-11 17:29:36 +00008 *
9 */
10
Eric Andersencbe31da2001-02-20 06:14:08 +000011#include "busybox.h"
Eric Andersen61dc0572000-07-11 17:29:36 +000012
13/* From <linux/kd.h> */
14struct kbentry {
15 unsigned char kb_table;
16 unsigned char kb_index;
17 unsigned short kb_value;
18};
Mike Frysinger7e64db22005-07-31 22:09:33 +000019#define KDGKBENT 0x4B46 /* gets one entry in translation table */
Eric Andersen61dc0572000-07-11 17:29:36 +000020
21/* From <linux/keyboard.h> */
Mike Frysinger7e64db22005-07-31 22:09:33 +000022#define NR_KEYS 128
23#define MAX_NR_KEYMAPS 256
Eric Andersen61dc0572000-07-11 17:29:36 +000024
Eric Andersen61dc0572000-07-11 17:29:36 +000025int dumpkmap_main(int argc, char **argv)
26{
27 struct kbentry ke;
28 int i, j, fd;
29 char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
30
Mike Frysingerf28c7ec2005-07-30 09:24:49 +000031 if (argc >= 2 && *argv[1] == '-')
Manuel Novoa III cad53642003-03-19 09:13:01 +000032 bb_show_usage();
Eric Andersen61dc0572000-07-11 17:29:36 +000033
Rob Landleyd921b2e2006-08-03 15:41:12 +000034 fd = xopen(CURRENT_VC, O_RDWR);
Eric Andersen61dc0572000-07-11 17:29:36 +000035
36 write(1, magic, 7);
37
Mike Frysingere11ff712005-07-31 22:06:38 +000038 /* Here we want to set everything to 0 except for indexes:
39 * [0-2] [4-6] [8-10] [12] */
Mike Frysinger08c20362005-07-31 20:51:58 +000040 memset(flags, 0x00, MAX_NR_KEYMAPS);
Mike Frysingere11ff712005-07-31 22:06:38 +000041 memset(flags, 0x01, 13);
42 flags[3] = flags[7] = flags[11] = 0;
Eric Andersenc7bda1c2004-03-15 08:29:22 +000043
Eric Andersen61dc0572000-07-11 17:29:36 +000044 /* dump flags */
Mike Frysinger08c20362005-07-31 20:51:58 +000045 write(1, flags, MAX_NR_KEYMAPS);
Eric Andersen61dc0572000-07-11 17:29:36 +000046
47 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
48 if (flags[i] == 1) {
49 for (j = 0; j < NR_KEYS; j++) {
50 ke.kb_index = j;
51 ke.kb_table = i;
52 if (ioctl(fd, KDGKBENT, &ke) < 0) {
Mike Frysinger198ea3c2005-07-30 09:29:10 +000053 bb_perror_msg("ioctl failed with %s, %s, %p",
Mike Frysingerf28c7ec2005-07-30 09:24:49 +000054 (char *)&ke.kb_index,
55 (char *)&ke.kb_table,
Mike Frysinger198ea3c2005-07-30 09:29:10 +000056 &ke.kb_value);
Mike Frysingerf28c7ec2005-07-30 09:24:49 +000057 } else {
58 write(1, (void*)&ke.kb_value, 2);
59 }
Eric Andersen61dc0572000-07-11 17:29:36 +000060 }
61 }
62 }
63 close(fd);
Matt Kraai3e856ce2000-12-01 02:55:13 +000064 return EXIT_SUCCESS;
Eric Andersen61dc0572000-07-11 17:29:36 +000065}