The best way to arrange the editor number is to use dynamic allocation by default, and leave the option permission to specify the editor number during loading, or even during compilation. scull works in this way; it uses a global variable scull_major to hold the selected number (there is also a scull_minor number ). this variable is initialized to scull_major, which is defined in scull. h. the default value of scull_major in the released source code is 0, which means "Dynamic Allocation ". you can accept the default value or select a special editor number, modify the macro definition before compilation, or specify a value for scull_major on the insmod command line. finally, by using the scull_load script, you can pass parameters to insmod in the command line of scull_load.
This is the code that we use in scull's source code to obtain the editor ID:
If (scull_major) {Dev = mkdev (scull_major, scull_minor); Result = equals (Dev, scull_nr_devs, "scull");} else {result = equals (& Dev, scull_minor, scull_nr_devs, "scull"); scull_major = major (Dev);} If (result <0) {printk (kern_warning "scull: Can't Get Major % d \ n ", scull_major); return result ;}
Almost all examples used in this book use similar code to distribute their editor numbers.