简体   繁体   中英

C & Android kernel module: what happened with f_flags here?

I have a self-coded kernel module in Android which I open with O_RDONLY|O_NONBLOCK .

O_NONBLOCK is 2048 in both the user-program and the kernel module.

I checked that with

print..("O_NONBLOCK is %d", O_NONBLOCK)

in user- & kernel-space.

But now, when I try to check if O_NONBLOCK was set, I got a really strange problem:

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
    }
..
}

I tried something else:

cat my_device

but again, filp->f_flags is 1 .

I would assume maybe 0 for O_RDONLY but not 1 which means O_WRONLY .

Anyone an idea or explanation?

EDIT:

I also don't expect cat beeing O_NONBLOCK , but O_WRONLY is totally wrong.

I open it this way:

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

and there's no fcntl later (and that shouldn't affect my_open at all. But of course I also tried to "re-set" O_NONBLOCK with fcntl without luck.

You need to make sure that the userspace, indeed, passes what you think it must be passing. I find it hard to believe, for example, that "cat" would pass "NONBLOCK". It has no reason to.

Use strace on the userspace end to test what actually gets passed in.

Also, and a bit offtopic, are you sure you care whether O_NONBLOCK is set during open? Please remember that it may also be set using fcntl later on.

Shachar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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