Page 151 - DCAP403_Operating System
P. 151

Operating System




                    Notes          unformatted, you must use unformatted I/O statements only. The last record of a sequential fi le
                                   is the end-of-fi le record.

                                   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 fi le. Direct access fi les 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, you 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”, you 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.
                                   Direct-access files support both formatted and unformatted record types. Both formatted and

                                   unformatted I/O work exactly as they do for sequential fi les.
                                   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 fi le


                                   would contain pointers to secondary index files, which would point to the actual data items. For
                                   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 fi le blocks.


                                   The file is kept sorted on a defined key. To find a particular item, I 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.
                                   8.4 Directory Structure
                                   The directories themselves are simply files indexing other files, which may in turn be directories



                                   if a hyerarchical indexing scheme is used. In order to protect the integrity of the file system in
                                   spite of user of program error, all modifications to these particular directory files are commonly



                                   restricted to the file management system. The typical contents of a directory are:

                                   1.   file name (string uniquely identifying the  file), type (e.g. text, binary data, executable,

                                       library), organization (for systems that support different organizations);
                                   2.   device (where the file is physically stored), size (in blocks), starting address on device (to

                                       be used by the device I/O subsystem to physically locate the fi le);

                                   3.   creator, owner, access information (who is allowed to access the file, and what they may do
                                       with it);
          144                              LOVELY PROFESSIONAL UNIVERSITY
   146   147   148   149   150   151   152   153   154   155   156