29.12.2012 Views

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6. Disk File Access and Control<br />

6.1 GENERAL FILE STRUCTURES<br />

<strong>The</strong> primary reason we make use of computer systems is <strong>to</strong> aid us in managing large volumes<br />

of data. Our computers utilize the Disk Operating System (DOS), the fundamental purpose<br />

of which is <strong>to</strong> make an easier job of handling the s<strong>to</strong>rage of that data. We usually want<br />

rapid access <strong>to</strong> data; therefore, the random access disk s<strong>to</strong>rage device is the selected<br />

s<strong>to</strong>rage medium due <strong>to</strong> its inherent speed in accessing data. <strong>The</strong>se devices take two forms,<br />

floppy disks with either one or two heads which use a single diskette with corresponding<br />

one or two surfaces, and winchester hard disk drives which consist of one or more<br />

platters with each platter consisting of two surfaces. <strong>The</strong> hard disk drive may use either<br />

a fixed or removable media.<br />

Regardless of the disk drive type, each surface is divided in<strong>to</strong> concentric circles of<br />

s<strong>to</strong>rage area called tracks. Each track is then subdivided by a fixed number of subareas<br />

called sec<strong>to</strong>rs. Although the number of sec<strong>to</strong>rs per track may vary from one media type <strong>to</strong><br />

another, the number of sec<strong>to</strong>rs in each track of the same media is constant. <strong>The</strong> DOS<br />

assigns numbers <strong>to</strong> every sec<strong>to</strong>r, every track, and every surface. Surfaces are numbered<br />

consecutively by one starting from zero. Tracks are numbered consecutively by one<br />

starting from zero at the outermost portion of the disk giving the innermost track the<br />

highest number. A CYLINDER consists of the like numbered tracks on all surfaces. For<br />

example, on a two-surface media, track zero of surface zero and track zero of surface one<br />

are grouped <strong>to</strong>gether in<strong>to</strong> cylinder zero. <strong>The</strong> sec<strong>to</strong>rs in each track are numbered starting<br />

from zero. Thus, each track contains like numbered sec<strong>to</strong>rs - regardless of track number<br />

or surface. <strong>The</strong>refore, each sec<strong>to</strong>r on a disk is designated unique by its respective<br />

sec<strong>to</strong>r, surface, and track numbers.<br />

Data is s<strong>to</strong>red in these sec<strong>to</strong>rs. Obviously, if your program had <strong>to</strong> keep track of all the<br />

sec<strong>to</strong>rs your data was occupying, you would have <strong>to</strong> make the program necessarily complex<br />

[if this is not obvious, you will become a believer after reading the section on file<br />

access]. <strong>The</strong> DOS alleviates you of this task by <strong>to</strong>tally managing the s<strong>to</strong>rage space. It<br />

does this by associating an 8-character name with the s<strong>to</strong>rage areas assigned <strong>to</strong> a<br />

logically connected set of data called a file. Thus, the name becomes a FILENAME. <strong>The</strong> DOS<br />

also permits a 3-character extension <strong>to</strong> be affixed <strong>to</strong> that name <strong>to</strong> better classify the<br />

type of file: data, text, command program, etc. This extension is termed the FILE<br />

EXTENSION. You can attach a unique PASSWORD and access level such as EXECute only or READ<br />

only <strong>to</strong> each file in order <strong>to</strong> provide a greater degree of protection <strong>to</strong> the information<br />

contained in the file. Furthermore, the file can be placed on any of up <strong>to</strong> eight disk<br />

s<strong>to</strong>rage devices. Each disk drive is assigned a DRIVE number from zero <strong>to</strong> seven.<br />

<strong>The</strong>refore, <strong>to</strong> uniquely reference a file, we put <strong>to</strong>gether the NAME, EXTENSION, PASSWORD,<br />

and DRIVE and refer <strong>to</strong> the result as a FILE SPECIFICATION. <strong>The</strong> term, file specification,<br />

is rather long so we shorten it <strong>to</strong> "filespec".<br />

In order <strong>to</strong> assign space on a disk for s<strong>to</strong>rage of file data, the DOS groups <strong>to</strong>gether a<br />

quantity of sec<strong>to</strong>rs in<strong>to</strong> a GRANULE. <strong>The</strong> size of the granule varies according <strong>to</strong> the<br />

capacity of the media. This variation in size was discussed in the GRANULE ALLOCATION<br />

TABLE section. <strong>The</strong> DOS assigns space dynamically <strong>to</strong> a file. This means that space is<br />

reserved for the file only when the file needs it. <strong>The</strong> process whereby the system looks<br />

for additional space is termed the ALLOCATION process. <strong>The</strong> DOS would prefer <strong>to</strong> allocate<br />

granules that are connected sequentially <strong>to</strong> each other. <strong>The</strong> sequential connections are<br />

only logical in nature, not physical connections. <strong>The</strong> DOS prefers <strong>to</strong> access a disk drive<br />

device in a particular order <strong>to</strong> optimize the transfer of data. Since the time <strong>to</strong> step the<br />

head from one cylinder <strong>to</strong> another is greater than the time <strong>to</strong> access a sec<strong>to</strong>r in the<br />

cylinder where the head is positioned, it is far preferable <strong>to</strong> access all sec<strong>to</strong>rs of a<br />

cylinder before stepping <strong>to</strong> another cylinder. If we look at sequential access of a file,<br />

we then would want <strong>to</strong> conceptualize a sequential connection <strong>to</strong> start from track zero,<br />

surface zero, sec<strong>to</strong>r zero incrementing the numbers like the odometer in a car as it<br />

6-1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!