Re: "struct inode" and internal "struct cdev*"?

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

 



On Sun, 13 Apr 2008, Arvin Moezzi wrote:

> On 4/11/08, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
> >
> >   from <linux/fs.h>:
> >
> >  struct inode {
> >
> >         ... snip ...
> >
> >         struct list_head        i_devices;
> >         union {
> >                 struct pipe_inode_info  *i_pipe;
> >                 struct block_device     *i_bdev;
> >                 struct cdev             *i_cdev;
> >         };
> >         int                     i_cindex;
> >         ... snip ...
> >  };
> >
> > so it's easy to see that an inode can hold at most one pointer to
> > one of a pipe, block dev or char dev structure.  but, under normal
> > circumstances, when is that "i_cdev" field actually set to point
> > to the appropriate "struct cdev"?
>
> hi robert,
>
> I am not an expert but this is what i could read out of the kernel
> source: So whenever you try to open a file, the underlying
> filesystem is asked by the vfs to get the corresponding inode of
> that file. It is there where the routine "init_special_inode" (see
> for example in fs/ext2/inode.c:ext2_iget) is called which fills in
> the file_operations i_fop member of struct inode with "def_chr_fops"
> (note def_chr_ops.open = chrdev_open). Afterwards vfs calls the
> method i_fop.open (which points to chrdev_open, see fs/
> open.c:__dentry_open). In chrdev_open (as you already pointed out)
> then, if not already set due to some earlier opens, i_cdev is set
> depending on the i_rdev field.

yes, i eventually tracked down the same thing after perusing the code
more carefully.  thanks.

rday
-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
    Have classroom, will lecture.

http://crashcourse.ca                          Waterloo, Ontario, CANADA
========================================================================

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