ºìÁªLinuxÃÅ»§
Linux°ïÖú

¹ØÓÚ¡¶linuxÉ豸Çý¶¯³ÌÐò¡·µÚÈý°æ µÚÈýÕ open·½·¨Ö®ÎÒ×Ô¼ºµÄÒÉ»ó

·¢²¼Ê±¼ä:2011-04-13 14:22:36À´Ô´:ºìÁª×÷Õß:stephenyong
1£ºopen·½·¨Ô­ÐÍ£ºint (*open)( struct inode *inode, struct file *filp)
²ÎÊý½âÊÍ£º
µÚÒ»¸ö²ÎÊýÊÇÒ»¸öÖ¸Ïòinode ½á¹¹ÌåÀàÐ͵ÄÖ¸Õ룬Ö÷ÒªÊÇΪÁËʹÓÃinode½á¹¹ÌåÖеÄinode->i_rdevÕâÒ»ÏÕâÒ»Ïî°üº¬Á˱»´ò¿ªµÄÉ豸µÄÕæÕýµÄÉ豸ºÅcdev£¨Ê²Ã´½ÐÕæÕýµÄÉ豸ºÅ£¿Äª·Ç»¹Óмٵģ¿»¹²»Çå³þ£©£¬¶øÕâ¸öcdevÓÖÊÇÊôÓÚscull_devÕâ¸ö½á¹¹ÌåµÄÒ»ÏÎÒÃÇͨ³£ÐèÒªµÄ²»ÊÇcdevÕâÒ»Ï¶þÊÇ°üº¬ÕâÒ»ÏîµÄÄǸöscull_dev½á¹¹Ìå
µÚ¶þ¸ö²ÎÊýÊÇÒ»¸öfileÀàÐ͵ÄÖ¸Õ룬ÕâÀïÃæÓõ½ËüÖ÷ÒªÊÇΪÁËÓõ½Õâ¸ö½á¹¹ÌåÀïÃæµÄ¹ØÓÚÎļþµÄһЩÊôÐÔ(¾ßÌåÓÃÄÄЩÐÅÏ¢£¿ÎÒÒ²²»Çå³þ£¡)

2£ºÕâÀïÃæÓÐÒ»¸öcontainer_of( )Õâ¸öº¯Êý£¬ËûµÄÔ­ÐÍÊÇ£ºcontainer_of £¨pointer£¬container_type,container_field£©
²ÎÊý½âÊÍ£º
µÚÒ»¸ö²ÎÊý£¬¿ÉÄÜÊÇÒ»¸öÖ¸Õ룬ÓÃÀ´´æ·Å×îºó½á¹ûµÄ£¨ÖÁÓÚʲôÊÂ×îºó½á¹û£¬´ý»áÌÖÂÛ£¬¼ÇסËûÊÇÒ»¸öÖ¸Õ룩
µÚ¶þ¸ö²ÐÖò£¬ËûÊÇÒ»ÖÖÊý¾ÝÀàÐÍ£¬±ÈÈçÊéÉϵÄstruct scull_dev ËûÊÇÒ»ÖֽṹÌåÀàÐÍ
µÚÈý¸ö²ÎÊý£¬Ëû¾ÍÊǵڶþ¸ö²ÎÊýÖÐËù°üº¬µÄÔªËØ£¬ÀýÈçstruct_scull->cdev
ʹÓãºcontainer_of£¨inode->i_rdev£¬struct scull_dev£¬cdev£©
Õâ¸öº¯ÊýÊDz»ÊÇ¿ÉÒÔÕâÑùÀí½â£¿¸ù¾ÝcdevµÄµØÖ·£¬ÎÒÃÇÀûÓÃÕâ¸öº¯Êý¿ÉÒÔÕÒµ½°üº¬cdevÕâÒ»ÏîµÄscull_dev½á¹¹ÌåµÄµØÖ·£¬È»ºó¾Í°ÑµÃµ½µÄÕâ¸ö½á¹¹ÌåµÄµØÖ·±£´æµ½inode->i_rdevÖУ¬ÒÔ±ãʹÓá£
Õâ¸öº¯ÊýµÄ·µ»ØÖµÓÖÊÇʲôÄØ£¿ÊDz»ÊǾÍÊDZ£´æµ½inode->i_rdevÀïÃæµÄÕâ¸öµØÖ·ÄÜ£¿
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. txgc_wm ÓÚ 2011-05-12 01:29:27·¢±í:

    ÅóÓÑ£¬Óлú»á¿ÉÒÔÒ»Æð̽ÌÖһϡ£
    QQ£º496223538