Ò»¡¢linuxµÄÉ豸Çý¶¯³ÌÐòÓëÍâ½çµÄ½Ó¿Ú¿ÉÒÔ·ÖΪÈý¸ö²¿·Ö£º
1£®Çý¶¯³ÌÐòÓë²Ù×÷ϵͳÄں˵Ľӿڡ£Í¨¹ýfile_operations(include/linux/fs.h)Êý¾Ý½á¹¹À´Íê³ÉµÄ¡£
2£®Çý¶¯³ÌÐòÓëϵͳÒýµ¼µÄ½Ó¿Ú¡£Õⲿ·ÖÀûÓÃÇý¶¯³ÌÐò¶ÔÉ豸½øÐгõʼ»¯¡£
3£®Çý¶¯³ÌÐòÓëÉ豸µÄ½Ó¿Ú¡£Õⲿ·ÖÃèÊöÁËÇý¶¯³ÌÐòÈçºÎÓëÉ豸½øÐн»»¥£¬Óë¾ßÌåµÄÉ豸ÃÜÇÐÏà¹Ø¡£
¶þ¡¢¸ù¾Ý¹¦ÄÜ»®·Ö£¬É豸Çý¶¯³ÌÐòµÄ´úÂëÓÐÒÔϼ¸²¿·Ö£º
1£®Çý¶¯³ÌÐòµÄ×¢²áºÍ×¢Ïú¡£
2£®É豸µÄ´ò¿ªºÍÊÍ·Å¡£
3£®É豸µÄ¶Áд²Ù×÷¡£
4£®É豸µÄ¿ØÖƲÙ×÷¡£
5£®É豸µÄÖжϺÍÂÖѯ´¦Àí¡£
Èý¡¢Çý¶¯³ÌÐòµÄ×¢²áºÍ×¢Ïú£º
É豸Çý¶¯³ÌÐò¿ÉÒÔÔÚϵͳÆô¶¯µÄʱºò³õʼ»¯£¬Ò²¿ÉÒÔÔÚÐèÒªµÄʱºò¶¯Ì¬¼ÓÔØ¡£×Ö·ûÉ豸µÄ³õʼ»¯ÓÉchr_dev_init()Íê³É£¬°üÀ¨¶ÔÄڴ棨devfs_register_chrdev(MEM_MAJOR,"mem",&memory_fops)£©£¬Öնˣ¨tty_init()£©£¬´òÓ¡»ú£¨lp_init()£©£¬Êó±ê£¨misc_init()£©µÈ×Ö·ûÉ豸µÄ³õʼ»¯¡£
¿éÉ豸³õʼ»¯ÓÉblk_dev_init()Íê³É£¬Õâ°üÀ¨¶ÔIDEÓ²ÅÌ£¨ide_init()£©£¬ÈíÅÌ£¨floppy_init()£©£¬¹âÇýµÈ¿éÉ豸µÄ³õʼ»¯¡£
ÿ¸ö×Ö·ûÉ豸»òÊÇ¿éÉ豸µÄ³õʼ»¯¶¼ÊÇͨ¹ýdevfs_register_chrdev()»òÊÇdevfs_register_blkdev()ÏòÄÚºË×¢²á¡£ÔڹرÕ×Ö·ûÉ豸»òÊÇ¿éÉ豸ʱ£¬»¹ÐèҪͨ¹ýdevfs_unregister_chrdev()»òÊÇdevfs_unregister_blkdev()´ÓÄÚºËÖÐ×¢ÏúÉ豸¡£
ËÄ¡¢É豸µÄ´ò¿ªºÍÊÍ·Å£º
´ò¿ªÉ豸ÊÇÓÉopen()À´Íê³ÉµÄ¡£ÀýÈ磬´òÓ¡»úÊÇÓÃlp_open()´ò¿ªµÄ£¬¶øÓ²ÅÌÊÇÓÃhd_open()´ò¿ªµÄ¡£Ôڴ󲿷ÖÉ豸Çý¶¯³ÌÐòÖУ¬openÍê³ÉÈçϹ¤×÷£º
1£®Ôö¼ÓÉ豸µÄÊÇÓüÆÊý¡£
2£®¼ì²éÉ豸µÄÏà¹Ø´íÎó£¬ÈçÉ豸ÉÐδ׼±¸ºÃ»òÊÇÀàËÆÓ²¼þµÄÎÊÌâ¡£
3£®¼ì²éÊÇÊ״δò¿ª£¬Ôò³õʼ»¯É豸¡£
4£®Ê¶±ð´ÎÉ豸ºÅ£¬ÈçÓбØÒªÔò¸üÐÂf_opÖ¸Õë¡£
5£®Èç¹ûÐèÒª£¬·ÖÅäÇÒÉèÖÃÒª·ÅÔÚfilp->private_dataÀïµÄÊý¾Ý½á¹¹¡£
ÊÍ·ÅÉ豸ÓÉrelease()À´Íê³É£¬ÀýÈçÊÍ·Å´òÓ¡»úÊÇÓÃlp_release()£¬¶øÊÍ·ÅÖÕ¶ËÉ豸ÊÇÓÃtty_release()¡£ÊÍ·ÅÉ豸µÄÒ»°ã²½Öè°üÀ¨£º
1£®ÊÍ·ÅÔÚfilp->private_dataÖеÄopen·ÖÅäµÄÄÚ´æ¡£
2£®Èç¹ûÊÇ×îºóÒ»´ÎÊÍ·Å£¬Ôò¹Ø±ÕÉ豸¡£
3£®µÝ¼õÉè±ðµÄʹÓüÆÊý¡£
Îå¡¢É豸µÄ¶Áд²Ù×÷£º
×Ö·ûÉ豸ʹÓø÷×ÔµÄread()ºÍwrite()À´½øÐÐÊý¾Ý¶Áд¡£ÀýÈ磬¶ÔÐéÄâÖն˵ĶÁдÊÇͨ¹ývcs_read()ºÍvcs_write()À´½øÐÐÊý¾Ý¶ÁдµÄ¡£
¿éÉ豸ʹÓÃͨÓõÄgeneric_file_read()ºÍgeneric_file_write()À´½øÐÐÊý¾Ý¶Áд¡£ÕâÁ½¸öͨÓú¯ÊýÏòÇëÇó±íÌí¼Ó¶ÁдÇëÇó£¬Äں˿ÉÒÔͨ¹ýll_rw_block()ÓÅ»¯ÇëÇó˳Ðò¡£ÓÉÓÚÊǶÔÄڴ滺³åÇø¶ø²»ÊÇÉ豸½øÐвÙ×÷µÄ£¬Òò¶ø¿ÉÒÔ¼Ó¿ì¶ÁдÇëÇó¡£Èç¹ûÄڴ滺³åÇøÄÚûÓÐÒª¶ÁÈëµÄÊý¾Ý»òÊÇÒª½«Ð´ÇëÇóдÈëÉ豸£¬ÄÇô¾ÍÒªÕæÕýµÄÖ´ÐÐÊý¾Ý´«Êä¡£ÕâÊÇͨ¹ýÊý¾Ý½á¹¹request_queueºÍrequest_fn()À´Íê³É(include/linux/blkdev.h£©¡£
Áù¡¢É豸µÄ¿ØÖƲÙ×÷£º
³ýÁ˶Áд²Ù×÷£¬ÓÐʱ»¹Òª¿ØÖÆÉ豸¡£Õâ¿ÉÒÔͨ¹ýÉ豸Çý¶¯³ÌÐòÖеÄioctl()À´Íê³É¡£ÀýÈçIDEÓ²Å̵ĿØÖÆ¿ÉÒÔͨ¹ýhd_ioctl()£¬¶Ô¹âÇýµÄ¿ØÖÆ¿ÉÒÔͨ¹ýcdrom_ioctl()¡£
Óë¶Áд²Ù×÷²»Í¬£¬ioctl()µÄÓ÷¨Óë¾ßÌåÉ豸ÃÜÇÐÏà¹Ø¡£ÒÔÈíÇýµÄfloppy_ioctl()ΪÀý(drivers/block/floppy.c£©£º
static int fd_ioctl(struct inode *inode,
struct file *filp,
unsigned int cmd,
unsigned long param);
ÆäÖУ¬cmdµÄÈ¡Öµ¼°º¬Ò嶼ÊÇÓëÈíÇýÓйصģ¬±ÈÈ磬FDEJECT±íʾµ¯³öÈíÅÌ¡£
³ýÁËioctl()£¬É豸Çý¶¯³ÌÐò»¹¿ÉÄÜÓÐÆäËû¿ØÖƺ¯Êý£¬±ÈÈçllseek()µÈ¡£
Æß¡¢É豸µÄÂÖѯºÍÖжϴ¦Àí£º
¶ÔÓÚ²»Ö§³ÖÖжϵÄÉ豸£¬¶ÁдʱÐèÒªÂÖѯÉ豸״̬£¬ÒÔ¼°ÊÇ·ñÐèÒª¼ÌÐø½øÐÐÊý¾Ý´«Êä¡£ÀýÈ磬´òÓ¡»ú¡£Èç¹ûÉ豸֧³ÖÖжϣ¬Ôò¿É°´ÕÕÖжϷ½Ê½½øÐС£
shuixian4716 ÓÚ 2012-02-03 09:26:14·¢±í:
ºÃ¶«Î÷°¡
china19901107 ÓÚ 2011-05-26 23:22:51·¢±í:
²»´í²»´í£¬Ö§³ÖÖ§³Ö£¡£¡£¡£¡
΢΢µÄ·ç ÓÚ 2011-05-17 17:29:43·¢±í:
ÊܽÌÁË
ƽ·²ÈËδÀ´ ÓÚ 2010-09-16 21:49:59·¢±í:
д³öÕûÌåÁË¡£²»¹ýÀï±ßÿ¾ä»°ÒªÕæÕýÄÜÀí½âÌåÑéµÄ»°£¬µÃ»¨¹¦·ò¿´LDD3ÁË¡£
lyanxia28 ÓÚ 2010-09-07 16:11:43·¢±í:
лл
lyanxia28 ÓÚ 2010-09-07 16:11:41·¢±í:
лл
wxwp ÓÚ 2010-09-05 21:19:52·¢±í:
Ï£ÍûÂ¥Ö÷ÄÜдµÄ¸üÏêϸЩ£¬ÆÚ´ý´ó×÷£¡
wxwp ÓÚ 2010-09-05 21:11:14·¢±í:
ÍÛ¡£¡£ÔÀ´ÊÇÕâÑù¡£¡£
dengt ÓÚ 2010-09-03 08:46:07·¢±í:
ѧϰ
xzqiu2010 ÓÚ 2010-03-18 20:56:28·¢±í:
»¹¿ÉÒÔ£¬¾ÍÊÇÌ«´óÁË
zhangbohtz ÓÚ 2010-02-02 13:23:13·¢±í:
лл£¡
nerissa ÓÚ 2010-01-08 11:46:04·¢±í:
¿´¿´
cernllyy ÓÚ 2009-09-22 17:22:52·¢±í:
²»ÖªµÀ˵ʲôÀ²¡£¡£¿´²»¶®À²¡£¡£
dongch123 ÓÚ 2009-09-11 13:58:55·¢±í:
ͦºÃµÄ
xuejack ÓÚ 2009-09-04 21:19:45·¢±í:
ѧϰ
xiazhouquan ÓÚ 2009-09-03 16:07:59·¢±í:
ѧϰ
jlj1986 ÓÚ 2009-08-28 16:04:04·¢±í:
дµÄͦºÃµÄ°¡