1
00:00:00,000 --> 00:00:05,006
(upbeat music)

2
00:00:05,006 --> 00:00:09,008
- [Instructor] Now you get to write kernel code.

3
00:00:09,008 --> 00:00:11,001
Don't do anything crazy, right?

4
00:00:11,001 --> 00:00:13,002
This is running in your kernel.

5
00:00:13,002 --> 00:00:14,008
Bad things could happen.

6
00:00:14,008 --> 00:00:16,009
You could wipe out your file system.

7
00:00:16,009 --> 00:00:20,007
Unlikely, but almost any bad thing could happen.

8
00:00:20,007 --> 00:00:21,006
Might even be possible

9
00:00:21,006 --> 00:00:24,003
to set your computer on fire. (chuckles)

10
00:00:24,003 --> 00:00:26,004
So of course, be careful.

11
00:00:26,004 --> 00:00:28,006
Do this, you know, like on a VM

12
00:00:28,006 --> 00:00:32,007
that you can easily restart, or something.

13
00:00:32,007 --> 00:00:36,002
So we're asking you to write a kernel module file.

14
00:00:36,002 --> 00:00:38,004
Call it lab.c.

15
00:00:38,004 --> 00:00:41,005
You got to include the init and cleanup functions.

16
00:00:41,005 --> 00:00:43,001
Got to include the header files,

17
00:00:43,001 --> 00:00:45,009
got to have prototypes for your functions.

18
00:00:45,009 --> 00:00:48,006
Do a GPL license.

19
00:00:48,006 --> 00:00:52,005
Do the register macros for your init and cleanup functions.

20
00:00:52,005 --> 00:00:55,004
Put a printk in the init and cleanup function.

21
00:00:55,004 --> 00:00:57,003
Pretty much just like we did in the example.

22
00:00:57,003 --> 00:00:58,008
You can pretty much type in the example,

23
00:00:58,008 --> 00:01:02,003
but call it lab.c instead of simple module.

24
00:01:02,003 --> 00:01:08,001
Then create a Makefile, one line in there, for your lab.o.

25
00:01:08,001 --> 00:01:12,005
Do the make command to build your module,

26
00:01:12,005 --> 00:01:16,008
get your ko, insert it, remove it,

27
00:01:16,008 --> 00:01:21,004
and then check the output showed up with dmesg.

28
00:01:21,004 --> 00:01:23,002
Cool.

29
00:01:23,002 --> 00:01:26,004
Now, edit your module,

30
00:01:26,004 --> 00:01:29,008
and instead of returning 0 return -1,

31
00:01:29,008 --> 00:01:32,009
rebuild it, insmod it,

32
00:01:32,009 --> 00:01:34,007
check the dmesg output and stuff.

33
00:01:34,007 --> 00:01:36,004
What happens when you return -1

34
00:01:36,004 --> 00:01:38,006
is what we're wanting you to look at.

35
00:01:38,006 --> 00:01:41,000
All right, be careful. Good luck.

