Re: Reading flags from device driver "open" call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Jul 30, 2007 at 09:35:29AM -0500, beck0778@xxxxxxx wrote:
> I am writing a block device driver for an SD card accessed over SPI. If the 
> card is write-protected (using the little switch on the side), I would like 
> to inform the kernel that the device is read-only, and can't be written to.
>
> After a bit of research, I've come to the conclusion that the proper place 
> to inform the kernel is during the call to my open function, when I should 
> return an error code if the kernel tries to open my device in read-write or 
> write-only mode. Here is my open function's signature:
>
> static int sdcard_open(struct inode *inode, struct file *filp);
>
> In the 'file' struct, there is an unsigned int field called 'f_flags'. I 
> think this is the proper way to look up the flags used in the open system 
> call.
>
> When I open my device using O_RDWR,   f_flags = 0x00010002
> When I open my device using O_RDONLY, f_flags = 0x00010000

You also opened it with O_SYNC.

> This leads me to believe that the "user is requesting write access" flag is 
> in bit position 1 (second from the right).

Correct.

#define O_ACCMODE       00000003
#define O_RDONLY        00000000
#define O_WRONLY        00000001
#define O_RDWR          00000002

Most if not all of the time the definition of such flags in kernel is
the same as in userspace. In that way you don't have to do flag
conversions on each call.

> Sure, I could write my driver on this assumption, but I would really like 
> to find a list of the flags that belong to struct file. Is there some way 
> to know which #define statements belong to which bitfield?

It's defined in asm-generic/fcntl.h which you shouldn't include.
Include linux/fcntl.h instead.


Erik

- -- 
They're all fools. Don't worry. Darwin may be slow, but he'll
eventually get them. -- Matthew Lammers in alt.sysadmin.recovery
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGrgtK/PlVHJtIto0RAlJYAJ401LKOBq1cMm7UcO9ksYJI044VUwCdEF59
0rtEdwUIJ2iisuTlD7S/hi4=
=fBHf
-----END PGP SIGNATURE-----

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux