3
0

dumpkmap.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /* no options, no getopt */
  11. #include "libbb.h"
  12. /* From <linux/kd.h> */
  13. struct kbentry {
  14. unsigned char kb_table;
  15. unsigned char kb_index;
  16. unsigned short kb_value;
  17. };
  18. #define KDGKBENT 0x4B46 /* gets one entry in translation table */
  19. /* From <linux/keyboard.h> */
  20. #define NR_KEYS 128
  21. #define MAX_NR_KEYMAPS 256
  22. int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  23. int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  24. {
  25. struct kbentry ke;
  26. int i, j, fd;
  27. RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
  28. /* bb_warn_ignoring_args(argc>=2);*/
  29. fd = get_console_fd_or_die();
  30. write(STDOUT_FILENO, "bkeymap", 7);
  31. /* Here we want to set everything to 0 except for indexes:
  32. * [0-2] [4-6] [8-10] [12] */
  33. memset(flags, 0x00, MAX_NR_KEYMAPS);
  34. memset(flags, 0x01, 13);
  35. flags[3] = flags[7] = flags[11] = 0;
  36. /* dump flags */
  37. write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS);
  38. for (i = 0; i < MAX_NR_KEYMAPS; i++) {
  39. if (flags[i] == 1) {
  40. for (j = 0; j < NR_KEYS; j++) {
  41. ke.kb_index = j;
  42. ke.kb_table = i;
  43. if (!ioctl_or_perror(fd, KDGKBENT, &ke,
  44. "ioctl failed with %s, %s, %p",
  45. (char *)&ke.kb_index,
  46. (char *)&ke.kb_table,
  47. &ke.kb_value)
  48. ) {
  49. write(STDOUT_FILENO, (void*)&ke.kb_value, 2);
  50. }
  51. }
  52. }
  53. }
  54. if (ENABLE_FEATURE_CLEAN_UP) {
  55. close(fd);
  56. RELEASE_CONFIG_BUFFER(flags);
  57. }
  58. return EXIT_SUCCESS;
  59. }