Sie sind auf Seite 1von 20

OPERATING SYSTEMS

(CS C372 & IS C362)


LECTURE 59: FILE SYSTEMS

File-System Structure

File structure

Logical storage unit


Collection of related information

File system resides on secondary storage


(disks)
File system organized into layers
File control block storage structure
consisting of information about a file

29 November 2012

Biju K Raveendran@BITS Pilani.

File system layout


Boot
block

Inode list

Data blocks

Boot block occupies the beginning of a file system

Super
block

Typically first block and may contain boot strap code.


Only one boot block is needed to boot the system, but every
file system has a (possibly empty) boot block.

Super block describes the state of a file system.

Size of the file system


Number of free blocks and list of free blocks in file system
Size of the Inode list
Number of free Inodes and List of free Inodes in the file system
Index of the next free block and free Inode
A flag indicating that the super block has modified etc

29 November 2012

Biju K Raveendran@BITS Pilani.

Allocation Methods

An allocation method refers to how disk


blocks are allocated for files:

Contiguous allocation
Linked allocation
Indexed allocation

29 November 2012

Biju K Raveendran@BITS Pilani.

Contiguous Allocation of Disk Space

29 November 2012

Biju K Raveendran@BITS Pilani.

Linked Allocation

29 November 2012

Biju K Raveendran@BITS Pilani.

File-Allocation Table

29 November 2012

Biju K Raveendran@BITS Pilani.

Example of Indexed Allocation

29 November 2012

Biju K Raveendran@BITS Pilani.

UNIX file system

Every file on a UNIX system has a unique id

Inode contains information necessary for a


process to access a file

It is known as inode number

File ownership, access rights, file size, and


location of the files data in the file system.

Kernel converts path + filename to the files


inode.

29 November 2012

Biju K Raveendran@BITS Pilani.

Inode

Disk inode consists of following fields


File owner identifier
Individual, group, super user
File type
File, directory, special file or FIFO (pipes)
File access permissions
File access and modified times
Number of links to the file
Table of contents for the disk addresses of data in a file
File size
Inode does not specify the path name(s) that access the file
Changing the content of a file automatically implies a
change to the inode, but changing the inode does not
imply that the contents of the file change.
29 November 2012

Biju K Raveendran@BITS Pilani.

10

Inode structure

13 / 15 entries in inode table of contents

10 / 12 direct
1 single indirect
1 double indirect
1 triple indirect

29 November 2012

Biju K Raveendran@BITS Pilani.

11

Combined Scheme: UNIX (4K bytes per block)

29 November 2012

Biju K Raveendran@BITS Pilani.

12

Example

Assume

Logical block = 1 K Bytes


Block number is addressable by a 32 bit (4 bytes)
A block can hold 256 block numbers
Maximum number of bytes possible in a file =
(10K + 256K + 64M +16G)bytes
Given that the file size field in the inode is 32 bits,
the size of a file is effectively limited to 4GB (232)

29 November 2012

Biju K Raveendran@BITS Pilani.

13

Process access data in a file by byte offset


The kernel converts the user view of bytes
into a view of blocks
File starts at logical block 0 and continues to
a logical block number corresponding to the
file size.
The kernel accesses the inode and converts
the logical file block number in to physical
disk block.

29 November 2012

Biju K Raveendran@BITS Pilani.

14

4096
228
45423
0
0
11111
0
367

101
367
0

0 331
75

428

3333

9156
824
29 November 2012

9156

331

Biju K Raveendran@BITS Pilani.

3333

15

E.g. 1

If a process wants to access byte offset 9000

Kernel calculate that the byte is in 8th block (starting


from 0)
It accesses the physical block number stored in 8th direct
map location. (If 367 is the value stored in 8th direct map
location then access 367th block from the disk.)
Then access 808th byte (9000 8192) in 367th block.
This will be the resultant 9000th byte in file.

29 November 2012

Biju K Raveendran@BITS Pilani.

16

E. g. 2

If process want to access byte offset 350,000 in


the file
9th direct pointer can store till (10K-1)
Single indirect pointer can store from 10K to
(266K-1)
Double indirect pointer can store from 266K to
(64266K-1)
The request is between these value. So the
request is in double indirect pointer.

29 November 2012

Biju K Raveendran@BITS Pilani.

17

350000 in a file is 350000 266K in double


indirection
= 77616 of a double indirection.
Since each single indirection can access 256K,
77616 is in the 0th single indirection block of double
indirection block.
So we will fetch block number 331.
Since the direct block in a single indirect block hold
1KB, 77616 is in 75th direct block in the single indirect
block.
So we will fetch block number 3333.
The offset location from where we need to access the
byte is calculated by 77616 75K = 816
If inode block entry is 0, then the logical block entries
contain no data.

29 November 2012

Biju K Raveendran@BITS Pilani.

18

Directories

Are the files that give file system its hierarchical structure.
They play important role in converting file name in to inode
number.
Directory is a file whose content is sequence of entries
Each entry consist of inode number and the name of a file
contained in the directory.
UNIX system restrict component names to a maximum of 14
characters, and 2 byte inode number.
Size of one directory entry is 16 bytes.
Every directory contain file names dot and double dots with inode
number of its directory and its parent directory respectively.
Access Permissions
Read allows a process to read the directory
Write allows process to create, remove directory entries.
Execute allows process to search the directory for a file name.

29 November 2012

Biju K Raveendran@BITS Pilani.

19

Conversion of a path name to an Inode

All path name searches start from the current


directory of the process unless the path name
start with /(start from the root).
The current directory is stored in the process
u area.
Root inode is stored in global variable
Example

fopen(/etc/passwd,r)
fopen(OS/Compre/CompreQ.pdf,r) where
current directory is /root/CSC372_ISC362

29 November 2012

Biju K Raveendran@BITS Pilani.

20

Das könnte Ihnen auch gefallen