我正在制作设备驱动程序。我添加了与 read 和 llseek 最相关的代码。我可以很好地输入和使用 read 。但是由于某种原因, llseek 无法进入。我在文件操作中将它列为 llseek 并将其与我想要的函数相匹配,参数似乎很好?
在 dmesg 中,我得到“inside READ”,但没有“inside SEEK”,也没有错误。终端或编译期间也没有错误。我也不太了解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,
};