Page 452 - DCAP103_Principle of operating system
P. 452

Unit 14: Case Study of Linux Operating System



            the data blocks. All the files and directories are stored here. If a file or directory consists of more   Notes
            than one block, the blocks need not be contiguous on the disk. In fact, the blocks of a large file
            are likely to be spread all over the disk.

            I-nodes corresponding to directories are dispersed throughout  the disk  block groups. Ext2
            attempts to collocate ordinary files in the same block group as the parent directory, and data
            files in the same block as the original file i-node, provided that there is sufficient space. This idea
            was taken from the Berkeley Fast File System (McKusick et al., 1984). The bitmaps are used to
            make quick decisions regarding where to allocate new file system data. When new file blocks
            are allocated, ext2 also preallocates a number (eight) of additional blocks for that file, so as to
            minimize the file fragmentation due to future write operations. This scheme balances the file
            system load across the entire disk. It also performs well due to its tendencies for collocation and
            reduced fragmentation. To access a file, it must first use one of the Linux system calls, such as
            open, which requires the file’s pathname. The pathname is parsed to extract individual.
            If a relative path is specified, the lookup starts from the process’ current directory, otherwise
            it starts from the root directory. In either case, the i-node for the first directory can easily be
            located: there is a pointer to it in the process descriptor, or, in the case of a root directory, it is
            typically stored in a predetermined block on disk.

            The directory file allows file names up to 255 characters and is illustrated in Figure 14.32. Each
            directory  consists  of  some  integral number of  disk  blocks  so  that directories  can  be written
            atomically to the disk. Within a directory, entries for files and directories are in unsorted order,
            with each entry directly following the one before it. Entries may not span disk blocks, so often
            there is some number of unused bytes at the end of each disk block.


              Figure 14.32: (a) A Linux Directory with Three Files and (b) The Same Directory After
                                 the File Voluminous has been Removed



























            Each directory entry in Figure 14.32 consists of four fixed-length fields and one variable-length field.
            The first field is the i-node number, 19 for the file colossal, 42 for the file voluminous, and 88 for the
            directory  bigdir.  Next  comes  a  field  reclen,  telling  how  big  the  entry  is  (in  bytes),  possibly
            including some padding after the name. This field is needed to find the next entry for the case



                                             LOVELY PROFESSIONAL UNIVERSITY                                   445
   447   448   449   450   451   452   453   454   455   456   457