Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/console-tools/dumpkmap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1411 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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 tarball for details.
8 *
9 */
10
11 #include "busybox.h"
12
13 /* From <linux/kd.h> */
14 struct kbentry {
15 unsigned char kb_table;
16 unsigned char kb_index;
17 unsigned short kb_value;
18 };
19 #define KDGKBENT 0x4B46 /* gets one entry in translation table */
20
21 /* From <linux/keyboard.h> */
22 #define NR_KEYS 128
23 #define MAX_NR_KEYMAPS 256
24
25 int 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
31 if (argc >= 2 && *argv[1] == '-')
32 bb_show_usage();
33
34 fd = xopen(CURRENT_VC, O_RDWR);
35
36 write(1, magic, 7);
37
38 /* Here we want to set everything to 0 except for indexes:
39 * [0-2] [4-6] [8-10] [12] */
40 memset(flags, 0x00, MAX_NR_KEYMAPS);
41 memset(flags, 0x01, 13);
42 flags[3] = flags[7] = flags[11] = 0;
43
44 /* dump flags */
45 write(1, flags, MAX_NR_KEYMAPS);
46
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) {
53 bb_perror_msg("ioctl failed with %s, %s, %p",
54 (char *)&ke.kb_index,
55 (char *)&ke.kb_table,
56 &ke.kb_value);
57 } else {
58 write(1, (void*)&ke.kb_value, 2);
59 }
60 }
61 }
62 }
63 close(fd);
64 return EXIT_SUCCESS;
65 }