ãã¡ã€ã«ã·ã¹ãã ã®ç®çã¯ãããŒã¿ãæ§æãä¿åããããšã§ãããäžè¬çã«ãã¡ã€ã«ã·ã¹ãã ã¯ãŠãŒã¶ãšã¢ããªã±ãŒã·ã§ã³éã§ããŒã¿ãå ±æãããšåæã«ããŒã¿ãç¶æãããåŸã£ãŠããã¡ã€ã«ã¯ã³ã³ãã¥ãŒã¿ãåèµ·åããŠãååšããŠããã
xv6ã®ãã¡ã€ã«ã·ã¹ãã ã¯UNIXã©ã€ã¯ãªãã®ãæäŸããŠããããã¡ã€ã«ããã£ã¬ã¯ããªããã¹å(第0ç« ãåç §ã®ããš)ããµããŒãããIDEãã£ã¹ã¯ã«ä¿åããããšã§æ°žç¶æ§ã確ä¿ããããšãã§ãã(第3ç« ãåç §)ããã¡ã€ã«ã·ã¹ãã ãå®çŸããããã«ã¯ããã€ãã®å°é£ã解決ããå¿ èŠãããã
- ãã¡ã€ã«ã·ã¹ãã ã¯ãã£ã¹ã¯äžã«ãããªãŒæ§é ã®ãã£ã¬ã¯ããªãšãã¡ã€ã«ãè¡šçŸããããã®ããŒã¿æ§é ãæ§æããå¿ èŠãããããŸãåãã¡ã€ã«ã®å 容ãä¿æããããã®èå¥åãšãã©ã®ãã£ã¹ã¯é åã空ããŠããããšããæ å ±ãä¿æããŠããå¿ èŠãããã
- ãã¡ã€ã«ã·ã¹ãã 㯠ã¯ã©ãã·ã¥ããã®ãªã«ã㪠ããµããŒãããå¿ èŠããããã€ãŸãã(äŸãã°é»æºé®æãªã©ã§)ã¯ã©ãã·ã¥ãçºçããŠããåèµ·ååŸã«ãã¡ã€ã«ã·ã¹ãã ã¯æ£ããåäœããå¿ èŠããããã¯ã©ãã·ã¥ã®ãªã¹ã¯ã¯ãããŒã¿ã®æŽæ°ã®éã«å²ã蟌ã¿ãçºçãããã£ã¹ã¯äžã®ããŒã¿ã®äžè²«æ§(äŸãã°ããã¡ã€ã«ãååšããããšãšãããªãŒç¶æ ã§ããããšã瀺ããããã¯ã®ããŒã¯ãªã©)ã«åœ±é¿ãåºãå Žåãªã©ããããããã
- ç°ãªãããã»ã¹ããã¡ã€ã«ã·ã¹ãã ãåæã«æ±ããããäžå€æ§ãç¶æããããã«ãã¡ã€ã«ã·ã¹ãã ãæäœããå¿ èŠãããã
- ãã£ã¹ã¯ãžã®ã¢ã¯ã»ã¹ã¯ã¡ã¢ãªãžã®ã¢ã¯ã»ã¹ã«æ¯ã¹ãŠæ Œæ®µã«é ããåŸã£ãŠãã¡ã€ã«ã·ã¹ãã ã¯é »ç¹ã«å©çšããããããã¯ã«ã€ããŠã¡ã¢ãªäžã«ãã£ãã·ã¥ããä»çµã¿ãæäŸããå¿ èŠãããã
æ¬ç« ã§ã¯ãäžèšã®å°é£ãxv6ã§ã¯ã©ã®ããã«è§£æ±ºããŠãããã«ã€ããŠèª¬æããã
xv6ã®ãã¡ã€ã«ã·ã¹ãã ã¯å³6-1ã«ç€ºãããã«7ã€ã®éå±€ã§æ§æãããŠããããã£ã¹ã¯éå±€ã¯ãIDEããŒããã©ã€ãã®ãããã¯ãèªã¿æžãããããããã¡ãã£ãã·ã¥éå±€ã¯ãã£ã¹ã¯ãããã¯ããã£ãã·ã¥ãããããã¯ã®ã¢ã¯ã»ã¹ã®åæãåããããŒã¿ãæ ŒçŽãããŠããç¹å®ã®ãããã¯ã«ã€ããŠããã£ãäžã€ã®ãããã¯ã®ã¿ãå€æŽãè¡ã£ãŠããããšãä¿èšŒããããã®ã³ã°éå±€ã¯é«äœã®éå±€ã®ããã€ãã®ãããã¯ã®æŽæ°æäœããã©ã³ã¶ã¯ã·ã§ã³ãšããŠã©ãããããŸãã¯ã©ãã·ã¥ãçºçããå Žåã§ãã(äŸãã°ãå
šãŠã®ãããã¯ãã¢ããããŒãããããããŸãã¯äžã€ãã¢ããããŒããããŠããªãç¶æ
ãä¿æã)ãããã¯ãã¢ãããã¯ã«æŽæ°ãããããšãä¿èšŒãããinodeéå±€ã¯åã
ã®ãã¡ã€ã«ãæäŸããããããã®ããŒãã¯inodeãšãããŠããŒã¯ãªi-numberãšããã¡ã€ã«ãä¿æããŠããããã€ãã®ãããã¯ã§æ§æãããããã£ã¬ã¯ããªéå±€ã¯ããã€ãã®ãã£ã¬ã¯ããªãæ§æããç¹å¥ãªçš®é¡ã®i-nodeãšããŠæ§æãããããã£ã¬ã¯ããªã®inodeã¯ãã£ã¬ã¯ããªã®ãšã³ããªåãå«ãŸããŠãããåãšã³ããªã«ã¯ãã¡ã€ã«åãši-numberãå
¥ã£ãŠããããã¹åéå±€ã¯ã/usr/rtm/xv6/fs.c
ã®ãããªéå±€çãªãã¹æ§æãæäŸããéå±€çãªæ¢çŽ¢ã«ããããã解決ããããã¡ã€ã«ãã£ã¹ã¯ãªãã¿éå±€ã¯å€ãã®UNIXã®è³æºãæœè±¡åãã(äŸãã°ããã€ããããã€ã¹ããã¡ã€ã«ãªã©)ããã¡ã€ã«ã®ã¢ã¯ã»ã¹ã«ã¯ãã¡ã€ã«ã·ã¹ãã ã€ã³ã¿ãã§ãŒã¹ãçšããã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã®ããã°ã©ãã³ã°ãç°¡ååããã
ãã¡ã€ã«ã·ã¹ãã ã¯inodeãã©ãã«æ ŒçŽãããã£ã¹ã¯ã®ã©ã®ãããã¯ã«ãã¡ã€ã«ã®å 容ãæ ŒçŽãããã«ã€ããŠã®æ¹éã決ããå¿ èŠãããããããè¡ãããã«ã¯ãxv6ã¯ãå³6-2ã«ç€ºãããã«ãã£ã¹ã¯ãããã€ãã®ã»ã¯ã·ã§ã³ã«åå²ããããã¡ã€ã«ã·ã¹ãã ã¯ãããã¯0ã¯äœ¿çšããªã(ããã¯ããŒãã»ã¯ã¿ãä¿æããŠãã)ããããã¯1ã¯ãã¹ãŒããããã¯ããšåŒã°ãããã¡ã€ã«ã·ã¹ãã ã®ã¡ã¿ããŒã¿ãæ ŒçŽããŠãã(ãããã¯ã®ãã¡ã€ã«ãµã€ãºãããŒã¿ãããã¯ã®æ°ãinodeã®æ°ããã°äžã®ãããã¯ã®æ°)ããããã¯2以éã¯inodeãä¿æããŠããããããã¯ãããã«è€æ°ã®inodeãä¿æããŠããããã®åŸã¯ãããããããããã¯ã§ããã䜿çšããŠãããããã¯ãèšé²ããŠãããæ®ã©ã®æ®ãã®ãããã¯ã¯ãããŒã¿ãããã¯ã§ãã; ããããã®ãããã¯ã¯ãããããããããã¯äžã§ããªãŒã§ããããšãããŒã¯ãããŠããããã¡ã€ã«ãããã¯ãã£ã¬ã¯ããªãä¿æãããŠããããã£ã¹ã¯ã®æåŸã®ãããã¯ã¯ãã®ã³ã°éå±€ã®ãã°ãæ ŒçŽãããŠããã
æ¬ç« ã®ä»¥éã§ã¯ãåéå±€ã«ã€ããŠè°è«ããããŸãã¯ãããã¡ãã£ãã·ã¥ã®éå±€ããå§ãŸããããŸãéžæãããäžäœéå±€ã®æœè±¡åã«ãããäžäœã®éå±€ãããæãããªã£ãŠããããšãèŠãŠãããã
ãããã¡ãã£ãã·ã¥éå±€ã®ä»äºã¯2ã€ãã: (1)ãã£ã¹ã¯ãããã¯ã®ã¢ã¯ã»ã¹ã®åæãè¡ãããã£ãäžã€ã®ãããã¯ã®ã³ããŒãã¡ã¢ãªäžã«ååšãããã£ãäžã€ã®ã«ãŒãã«ã¹ã¬ããããã®ã³ããŒã䜿ã£ãŠããããšãä¿èšŒãã;
(2)é »ç¹ã«å©çšãããããã¯ããã£ãã·ã¥ããäœéãªãã£ã¹ã¯ããäœåºŠãèªã¿åºãå¿
èŠãç¡ãããã³ãŒãã¯bio.c
ã«å®è£
ãããŠããã
ãããã¡ãã£ãã·ã¥ã®ããã«ãšã¯ã¹ããŒããããäž»ã®ã€ã³ã¿ãã§ãŒã¹ã¯ãbread
ãšbwrite
ã§ãã; åè
ã¯ã¡ã¢ãªã«ã³ããŒããããèªã¿æžãå¯èœãªãããã¯ã®å
容ã®ã³ããŒãååŸããåŸè
ã¯æŽæ°ããããããã¡ããã£ã¹ã¯ã®é©åãªãããã¯ã«æžã蟌ããã«ãŒãã«ã¹ã¬ããã¯ãæžã蟌ã¿ãå®äºãããšãã¯brelse
ãåŒã³åºããŠããããã¡ã解æŸããªããã°ãªããªãã
ãããã¡ãã£ã·ã¥ã¯åãããã¯ãåæåããåãããã¯ããæ倧ã§ã1ã€ã®ã«ãŒãã«ã¹ã¬ãããããããã¯ã®ãããã¡ãåç
§ãèš±å¯ãããŠããªãç¶æ
ãäœãããã1ã€ã®ã«ãŒãã«ã¹ã¬ããããããã¡ãåç
§ããŠãããããã解æŸããŠããªããã°ãä»ã®ã¹ã¬ãããbread
ãåŒã³åºããŠåäžã®ãããã¡ãåç
§ããããšããŠãããã¯åŸ
ãããããããé«äœã®ãã¡ã€ã«ã·ã¹ãã éå±€ã¯ãããã¡ãã£ãã·ã¥ãããã¯ã®åæã«ãããäžå€æ§ãä¿ãããããšãæ¯æŽããŠããã
ãããã¡ãã£ãã·ã¥ã¯ãã£ã¹ã¯ãããã¯ãä¿æããããã®åºå®æ°ã®ãããã¡ãæã£ãŠããããã¡ã€ã«ã·ã¹ãã ããã£ãã·ã¥äžã«ååšããŠããªããããã¯ãèŠè«ããå Žåã¯ããããã¡ãã£ãã·ã¥ã¯çŸåšä¿æããŠãããããã¡ãšäº€æããŠããããã¡ããªãµã€ã¯ã«ããªããã°ãªããªãããããã¡ãã£ãã·ã¥ã¯æãæè¿å©çšãããŠããªããããã¡ã«æ°ãããããã¯ãæ¿å ¥ãããæãå©çšãããŠããªããããã¡ã¯ãä»åŸæãå©çšãããªããããã¯ã§ãããšããä»®å®ã«åºããŠããã
ãããã¡ãã£ãã·ã¥ã¯åæ¹åã®ãªã³ã¯ãªã¹ãã®ãããã¡ã§ããã
main
ããåŒã°ããé¢æ°binit
(1231è¡ç®)ã«ãã£ãŠãªã¹ããNBUF
åã®éçãªé
åbuf
ãåæåãã(4350-4359è¡ç®)ãå
šãŠã®ãªã³ã¯ãªã¹ããåç
§ãããããã¡ãã£ãã·ã¥ãžã®ã¢ã¯ã»ã¹ã¯bcache.head
ãå©çšããŠã¢ã¯ã»ã¹ãããbuf
é
åã¯å©çšãããªãã
ãããã¡ã¯3ã€ã®ç¶æ
ããããæã£ãŠãããB_VALID
ã¯ãããã¡å
ã«ãããã¯ã®ã³ããŒãååšããŠããããšã瀺ããŠãããB_DIRTY
ã¯ãããã¡ã®å
容ãå€æŽãããŠããããã£ã¹ã¯ã«æžãæ»ãå¿
èŠãããããšã瀺ããŠãããB_BUSY
ã¯ããã€ãã®ã«ãŒãã«ã¹ã¬ããããã®ãããã¡ãåç
§ããŠããããŸã 解æŸãããŠããªãããšã瀺ãã
bread
(4402è¡ç®)ãbget
é¢æ°ãåŒã³ãäžããããã»ã¯ã¿ã®ãããã¡ãè¿ã(4406è¡ç®)ããããããã¡ããã£ã¹ã¯ããèªãå¿
èŠãããã°ãbread
ã¯iderw
ãåŒã³åºããŠããããã¡ãè¿ãããã«ãããbget
(4366è¡ç®)ã¯äžããããããã€ã¹ãšã»ã¯ã¿çªå·ãããããã¡ãªã¹ããã¹ãã£ã³ãã(4737-4384è¡ç®)ããããã®ãããªãããã¡ãååšãããããã¡ããã·ãŒã§ãªããã°ãbget
ã¯B_BUSY
ãã©ã°ãç«ãŠãŠé¢æ°ããæ»ã(4376ãŒ4383è¡ç®)ããããããã¡ãæ¢ã«äœ¿çšãããŠããã°ãbget
ã¯ãããã¡äžã§ã¹ãªãŒãç¶æ
ã«å
¥ãã解æŸãããã®ãåŸ
ã€ããããsleep
ããæ»ããšãbget
ã¯ãããã¡ã解æŸããããšä»®å®ããããšã¯ã§ããªããå®éãsleep
ã¯buf_table_lock
ã解æŸããŠå床ãããã¡ãååŸããããbãæ£ãããããã¡ã§ããä¿èšŒã¯ãªã : ãããããç°ãªããã£ã¹ã¯ã»ã¯ã¿ã«ãã£ãŠåå©çšãããŠããã§ããããbget
ã¯æåããããçŽã(4383è¡ç®)å¿
èŠããããä»åºŠã¯ãŸãå¥ã®æéã«è§£æ±ºãããããšãæåŸ
ããŠããã
äžããããã»ã¯ã¿ããããã¡ãã£ãã·ã¥ã«ååšããªãå ŽåããŸããbget
ã¯ããããå¥ã®ã»ã¯ã¿ãšããŠå©çšãããŠããäžã€ã®ãããã¡ãåå©çšããå¿
èŠãããã次ã«ããããã¡ãªã¹ããã¹ãã£ã³ããŠãããžãŒã§ã¯ãªããããã¡ãæ¢çŽ¢ãã: ãã®ãããªãããã¡ã¯ãã©ãã§ã䜿çšå¯èœã§ãããbget
ã¯ãããã¡ã®ã¡ã¿ããŒã¿ãç·šéããæ°ããããã€ã¹ãšã»ã¯ã¿çªå·ãèšé²ãããããã¡ããæ»ãåã«ãããã¡ãããžãŒã§ããããšãããŒã¯ãã(4393è¡ç®)ããã©ã°ã®èšå®ã¯,B_BUSY
ãããã ãã§ãªããB_VALID
ãšB_DIRTY
ãã¯ãªã¢ããããšãå¿ããªãããã«ãããããã«ãããbread
ã¯ãããã¡ã®éå»ã®å€ãå
容ãèªãŸãã«ããããã¯ã®ããŒã¿ããã£ã¹ã¯ããèªãããã«èšå®ãããã
ãããã¡ãã£ãã·ã¥ã¯åæã®ããã«ãå©çšãããã®ã§ãç¹å®ã®ãã£ã¹ã¯ã»ã¯ã¿ã«å¯ŸããŠãã£ãäžã€ã®ãããã¡ãå©çšãããããšã¯éèŠã§ãããå²ãåœãŠã®æ¹æ³(4391-4393è¡ç®)ã¯ãå²ãåœãŠã¢ã«ãŽãªãºã ã¯åžžã«å®å
šã§ãããããã¯bget
ãæåã«ã«ãŒãã«å
¥ã£ãŠããããã以é決ããŠbut_table_lock
ã解æŸããããŸã§è«Šããªãããã§ããã
ããå
šãŠã®ãããã¡ãããžãŒã§ãããªãã°ãäœããééã£ãŠãããããbget
ã¯ãããã¯ã§çµäºããã
ããäžåãªå¯Ÿå¿ãšããŠã¯ããããã¡ãããªãŒã«ãªããŸã§ã¹ãªãŒãããããšã§ãããããããããã§ããããããã¯ããå¯èœæ§ãããã
bread
ãåŒã³åºãå
ã«åž°ããšãåŒã³åºãå
ã¯ãããã¡ãæä»çã«å©çšããŠããç¶æ
ã«ãªãããããŒã¿ãã€ãã®èªã¿èŸŒã¿ãŸãã¯æžã蟌ã¿ãã§ãããããèªã¿åºãå
ãããŒã¿ã®æžã蟌ã¿ãè¡ã£ããªãã°ãbwrite
ãåŒã³åºããŠããããã¡ã解æŸããåã«ãã£ã¹ã¯ã®æžã蟌ã¿åŠçãè¡ãå¿
èŠããããbwrite
(4414è¡ç®)ã¯B_DIRTY
ãã©ã°ãèšå®ããiderw
ãåŒã³åºããŠãããã¡ããã£ã¹ã¯ã«æžã蟌ãã
èªã¿åºãå
ããããã¡ã®åŠçãå®äºãããšãbrelse
ãåŒã³åºããŠè§£æŸããªããã°ãªããªã(brelse
ã¯b-releaseã®ç¥èªã§ãããæå·ãããŠã¯ããããåŠãã§ãã䟡å€ããã: Unixããå©çšãããŠããèšèã§ãããBSDãLinux, Solarisã§ãå©çšãããŠãã)ãbrelse
(4425è¡ç®)ã¯ãããã¡ããªã³ã¯ãªã¹ãã®å
é ã«ç§»åã(4432-4437è¡ç®)ãB_BUSY
ããããã¯ãªã¢ãããããã¡äžã§ã¹ãªãŒãç¶æ
ã«ãªã£ãŠããããã»ã¹ãèµ·ããããããã¡ã移åããããšã«ãã£ãŠãã©ã®ãããã¡ãæè¿å©çšãããããåããããã«ãªã£ãŠãã(ã€ãŸãããã€è§£æŸãããããåããããã«ãªã£ãŠãã)ãæåã®ãããã¡ã¯æãæè¿å©çšããããã®ã§ãããååšããŠãããããã¡ã®ã¹ãã£ã³ã§ã¯ã¯ãŒã¹ãã±ãŒã¹ã§åŠçããå¿
èŠããããããããæè¿å©çšããããããã¡ãæåã«ãã§ãã¯ããããšã«ãã£ãŠ(bcache.head
ããå§ãŸããnext
ãã€ã³ã¿ã蟿ã£ãŠãã)ãåç
§å±ææ§ã掻çšããŠã¹ãã£ã³ã®æéãåæžããããšãã§ãããæè¿å©çšãããŠããªããããã¡ãéžæãåå©çšããããã®ã¹ãã£ã³ã§ã¯ããããã¡ãéæ¹åã«ã¹ãã£ã³ããããšã§å®çŸã§ãã (prev
ãã€ã³ã¿ã蟿ã£ãŠãã)ã
ãã¡ã€ã«ã·ã¹ãã ã«ãããæãèå³æ·±ãåé¡ã¯ãã¯ã©ãã·ã¥ããã®å埩ã§ãããå€ãã®ãã¡ã€ã«ã·ã¹ãã ã®æäœã§ã¯ãã£ã¹ã¯ãžã®è€æ°åã®æžã蟌ã¿ãçºçããããã¯ã©ãã·ã¥ã¯ãããäžéšåã®æžã蟌ã¿ããã¡ã€ã«ã·ã¹ãã äžã®ãã£ã¹ã¯ã«å¯ŸããŠå®è¡ãããåŸã§çºçãããã®çµæäžè²«æ§ã®ç¡ãç¶æ ãçºçãããäŸãã°ããã£ã¹ã¯ã®æžã蟌ã¿é çªã«äŸåããŠããã¡ã€ã«åé€äžã®ã¯ã©ãã·ã¥ã§ã¯è§£æŸãããinodeã®ãã£ã¬ã¯ããªã®ãšã³ããªãã€ã³ããæ¶å€±ããããå²ãåœãŠã¯ããããã®ã®è§£æŸãããªãinodeãçºçããããããåŸè ã¯æ¯èŒçç©ããã§ãããã解æŸãããinodeãåç §ãããã£ã¬ã¯ããªãšã³ããªã¯ãåèµ·ååŸã«ã·ã¹ãã ã«æ·±å»ãªåé¡ãçºçãããå¯èœæ§ãããã
xv6ã¯ãã®ãããªãã¡ã€ã«ã·ã¹ãã æäœäžã®ã¯ã©ãã·ã¥ã®åé¡ãã·ã³ãã«ãªãã®ã³ã°ã«ãã£ãŠè§£æ±ºããŠãããxv6ã®ã·ã¹ãã ã³ãŒã«ã¯ããã£ã¹ã¯äžã®ãã¡ã€ã«ã·ã¹ãã æ§é ã«å¯ŸããŠçŽæ¥çã«æžã蟌ã¿ãè¡ããªãããã®å€ããã«ãå šãŠã®ãã£ã¹ã¯ãžã®ææã®æžã蟌ã¿ã¯ããã£ã¹ã¯äžã®ãã°ãšããŠçæããé 眮ããããã·ã¹ãã ã³ãŒã«ãå šãŠã®æžã蟌ã¿ããã°ãããšãç¹å¥ãªã³ãããèšé²ããã£ã¹ã¯ã«å¯ŸããŠæžã蟌ãŸãããã°ã®å 容ãå®å šãªæäœãšããŠåæ ãããããã®åŸã·ã¹ãã ã³ãŒã«ãæžã蟌ã¿ããã£ã¹ã¯ã®ãã¡ã€ã«ã·ã¹ãã ããŒã¿æ§é ã«åæ ãããæžã蟌ã¿åŠçãå®äºãããšãã·ã¹ãã ã³ãŒã«ã¯ãã£ã¹ã¯äžãããã°ãæ¶å»ããã
ã·ã¹ãã ãã¯ã©ãã·ã¥ãåèµ·åãããšããã¡ã€ã«ã·ã¹ãã ã¯ããã»ã¹ãå®è¡ããåã«ä»¥äžã®ãããªé çªã§ãªã«ããªããã³ãŒããå®è¡ããããããã°ãå®å šãªæäœãšããŠèšé²ãããŠãããšããªã«ããªã³ãŒãã¯ãã®æžã蟌ã¿ããã£ã¹ã¯äžã®ãã¡ã€ã«ã·ã¹ãã ã«åæ ãããããããã°ãå®å šãªæäœãšããŠããŒã¯ãããŠããªããšããªã«ããªã³ãŒãã¯ãã®ãã°ãç¡èŠããããªã«ããªã³ãŒãã¯ãã°ãæ¶å»ããŠçµäºããã
xv6ã¯ãã¡ã€ã«ã·ã¹ãã æäœäžã®ã¯ã©ãã·ã¥ã®åé¡ã解決ããã®ã ãããïŒãããã£ã¹ã¯ã®æäœã³ããããå®äºããåã«ã¯ã©ãã·ã¥ãçºçãããšããã£ã¹ã¯äžã®ãã°ã¯å®äºãšããŠããŒã¯ããããªã«ããªã³ãŒãããããç¡èŠãããã£ã¹ã¯äžã®ç¶æ ã¯æäœã¯å§ãŸã£ãŠããªããã®ãšãªãããããã£ã¹ã¯æäœãå®äºããŠããã¯ã©ãã·ã¥ãçºçãããšããªã«ããªã³ãŒãã¯ãäŸããã£ã¹ã¯ãžã®æžã蟌ã¿ã®åæã®æäœãäºéã«å®è¡ãããããšã«ãªã£ããšããŠããå šãŠã®æžã蟌ã¿æäœãå床å®è¡ãããã©ã¡ãã®å Žåã«ãããã°ã¯ã¯ã©ãã·ã¥ã«é¢ããŠã¯æäœã®ã¢ãããã¯ãä¿ã€: å埩ã®åŸã¯ããã£ã¹ã¯äžã®å šãŠã®æäœã¯å®äºããŠããããå šãå®è¡ãããŠããªããã®ã©ã¡ããã§ããã
ãã°ã¯ãã£ã¹ã¯ã®æåŸã®æ¢ç¥ã®é åã«é 眮ãããŠããããã°ã¯ããããããã¯ãšãããã«ç¶ããŠæŽæ°ããããããã¯ã®ã³ããŒ(ãã°ããããããã¯)ãç¶ããŠãããããããããã¯ã¯ã»ã¯ã¿çªå·ã®é åã§ãããããããã°ããããããã¯ã«çžåœãããããããããã¯ã¯ãã°ããããããã¯ã®æ°ãå«ãã§ãããxv6ã¯ãã©ã³ã¶ã¯ã·ã§ã³ã³ããããçºçãããšããããããã¯ãžæžã蟌ã¿ãè¡ãããã³ããããèµ·ããåã§ã¯ãªãããã°ããããããã¯ããã¡ã€ã«ã·ã¹ãã ã«ã³ããŒããã段éã§ã«ãŠã³ãã¯0ã«æ»ããããåŸã£ãŠããã©ã³ã¶ã¯ã·ã§ã³ã®éäžã§ã¯ã©ãã·ã¥ãçºçãããšããã°ããããããã¯ã®ã«ãŠã³ãã0ãšãªã£ãŠãã; ã³ãããåŸã®ã¯ã©ãã·ã¥ã¯ãéãŒããšããŠã«ãŠã³ããããã
åã·ã¹ãã ã³ãŒã«ã®ã³ãŒãã¯ãæžã蟌ã¿åã®æåããæåŸãŸã§ãã¢ãããã¯ã§ããããšã瀺ããŠãããå¹çåã®ãããšããã¡ã€ã«ã·ã¹ãã ã³ãŒãã®äžŠåæ§ã蚱容ããããã«ããã®ã³ã°ã®ã·ã¹ãã ã¯è€æ°ã®ã·ã¹ãã ã³ãŒã«ã®åãã©ã³ã¶ã¯ã·ã§ã³ãã«ãŠã³ãããããšãã§ãããåŸã£ãŠãåäžã®ã³ããããè€æ°ã®å®å šãªã·ã¹ãã ã³ãŒã«ã®æžã蟌ã¿ãèªèµ·ãããããšããããã¢ãããã¯æ§ãç¶æããããã«ããã®ã³ã°ã·ã¹ãã ã¯ãã¡ã€ã«ã®ã·ã¹ãã ã³ãŒã«ãäžã€ãå®è¡äžã§ãªããšãã«éã£ãŠã³ããããè¡ãããã
è€æ°ã®ãã©ã³ã¶ã¯ã·ã§ã³ããŸãšããŠã³ããããããšããã¢ã€ãã¢ã¯ããã°ã«ãŒãã³ãããããšããŠç¥ãããŠãããã°ã«ãŒãã³ãããã¯ãè€æ°ã®ãã©ã³ã¶ã¯ã·ã§ã³ã蚱容ããŠäžŠåã«å®è¡ãããã¡ã€ã«ã·ã¹ãã ãè€æ°ã®ããããåŠçãã®ãã£ã¹ã¯æžã蟌ã¿ãèš±å¯ããããã«ããåäžã®ãã£ã¹ã¯æäœããã£ã¹ã¯ãã©ã€ãã«çºè¡ãããããã«ããŠããã ããã«ããããã£ã¹ã¯ããããã¯ãžã®æžã蟌ã¿ã®ã¹ã±ãžã¥ãŒã«ãšããã£ã¹ã¯ã®ãã³ãå¹ ã®æ¯çãèæ ®ããŠæžã蟌ãããšãã§ããããã«ãªããxv6ã®IDEãã©ã€ãã¯ãããåŠçããµããŒãããŠã¯ããªãããxv6ã®ãã¡ã€ã«ã·ã¹ãã ã®ãã¶ã€ã³ã¯ãããå®è¡ã§ããããã«ããŠããã
xv6ã¯ãã°ãä¿æããããã«åºå®ãµã€ãºã®ãã£ã¹ã¯é åã確ä¿ããŠããããã©ã³ã¶ã¯ã·ã§ã³äžã®ã·ã¹ãã ã³ãŒã«ã«ãã£ãŠæžã蟌ãŸãããããã¯ã®ç·éã¯ããã®é åã«åãŸããµã€ãºã§ãªããã°ãªããªããããã«ããã2ã€ã®çµè«ãåŸããããã©ã®ãããªã·ã¹ãã ã³ãŒã«ããã°äžã«ååšããã¹ããŒã¹ãããå¹
åºããããã¯ã«æžã蟌ãããšã¯ã§ããªããããã¯æ®ã©ã®ã·ã¹ãã ã³ãŒã«ã«ãšã£ãŠåé¡ã§ã¯ãªãããã·ã¹ãã ã³ãŒã«ã®ãã¡ã®2ã€ããå€ãã®ãããã¯ã«ããŒã¿ãæžã蟌ãå¯èœæ§ããã:write
ãšunlink
ã§ããã
倧ããªãã¡ã€ã«ã®æžã蟌ã¿ã«ãããå€ãã®ããŒã¿ãããã¯ãžã®æžã蟌ã¿ãšãå€ãã®ãããããããããã¯ãšinodeãžã®æžã蟌ã¿ãçºçããã;倧ããªãã¡ã€ã«ãžã®unlink
ã¯ãå€ãã®ãããããããããã¯ãšinodeãžã®æžã蟌ã¿ãçºçããããxv6ã®ã·ã¹ãã ã³ãŒã«ã¯ããã®ãã倧ããªæžã蟌ã¿ãçºçãããšãå°ããªæžã蟌ã¿ãžãšåå²ãããã°ã®ãµã€ãºã«åãããã«ãããunlink
ã¯å®éã«ã¯åé¡ã«ã¯ãªãããããã¯xv6ã®ãã¡ã€ã«ã·ã¹ãã ã¯ãã£ãšäžã€ã®ãããããããããã¯ããå©çšããªãããã§ãããããäžã€ã®çµè«ã¯ããã°é åãå¶éãããããšã«ããããã®ã³ã°ã·ã¹ãã ã¯ã·ã¹ãã ã³ãŒã«ããã°äžã®æ®ãã®é åã«ãã£ããããããã«ãªããŸã§ãç¹å®ã®ã·ã¹ãã ã³ãŒã«ã®æžã蟌ã¿ãéå§ããããšãã§ããªããšããå¶çŽã§ããã
ã·ã¹ãã ã³ãŒã«äžã®ãã°ã®å žåçãªå©çšäŸã¯ä»¥äžã®ãããªãã®ã§ãã:
begin_op();
...
bp = `bread`(...);
bp->data[...] = ...;
`log_write`(bp);
...
end_op();
begin_op
(4628è¡ç®)ã¯ããã°ã·ã¹ãã ãã³ããããçºçããŠããªãç¶æ
ã«ãªãããã®ã·ã¹ãã ã³ãŒã«ã«ããæžã蟌ã¿ã§çºçãããã°ãæ ŒçŽã§ãããŸã§ãã°é åãåå確ä¿ããããŸã§åŸ
ã¡åãããè¡ããlog.outstanding
ã¯ã·ã¹ãã ã³ãŒã«ã®åŒã°ããåæ°ãã«ãŠã³ããã; ã€ã³ã¯ãªã¡ã³ããããããšã«ãããé åãäºçŽããã·ã¹ãã ã³ãŒã«ãçºçããŠããæäžã®ã³ããããä¿è·ãããxv6ã®ã³ãŒãã¯åã·ã¹ãã ã³ãŒã«ãMAXOPBLOCKS
åã®ãããã¯ãžã®æžã蟌ã¿ãŸã§ããçºçãããªããšããä¿å®çãªä»®å®ãè¡ã£ãŠããã
log_write
(4722è¡ç®)ã¯bwrite
ã®ä»£çãšããŠåäœãããlog_write
ã¯ããããã¯ã®ã»ã¯ã¿çªå·ãã¡ã¢ãªäžã«èšé²ãããã£ã¹ã¯äžã®ãã°ã®ã¹ããããäºçŽãããããã¯ãã£ãã·ã¥ã匷å¶çã«æ»ãããããšãé²ãããã«ãB_DIRTY
ã®ããŒã¯ãä»å ãããããããã¯ã¯ã³ãããããããŸã§ãã£ãã·ã¥äžã«ä¿æãããŠããªããã°ãªããããããçµäºãããšããã£ãã·ã¥ãããã³ããŒãå¯äžã®å€æŽã®èšé²ãšãªã; ã³ããããçµäºãããŸã§ããã£ã¹ã¯äžã«é
眮ããããã®é åã«ã¯æžã蟌ã¿ãçºçãããããšã¯ã§ããªã;ãŸããåäžã®ãã©ã³ã¶ã¯ã·ã§ã³ã«ãããèªã¿èŸŒã¿åŠçã¯ããã®å€æŽãåç
§ããªããã°ãªããªããlog_write
ã¯ãããã¯ãåäžã®ãã©ã³ã¶ã¯ã·ã§ã³ã§äœåºŠãæžã蟌ãŸããå Žåã«éç¥ãè¡ãããã°äžã®åäžã®ã¹ãããã«ãããã¯ãå²ãåœãŠãããã®æé©åã¯ããåžåããšãã°ãã°åŒã°ããããã®æé©åã¯å
±éã®æè¡ã§ãããäŸãã°ãããã€ãã®inodeãä¿æãããŠãããã£ã¹ã¯ãããã¯ãããã©ã³ã¶ã¯ã·ã§ã³ã«ããäœåºŠãæžãæããããå Žåãªã©ã«æå¹ã§ãããããã€ãã®ãã£ã¹ã¯ã®æžã蟌ã¿ã1ã€ã«åžåãããããšã«ããããã¡ã€ã«ã·ã¹ãã ã¯ãã°ã®é åãç¯çŽããããšãã§ãããã£ã¹ã¯ãããã¯ã®ãã£ã¹ã¯ãžã®æžã蟌ã¿ã®ããã®åæ°ãåæžããããšã«ããæ§èœãåäžãããããšãã§ããã
end_op
(4653è¡ç®)ã¯ããŸãå
šäœã®ã·ã¹ãã ã³ãŒã«ã®åæ°ããã¯ãªã¡ã³ããããããã«ãŠã³ãããŒãã ãšãcommit()
ãåŒã³åºãããšã«ãããçŸåšã®ãã©ã³ã¶ã¯ã·ã§ã³ãã³ãããããããã®åŠçã«ã¯ã4ã€ã®æ®µéããããwrite_log()
(4683è¡ç®)ã¯ãã©ã³ã¶ã¯ã·ã§ã³ã«ããå€æŽãããåãããã¯ããããã¡ãã£ãã·ã¥ãããã£ã¹ã¯äžã®ãã°ã¹ãããã«ã³ããŒãããwrite_head()
(4604è¡ç®)ã¯ãã£ã¹ã¯ã«å¯ŸããŠããããããã¯ã®æžã蟌ã¿ãè¡ã: ãããã³ããããã€ã³ãã§ããããã®æžã蟌ã¿ç§»è¡ã®ã¯ã©ãã·ã¥ã¯ãçµæãšããŠãã°ãããã©ã³ã¶ã¯ã·ã§ã³ã®æžã蟌ã¿ãå床å®è¡ããããšã«ããå埩ããããinstall_trans()
(4572è¡ç®)ã¯ãã°äžããåãããã¯ãèªã¿ããã¡ã€ã«ã·ã¹ãã ã®æ£ããé åã«æžã蟌ã¿ãè¡ããæåŸã«ãend_op()
ã¯ãã°ãããã«ãŒããã«ãŠã³ããã; ããã¯ã次ã®ãã©ã³ã¶ã¯ã·ã§ã³ã«ãããã°ã®ãããã¯ã®æžã蟌ã¿ãçºçããããåã«å®äºããå¿
èŠãããã
ããã«ããã¯ã©ãã·ã¥ã«ãããããã©ã³ã¶ã¯ã·ã§ã³ã®ãããã«ãããå¥ã®ãã©ã³ã¶ã¯ã·ã§ã³ã®ãããã¯ãå埩ãããŠããŸãããšãé²ãã
recover_from_log
(4618è¡ç®)ã¯ãinitlog
(4556è¡ç®)ã«ããåŒã³åºãããæåã®ããã»ã¹ãå®è¡ããããããåã«ããŒãäžã«åŒã³åºããã(2794è¡ç®)ãããã¯ãã°ããããèªã¿èŸŒã¿ãããããã³ãããããããã©ã¶ã¯ã·ã§ã³ãååšããããšç€ºããŠãããªãã°ãend_op()
ãšäŒŒããããªåäœãè¡ãã
ãã°ã®ãå©çšããäŸãfilewrite
(5752è¡ç®)ã«èŒã£ãŠããããã©ã³ã¶ã¯ã·ã§ã³ã¯ä»¥äžã®ãããªãã®ã§ããã
begin_op();
`ilock`(f->ip);
r = writei(f->ip, ...);
`iunlock`(f->ip);
end_op();
ãã®ã³ãŒãã¯ã«ãŒãã«å²ãŸããŠããã倧ããªæžã蟌ã¿ãå°æ°ã®ã»ã¯ã¿ã«æžã蟌ããããªåã
ã®ãã©ã³ã¶ã¯ã·ã§ã³ã«åå²ããŠããããã°ã®ãªãŒããããŒãé²ãã§ãããwritei
ã®åŒã³åºãã«ããããã©ã³ã¶ã¯ã·ã§ã³ã®äžéšãšããŠè€æ°ã®ãããã¯ãžã®æžã蟌ã¿ãè¡ã: ãã¡ã€ã«ã®inodeãšã1ã€ä»¥äžã®ãããããããããã¯ãšãããã€ãã®ããŒã¿ãããã¯ãžã®æžã蟌ã¿ãè¡ãããã
ãã¡ã€ã«ãšãã£ã¬ã¯ããªã®å 容ã¯ããªãŒãªããŒã«ããå²ãåœãŠããããã£ã¹ã¯ãããã¯ã«æ ŒçŽããããxv6ã®ãããã¯ã¢ãã±ãŒã¿ã¯ãã£ã¹ã¯äžã®ããªãŒãªããããããã«ãã£ãŠç®¡çãããŠãããããããããã®1ãããã1ãããã¯ã«çžåœããããããã0ã®å Žåã¯ãã®ãããã¯ãããªãŒã§ããããšã瀺ãã1ãããããã®ãããã¯ã䜿çšããŠããããšã瀺ããããŒãã»ã¯ã¿ãã¹ãŒããŒãããã¯ãinodeãããã¯ããããããããããã¯ã«çžåœãããããã¯åžžã«1ã§ããã
ãããã¯ã¢ãã±ãŒã¿ã¯2ã€ã®æ©èœãæäŸãã: balloc
ã¯æ°ãããã£ã¹ã¯ãããã¯ãå²ãåœãŠãbfree
ã¯ãããã¯ã解æŸãããballoc
(4804)ã¯readsb
ãåŒã³åºããŠãã£ã¹ã¯(ãããã¯ãããã¡ãã£ãã·ã¥)äžããã¹ãŒããããã¯ãåŒã³åºããŠsb
ã«æ ŒçŽãããballoc
ã¯ã©ã®ããªãŒãªãããããããããã©ã®ãããã¯ãããŒãã»ã¯ã¿ãã¹ãŒããŒãããã¯ãinodeãã(BBLOCK
ã䜿ã£ãŠ)äœåæ¶è²»ããããèšç®ãããã«ãŒã(4812è¡ç®)ã¯å
šãŠã®ãããã¯ãèæ
®ããŠããã0ããå§ãŸã£ãŠsb.size
ãŸã§ã«ãŒããããããã¯ãã¡ã€ã«ã·ã¹ãã äžã®ãããã¯ã®æ°ã«çžåœãããããããããããŒãã®ãããã¯ãã€ãŸãããªãŒã®ãããã¯ãæ¢ããballoc
ããã®ãããªãããã¯ãçºèŠãããšããããããããæŽæ°ããŠãã®ãããã¯ãè¿ããå¹çåã®ããã«ãã«ãŒãã¯2ã€ã®éšåããæ§æãããŠãããå€åŽã®ã«ãŒãã¯ããããããã®ãããã®åãããã¯ãèªã¿åºããå
éšã«ãŒãã¯ãããã¯å
ã®å
šãŠã®BPB
ãããããã§ãã¯ããã2ã€ã®ããã»ã¹ãåæã«ãããã¯ã確ä¿ããããšãããšã¬ãŒã¹ã³ã³ãã£ã·ã§ã³ãçºçãããããããã¯çŠæ¢ãããŠããããããã¡ãã£ãã·ã¥ã¯ãã£ã1ã€ã®ããã»ã¹ããããããããããã¯ãåç
§ã§ããããã«ãªã£ãŠããã
bfree
(4831è¡ç®)ã¯æ£ãããããããããããã¯ãæ¢çŽ¢ãããã®ããããã¯ãªã¢ããã
bread
ãšbrelse
ãæä»çã«çšããããšã«ãã£ãŠãæ瀺çãªããã¯ãé¿ããããã«ããŠããã
æ¬ç« ã«ããã以éã«ç»å Žããæ®ã©ã®ã³ãŒãã§ã¯ãballoc
ãšbfree
ã¯ãã©ã³ã¶ã¯ã·ã§ã³ã®å
éšã§åŒã°ããã
inodeãšããçšèªã¯2ã€ã®é¢é£ããæå³ãæã£ãŠããããã£ã¹ã¯äžã®ãã¡ã€ã«ãµã€ãºãšããŒã¿ãããã¯çªå·ãå«ãããŒã¿æ§é ã®ããšãæããã"inode"ãšããçšèªããã¡ã¢ãªäžã®inodeã®ããšãæãããã£ã¹ã¯äžã®inodeã®ã³ããŒã§ãããã«ãŒãã«äžã§å¿ èŠãšãããå€éšæ å ±ãšããæå³ãæã£ãŠããã
ãã£ã¹ã¯äžã®å
šãŠã®inodeã¯ãã£ã¹ã¯äžã®inodeãããã¯ãšåŒã°ããé£ç¶ããé åã«ããã¯ãããŠãããå
šãŠã®inodeã¯åããµã€ãºã§ãããinodeçªå·n
ãäžãããããšããã®inodeã®å Žæããã£ã¹ã¯äžã§æ¢ãã®ã¯ãããããå®éããã®çªå·n
ã¯inodeçªå·ããããã¯i-numberãšåŒã°ããinodeãã©ã®ããã«ããŠå®è£
ã«ãã£ãŠèå¥ãããŠããã®ãã瀺ããŠããã
ãã£ã¹ã¯äžã®inodeã¯ãstruct dinode
(3926è¡ç®)ãšããŠå®çŸ©ãããŠãããtype
ãã£ãŒã«ãããã¡ã€ã«ãšãã£ã¬ã¯ããªãšãç¹æ®ãã¡ã€ã«(ããã€ã¹ãªã©)ãšãåºå¥ããŠãããtype
ãã£ãŒã«ãããŒããªãã°ããã£ã¹ã¯äžã®inodeã解æŸãããŠããããšã瀺ããnlink
ãã£ãŒã«ããããã®inodeãšã³ããªãåç
§ããŠãããã£ã¬ã¯ããªãšã³ããªã®æ°ã瀺ããããã¯ãã£ã¹ã¯äžã®inodeãšãã®ããŒã¿ã解æŸãããããšãèå¥ããããã«å©çšãããã
size
ãã£ãŒã«ãã¯ãã¡ã€ã«ã®ãµã€ãºãæ ŒçŽããŠãããaddr
é
åã¯ãã£ã¹ã¯ãããã¯äžã®ãã¡ã€ã«ãä¿æããŠãããããã¯ã®æ°ãèšé²ããŠããã
ã«ãŒãã«ã¯ãã¡ã¢ãªäžã®ã¢ã¯ãã£ããªinodeã®éåãä¿æããŠãã; struct inode
(4012è¡ç®)ã¯ãã£ã¹ã¯äžã®struct dinode
ã®ã¡ã¢ãªã³ããŒã§ãããã«ãŒãã«ã¯ãCã®ãã€ã³ã¿ããã®inodeãåç
§ãããšãã«ã®ã¿ã¡ã¢ãªäžã«ãã®inodeãæ ŒçŽãããref
ãã£ãŒã«ãã¯ã¡ã¢ãªäžã®inodeãåç
§ããŠããCã®ãã€ã³ã¿ã®æ°ã瀺ããŠããããã®æ°ã0ã«ãªããšãã«ãŒãã«ã¯ã¡ã¢ãªäžãããã®inodeãåé€ãããiget
ãšiput
é¢æ°ã¯inodeã確ä¿ã解æŸããé¢æ°ã§ãåç
§ã«ãŠã³ããå€æŽãããinodeãžã®ãã€ã³ã¿ã¯ãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãçŸåšã®ã¯ãŒãã³ã°ãã£ã¬ã¯ããªãexec
ã®ãããªäžæçãªã«ãŒãã«ã³ãŒããªã©ããååŸããããšãã§ããã
iget
ã«ããè¿ããããã€ã³ã¿ã¯è©²åœããiput
()ãåŒã°ãããŸã§æ£ããããšãä¿èšŒãããŠãã; inodeã¯åé€ãããããã€ã³ã¿ã«ããåç
§ãããinodeã¯ç°ãªãinodeã«ããåå©çšãããããšã¯ç¡ããiget
ã¯inodeãžã®éæä»çã¢ã¯ã»ã¹ãæäŸããŠãããåŸã£ãŠãåäžã®inodeã«å¯ŸããŠè€æ°ã®ãã€ã³ã¿ãæã€ããšãã§ããããã¡ã€ã«ã·ã¹ãã ã®ã³ãŒãã¯ãã®iget
()ã®åäœã«äŸåããŠãããinodeãžã®é·ãæéã®åç
§(ãã¡ã€ã«ããçŸåšã®ãã£ã¬ã¯ããªãéãæäœãªã©)ããè€æ°ã®inodeãæäœããå Žå(ãã¹åã®æ¢çŽ¢ãªã©)ã®ã³ãŒãã®ããããããã¯ãé¿ããããã®ã¬ãŒã¹ã³ã³ãã£ã·ã§ã³ã®é²æ¢ã«å©çšãããŠããã
iget
ãè¿ãstruct inode
ã«ã¯ã䟿å©ãªæ
å ±ã¯ããŸãå
¥ã£ãŠããªãããã£ã¹ã¯äžã®inodeã®ã³ããŒãä¿æãããŠããããšãä¿èšŒããããã«ã¯ãã³ãŒãã¯ilock
é¢æ°ãåŒã³åºããªããã°ãªããªãã
ãã®ã³ãŒãã¯inodeãããã¯ã(ããã«ããä»ã®ããã»ã¹ãilock
ãããããšãåºæ¥ãªããªã)ããããã®inodeããŸã èªã¿åºããŠããªããã°ããã£ã¹ã¯ããinodeãèªã¿åºããiunlock
ã¯ããã®inodeã®ããã¯ã解æŸãããinodeãã€ã³ã¿ã®ç¢ºä¿ãšãinodeã®ããã¯ã®æ©èœãåé¢ããããšã«ãããããã€ãã®ç¶æ³ãäŸãã°ããã£ã¬ã¯ããªã®åç
§äžã«ãããŠãããããã¯ãåé¿ããããšãã§ãããè€æ°ã®ããã»ã¹ãiget
ã«ãã£ãŠè¿ãããinodeãžã®Cã®ãã€ã³ã¿ãä¿æããããšãã§ãããããã£ãäžã€ã®ããã»ã¹ã®ã¿ããåãæéã«inodeãããã¯ããããšãã§ããã
inodeãã£ãã·ã¥ã¯ãã«ãŒãã«ã³ãŒããããã¯ãCãã€ã³ã¿ãä¿æããããŒã¿æ§é ãinodeãå©çšãããšãã ããã£ãã·ã¥ããããäž»ããæ©èœã¯è€æ°ã®ããã»ã¹ãinodeãžåç §ãããšãã®æ¬åœã®åæãåãããã§ããããã£ãã·ã¥ãããããšãæ¬æ¥ã®æ©èœã§ã¯ãªããããinodeãé »ç¹ã«å©çšããããªãã°ããããã¡ãã£ãã·ã¥ããããã¡ã¢ãªäžã«ä¿æããinodeãã£ãã·ã¥ãä¿æããèš³ã§ã¯ãªãã
æ°ããinodeãå²ãåœãŠã(äŸãã°ãæ°ãããã¡ã€ã«ãäœæãããšããªã©)æã¯ãxv6ã¯ialloc
(4953è¡ç®)ãåŒã¶ãialloc
ã¯balloc
ãšäŒŒãŠããïŒãã£ã¹ã¯äžã®inodeæ§é äœãã«ãŒãããäžã€ãã€ãããªãŒãªç¶æ
ã®inodeãæ¢ããŠãããããªãŒãªinodeãçºèŠãããšãæ°ããtypeããã£ã¹ã¯äžã«æžã蟌ã¿ãinodeãã£ãã·ã¥ãããšã³ããªãè¿ããŠãæåŸã®iget
ã«æž¡ã(4970è¡ç®)ãialloc
ã®æ£ããåäœã¯1ã€ã®ããã»ã¹ãbp
ãåç
§ããŠããããšãåæã«ããŠãã: ialloc
ã¯ããã€ãã®ä»ã®ããã»ã¹ãåæã«åäœããã«äœ¿çšå¯èœã§ããããšãåæã«åäœããŠããã
iget
(5004è¡ç®)ã¯inodeãã£ãã·ã¥äžãæ¢çŽ¢ããŠãææã®ããã€ã¹ãšææã®inodeçªå·ããã¢ã¯ãã£ããªãšã³ããª(ip->ref>0
)ãèŠã€ããã該åœãããšã³ããªãçºèŠãããšããã®inodeãžã®æ°ããåç
§ãè¿ã(5013-5017è¡ç®)ãiget
ãã¹ãã£ã³ããããã«ãæåã®ïœã®ã¹ãããã®å Žæãèšé²ããŠãã(5018-5109è¡ç®)ããã£ãã·ã¥ãšã³ããªã確ä¿ããªããã°ãªããªããšãã«å©çšããã
inodeã®å
容ãã¡ã¿ããŒã¿ãèªã¿æžãããåã«ãiget
ã¯ilock
ãå©çšããŠinodeãããã¯ããªããã°ãªããªãã
ilock
(5053è¡ç®)ã¯æ
£ã芪ããã sleep
ã®ã«ãŒããçšããŠãip->flag
ã®I_BUSY
ããããã¯ãªã¢ããããã®åŸã»ãããããã®ãåŸ
ã£ãŠãã(5062-5064è¡ç®)ãäžåºŠilock
ãinodeã«å¯Ÿããæä»çãªã¢ã¯ã»ã¹ã確ä¿ãããšãå¿
èŠãªãã°ãã£ã¹ã¯äžããinodeã®ã¡ã¿ããŒã¿ãããŒããã(ããæ£ç¢ºã«èšãã°ããããã¡ãã£ãã·ã¥ã«ããŒãããã)ãiunlock
(5085è¡ç®)é¢æ°ã¯I_BUSY
ããããã¯ãªã¢ããilock
äžã§ã¹ãªãŒãç¶æ
ã«ãªã£ãŠããä»»æã®ããã»ã¹ãèµ·ããã
iput
ã¯inodeã®åç
§ã«ãŠã³ã¿ããã¯ãªã¡ã³ããããããšã§ãCãã€ã³ã¿ã®åç
§ã解æŸãã(5124è¡ç®)ããããããå¯äžã®åç
§ã§ããã°ãinodeãã£ãã·ã¥äžã®inodeã¹ãããã¯è§£æŸãããå¥ã®inodeã®ããã«åå©çšãããã
iput
ãCãã€ã³ã¿ã®åç
§ãååšãããinodeã¯ãªã³ã¯ãæã£ãŠããªããã°(ããã¯ãã£ã¬ã¯ããªã®äžã§ã¯çºçããªãxxx?)ãinodeãšãã®ããŒã¿ãããã¯ã¯åç
§ãããŠããªããã°ãªããªããiput
ã¯inodeãå床ããã¯ãã; itrunc
ãåŒã³åºããŠãã¡ã€ã«ããŒããã€ãã«ãªããŸã§åãåãããã®ããŒã¿ãããã¯ã解æŸãã; inodeã¿ã€ãã0(éå²ãåœãŠ)ã«èšå®ãã;ãã®å€æŽããã£ã¹ã¯ã«æžã蟌ã; æåŸã«inodeãã¢ã³ããã¯ãã(5111-5123è¡ç®)ã
inodeã解æŸãããšãã®iput
ã®ãããã³ã°ãããã³ã«ã¯ãã§ãã¯ããã«å€ãããã®ã§ããã
æåã«ãipãI_BUSY
ãèšå®ããããšã§ããã¯ãããšãiput
ã¯ãããããã¯è§£é€ããããã®ãšä»®å®ããã
ããã¯ä»¥äžã®ãããªå Žåããããšèãããã: åŒã³åºãå
ã¯iput
ãåŒã³åºãåã«ipãã¢ã³ããã¯ããŠããå¿
èŠããããä»ã®ããã»ã¹ããã®inodeãããã¯ããŠããªããããã¯ããã®ã³ãŒããã¹äžã§ã¯inodeã¯åç
§ãããŠãããããªã³ã¯ãååšããªã(ã€ãŸããã©ã®ãããªãã¹åããã®inodeãåç
§ããŠããã)ããããŠæªã 解æŸã®ããŒã¯ãä»ããŠããªãããã§ãã¯ãã¹ã2ã€ãã®å Žæã¯ãiput
ãinodeã®ãã£ãã·ã¥ããã¯ãäžæçã«è§£æŸã(5116è¡ç®)ãå床ååŸãã(5120è¡ç®)ããšã§ãããããã¯itrunc
ãšiupdate
ããã£ã¹ã¯I/Oãè¡ã£ãŠããéã«ã¹ãªãŒãããããã§ãããããããã®ããã¯ãä¿æããŠããªãéã¯ãäœãçºçãããåãããªããæããã«ãäžåºŠiupdate
ãçµäºãããšããã£ã¹ã¯äžã®inodeã¯è§£æŸãšããŒã¯ãããŠãããå¹³è¡ããŠåŒã°ããialloc
ã¯iput
ãçµäºããåã«ãã®å ŽæãçºèŠããããšãããããç¥ããªããialloc
ã¯iget
ãåŒã³ããã£ãã·ã¥äžã«ipãçºèŠãããã®I_BUSY
ãã©ã°ãã»ãããããŠããã®ã確èªãã¹ãªãŒãç¶æ
ã«å
¥ããialloc
ã¯ãã®ãããã¯ã®å Žæãè¿ããããããªããä»ãã³ã¢äžã®inodeã¯ãã£ã¹ã¯ã«å¯ŸããŠåæããããŠããªã: ialloc
ã¯ãã£ã¹ã¯ã®ããŒã·ã§ã³ãååæåããããilock
äžã«ã¡ã¢ãªã«ããŒããããåŒã³åºãå
ã«äŸåããŠãããåžžã«ãã®ãããªåäœã«ãªãããšãä¿èšŒããããã«ãiput
ã¯I_BUSY
ãã¯ãªã¢ããã ãã§ãªããinodeã®ããã¯ã解æŸããåã«ãI_VALID
ãã¯ãªã¢ããå¿
èŠããããããã¯ãflags
ããŒãã«èšå®ããããšã§å®è¡ããã(5121è¡ç®)ã
iput
ã¯ãã£ã¹ã¯ãžæžã蟌ã¿ãã§ãããããã¯ãã¡ã€ã«ã·ã¹ãã ãå©çšããã·ã¹ãã ã³ãŒã«ã¯ã(äŸãã°read()
ã®ãããªread-onlyãªã·ã¹ãã ã³ãŒã«ã§ãã£ãŠã)ããã£ã¹ã¯ãžã®æžã蟌ã¿ãçºçãããããšã瀺ããŠãããããã¯ã€ãŸããRead-Onlyãªã·ã¹ãã ã³ãŒã«ãããã¡ã€ã«ã·ã¹ãã ãå©çšããå Žåã¯ãã©ã³ã¶ã¯ã·ã§ã³ãã©ããããŠãããªããã°ãªããªãããšã瀺ããŠããã
ãã£ã¹ã¯äžã®inodeæ§é äœã§ããstruct inode
ã«ã¯ããµã€ãºãšãããã¯çªå·ã®é
åãã¯ãã£ãŠãã(å³6-4ãåç
§ã®ããš)ããã®ãããã¯ã®inodeããŒã¿ã¯dinode
ã®addr
é
åããæ¢çŽ¢ããããããŒã¿ã®æåã®NDIRECT
ãããã¯ã¯é
åäžã®æåã®NDIRECT
ãšã³ããªã«ãªã¹ãåãããŠããã; ãããã®ãããã¯ã¯direct blocksãšåŒã°ããã
次ã®NINDIRECT
ã¯inodeãå
¥ã£ãŠããèš³ã§ã¯ãªãããindirect blockãšåŒã°ããããŒã¿ãããã¯ãå
¥ã£ãŠããã
addr
é
åã®æåŸã®ãšã³ããªã¯éæ¥ãããã¯ã®ã¢ãã¬ã¹ãå
¥ã£ãŠãããåŸã£ãŠããã¡ã€ã«ã®æåã®6kB(NDIRECTÃBSIZE
)ãã€ãã¯ãinodeã®ãããã¯ãªã¹ãããããŒãããããšãã§ããäžæ¹ã§æ¬¡ã®64kB(NINDIRECT
ÃBSIZE
)ãã€ãã¯é¢ç¯ãããã¯ãããŒãããŠãããããŒãããããšãã§ãããããã¯ãã£ã¹ã¯äžã®è¡šçŸãšããŠã¯è¯ãããéæ¥ãããã¯ãžã®ã¢ã¯ã»ã¹ãããè€éã§ãããbmap
é¢æ°ããã®è¡šçŸã管çããreadi
ãwritei
ãªã©ã®ããé«äœãªã«ãŒãã³ãç°¡åã«åç
§ã§ããããã«ããŠãããbmap
ã¯inode ipã®bnçªç®ã®ããŒã¿ãããã¯ãã£ã¹ã¯ãããã¯ã®çªå·ãè¿ããããipããã®ãããªãããã¯ãæã£ãŠããªããã°ãbmap
ã¯ãããå²ãåœãŠãã
bmap
é¢æ°(5160è¡ç®)ã¯ããŸãç°¡åãªã±ãŒã¹ããæ¢ã£ãŠãã: æåã®NDIRECT
ãããã¯ã¯inodeèªèº«ã«äžŠãã§ãã(5165-5169è¡ç®)ã次ã®NINDIRECT
ãããã¯ã¯ip->addrs[NDIRECT]
ã«é
眮ãããŠããéæ¥ãããã¯ã«é
眮ãããŠãããbmap
ã¯éæ¥ãããã¯ãèªã¿èŸŒã¿(5176è¡ç®)ããããã¯äžã®å³åŽãããããã¯ã®çªå·ãèªã¿èŸŒãã§ãã(5177è¡ç®)ããããã®ãããã¯çªå·ãNDIRECT
+NINDIRECT
ãè¶ããŠããã°ãbmap
ã¯ãããã¯ãèµ·ãã; writei
ã¯ãã®ãããªç¶æ
ãé²ãããã®åŠçããªãããŠãã(5315è¡ç®)ã
ãŸã¯ãããã¯ãå¿
èŠã«å¿ããŠå²ãä»ãããip->addrs[]
ãããã¯éæ¥ãšã³ããªããŒãã§ãããããšã¯ãã©ã®ãããªãããã¯ãå²ãåœãŠãããŠããªãããšãæå³ãããbmap
ããŒãã«ééãããšãæ°ãããããã¯çªå·ãšãããåãæ¿ããå¿
èŠã«å¿ããŠå²ãåœãŠãè¡ã(5166-5167, 5174-5175è¡ç®)ã
itrunc
ã¯ãã¡ã€ã«ã®ãããã¯ã解æŸããinodeã®ãµã€ãºããŒãã«ãªã»ãããããitrunc
(5206è¡ç®)ã¯çŽæ¥ãããã¯ããŸãã¯è§£æŸã(5212-5217è¡ç®)ã次ã«éæ¥ãããã¯ã®ãªã¹ãã解æŸããŠãã(5222-5225è¡ç®)ããããŠæåŸã«éæ¥ãããã¯ãã®ãã®ã解æŸãã(5227-5228è¡ç®)ã
bmap
ã«ãããreadi
ããã³writei
ã«ãšã£ãŠinodeã®ããŒã¿ãååŸãããããªããreadi
(5252è¡ç®)ã¯ãªãã»ãããšã«ãŠã³ãããã¡ã€ã«ã®æåŸå°Ÿãè¶ããããšããªãããšã確èªããããã¡ã€ã«ã®æåŸå°Ÿãè¶ããŠèªã¿èŸŒã¿ãè¡ãå Žåã¯ãšã©ãŒãè¿ã(5263-5264è¡ç®)ããã¡ã€ã«ã®æåŸå°Ÿããèªã¿èŸŒãããããã¯ãã¡ã€ã«ã®æåŸå°Ÿãè¶ããŠèªã¿èŸŒãå Žåã¯ãèŠæ±ãããµã€ãºãããå°ãªããµã€ãºãè¿ã(5263-5266è¡ç®)ãã¡ã€ã³ã«ãŒãã¯ãã¡ã€ã«ã®åãããã¯ãåŠçãããããã¡ããããŒã¿ãdstã«ã³ããŒãã(5268-5273è¡ç®)ãwritei
(5302è¡ç®)ã¯readi
ãšäŒŒãŠãããã3ã€ã®ç°ãªãå Žæããã: writei
ã¯ãã¡ã€ã«ã®æåŸå°Ÿãè¶ããŠæžã蟌ãããšãããšããã¡ã€ã«ãæ¡å€§ããæ倧ãã¡ã€ã«ãµã€ãºãŸã§æ¡åŒµãã(5315-5316è¡ç®); ã«ãŒãã¯outã®ä»£ããã«ã«ããŒã¿ããããã¡ãžã³ããŒãã(5321è¡ç®);ãããŠãããã¡ã€ã«ãæžã蟌ã¿ã«ããæ¡åŒµããããšãwritei
ã¯ãµã€ãºãæŽæ°ããªããã°ãªããªã(5326-5329è¡ç®)ã
readi
ããã³writei
ã¯ip>type==T_DEV
ããã§ãã¯ãããšããããéå§ãããããã®ã±ãŒã¹ã¯ããã¡ã€ã«ã·ã¹ãã äžã«ååšããŠããªãç¹æ®ãªããã€ã¹ãªã©ãæäœãããšãã«å©çšããã; ãã¡ã€ã«èšè¿°éå±€äžã§ãã®ãããªå Žåã«ééãããšãé¢æ°ã¯ãã®å Žã§æ»ãã
é¢æ°starti
(4773è¡ç®)ã¯inodeã®ã¡ã¿ããŒã¿ãstart
æ§é äœã«ã³ããŒããããã«ããstart
ã·ã¹ãã ã³ãŒã«ã«ãããŠãŒã¶ããã°ã©ã ããåç
§ã§ããããã«ãªãã
ãã£ã¬ã¯ããªã¯ãå
éšçã«ã¯ãã¡ã€ã«ã®ããã«å®è£
ãããããã£ã¬ã¯ããªã®inodeã®ã¿ã€ãã¯T_DIR
ã§ããããã®ããŒã¿ã¯ãã£ã¬ã¯ããªãšã³ããªã®åã§ãããåãšã³ããªã¯struct dirent
(3950è¡ç®)ã§ãããããããã«ã¯ååãšinodeçªå·ãå
¥ã£ãŠãããååã¯æ®ã©ãDIRSIZ(14)ã§ãã; ãããããããçãããã°ãNUL(0)ã«ããçµç«¯ãããããã£ã¬ã¯ããªãšã³ããªã®inodeçªå·ããŒãã§ãããšãããã¯è§£æŸãããŠããã
dirlookup
(5361è¡ç®)ã¯äžãããååã®ãã£ã¬ã¯ããªãæ¢çŽ¢ãããããèŠã€ãã£ããªãã°ã該åœããinodeã®ãã€ã³ã¿ãè¿ããããã¯ã®è§£æŸãè¡ããåŒã³åºãå
ãç·šéãè¡ããããã°ããã£ã¬ã¯ããªã®ãšã³ããªã«ãã€ããªãã»ããã«*poff
ãèšå®ãããdirlookup
ãæ£ããååã®ãšã³ããªã掟é£ããã°ã*poff
ãæŽæ°ãããã®ãããã¯ãæŽæ°ããiget
ã«ããååŸããããã¯ã解æŸããinodeãè¿ããiget
ãããã¯ã解æŸããinodeãè¿ãçç±ããdirlookup
ã®ããã§ãããåŒã³åºãå
ãdp
ãããã¯ãããšãããæ¢çŽ¢ã.ãã€ãŸãçŸåšã®ãã£ã¬ã¯ããªã®ãšã€ãªã¢ã¹ã«å¯Ÿãããã®ã§ãããªãã°ãæ»ãé¢æ°ãdp
ãå床ããã¯ããããããã¯ãçããåã«inodeãããã¯ãã(è€æ°ã®ããã»ã¹ã«ããæ¢çŽ¢ãšã..ãã€ãŸã芪ãã£ã¬ã¯ããªã®æ¢çŽ¢ã«ã¯ã.ã®ã¿ãåé¡ãªã®ã§ã¯ãªããããè€éãªãããããã¯ã®ã·ããªãªãããã)åŒã³åºãå
ã¯dp
ãã¢ã³ããã¯ããããšãã§ã次ã«ipãããã¯ããäžåºŠã«äžã€ããããã¯ãä¿æããŠããªãããšãä¿èšŒããã
dirlink
(5402è¡ç®)é¢æ°ã¯äžããããååã®æ°ãããã£ã¬ã¯ããªãšã³ããªãšinodeçªå·ããã£ã¬ã¯ããªdpã«æžã蟌ãããããã®ååãæ¢ã«ååšãããšãdirlink
ã¯ãšã©ãŒãè¿ã(5408-5412è¡ç®)ãã«ãŒãã¯ãã£ã¬ã¯ããªãšã³ããªãèªã¿èŸŒã¿å²ãåœãŠãããŠããªããšã³ããªãæ¢çŽ¢ãããããã§ãªããã°ãã«ãŒãã¯çµäºããdp->size
ã«offãã»ããããŠçµäºãããã©ã¡ãã«ããŠããdirlink
ã¯æ°ãããšã³ããªã«å¯ŸããŠãªãã»ããoffãæžã蟌ãããšã§ãã£ã¬ã¯ããªã«æ°ãããšã³ããªãè¿œå ãã(5422-5425è¡ç®)ã
ãã¹åã®æ¢çŽ¢ã«ã¯ãdirlookup
ãé£ç¶ããŠåŒã³åºãããšã«ãªããããããã®åŒã³åºãã«ãããåãã¹ã®ã³ã³ããŒãã³ããæ¢çŽ¢ããããšã«ãªããnamei
(5540è¡ç®)ã¯pathãè©äŸ¡ãã該åœããinodeãè¿ããé¢æ°nameparent
ã¯å€æ°ã§ãã: ããã¯æåŸã®èŠçŽ ã®åã§åæ¢ãã芪ãã£ã¬ã¯ããªã®inodeãè¿ããæåŸã®èŠçŽ ãnameã«è¿ããã©ã¡ãã®åŒã³åºãããå®éã«åäœãããããã«ãnamex
ãšããé¢æ°ã«ããäžè¬åãããã
namex
(5505è¡ç®)ã¯ãã¹ã®è©äŸ¡ãã©ãããéå§ããããã決å®ããããããã¹ãã¹ã©ãã·ã¥ããå§ãŸãã®ã§ããã°ããã¹ã®æ¢çŽ¢ã¯ã«ãŒãããè¡ããã; ããã§ãªããã°ãçŸåšã®ãã£ã¬ã¯ããªããæ¢çŽ¢ãè¡ããã(5509-5512è¡ç®)ã次ã«skipelem
ã䜿ã£ãŠãã¹ã®åèŠçŽ ã«ã€ããŠèª¿æ»ãè¡ã(5514è¡ç®)ãåã«ãŒãã®ã€ã¿ã¬ãŒã·ã§ã³ã§ã¯ãçŸåšã®inode ipã«å¯ŸããŠnameãæ¢çŽ¢ããªããã°ãªããªããã€ã¿ã¬ãŒã·ã§ã³ã¯ãipãããã¯ãããšããããå§ãŸããããããã£ã¬ã¯ããªã§ãããããã§ãã¯ããããã£ã¬ã¯ããªã§ãªããã°ãæ¢çŽ¢ã¯å€±æã§ãã(5515-5519è¡ç®)ã(ipãããã¯ããã®ã¯ãip->type
ã足å
ãå€æŽããå¯èœæ§ãããããã§ã¯ãªã-ããã¯äžå¯èœã§ãã-ããããilock
ãåäœãããšãip->type
ã¯ãã£ã¹ã¯ããããŒããããŠããããšãä¿èšŒãããã®ã§ã¯ç¡ããªã)ã
ããåŒã³åºããnameiparent
ã§ããããããæåŸã®ãã¹èŠçŽ ã§ããã°ãã«ãŒãã¯nameiparent
ã®å®çŸ©ã®éãã«(xxx)ãããããåã«åæ¢ãã; æåŸã®ãã¹èŠçŽ ã¯æ¢ã«nameã«ã³ããŒãããŠãããããnamex
ã¯ããã¯ãããŠããªãipã®ã¿ãè¿ãå¿
èŠããã(5520-5524è¡ç®)ã
æåŸã«ãã«ãŒãã¯dirlookup
ãå©çšããŠãã¹èŠçŽ ãæ¢çŽ¢ããip=next
ãèšå®ããããšã§ã次ã®ã€ã¿ã¬ãŒã·ã§ã³ã«åãã(5525-5530è¡ç®)ãã«ãŒãããã¹èŠçŽ ã®æåŸãŸã§èµ°ãåããšãip
ãè¿ãã
Unixã€ã³ã¿ãã§ãŒã¹ã®ã¯ãŒã«ãªåŽé¢ã®äžã€ã¯ãUnixã®æ®ã©ã®è³æºã¯ãã¡ã€ã«ãšããŠè¡šçŸãããã³ã³ãœãŒã«ã®ãããªããã€ã¹ããã€ãããããŠå¿è«å®éã®ãã¡ã€ã«ããã¡ã€ã«ãšããŠè¡šçŸãããããã¡ã€ã«èšè¿°éå±€ã¯ãã®çµ±äžæ§ãå®çŸããããã®éå±€ã§ããã
第0ç« ã§èŠãããã«ãxv6ã¯åããã»ã¹ã§éãããã¡ã€ã«ãããã¡ã€ã«ãã£ã¹ã¯ãªãã¿ã®ããŒãã«ãæã£ãŠãããããããã®éãããã¡ã€ã«ã¯struct file
(4000è¡ç®)ãšããŠè¡šçŸãããŠãããinodeããã€ããããã«i/oãªãã»ããã®ã©ããã§ãããopen
ãåŒã³åºãããšã«ãã£ãŠãæ°ãããã¡ã€ã«(æ°ããstruct file
)ãéããã: ããè€æ°ã®ããã»ã¹ãåæã«åããã¡ã€ã«ãããããéãããšããŠããã°ãç°ãªãã€ã³ã¹ã¿ã³ã¹ãç°ãªãi/oãªãã»ãããæã£ãŠãããäžæ¹ã§ãäžã€ã®ããã»ã¹ã«ãã£ãŠéããããã¡ã€ã«(åäžã®struct file
)ã¯ãããã»ã¹ã®ãã¡ã€ã«ããŒãã«äžã«è€æ°åååšããããã¯è€æ°ã®ããã»ã¹ã®ããŒãã«ã«ååšãããããã«ãããããäžã€ã®ããã»ã¹ãope
nãå©çšããã¡ã€ã«ããªãŒãã³ããdup
ãå©çšããŠãšã€ãªã¢ã¹ãäœæããããfork
ã䜿ã£ãŠåããã»ã¹ãšå
±æããããšãæãåŸããäžã€ã®ãã¡ã€ã«ã¯èªã¿èŸŒã¿çšãšæžã蟌ã¿çšã«ãªãŒãã³ããããšãå¯èœã§ãããreadable
ãããã¯writable
ãã£ãŒã«ããããããèšé²ããŠããã
ã·ã¹ãã äžã®å
šãŠã®ãªãŒãã³äžã®ãã¡ã€ã«ã¯ãã°ããŒãã«ãªãã¡ã€ã«ããŒãã«ftable
ã«ä¿æãããŠããã
ãã¡ã€ã«ããŒãã«ã¯ããã¡ã€ã«ãå²ãåœãŠãããã®é¢æ°ãæã£ãŠãã(filealloc
)ãããã«ããè€æ°ã®åç
§ãäœæã(filedup
)ãfileclose
ã«ããåç
§ã解æŸããfileread
ãããã¯filewrite
ã«ããèªã¿æžããè¡ãã
æåã®3ã€ã®é¢æ°ã¯ãä»ã§ã¯ããªãã¿ã®åœ¢åŒãåã£ãŠãããfilealloc
(5025è¡ç®)ã¯ãã¡ã€ã«ããŒãã«ãã¹ãã£ã³ããå²ãåœãŠãããŠããªããã¡ã€ã«(f->ref==0
)ãæ¢ããæ°ããåç
§ãè¿ã;filedup
(5652è¡ç®)ã¯åç
§ã«ãŠã³ããã€ã³ã¯ãªã¡ã³ããã; fileclose
(5664è¡ç®)ã¯åç
§ã«ãŠã³ãããã¯ãªã¡ã³ãããããã¡ã€ã«ã®åç
§ã«ãŠã³ãããŒãã«ãªããšãfileclose
ã«ããã¿ã€ãã«å¿ããŠpipeãããã¯inodeã解æŸããã
é¢æ°filestat
,fileread
,filewrite
ã¯ãã¡ã€ã«ã«å¯Ÿããstat,read,write
ã®å®è£
ã§ãããfilestat
(5702è¡ç®)ã¯inodeã«å¯ŸããŠã®ã¿æäœãèš±ãããŠãããstati
ãåŒã³åºããfileread
ãšfilewrite
ã¯éããŠããã¢ãŒãã«å¿ããŠãã®æäœãèš±ãããŠãããã©ããããã§ãã¯ãããã€ããinodeã®å®è£
ã«å¯ŸããŠèŠæ±ãåãæž¡ãããããã¡ã€ã«ãinodeãšããŠè¡šçŸãããŠãããšãfileread
ãšfilewrite
ã¯i/oã¯ãã¡ã€ã«ã®æäœã®ããã«ãªãã»ãããçšãããã¡ã€ã«ãé²ãã(5725-5726,5765-5766è¡ç®)ããã€ãã¯ãªãã»ããã®æŠå¿µãç¡ããinodeã®é¢æ°ã«ã¯ãããã¯ãæãããå¿
èŠããã£ãããšãæãåºãã(5705-5707,5724-5727,5764-5778è¡ç®)ãinodeã®ããã¯ã¯äŸ¿å©ãªå¯äœçšãæã£ãŠãããreadãšwriteã®ãªãã»ãããã¢ãããã¯ã«æŽæ°ããããšããããšã§ãããåŸã£ãŠãåããã¡ã€ã«ãžåæã«è€æ°ã®æžã蟌ã¿ããã£ãå Žåã«ã¯ãããããã®ããŒã¿ã¯äžæžãããããããããã®æžã蟌ã¿ãæåŸã«ã€ã³ã¿ãŒã¬ãŒã¹ãããšããããšã«ãªãã
äœéå±€ãæ®ã©ã®ã·ã¹ãã ã³ãŒã«ãæäŸããé¢æ°ãçšããã®ã¯æ®éã®ããšã§ãã(sysfile.c
ãåç
§ã®ããš)ã
ããããããã€ãã®é¢æ°ã¯ãã調æ»ããªããã°ãªããªããã®ãããã
é¢æ°sys_link
ãšsys_unlink
ã¯ãã£ã¬ã¯ããªãç·šéããinodeã®äœæãåé€åç
§ãè¡ãããã©ã³ã¶ã¯ã·ã§ã³ãå©çšããåã®è¯ãäŸãããäžã€ååšãããsys_link
(5913è¡ç®)ã¯ãã®åŒæ°ããã§ãããããšããããå§ãŸãã2ã€ã®æååoldãšnewãæž¡ã(5918è¡ç®)ãold
ãååšããŠããããã£ã¬ã¯ããªã§ã¯ç¡ã(5922-5925è¡ç®)ãsys_link
ã¯ip->nlink
ã®ã«ãŠã³ããã€ã³ã¯ãªã¡ã³ãããã次ã«ãsys_link
ã¯nameiparent
ãåŒã³åºãã芪ãã£ã¬ã¯ããªãæ¢ããnewãšã¬ã³ãã®æçµçãªãã¹ãæ¢ã(5938è¡ç®),oldã®inodeãæãæ°ãããã£ã¬ã¯ããªãäœæãã:inodeçªå·ã¯ã1ã€ã®ãã£ã¹ã¯ã«ã€ã1ã€ã®æå³ããæã£ãŠããªãããããã®ãããªé¢ä¿ã§ãšã©ãŒãçºçãããšãsys_link
ã¯æ»ã£ãŠããŠãip->nlink
ããã¯ãªã¡ã³ãããã
ãã®ãããªå®è£
ã«ã¯ãè€æ°ã®ãã£ã¹ã¯ãããã¯ã®æŽæ°ãå¿
èŠã«ãªãããããã©ã³ã¶ã¯ã·ã§ã³ããã®å®è£
ãç°¡ååããŠãããããããã©ã®ãããªé çªã§å®è¡ãããã«ã€ããŠã¯èæ
®ããªããŠãè¯ããå
šãŠæåããããå
šãæåããªããã®2ã€ããååšããªããäŸãã°ããã©ã³ã¶ã¯ã·ã§ã³ãååšããªããã°ããªã³ã¯ãããã ãããåã«ip->nlink
ãæŽæ°ãããšããã¡ã€ã«ã·ã¹ãã äžã«äžæçã«éå®å
šãªç¶æ
ãäœã£ãŠããŸãããã®éã«ã¯ã©ãã·ã¥ãçºçãããšå€§æ害ãçºçããŠããŸãããã©ã³ã¶ã¯ã·ã§ã³ã§ã¯ããã®ãããªããšãèæ
®ããªããŠãè¯ãã
sys_link
ã¯æ¢åã®inodeã«æ°ããååãä»ãããcreate
é¢æ°(6057è¡ç®)ã¯æ°ããinodeã«å¯ŸããŠæ°ããååãä»ããããããã¯ã3ã€ã®ãã¡ã€ã«ãäœæããã·ã¹ãã ã³ãŒã«ã®äžè¬åã§ãã: openã¯O_CREATE
ãã©ã°ä»ãã®é¢æ°ã§ãæ°ãããã¡ã€ã«ãäœæãããmkdir
ã¯æ°ãããã£ã¬ã¯ããªãäœæããmkdev
ã¯æ°ããããã€ã¹ãã¡ã€ã«ãäœæãããsys_link
ãcreate
ã¯nameiparent
ãåŒã³åºãæããå§ãŸãã芪ãã£ã¬ã¯ããªã®inodeãååŸããã次ã«ãdirlookup
ãåŒã³åºãããã®ååãæ¢ã«ååšããŠãããããã§ãã¯ãã(6067è¡ç®)ããããã®ååãååšãããšãcreate
ã®åäœã¯ãã·ã¹ãã ã³ãŒã«ãã©ã®ãããªç®çã®ããã«å©çšãããŠãããã«ãã£ãŠåäœãå€ãã:openã¯mkdir
ãšmkdev
ã®2ã€ã®æå³ãæã£ãŠãããããcreate
ãopenã®å€ããã«åŒã³åºãã(type==T_FILE)
ãéåžžã®ãã¡ã€ã«èªèº«ãšããŠååšãããªãã°ãopenã¯æåãšããŠåäœããcreate
ãåæ§ã«åäœãã(6071è¡ç®)ãããã§ãªããã°ããšã©ãŒãšããŠåäœãã(6072-6073è¡ç®)ããããã®ãã¡ã€ã«åãååšããŠããªããã°ãcreate
ã¯æ°ããinodeãialloc
ãå©çšããŠå²ãåœãŠã(6076è¡ç®)ãããæ°ããinodeããã£ã¬ã¯ããªã§ããã°ãcreate
ã¯.ãš..ã®ãšã³ããªãåæåãããæåŸã«ãããŒã¿ãåæåããããããªç¹æ§ãæã£ãŠããã°ãcreate
ã¯èŠªãã£ã¬ã¯ããªã«ãªã³ã¯ãè¡ã(6089è¡ç®)ãsys_link
ã®ãããªcreate
ã¯2ã€ã®inodeãåæã«ããã¯ãã: ipãšdpã§ãããinode ipã¯æ°ãã«å²ãåœãŠããããã®ã§ããããããããã¯ãããããã¯ããå¯èœæ§ã¯ç¡ã:ã·ã¹ãã äžã®ãã以å€ã®ãã¡ã€ã«ipã®ããã¯ãããããšããããç¥ããªãããdpãããã¯ããããšã¯ç¡ãã
create
ãå©çšããããšã§ãsys_open
,sys_mkdir
,sys_mknod
ã®å®è£
ãç°¡åã«ãªããsys_open
(6101è¡ç®)ã¯æãè€éã§ãããäœæ
ãªãã°æ°ãããã¡ã€ã«ã®äœæã¯ããããããããšã®ã§ããæ©èœã®äžéšã ããã§ãããopenãO_CREATE
ãã©ã°ãšå
±ã«æž¡ãããã°ãcreate
(6114è¡ç®)ãåŒã³åºããããã§ãªããã°ãnamei
(6120è¡ç®)ãåŒã³åºããcreate
ã¯ããã¯ãããinodeãè¿ãããnamei
ã¯ããã§ã¯ãªããåŸã£ãŠãsys_open
ã¯èªã¿åºãã®ããã ãã«å©çšãããæžã蟌ã¿ã«ã¯å©çšãããªããinodeãäžã€ã®æ¹æ³ããã以å€ã§ããå
¥æã§ããªãã£ããšä»®å®ãããšãsys_open
ã¯ãã¡ã€ã«ãšãã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãå²ãåœãŠ(6132è¡ç®)ããã¡ã€ã«ãåãã(6142-6146è¡ç®)ãçŸåšã®ããã»ã¹ããŒãã«ã«ã®ã¿ååšããããããã以å€ã®ããã»ã¹ã¯éšåçã«ããåæåã¯ãããªãããšã«æ³šæããã
第5ç« ã§ã¯ãç§éããã¡ã€ã«ã·ã¹ãã ã«ã€ããŠåŠã¶åã«ãã€ãã®å®è£
ã«ã€ããŠèª¿æ»ãããsys_pipe
é¢æ°ã¯ãã¡ã€ã«ã·ã¹ãã ã«å®è£
ãæ¥ç¶ãããã€ãã®ãã¢ãäœæããæ©èœãæäŸããããã®åŒæ°ã¯2ã€ã®æŽæ°ã®ããã®ç©ºéãžã®ãã€ã³ã¿ã§ããã2ã€ã®æ°ãããã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãæäŸããã次ã«ããã€ããå²ãåœãŠããã¡ã€ã«ãã£ã¹ã¯ãªãã¿ãèšçœ®ããã
çŸå®äžçã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãæã£ãŠãããããã¡ãã£ãã·ã¥ã¯xv6ã®ãã®ãããè€éã ããåæ§ã«2ã€ã®ç®çã®ããã«å®è£ ãããŠãã:ãã£ã¹ã¯ãžã®ã¢ã¯ã»ã¹ããã£ãã·ã¥ããåæã¢ã¯ã»ã¹ãå®çŸãããšãããã®ã§ãããxv6ã®ãããã¡ãã£ãã·ã¥ã¯V6ã®ããã«ãã·ã³ãã«ãªLeast Recently Used(LRU)ã®ããªã·ã§å®è£ ãããŠãã;ããè€éãªå ¥ãæ¿ãã®ããªã·ã§å®è£ ãããããšãã§ããããã©ã®å®è£ ãåªããŠãããã¯ç¶æ³ã«äŸåããã ããå¹ççãªLRUãã£ãã·ã¥ã¯ãªã³ã¯ãªã¹ããé€å»ããæ¢çŽ¢ã®ããã«ããã·ã¥ããŒãã«ãçšããŠãLRUã®çœ®ãæãã®ããã«ããŒãæ§é ãå©çšããŠãããçŸä»£ã®ãããã¡ãã£ãã·ã¥ã¯ã¡ã¢ãªããããã¡ã€ã«ããµããŒãããããã«ä»®æ³ã¡ã¢ãªã·ã¹ãã ãçµ±åããŠããã
xv6ã®ãã®ã³ã°ã·ã¹ãã ã¯éå¹çã§ãããã³ãããã¯ãã¡ã€ã«ã®å¯ŸããŠãã·ã¹ãã ã³ãŒã«ã䜿ã£ãŠåæã«çºçãããããšãã§ããªããã·ã¹ãã ã¯ããããã¯äžã®å ããªãã€ããæžãæããããšããŠãããããã¯å šäœããã°ãããåæã«åæçãªãã°ã®æžã蟌ã¿ãè¡ããããããã¯ãã£ã¹ã¯å šäœãå転ãããæéãèŠãããå®éã®ãã®ã³ã°ã·ã¹ãã ã¯ãã®ãããªåé¡ã«å šãŠçŠç¹ãåœãŠãŠããã
ãã£ãã·ã¥ãªã«ããªããµããŒãããããã«ã¯ããã®ã³ã°ã¯å¯äžã®æ¹æ³ã§ã¯ãªããåæã®ãã¡ã€ã«ã·ã¹ãã ã¯åèµ·åã®éã¯Scavengerãå©çšããŠãã(äŸãã°ãUNIXã®fsck
ããã°ã©ã ãªã©)ãããã«ãããå
šãŠã®ãã¡ã€ã«ãšãã£ã¬ã¯ããªããããã¯ãšinodeããªãŒãªã¹ãããã§ãã¯ããæ¢çŽ¢ãšèª€ã£ãŠããéšåã®ä¿®åŸ©ãè¡ã£ãŠãããscanvengingã¯å€§ããªãã¡ã€ã«ã·ã¹ãã ã§ã¯æéãããã£ãŠããŸããããã«ãªãªãžãã«ã®ã·ã¹ãã ã³ãŒã«ãã¢ãããã¯ãªåäœãããæ¹æ³ã§ã¯ãã·ã¹ãã äžã®ççŸã解決ã§ããªãããšããã£ãããã°ã䜿ã£ãå埩ã®æ¹æ³ã¯ããé«éã§ãããã¯ã©ãã·ã¥ããå Žåã«ã¯ã·ã¹ãã ã³ãŒã«ãã¢ãããã¯ã«åäœãããããšãã§ãã(xxx)ã
6ã¯åæã®UNIXãæ¡çšããŠããinodeãšãã£ã¬ã¯ããªã®ãã£ã¹ã¯äžåºæ¬ã¬ã€ã¢ãŠããšåããã®ãå©çšããŠãã; ãã®æ§é ã¯é·å¹Žç¶æãããŠãããBSDã®UFS/FFSãšLinuxã®ext2lext3ã¯åºæ¬çã«ãããšåããã®ãå©çšããŠããããã®ãã¡ã€ã«ã·ã¹ãã ã®ã¬ã€ã¢ãŠãã®æãå¹çã®æªããšããã¯ãã£ã¬ã¯ããªã§ããããã£ã¬ã¯ããªã®æ¢çŽ¢ã«ã¯å šãŠã®ãã£ã¹ã¯ãããã¯ã®ç·åœ¢ã¹ãã£ã³ãå¿ èŠã§ãããããã¯ãã£ã¬ã¯ããªããã£ã¹ã¯ãããã¯äžã«ãããããååšããªãå Žåã¯åŠ¥åœãªæ§æã§ãããããã£ã¬ã¯ããªäžã«è€æ°ã®ãã¡ã€ã«ãååšããå Žåã¯é«äŸ¡ãªå®è£ ã§ãããMicrosoftã®NTFS,Mac OX Xã®HFS, Solarisã®ZFSã¯ããã£ã¬ã¯ããªã®ãã©ã³ã¹æšã®æ§é ã§å®è£ ããŠããã ãã®å®è£ ã¯è€éã§ããããã£ã¬ã¯ããªã®æ¢çŽ¢ã察æ°æéã§å®è¡ããããšãã§ãããxv6ã¯ãã£ã¹ã¯æäœã®å€±æã«å¯ŸããŠææã§ãã: ãããã£ã¹ã¯æäœã倱æãããšãxv6ã¯ãããã¯ãèµ·ãããŠããŠã³ãããããã劥åœãªæ¹åŒã§ãããã©ããã¯ãããŒããŠã§ã¢ã«äŸåãã: ãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãåé·ã«ãã£ã¹ã¯ã®å€±æããã¹ã¯ããç¹å¥ãªããŒããŠã§ã¢ã®äžã§åäœããŠããã®ã ãšãããããããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯å€±æããããšã¯é »ç¹ã§ã¯ãªããªãããããã¯ãçºçããããšèªäœã¯åé¡ã§ã¯ãªããªãã
äžæ¹ã§ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãæšæºçãªãã£ã¹ã¯ãå©çšããŠããå Žåã¯ããã£ã¹ã¯æäœã®å€±æãæ€åºããå¿ èŠããããããäžå¯§ã«å¯ŸåŠããå¿ èŠãããããã£ãŠããã¡ã€ã«äžã®ãããã¯ã®ãã¹ã¯æ®ãã®ãã¡ã€ã«ã·ã¹ãã ã®å©çšã«ã¯åœ±é¿ãäžããªããxv6ã¯ããã¡ã€ã«ã·ã¹ãã ã¯ãã£ã¹ã¯ããã€ã¹ã«ãã£ããããå¿ èŠãããããã®ãµã€ãºã¯å€åããªãããšãåæã«ããŠããã
ãã倧ããªããŒã¿ããŒã¹ããã«ãã¡ãã£ã¢ãã¡ã€ã«ãå¿ èŠãªã«ããã¹ãã¬ãŒãžã®ãµã€ãºãå¢å ãããªããã°ãªããªãå Žåããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã¯ããã¡ã€ã«ã·ã¹ãã ããã1ã€ã®ãã£ã¹ã¯ããšããå¶çŽãåãé€ããªããã°ãªããªããåºæ¬çãªã¢ãããŒãã¯å€§ãã®ãã£ã¹ã¯ãéããŠãäžã€ã®è«ççãªãã£ã¹ã¯ãšããããšã§ããã ããŒããŠã§ã¢çãªè§£æ±ºæ³ãšããŠã¯ãRAIDã®ãããªæ¹åŒãæãæåã§ããããçŸåšã®ãã¬ã³ãã¯ãå¯èœãªéããœãããŠã§ã¢ãçšããŠãã£ã¹ã¯ã®ãŸãšããå®çŸããããšã§ããããããã®ãœãããŠã§ã¢ã®å®è£ ã¯ãå žåçã«ãè«ççãªãã£ã¹ã¯ã®å¢å ãçž®éãªã©ããªã³ã¶ãã©ã€ã«å®çŸã§ãããããªãªãããªæ©èœãæã£ãŠããã ãã¡ããããªã³ã¶ã€ãã©ã€ã«ãã£ã¹ã¯ã®æ¡åŒµãçž®å°ãå®çŸã§ããã¹ãã¬ãŒãžéå±€ã«ã¯ãåæ§ã®ããšãå®çŸã§ãããã¡ã€ã«ã·ã¹ãã ãå¿ èŠã§ãã:xv6ãå©çšããŠããåºå®ãµã€ãºã®inodeãããã¯ã§ã¯ããã®ãããªç°å¢ã§ã¯ããŸãåäœããªãããã£ã¹ã¯ç®¡çããã¡ã€ã«ã·ã¹ãã èªäœããåé¢ãããã®ããæã綺éºãªå®è£ ã§ãããã ã€ã³ã¿ãã§ãŒã¹éãè€éã«ãªããSunã®ZFSããããããçµã¿åãããããªããã€ãã®å®è£ ãå¿ èŠã«ãªãã
xv6ã®ãã¡ã€ã«ã·ã¹ãã ã«ã¯çŸä»£ã®ãã¡ã€ã«ã·ã¹ãã ã®å€ãã®æ©èœãæ¬ èœããŠãã; äŸãã°ãã¹ãããã·ã§ãããšãã€ã³ã¯ãªã¡ã³ã¿ã«ãªããã¯ã¢ããã®ãµããŒããæããŠãããçŸä»£ã®UNIXã®ã·ã¹ãã ã¯ãåäžã®ã·ã¹ãã ã³ãŒã«ãå©çšããŠãã£ã¹ã¯äžã®å€ãã®çš®é¡ã®è³æºã«ã¢ã¯ã»ã¹ããããšãã§ããããã«ãµããŒããããŠãã:
ååä»ããã€ããããããã¯ãŒã¯æ¥ç¶ãããªã¢ãŒãæ¥ç¶ã®ãããã¯ãŒã¯ãã¡ã€ã«ã·ã¹ãã ãã/procã®ãããªç£èŠãšå¶åŸ¡ã€ã³ã¿ãã§ãŒã¹ã§ãããxv6ã®fileread
ããã³filewrite
ã®ifæã®ä»£ããã«ããããã®ã·ã¹ãã ã§ã¯å
žåçã«ãªãŒãã³ãããã¡ã€ã«ã®é¢æ°ãã€ã³ã¿ã®ããŒãã«ãæã£ãŠããããã®é¢æ°ãã€ã³ã¿ãåŒã³åºãããšã«ãã£ãŠããã®inodeã®å®è£
ã«å¯Ÿããæ©èœãåŒã³åºãããšãã§ããããããã¯ãŒã¯ãã¡ã€ã«ã·ã¹ãã ãšãŠãŒã¶ã¬ãã«ãã¡ã€ã«ã·ã¹ãã ã§ã¯ããããã®åŒã³åºãããããã¯ãŒã¯ã®RPCã«å€æããé¢æ°ããæ»ãåã«ã¬ã¹ãã³ã¹ãåŸ
ã€ãšããæ©èœãè¿œå ãããŠããã
- äœæ
balloc
ã§ã¯panicãèµ·ããããã«ãªã£ãŠããã®ãïŒxv6ã¯å埩ã§ãããïŒ - äœæ
ialloc
ã§ã¯panicãèµ·ããããã«ãªã£ãŠããã®ãïŒxv6ã¯å埩ã§ãããïŒ - äœæ
filealloc
ã¯ãã¡ã€ã«å€ã®å ŽæãæäœããŠãpanicãèµ·ãããªãããã«ãªã£ãŠããã®ãïŒäœæ ããã¯äžè¬çãªã®ããããã¯ãã³ããªã³ã°ãã䟡å€ããããïŒ - ipã«çžåœãããã¡ã€ã«ãä»ã®
sys_link
ã®åŒã³åºããšiunlock
(ip)ãšdirlink
ã®éã«ä»ã®ããã»ã¹ã«ããã¢ã³ãªã³ã¯ãåãä»ãããšããããªã³ã¯ã¯æ£ããçæããããïŒããã§ãªãå Žåã¯äœæ ãïŒ create
ã¯4ã€ã®é¢æ°åŒã³åºããçºçããã(1ã€ã¯ialloc
ãããæ®ãã¯dirlink
ãã)ãããäžã€ãæåããªãã£ãããcreate
ã¯panicãåŒã³åºããäœæ ããã¯åŠ¥åœãªèšèšãªã®ãïŒäœæ ãããã®4ã€ã®ããããã®åŒã³åºãã倱æããããšãã§ããªãã®ãïŒ- sys_chdirã¯
iput(cp->cwd)
ãåŒã³åºãåã«iunlock(ip)
ãåŒã³åºããcp->cwd
ãããã¯ãããããšããããiput
ã®åŸã«iunlock(ip)
ãåŒã³åºãããšãããšãããããã¯ãããäœæ ãããªãã®ãïŒ