LINUX File System: Slides Adopted From
LINUX File System: Slides Adopted From
LINUX File System: Slides Adopted From
CCE651..12
Partition 1
Partition 2
Partition 3 (Extended)
Partition 4
3
Introduction
Data used by a computer system is stored in a variety of different storage medium A file system provides a logical view of this data/information The OS provides a mapping between the logical and physical units of storage
4
Introduction
Files
A named collection of related info Consists of a sequence of bits, bytes, lines, or records For each file, the OS keeps the following info:
Name Type Location Size Important dates
6
Directories
A file system may be divided into partitions Each partition will have a directory structure Directories store information such as name, size, and location of a file Operations performed on directories include: search for a file, create a file, list a directory, traverse a file system
7
Directory Structure
Collection of nodes that contains information about the all files
Directory
Files
F1
F2
F3
F4
Fn
10
Directory Implementation
Linear list of file names with pointer to the data blocks
simple to program time-consuming to execute
Allocation Methods Refers to how disk blocks are allocated for files:
Contiguous allocation Linked allocation Indexed allocation
12
Contiguous Allocation
13
Contiguous Allocation
Each file occupies a set of contiguous blocks on the disk Simple, only starting location and length (number of blocks) are required Random access External fragmentation (dynamic storage-allocation problem) Files hard to grow
14
Linked Allocation
15
Linked Allocation
Each file is a linked list of disk blocks that may be scattered anywhere on the disk Simple need only starting address and no size-declaration is necessary No fragmentation or waste of space Sequential access only (no random access) Each block consumes 4 bytes to point to the next block (4B in 512B/B.78% waste) If one pointer is lost, the file state is not guaranteed
16
File-Allocation Table
17
Indexed Allocation
19
Indexed Allocation
Solves the problem of direct access
Brings the pointers into one location: the index block Index block is an array of disk-block addresses The ith entry in the index block points to the ith block in the file
Indexed Allocation
Each file has an index block
If file is small few non null pointers (i.e. space is wasted more than with a linked list) If file is big Index block may not be sufficient to hold enough pointers to file blocks
21
22
.....
Process n
User mode
System mode
File system
24
Structure of a UNIX inode Access rights Owner Size Times Data Data Data
Data
Data Data
Data
Data
25
Data blocks
28
structure of Ext2 file system: block groups, data blocks close to their inodes and file nodes close to their directory node
29
Boot block
Block group n
30
The superblock in the ext2 filesystem Number of inodes, number of blocks Number of reserved blocks, number of free blocks Number of free inodes, first data block Block size Blocks per group Inodes per group Time of mounting Ext2 signature
31
struct ext2_super_block { unsigned long s_inodes_count; /* Inodes count */ unsigned long s_blocks_count; /* Blocks count */ unsigned long s_r_blocks_count; /* Reserved blocks count */ unsigned long s_free_blocks_count;/* Free blocks count */ unsigned long s_free_inodes_count;/* Free inodes count */ unsigned long s_first_data_block; /* First Data Block */ unsigned long s_log_block_size; /* log(Block size) - 10 */ long s_log_frag_size; /* Fragment size */ unsigned long s_blocks_per_group; /* # Blocks per group */ unsigned long s_frags_per_group; /* # Fragments per group */ unsigned long s_inodes_per_group; /* # Inodes per group */ unsigned long s_mtime; /* Mount time */ unsigned long s_wtime; /* Write time */ unsigned long s_pad; /* Padding to get the magic signature at the same offset as in the previous ext fs */ unsigned short s_magic; /* Magic signature */ unsigned short s_valid; /* Flag */ unsigned long s_reserved[243]; /* Padding to the end of the block */};
32
Field
Description
bg_block_bitmap
bg_inode_bitmap bg_inode_table bg_free_blocks_count bg_free_inodes_count bg_used_dirs_count bg_pad bg_reserved
struct ext2_inode { unsigned short i_mode; /* File mode */ unsigned short i_uid; /* Owner Uid */ unsigned long i_size; /* Size in bytes */ unsigned long i_atime; /* Access time */ unsigned long i_ctime; /* Creation time */ unsigned long i_mtime; /* Modification time */ unsigned long i_dtime; /* Deletion Time */ unsigned short i_gid; /* Group Id */ unsigned short i_links_count; /* Links count, max 32000 */ unsigned long i_blocks; /* Blocks count */ unsigned long i_flags; /* File flags */ unsigned long i_reserved1; unsigned long i_block[15]; /* Pointers to blocks */ unsigned long i_version; /* File version (for NFS) */ unsigned long i_file_acl; /* File ACL */ unsigned long i_dir_acl; /* Directory ACL */ unsigned long i_faddr; /* Fragment address */ unsigned char i_frag; /* Fragment number */ unsigned char i_fsize; /* Fragment size */ unsigned short i_pad1; unsigned long i_reserved2[2]; };
35
Reserved inodes
Inode 1 is reserved for a list of bad blocks on the device. The root directory has inode number 2. This number must be fixed in advance, since the mount() system call must be able to find the root directory. A few other inode numbers have a special meaning. Inode 11 is the first one for ordinary use.
36
Directory entry
struct ext2_dir_entry_2 { __u32 inode; /* Inode number; 0: unused */ __u16 rec_len; /* Directory entry length */ __u8 name_len; /* Name length */ __u8 file_type; char name[up to 255]; /* File name */ };
37
File_type 0 1 2 3 4 5 6 7
Description Unknown Regular file Directory Character Device Block device Named pipe Socket Symbolic link
38
40