[英]Driver function won't execute in c, but others will
I'm making a device driver. 我正在制作设备驱动程序。 I've added code that is most relevant to read and llseek. 我添加了与阅读和学习最相关的代码。 I can enter and use read perfectly fine. 我可以输入并使用阅读功能。 But for some reason, llseek can't be entered. 但是由于某些原因,无法输入llseek。 I have it listed in the file operations as llseek and match it to the function I want, the arguments appear to be good? 我在llseek的文件操作中列出了它,并将其与我想要的功能匹配,参数似乎很好?
In dmesg, i get "inside READ" but no "inside SEEK" and no errors. 在dmesg中,我得到“ inside READ”,但没有“ inside SEEK”,也没有错误。 Also no errors in terminal, or during compilation. 在终端或编译期间也没有错误。 I don't know c too well either. 我也不太了解c。
main 主要
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);
In my device driver: 在我的设备驱动程序中:
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,
};
Regarding your second issue: 关于第二个问题:
printk
is line buffered. printk
是行缓冲的。 This means that the buffer will be flushed (contents will be sent to the logfile) upon encountering a newline character ( \\n
). 这意味着在遇到换行符( \\n
)时,将刷新缓冲区(内容将发送到日志文件)。 Otherwise, it will be done only when the program exits. 否则,仅在程序退出时才完成。
So use '\\n' in your printk
statements. 因此,在您的printk
语句中使用“ \\ n”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.