UNIX File System - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

UNIX File System

Description:

Free-Block List Maintenance ... block to prevent two processes from updating the free list at the same time. Block allocation: ... – PowerPoint PPT presentation

Number of Views:152
Avg rating:3.0/5.0
Slides: 15
Provided by: yongj
Category:
Tags: unix | file | system

less

Transcript and Presenter's Notes

Title: UNIX File System


1
UNIX File System
  • UNIX
  • One of the most popular operating systems,
    evolving since 1969
  • written in C with small kernel
  • UNIX file system
  • overall structure of the file storage and control
    on the UNIX system.
  • one of the most significant aspects of UNIX

2
Overview
  • Anything as a file, all files as streams of bytes
    in UNIX kernel, hierarchical, directory-based
  • Four types of files
  • regular file ASCII files
  • directory-type file map file names to the
    contents in a directory
  • special file other device - such as printer,
    terminals
  • named pipe FIFO
  • inode index node representing a file. Every
    access to the file must make use of the
    information of the inode.
  • files vs. file names
  • UNIX supports multiple file systems, one in
    charge of UNIX system startup, others can be
    mounted or removed

3
INODE Structure
  • Administrative information and physical data
    addresses of the file
  • file mode
  • count of hard links
  • owner id
  • group id
  • time of last file access
  • time of last file modification
  • time of last inode modification
  • file size
  • file addresses

4
File Addresses in an INODE
  • Block as the basic address unit, BLOCKSIZE is
    constant
  • 13 three-byte pointers point either directly or
    indirectly to the disk blocks containing the data
    contents of the file.
  • Pointers 0-9 addresses of direct blocks
    containing file data
  • Pointer 10 address of a single indirect block, a
    block containing the addresses of direct blocks
  • Pointer 11 address of a double indirect block, a
    block containing the addresses of single indirect
    blocks which contain the addresses of direct
    blocks
  • Pointer 12 address of a triple indirect block

5
File Addresses in an INODE
Direct block addresses
000
009
010
011
012
.
001
Indirect block addresses
Double indirect block addresses
Triple indirect block addresses
File data blocks
6
File Addresses in an INODE
  • file size blocksize 1K, block address is of
    three bytes in the disk resident inode, converted
    to four bytes in memory (1024 / 4 256 block
    addresses in one block)
  • direct block address 10K
  • indirect block addresses 256K
  • double indirect block addresses 256 256K 64M
  • tripe indirect block addresses 256 64M 16G
  • addresses for special files only the first two
    pointers are used device channel number, minor
    device number
  • addresses for named pipes named pipes are
    limited to 10K

7
External View of a File System
root ( / )
user
bin
dev
etc
ls.tmp
hello.c
junk
vi
hello
tty1 mto tty2 null
8
Internal View of a File System
Boot Block
Block 0
Super Block
1
2
i-list Blocks
.
.
.
Last i-list Blocks
FD-1
First Data Block
FD
.
.
Data Blocks
.
Total Blocks in File System
T
9
Internal View of a File System
  • Boot Block the first block in a UNIX file
    system, contains the boot program and other
    initialization information or unused.
  • Super Block always the second block, contains
    the complete catalog of specific information
    about the file system
  • i-list Blocks list of inodes for the file
    system, contiguous and always follows the super
    block. The number of inodes is specified by the
    system administrator
  • Data Blocks immediately follow the i-list and
    consume the rest of the blocks.

10
Free Blocks Organization
  • All free blocks appear in the free-block chain.
    The free-block chain is a linked list of
    free-block address blocks. Each free-block
    address block holds up to 50 four-byte addresses
    of free blocks.
  • The superblock entry s_free0 heads the
    free-block chain, that is points to the next
    free-block address block.
  • Free-block address block structure
  • struct
  • int df_nfree
  • d_addr_t df_freeNICFREE

11
Free-Block List Structure
s_nfree
s_free0 s_free1 s_free49
df_nfree df_free0 df_free1 df_free49
df_nfree df_free0 df_free1 df_free49
df_nfree df_free0 df_free1 df_free49
df_nfree df_free0 df_free1 df_free49
12
Free-Block List Maintenance
  • s_flock flag in the super block to prevent two
    processes from updating the free list at the same
    time.
  • Block allocation
  • case 1 s_nfree gt 1, allocate s_frees_nfree,
    s_nfree --
  • case 2 s_nfree 1, read block s_free0, copy
    block content
  • Block de-allocation
  • case 1 s_nfree lt 50, place free block to
    s_frees_nfree, s_nfree
  • case 2 s_nfree 50, use the de-allocated block
    as new free block address block, copy block
    content, s_nfree 1

13
Free-Inode List Maintenance
  • A free inode is an unused inode, i.e. with zero
    mode. The superblock contains a cache of indices
    of free inodes in an array s_node, 100 in size.
  • s_ilock for concurrency control
  • inode allocation
  • case 1 s_ninode gt 0, superblock cache contains a
    free inode address
  • case 2 s_ninode 0, search the i-list for free
    inode, refill the s_node array
  • inode de-allocation
  • case 1 s_ninode lt 100, put it in the s_node
    array
  • case 2 s_ninode 100, update s_node array or
    do nothing

14
System Calls to UNIX File Systems
  • 19 system calls into 7 categories

Return file desp.
Assign inodes
Set file attr.
Process input/ output
Change file system
Modify view of file system
Use namei algorithm
open close creat pipe dup
creat link unlink
chown chmod stat fstat
read write lseek
mount umount
chdir chroot
open creat mknod chdir chroot chown chmod
stat mount umount
Write a Comment
User Comments (0)
About PowerShow.com