Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Internal representation of files ppt

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Próximo SlideShare
Disk management
Disk management
Cargando en…3
×

Eche un vistazo a continuación

1 de 47 Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

Similares a Internal representation of files ppt (20)

Anuncio

Internal representation of files ppt

  1. 1. 1 INTERNAL REPRESENTATION OF FILES Prepared by, A. V. Surve
  2. 2. 2 Contents  Inodes  Structure of a regular file  Directories  Conversion of a path name to an inode  Super block  Inode assignment to a new file  Allocation of Disk Blocks.  Other File Types
  3. 3. 3 Lower Level File system Algorithms namei alloc free ialloc ifree iget iput bmap buffer allocation algorithms getblk brelse bread breada bwrite
  4. 4. 4 Inodes  Contains the information necessary for a process to access a file.  Exists in a static form on disk.  The kernel reads them into an in-core inode to manipulate them.  2 Types:  Disk Inode  In-core Inode
  5. 5. 5 Disk Inodes (1/2) Consists of following fields:  File Owner identifier  Individual owner  “Group” owner  Set of users who have access rights to a file  File Type  File  Regular, directory, character or block special  FIFO (pipe)  File Access permissions  To protect by three classes(owner, group, other)  Read, write, execute
  6. 6. 6 Disk Inodes (2/2)  File Access times  Last modified time, Last access time, Last modification time of Inode  Number of links to the file  Represents no. of names the file has in directory hierarchy.  Table of contents for the disk address of data in a file  Kernel saves the data in discontiguous disk blocks  The Inodes identifies the disk blocks that contain file’s data.  File Size  The inode does not specify the path name(s) that access the file.
  7. 7. 7 Disk Inodes - Sample  Distinction between writing the contents of an inode to disk and writing the contents of a file to disk
  8. 8. 8 in-core inode  Contents in addition to the fields of the disk inode  Status of the in-core inode  the inode is locked,  a process is waiting for the inode to become unlocked,  the in-core representation of the inode differs from the disk copy as a result of a change to the data in the inode,  the in-core representation of the file differs from the disk copy as a result of a change to the file data,  The file is a mount point
  9. 9. 9 in-core inode  Logical Device Number of the file system that contains file.  Inode Number  Pointers to other in-core inodes  Reference Count  Number of instances of the active file..  The kernel links inodes on hash queues and on a free list in the same way that it links buffers on buffer hash queues and on the buffer free list.  A hash queue is identified according to the inode's logical device number and inode number.
  10. 10. 10 Difference between in-core inode and buffer header  In-core inode has In-core reference count.  If count=0, Inode in inactive. (kernel can reallocate in-core inode)  If count = or >= 1, Inode is Active.  Buffer header don’t have reference count.  Buffer is locked when it is allocated.  Buffer is unlocked; it will be in free list.
  11. 11. 11 Accessing Inodes (IGET Algo.) (1/4)  Kernel  Identifies particular inodes by their file system and inode number  Allocates in-core inodes  Using algorithm iget  Allocates an in-core copy of an inode  Map the device number and inode number into a hash queue  Search the queue for the inode  If not find the inode, allocates one from the free list and locks it  Read the disk copy of the newly accessed inode into the in-core copy
  12. 12. 12
  13. 13. 13 Accessing Inodes (2/4)  Computation of logical disk block block num = ((inode number –1)/number of inodes per block) + start block of inode list Where, Block num=Disk block number Start block of inode list=Beginning of Inode List. Inode number= Inode number to be searched
  14. 14. 14 Accessing Inodes (3/4)  Read the block using the algorithm bread  Computation of the byte offset of the inode in the block ((inode number –1) modulo (number of inodes per block)) * size of disk inode Where, Inode number= Inode number. Size of disk inode = Size of disk inode
  15. 15. Example  Find the block number and block offset of inode in the block for following inode number:  6895  4258  Assumptions: 1. Start Block of Inode List: 200 2. Disk Block size: 1024 bytes 3. Size of Disk Inode: 64 bytes 15
  16. 16. 16
  17. 17. 17 Accessing Inodes (4/4)  Hold lock during execution of a system call for possibly consistency  Release it at the end of system call  The lock is free between system calls  To allow processes to share simultaneous access to a file  The reference count remains set between system calls  To prevent the kernel from reallocating an active in-core inode
  18. 18. 18 Release Inodes (IPUT Algo.)  Using algorithm iput  decrements in-core reference count  Write the inode to disk  Reference count is 0  The in-core copy differs from the disk copy  Add the inode on the free list of inodes  For caching
  19. 19. 19
  20. 20. 20 Structure of a Regular File  Table of contents in an inode  Location of a file’s data on disk  A set of disk block #  Each block on a disk is addressable by number  Not contiguous file allocation strategy  Why ?  When a file expand or contract…  Fragmentations occur
  21. 21. 21 Sample - Fragmentation  File B was expanded  Garbage collection – too high cost File A File B File C 40 50 60 70 …. ……. File A Free File C 40 50 60 70 …. …….File B 85
  22. 22. 22 Structure of a Regular File – UNIX System V 13 entries in the inode table of contents  10 Direct, 1 Single Indirect, 1 Double Indirect, 1 Triple Indirect Block  Assume  a logical block = 1K bytes  a block number is addressable by a 32 bit (4 bytes) integer  a block can hold up to 256 block numbers  Byte Capacity of a File 10 direct blocks with 1K bytes each= 10K bytes 1 indirect block with 256 direct blocks= 1K*256 = 256K bytes 1 double indirect block with 256 indirect blocks = 256K*256= 64M bytes 1 triple indirect block with 256 double indirect blocks=64M*256= 16G bytes
  23. 23. 23 Direct and Indirect Blocks in Inode – UNIX System V Inode Data Blocks direct0 direct1 direct2 direct3 direct4 direct5 direct6 direct7 direct8 direct9 single indirect double indirect triple indirect ………..
  24. 24. 24 Block Layout of a Sample File and its Inode 4096 228 45423 0 0 11111 0 101 367 0 428 9156 824 331 3333 9156 331 33330 75 367 1 disk block = 1024 bytes byte offset 9000, byte offset 350,000 816th 808th
  25. 25. 25 Structure of a Regular File  Processes  access data in a file by byte offset  view a file as a stream of bytes  The kernel  accesses the inode  converts the logical file block into the appropriate disk block
  26. 26. 26
  27. 27. 27 Directories (1/2)  A directory is a file  Its data is a sequence of entries  Contents of each entries  an inode number and the name of a file  Path name is a null terminated character string divided by slash (“/”)  UNIX System V  Maximum of component name : 14 characters  Inode # : 2 bytes  Size of a directory : 16 bytes
  28. 28. 28 Directories (2/2) Directory layout for /etc
  29. 29. 29 Conversion of a Path Name to an Inode  The initial access to a file is by its path name  Open, chdir, link system calls  The kernel works internally with inodes rather than with path name  Converting the path names to inodes  Using algorithm namei  parse the path name one component at a time  convert each component into an inode  finally return the inode of the input path name
  30. 30. 30
  31. 31. 31 Sample-namei(/etc/passwd) Encounters “/” and gets the system root inode Current working inode = root Permission check Search root for a file – “etc” Access data in the root directory block by block Search each block one entry-”etc” Finding Release the inode for root(iput) Allocate the inode for etc(iget) by inode # found Permission check for “etc” Search “etc” block by block for a directory struct. entry for “passwd” Finding Relase the the inode for “etc” Allocate the inode for “passwd” Return that inode
  32. 32. 32 Super Block  Contents  the size of the file system.  the number of free blocks in the file system.  a list of free blocks available on the file system.  the index of the next free block in the free block list,  the size of the inode list.  the number of free inodes in the file system.  a list of free inodes in the file system.  the index of the next free inode in the free inode list.  lock fields for the free block and free inode lists.  a flag indicating that the super block has been modified.
  33. 33. 33 Inode Assignment to A New File (1/4)  a known inode  Algorithm iget : to allocate  Algorithm namei : to determine inode #  Algorithm ialloc  To assign a disk inode to a newly created file  Super block contains an array  To improve performance of searching a free inode  To cache the numbers of free inodes
  34. 34. 34
  35. 35. 35 Inode Assignment to a New File (2/4) free inodes 83 48 empty 18 19 20 array1 Super Block Free Inode List index free inodes 83 empty 18 19 20 array2 Super Block Free Inode List index Assigning Free Inode from Middle of List
  36. 36. 36 Inode Assignment to a New File (3/4) index Assigning Free Inode – Super Block List Empty 470 empty array1 Super Block Free Inode List index 0 535 free inodes 476 475 471 array2Super Block Free Inode List 0 48 49 50 remembered inode
  37. 37. 37
  38. 38. 38 Inode Assignment to a New File (4/4) 535 476 475 471 free inodes remembered inode Original Super Block List of Free Inodes index Free Inode 499 499 476 475 471 free inodes remembered inode index Free Inode 601 499 476 475 471 free inodes remembered inode index
  39. 39. 39 Race Condition  A Race Condition Scenario in Assigning Inodes  three processes A, B, and C are acting in time sequence 1. The kernel, acting on behalf of process A, assigns inode I but goes to sleep before it copies the disk inode into the in-core copy. 2. While process A is asleep, process B attempts to assign a new inode but free inode list is empty, and attempts assign free inode at an inode number lower than that of the inode that A is assigning. 3. Process C later requests an inode and happens to pick inode I from the super block free list
  40. 40. 40 Race Condition in Assigning Inodes (1/2)
  41. 41. 41 Race Condition in Assigning Inodes (2/2) time …………………………………………….I Empty …………………………. free inodes free inodes free inodes L J I J I K …………………………………………………………………... ………………………………………………….……………. ……………………………………………………... (a) (b) (c) (d) (e)
  42. 42. 42 Allocation of Disk Blocks  When a process writes data to a file, the kernel must allocate disk blocks  An array in the file system super block  To cache the numbers of free disk block in the file system  Mkfs  Organize the data blocks of a file system in a linked list  Each link is a disk block  The block contains an array of free disk block numbers  One array entry is the number of the next block of the linked list
  43. 43. 43 Linked list of free disk block number 109 109 103 100 …………………………... 109 211 208 205 202 ………………… 112 211 310 307 304 301 ………………… 214 310 409 406 403 400 ………………… 313
  44. 44. 44
  45. 45. 45 Requesting and Freeing Disk Blocks (1/2) 109 ………………………………………………………… 211 208 205 202 …………………………….. 112 109 949 ………………………………………………….. 211 208 205 202 ………………………………. 112 super block list original configuration 109 109 After freeing block number 949
  46. 46. 46 Requesting and Freeing Disk Blocks (2/2) 211 208 205 202 ……………………………… 112 344 341 338 335 ………………………………. 243 After assigning block number(109) replenish (fill up again) super block free list 211 109 ……………………………………………………….. 211 208 205 202 ………………………………. 112 109 After assigning block number(949)
  47. 47. 47 Other File Types  Pipe  fifo (first-in-first-out)  its data is transient  Once data is read from a pipe, it cannot be read again  The data is read in the order that it was written to the pipe, no deviation from that order  using only direct block  Special File (including block device, character device)  Specifying devices  The inode does not reference any data  The inode contains the major and minor device number  major number  a device type such as terminal or disk  minor number  the unit number of the device

×