19
Operating System Concepts and Techniques Lecture 17 Information management-1* Foundations and UNIX/Linux File System M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011. To order: www.iUniverse.com , www.barnesandnoble.com, or www.amazon.com * Information management is not usually covered in the first university course of operating systems

Operating System Concepts and Techniques Lecture 17 Information management-1* Foundations and UNIX/Linux File System M. Naghibzadeh Reference M. Naghibzadeh,

Embed Size (px)

Citation preview

Operating System Concepts and

Techniques Lecture 17

Information management-1*Foundations and UNIX/Linux File

System

M. Naghibzadeh

ReferenceM. Naghibzadeh, Operating System Concepts and Techniques, First ed., iUniverse Inc., 2011.

To order: www.iUniverse.com, www.barnesandnoble.com, or www.amazon.com

* Information management is not usually covered in the first university course of operating systems

Storage mediaDisk pack: An structured hardware consisting

of Many plates, two surfaces per plate, many same

capacity tracks on each surface, many same capacity sectors on each track

Disk model

Each partition

2

Sector 1 Sector 2 … … … Sector mn

... Track 0 Track m-1

Partition 1 Partition 2 .... Partition k

Sector 1

3

FileAn structure of vast amount of information to

be stored on persistent media, could be Collection of bytes

ASCII Binary

Collection of records Tree structure

File types Regular: user files

Directories: meta data about files Special Files: for example, I/O files for printer

Block special: files for tapes, disks

4

File Attributes/Data/operations/access

Each file consists of: Attributes: owner, creator, password, Archive/system,

Hidden, lock, temporary, random access, ASCII/Binary, time of last access, creation time, key

length, key position, record length, max size, current size, time of last change etc.

Data

Valid operations are: create, delete, open, close, read, write, append, seek,

get attributes, set attributes, rename

File access: Sequential, random

Storage allocationContiguous allocation: a file (or directory) is

considered a chunk of data that must be stored in a contiguous data area of the storage device

Size of each file is a multiple of blocks Block size is a power of two sectors

Advantages: address calculation is simple

For sequential access prefetch is possible Disadvantage

External fragmentation May require frequent defragmentation

5

Disk attributes, metadata, … File 1 File 2 … File i Unallocated area

Storage allocation...Chained allocation: Data blocks of a file need

not take a contiguous area, but they are chained together

Advantage No external fragmentation

Disadvantages: Address calculation is difficult

Random access is time consuming and needs excessive disk access

6

Disk attributes, metadata, …

Storage allocation...Indexed allocation: any block of data can sit in

any block frame of disk Index table(s), will make note of which block is stored

where, it uses disk block numbers instead of the physical address of the block; options are:

Only one table: like FAT One table for every file or directory: like UNIX

Advantages: No external fragmentation

index table is usually in the main memory thus rendering both sequential and random access to files

and directories efficient

7

Other topicsFree space management

Chained free pieces Bitmap

Index table

Bad block management Substitute sectors File of bad blocks

8

Directory tree/directoryDirectory tree: the organization of files and

directories, on a volume, in the form of a tree Directory: a folder of files and subdirectories

and their handles

Figure 1

Directory operations: Create, delete, opendir, closedir, readdir,

rename, link, unlink

9

Directory

File

B C

RSWX

A D

P

Q L K

UNIX File System(USF)Structure of a partition is:

Superblock has attributes and metadata of the file system itself; size in blocks of the file system; size in blocks of the

i-node list, number of free blocks and i-nodes, free block list

Indexed allocation is used to allocate available blocks to file and directory data. Every file or directory has its own

index tableThe index table is a special one, called index-node (or i-

node for short)The length of all i-nodes is the same, usually 64 bytes and

the total numberIf total number of i-nodes is say 1024, then the space

requirement for this area is 64*1024 bytes or 64 kilo bytes

10

Boot block Superblock i-node list Data blocks

UNIX File System(USF)…Root does not have a name, instead its i-node is

the first i-node of the i-node listAt computer start/restart root directory

becomes current directoryThe last 4 rows of I-node needs special attention

11

File mode Flags for file type, execution, owner permissions, Group permissions, and other permissions

Link count Number of links to this i-nodeOwnerID ID of the ownerGroupID ID of the group of the owner of this fileFile size File size in bytes

Last accessed Time of last accessLast modified Time of last modification

Inode modified Time of last i-node modificationDirect addresses Ten direct addresses

Single indirect addresses Pointer to a block of addressesDouble indirect addresses Pointer to a block of addresses

Triple indirect addresses Pointer to a block of addresses

Some information of i-node

I-nodeIn memory i-node is 64 bytes; the rest is

on disk extensionsTen block address for the file data (3 bytes

each)One single indirect

One double indirectOne triple indirect

12

.

.

.

.

.

.

.

.

.

.

.

..

.

.

.

.

.

.

.

.

.

.

.

.

.

..

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

..

.

..

.

.

.

.

.

.

.

Data blocks

Table of pointers

File ordirectory attributes

10 Direct pointers todata blocks

Single indirect

Double indirect

Triple indirect

Largest file sizeVaries with:

block sizes; assume 1K Size of disk addresses used; assume 4 bytes

Direct addresses: total 10K Single indirect addresses: total 256K

Double indirect addresses: total 256*256K Triple indirect addresses: total 256*256*256K

Overall total:(10+256+256*256+256*256*256)K

Not too big, but a larger block size allows a larger file

13

Directory data

I-node number

File name

14

2 bytes 14 bytes

6 0

1 00

12 S

9 R

1 0

1 00

5 A

8 B

6 C

4 D

(b) Directory C’s data of Figure 1

Data block no 120

(a)Root directory’s data of Figure 1Data block no 100

Format of directory data records

Figure 2: The structure of directory data blocks

Looking for a file’s dataHow can the file Q’s data storage location be found?

The operating system goes to current directory’s i-node and locates Q and its i-node number

Suppose file Q is not in the current directory but its absolute path is say /C/S/Q

The file system will access i-node number 1 and search for the root’s data location (data block no 100, Figure 2a)

It looks for C and its i-node number which is 6; using i-node number six it looks for directory C’s data block (say no. 120)

In this databblock (Figure 2b) the file system looks for S and its i-node number (say 12)

It continues this process until Q’s i-node number is found; using this i-node the file system searches for Q’s data

storage blocks.

15

16

Advantage/DisadvantageAdvantages:

i-nodes can be shared while in main memory, hence file sharing

Fast processing

Disadvantage: i-node updates are not instant, in

memory i-node may be changed while on disk is something different

17

SummaryCaches and main memories lose their contents

as soon as the computer is turned offWe must store persistent information on

persistent devicesThe well thought out organization of information

in secondary storage, especially in light of its vastness, is extremely crucial

This responsibility lies with the file systemMany file systems have been developed to

address this taskIn this lecture, the design foundation of file

systems was studiedThe design details of a major file systems, the

UNIX File System (UFS) was thoroughly investigated

18

Find outThe differences between Unix file system and

Linux file systemAll the information that is stored in a 64 byte i-

nodeWhy the name of files and subdirectories of a

directory should not be stored within the i-node of that directory and they have to be stored in

data blocks?The difference between a file system and a file

How can a file be organized to represent all bad blocks of a disk

What is the usage of a substitute sector

19

Any questions?