Operating Systems Lecture 34: File Systems and Directories - Prof. Godmar Volker Back, Study notes of Operating Systems

A portion of lecture notes from cs 3204 operating systems course at spring 2006. Topics such as multi-level indices, storing and positioning inodes, directories, using linear lists and b-trees, absolute paths, and some issues in name resolution. The lecture also discusses hard and soft links.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-bho-1
koofers-user-bho-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS 3204
Operating Systems
Godmar Back
Lecture 34
4/14/2006CS 3204 Spring 2006 2
Announcements
Project 4 due Wed, May 3, 11:59pm
Recommended reading
Chapter 11.1-11.5, 11A
Chapter 12, in particular 12.7
Project 4 help sessions next Monday &
Tuesday
Filesystems
4/14/2006CS 3204 Spring 2006 4
Multi-Level Indices
Used in Unix &
Pintos (P4)
1
2
3
..
N
FLI
SLI
TLI
1
2
index
N
index2
index
index
N+IN+1
N+I+1
index3index2
Direct
Blocks
Indirect
Block
Double
Indirect
Block
Triple
Indirect
Block index N+I+I2
4/14/2006CS 3204 Spring 2006 5
Storing Inodes
Unix v7, BSD 4.3
FFS (BSD 4.4)
Cylindergroups have
superblock+bitmap+inode list+file space
Try to allocate file & inode in same
cylinder group to improve access locality
I0I1I2 I3I4 …..
Superblock Rest of disk for files & directories
I0I1
SB1 Files … I3I4 ….. Files … I8I9 ….. Files …SB2 SB3
CGi
4/14/2006CS 3204 Spring 2006 6
Positioning Inodes
Putting inodes in fixed place makes finding
inodes easier
Can refer to them simply by inode number
After crash, there is no ambiguity as to what
are inodes vs. what are regular files
Disadvantage: limits the number of files
per filesystem at creation time
Use “df –ih” on Linux to see how many inodes
are used/free
pf3

Partial preview of the text

Download Operating Systems Lecture 34: File Systems and Directories - Prof. Godmar Volker Back and more Study notes Operating Systems in PDF only on Docsity!

CS 3204

Operating Systems

Godmar Back

Lecture 34

CS 3204 Spring 2006 4/14/2006 2

Announcements

• Project 4 due Wed, May 3, 11:59pm

• Recommended reading

– Chapter 11.1-11.5, 11A

– Chapter 12, in particular 12.

• Project 4 help sessions next Monday &

Tuesday

Filesystems

CS 3204 Spring 2006 4/14/2006 4

Multi-Level Indices

• Used in Unix &

1 Pintos (P4)

N

FLI

SLI

TLI

index

N

index 2

index

index

N+1 N+I

N+I+

index 3 index 2

Direct Blocks

Indirect Block

Double Indirect Block Triple Indirect Block index

N+I+I^2

CS 3204 Spring 2006 4/14/2006 5

Storing Inodes

• Unix v7, BSD 4.

• FFS (BSD 4.4)

• Cylindergroups have

superblock+bitmap+inode list+file space

• Try to allocate file & inode in same

cylinder group to improve access locality

Superblock I 0 I 1 I 2 I 3 I4 ….. Rest of disk for files & directories

SB1 I 0 I 1 …Files … SB2 I 3 I4 ….. Files … SB3I 8 I9 ….. Files …

CGi

CS 3204 Spring 2006 4/14/2006 6

Positioning Inodes

• Putting inodes in fixed place makes finding

inodes easier

– Can refer to them simply by inode number

– After crash, there is no ambiguity as to what

are inodes vs. what are regular files

• Disadvantage: limits the number of files

per filesystem at creation time

– Use “df –ih” on Linux to see how many inodes

are used/free

CS 3204 Spring 2006 4/14/2006 7

Directories

• Need to find file descriptor (inode), given a name

• Approaches:

  • Single directory (old PCs), Two-level approaches with 1 directory per user

• Now exclusively hierarchical approaches:

  • File system forms a tree (or DAG)

• How to tell regular file from directory?

  • Set a bit in the inode

• Data Structures

  • Linear list of (inode, name) pairs
  • B-Trees that map name -> inode

CS 3204 Spring 2006 4/14/2006 8

Using Linear Lists

• Advantage: (relatively) simple to

implement

• Disadvantages:

– Scan makes lookup (& delete!) really slow for

large directories

– Can cause fragmentation (though not a

problem in practice)

23 multi-oom 15 sample.txt

offset 0

inode #

CS 3204 Spring 2006 4/14/2006 9

Using B-Trees

• Advantages:

– Scalable to large number of files: in growth, in

lookup time

• Disadvantage:

– Complex

– Overhead for small directories

CS 3204 Spring 2006 4/14/2006 10

Absolute Paths

• How to resolve a path name such as

“/usr/bin/ls”?

– Split into tokens using “/” separator

– Find inode corresponding to root directory

  • (how? Use fixed inode # for root)

– (*) Look up “usr” in root directory, find inode

– If not last component in path, check that inode

is a directory. Go to (*), looking for next comp

– If last component in path, check inode is of

desired type, return

CS 3204 Spring 2006 4/14/2006 11

Some Issues in Name Resolution

• Must have a way to scan an entire directory

without other processes interfering -> need a

“lock” function

• But don’t need to hold lock on /usr when

scanning /usr/bin

  • Directories can only be removed if they’re empty

• Most OS cache translations in “namei” cache –

maps absolute pathnames to inode

CS 3204 Spring 2006 4/14/2006 12

Current Directory

• Relative pathnames are resolved relative

to current directory

– Provides default context

– Every process has one in Unix/Pintos

• chdir(2) changes current directory

• lookup algorithm the same, except starts

from current dir

– process should keep current directory open

– current directory inherited from parent