dumpkmap.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "busybox.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)
  22. {
  23. struct kbentry ke;
  24. int i, j, fd;
  25. char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
  26. if (argc >= 2 && *argv[1] == '-')
  27. bb_show_usage();
  28. fd = xopen(CURRENT_VC, O_RDWR);
  29. write(1, magic, 7);
  30. /* Here we want to set everything to 0 except for indexes:
  31. * [0-2] [4-6] [8-10] [12] */
  32. memset(flags, 0x00, MAX_NR_KEYMAPS);
  33. memset(flags, 0x01, 13);
  34. flags[3] = flags[7] = flags[11] = 0;
  35. /* dump flags */
  36. write(1, flags, MAX_NR_KEYMAPS);
  37. for (i = 0; i < MAX_NR_KEYMAPS; i++) {
  38. if (flags[i] == 1) {
  39. for (j = 0; j < NR_KEYS; j++) {
  40. ke.kb_index = j;
  41. ke.kb_table = i;
  42. if (ioctl(fd, KDGKBENT, &ke) < 0) {
  43. bb_perror_msg("ioctl failed with %s, %s, %p",
  44. (char *)&ke.kb_index,
  45. (char *)&ke.kb_table,
  46. &ke.kb_value);
  47. } else {
  48. write(1, (void*)&ke.kb_value, 2);
  49. }
  50. }
  51. }
  52. }
  53. close(fd);
  54. return EXIT_SUCCESS;
  55. }