Title: File System Design
1File System Design
- Lecture notes for CEG 433
- Lectures by Dr. Prabhaker Mateti
- Notes by Patrick Flaherty
- January 2005
2Disk Structure
- Typical disks have multiple platters
- Each platter organized into n tracks with a fixed
number of sectors on each track - Tracks sectors may be though of as logically
arranged in a linear order
3File System Design
- For any hard disk, there is some fixed number of
tracks and sectors - Sector size may vary from disk to disk -- but not
within a given disk - For our initial design, we define
block sector - For the class project we will design an
i-Node based file system
4MyFile.txt
- Let blockksize 1024 bytes (i.e., 1k)
- Hard disks work only with blocks
- Thus, MyFile.txt will be stored in a number of
blocks determined by the size of the file - Why block 250, 23, etc.?
- Because the file system used the first 5 free
blocks available
Q If a File occupies 5 blocks, how big is its
size in bytes ? A 4k1 Filesize 5k
Block
5File System Design - Directory
- Think of a directory as a table
- File Local Name
- ? How to read it
- Problem Lots of block numbers gt cumbersome
- Put the block s away somewhere
- Identify the place where you put them with
another number (call it i-node)
First concept
Now File ? (11) ? i-node
Revised
6File System Design i-Nodes
- Given i-number ? list of block s
- How?
- i-number is defined as an index for an array
named i-node array where each i-node is an
array of (for example) 7 elements - Look at i-node 5
A single i-Node
Notice these do not point to any address
A pointer to block number 250
7File System Design i-Nodes (cont.)
- The i-node array is not in memory but on the disk
- How many i-nodes should we have?
- Obviously 5 is too few and 5 zillion is too many
- Need to think about file size before choosing the
number of i-nodes we will need - More questions
- How much space is required for these i-nodes?
- Where do we put them?
8File System Design i-Nodes (cont.)
- i-node size ht wd
- Assume Width 4 bytes
- Implication 232 1 possible block numbers
- For our design
- Let each i-node be an array of 7 elements
- 6 elements available to point to a block
- 1 element reserved for later use
Width (wd)
Height (ht)
9File System Design i-Nodes (cont.)
- Suppose
- i-node size ht wd
- Width 4 bytes
- Total number of i-nodes ni
- Total space for all i-nodes ht 4 ni
- How many blocks will this use?
10File System Design i-Nodes (cont.)
- All i-nodes are initialized with all values set
equal to 0 - Questions
- Where do we put the blocks? (Well get to this
shortly) - Where does the root directory go?
Blocks containing the i-node array
Block 0 is reserved
11File System Design Directories
- By convention, put root directory in i-node 1
- But first, we must create it
- By design choice
- A single dot . refers to the current directory
as a name - A double dot .. refers to the parent directory
- Suppose current directory is d2 with parent
directory d1 - Given /d1/d2
- d2 will look like this
- What is the size of the root directory? (Ans. 13
bytes)
Root directory
All other directories
12File System Design Bit Vectors
- How do we keep track of free blocks and free
i-nodes? - One way is to use bit vectors
- Free bit vector of blocks fbvbx
- Where for each bit
- Assume nb the number of blocks in the hard disk
- Then size of fbvb nb bits
blocks - Similarly for the free bit vector of i-nodes
fbvix - Size of fbvi ni bits blocks
0 the xth block is in use 1 the xth block
is free
13File System Design File Volume
- Now we have
- The action that does this should be called Make
File Volume but for historical reasons it is
called mkfs - The File System includes algorithms and other
required code
fbvi
i-node array
The root directory
fbvb
14Create A New Directory
- What are the steps?
- Find a free i-node for the new directory gt 6
- Parent directory i-node will be the current
working directorys (CWD) i-node gt cwdin - Find the next free block number gt 17
- Write block (17, P) where P is a pointer to the
directory data structure mark i- 6 and block
17 as in use - Link the newly crated directory to its parent
All other directories