dumpkmap.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "libbb.h"
  11. /* From <linux/kd.h> */
  12. struct kbentry {
  13. unsigned char kb_table;
  14. unsigned char kb_index;
  15. unsigned short kb_value;
  16. };
  17. #define KDGKBENT 0x4B46 /* gets one entry in translation table */
  18. /* From <linux/keyboard.h> */
  19. #define NR_KEYS 128
  20. #define MAX_NR_KEYMAPS 256
  21. int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  22. int dumpkmap_main(int argc, char **argv)
  23. {
  24. struct kbentry ke;
  25. int i, j, fd;
  26. char flags[MAX_NR_KEYMAPS];
  27. if (argc >= 2 && argv[1][0] == '-')
  28. bb_show_usage();
  29. fd = xopen(CURRENT_VC, O_RDWR);
  30. write(1, "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(1, 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(1, (void*)&ke.kb_value, 2);
  50. }
  51. }
  52. }
  53. }
  54. close(fd);
  55. return EXIT_SUCCESS;
  56. }