Your SlideShare is downloading. ×
  • Like
  • Save
File System Modules
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

File System Modules

  • 13,962 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
13,962
On SlideShare
0
From Embeds
0
Number of Embeds
7

Actions

Shares
Downloads
0
Comments
1
Likes
9

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. File System Modules © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
  • 2. What to Expect?Ws of a File SystemThree levels of File SystemsFS relation with a Hard Disk PartitionFS relation with /Writing a FS module © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 2 All Rights Reserved.
  • 3. What is a File System?Three 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> 3 All Rights Reserved.
  • 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. Recall© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
  • 6. 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> 6 All Rights Reserved.
  • 7. 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> 7 All Rights Reserved.
  • 8. 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> 8 All Rights Reserved.
  • 9. Design a FSLets Take 1 PartitionWith 16 blocks of 2 sectors eachSize = 16 x 2 x 512 bytes = 16KiBGiven 3 data pieces Source Code – 2.5KiB Image – 8KiB Document – 2KiBPlace optimally for further operations © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
  • 10. 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 modules We will use a simplified versionSecond 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> 10 All Rights Reserved.
  • 11. Simplified Hardware Layout Logic for DriverUse the block device driver (rb.ko)Hardware Layout Logic: Fixed as followsRoot of the File System Inode Number: 1 Contains at least one file: moksha.txt Inode Number: 2 Size can grow upto the block layer underneath © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
  • 12. VFS SpecificsInherited from the Linux specific FSPromoted to a super set of various FSProviding 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> 12 All Rights Reserved.
  • 13. Virtual File System Interactions complete User Space File System View @ / VFS .... ext2 .... vfat .... Partition 0 Partition 1 ... Partition N ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 13 All Rights Reserved.
  • 14. 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> 14 All Rights Reserved.
  • 15. VFS Interaction Internals Inode Cache VFS Directory Cache ext2 .... vfat Buffer Cache Block Block Drivers Drivers © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
  • 16. VFS Interaction DetailsFive categories File System level Super Block level (Meta Meta Data) Inode level (Meta Data) File level (Data) Buffer Cache level © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 16 All Rights Reserved.
  • 17. File System RegistrationHeader: <linux/fs.h>APIs int register_filesystem(file_system_type *) int unregister_filesystem(file_system_type *)File System Operations get_sb/mount: (Invoked by mount) get_sb_bdev/mount_bdev -> Fill the Super Block kill_sb: (Invoked by umount) kill_block_super © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 17 All Rights Reserved.
  • 18. Fill the Super BlockBlock Size & BitsMagic NumberSuper Block OperationsFile System typeRoot Inode Inode Operations Inode Mode File Operations © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 18 All Rights Reserved.
  • 19. Super Block OperationsHeader: <linux/fs.h>APIs write_inode: Update File Meta Data statfs: Get the File Status (Invoked by stat) simple_statfs (Handler from libfs) © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 19 All Rights Reserved.
  • 20. Inode OperationsHeader: <linux/fs.h>APIs lookup Search the file name by absolute path Traverse the inode chain if found matching inode, then populate the dentry with the inode informationInode Information Size Mode File Operations ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 20 All Rights Reserved.
  • 21. File OperationsHeader: <linux/fs.h>APIs open → generic_file_open read → do_sync_read → generic_file_aio_read → do_generic_file_read → readpage write → do_sync_write → generic_file_aio_write → generic_file_buffered_write → write_begin & write_end release readdir: Change Directory (cd). List Directory (ls) Directory Entry Fill Function fsync: Sync the File (sync) simple_sync_file © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 21 All Rights Reserved.
  • 22. Address Space OperationsThe Buffer / Page Cache level OperationsHeader: <linux/fs.h>Page Operations readpage (Invoked by read) write_begin, write_end (Invoked by write) writepage (Invoked by pdflush kernel threads)Page Functions PageUptodate, PageDirty, PageWriteback, PageLocked SetPageUptodate, ClearPageDirty, unlock_page, ... page_address, ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 22 All Rights Reserved.
  • 23. Peek into the Pseudo Driver © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 23 All Rights Reserved.
  • 24. What all have we learnt?Ws of a File SystemThree levels of File Systems And relation between themFS relation with a Hard Disk PartitionFS relation with / Role of VFSWriting a FS module Simplified Interaction with the Block Driver 5 Operation Sets with VFS © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 24 All Rights Reserved.
  • 25. Any Queries?© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 25 All Rights Reserved.