Page 63 - DCAP602_NETWORK_OPERATING_SYSTEMS_I
P. 63

Unit 3: File System Hierarchy




          the end of the file and the file pointer. Similarly, a write appends to the end of the end of the file   notes
          and advances to the end of the newly written material (the new end of file). Such a file can be reset
          to the beginning, and, on some systems, a program may be able to skip forward or backward n
          records, for some integer n. This scheme is known as sequential access to a file. Sequential access
          is based on a tape model of a file.
          A  sequential  file  may  consist  of  either  formatted  or  unformatted  records.  If  the  records  are
          formatted,  you  can  use  formatted  I/O  statements  to  operate  on  them.  If  the  records  are
          unformatted, you must use unformatted I/O statements only. The last record of a sequential file
          is the end-of-file record.
          3.3.2 Direct access


          Direct access is based on a disk model of a file. For direct access, the file is viewed as a numbered
          sequence of block or records. A direct-access file allows arbitrary blocks to be read or written.
          Thus,  after  block  18  has  been  read,  block  57  could  be  next,  and  then  block  3.  There  are  no
          restrictions on the order of reading and writing for a direct access file. Direct access files are of
          great use for intermediate access to large amounts of information.
          The file operations must be modified to include the block number as a parameter. Thus, we have
          “read n”, where n is the block number, rather than “read next”, and “write n”, rather that “write
          next”. An alternative approach is to retain “read next” and “write next” and to add an operation;
          “position file to n” where n is the block number. Then, to effect a “read n”, we would issue the
          commands “position to n” and then “read next”.
          Not all OS support both sequential and direct access for files. Some systems allow only sequential
          file access; others allow only direct access. Some systems require that a file be defined as sequential
          or direct when it is created; such a file can be accessed only in a manner consistent with its
          declaration.




             Note     Direct-access files support both formatted and unformatted record types. Both
             formatted and unformatted I/O work exactly as they do for sequential files.

          3.3.3 other access methods

          Other access methods can be built on top of a direct-access method. These additional methods
          generally involve the construction of an index for a file. The index contains pointers to the various
          blocks. To find an entry in the file, the index is searched first and the pointer is then used to access
          the file directly to find the desired entry. With a large file, the index itself may become too large
          to be kept in memory. One solution is to create an index for the index file. The primary index file
          would contain pointers to secondary index files, which would point to the actual data items.

                 Example: IBM’s indexed sequential access method (ISAM) uses a small master index that
          points to disk blocks of a secondary index. The secondary index blocks point to the actual file
          blocks. The file is kept sorted on a defined key. To find a particular item, we first make a binary
          search of the master index, which provides the block number of the secondary index. This block
          is read in, and again a binary search is used to find the block containing the desired record.
          Finally, this block is searched sequentially. In this way, any record can be located from its key by
          at most direct access reads.









                                           LoveLy professionaL university                                    57
   58   59   60   61   62   63   64   65   66   67   68