代码之家  ›  专栏  ›  技术社区  ›  grilam14

驱动程序函数不会在c中执行,但其他函数会执行

  •  0
  • grilam14  · 技术社区  · 6 年前

    在dmesg中,我得到“内部读取”,但没有“内部查找”,也没有错误。在终端或编译过程中也没有错误。我也不太了解c。

    主要的

    int file = open("/dev/simple_char_driver", O_RDWR);
    
    //read example, this works fine
    printf("Enter how many bytes you want to read: \n");
    int len[10];
    scanf("%d", len);
    char *ptr = malloc(*len * sizeof(char));
    
    read(file, ptr, *len);
    
    //llseek example, doesn't enter
    int offset [10];
    int whence [10];
    scanf("%d",offset);
    printf("Enter a value for whence: \n");
    scanf("%d",whence);
    
    llseek(file, offset, whence); 
    

    在我的设备驱动程序中:

    loff_t simple_char_driver_seek (struct file *pfile, loff_t offset, int whence)
    {
        printk(KERN_ALERT "Inside SEEK");
        return 0;
    }
    
    ssize_t simple_char_driver_read (struct file *pfile, char __user *buffer, size_t length, loff_t *offset)
    {
        printk(KERN_ALERT "Inside READ");
        return 0;
    }
    
    struct file_operations simple_char_driver_file_operations = {
    
        .owner   = THIS_MODULE,
        .open    = simple_char_driver_open,
        .release = simple_char_driver_close,
        .read    = simple_char_driver_read,
        .write   = simple_char_driver_write,
        .llseek  = simple_char_driver_seek,
    };
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   P.W    6 年前

    关于你的第二个问题:
    printk 是缓存线。这意味着一旦遇到换行符,缓冲区将被刷新(内容将被发送到日志文件)( \n
    所以在你的 声明。