Mastermind Character Device Module for System Programming Course
In order to compile the Mastermind module, first run the make file and wait until it finishes compiling.
$ make
Before continuing, it's better to become root.
$ sudo su
After compiling the module, insert the module into kernel.
$ insmod mastermind.ko mmind_number="4283"
Assuming major number is 239, create a device node:
$ mknod /dev/mastermind c 239 0
Now, we can test the game:
$ echo "1234" > /dev/mastermind
$ cat /dev/mastermind
1234 1+ 2- 0001
$ echo "4513" > /dev/mastermind
$ cat /dev/mastermind
1234 1+ 2- 0001
4531 1+ 1- 0002
In order to test ioctl commands, first compile test code.
$ gcc mmind_ioctl.c -o test
Then run the output file with arguments depending on the ioctl command to test. For MMIND_REMAINING command:
$ ./test 0
For MMIND_NEWGAME command, assuming new secret number is 1509:
$ ./test 1 1509
For MMIND_ENDGAME command:
$ ./test 2
$ rmmod mastermind
$ rm /dev/mastermind