Вход/Регистрация
Энциклопедия разработчика модулей ядра Linux
вернуться

Померанц Ори

Шрифт:

#endif

/* The module's file functions ********************** */

/* Here we keep the last message received, to prove

* that we can process our input */

#define MESSAGE_LENGTH 80

static char Message[MESSAGE_LENGTH];

/* Since we use the file operations struct, we can't use

* the special proc output provisions - we have to use

* a standard read function, which is this function */

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

static size_t module_output(

 struct file *file, /* The file read */

 char *buf, /* The buffer to put data to (in the user segment) */

 size_t len, /* The length of the buffer */

 loff_t *offset) /* Offset in the file - ignore */

#else

 static int module_output(

 struct inode *inode, /* The inode read */

 struct file *file, /* The file read */

 char *buf, /* The buffer to put data to (in the user segment) */

 int len) /* The length of the buffer */

#endif

{

 static int finished = 0;

 int i;

 char message[MESSAGE_LENGTH+30];

 /* Return 0 to signify end of file - that we have

 * nothing more to say at this point. */

 if (finished) {

finished = 0;

return 0;

 }

 /* If you don't understand this by now, you're

 * hopeless as a kernel programmer. */

 sprintf(message, "Last input:%s\n", Message);

 for(i=0; i<len && message[i]; i++) put_user(message[i], buf+i);

 finished = 1;

 return i; /* Return the number of bytes "read" */

}

/* This function receives input from the user when

* the user writes to the /proc file. */

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

static ssize_t module_input(

 struct file *file, /* The file itself */

 const char *buf, /* The buffer with input */

 size_t length, /* The buffer's length */

 loff_t *offset) /* offset to file - ignore */

#else

 static int module_input(

 struct inode *inode, /* The file's inode */

 struct file *file, /* The file itself */

 const char *buf, /* The buffer with the input */

 int length) /* The buffer's length */

#endif

{

 int i;

 /* Put the input into Message, where module_output

 * will later be able to use it */

 for(i=0; i<MESSAGE_LENGTH-1 && i<length; i++)

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

 get_user(Message[i], buf+i);

#else

 Message[i] = get_user(buf+i);

#endif

 /* we want a standard, zero terminated string */

 Message[i] = '\0';

 /* We need to return the number of input characters used */

 return i;

}

/* 1 if the file is currently open by somebody */

int Already_Open = 0;

 /* Queue of processes who want our file */

static struct wait_queue *WaitQ = NULL;

/* Called when the /proc file is opened */

static int module_open(struct inode *inode, struct file *file) {

 /* If the file's flags include O_NONBLOCK, it means

  • Читать дальше
  • 1
  • ...
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • ...

Ебукер (ebooker) – онлайн-библиотека на русском языке. Книги доступны онлайн, без утомительной регистрации. Огромный выбор и удобный дизайн, позволяющий читать без проблем. Добавляйте сайт в закладки! Все произведения загружаются пользователями: если считаете, что ваши авторские права нарушены – используйте форму обратной связи.

Полезные ссылки

  • Моя полка

Контакты

  • chitat.ebooker@gmail.com

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