loadkmap.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini loadkmap implementation for busybox
  4. *
  5. * Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. *
  9. */
  10. #include "libbb.h"
  11. #define BINARY_KEYMAP_MAGIC "bkeymap"
  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. /* sets one entry in translation table */
  19. #define KDSKBENT 0x4B47
  20. /* From <linux/keyboard.h> */
  21. #define NR_KEYS 128
  22. #define MAX_NR_KEYMAPS 256
  23. int loadkmap_main(int argc, char **argv);
  24. int loadkmap_main(int argc, char **argv)
  25. {
  26. struct kbentry ke;
  27. int i, j, fd;
  28. uint16_t ibuff[NR_KEYS];
  29. char flags[MAX_NR_KEYMAPS];
  30. char buff[7];
  31. if (argc != 1)
  32. bb_show_usage();
  33. fd = xopen(CURRENT_VC, O_RDWR);
  34. xread(0, buff, 7);
  35. if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
  36. bb_error_msg_and_die("this is not a valid binary keymap");
  37. xread(0, flags, MAX_NR_KEYMAPS);
  38. for (i = 0; i < MAX_NR_KEYMAPS; i++) {
  39. if (flags[i] == 1) {
  40. xread(0, ibuff, NR_KEYS * sizeof(uint16_t));
  41. for (j = 0; j < NR_KEYS; j++) {
  42. ke.kb_index = j;
  43. ke.kb_table = i;
  44. ke.kb_value = ibuff[j];
  45. ioctl(fd, KDSKBENT, &ke);
  46. }
  47. }
  48. }
  49. if (ENABLE_FEATURE_CLEAN_UP) close(fd);
  50. return 0;
  51. }