#include <asm/uaccess.h> // copy_to_user
#include <linux/module.h>
#include <linux/kernel.h>
static int devmajor = 77;
static char devname[] = "logdev";
static char devbuf[] = "this is my message.\n";
static int
logdev_read(struct file *filp, char *buf, size_t count, loff_t *pos)
{
int copy_len = sizeof(devbuf);
copy_to_user(buf, devbuf, copy_len);
return copy_len;
}
static struct file_operations logdev_fops = {
.read = logdev_read,
};
int
init_module(void)
{
register_chrdev(devmajor, devname, &logdev_fops);
printk(KERN_INFO "logdev init\n");
return 0;
}
void
cleanup_module(void)
{
unregister_chrdev(devmajor, devname);
printk(KERN_INFO "logdev clean\n");
}
MODULE_DESCRIPTION( "sample char device driver" );
$ ls -l /dev/logdev
crw-r--r-- 1 root root 77, 0 /dev/logdev
0 件のコメント:
コメントを投稿