Calcolatori Elettronici e Sistemi Operativi File � Logical unit of storage – usually persistent – shareable among processes and users Filesystem � Attributes – Name – Ownership – Type – Position – Size – Allocated size – Permissions – Dates and times � modification � creation � access File Directory � Operations � Structure � Set of files and directories – create – none � Operations � sequence of bytes – delete – inspect directory content – sequence of records – open / close – create / delete files/directories � record: ordered set of “fields” – read / write – complex structure – rename files/directories – seek � formatted documents, databases, etc. – traversal – resize – indexes, hash tables, search trees � Access usually imposed at user level – sequential – random
Directory Directory � Organization � Organization dir1 dir2 fileA dir1 dir2 fileA – Tree – Tree fileB dir3 fileC fileD dir4 fileE fileB dir3 fileC fileD dir4 fileE – Acyclic graph – Acyclic graph – Generic graph – Generic graph � symbolic links � symbolic links � hard links � hard links fileH fileI fileF fileG fileF fileG fileH Allows sharing Directory Links � Organization � Symbolic link dir1 dir2 fileA – just a string to identify the target file/directory – Tree � accessing to symlink is translated to accessing the target fileB dir3 fileC fileD dir4 fileE – Acyclic graph � deleting symlink has no effect on file � deleting file “breaks” the symlink – Generic graph � can cross filesystems � symbolic links / � hard links | +-dir1 fileF fileG dir | | | +-file | +-dir2 | +-symlink /dir1/file
Links Mount / Unmount / � "Modular" hierarchy | +-dir1 | | � Connection directory: mount point | +-file | +-dir2 | +-hardlink � Hard link – another access point to the same file on disk � accessing the hard link is accessing the target file � deleting the hard link (or the file) decreases the reference count – when count=0 the file is actually deleted � cannot cross filesystems Filesystem implementation File allocation � Goals: � Superblock (or boot record, or boot sector) – minimize access time � Allocation structures – reduce management overhead – FAT, inode tables – reduce space wasted � Clusters (or blocks) � Contiguous – suitable for read only filesystems (e.g., iso9660) – Contiguous, fixed size, sets of sectors � Linked list – Allocation unit – example: FAT � Directories � Indexed � Files – example: ext2
Contiguous allocation Contiguous allocation directory � Simple file pos len � Fragmentation test 0 6 0 1 2 3 4 doc.txt 6 2 5 6 7 8 9 � Limited resizing support src.tar 8 10 10 11 12 13 14 – Tradeoff management/efficiency 15 16 17 18 19 � Unused space between files 20 21 22 23 24 � File reallocation (copy data in the new position) 25 26 27 28 29 � Need for compaction 30 31 32 33 34 – Deleted files � holes 35 36 37 38 39 – � Previous issues do not occur on read-only filesystems Linked list allocation Linked list allocation directory � Simple dynamic management file start len – tail adding of free blocks in the list test 0 6 0 1 2 3 4 doc.txt 2 2 � No fragmentation 5 6 7 8 9 src.tar 10 10 10 11 12 13 14 � Seek time: O(n) 15 16 17 18 19 � List: critical structure 20 21 22 23 24 list1 : 25 26 27 28 29 0 � 6 � 22 � 23 � 38 � 33 – A single pointer loss can destroy lot of data 30 31 32 33 34 list2 : � Multiple copies 35 36 37 38 39 2 � 8 list3 : 10 � 15 � 25 � 26 � 32 � 37 � 36 � 35 � 30 � 20
Linked list allocation example: FAT Indexed allocation Directory entry directory name size start cluster file idx_tbl len test 0 6 0 1 2 3 4 doc.txt 5 2 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 src.tar 12 10 13 16 17 EOF 10 11 12 13 14 Fat entries 15 16 17 18 19 Table 0 Table 5 Table 12 20 21 22 23 24 idx block idx block idx block 0 1 0 3 0 15 1 38 1 6 1 17 25 26 27 28 29 { { { { 2 27 2 16 10 11 12 13 14 15 16 17 18 19 3 28 3 22 30 31 32 33 34 4 29 4 23 5 20 5 24 Clusters 6 30 35 36 37 38 39 7 31 8 33 9 34 Each FAT entry maps one cluster FATs are allocated in a reserved area Indexed allocation Indexed list allocation example: ext2 idx block ptr 0 Inodes are allocated in a reserved area. 1 � Seek time: O(0) 2 3 4 data 5 Indirect, double-indirect, and triple 6 blocks � No fragmentation 7 indirect blocks are allocated in the data 8 9 area (they are data blocks among data 10 11 - � Maximum file size is fixed blocks allocated for files) - - indirect data block – The size of the index table must be defined at creation blocks Inside the � Multi-level indexing inode � Linked list of index tables double indirect indirect � Maximum number of files is fixed block data block blocks – Room for the index tables must be allocated at creation data triple � Overhead blocks indirect double block indirect indirect – Unused index tables are allocated block block
Indexed list allocation example: ext2 Directory � Block size: 4096 bytes � Linear list of entries � Pointer size: 4 bytes – Simple – Search time: O(n) � Direct pointers: 12 � Hash table � Indirect pointers: 4096/4 = 2 10 – Search time: O(1) � Double indirect pointers: 1024 x 4096/4 = 2 20 – Collisions � Triple indirect pointers: 2 20 x 4096/4 = 2 30 � Total allocable blocks: 12 + 2 10 + 2 20 + 2 30 � Maximum file size: ~ 4096 x 2 30 = 2 42 = 4 TB Actually bounded by nblocks (2 32 ) x sector size (512) = 2 41 = 2TB Free blocks Journaled filesystem � Bitmap � Changes are transactions – Reserved disk area: each bit store info on 1 block – Very efficient if buffered – Transactions are recorded in a log (special area on disk) – Easy to identify contiguous free blocks – Overhead – A transaction is complete when completely recorded in log � Linked list – Recorded transactions are written on filesystem – No overhead � asynchronously � It can be viewed as a “special” file – Wrote transitions are removed from log � Grouping – As linked list, but each node is a group of blocks � Pending operations can be restored in case of system crash � Counting – As linked list � Seeks can be optimized on a very large amount � Each node is the first free block of a free area � In each node there is the counter of the following free blocks
Virtual filesystem Virtual filesystem User process � Single, uniform file system interface to user processes. � Defines a common file model syscall interface – filesystem's general feature and behavior. VFS – assumes that files are objects in a computer's mass storage ext2 FAT iso9660 NTFS NFS cramfs � same basic properties (regardless of the target file system) – unique name disk cache – owner device drivers – protection information Operating system – can be created, deleted, read, written � Needs a mapping module to the real filesystem HW Typical Unix file structure VFS – example: linux /proc kmsg 1 loadavg 10 system information (examples) bin usr locks 1229 boot bin meminfo ... cat /proc/cpuinfo dev doc misc acpi processor : 0 etc include asound modules vendor_id : GenuineIntel home info ... buddyinfo cpu family : 6 root lib sys bus model : 15 user1 local debug cmdline ... user2 sbin dev cpuinfo share crypto fs cat /proc/ide/ide0/hda/geometry lib src kernel devices physical 16383/16/63 mnt diskstats acct logical 16383/255/63 opt var acpi_video_flags dma backups proc bootloader_type driver cat /proc/sys/kernel/hostname root cache cad_pid execdomains www sbin lib ... fb srv local filesystems domainname cat /proc/sys/kernel/osrelease sys lock hostname fs 2.6.28-686 tmp log ... ide mail osrelease interrupts opt ... iomem run threads-max ioports spool unknown_nmi_panic irq tmp kallsyms version net kcore vm key-users
Recommend
More recommend