Unix File System Internal Structures By C. Shing ITEC Dept Radford University
Objectives Understand partition and file system Understand the file system components Understand the component structure Understand the difference between file and directory Understand how a new file is stored Understand how Unix search file through directory tree
Partition Partition: logically independent disk, accessed by own devices (SCSI disk supports 8 sd, IDE disk can have 4 hd) Example: Linux IDE w 400 cylinders: –3 Primary (/dev/hda[1-3]): cylinder –1 Extend partitions(/dev/hda4): cylinder , used up to logical partitions (replace.dev/had[5-63], can combine adjacent logical partitions)
File System A file system: has directory structure, created to store and retrieve data in files and directory (using disk blocks) Note: One file system is usually on one partition
File System Type Ext2, ext4: for Linux ufs: for SVR4 hsfs or iso9660: for CD-ROM msdos or pcfs: for DOS
Filesystem - Creation Unix commands: –mkfs ext2 /dev/fd0 construct a filesystem –format –t ext2 /dev/fd0 format, repair and analyze disk –fdisk /dev/fd0 create/modify disk partition table
System Components File System 1.Boot block: disk block #0 2.Super-block: disk block #1 3.Inode table: disk block #2 on 4.Data blocks: disk block # starts after inode table blocks
System Components – boot block (1 st Sector) contains MBR (Master Boot Record like in Windows)- 446 bytes –Contains bootstrap program & boot loader and disk partition table- 64 bytes Note: Boot up process: BIOS->run bootsrap(MBR) ->partition disk (partition table) ->select boot loader (CMOS) -> load kernel to disk
System Components – super-block Similar to Windows Boot Block –has boot loader A bitmap of blocks –1: block used –0: free block A bitmap of inode –1: inode used –0: inode block Note: newer system has super-block back- up to prevent system corruption
System Components – inode table List of inodes (index nodes): starts from inode #2 –Inode: 128 Bytes size, represents file, unique in a file system, contains 1.Meta-data 2.Direct block pointers: 10, points to data block 3.Indirect block pointers: 4GB> file size > 40K(for 4K block) 4.Double block pointers: file size > 4 GB 5.… Note: Inode #1 not used: bad block (location of un-usable blocks), prevent from allocating to other files
System Components – data block Store actual user data (contents of file)
File and Directory File: stream of bytes, represented by inode Directory: filenames and their location of inodes
File and Directory Example: –File: inode Meta-dataData Block location
File and Directory Example: –Directory: / NameInode Number.2..2 adminrootfile100 /usr32704
Store New File When a new file is created, the file system will perform the following: 1.Find a free inode (from super-block) to store file properties 2.Find a free block (from super-block) to store the file contents from Kernel buffer 3.Store the block number in the inode 4.Puts filename and the inode number in the current directory
Directory/File Traversal 1.Starts from / (. has inode #2) 2.Find the subdirectory name 3.Find its inode number and its block number 4.Go to the block 5.Go back to step 2, until filename is found
Reference Ch. 14: Unix Internals