36
Rushdi Shams, Dept of CSE, KUET 1 Operating Systems Operating Systems File Systems File Systems Version 1.0

Lecture 14,15 and 16 file systems

  • View
    190

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 1

Operating SystemsOperating SystemsFile SystemsFile Systems Version 1.0

Page 2: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 2

Introduction• Processes can store a limited amount of

information within its own address space.• For some applications this size is adequate

but for others (airline reservations, banking), the space is too small

Page 3: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 3

Introduction• Information stored must survive the

termination of the process using it. Typically, processes were designed in a way such that after their usage on variables, the values are lost when processes release them.

• Inappropriate for applications like database systems

Page 4: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 4

Introduction• Multiple processes must be able to access the

information concurrently. Truly speaking, while a process operates on an information, it was not accessible for others

Page 5: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 5

Introduction• So, we have three essential requirements for

long-term information storage-1. Store a large amount of information2. The information must be stored for a long

time3. Multiple processes must be able to access

the information concurrently• These requirements led us towards keeping

the information in files

Page 6: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 6

Introduction• Information in files must be persistent-

process termination and creation must not affect them

• Only the owner can modify/delete the information if she likes.

Page 7: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 7

File NamingWhen a process creates a file, it gives a file

nameWhen the process terminates, the file

continues to exist and can be accessed by other processes using its name.

Some file systems distinguish between upper and lower case letters, whereas others do not.

Are the file names cat.doc, cAt.doc, caT.doc and CAT.doc same in windows? What about in UNIX?

Page 8: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 8

File NamingMany OS support two-part file names- two

parts separated with a period (.). The part after the period is called file

extension. Filename extensions can be considered a type

of metadata. They are commonly used to infer information

about the way data might be stored in the file.

Page 9: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 9

File Structure

Generally, there are three kinds of files-1. Byte Sequence2. Record Sequence3. Tree Sequence

Page 10: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 10

File Types Generally, there are

two types of files-1. ASCII files2. Binary files

ASCII files are easy to understand if you use a text editor whereas binary files are completely glibberish if you print them

Page 11: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 11

File Access StrategiesSequential access

read all bytes/records from the beginningcannot jump around, could rewind or back up

Random accessbytes/records read in any orderessential for data base systemsread can be …

move file marker (seek), then read or … read and then move file marker

Page 12: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 12

File Access StrategiesThere are also several file usage patterns.Most files are small (e.g., .login and .c files),

and most file references are too small files.Large files use up most of the disk space

(e.g., mp3 files).Large files account for most of the bytes

transferred between memory and disk.

Page 13: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 13

File Access StrategiesThese usage patterns are bad news for file

system designers. To achieve high performance, a designer

needs to make sure that small files are accessed efficiently, since there are many of them, and they are used frequently.

A designer also needs to make sure that large files are accessed efficiently, since they consume most of the disk space, and account for most of the data movement.

Page 14: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 14

Directories To keep track of files, file systems normally

have directories or folders In many systems directories themselves are

files! Simply put, there are three types of

directory systems-1. Single-level directory systems2. Two-level directory systems3. Hierarchical directory systems

Page 15: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 15

Single-level directory systemSimplest form of directory

systemOne directory contains all

the filesSometimes called root

directoryGood choice when number

of user is only oneThe directory in figure has

two owners- A and B having four files

Problem- different users may accidentally use same names for their files

Page 16: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 16

Two-level directory systemEach user will have

separate directories containing their owned files

The problem with naming is resolved.

Log in procedure is required

May allow one user to access others’ files

Page 17: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 17

Hierarchical Directory SystemsThe problem of two-level

directory system is the absence of grouping facility

You may group your works like- games in one place, movies in the other.

Hierarchical directory systems have the facility of two-level directory systems plus the organization facility

Page 18: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 18

File System LayoutFile systems are stored on disksDisks are divided up into one or more

partitionsEach partition has independent file systemsSector 0 of the disk is called Master Boot

Record (MBR)Computer uses MBR to boot itselfThe end of MBR contains the partition table-

that has the start and end address of each partition

Page 19: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 19

File System LayoutOne of the partitions in the partition table is

marked as activeWhen computer is booted, the BIOS reads in

and executes MBRThe first thing MBR program does is to locate

the active partitionThe first block of this active partition is Boot

Block.MBR reads and executes it.The program in Boot Block loads the OS

contained in that partition

Page 20: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 20

File System LayoutEvery partition starts with a Boot BlockBut only the partition having the OS will be

marked as activeOther partitions hold the Boot Block as you

can change your mind and copy another version of the OS into one of them

Page 21: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 21

File System Layout

Page 22: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 22

File System Layout

Super Block contains all the key parameters about the file system

It is read into memory when the computer is booted or the file system is first touched

Typically holds a Magic Number to identify the file system type (.exe or .bmp?), number of blocks, etc

Page 23: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 23

File System Layout

Free space management reveals the free blocks in the file system

i-nodes is an array of data structures, one per file, simply telling about the file

Root directory contains the top of the file system treeRemainder of the disk contains all other directory and files

for that partition

Page 24: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 24

Implementing Files: Contiguous AllocationSimplest allocation scheme to store each file

as a contiguous run of disk blocksDisk with 1 KB blocks, a 50 KB file would

need 50 consecutive blocks; Disk with 2 KB blocks would make it okay with 25 consecutive blocks

Page 25: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 25

Implementing Files: Contiguous Allocation

Page 26: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 26

Implementing Files: Contiguous AllocationAdvantages

Simple to implement You only need to know the disk address of the first

block and the distance of the file block from itRead performance is excellent, as you need only

two seek operations (boot block and file block) and one read operation (one contiguous stream of bytes)

DisadvantagesDisks become fragmentedWastage of storage is possible

Page 27: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 27

Implementing Files:Linked List AllocationEvery block will have two sections- a pointer

to next one (the first word of the block) and data (the rest of the words)

Unlike contiguous allocation, every disk block can be used in this method

No space is lost due to disk fragmentation

Page 28: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 28

Implementing Files:Linked List AllocationReading a file sequentially is straight forward

but random access is slow.To get block n, the OS has to start at the

beginning and read the n-1 blocks prior to itOverhead due to pointer information

Page 29: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 29

Implementing Files:Linked List Allocation

Page 30: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 30

Linked List Allocation:using Table in MemoryThe disadvantages are eliminated by taking

the pointer word from each block and putting it into a table in memory

Such a table in main memory is called FAT (File Allocation Table)

Page 31: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 31

Linked List Allocation:using Table in Memory

Page 32: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 32

Linked List Allocation:using Table in MemoryEntire block is available for data (no pointer

information)Faster random accessThe primary disadvantage-

the table must be in memory all the time to make it work

a 20 GB disk and with 1 KB block size, the table needs 20 million entries one for each of 20 million blocks

each entry is 4 bytes longso, FAT will occupy 80 MB space in memory all

the time

Page 33: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 33

i-nodesIt is a data structure that lists the attributes

and disk addresses of the file’s blocksWith i-nodes, it is possible to find all the

blocks of a filei-nodes need only be in memory when the

corresponding file is openIf each i-node contains n-bytes and there are

k-files are opened at a time, that instant, kn-bytes are reserved in memory

Page 34: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 34

i-nodes

Page 35: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 35

i-nodesThis array is usually far smaller than the space

occupied by the FATTable for holding the linked list is proportional to

disk itself.If the disk has n blocks, the table needs n-entriesAs the disks grow, the table grows linearly with

themi-node requires an array whose size is

proportional to the maximum number of files that may be open at once (it does not matter if you have 1 petabyte HDD )

Page 36: Lecture 14,15 and 16  file systems

Rushdi Shams, Dept of CSE, KUET 36

i-nodesThe disadvantage is if you fix the size of i-

node and your files have a tendency to grow larger (obviously you cannot say your file will be always 6MB in size )