Здравствуйте. У меня такая проблемма. Написал драйвер для своего устройства. Писал в ядре 2.4.
Сейчас возникла необходимость скомпилировать в ядре 2.6, но я не могу понять как в 2.6 работает механизм учета использования драйвера. В 2.4 все просто MOD_DEC_USE_COUNT, MOD_INC_USE_COUNT, MOD_IN_USE. В ядре 2.6 этого нет. Скажу сразу, что автоматически (без моего вмешательства), счетчик остается равным 0 при открытии файла устройства, и ядро даже позволяет выгрузить используемый драйвер, что приводит к полному зависанию системы.
Зарание Спасибо.
Счетчик использования модуля в ядре 2.6
Модератор: Модераторы разделов
Re: Счетчик использования модуля в ядре 2.6
я очень далек от писания ядрёных модулей, но вот что я нашел в The Linux Kernel Module Programming Guide
если я все правильно понял, то это как раз то, что тебе нужно.Normally, when you don't want to allow something, you return an error code (a negative number) from the function which is supposed to do it. With cleanup_module that's impossible because it's a void function. However, there's a counter which keeps track of how many processes are using your module. You can see what it's value is by looking at the 3rd field of /proc/modules. If this number isn't zero, rmmod will fail. Note that you don't have to check the counter from within cleanup_module because the check will be performed for you by the system call sys_delete_module, defined in linux/module.c. You shouldn't use this counter directly, but there are functions defined in linux/module.h which let you increase, decrease and display this counter:
* try_module_get(THIS_MODULE): Increment the use count.
* module_put(THIS_MODULE): Decrement the use count.
It's important to keep the counter accurate; if you ever do lose track of the correct usage count, you'll never be able to unload the module; it's now reboot time, boys and girls. This is bound to happen to you sooner or later during a module's development.
слава роботам!