CIS-4020 Homework #2: The seq_file API

Due: Thursday, September 8, 2016

The reading for this week is the same as last week: In the text you should review/skim the introductory chapters 1 and 2 to familiarize yourself with the material they contain. Our first topic is system calls, covered in chapter 5.

This assignment asks you to study in more depth how the seq_file API works by reading the kernel source of some supporting seq_file functions. A sketch of how the seq_file API can be used by a module author is in You have worked (or will be working) with this skeleton in Lab #2.

  1. Using cscope find the definition of function seq_open. In which file is it located? Look at the bottom of the console when the function is first opened, or use the 1^G command in Vim. Give your answer as a path relative to the top of the kernel source tree. This is a convention we will follow when talking about file names in the kernel source. On what line does the function start? Use the ':set number' command in Vim to display line numbers.

  2. In your own words explain approximately what that function is doing. The important part is the section at the top of the function. You do not need to understand every nuance of the code, but hopefully you can glean, with study, the general idea of what is happening there.

    Note that the sizeof operator can take an expression in which case it considers only the type of that expression. The expression is not evaluated. For example, sizeof(5+2) is 4 because the expression 5+2 has type int and integers are four bytes. The expression 5+2 is never actually evaluated.

  3. On line 92 what is the effect of the line file->f_mode &= ~FMODE_PWRITE? Here I'm asking about the how the bit manipulation operators are working. You might want to look up the value of FMODE_PWRITE.

  4. Using cscope find the definition of function seq_read. On line 190 you will see a use of 'unlikely'. What does that mean? See Chapter 2 of the text.

  5. The main part of seq_read is the while loop starting on line 230. Note that seq_read is called when an application tries to read the proc file (assuming the module author set it up that way). In your own words explain approximately what that loop is doing and how it relates to the code in the module. Note that an expression such as m->op->start(m, &pos) invokes the 'start' method in the module (one of the seq_file operations).

Last Revised: 2016-08-23
© Copyright 2016 by Peter C. Chapin <>