To print message to a tty.
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/tty.h>
#include <linux/version.h>
static void print_string(char *str)
{
struct tty_struct *my_tty;
/*
* tty struct went into signal struct in 2.6.6
*/
#if(LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,5))
/*
* The tty for the current task
*/
my_tty=current->tty;
#else
/*
* The tty for the current task, for 2.6.6+ kernels
*/
my_tty=current->signal->tty;
#endif
/*
* If my_tty is NULL, the current task has no tty you can print to
* (ie, if it's a daemon). Ifso,there'snothingwecando.
*/
if (my_tty != NULL){
/*
* my_tty->driveris a struct which holds the tty's functions,
* one of which (write) is used to write strings to the tty.
* It can be used to take a string either from the user's or
* kernel's memory segment.
*
* The function's 1st parameter is the tty to write to,
* because the same function would normally be used for all
* tty's of a certain type. The 2nd parameter controls whether
* the function receives a string from kernel memory (false, 0)
* or from user memory (true, non zero). The 3rd parameter is
* a pointer to a string. The 4th parameter is the length of
* the string.
*/
((my_tty->driver)->write)(my_tty, /*The tty itself*/
0, /*Don't take the string from user space */
str, /*String */
strlen(str)); /*Length*/
/*
* ttys were originally hardware devices, which (usually)
* strictly followed the ASCII standard. InASCII,tomoveto
* a new line you need two characters, a carriage return and a
* line feed. On Unix, the ASCII line feed is used for both
* purposes - so we can't just use /n, because it wouldn't have
* a carriage return and the next line will start at the
* column right after the line feed.
*
* This is why text files are different between Unix and
* MS Windows. In CP/Mand derivatives,like MS-DOS and
* MS Windows, the ASCII standard was strictly adhered to,
* and therefore a newline requirs both a LF and a CR.
*/
((my_tty->driver)->write)(my_tty,0,"/015/012",2);
}
}
static int __init print_string_init(void)
{
print_string("The module has been inserted. Hello world!");
return 0;
}
static void __exit print_string_exit(void)
{
print_string("The module has been removed. Fare well world!");
}
module_init(print_string_init);
module_exit(print_string_exit);
The great earth in Shichuang province almost caught the eyes of all country people.
Donation from all leveles, from oversea, from other countries, is not stoped.
It is said that about three million people died from this great earth. Many teacher and
students died suddenly in this earth. The great earth is not any forecast before and is
too sudden to people lost their home, lost their family, lost their relatives.
Luckly, the hope is always kept in their mind.