0

I'm trying to change the keyboard driver in minix, my idea is store in a file all the characters that the used introduced in the keyboard.I declare a global FILE * fp and insert this piece of code in /usr/src/drivers/tty/keyboard.c

while (icount > 0) {
         scode = *itail++;      /* take one key scan code */
          if (itail == ibuf + KB_IN_BYTES) itail = ibuf;
          icount--;

          /* Function keys are being used for debug dumps. */
          if (func_key(scode)) continue;

           /* Perform make/break processing. */
           ch = make_break(scode);

           if (ch <= 0xFF) {
                  /* A normal character. */

                  fp = fopen("log.txt","a+");
                  fprint(fp,"%c",ch);
                  fclose(fp);

                   buf[0] = ch;
                   (void) in_process(tp, buf, 1);
          } else ...

then I run "make" in the directory and reboot but this does not work. I mean, the file is not created. Any idea?

  • "...does not work" is a little hazy. Please edit your question and add some additional information about what "does not work". Is it too slow? Doesn't write the keys to the file? Opens a gateway between the worlds through which ooze pestilential creatures of foulest evil? – Bob Jarvis - Слава Україні Jun 09 '16 at 18:45
  • If you are _truly_ modifying the keyboard _driver_ (ie. it's in the minux kernel), you won't be able to use `stdio.h` style streams [unless minux is different from every other unix kernel I've ever used]. You'll have to use the internal minix functions for I/O. And, doing `open, write one char, close` is _extremely_ inefficient [and can lead to complications]. Open the log file _once_ – Craig Estey Jun 09 '16 at 18:51
  • But I think that minix drivers belongs to user space, and in this minix tutorial uses the stdlib functions... http://wiki.minix3.org/doku.php?id=developersguide:driverprogramming – M. Fidalgo Jun 09 '16 at 19:02

1 Answers1

0

This won't work. The keyboard driver is inside the TTY "driver", a service which is in charge of the console. FS/VFS will transmit the I/O requests concerning that console to TTY. fopen, fprint, and fclose in your code are ways to perform such requests. But VFS can only handle requests from "user" programs (and transmit them down to drivers); TTY is not a "user" program, and as such, is not allowed to perform I/O requests.

AntoineL
  • 888
  • 4
  • 25
  • 1
    Yet, OP runs "make" and somehow thinks it built. – Kaz Jun 12 '16 at 19:09
  • @AntonieL I´m sorry but you're wrong, the program works fine, the problem was that I was running "make" in other directory... – M. Fidalgo Jun 14 '16 at 19:56
  • OK, I am wrong since I misunderstood that the program you wrote was not `TTY` (which source is in `/usr/src/drivers/tty/keyboard.c`), and your unidentified program is fine. Sorry for the time lost. Also, you better abstain to rebuild the kernel. – AntoineL Jun 15 '16 at 07:38