Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the story should starts from what happened when you type:</p> <pre><code>mknod /dev/c83 c 8 3 </code></pre> <p>it will call ext2_mknod("/dev", "c83", CHAR, DEV(8, 3)), most file systems implement mknod as a wrapper of init_special_inode:</p> <pre><code>void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev) { inode-&gt;i_mode = mode; if (S_ISCHR(mode)) { inode-&gt;i_fop = &amp;def_chr_fops; inode-&gt;i_rdev = rdev; } else if (S_ISBLK(mode)) { inode-&gt;i_fop = &amp;def_blk_fops; inode-&gt;i_rdev = rdev; } else if (S_ISFIFO(mode)) inode-&gt;i_fop = &amp;def_fifo_fops; else if (S_ISSOCK(mode)) inode-&gt;i_fop = &amp;bad_sock_fops; else printk(KERN_DEBUG "init_special_inode: bogus i_mode (%o)\n", mode); } </code></pre> <p>when you finally call open("/dev/c83"), it will goes into function def_chr_fops.chrdev_open, which will replace the fops for file "/dev/c83" with the fops your registered in cdev_init():</p> <pre><code>int chrdev_open(struct inode * inode, struct file * filp) { struct cdev *p; ... p = inode-&gt;i_cdev; ... filp-&gt;f_op = fops_get(p-&gt;ops); ... if (filp-&gt;f_op-&gt;open) { lock_kernel(); ret = filp-&gt;f_op-&gt;open(inode,filp); unlock_kernel(); } ... return ret; } </code></pre> <p>after that, every system call such as read/write/close goes directly to functions pointers registered in cdev_init()!</p> <p>so, for your first question:</p> <ol> <li>yes, as you see in chrdev_open().</li> <li>yes, since the fops of devices is really same as the one registered in cdev_init</li> <li> plays a importance role in open(), since open() use pairs to find the correct device drivers. but after that, other file operations, such as read/write/close(), don't take part in again, everything goes through function pointers in fops resolved in open().</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload