linux用户空间资料读取到内核驱动

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static int __init read_pic_init(void)
{
    int ret = 0;
    struct file *fp;
    loff_t pos;
    char imageBuffer[1024];
    
    printk("hello kernel\r\n");
    fp = filp_open("/home/pi/navydev/3_fb/Test.bmp",O_RDWR | O_CREAT,0777);
    if (IS_ERR(fp)){
        printk("no picture!\r\n");
		return -1;
    } 

    pos = 0;
    ret = kernel_read(fp, imageBuffer, 1024, &pos);
    if(ret < 0) {
        printk("read error!\r\n");
    }
    printk("===%#xn",imageBuffer[0]);
    printk("===%#xn",imageBuffer[1]);
    printk("===%#xn",imageBuffer[2]);
    printk("===%#xn",imageBuffer[3]);
    printk("===%#xn",imageBuffer[4]);
    printk("===%#xn",imageBuffer[5]);
    printk("===%#xn",imageBuffer[6]);
    printk("===%#xn",imageBuffer[7]);

    filp_close(fp,NULL);
         
    return 0;
}
 
static void __exit read_pic_exit(void)
{
     printk("read pic exit\r\n");
}
 
module_init(read_pic_init);
module_exit(read_pic_exit);
 
MODULE_LICENSE("GPL");

 

你可能感兴趣的:(Linux,树莓派,linux,kernel,kernel_read,file_open)