Чтение онлайн

на главную - закладки

Жанры

Энциклопедия разработчика модулей ядра Linux

Померанц Ори

Шрифт:

* called so far */

static int TimerIntrpt = 0;

/* This is used by cleanup, to prevent the module from

* being unloaded while intrpt_routine is still in

* the task queue */

static struct wait_queue *WaitQ = NULL;

static void intrpt_routine(void *);

/* The task queue structure for this task, from tqueue.h */

static struct tq_struct Task = {

 NULL, /* Next item in list - queue_task will do

* this for us */

 0, /* A flag meaning we haven't been inserted

* into a task queue yet */

 intrpt_routine, /* The function to run */

 NULL /* The void* parameter for that function */

};

/* This function will be called on every timer

* interrupt. Notice the void* pointer - task functions

* can be used for more than one purpose, each time

* getting a different parameter. */

static void intrpt_routine(void *irrelevant) {

 /* Increment the counter */

 TimerIntrpt++;

 /* If cleanup wants us to die */

 if (WaitQ != NULL) wake_up(&WaitQ);

 /* Now cleanup_module can return */

 else queue_task(&Task, &tq_timer);

 /* Put ourselves back in the task queue */

}

/* Put data into the proc fs file. */

int procfile_read(char *buffer, char **buffer_location, off_t offset, int buffer_length, int zero) {

 int len; /* The number of bytes actually used */

 /* This is static so it will still be in memory

 * when we leave this function */

 static char my_buffer[80];

 static int count = 1;

 /* We give all of our information in one go, so if

 * the anybody asks us if we have more information

 * the answer should always be no. */

 if (offset > 0) return 0;

 /* Fill the buffer and get its length */

 len = sprintf(my_buffer, "Timer was called %d times so far\n", TimerIntrpt);

 count++;

 /* Tell the function which called us where the buffer is */

 *buffer_location = my_buffer;

 /* Return the length */

 return len;

}

struct proc_dir_entry Our_Proc_File = {

 0, /* Inode number - ignore, it will be filled by

* proc_register_dynamic */

 5, /* Length of the file name */

 "sched", /* The file name */

 S_IFREG | S_IRUGO,

 /* File mode - this is a regular file which can

* be read by its owner, its group, and everybody else */

 1, /* Number of links (directories where

* the file is referenced) */

 0, 0, /* The uid and gid for the file - we give it to root */

 80, /* The size of the file reported by ls. */

 NULL, /* functions which can be done on the

* inode (linking, removing, etc.) - we don't

* support any. */

 procfile_read,

 /* The read function for this file, the function called

* when somebody tries to read something from it. */

 NULL

 /* We could have here a function to fill the

* file's inode, to enable us to play with

* permissions, ownership, etc. */

};

/* Initialize the module - register the proc file */

int init_module {

 /* Put the task in the tq_timer task queue, so it

 * will be executed at next timer interrupt */

 queue_task(&Task, &tq_timer);

 /* Success if proc_register_dynamic is a success,

 * failure otherwise */

#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0)

 return proc_register(&proc_root, &Our_Proc_File);

#else

 return proc_register_dynamic(&proc_root, &Our_Proc_File);

#endif

}

/* Cleanup */

void cleanup_module {

 /* Unregister our /proc file */

 proc_unregister(&proc_root, Our_Proc_File.low_ino);

 /* Sleep until intrpt_routine is called one last

 * time. This is necessary, because otherwise we'll

 * deallocate the memory holding intrpt_routine and

Поделиться:
Популярные книги

Адвокат Империи 3

Карелин Сергей Витальевич
3. Адвокат империи
Фантастика:
городское фэнтези
попаданцы
аниме
фэнтези
фантастика: прочее
5.00
рейтинг книги
Адвокат Империи 3

Кротовский, может, хватит?

Парсиев Дмитрий
3. РОС: Изнанка Империи
Фантастика:
попаданцы
альтернативная история
аниме
7.50
рейтинг книги
Кротовский, может, хватит?

Дурная жена неверного дракона

Ганова Алиса
Любовные романы:
любовно-фантастические романы
5.00
рейтинг книги
Дурная жена неверного дракона

Вонгозеро

Вагнер Яна
1. Вонгозеро
Детективы:
триллеры
9.19
рейтинг книги
Вонгозеро

Ведьма Вильхельма

Шёпот Светлана
Любовные романы:
любовно-фантастические романы
8.67
рейтинг книги
Ведьма Вильхельма

Папина дочка

Рам Янка
4. Самбисты
Любовные романы:
современные любовные романы
5.00
рейтинг книги
Папина дочка

Законы Рода. Том 6

Flow Ascold
6. Граф Берестьев
Фантастика:
юмористическое фэнтези
аниме
5.00
рейтинг книги
Законы Рода. Том 6

Как я строил магическую империю 7

Зубов Константин
7. Как я строил магическую империю
Фантастика:
попаданцы
постапокалипсис
аниме
фантастика: прочее
5.00
рейтинг книги
Как я строил магическую империю 7

Лучший из худший 3

Дашко Дмитрий
3. Лучший из худших
Фантастика:
городское фэнтези
попаданцы
аниме
6.00
рейтинг книги
Лучший из худший 3

Штурмовик из будущего 3

Политов Дмитрий Валерьевич
3. Небо в огне
Фантастика:
попаданцы
альтернативная история
5.00
рейтинг книги
Штурмовик из будущего 3

Последний попаданец 2

Зубов Константин
2. Последний попаданец
Фантастика:
юмористическая фантастика
попаданцы
рпг
7.50
рейтинг книги
Последний попаданец 2

Идеальный мир для Лекаря 14

Сапфир Олег
14. Лекарь
Фантастика:
юмористическое фэнтези
попаданцы
аниме
5.00
рейтинг книги
Идеальный мир для Лекаря 14

Безумный Макс. Поручик Империи

Ланцов Михаил Алексеевич
1. Безумный Макс
Фантастика:
героическая фантастика
альтернативная история
7.64
рейтинг книги
Безумный Макс. Поручик Империи

Вдова на выданье

Шах Ольга
Любовные романы:
любовно-фантастические романы
5.00
рейтинг книги
Вдова на выданье