我在 Android 中有一个自编码内核模块,我用O_RDONLY|O_NONBLOCK
.
O_NONBLOCK
在2048
用户程序和内核模块中。
我用
print..("O_NONBLOCK is %d", O_NONBLOCK)
在用户和内核空间。
但是现在,当我尝试检查是否O_NONBLOCK
已设置时,我遇到了一个非常奇怪的问题:
static int my_open(struct inode *inode, struct file *filp) {
if (filp->f_flags & O_NONBLOCK) {
printk("O_NONBLOCK");
} else {
printk("NOT O_NONBLOCK");
printk("O_NONBLOCK in my_open is: %d", O_NONBLOCK); // -> prints 2048
printk("filp->f_flags in my_open is: %d", filp->f_flags); // -> prints 1, not 2048 or larger
}
..
}
我尝试了别的东西:
cat my_device
但同样,filp->f_flags
是1
。
我会假设可能0
是因为O_RDONLY
但不是1
这意味着O_WRONLY
。
任何人的想法或解释?
编辑:
我也不指望cat
beeing O_NONBLOCK
,但这O_WRONLY
是完全错误的。
我这样打开它:
pcm->dfd=open(fname, O_RDONLY|O_NONBLOCK);
并且没有fcntl
以后(这根本不应该影响。但当然我也尝试过my_open
“重新设置”但没有运气。O_NONBLOCK
fcntl