aboutsummaryrefslogtreecommitdiffstats
path: root/tasks/12/readme
blob: e18cb3cb61869209c0a33f1186969357014f5900 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Task 12
=======

Nice job with the driver patch.  That took some work in finding the
proper place to modify, and demonstrates a great skill in tracking down
issues when you can't get a specific piece of hardware working.

Now let's step back from drivers (they are boring things), and focus on
the kernel core.  To do that, we need to go way back to the basics --
stuff you would learn in your "intro to data structures" class, if you
happened to take one.

Yes, I'm talking about linked lists.

The kernel has a unique way of creating and handling linked lists, that
is quite different than the "textbook" way of doing so.  But, it turns
out to be faster, and simpler, than a "textbook" would describe, so
that's a good thing.

For this task, write a kernel module, based on your cleaned up one from
task 04, that does the following:

  - You have a structure that has 3 fields:

      char  name[20];
      int   id;
      bool  busy;

    name this structure "identity".

  - Your module has a static variable that points to a list of these
    "identity" structures.

  - Write a function that looks like:

      int identity_create(char *name, int id)

    that creates the structure "identity", copies in the 'name' and 'id'
    fields and sets 'busy' to false.  Proper error checking for out of
    memory issues is required.  Return 0 if everything went ok; an error
    value if something went wrong.

  - Write a function that looks like:

      struct identity *identity_find(int id);

    that takes a given id, iterates over the list of all ids, and
    returns the proper 'struct identity' associated with it.  If the
    identity is not found, return NULL.

  - Write a function that looks like:

      void identity_destroy(int id);

    that given an id, finds the proper 'struct identity' and removes it
    from the system.

  - Your module_init() function will look much like the following:

      struct identity *temp;

      identity_create("Alice", 1);
      identity_create("Bob", 2);
      identity_create("Dave", 3);
      identity_create("Gena", 10);

      temp = identity_find(3);
      pr_debug("id 3 = %s\n", temp->name);

      temp = identity_find(42);
      if (temp == NULL)
              pr_debug("id 42 not found\n");

      identity_destroy(2);
      identity_destroy(1);
      identity_destroy(10);
      identity_destroy(42);
      identity_destroy(3);

   Bonus points for properly checking return values of the above
   functions.