For the condition "file->f_mode", when it failed, it should return EACCES rather than EBADF.

From: majianpeng
Date: Sun Feb 03 2013 - 21:07:20 EST


Hi all,
When I wanted to do discard operations,but i set the openflag was O_RDONLY,it returned a EBADF rather than EACCES or EPERM.
I searched the code and found:
>case BLKDISCARD:
>case BLKSECDISCARD: {
> uint64_t range[2];

> if (!(mode & FMODE_WRITE))
> return -EBADF;
Initial i thought there was error.But i searched all code of kernel and found some places like this.

The description of EBADF is "Bad file numbe". There are some places where returned EBADF like,
>if (!f.file)
> return -EBADF;

So i think for checking file->f_mode when failed, it should return EACCESS.


Jianpeng Ma
Thanks!


N?叉??y??b??千v??藓{.n???{?赙zXФ?塄}?财??j:+v???赙zZ+€?zf"?????i????ア??璀??撷f?^j谦y??@A?囤?0鹅h??i