File system implementation - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

File system implementation

Description:

File system implementation. Local File systems ... Boot area. Code required to bootstrap the operating system. Superblock ... Inode lookup: lookuppn()&s5lookup ... – PowerPoint PPT presentation

Number of Views:102
Avg rating:3.0/5.0
Slides: 20
Provided by: scie203
Category:

less

Transcript and Presenter's Notes

Title: File system implementation


1
File system implementation
  • Local File systems and Remote File systems
  • General purpose local file system
  • System V file system(s5fs)
  • Berkeley Fast File System(FFS)
  • It is updated to be Unix File System(ufs)
  • vnode/vfs architecture (developed by SUN
    Microsystems)
  • can support multiple file system types

2
System V file system
  • The file system resides on a single logical disk
    or partition
  • A partition can be viewed as a linear array of
    blocks
  • block represents the granularity of space
    allocation for files
  • a disk block is 512 bytes some power of 2
  • physical block number identifies a block on a
    given disk partition
  • physical block number can be translated into
    physical location on a partition

3
Disk partition
B
S
inode list
data blocks
  • Boot area
  • Code required to bootstrap the operating system
  • Superblock
  • Attributes and metadata of the file system itself
  • inode list
  • a linear array of inodes
  • data blocks
  • data blocks for files and directories, and
    indirect blocks

4
Superblock
  • It contains
  • Size in blocks of the file system
  • Size in blocks of the inode list
  • Number of free blocks and inodes
  • Free block list(Partial)
  • Free inode list(Partial)
  • The kernel reads the superblock and stores it in
    memory when mounting the file system

5
Inode
  • Each file has an inode associated with it
  • Inode contains metadata for file
  • on-disk inode refers to inode stored in disk
    within the inode list
  • in-core inode refers to inode stored in memory
    when a file is open

6
On-disk inode
  • The size of on-disk inode is 64 bytes

7
On-disk inode
  • Unix files are not contiguous on disk
  • File system need to maintain a map of the disk
    location of every block of the file

0
1
2
3
4
5
6
7
8
9
indirect
10
11
Double indirect
12
triple indirect
8
In-core Inode
  • It contains all the fields of on-disk inode, and
    some additional fields, such as
  • The status of the in-core inode (whether the
    inode is locked, which process is waiting, etc.)
  • The logical device number containing the file
  • The inode number of the file
  • Pointers to keep the inode on a free list
  • Pointers to keep the inode on a hash queue.
  • Block number of last block read.

9
Inode operation
  • Inode lookup lookuppn()s5lookup()
  • translates a pathname and returns a pointer to
    the vnode of the desired file
  • allocate inode iget()
  • read an inode from disk into memory by inode
    number or initialize an empty inode if not found
  • release inode iput()
  • kernal writes the inode to disk if the in-core
    copy differs from the disk copy

10
File Operation
  • Read and write system call use the following
    arguments
  • File descriptor, user buffer address, count of
    number of byte transferred
  • Offset is obtained from the opened file object
  • Offset is advanced to the number of byte
    transferred
  • For random I/O lseek is used to set the offset
    to desired location
  • Kernel verifies the file mode and puts an
    exclusive lock on the inode for serialized access
  • File read s5read()

11
Structure of the File System
  • File system is organised as a heirarchy of
    directories
  • It starts from a single directory called
    root(represented by a /).
  • /(root)
  • --------------------------------------------------
    ------------------
  • /bin /dev /etc /tmp /usr
    /kernelfile

12
Different types of Files
  • Ordinary files
  • Directories
  • Special files
  • Pipes

13
Directories
  • Directory is file containing list of files and
    subdirectories
  • It has fixed size records of 16 bytes each
    which contains - a filename(14
    bytes) - an inode number (2 bytes) which
    acts as a pointer to where the system can find
    info about the file.

14
Special Files
  • Special files are contained in the directory
    /dev.
  • They are used to represent a real physical
    device such as a printer, tape device etc.
  • Ex Special device - /dev/null(unwanted output
    can be redirected).

15
Pipes
  • UNIX allows us to link commands together using a
    pipe.
  • The pipe acts as a temporary file which only
    exists to hold data from one command until its
    read by another. ex command1 command2
    command3....

16
System call Open
The syntax of the open call is fd open
(pathname, flags, modes) where pathname
is a file name, flags indicate the type of open
(read or write), modes gives the file
permissions (if created) fd, an integer, is the
file descriptor that is returned. algorithm
open inputs filename, type of open, file
permissions output file descriptor


convert file name to inode
(using s5lookup)

if (file does not exist or
not permitted access) return (error) allocate
file table entry for inode, initialize count,
offset allocate user file descriptor entry, set
pointer to file table entry if (type of open
specifies truncate file) free all data
blocks unlock (inode) return (user file
descriptor)


17
System Call Read
The syntax for the read system call is number
read(fd, buf, cnt) where fd is the file
descriptor, buf is the address of a data
structure that will contain the read data, cnt
is the number of bytes the user wants to read and
number is the number of bytes actually read. -
the kernel gets the file table entry that
corresponds to the fd. - the kernel sets various
parameters like the I/O mode(to indicate that a
read is being done), count(to indicate the number
of bytes to read), the target address of the user
data buffer etc. - the algorithm then goes into
a loop until the read is completed.
18
System Call
  • Some of the other System calls that are provided
    in UNIX are
  • File and record locking It is a capability to
    prevent other processes from reading and writing
    any part of the entire file. Similarly we also
    have record locking.
  • Positioning the File I/O The system call lseek
    is used to position the I/O and allow random
    access to a file. Its syntax is
  • position lseek(fd, offset, reference)
  • Closing a File A process closes an open file
    when it is no longer needed. The syntax for close
    is close(fd)

19
System Call
  • File Creation create system call creates a
    new file in the system. The syntax for create
    system call is
  • fd create(pathnames, modes)
  • Creation of Special files mknod system call
    creates special files in the system like pipes,
    device files and directories. Its syntax is
  • mknod(pathname, type and permissions, dev)
  • where pathname is the name of the node to be
    created,
  • type and permissions give the node type(ex.
    directory) and access permissions to the new
    file,
  • dev specifies the major and minor device numbers
    for block and character special files.
Write a Comment
User Comments (0)
About PowerShow.com