Input and output refer to the data your computer system
receives and the data that it sends. OS-9 can receive (input)
data from a keyboard, disk files, modems, and other terminals. It
can send (output) data to all of these devices-except the key
board-and to a video display.
OS-9 receives and sends data in the same format, regardless of
whether the destination is a file or a device. It overcomes the dif
ferences in the devices by defining a standard for them and using
device drivers to make each device conform to the standard. The
result: a much simpler and more versatile input/output system.
The base of OS-9's unified I/O system is an organization of
paths. Input/output paths are, in effect, software links between
files. (Remember, OS-9 thinks of all devices as files.)
Individual device drivers process data so that it conforms to the
hardware requirements of the device involved. Data transfer is in
streams of 8-bit bytes that can be either bidirectional (read/
write) or unidirectional (read only or write only), depending on
the device, how you establish the path, or both. A byte is a unit
of computer data. (A byte may contain the code for one alphabet
character.) A bit is a binary digit and has a value of either 0 or
1.
OS-9 does not require the data it manages to have any special
format or meaning. The meaning of the data is determined by
the programs that use it.
A directory is a storage place for other directories and files. It
contains the information about the directories and files assigned
to it so that OS-9 can easily find and access the data they
contain.
Each disk has its own directory system. For example, a typical
system diskette, diagrammed partially and simply, might look
like this:
The ROOT directory of /DO the ROOT from which the rest of
the disk's file system grows-contains a file called Startup and
two directories, SYS and CMDS.
SYS and CMDS, in turn, contain files: SYS contains Errmsg,
and CMDS contains Copy, List, Dir, Del, and Format. All these
files and directories, and many more, come built into the OS-9
system.
OS-9 organizes each directory area into 32-byte records. The
first 29 bytes contain filename characters. The first byte of the
name has its sign bit (the leftmost or most significant bit) set.
When you delete a file, it is not immediately destroyed. Rather,
the deletion process sets the first character position of the record
to zero, and OS-9 no longer recognizes the record. Although the
file contents still exist, they are no longer accessible to you or
OS-9. Subsequent file creations overwrite deleted records.
The last three bytes of a record make up a 24-bit binary number
that is the logical sector number pointing to the file descriptor
record. Logical sectors are numbered with reference to the
sequence of their use, rather than their physical location on a
disk. See "Disk Files" for more information on disk organization.
You create directories using the MAKDIR command and can
identify them by the D (directory) attribute. (See "Examining
and Changing File Attributes".) MAKDIR initializes each direc
tory with two entries having the names "." and "..". These
entries contain the logical sector numbers of the directory and
its parent directory, respectively.
You cannot use the COPY and LIST commands (as described in
Getting Started With OS-9) with directories. Instead, use DSAVE
and DIR.
You cannot delete directories directly. You must first empty a
directory of files, convert it into a standard file, and then delete
it. However, the DELDIR command performs all these functions
automatically.
The system stores all files as an ordered sequence of 8-bit bytes.
The file can be any size from 0 bytes to the maximum capacity
of the storage device and can be expanded or shortened as
desired.
When OS-9 creates or opens a file, it establishes a file pointer for
it. OS-9 addresses bytes within the file in the same manner it
addresses memory, and the file pointer holds the address of the
next byte to write or read. OS-9's read and write functions
always update the pointer as the system transfers data.
This pointer function lets assembly-language programmers and
high-level language programmers reposition the file pointer. To
expand a file, write past the previous end of the file. Reading up
to the last byte of a file causes the next read request to return
an end-of-file status.
OS-9's file system also uses a universal organization for all I/O
devices. This feature means that application programs can treat
each hardware device similarly. The following section gives basic
information about the physical file structure used by OS-9. (For
more information, see the OS-9 Level Two Technical Reference
manual.)
The data contained in a file is stored in one or more sectors (disk
storage units). These file sectors have both a logical and a physi
cal arrangement. The logical arrangement numbers the sectors
in sequence. The physical arrangement can be in any order
based on the actual location of a sector on a disk's surface. For
instance, Logical Sector 1 might be located at Physical Sector
10, and Logical Sector 2 might be located at Physical Sector 19.
Each sector contains 256 data bytes. The first sector of every file
(Logical Sector Number 0 or LSN 0) is called the file descriptor.
It contains the logical and physical description of the file. The
disk driver module links sector numbers to physical track/sector
numbers on a disk.
A sector is the smallest physical unit of a file that OS-9 can
allocate for storage. On the Color Computer, a sector is also the
smallest file unit. (To increase efficiency on some larger-capacity
disk systems, OS-9 uses uniform-sized groups of sectors, called
clusters, as the smallest allocatable unit. A cluster is always an
integral power of two-2, 4, 8, and so on.)
OS-9 uses one or more sectors of each disk as a bitmap (usually
starting at LSN 1) in which each data bit corresponds to one
cluster on the disk. The system sets and clears bits to indicate
which clusters it is using, which clusters are defective, and
which clusters are free for allocation. The Color Computer
default floppy disk system uses this format:
Each OS-9 file has a directory entry that includes the filename
and the logical sector number of the file's file descriptor sector.
The file descriptor sector contains a complete description of its
file, including:
Unless the file size is 0, the file uses one or more sectors/clusters
to store data. The system groups data sectors into one or more
adjacent blocks called segments.
Text files contain variable-length lines of ASCII characters. A
carriage return (ASCII code OD hexadecimal or 13 decimal) ter
minates each line. Text files contain such data as program
source code, procedure files, messages, and documentation.
Programs usually read text files sequentially. Almost all high
level languages (such as BASIC09) support text files.
Random-access files consist of sequences of records, with each
record the same length. A program can find any record's begin
ning address by multiplying the record number by the number of
bytes used for each record. This feature allows direct access of
any record.
Usually, high-level languages let you subdivide records into
fields. Each field can have a fixed length and use. For example,
the first field of a record can be 25 text characters in length, the
next field can be two bytes in length and used to hold 16-bit
binary numbers, and so on.
OS-9 does not directly process records. It only provides the basic
file functions used by high-level languages to create and handle
random-access files.
Programmers use high-level languages like BASIC09, Pascal,
and C to create random-access data files. For instance, in
BASIC09 and Pascal, GET, PUT, and SEEK functions operate
on random-access files.
Procedure files are disk files that contain commands. You can
use them to execute a series of commands by typing and enter
ing a single command name.
Your System Master diskette contains one procedure file named
Startup. You can create your own procedure files using the
BUILD command, copying input from the keyboard to a file, or
by using a text editor program. For instance, suppose you have
three disk drives, /D0, /D 1, and /H0. You could create three very
simple procedures to allow you to look at the directories of these
disks by typing and entering a simple two-character command.
The first line creates a file named P1 (print directory for Drive
/D1). When you press ENTER , a question mark appears on the
screen telling you that OS-9 is waiting for input. Type the rest
of the lines. Finally, press ENTER at the beginning of a line to
tell OS-9 that the input is complete. OS-9 closes the file.
Now, to see the contents of Drive /D 1, type p 1 ENTER . The com
mand d i 5 p 1 a y e C clears the video screen. The command
d i 5 p 1 a y 0 A causes the cursor to drop down one line on the
screen.
Use your imagination. Almost anything you can do from the key
board, you can do with a procedure file. However, remember that
OS-9 looks only in the current data directory for a procedure
file, unless you provide a full pathlist to the procedure. Also,
OS-9 must be able to find any command in the current execution
directory that is part of a procedure file. If the current execution
directory does not contain the commands you need, change it,
either from the keyboard or as part of your procedure file.
OS-9 program modules are executable program code, generated
by an assembler or compiled by a high-level language. A file can
contain one or more program modules.
Each module has a standard format that includes the object code
(the executable portion of the module), a module header that
describes the type and size of the module, and a CRC (Cyclic
Redundancy Checksum) value. The system stores program mod
ules in files in the same structure in which they load into mem
ory. Because OS-9 programs are position-independent, they do
not require specific memory addresses for loading.
For OS-9 to load program module(s) from a file, the file execute
attribute must be set, and each module must have a valid mod
ule header and CRC value. If you or the system alters a program
module in any way (either as a file or in memory), its CRC
check value becomes incorrect, and OS-9 cannot load the module.
If a file contains two or more modules, OS-9 treats them as a
group and assigns contiguous memory locations for them.
Using LIST on program files or any other files that contain
binary data, causes a jumbled display of random characters and
an error message.
OS-9's basic file functions are so versatile that you can devise
almost unlimited numbers of special-purpose file formats for
particular applications that require formats not discussed here
(text, random-access, and so on).
Each file and directory has properties called ownership and attri
butes that determine who can access the file and how they can
use it.
OS-9 automatically stores the user number associated with the
creation of a file. The system considers the owner of the number
to be the owner of the file.
Security functions are based on access attributes. There are
eight attributes, each of which can be turned off or on indepen
dently. When the D (directory) attribute is on for a file, that file
is a directory. (Only MAKDIR can set the D attribute for a file.)
When the S (shareable) attribute is on, only one program or user
can access the file at a time.
The other six attributes control whether the file can be read
from, written to, or executed by either the owner or the public
(all other users.) When on, these six attributes function as
follows:
For example, if a file has all permissions on except write permit
to public and read permit to public, the owner has unrestricted
access to the file. Other users can execute it but cannot read,
copy, delete, or alter it.
You can use the DIR command, with the E (entire) option, to
examine the security permissions of all files in a particular
directory. An example of output using DIR E on the current data
directory is: _permission to prevent binary files from
being used as text files.
Use this permission to protect important
files from accidental deletion or
modification.
and execute it. To be loaded, the file must
contain one or more valid OS-9 memory
modules.
The following command enables public write and public read per
missions and removes the execute permission for both the owner
and the public:
When two or more processes use the same file simultaneously,
they might attempt to update the file at the same time, causing
unpredictable results. When you open a file in the update mode,
OS-9 eliminates the problem of simultaneous use by locking the
sections of the file. The lock covers any disk sectors containing
the bytes last read by each process accessing the file. If one pro
cess attempts to access a locked portion of a file, OS-9 puts the
process to sleep until the locked area is free.
OS-9 moves the lock and frees the area when it reads from or
writes to another area. The system removes a lock on a file when
the process associated with the lock closes its path to the file. A
process can have only one lock on a file, but it can have locks on
more than one file.
You can lock an entire file by activating its single user bit. (See
the earlier section "Examining and Changing File Attributes.")
When the single user bit is on, only one process can open a path
to the file at a time. Attempts by other processes to access the
file result in an error.
Although OS-9 and your computer can access all these devices,
your original diskette does not configure it to do so. For informa
tion on configuring your system, see Chapter 7 of Getting
Started With OS-9.
Because device names are at the root of the file system, you can
use them only as the first part of a pathlist. Always precede the
name of a device with a slash.
When you refer to a non-disk device, for example a terminal or
printer, use only the device name. /P, for instance, is the full
allowable pathlist for a printer.
Note: An I/O device name is actually the name of an OS-9
device descriptor that you precede with a slash (/). OS-9
automatically loads device descriptors during the OS-9 boot
sequence. You can add or delete other device descriptors
while the system is running or add device descriptors to the
bootfile using CONFIG.