Which member of the file data struct. holds file access type?

Which member of the file data struct. holds file access type?

Post by Fredric Moreniu » Wed, 05 Sep 2001 21:29:02



Hello,

I am writing a custom char device driver and would like to check which
file access mode (reading only ,writing only, etc.) a process that opens
the char file requests. Which member of the file data structure holds this
information and which are the possible types?

Thanks,

Fredric Morenius

 
 
 

Which member of the file data struct. holds file access type?

Post by Kasper Dupon » Wed, 05 Sep 2001 23:27:31



> Hello,

> I am writing a custom char device driver and would like to check which
> file access mode (reading only ,writing only, etc.) a process that opens
> the char file requests. Which member of the file data structure holds this
> information and which are the possible types?

The f_mode field. I suggest you see how
sys_read and sys_write check that field.
(linux/fs/read_write.c)

> Thanks,

> Fredric Morenius


--
Kasper Dupont

 
 
 

Which member of the file data struct. holds file access type?

Post by Pete Zaitc » Thu, 06 Sep 2001 00:13:59


Quote:> > I am writing a custom char device driver and would like to check which
> > file access mode (reading only ,writing only, etc.) a process that opens
> > the char file requests. Which member of the file data structure holds this
> > information and which are the possible types?

> The f_mode field. I suggest you see how
> sys_read and sys_write check that field.
> (linux/fs/read_write.c)

Kasper's answer is correct for testing permissions, but
this is not how I interpret Fredric's question.
He probably was looking for something like this:

static int ymf_open(struct inode *inode, struct file *file)
{
        .................
        if (file->f_mode & FMODE_WRITE) {
                ....  Program device for write
        }
        if (file->f_mode & FMODE_READ) {
                .... Program device for read
        }
        return 0;

Quote:}

Note that both flags may be set if the process is using O_RDWR.

-- Pete

 
 
 

1. glibc 2.0 accessing _cnt member in FILE struct (stdio.h)

Hi:

Glibc 2.0 has opaque stdio. How can I get access to the _cnt member of
of the FILE struct. Looking into the source for glibc 2.0.6 (?) shows
that stdio/glue.c appears to resolve this. But I can find no reference
to this in /usr/include/stdio.h. Is this something that needs to be
compiled into the library specially or accessed differently.

Or is there another way to query the input buffer status?

I am running Redhat 5.2 (2.0.36) with glibc 2.0.7.

Thank you for your time.

Regards,

-Jack de Valpine

2. 2.4.21-rc5-ac2, kernel BUG at ide-iops.c:1262 (burning CD on IBM T30)

3. FILE struct members in Linux

4. IBM cardbus

5. HELP: struct data members alignment???

6. Probs with netscape and kde

7. Gator eWallet Insecure User Data files Encryption and Gator BackUp / Banner Server Access/File retrieving

8. how to print multiple pages on one

9. Holding data in fifo file that exceeds PIPE_BUF size

10. Different types of access according to the newsgroups in the nnrp.access file

11. Identifying members of group for file access

12. How to do <cmd> file | hold file

13. STYLE: better to have one-file-many-functions or many-files-holding-one-function