File Systems
Total Page:16
File Type:pdf, Size:1020Kb
Input & Output 1: File systems ● What are files? ● A sequence of (usually) fixed sized blocks stored on a device. ● A device is often refered to as a volume. ● A large device might be split into several volumes, or partitions. ● Or a volume might span more than one device. ● Each volume, or partition is divided into numbered blocks. Input & Output : ● The O/S has to keep track of which blocks are used by which file. ● A mapping between the file name, the volume, and the blocks in which it is kept. ● A special file known as a directory holds these mappings ● The simplest structure has a single volume and a single layer. ● A table holds the mapping information. Input & Output : Flat File Systems ● Macintosh File System (MFS), A 400 kilobyte floppy disc based flat file system. ● Each file contained two parts, known as forks : ● Resource Fork : – contains metadata in the form of attribute/value pairs – icon bitmaps – program segments – structured data ● Data Fork : – contains the file data in common with other file systems – Introduced with the Macintosh 128k in January 1984 Input & Output : Hierarchical File systems ● MS-DOS FAT(12/16/V) file system. Provided directories in a tree structure. ● Data stored in 512 byte sectors, grouped into clusters of 4 to 64 sectors. – Each cluster has an entry in the File Allocation Table (FAT) to indicate how it is being used. – Entry values include: ● marked as ’bad’ ● unused ● used ● next cluster number/end of chain number Input & Output : Hierarchical File Systems 2 ● Each directory table has a 32 byte entry per file containing ● File name and extension – also used to indicate deletion ● File Attributes – Read-only – Hidden – System – Directory ● Change Date/time ● File Size ● Starting cluster number Input & Output : Hierarchical File Systems 3 ● Disk Structure : ● Volume Boot Sector, the first sector. ● File Allocation Table, held in the next sectors ● Two copies are kept – primary, – backup. ● Root Directory Table, following the 2nd FAT – Fixed size, which limits number of entries. – 1.44Mb floppy = 224 entries – Hard disk = 512 entries Input & Output : Hierarchical File Systems 3 ● Each directory has 2 special entries ● . and .. ● shorthand for the current directory and the parent directory. ● Files need not occupy adjacent clusters, leading to fragmented files. ● Chaining clusters together to hold files is risky. The directory table only holds the first cluster number. ● The FAT holds the chain information. FAT16 Diagrams File systems : Linux VFS ● Related calls ● file_ops : inode_ops: ● llseek (); create(); ● read (); lookup(); ● write (); link(); ● readdir (); mkdir(); ● poll (); rmdir(); ● ioctl (); rename(); ● mmap (); readpage(); ● open (); writepage() ● release (); readlink(); Linux File systems: 2 ● Review : ● Directories are special files containing variable length records, one for each file or – directory contained within the directory. struct dirent { unsigned short d_namlen; /* name length */ unsigned short d_reclen; /* entry length */ long int d_ino; /* inode number */ char d_name[]; /* file name */ }; ● They only hold the file name and a reference number, the index node. Linux File systems: 3 ● The inode has two forms ● The ’on-disk’ inode : – contains the information preserved when the file is closed, occupies 128 bytes. – The file mode, (permissions and access control) – The UID and the GID of the owner & group. – The size in bytes – Last access, modification & creation times – Link count – number of blocks – Array of pointers to actual data blocks. – Fragment information. Linux File systems: 4 ● The ’in-memory’ inode : ● contains the above + additional information – pointers to the linked list holding the inode – the device on which the inode is kept – the number of current users of this file. – – mutual exclusion information – – pointers to operations specific to the file type. – pointers into virtual memory holding the file – – file type specific information Linux File systems: 5 ● File Types can be ● file! – -rwxr-xr-x 1 craig craig 249823232 2010-12-08 21:08 sdimage-new.dd ● directory – drwx------ 2 ngunton ecestaff 4096 Feb 12 2004 mail ● socket – srwxr-xr-x 1 ngunton ecestaff 0 Nov 18 20:17 SOff_ ● soft link – lrwxrwxrwx 1 root root 8 Jul 10 2002 cdrom->/dev/hdc ● block special (device) – brw-r--r-- 1 root disk 22, 0 May 8 1995 hdc ● character special (device) – crwx-w---- 1 ngunton tty 4, 1 Nov 22 09:20 tty1 ● named pipe – prw------- 1 ngunton ecestaff 0 Nov 22 17:29 mypipe Linux File systems: 6 ● Opening a file: ● Lookup the directory entry for the file. ● If the file does not exist, create it? ● Check the user privileges against file permissions ● Check if the file is already open – refuse access? – refuse if open for write? – refuse write if open for read? ● Create in-memory inode if above succeed. ● Return file-handle to user. Getting a copy of the file info Getting a copy of the file info Getting a copy of the file info Getting a copy of the file info Linux File systems: On disk Linux File systems: On disk Linux File systems: On disk Super Block: ● Every block group has a copy of the super block. ● ● Contains unchanging information about the file system (partition) including : ● total inode & free inode count ● total number of data blocks ● number of free blocks ● size of a block group ● location of first data block ● ID of this block group ● size of a block ● Copied into memory when the file system is mounted. Block Group Descriptor: ● This is also present in each block group. ● ● A table of records, one for each block group, containing information specific to an ● individual block group. ● pointer to a bitmap tracking data block allocation ● pointer to a bitmap tracking inode allocation ● pointer to the inode table. ● counter of free data blocks in group. ● counter of free inodes in group. ● number of directories in this group. ● Also copied into memory when filesystem is mounted. Bitmaps: ● Block bitmap: ● one bit for each data block, – 0 = free; – 1 = in use; ● Exactly one disk block in size. ● ● Inode bitmap: ● ● one bit for each inode, as per the block bitmap. Inode Table : Inode table Inode table Inode Table : 3 This limits the maximum file size to 64 gigabytes. .