ryao / datto_char

Kernel module for job interview with Datto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is a simple kernel module written to satisfy the requirements for a job
interview with Datto.

Beyond posting this on github, the requirements for this module are as follows:

1.      Write a character driver for the Linux kernel (your choice of Linux
        distribution and kernel version after 2.6.32).

2.      The driver should expose a single character device named
        /dev/datto_char.

3.      Driver should be able to accept a single character via IOCTL.

4.      Reading from the character device should output that character
        repeated indefinitely.

5.      If the driver has not been initialized with a character,it should
        instead return an EINVAL when reading from it.

This module was written on Gentoo Linux using Linux 4.1.3, but should build
against any recent kernel (Linux 2.6.26 and later) on any distribution with the
kernel toolchain, headers and build system installed. Here is a sample session:

	$ cd /path/to/datto_dev
	$ make
	make -C /lib/modules/4.1.3/build M=/home/richard/devel/datto_char modules
	make[1]: Entering directory '/usr/src/linux-4.1.3'
	  CC [M]  /home/richard/devel/datto_char/datto_char.o
	  Building modules, stage 2.
	  MODPOST 1 modules
	  CC      /home/richard/devel/datto_char/datto_char.mod.o
	  LD [M]  /home/richard/devel/datto_char/datto_char.ko
	make[1]: Leaving directory '/usr/src/linux-4.1.3'
	$ sudo insmod datto_dev.ko
	$ cat /dev/datto_char
	cat: /dev/datto_char: Invalid argument
	$ cd ioctl_cmd
	$ make ioctl_cmd
	cc -o ioctl_cmd ioctl_cmd.c
	$ ./ioctl_cmd a /dev/datto_dev
	$ cat /dev/datto/dev
	# Wall of text (you want to hit Ctrl+C)
	$ make clean
	rm ioctl_cmd
	$ cd ..
	$ sudo rmmod datto_char.ko
	$ make clean
	make -C /lib/modules/4.1.3/build M=/home/richard/devel/datto_char clean
	make[1]: Entering directory '/usr/src/linux-4.1.3'
	  CLEAN   /home/richard/devel/datto_char/.tmp_versions
	  CLEAN   /home/richard/devel/datto_char/Module.symvers
	make[1]: Leaving directory '/usr/src/linux-4.1.3'

About

Kernel module for job interview with Datto


Languages

Language:C 94.7%Language:Makefile 5.3%