简体   繁体   English

打开文件O_NONBLOCKING在内核模块中丢失

[英]open file O_NONBLOCKING gets lost in kernel module

I am opening a file in my C program: 我在我的C程序中打开一个文件:

pcm->dfd = open(fname, O_RDONLY|O_NONBLOCK);

and later call select() and read() on it. 然后在其上调用select()read()

But my problem is, that the O_NONBLOCK gets lost somewere: 但我的问题是, O_NONBLOCK丢失了一些:

ssize_t my_read(struct file *filp, char __user *user_buffer, size_t bytes_requested, loff_t *capture_ptr) {

    if (filp->f_flags & O_NONBLOCK){
        LOGI("mode: O_NONBLOCK");
    }
    else{
        LOGI("mode: BLOCKING"); // <-- this is printed      
    }
    ..
}

I also tried 我也试过了

pcm->dfd=open(fname, O_RDONLY|O_NONBLOCK);

// O_NONBLOCK does not work :/
int flags = fcntl(pcm->dfd, F_GETFL, 0);
fcntl(pcm->dfd, F_SETFL, flags | O_NONBLOCK);

It's not a logging-problem, the driver also behaves as in blocking-mode. 这不是日志记录问题,驱动程序也像阻塞模式一样。

Anyone an idea? 有人有想法吗?

EDIT: 编辑:

The code which reads from the opened file is absolutely simple: 从打开的文件中读取的代码非常简单:

size=read(pcm->dfd,inBuffer,inBufferBytes);

I also checked the program if there's a fcntl() somewere else, but no.. 我还检查了程序,如果有一个fcntl()其他一些,但没有..

EDIT 2: 编辑2:

May it be possible, that the O_NONBLOCK has an other value in my user-program (Android NDK) than in the kernel? O_NONBLOCK在我的用户程序(Android NDK)中的其他值是否可能比在内核中有其他值? I searched for O_NONBLOCK in the kernel-headers and already there are 2 different definitions. 我在kernel-headers中搜索了O_NONBLOCK ,并且已经有2个不同的定义。

I also checked the open -implementation in my kernel module and already there filp->f_flags is not O_NONBLOCK . 我还检查了我的内核模块中的open -implementation,并且已经有filp->f_flags 不是 O_NONBLOCK

According to open(2) man-page , passing O_NONBLOCK only makes the open call itself non-blocking (which you, probably, don't want). 根据open(2)man-page ,传递O_NONBLOCK只会使open调用本身非阻塞(你可能不想要)。 It does not imply, that the opened file descriptor will also be in non-blocking mode -- you have to set that with a fcntl() after opening. 这并不意味着打开的文件描述符也将处于非阻塞模式 - 您必须在打开后使用fcntl()进行设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM