UNIX 6th code reading - ãã¡ã¤ã«ã·ã¹ãã æ¦è¦
ã¯ããã«
ä»åããUNIX v6ã®ãã¡ã¤ã«ã·ã¹ãã ãè¦ã¦ããã¾ãã
ãããªãLionsæ¬18ç« ãèªã¿è§£ãã¦ããã®ã¯é£ããã¨æããã®ã§ãã¾ãã¯ãã¡ã¤ã«ã·ã¹ãã ã®æ¦è¦ãã¾ã¨ãã¦ã¿ã¾ããã
ä»åã¯ãããã¯ããã¤ã¹ä¸ã§ã®å¦çãä¸å¿ã«ã¾ã¨ãã¦ããã¾ãã次åã¯ã³ã¢ã¡ã¢ãªä¸ã§ã®å¦çãã¾ã¨ãããã¨æã£ã¦ãã¾ãã
ãããã¯ããã¤ã¹
ãããã¯ããã¤ã¹ã®å é #0ã¯ãã¼ãããã°ã©ã ãªã©ã«ä½¿ããã¾ãã
次ã®#1ã¯super blockã¨å¼ã°ãããããã¯ã§ããã®ããã¤ã¹ã®æ å ±ãå«ã¾ãã¾ããfilsysæ§é ä½(5561è¡ç®)ãåèã«ãã¦ãã ããã
ãã®å¾ã®#2ã#n+1ã¾ã§ã¯inodeã§å ãããã¾ããinodeã¯ãã¡ã¤ã«ã®æ å ±ãæã£ããã¼ã¿ã§ããã¡ã¤ã«ãµã¤ãºããã¼ããã·ã§ã³ãæ´æ°æ¥æã対å¿ãããã¡ã¤ã«ãã¼ã¿ã®ã¢ãã¬ã¹ãªã©ãæã¡ã¾ããå¾è¿°ãã¾ããããã¡ã¤ã«åã¯æã£ã¦ãã¾ããã
ã¾ããi_numberã¨ãã¦ãinodeèªä½ã®ãã³ãã¼ãæã£ã¦ãããããã¯ãããã¯ããã¤ã¹ä¸ã®ã¢ãã¬ã¹ã¨ä¸å¯¾ä¸ã«å¯¾å¿ãã¾ãã(ã¢ãã¬ã¹ããi_numberã決ã¾ãã®ã§ãi_numberèªä½ã¯ãããã¯ããã¤ã¹ä¸ã«ã¯è¨é²ããã¾ããã)
inodeãæã£ã¦ãããã¼ã¿ã¯5605è¡ç®ã§å®ç¾©ããã¦ããinodeæ§é ä½ãåç §ãã¦ãã ããã5659è¡ç®ã§å®ç¾©ããã¦ããinodeæ§é ä½ã¯ã³ã¢ã¡ã¢ãªä¸ã§ã®å®ç¾©ã§ãã®ã§ã注æãã
inodeã¯32bytesã§ã1ãããã¯(512bytes)ä¸16åã®inodeãåå¨ãã¾ãããªã®ã§ãããi_number = iã®inodeãåå¨ãããããã¯ã¯(i+31)/16ã§è¡¨ããããããã¯ä¸ã®ã¢ãã¬ã¹ã¯32*((i+31)%16)ã§è¡¨ããã¾ãã
inodeãããã¡ã¤ã«ãã¼ã¿ã¸ã®ã¢ãã¬ã¹ãããã³ã°
ã¦ã¼ã¶ããã¥ã¢ã«ã®FILE SYSTEM(V)ã«è©³ããæ¸ããã¦ããã®ã§ã覧ãã ããã
ãããã³ã°ã¯å¤§ããããã§ä¸ç¨®é¡ããã¾ãã
- ç´æ¥åç §
- éæ¥åç §
- äºééæ¥åç §
ä¸ããé ã«æ±ãããã¡ã¤ã«ãµã¤ãºã大ãããªãã¾ãã
ç´æ¥åç §
ç´æ¥åç §ã¯ãinodeã®flags 010000(large fileãã©ããã®ãã©ã°)ã0ã®ã¨ãã«é©ç¨ããã¾ãã
ãã¡ã¤ã«ä¸ã®ã¢ã¯ã»ã¹ããããã¤ããªãã»ããNã512ã§å²ãããããbã¨ããã(large fileã§ãªãã¨ãã¯)bã7以ä¸ã®ã¯ãã§ãããinodeã®addr[b]ã«è©²å½ã®ããã¤ã¹ãããã¯Noãæ ¼ç´ããã¦ãã¾ãã
ç´æ¥åç §ã§æ±ããæ大ã®ãã¡ã¤ã«ãµã¤ãºã¯512 x 8 = 4,096bytes = 4KB??
éæ¥åç §
éæ¥åç §ã¯inodeã®flags 010000ã1ã®æã«é©ç¨ããããã¤ãä¸è¨bã256ã§å²ã£ãå¤ã6以ä¸ã§ããå ´åã«é©ç¨ããã¾ãã
bã256ã§å²ã£ãå¤ãiã¨ããã¨ãinodeã®addr[i]ã«ã¯éæ¥åç §ãããã¯ã®ã¢ãã¬ã¹ãæ ¼ç´ããã¦ãã¾ãã(éæ¥åç §ãããã¯ã¯ãããã¤ã¹ã®inodeã®ã¨ãªã¢ã¨ãã¡ã¤ã«ãã¼ã¿ã®ã¨ãªã¢ã©ã£ã¡ã«æ ¼ç´ããã¦ãããã ãããinodeã®ã¨ãªã¢ï¼ï¼)
ãã®ãããªã³ã¡ã³ããé ãã¾ãããéæ¥åç §ãããã¯ã¯ãã¼ã¿ã¨ãªã¢ã«ããããã§ãã
Nãå²ã£ããã¾ããããéæ¥åç §ãããã¯ã®ä¸ã®ãªãã»ããã決ã¾ããããã«ã¯ããã¤ã¹ã®ãããã¯Noãæ ¼ç´ããã¦ãã¾ãã
éæ¥åç §ã§æ±ããæ大ã®ãã¡ã¤ã«ãµã¤ãºã¯512 x 256 x 7 = 917,504bytes = 896KB??
äºééæ¥åç §
äºééæ¥åç §ã¯inodeã®flags 010000ã1ã®æããã¤ãä¸è¨iã7ã§ããã¨ãã«é©ç¨ããã¾ãã
inodeã®addr[7]ã«ã¯éæ¥åç §ãããã¯ã®å é ã¢ãã¬ã¹ãæ ¼ç´ããã¦ãã¾ããããã¦ããã®éæ¥åç §ãããã¯ã®ããããã®ãã¼ã¿ã¯ãäºééæ¥åç §ãããã¯ã®ã¢ãã¬ã¹ãæãã¦ãã¾ãã
äºééæ¥åç
§ã§æ±ããæ大ã®ãã¡ã¤ã«ãµã¤ãºã¯512 x 256 x 256 = 33,554,432bytes = 32MBãªã®ã§ããããã¡ã¤ã«ã®å¤§ããã24bitsã§ä¿åããã¦ãããããå®è³ªã¯16,777,216bytes = 12MBã¾ã§ããæ±ããªãããã§ãã
ããã«ããã®ãããªã³ã¡ã³ããé ãã¾ããã確ãã«ãã£ã¹ã¯èªä½ã®ãµã¤ãºä¸éãèæ ®ããªãã¨ããã¾ãããããã£ã¹ã¯èªä½ã«32MBã®å¶éãããã®ã§ãaddr[0]ãaddr[7]å ¨ã¦ã§äºééæ¥åç §ã使ãå¿ è¦ããªããaddr[7]ããã®ã¿äºééæ¥åç §ã使ãè¨è¨ã«ãªã£ã¦ããã®ããããã¾ããã
ããã«ããã«ããã®ãããªã³ã¡ã³ããé ãã¾ããã
äºééæ¥åç §ã使ã£ã¦ããã¨ã(addr[7]=1ã®ã¨ã)ã§ããaddr[0-6]ã®éæ¥åç §ã使ã£ã¦ããããã§ãã
ãã®ããã«æã£ã¦ããã®ã§ãããäºééæ¥åç §åä½ã§æ±ããmax sizeã32MBã¨ãããã¨ã¿ããã§ãã
ä¸è¨ä¸ç¨®ã®åç §æ¹æ³ãçµµã§ã¾ã¨ãã¦æãã¨ãããªæãã§ãã
ãã®ãããã³ã°ã¯bmap( )(6415è¡ç®)ã§å¦çãããã¦ã¼ã¶ããã»ã¹ã¬ãã«ã§ç´æ¥æèãããã¨ã¯ãªãã¨æãã¾ãã
ãã£ã¬ã¯ããª
åãã¡ã¤ã«ã¯ãã¡ã¤ã«ã®ãã¹åã§ã¢ã¯ã»ã¹ã§ããããã«ãªã£ã¦ãã¾ãããã¹åããinodeãåå¾ã§ãã¾ãããã¹åããinodeã¸ã®å¤æã¯namei( )(7518è¡ç®)ã§å¦çããã¾ãã
ãã¡ã¤ã«é¡ã¯ã«ã¼ããã£ã¬ã¯ããªãé ç¹ã¨ããæ¨æ§é ã§è¡¨ããã¾ãããã£ã¬ã¯ããªã¯é ä¸ã«ãã¡ã¤ã«ãæã¦ã¾ããåãã£ã¬ã¯ããªã»ãã¡ã¤ã«ã®ã¢ã¯ã»ã¹è¨±å¯ããªãã¨ã¢ã¯ã»ã¹ã§ãã¾ãã(ãã¼ããã·ã§ã³)ã
(æ¬å½ã¯ãªã³ã¯(ã·ã³ããªãã¯ãªã³ã¯ããã¼ããªã³ã¯)ãããã®ã§ãç´ç²ãªæ¨æ§é ã§ã¯ãªããä¸ããä¸ã¸ãã©ããã¹ãåå¨ãã¦ãã¾ãã)
ããã¦ãé ããã³ã¡ã³ããåæ²ã
åãã£ã¬ã¯ããªã¯ãã¡ã¤ã«åã¨inumber(inodeã®çªå·)ã®å¯¾å¿é¢ä¿ã表ãããã¼ãã«ãæã£ã¦ãã¾ãããããªæãã«ã
name | inumber |
---|---|
. | 16 |
.. | 44 |
fuga | 60 |
hoge | 80 |
homu | 122 |
ãã£ã¬ã¯ããªããã®inode(inumber)ã表ããã¡ã¤ã«åãæã£ã¦ããã ãã§ããã¡ã¤ã«ãã¼ã¿ãinodeèªä½ã¯ãã¡ã¤ã«åãæã£ã¦ããªããã¨ã«æ³¨æãã¦ãã ããã
ã¾ããä¸è¨ã®namei( )ã¯ãã«ã¼ãããããããã¯ã«ã¬ã³ããã£ã¬ã¯ããªãèµ·ç¹ã¨ãã¦ããã¹åã®æåãã1è¦ç´ ãã¤inodeãåå¾ãããã£ã¬ã¯ããªã®ä¸ãè¦ã¦ã¯è©²å½ã®inodeãåå¾ããããã«ãã®ä¸ãè¦ã¦â¦â¦ã¨ç¹°ãè¿ãã¦ç®çã®ãã¡ã¤ã«ã»ãã£ã¬ã¯ããªã®inodeãåå¾ãã¾ãã
çµããã«
ä»åã¯ãããã¯ããã¤ã¹ä¸ã®å¦çãä¸å¿ã¨ãããã¡ã¤ã«ã·ã¹ãã ã«ã¤ãã¦ã¾ã¨ãã¦ã¿ã¾ããã次åã¯ã³ã¢ã¡ã¢ãªä¸ã§ã®å¦çãä¸å¿ã¨ããã¾ã¨ããæ¸ãäºå®ã§ãããã®å¾ãLionsæ¬ã®18ç« ä»¥éãèªã¿è§£ãã¦è¡ããã¨æã£ã¦ãã¾ãã
superblockããã¦ã³ãã®è©±ãinodeã»ãã¡ã¤ã«ãã¼ã¿ãããã¯ã®å²ãå½ã¦ã¢ã«ã´ãªãºã ã«ã¤ãã¦ã話ããæ¹ãããã£ãã®ããããã¾ãããããããã¯Lionsæ¬ã®è©²å½ããç« ã§è§¦ãã¾ãã®ã§ãã°ããå¾ ã¡ãã