Minix File System

  • View
    220

  • Download
    0

Embed Size (px)

Text of Minix File System

  • 8/10/2019 Minix File System

    1/38

    M i n i x F i l e S y s t e m

    C S C 3 1 5 0

    D r . J o h n C . S . L u i

    A b s t r a c t

    I n t r o d u c t i o n t o M i n i x F i l e S y s t e m

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i

  • 8/10/2019 Minix File System

    2/38

    S u p p l e m e n t a r y N o t e : T h e M i n i x F S

    O v e r v i e w o f M i n i x F S

    M i n i x F S i s j u s t a b i g C p r o g r a m r u n s i n a u s e r

    s p a c e .

    u s e r p r o c e s s e s s e n d m e s s a g e s t o t h e F S t e l l i n g w h a t

    t h e y w a n t d o n e . T h e F S d o e s t h e w o r k a n d s e n d s

    b a c k a r e p l y . I t c a n b e u s e d a s a n e t w o r k l e s e r v e r !

    O v e r v i e w o f M i n i x F S 1 ) m e s s a g e s , 2 ) F S l a y o u t , 3 )

    i - n o d e s , 4 ) b l o c k c a c h e , 5 ) b i t m a p s , 6 ) d i r e c t o r i e s

    a n d p a t h n a m e s , 7 ) t h e p r o c e s s t a b l e , 8 ) p i p e l e s ,

    9 ) i n t e g r a t i o n .

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i 1

  • 8/10/2019 Minix File System

    3/38

  • 8/10/2019 Minix File System

    4/38

    F S h a s a m a i n l o o p t h a t w a i t s f o r a m e s s a g e t o

    a r r i v e , m e s s a g e t y p e w i l l b e e x t r a c t e d a n d u s e d a s a n

    i n d e x i n t o a t a b l e c o n t a i n i n g p o i n t e r s t o p r o c e d u r e s

    w i t h i n t h e F S t h a t h a n d l e t h e r e q u e s t . W h e n d o n e ,

    r e t u r n s t a t u s .

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i 3

  • 8/10/2019 Minix File System

    5/38

    F S l a y o u t

    T h e M i n i x F S i s a l o g i c a l , s e l f - c o n t a i n e d e n t i t y w i t h

    i - n o d e s , d i r e c t o r i e s a n d d a t a b l o c k s . E x a m p l e o f a

    3 6 0 K l a y o u t w i t h 1 2 7 i - n o d e s a n d 1 K b l o c k s i z e .

    F i g u r e 5 . 3 0 .

    ~~

    ~~

    Bootblock

    Superblock I-nodes one disk block

    I-nodebit map

    Zonebit map Data

    Figure 5.30: Minix FS Layout

    B o o t b l o c k . W h e n a c o m p u t e r i s t u r n e d o n , t h e

    h a r d w a r e r e a d s t h e b o o t b l o c k i n t o m e m o r y a n d

    j u m p t o i t .

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i 4

  • 8/10/2019 Minix File System

    6/38

    s u p e r - b l o c k c o n t a i n s i n f o r m a t i o n a b o u t l e s y s t e m

    l a y o u t . F i g u r e 5 . 3 1 .

    Numer of nodesNumber of zones

    Number of i-node bit map blocksNumber of zone bit map blocks

    First data zoneLog 2(zone size/block size)

    Maximum file sizeMagic numberPointer to i-node bit map block

    Super-blocks device number

    I-node of mounted file system

    I-node mounted onTime of last update

    Read-only flag/Dirty flag

    . . . .

    Pointer to zone bit map block . . . .

    Presenton disk and inmemory

    Presentin memory

    but noton disk

    11011011101101110011011011101111

    . . . . . . .

    01011011101101110011011011101110

    . . . . . . .

    I-node bit map

    Zone bit map

    Figure 5.31: The MINIX super-block

    G i v e n b l o c k s i z e a n d n u m b e r o f i - n o d e s . I t i s e a s y

    t o c o m p u t e t h e s i z e o f i - n o d e b i t m a p a n d n u m b e r

    o f b l o c k s f o r i - n o d e s . F o r e x a m p l e , w i t h 1 K b l o c k

    s i z e , e a c h b l o c k o f b i t m a p s c a n i n d i c a t e s t a t u s o f

    8 1 9 1 i - n o d e s . I f i - n o d e s a r e o f 3 2 - b y t e s , e a c h b l o c k

    h o l d s 3 2 i - n o d e s , t h e r e f o r e , 1 2 7 i - n o d e s n e e d 4 d i s k

    b l o c k s .

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i 5

  • 8/10/2019 Minix File System

    7/38

    d i s k s t o r a g e i s a l l o c a t e d i n u n i t s ( z o n e s ) o f 1 , 2 , 4 , 8

    o r i n g e n e r a l , 2

    n

    b l o c k s .

    m a p p i n g f r o m z o n e t o b l o c k o r v i c e v e r s a c a n b e

    d o n e b y a l g o r i t h m . F o r e x a m p l e , w i t h 8 b l o c k s p e r

    z o n e , t o n d z o n e c o n t a i n i n g b l o c k 1 2 8 , j u s t s h i f t

    1 2 8 r i g h t b y 3 b i t s .

    w h e n M i n i x i s b o o t e d , t h e s u p e r - b l o c k f o r t h e r o o t

    d e v i c e i s r e a d i n t o a t a b l e c a l l e d s u p e r - b l o c k s t a b l e .

    N e w p a r a m e t e r s a r e t h e n d e r i v e d a n d s t o r e d i n t h i s

    t a b l e l i k e w h e t h e r i t h a s b e e n m o u n t e d r e a d - o n l y ,

    m o d i e d s t a t u s e l d .

    T o e n f o r c e a k n o w n s t r u c t u r e , t h e u t i l i t y p r o g r a m

    m k f s i s p r o v i d e d t o b u i l d a l e s y s t e m .

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i 6

  • 8/10/2019 Minix File System

    8/38

    B i t M a p s

    i - n o d e s a n d z o n e b i t m a p s k e e p t r a c k o f s t a t u s .

    u p o n b o o t u p , s u p e r - b l o c k a n d b i t m a p s f o r t h e

    r o o t d e v i c e a r e l o a d e d i n t o m e m o r y .

    t o r e m o v e a l e , b a s e d o n t h e i - n o d e n u m b e r , w e

    w i l l k n o w w h i c h p o i n t e r i n i n t h e s u p e r - b l o c k t o g o

    t o a n d a c c e s s t h e i - n o d e b i t m a p a n d t h e n c l e a r t h e

    c o r r e s p o n d i n g b i t .

    t o c r e a t e a l e , s e q u e n t i a l l y s e a r c h t h r o u g h t h e b i t

    m a p b l o c k s u n t i l i t n d s a f r e e i - n o d e . T h i s i - n o d e

    i s t h e n a l l o c a t e d f o r t h e n e w l e . I f n o a v a i l a b l e

    i - n o d e , r e t u r n 0 .

    R a t i o n a l f o r z o n e i s t o i m p r o v e p e r f o r m a n c e s o t h a t

    d i s k b l o c k s t h a t b e l o n g t o t h e s a m e l e a r e l o c a t e d

    o n t h e s a m e c y l i n d e r a s m u c h a s p o s s i b l e .

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i 7

  • 8/10/2019 Minix File System

    9/38

    I - n o d e s

    i n M i n i x , i - n o d e i s a 3 2 - b y t e s s t r u c t u r e . F i g u r e

    5 . 3 2 .

    Mode

    Uid

    File Size

    Time of lastmodification

    Link

    Zone 0 number

    Zone 1 number

    Zone 5 number

    Zone 6 number

    Indirect

    Double Indirect

    Zone 2 number

    Zone 3 number

    Gid

    Zone 4 number

    3 2 b y

    t e s

    File type and RWX bitIdentifies the user who owns the file

    Number of bytes in the file

    In seconds, since Jan. 1, 1970

    Directories listing this i-node/owners group

    Zone numbers forthe first 7 datasones in the file

    Only used for files larger than 7 zones

    Figure 5.32: The MINIX i-node

    m o d e i n d i c a t e s t h e t y p e o f l e ( r e g u l a r , d i r e c t o r y ,

    b l o c k s p e c i a l , c h a r a c t e r s p e c i a l o r p i p e ) , p r o t e c t i o n

    b i t s .

    I t i s d i e r e n t f r o m t r a d i t i o n a l u n i x 1 ) n u m b e r o f

    t i m e e l d , 2 ) l i n k a n d g i d s i z e s , 3 ) f e w e r d i s k b l o c k

    p o i n t e r s .

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i 8

  • 8/10/2019 Minix File System

    10/38

    W h e n a l e i s o p e n e d , i t s i - n o d e i s l o c a t e d a n d

    b r o u g h t i n t o t h e i n o d e t a b l e i n m e m o r y . I t r e m a i n s

    t h e r e u n t i l t h e l e i s c l o s e d .

    t h e i n o d e t a b l e h a s s e v e r a l p a r a m e t e r s w h i c h i s n o t

    i n d i s k , 1 ) i - n o d e ' s d e v i c e n u m b e r s o s y s t e m k n o w s

    w h e r e t o w r i t e b a c k t h e i - n o d e , 2 ) a c o u n t e r f o r e a c h

    i - n o d e t o i n d i c a t e t h e n u m b e r o f p r o c e s s o p e n i n g

    t h e l e . W h e n t h e c o u n t e r i s z e r o , t h e i - n o d e i s

    r e m o v e d f r o m t h e t a b l e a n d w r i t t e n t o d i s k i f i t h a s

    b e e n m o d i e d .

    C S C 3 1 5 0 : I n t r o d u c t i o n t o O p e r a t i n g S y s t e m s . P r e p a r e d b y D r . J o h n C . S . L u i 9

  • 8/10/2019 Minix File System

    11/38

    B l o c k C a c h e

    b l o c k c a c h e i s u s e d t o i m p r o v e F S p e r f o r m a n c e .

    E a c h b l o c k b u e r i s i m p l e m e n t e d a s a n o d e w i t h

    1 ) p o i n t e r s 2 ) c o u n t e r s , 3 ) a g s , 4 ) r o o m f o r a d i s k

    b l o c k .

    b u e r s a r e c h a i n e d t o g e t h e r i n a d o u b l e - l i n k l i s t

    w i t h m o s t r e c e n t l y u s e d ( M R U ) t o l e a s t r e c e n t l y

    u s e d ( L R U ) . F i g u r e 5 . 3 3 .

    Hash table Rear (MRU) Front (LRU)

    Figu