Linux File System

9,765 views
9,657 views

Published on

Published in: Technology
1 Comment
17 Likes
Statistics
Notes
  • very usefula nd inforamtive link ....
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
9,765
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
1
Likes
17
Embeds 0
No embeds

No notes for slide

Linux File System

  1. 1. Linux File System© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
  2. 2. What to Expect?Ws of a File SystemThree Levels of File System © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 2 All Rights Reserved.
  3. 3. What is a File System?Mechanism of Organizing our Data Labelling by Names, Easy Access, ...Algorithm to Achieve the DesiredOrganization Ability to Store, Retrieve, Search, Sort, ...Data Structures to Achieve the DesiredPerformance © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 3 All Rights Reserved.
  4. 4. Why we need a File System?Preserve Data for Later Access Update DiscardTag Data for Categorizing Easy & Fast LookupFast & Reliable Data Management by Optimized Operations © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
  5. 5. File System DecodedThree things at three levels Hardware Space – The Physical Organization of Data on the Storage Devices Kernel Space – Drivers to decode & access the data from the Physical Organization User Space – All what you see from / - The User ViewWhich ever it be, it basically does Organize our data For easy access by tagging For fast maintenance by optimizing © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
  6. 6. Hardware Space File System © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
  7. 7. The Hard Disk Tracks SectorsDisk orPlatter © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
  8. 8. The Hard Disk Spindle Heads . .Cylinder . . . . © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 8 All Rights Reserved.
  9. 9. Understanding a Hard DiskExample (Hard Disk) Heads (or Platters): 0 – 9 Tracks (or Cylinders): 0 – 24 Sectors: 1 – 64Size of the Hard Disk 10 x 25 x 64 x 512 bytes = 8000KiBDevice independent numbering (h, t, s) → 64 * (10 * t + h) + s → (1 - 16000) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
  10. 10. Partitioning a Hard DiskFirst Sector – Master Boot Record (MBR) Contains Boot Info Contains Physical Partition TableMaximum Physical Partitions: 4 At max 1 as Extended Partition Rest as Primary PartitionExtended could be further partitioned into Logical PartitionsIn each partition First Sector – Boot Record (BR) Remaining for File System / Format Extended Partition BR contains the Logical Partition Table © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
  11. 11. Placement of a Hardware FSEach Partition contains a File System Raw (no FS) OrganizedOrganized one is initialized by the correspondingFormating“Partition Type is to OS” W95*, DOS*, BSD*, Solaris*, Linux, ...“Format Type is to File System” ext2, ext3, vfat, ntfs, jffs2, …Particular Partition Types support only Particular FileSystem Types © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
  12. 12. Design a FSLets Take 1 PartitionWith 16 blocks of 2 sectors eachSize = 16 x 2 x 512 bytes = 16KBGiven 3 data pieces Source Code – 2.5KB Image – 8KB Document – 2KBPlace optimally for further operations © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 12 All Rights Reserved.
  13. 13. Kernel Space File System© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 13 All Rights Reserved.
  14. 14. Kernel Space File SystemHas 2 Roles to Play Decode the Hardware FS Layout to access data (by implementing your logic in s/w) Interface that with the User Space FS to give you a unified view, as you all see at /First part: ext2, ext3, vfat, ntfs, jffs2, … Also called the File System modulesSecond part: VFS Kernel provides VFS to achieve the virtual user view So, FS module should actually interact with VFS © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 14 All Rights Reserved.
  15. 15. Linux specific File SystemsInitial Linux: Minix FSAs Linux matured: Extended (ext) FS1994: Second Extended (ext2) FSLatest: Third Extended (ext3) FSFeatures Introduced: Access Control Lists (ACL) Block Fragmentation Logical Deletion Journaling © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
  16. 16. Linux FS Data StructuresSuper block – Stores filesystem meta dataInode – Stores file meta dataDirectory Entry – Stores file name & inodenumberInode & Data block Bitmap – Bitmap fortracking usage status of the variousblocksGroup Entry – Stores information ofgroups of Data Storage © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 16 All Rights Reserved.
  17. 17. Linux FS TransitionsChoosing Optimal Block Size (from 1KiB to4KiB), depending on the expected average filelengthChoosing Number of InodesPartition Groups: Each group includes DataBlocks and Inodes stored in adjacent tracksPreallocating Disk Data Blocks to Regular FilesFast Symbolic Links © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 17 All Rights Reserved.
  18. 18. File System related CommandsFile and Inode information – statHardlinks and Softlinks – ln & ln -sMounting filesystem – mount & umountCreating special files – mknod, mkfifoPermission related – chmodOwnership related – chown, chgrpTimestamp related – touch © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 18 All Rights Reserved.
  19. 19. Case Study: ext2/ext3© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 19 All Rights Reserved.
  20. 20. ext2/ext3: Disk Data Structure Boot Block group 0 ... Block group n blockSuper Group Data block Inode Inode Data blocksblock Descriptors Bitmap Bitmap Table1 block n blocks 1 block 1 block n blocks n blocks Superblock and Group Descriptors are duplicated in each Block Group Superblock and Group Descriptors in Block Group 0 are used by the kernel © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 20 All Rights Reserved.
  21. 21. ext2/ext3: Superblockunsigned long s_frag_size; /* Size of a fragment in bytes */unsigned long s_frags_per_block; /* Number of fragments per block */unsigned long s_inodes_per_block; /* Number of inodes per block */unsigned long s_frags_per_group; /* Number of fragments in a group */unsigned long s_blocks_per_group; /* Number of blocks in a group */unsigned long s_inodes_per_group; /* Number of inodes in a group */unsigned long s_itb_per_group; /* Number of inode table blocks per group */unsigned long s_gdb_count; /* Number of group descriptor blocks */unsigned long s_desc_per_block; /* Number of group descriptors per block */unsigned long s_groups_count; /* Number of groups in the fs */... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 21 All Rights Reserved.
  22. 22. ext2/ext3: Group Descriptor__le32 bg_block_bitmap; /* Blocks bitmap block number */__le32 bg_inode_bitmap; /* Inodes bitmap block number */__le32 bg_inode_table; /* Inodes table first block number */__le16 bg_free_blocks_count; /* Free blocks in the group */__le16 bg_free_inodes_count; /* Free inodes in the group */__le16 bg_used_dirs_count; /* Directories in the group */__le16 bg_pad; /* Alignment to word */__le32 bg_reserved[3]; /* Nulls to pad out 24 bytes */ © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 22 All Rights Reserved.
  23. 23. ext2/ext3: Inode EntryInode Table consists of Inode Entries. An Inode Entry is as follows __le16 i_mode; /* File type & access rights */ __le16 i_uid; /* Low 16 bits of owner uid */ __le32 i_size; /* File size in bytes */ __le32 i_atime; /* Last file access time */ __le32 i_ctime; /* File creation time */ __le32 i_mtime; /* Last file contents modification time */ __le32 i_dtime; /* File deletion time */ __le16 i_gid; /* Low 16 bits of group id */ __le16 i_links_count; /* Hard links counter */ __le32 i_blocks; /* Number of data blocks of the file */ __le32 i_flags; /* File flags */ union osd1; /* OS specific information */ __le32 i_block[12 + 3]; /* Pointers to data blocks */ ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 23 All Rights Reserved.
  24. 24. ext2/ext3: File TypesFile Types supportedFile Type Value Description0 Unknown1 Regular2 Directory3 Character Device4 Block Device5 Named Pipe6 Socket7 Symbolic Link © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 24 All Rights Reserved.
  25. 25. ext2/ext3: Directory EntryDirectory is a File, with Data Blockscontaining Directory EntriesA Directory Entry is as follows __le32 inode; /* Inode number */ __le16 rec_len; /* Directory entry length */ __u8 name_len; /* Name length */ __u8 file_type; /* File type */ char name[255]; /* File name */ © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 25 All Rights Reserved.
  26. 26. Virtual File System© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 26 All Rights Reserved.
  27. 27. VFS SpecificsInherited from the Linux specific FSPromoted to a super set of various FSProvides a unified view to the UserDefault values for various attributes owner, group, permissions, …File Types Same seven types as in ext2/ext3 © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 27 All Rights Reserved.
  28. 28. Virtual File System Interactions User Space File System View @ / VFS .... ext2 .... vfat .... Partition 0 Partition 1 ... Partition N ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 28 All Rights Reserved.
  29. 29. Virtual File System Internals d r Super Block Directory Entry Table Inode Table> FS Meta Data> Root Inode Number > File Name > Inode Number > File Meta Data > File Data Block Nos Data Block © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 29 All Rights Reserved.
  30. 30. Recall: User Space File System © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 30 All Rights Reserved.
  31. 31. / & the System Directories/bin, /sbin - system binaries/applications/var - logs, mails/proc, /sys - “virtual” windows into the kernel/etc - configuration files/lib - shared system libraries/dev - device files/boot - Linux kernel and boot related binary files/opt - for third-party packages/root, /home - home directory for super user & other users/usr - user space related files and dirs (binaries, libraries, ...)/tmp - scratch pad/mnt - mount points © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 31 All Rights Reserved.
  32. 32. What all have we learnt?Ws of a File SystemThree Levels of File System Hardware Space Kernel Space User Space © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 32 All Rights Reserved.
  33. 33. Any Queries?© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 33 All Rights Reserved.

×