1
0
mirror of https://github.com/ioacademy-jikim/device_driver synced 2025-06-07 07:56:08 +00:00
device_driver/03_day/kernel_file.c
ioacademy-jikim e92d98c6d0 first sample
2015-08-19 19:26:23 +09:00

30 lines
600 B
C

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/gfp.h>
// /data/aaa
int my_init(void) {
char *buff;
struct file *filp;
int ret;
filp = filp_open( "/data/bbb", O_WRONLY|O_TRUNC|O_CREAT, 0666 );
if( filp == 0 )
return 0;
buff = (char*)__get_free_pages( GFP_KERNEL, 0 );
strcpy(buff, "hello world");
ret = kernel_write( filp, buff, strlen(buff), 0 );
printk("ret=%d\n", ret );
free_pages( (unsigned long)buff, 0 );
filp_close( filp, 0 );
return 0;
}
void my_exit(void)
{
}
MODULE_LICENSE("GPL");
module_init( my_init );
module_exit( my_exit );