Hardware Reference
In-Depth Information
A disk can hold many files, each with some particular kind of data, for example, a
picture, a spreadsheet, or the text of a book chapter. Different files have different
lengths and other properties. The abstraction of a file allows virtual I/O to be
organized in a simple way.
To the operating system, a file is normally just a sequence of bytes, as we have
described above. Any further structure is up to the application programs. File I/O
is done by system calls for opening, reading, writing, and closing files. Before a
file can be read, it must be opened. The process of opening a file allows the oper-
ating system to locate the file on disk and bring into memory information neces-
sary to access it.
Once a file has been opened, it can be read. The read system call must have
the following parameters, at a minimum:
1. An indication of which open file is to be read.
2. A pointer to a buffer in memory in which to put the data.
3. The number of bytes to be read.
The read call puts the requested data in the buffer. Usually, it returns the count of
the number of bytes actually read, which may be smaller than the number re-
quested (you cannot read 2000 bytes from a 1000-byte file).
Associated with each open file is a pointer telling which byte will be read next.
After a read it is advanced by the number of bytes read, so consecutive read s read
consecutive blocks of data from the file. Usually, there is a way to set this pointer
to a specific value, so programs can randomly access any part of the file. When a
program is done reading a file, it can close it, to inform the operating system that it
will not be using the file any more, thus allowing the operating system to free up
the table space being used to hold information about the file.
Mainframe computers are still around (especially for running very large
e-commerce Websites) and some of them still run traditional operating systems (al-
though many run Linux). The traditional mainframe operating systems have a dif-
ferent model of what a file is, and it is worth taking a brief look at this model, just
to show that the UNIX way is not the only way to do things. In these traditional
systems, a file is a sequence of logical records , each with a well-defined structure.
For example, a logical record might be a data structure consisting of five items:
two character strings, ''Name,'' and ''Supervisor''; two integers, ''Department''
and ''Office''; and a Boolean, ''SexIsFemale.'' Some operating systems make a
distinction between files in which all the records in a file have the same structure
and files which contain a mixture of different record types.
The basic virtual input instruction reads the next record from the specified file
and puts it into main memory beginning at a specified address, as illustrated in
Fig. 6-20. To perform this operation, the virtual instruction must be told which file
to read and where in memory to put the record. Often there are options to read a
specific record, specified either by its position in the file or by its key.
 
Search WWH ::




Custom Search