Search

Using get_options to read a range of integer arguments from a function in linux kernel.

In the post , we saw how to use read integers using the get_option, if we want to read a range of integers we can use get_options.



Ref: Kernel API

To read the numbers that are passed,as it is a range we will use an array into which the numbers can be filled. The array will have to be declared with the appropriate size.

The array will be passed to get_options which will fill the array with the elements that belong the range that was passed as shown in the function below.



We can pass a range of integers seperated by a "-" , which will be used to fill the array with the elements.

The following is the full code that passes range of numbers to the getargs function shown above,which in turn prints out all the numbers in the range.



Save the file as readOptions.c and compile it using the following makefile.



Compile and insert the code using



To view the output, run the command dmesg.


No comments:

Post a Comment