Access Method I/O Guide
Access Method I/O Guide
CHAPTER ‘OBJECTIVES
° Describe the user visible file and record operations as well as when and how
` ~ Understand the concept of a current record and how it is used by both the ac-
' Understand the internal control structures that are required to design and im~
° Discuss the critical aspects and trade-of fs in l/O perforrriartccand how overall
° Discuss how accesslmerhod 1/O differs from basic file system I/O
8. 7 0 VERVIEW
ln this chapter we discuss how an access method (AM) spans the gulf bctwccn the
- user and the tile system in order to get the job done. To accomplish this objective,
we must determine what kinds of operations users would like to be able to perform
on records. Then we will examine how these requests can be mapped by thc access
method into a series of calls that are understandable by the file system.
The access methods form the standard interface between applications written
in high-let el languages andthe file system/devices (see Figure S»0). As such, the AM
also serves to hide most, if not all device specifics from the application, and thus
the user really only needs to understand the application tp be done. ln addition, the
;,¢.;,~5, mgrhod is able to provide user programs with more capability than the basic
tile .system alone can provide. Thus, although many ofthe commands appear similar
to the BFS commands. the user is really gaining the capability to work with records
instead of blocks. The specifics of the access methods will become much clearer in
Part lll of the book. Finally, the AM understands the content of :he blocks that
iz passes to the file system lo be read or written. The file system, on the other hand,
does not understand the content of the blocks that it reads and writes.
How does an access method actually organize user data records within a particular
file organization? What algorithms are used to insert new records and also to retrieve
old data records? Each ofthe tile organizations discussed in the rest of Part lll uggg
different techniques and trade~offs. lt is the purpose of this section within each chapter
required to perform a particular function call. Then, in each of the following access.
For example, the standard set of tile attributes might consist of the following
IICHISI -
° Filename or pathname
° File size
It is the last item inahe list above that will be discussed in some detail in each
To insert and retrieve user data records from a file, it is necessary to build enough
file overhead or Iile structure to enable the associated access method to access the
data records. This is similar to the overhead that the basic tile system built on the
disk or tape devices. On disk, the BFS built a boot block, a disk allocation table,
and a directory structure. With this system overhead, the BFS was able to manage
all of the users and all ofthe disk space efficiently and effectively.
This section in each of the unique access method chapters that follows will discuss
what structure is built and why. With knowledge of the file structure, we will im-H
E OPERA 7'/ONS
\\'h;ir kinds of operations do users want, to perform, and what kinds of file opera-
tion; med 10 be supported? File operations operate not on the data records within
the me but on the tile itself. For example, we might want to create a file today and
a¢¢¢55 of 0/,gn it tomorrow. In addition, when we are done processing the file, we
mav want to cut the link to the file or close the files Similarly, we may not always
zue-ss correctly how large the lile will become. Therefore, we will want the capability
of increasing _the size or extending the tile. Finally, at some point in the future, we
may no longer need to keep it; and therefore we will want to get rid of or delete the file.
tile operations, As we proceed through this section, try to relate the functions and
languages with which you are familiar. When you run across data that are not sup-
ported by the language, try to determine where the access method can retrieve the
information. Finally, compare these access method file operations against those per~
The purpose of the CREA T_Efunc1io/1 is ro allow users lo create brand-new files.
Before any records can be written into a file, and before any records can be read
from a file, the file must first be created. How can a file be created? What does it
mean to create a file? If we examine most high-level languages, the capability of creat-
ing all but the most simple sequential files isjust about nonexistent. One of the reasons
for this is that the languages were defined with a particular audience in mind.
tend to perform many I/O operations. Thus the COBOL 1/O support is fairly exten-
si\'e_ FORTRAN was targeted at scientific and engineering applications that require
many calculations and few l/O operations. Thus the FORTRAN language supports
,fr very restricted set of l/O operations. Given this situation, most systems provide
users with utility programs that interactively request all the data needed to create
a lilc_ and then it goes off and creates the file itself.
needed by thc BFS CREATE_FlLE function, all of the following data are needed:
~ Filename
‘ File 'size
~ File organization
Block sizfi A
° Record format
Next, we discuss step by step the tasks performed by the CREATE function.
never create a tile that cannot be used because the user parameters are incorrect, or
worse, correct but inconsistent. At the successful completion of the CREATE re-
quest, the user must be assured that the lile is ready for use. Therefore, the job of
the access method is to ensure, to the best of its abilities, that the input parameters
are consistent' and correct. For example, if a filename was not supplied, how could
the user identify and locate the file tomorrow? Also, it is wrong if the block size
specified for the lile is smaller than the record size, because a block must be able
2. Call the Basic File Sysrenr ‘s CRE/I TE_FlLE Function. - The heart of
CREATE processing requires that the correct disk or tape be mounted in the device,
the name of the file be added to the directory, and disk space be alloested to it. These
are the primarygfunctions of the basic file system CREATE_FlLE routine. ln addi-
tion, the I/O buf |'er(s) must be allocated and initialized. The size of each l/O buffer
erly CREATE the tile. In this section we discuss those things that must be done for
each file organization over and above the standard processing, For examples, labels
information must be written onto the medium in order for the file system to locate
the file and to read and write the blocks within the file. ln addition, information
must be written out in order for the access method to be able to manipulate the records
within the tile. The basic tile system deals only with the blocks in the file, but the
access method must deal with the records within the blocks.
For the access method to be able to manipulate the records, it must know the
record‘s format and size as-well as other file-organization-specific data. The file
organization, record format, and record size are attributes of the file that the access
method must have in order to operate on the records correctly. Therefore, this information
must also be written to the file. ln fact, the overall set of file attributes, as
these parameters are really known, include all the important information about a
tile that is needed to be able to process the file correctly, such as:
.` ~
° Filename
. .1
° File organization
,‘ Block size
‘ Record format
Record size
The question is: Since it is soaimportant, where is this information written? The
jile sysle/ri can record these dam virtually anywhere, as long as they can be readily
retrieved whenever they are needed. The two easiest places to record the data are
giihgr as part of the lile's directory entry or within the file itself. The directory entry
is acceptable for standard data required by all lile organizations, but when we get
the convention of putting only a minimal amount of data into the directory entry
and the rest of the file attributes into the file itself (see Figure 8-1). For example,
in the directory entry we could store the following infomation about the file:
Filename
- Fate size `
° Block size
Then, within the Hle itself we could store the "nonstandard" data, such as:
° File-organizatiorvspecific data
' ' The rationale for t/tLs_spIit is to put into the directory entry only those data
that might be reasonably useful when not acc'e.rsirtg_the_/ile. After all, if we were go-
ing to access the me, it' would not really matter inuch where the data had been stored,
ldirectory listing, it might be useful to have some of the data about the file displayed
Where in the file do we write the attributes? By convention, we can record them
in the first t1 blocks of the file. Why? Because at create time, there are no records
in the file yet, and thus the first block in the file will always be available. Also, it
is an easy convention to remember and the file system dos not need to go looking
‘ 5. Return Status and a-File Identtyier to Calling Program. This is the last
step in the file CREATE prooess. The file identifier is required so that the user can
read and write to many different files atfthe same lime. The file identifier allows the
‘ user to uniquely specify which of the current (iles the record operation is to be per-
formed on. lt is always necessary to notify the calling program whether or not the
request that was made completed successfully or whether it encountered errors. Only
when thecalling program is told that the operation completed successfully can the
program assume that records can now be written into the file.
Unsuccessful CREATE requests could have failed for any number of reasons,
such as:
° File already exists on the medium with the same name. ln this case either we
gave an incorrect name, or the file had already been created by someone else,
the user application programs, and status must always be returned to the user`s
program.
Iii \t|iiim;iri; we haw seen that the access method (.~\:\l) CREATE function
grcatl; o\crl:tp_» the basic file systenfs CREATE_FlLE operation. \\’e can summarize
.\i mc gompletion ofthe CREATE processing. the file has been completely built
and is left open for the user to write and read records. '
The purpose of the access OPEN function is to al/ow users la accessfiles that have
been previously created within the system. lf the file has already been created, all
a user wants to do is to read and write the records within the file. Thus the appropriate
On the other hand, some high~level languages do not provide the capability of
allowing a user to create a new iile.,Instead, they allow the user to open a tile. lf
the file does not exist, it is assumed to be a user request to create a new file.
ln any case, the OPEN request formally connects the user’s program with a
° Filename
ln addition, users are allowed to open _the file under certain user-defined cpn~
~ OPEN for input only (i.e., the user will perform only READ type operations)
° OPEN for oulpul only (i.e,, the user will only WRITE to this ftle)
° OPEN for input and output (i.e., the user wants to be able to perform all types
it is again up to the access methods to ensure that only those record requests
that conform to the mode under which the File was opened are actually processed.
the complete pathname to locate the file, the file system can then retrieve the me
attributes that were written at the time the file was built.
All the information written out as part of the CREATE processing is read back
as part of the OPEN processing. This is because the OPEN task must bring the file
system and access method back up to the level that existed just after the file had been
in the CREATE processing. However, the input parameters are somewhat different
since we no longer need to specify all the file attributes: we need only find and read
them page How can we find the location of the file. and then its attributes? All that
s required is the file, or more specifically, the pathname, With these data, the file
system can read the directory entries until it finds a matching name, lt can then read
th¢ amibuttgg into memory, where the access method can copy them into the pre-
Thus the only parameter that needs to be validated is the lile's pathname. lf
that is correct, the Gle can be found, and all the other parameters or attributes can
be read from the file itself. This is a critical point. We could have let the user rcspccify
all ol' the f`|le"s attributes. However, it is the job of the acccssfmethods to guarantee
that data are never datroyed within the file and that the records can always bc success-
ll' the user must specify the lile's attributes each time, what if thc user makes
a mistake? What if there are 200 users each wanting access to the satne file? What
is the probability that alliof those 200 users will supply the file attribute data with
no errors? lt is simply not worth the risk to the data within the tile. The tile system
and the access methods should only trust the person who had the responsibility of
creating thc file and delining all of the |ile's attributes, lf the person who created
the file was wrong on one or more of the attributes, there is nothing that can be done,
short of recreating thelile. But if there is a conflict between the attributes recorded
in the file and the attributs passed by a user of the file, there is no choice but to
take the attributes that were written into the Ele itself. Also, remember, that all records
“Titten into the File were written according to the attributes defined within the file,
2. Call the Basic File S ystem '.\‘ 0PEN_FILE Function. As part of the OPEN
processing. the access method must ensure that the lile is ready for the user to access
the records in it. l-`|rst, the access method must check the volume label to ensure that
the correct volume has been mounted on the device. Remember that file “abc” can
reside on multiple volumes (e.g., backup versions). Thus it is critical that the correct
volume be mounted and verified by the access method. Then, and only then, can
Next, the access method must determine the size of the blocks in the file from
the file attribuies;'I'hen it must tell theiilesystctn toallocateone or more I/O buf-
fers large enough to contain the largest block in the file. Once this has been done,
I/O can be done by the lile system to read or write any block in the lile on behalf
of the user. _
The next function that must be performed is to allocate mainmemory space for
the FCB. Then the access method must copy the relevent file attributm into thc FCB
basic tile system. Like thc CREATE processing, a fair amount of the processing
process is much more standard-across the set of tile organizations, there are still certain
unique things which must be done at OPEN time for particular file types. It
is the purpose of this section to highlight all file organization specific processing which
it uw; and above the standard processing. Typically. at the completion of OPEN
processing, the access methods set the current record pointer to point to the first user
data record in the file. This is done so that the user can immediately execute a READ
4. Read the File's Attributes. Now that the control blocks and E/O buffers
have been allocated, it is necessary to access all of the attributes of the Ele. These
characteristics can be read both from the lile’S directory entry and from the file iv
self. These attributes are then copied into the various control blocks within the tile
system.
5. Return Status and the File Identifier to the Calling Program. Again, as
with the CREATE request, the calling program must be informed as to whether or
not the request was completed successfully. lf it was, the user can assume that reading
and writing of the records can begin immediately. If there was an error, the user must
determine the next 'course of action. In any case, it is up to the user to determine
what to do next.
An OPEN function call can fail for a variety of reasons, such as:
° File was found, but the current user does not have sufficient access rights to
Also, the OPEN function returns to the calling program a file identifier, which
uniquely identifies this specific File among all the files that are currently OPEN on
ln summary, an OPEN request is very similar to the basic file system‘s OPEN_
file is left in a state in which the user can then access the data records.
8. 3, 3 Close File
The purpose of the CLOSE function is Io allow users the opportunity y to deaccess,
or slap using, a particular file. After a user has processed the records in the file,
there needs to be some way to tell the access method “l’m done." This is one of
the tasks of the CLOSE request. When this function is invoked, the access method
knows that its sole responsibility is to ensure that the file is deceased correctly in
Such a way that no records are lost or destroyed. The only input required is the unique
file identifier that was returned by the file system by the CREATE or OPEN functions. To
accomplish this task, the CLOSE routine performs the following tasks
1. Write Out Any Remaining Data Still in I/0 Buffers. Sometimes, as we
shall soon see, the records and blocks in a file are not actually written back to the
file until they have to be. This cuts down on the actual number of real I/O opera-
tions performed and therefore improves performance. On the other hand, it then
forces on the CLOSE routine the responsibility to ensure that any data not yet writ-
ten into the file actually get transferred there. ln this manner, no records will be lost
To perform this function, the access methods must maintain enough internal
ensuring that all critical file-processing information has been written out into thc file.
Although this may _be the case in most situations, there will arise cases in which the
data are not rewritten until the file is closed in order, for example, to improve per-
formance. Trailer labels on tape could be written out now, for example.
An access method might need to write out the following kinds of information:
By saving _these data, each access method will then be able to successfuly re-
OPEN the file later and correctly process all of its data records. ` i
3. _Call the Basic File System CLOSE_FILE Function. The purpose of this
call is to allow the basic file system to clean up its tables, as well as to be able to
deallocate any main memory that was used in support of theprocessing of that tile.
Also, the basic tile system will write out all blocks in I/O buffers which have been
modified since the last write of the buffer. ~
4. Return Status to the Calling Program. This is done for the same reasons
as mentioned previously. lt is brought up here again simply to help drive home th:
importance of notifying the calling program of the status (i.e., success or failure)
It is possible for a CLOSE function to encounter errors and thus not complete
successfully. Typically, these kinds of errors are easy to fix, such as:
° File l/O errors encountered when writing the IlO buffers out into the lile.
~ Not _enough space on the medium to write out all of the modified l/O block
buffers.
ln summary, the CLOSE operation is almost the exact inverse of the processing that is performed at
OPEN time. Also, in is again wonhwhile 10 View the (1055
lr is uorrh noxing thai if a user fails lo issue the CLOSE requesr before finish-
ing cxccuiion of ihe program, it is the responsibility olflhe access method to perform
the proper processing as 1] the user had _vpecijically requested a close operalion lo
file. Also, ihcrc could have been a bug in the uscr’s program, but the user is not
yer aware ihar a problem exists. Remember, the file system and access method must
always work iogelher to ensure that the correct processing gels done, whether or not
lo increase lhe size of a file. This is essentially the same function as that provided
by the basic Iile system EXTEND_FlLE function. It is redone here to present to users
The processing that the EXTEND function performs is similar to the process»
I. Validate All Input Parameters. First, all input parameters are validated.
2. Call the Basic HI: Sys1em EX TENDTunction. Then, if all is well, the basic
File system EXTEND_FlLE funuion is called to physically extend the file by the
quired for each lilc organization that is unique is minimal, there will becases in which
the EXTEND processing will be access method dependent. For example,-with the
more complex file organizations such as VSAM, space might be allocated for very
specific uses within the File itself, as opposed simply to adding to a pool of space
calling program to indicate whether or not the file was extended successfully, As is
usually the case. it is possible for the EXTEND function not to complete processing
the lile. This is typically done to prevent the case ofa runaway program taking