
filesystems 3 1 last time FAT headers, free space, allocating space hard disk performance seek times from physical movement of disk head queues of requests, scheduled to control seek time smarts in controller: bad blocks, scheduling solid state disks block remapping to hide erasure blocks in flash xv6 filesystem inodes contain info about file blocks, type, size, etc. (instead of directory entries) 2 xv6 filesystem xv6’s filesystem similar to modern Unix filesytems better at doing contiguous reads than FAT better at handling crashes supports hard links (more on these later) divides disk into blocks instead of clusters file block numbers, free blocks, etc. in different tables 4 inodefreewhat block about — filesuperblock map finding information — 1 bit —free “header”per inodes data block struct dinode { ←logstart1xv6 if available,solution:struct scan 0 ifsuperblock used for type = { 0 short type;uint //size;File type // T_DIR,//T_FILESize ,ofT_DEVfile system image (blocks) ←inodestartallocatingtypical Unix blocks:uint solution:nblocks; scan separate for 1 bits free inode map ninodesshort major;// short# of dataminor;blocks// T_DEV only contiguous 1s — contigous blocks inode size uint ninodes; short nlink; ←bmapstart // # of inodes // Numberuintofnlog;links to inode in file system uint size; // //# ofSizelogofblocksfile (bytes) uint addrs[NDIRECT+1];uint logstart; nblocks // Data block// blockaddresses# of first log block }; uint inodestart; // block # of first inode block locationuint ofbmapstart; data as block numbers: e.g. addrs[0]// block =# 11;of addrs[1]first free = 14;map block }; special case for larger files xv6 disk layout the disk 0 (boot block) 1 super block 2 log 3 4 5 inode array 6 7 free block map 8 9 data blocks block number 10 11 12 13 14 15 5 16 17 18 inodefreewhat block about — file map finding information — 1 bitfree per inodes data block struct dinode { 1xv6 ifshort available,solution:type; scan 0 if// used forFile typetype = 0 // T_DIR, T_FILE, T_DEV allocatingtypicalshort Unixmajor; blocks: solution:short scan separate forminor; 1 bits free// T_DEV inodeonly map contiguous 1s — contigous blocks short nlink; // Number of links to inode in file system uint size; // Size of file (bytes) uint addrs[NDIRECT+1]; // Data block addresses }; location of data as block numbers: e.g. addrs[0] = 11; addrs[1] = 14; special case for larger files xv6 disk layout the disk 0 (boot block) superblock — “header” 1 super block ←logstart struct superblock { 2 uint size; log 3 // Size of file system image (blocks) 4 ←inodestart uint nblocks; ninodes // # of data blocks 5 inode array uint ninodes; 6 inode size ←bmapstart // # of inodes 7 free block map uint nlog; 8 // # of log blocks 9 uint logstart; data blocks nblocks // block # of first log block block number 10 uint inodestart; 11 // block # of first inode block 12 uint bmapstart; 13 // block # of first free map block 14 }; 15 5 16 17 18 freewhat block aboutsuperblock map finding — 1 bit —free “header”per inodes data block ←logstart1xv6 if available,solution:struct scan 0 ifsuperblock used for type = { 0 uint size; // Size of file system image (blocks) ←inodestartallocatingtypical Unix blocks:uint solution:nblocks; scan separate for 1 bits free inode map ninodes // # of data blocks contiguous 1s — contigous blocks inode size uint ninodes; ←bmapstart // # of inodes uint nlog; // # of log blocks uint logstart; nblocks // block # of first log block uint inodestart; // block # of first inode block locationuint ofbmapstart; data as block numbers: e.g. addrs[0]// block =# 11;of addrs[1]first free = 14;map block }; special case for larger files xv6 disk layout the disk 0 (boot block) inode — file information 1 super block struct dinode { 2 short type; // File type log 3 // T_DIR, T_FILE, T_DEV 4 short major; short minor; // T_DEV only 5 inode array 6 short nlink; 7 // Number of links to inode in file system free block map 8 uint size; // Size of file (bytes) uint addrs[NDIRECT+1]; 9 data blocks // Data block addresses block number 10 }; 11 12 13 14 15 5 16 17 18 freewhat block aboutsuperblock map finding — 1 bit —free “header”per inodes data block ←logstart1xv6 if available,solution:struct scan 0 ifsuperblock used for type = { 0 uint size; // Size of file system image (blocks) ←inodestartallocatingtypical Unix blocks:uint solution:nblocks; scan separate for 1 bits free inode map ninodes // # of data blocks contiguous 1s — contigous blocks inode size uint ninodes; ←bmapstart // # of inodes uint nlog; // # of log blocks uint logstart; nblocks // block # of first log block uint inodestart; // block # of first inode block uint bmapstart; // block # of first free map block }; xv6 disk layout the disk 0 (boot block) inode — file information 1 super block struct dinode { 2 short type; // File type log 3 // T_DIR, T_FILE, T_DEV 4 short major; short minor; // T_DEV only 5 inode array 6 short nlink; 7 // Number of links to inode in file system free block map 8 uint size; // Size of file (bytes) uint addrs[NDIRECT+1]; 9 data blocks // Data block addresses block number 10 }; 11 12 location of data as block numbers: 13 e.g. addrs[0] = 11; addrs[1] = 14; 14 special case for larger files 15 5 16 17 18 inodewhat about — filesuperblock finding information —free “header” inodes struct dinode { ←logstartxv6 solution:struct scansuperblock for type = { 0 short type;uint //size;File type // T_DIR,//T_FILESize ,ofT_DEVfile system image (blocks) ←inodestarttypical Unixuint solution:nblocks; separate free inode map ninodesshort major;// short# of dataminor;blocks// T_DEV only inode size uint ninodes; short nlink; ←bmapstart // # of inodes // Numberuintofnlog;links to inode in file system uint size; // //# ofSizelogofblocksfile (bytes) uint addrs[NDIRECT+1];uint logstart; nblocks // Data block// blockaddresses# of first log block }; uint inodestart; // block # of first inode block locationuint ofbmapstart; data as block numbers: e.g. addrs[0]// block =# 11;of addrs[1]first free = 14;map block }; special case for larger files xv6 disk layout the disk 0 (boot block) free block map — 1 bit per data block 1 super block 2 1 if available, 0 if used log 3 4 allocating blocks: scan for 1 bits 5 inode array contiguous 1s — contigous blocks 6 7 free block map 8 9 data blocks block number 10 11 12 13 14 15 5 16 17 18 inodefree block — filesuperblock map information — 1 bit — “header”per data block struct dinode { ←logstart1 if available,struct 0 ifsuperblock used { short type;uint //size;File type // T_DIR,//T_FILESize ,ofT_DEVfile system image (blocks) ←inodestartallocating blocks:uint nblocks; scan for 1 bits ninodesshort major;// short# of dataminor;blocks// T_DEV only contiguous 1s — contigous blocks inode size uint ninodes; short nlink; ←bmapstart // # of inodes // Numberuintofnlog;links to inode in file system uint size; // //# ofSizelogofblocksfile (bytes) uint addrs[NDIRECT+1];uint logstart; nblocks // Data block// blockaddresses# of first log block }; uint inodestart; // block # of first inode block locationuint ofbmapstart; data as block numbers: e.g. addrs[0]// block =# 11;of addrs[1]first free = 14;map block }; special case for larger files xv6 disk layout the disk 0 (boot block) what about finding free inodes 1 super block 2 xv6 solution: scan for type = 0 log 3 4 typical Unix solution: separate free inode map 5 inode array 6 7 free block map 8 9 data blocks block number 10 11 12 13 14 15 5 16 17 18 xv6 directory entries struct dirent { ushort inum; char name[DIRSIZ]; }; inum — index into inode array on disk name — name of file or directory each directory reference to inode called a hard link multiple hard links to file allowed! 6 xv6 allocating inodes/blocks need new inode or data block: linear search simplest solution: xv6 always takes the first one that’s free 7 xv6 inode: direct and indirect blocks addrs data blocks addrs[0] addrs[1] … addrs[11] addrs[12] indirect block of … direct blocks … 8 xv6 file sizes 512 byte blocks 2-byte block pointers: 256 block pointers in the indirect block 256 blocks = 131072 bytes of data referenced 12 direct blocks @ 512 bytes each = 6144 bytes 1 indirect block @ 131072 bytes each = 131072 bytes maximum file size = 6144 + 131072 bytes 9 similar pointers like xv6 FS —whole butowner more bunch indirection and of group times type (regular, directory, device) and permissions (read/write/execute for owner/group/others) Linux ext2 inode struct ext2_inode { __le16 i_mode; /* File mode */ __le16 i_uid; /* Low 16 bits of Owner Uid */ __le32 i_size; /* Size in bytes */ __le32 i_atime; /* Access time */ __le32 i_ctime; /* Creation time */ __le32 i_mtime; /* Modification time */ __le32 i_dtime; /* Deletion Time */ __le16 i_gid; /* Low 16 bits of Group Id */ __le16 i_links_count; /* Links count */ __le32 i_blocks; /* Blocks count */ __le32 i_flags; /* File flags */ ... __le32 i_block[EXT2_N_BLOCKS]; /* Pointers to blocks */ ... }; 10 similar pointers like xv6 FS —whole butowner more bunch indirection and of group times Linux ext2 inode struct ext2_inode { __le16 i_mode; /* File mode */ __le16 i_uid; /* Low 16 bits of Owner Uid */ __le32 i_size; /* Size in bytes */ __le32 i_atime; /* Access time */ __le32 i_ctime; /* Creation time */ __le32 i_mtime; /* Modification time */ __le32type i_dtime; (regular, directory,/* Deletion device) Time */ __le16and i_gid; permissions (read/write/execute/* Low 16 forbits owner/group/others)of Group Id */ __le16 i_links_count; /* Links count */ __le32 i_blocks; /* Blocks count */ __le32 i_flags; /* File flags */ ... __le32 i_block[EXT2_N_BLOCKS];
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages80 Page
-
File Size-