ÎÒÏÂÔØÁËÒ»¸ölinux-2.6.31.5µÄÄںˣ¬½øÐÐÁ˱àÒë
È»ºó¿ªÊ¼±àд×Ô¼ºµÄÐéÄâ×Ö·ûÉ豸Çý¶¯
/**
*rwbuf.h, driver for virtual char-device
*/
#define RWBUF_NAME "rwbuf" // É豸Îļþ /dev/rwbuf
#define RWBUF_DEV "/dev/rwbuf" // device path
#define RWBUF_MAJOR 60 // Ö÷É豸ºÅ
#define RWBUF_CLEAR 0x909090 // IO Ctrl Command
ÉÏÃæÊǺêµÄÍ·Îļþ
#include "rwbuff.h"
#include <unistd.h>
#include <linux/kernel.h> //for kernel programming
#include <linux/module.h> //for kernel module struct
#include <linux/init.h>
#include <linux/fs.h> //struct file_operations
#include <sys/types.h>
static struct file_operations rwbuf_fpos = {
open: rwbuf_open,
release: rwbuf_close,
read: rwbuf_read,
write: rwbuf_write,
ioctl: rwbuf_ioctl,
};
int init_module()
{
printk("Hello world\n");
if(register_chrdev(RWBUF_MAJOR,RWBUF_NAME,&rwbuf_fpos)){
printk("register error\n");
return -1;
}
else
printk("register ok\n");
return 0;
}
void cleanup_module()
{
ÎÒĿǰÔÚ±¾µØµÄlinuxÉÏдÁËÒ»¸öswingµÄ½çÃæ£¬Ïëͨ¹ýÕâ¸ö½çÃæÀ´¿ØÖÆÆäËüµçÄÔµÄlinuxÖØÆô¡£
ÎÒÖªµÀÓÃRuntime.getRuntime().exec("shutdown -r");¿ÉÒÔ¿ØÖƱ¾»úLinuxÖØÆô£¬µ«ÊÇÔõô¿ØÖÆÔ¶³ÌµÄlinuxÖØÆôÄØ£¿ ......
ÔÏȵÄGCC°æ±¾Îª4.1.2,ÎÒÖØÐ±àÒë°²×°ÁËGCC4.3.2£¬µ«ÊDZàÒëÍê³ÌÐòÔËÐгÌÐòʱ»á³öÏÖversion `GLIBCXX_3.4.9' not found Õâ¸öÎÊÌâ.ÔÚÍøÉÏÃæ²éÁËÒ»ÏÂÊÇÈíÁ¬½ÓµÄÎÊÌâ¡£µ«ÊDZ¾È˶ÔLinux²»Ì«ÊìϤ£¬¡°Ó¦¸ÃÖÆ×÷RPM°üÈ»ºó ......